Jump to content

[PY] Enable colors in Notice Board


Recommended Posts

  • Active+ Member

With these modifications, you will enable colors in notice board, like this:

 

Image:

 

spacer.png

 

Tutorial:

 

Open uitip.py and add this to the start of the file:

import re

 

Now find class TipBoard(ui.Bar):, and replace it with this:

 

class TipBoard(ui.Bar):

	SCROLL_WAIT_TIME = 3.0
	TIP_DURATION = 5.0
	STEP_HEIGHT = 17

	def __init__(self):
		ui.Bar.__init__(self)

		self.AddFlag("not_pick")
		self.tipList = []
		self.curPos = 0
		self.dstPos = 0
		self.nextScrollTime = 0

		self.width = 370		

		self.SetPosition(0, 70)
		self.SetSize(370, 20)
		self.SetColor(grp.GenerateColor(0.0, 0.0, 0.0, 0.5))
		self.SetWindowHorizontalAlignCenter()

		self.__CreateTextBar()

	def __del__(self):
		ui.Bar.__del__(self)

	def __CreateTextBar(self):

		x, y = self.GetGlobalPosition()

		self.textBar = TextBar(370, 300)
		self.textBar.SetParent(self)
		self.textBar.SetPosition(3, 5)		
		self.textBar.SetClipRect(0, y, wndMgr.GetScreenWidth(), y+18)
		self.textBar.Show()

	def __CleanOldTip(self):
		leaveList = []
		for tip in self.tipList:
			madeTime = tip[0]
			if app.GetTime() - madeTime > self.TIP_DURATION:
				pass
			else:
				leaveList.append(tip)

		self.tipList = leaveList

		if not leaveList:
			self.textBar.ClearBar()
			self.Hide()
			return

		self.__RefreshBoard()

	def __RefreshBoard(self):

		self.textBar.ClearBar()

		index = 0
		for tip in self.tipList:
			text = tip[1]
			rgb = tip[2]
			if rgb != (0,0,0):
				self.textBar.SetTextColor(rgb[0],rgb[1],rgb[2])
			self.textBar.TextOut(0, index*self.STEP_HEIGHT, text)
			self.textBar.SetTextColor(255,255,255)
			index += 1

	def SetTip(self, text):
		if not app.IsVisibleNotice():
			return

		rgb = (0,0,0)
		mat = re.search("\|cFF([a-zA-Z0-9]+)\|h", text)
		if mat and mat.group(1):
			hexd = mat.group(1)
			rgb = tuple(int(hexd[i:i+2], 16) for i in (0, 2, 4))

		curTime = app.GetTime()
		self.tipList.append((curTime, text, rgb))
		self.__RefreshBoard()

		self.nextScrollTime = app.GetTime() + 1.0

		if not self.IsShow():
			self.curPos = -self.STEP_HEIGHT
			self.dstPos = -self.STEP_HEIGHT
			self.textBar.SetPosition(3, 5 - self.curPos)
			self.Show()

	def OnUpdate(self):

		if not self.tipList:
			self.Hide()
			return

		if app.GetTime() > self.nextScrollTime:
			self.nextScrollTime = app.GetTime() + self.SCROLL_WAIT_TIME

			self.dstPos = self.curPos + self.STEP_HEIGHT

		if self.dstPos > self.curPos:
			self.curPos += 1
			self.textBar.SetPosition(3, 5 - self.curPos)

			if self.curPos > len(self.tipList)*self.STEP_HEIGHT:
				self.curPos = -self.STEP_HEIGHT
				self.dstPos = -self.STEP_HEIGHT

				self.__CleanOldTip()

 

Example of use:

            
--- in quests:

		notice_all("|cFF29BFBF|hColored text Example#1")
		notice("|cFFFF0000|hColored text Example #2")

--- ingame:
		"n |cFF29BFBF|h Hello World"

 

That's all 🙂

Edited by Metin2 Dev International
Core X - External 2 Internal
  • Metin2 Dev 4
  • Good 1
  • Love 1

spacer.png

Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.