Jump to content

[Python] Ui functions for real developers


Guest Ezrekith

Recommended Posts

Guest Ezrekith

Talkshow:

Spoiler

Please do not start to add this functions if you don't have a minimal Python knowledge because it will be useless for you.

 

But if you think it's useful for you, here is some tips:

-You can create more over in/out even for the classes

-You can create more event functions for classes

any many more usefull + functions for you imagebox, anibox, button and text.

 

Example for the AniImage:

Spoiler

 

 

class Window(object):

#Replace or expand with those functions which you will need in the future.
#(I have the target info system included in this, so watch out!)

class Window(object):
	def NoneMethod(cls):
		pass

	NoneMethod = classmethod(NoneMethod)

	def __init__(self, layer = "UI"):
		self.hWnd = None
		self.parentWindow = 0
		self.RegisterWindow(layer)
		self.onMouseLeftButtonUpEvent = None
		self.Hide()
		
		self.mouseLeftButtonDownEvent = None
		self.mouseLeftButtonDownArgs = None
		self.mouseLeftButtonUpEvent = None
		self.mouseLeftButtonUpArgs = None
		self.mouseLeftButtonDoubleClickEvent = None
		self.mouseRightButtonDownEvent = None
		self.mouseRightButtonDownArgs = None
		self.moveWindowEvent = None
		self.renderEvent = None
		self.renderArgs = None

		self.overInEvent = None
		self.overInArgs = None

		self.overOutEvent = None
		self.overOutArgs = None

		self.baseX = 0
		self.baseY = 0

		self.SetWindowName("NONAME_Window")

	def __del__(self):
		wndMgr.Destroy(self.hWnd)

	def RegisterWindow(self, layer):
		self.hWnd = wndMgr.Register(self, layer)

	def Destroy(self):
		pass

	def GetWindowHandle(self):
		return self.hWnd

	def AddFlag(self, style):
		wndMgr.AddFlag(self.hWnd, style)

	def IsRTL(self):
		return wndMgr.IsRTL(self.hWnd)

	def SetWindowName(self, Name):
		wndMgr.SetName(self.hWnd, Name)

	def GetWindowName(self):
		return wndMgr.GetName(self.hWnd)

	if app.ENABLE_SEND_TARGET_INFO:
		def SetParent(self, parent):
			if parent:
				wndMgr.SetParent(self.hWnd, parent.hWnd)
			else:
				wndMgr.SetParent(self.hWnd, 0)
	
		def SetAttachParent(self, parent):
			wndMgr.SetAttachParent(self.hWnd, parent.hWnd)
	else:
		def SetParent(self, parent):
			wndMgr.SetParent(self.hWnd, parent.hWnd)

	def SetParentProxy(self, parent):
		self.parentWindow=proxy(parent)
		wndMgr.SetParent(self.hWnd, parent.hWnd)

	
	def GetParentProxy(self):
		return self.parentWindow

	def SetPickAlways(self):
		wndMgr.SetPickAlways(self.hWnd)

	def SetWindowHorizontalAlignLeft(self):
		wndMgr.SetWindowHorizontalAlign(self.hWnd, wndMgr.HORIZONTAL_ALIGN_LEFT)

	def SetWindowHorizontalAlignCenter(self):
		wndMgr.SetWindowHorizontalAlign(self.hWnd, wndMgr.HORIZONTAL_ALIGN_CENTER)

	def SetWindowHorizontalAlignRight(self):
		wndMgr.SetWindowHorizontalAlign(self.hWnd, wndMgr.HORIZONTAL_ALIGN_RIGHT)

	def SetWindowVerticalAlignTop(self):
		wndMgr.SetWindowVerticalAlign(self.hWnd, wndMgr.VERTICAL_ALIGN_TOP)

	def SetWindowVerticalAlignCenter(self):
		wndMgr.SetWindowVerticalAlign(self.hWnd, wndMgr.VERTICAL_ALIGN_CENTER)

	def SetWindowVerticalAlignBottom(self):
		wndMgr.SetWindowVerticalAlign(self.hWnd, wndMgr.VERTICAL_ALIGN_BOTTOM)

	def SetTop(self):
		wndMgr.SetTop(self.hWnd)

	def Show(self):
		wndMgr.Show(self.hWnd)

	def Hide(self):
		wndMgr.Hide(self.hWnd)
		
	def SetVisible(self, is_show):
		if is_show:
			self.Show()
		else:
			self.Hide()

	def Lock(self):
		wndMgr.Lock(self.hWnd)

	def Unlock(self):
		wndMgr.Unlock(self.hWnd)

	def IsShow(self):
		return wndMgr.IsShow(self.hWnd)

	def UpdateRect(self):
		wndMgr.UpdateRect(self.hWnd)

	def SetSize(self, width, height):
		wndMgr.SetWindowSize(self.hWnd, width, height)

	def GetWidth(self):
		return wndMgr.GetWindowWidth(self.hWnd)

	def GetHeight(self):
		return wndMgr.GetWindowHeight(self.hWnd)

	def GetLocalPosition(self):
		return wndMgr.GetWindowLocalPosition(self.hWnd)
		
	def GetLeft(self):
		x, y = self.GetLocalPosition()
		return x

	def GetGlobalLeft(self):
		x, y = self.GetGlobalPosition()
		return x

	def GetTop(self):
		x, y = self.GetLocalPosition()
		return y

	def GetGlobalTop(self):
		x, y = self.GetGlobalPosition()
		return y

	def GetRight(self):
		return self.GetLeft() + self.GetWidth()

	def GetBottom(self):
		return self.GetTop() + self.GetHeight()

	def GetGlobalPosition(self):
		return wndMgr.GetWindowGlobalPosition(self.hWnd)

	def GetMouseLocalPosition(self):
		return wndMgr.GetMouseLocalPosition(self.hWnd)

	def GetRect(self):
		return wndMgr.GetWindowRect(self.hWnd)

	def SetPosition(self, x, y):
		wndMgr.SetWindowPosition(self.hWnd, x, y)

	def SetCenterPosition(self, x = 0, y = 0):
		self.SetPosition((wndMgr.GetScreenWidth() - self.GetWidth()) / 2 + x, (wndMgr.GetScreenHeight() - self.GetHeight()) / 2 + y)
		
	def SavePosition(self):
		self.baseX = self.GetLeft()
		self.baseY = self.GetTop()
	
	def UpdatePositionByScale(self, scale):
		self.SetPosition(self.baseX * scale, self.baseY * scale)
		
	def SetLeft(self, x):
		wndMgr.SetWindowPosition(self.hWnd, x, self.GetTop())

	def IsFocus(self):
		return wndMgr.IsFocus(self.hWnd)

	def SetFocus(self):
		wndMgr.SetFocus(self.hWnd)

	def KillFocus(self):
		wndMgr.KillFocus(self.hWnd)

	def GetChildCount(self):
		return wndMgr.GetChildCount(self.hWnd)

	def IsIn(self):
		return wndMgr.IsIn(self.hWnd)
		
	def IsInPosition(self):
		xMouse, yMouse = wndMgr.GetMousePosition()
		x, y = self.GetGlobalPosition()
		return xMouse >= x and xMouse < x + self.GetWidth() and yMouse >= y and yMouse < y + self.GetHeight()
	
	def SetMouseLeftButtonDownEvent(self, event, *args):
		self.mouseLeftButtonDownEvent = event
		self.mouseLeftButtonDownArgs = args
	
	def OnMouseLeftButtonDown(self):
		if self.mouseLeftButtonDownEvent:
			apply(self.mouseLeftButtonDownEvent, self.mouseLeftButtonDownArgs)

	if app.ENABLE_SEND_TARGET_INFO:
		def SetOnMouseLeftButtonUpEvent(self, event, *args):
			self.mouseLeftButtonUpEvent = event
			self.mouseLeftButtonUpArgs = args
	else:
		def SetOnMouseLeftButtonUpEvent(self, event):
			self.onMouseLeftButtonUpEvent = ev

	def SetMouseLeftButtonDoubleClickEvent(self, event):
		self.mouseLeftButtonDoubleClickEvent = event
	
	def OnMouseLeftButtonDoubleClick(self):
		if self.mouseLeftButtonDoubleClickEvent:
			self.mouseLeftButtonDoubleClickEvent()
	
	def SetMouseRightButtonDownEvent(self, event, *args):
		self.mouseRightButtonDownEvent = event
		self.mouseRightButtonDownArgs = args
	
	def OnMouseRightButtonDown(self):
		if self.mouseRightButtonDownEvent:
			apply(self.mouseRightButtonDownEvent, self.mouseRightButtonDownArgs)
	
	def SetMoveWindowEvent(self, event):
		self.moveWindowEvent = event
	
	def OnMoveWindow(self, x, y):
		if self.moveWindowEvent:
			self.moveWindowEvent(x, y)
	
	def SAFE_SetOverInEvent(self, func, *args):
		self.overInEvent = __mem_func__(func)
		self.overInArgs = args
	
	def SetOverInEvent(self, func, *args):
		self.overInEvent = func
		self.overInArgs = args
	
	def SAFE_SetOverOutEvent(self, func, *args):
		self.overOutEvent = __mem_func__(func)
		self.overOutArgs = args
	
	def SetOverOutEvent(self, func, *args):
		self.overOutEvent = func
		self.overOutArgs = args
	
	def OnMouseOverIn(self):
		if self.overInEvent:
			apply(self.overInEvent, self.overInArgs)
	
	def OnMouseOverOut(self):
		if self.overOutEvent:
			apply(self.overOutEvent, self.overOutArgs)
	
	def SAFE_SetRenderEvent(self, event, *args):
		self.renderEvent = __mem_func__(event)
		self.renderArgs = args
	
	def ClearRenderEvent(self):
		self.renderEvent = None
		self.renderArgs = None
	
	def OnRender(self):
		if self.renderEvent:
			apply(self.renderEvent, self.renderArgs)
		
	def SetOnMouseLeftButtonUpEvent(self, event):
		self.onMouseLeftButtonUpEvent = event
		
	def OnMouseLeftButtonUp(self):
		if self.onMouseLeftButtonUpEvent:
			self.onMouseLeftButtonUpEvent()

class TextLine(Window):

#Replace or expand with those functions which you will need in the future.

class TextLine(Window):
	def __init__(self):
		Window.__init__(self)
		self.max = 0
		self.SetFontName(localeInfo.UI_DEF_FONT)

	def __del__(self):
		Window.__del__(self)

	def RegisterWindow(self, layer):
		self.hWnd = wndMgr.RegisterTextLine(self, layer)

	def SetMax(self, max):
		wndMgr.SetMax(self.hWnd, max)

	def SetLimitWidth(self, width):
		wndMgr.SetLimitWidth(self.hWnd, width)

	def SetMultiLine(self):
		wndMgr.SetMultiLine(self.hWnd, True)

	def SetHorizontalAlignArabic(self):
		wndMgr.SetHorizontalAlign(self.hWnd, wndMgr.TEXT_HORIZONTAL_ALIGN_ARABIC)

	def SetHorizontalAlignLeft(self):
		wndMgr.SetHorizontalAlign(self.hWnd, wndMgr.TEXT_HORIZONTAL_ALIGN_LEFT)

	def SetHorizontalAlignRight(self):
		wndMgr.SetHorizontalAlign(self.hWnd, wndMgr.TEXT_HORIZONTAL_ALIGN_RIGHT)

	def SetHorizontalAlignCenter(self):
		wndMgr.SetHorizontalAlign(self.hWnd, wndMgr.TEXT_HORIZONTAL_ALIGN_CENTER)

	def SetVerticalAlignTop(self):
		wndMgr.SetVerticalAlign(self.hWnd, wndMgr.TEXT_VERTICAL_ALIGN_TOP)

	def SetVerticalAlignBottom(self):
		wndMgr.SetVerticalAlign(self.hWnd, wndMgr.TEXT_VERTICAL_ALIGN_BOTTOM)

	def SetVerticalAlignCenter(self):
		wndMgr.SetVerticalAlign(self.hWnd, wndMgr.TEXT_VERTICAL_ALIGN_CENTER)

	def SetSecret(self, Value=True):
		wndMgr.SetSecret(self.hWnd, Value)

	def SetOutline(self, Value=True):
		wndMgr.SetOutline(self.hWnd, Value)

	def SetFeather(self, value=True):
		wndMgr.SetFeather(self.hWnd, value)

	def SetFontName(self, fontName):
		wndMgr.SetFontName(self.hWnd, fontName)

	def SetDefaultFontName(self):
		wndMgr.SetFontName(self.hWnd, localeInfo.UI_DEF_FONT)

	def SetFontColor(self, red, green, blue):
		wndMgr.SetFontColor(self.hWnd, red, green, blue)

	def SetPackedFontColor(self, color):
		wndMgr.SetFontColor(self.hWnd, color)

	def SetText(self, text):
		wndMgr.SetText(self.hWnd, text)

	def GetText(self):
		return wndMgr.GetText(self.hWnd)

	def GetTextSize(self):
		return wndMgr.GetTextSize(self.hWnd)
		
	def GetTextWidth(self):
		w, h = self.GetTextSize()
		return w

	def GetTextHeight(self):
		w, h = self.GetTextSize()
		return h
		
	def AdjustSize(self):
		x, y = self.GetTextSize()
		wndMgr.SetWindowSize(self.hWnd, x, y)

	def GetRight(self):
		return self.GetLeft() + self.GetTextWidth()

	def GetBottom(self):
		return self.GetTop() + self.GetTextHeight()
		
	def SetCenter(self):
		wndMgr.SetWindowPosition(self.hWnd, self.GetLeft() - self.GetTextWidth()/2, self.GetTop())

	def ShowPercentage(self, xStartPct, xEndPct):
		wndMgr.SetRenderingRect(self.hWnd, xStartPct, 0.0, xEndPct, 0.0)
		
	def SetParent(self, parent):		
		wndMgr.SetParent(self.hWnd, parent.hWnd)

class ImageBox(Window):

#Replace or expand with those functions which you will need in the future.

class ImageBox(Window):
	def __init__(self, layer = "UI"):
		Window.__init__(self, layer)

		self.name=""
		self.eventDict={}
		self.argDict={}
		self.argsDict={}

	def __del__(self):
		Window.__del__(self)

	def RegisterWindow(self, layer):
		self.hWnd = wndMgr.RegisterImageBox(self, layer)

	def LoadImage(self, imageName):
		self.name = imageName
		wndMgr.LoadImage(self.hWnd, imageName)

		if len(self.eventDict)!=0:
			print "LOAD IMAGE", self, self.eventDict

	def GetImageName(self):
		return self.name

	def SetAlpha(self, alpha):
		wndMgr.SetDiffuseColor(self.hWnd, 1.0, 1.0, 1.0, alpha)

	def GetWidth(self):
		return wndMgr.GetWidth(self.hWnd)

	def GetHeight(self):
		return wndMgr.GetHeight(self.hWnd)

	def ForceRender(self):
		wndMgr.ImageForceRender(self.hWnd)
		
	def SetMouseOverInEvent(self, func, *args):
		self.eventDict["MOUSE_OVER_IN"]=__mem_func__(func)
		self.argsDict["MOUSE_OVER_IN"]=args

	def SetMouseOverOutEvent(self, func, *args):
		self.eventDict["MOUSE_OVER_OUT"]=__mem_func__(func)
		self.argsDict["MOUSE_OVER_OUT"]=args

	def SetMouseClickEvent(self, event, *args):
		self.eventDict["MOUSE_BUTTON_DOWN"]=__mem_func__(event)
		self.argsDict["MOUSE_BUTTON_DOWN"]=args

	def SetMouseButtonUpEvent(self, event, *args):
		self.eventDict["MOUSE_BUTTON_UP"]=__mem_func__(event)
		self.argsDict["MOUSE_BUTTON_UP"]=args

	def SetMouseRightClickEvent(self, func, *args):
		self.eventDict["MOUSE_RIGHT_BUTTON_DOWN"]=__mem_func__(func)
		self.argsDict["MOUSE_RIGHT_BUTTON_DOWN"]=args

	def SetMouseDoubleClickEvent(self, func, *args):
		self.eventDict["MOUSE_DOUBLE_CLICK_EVENT"]=__mem_func__(func)
		self.argsDict["MOUSE_DOUBLE_CLICK_EVENT"]=args

	def OnMouseOverIn(self):
		try:
			apply(self.eventDict["MOUSE_OVER_IN"], self.argDict["MOUSE_OVER_IN"])
		except KeyError:
			pass

	def OnMouseOverOut(self):
		try:
			apply(self.eventDict["MOUSE_OVER_OUT"], self.argDict["MOUSE_OVER_OUT"])
		except KeyError:
			pass

	def OnMouseLeftButtonUp(self):
		try:
			apply(self.eventDict["MOUSE_LEFT_UP"], self.argDict["MOUSE_LEFT_UP"])
		except KeyError:
			pass

	def OnMouseLeftButtonDown(self):
		try:
			apply(self.eventDict["MOUSE_LEFT_DOWN"], self.argDict["MOUSE_LEFT_DOWN"])
		except KeyError:
			pass


	def OnMouseRightButtonDown(self):
		try:
			if self.eventDict["MOUSE_RIGHT_BUTTON_DOWN"]:
				apply(self.eventDict["MOUSE_RIGHT_BUTTON_DOWN"], self.argsDict["MOUSE_RIGHT_BUTTON_DOWN"])
		except KeyError:
			pass

	def OnMouseLeftButtonDoubleClick(self):
		try:
			if self.eventDict["MOUSE_DOUBLE_CLICK_EVENT"]:
				apply(self.eventDict["MOUSE_DOUBLE_CLICK_EVENT"], self.argsDict["MOUSE_DOUBLE_CLICK_EVENT"])
		except KeyError:
			pass

	def SAFE_SetStringEvent(self, event, func,isa=FALSE):
		if not isa:
			self.eventDict[event]=__mem_func__(func)
		else:
			self.eventDict[event]=func

	def SAFE_SetMouseClickEvent(self, func, *args):
		self.eventDict["MOUSE_LEFT_DOWN"]=__mem_func__(func)
		self.argDict["MOUSE_LEFT_DOWN"]=args

class ExpandedImageBox(ImageBox):

#Replace or expand with those functions which you will need in the future.

class ExpandedImageBox(ImageBox):

	ANIMATION_DIRECTION_RIGHT = 0
	ANIMATION_DIRECTION_LEFT = 1

	def __init__(self, layer = "UI"):
		ImageBox.__init__(self, layer)

		self.isAnimated = False
		self.animationDuration = 0
		self.animationDurationCounter = 0
		self.animationIndex = 0
		self.animationDirection = self.ANIMATION_DIRECTION_RIGHT

		self.baseX = 0
		self.baseY = 0

		self.isScalingOverTime = False
		self.xScaleStart = 0
		self.xScaleEnd = 0
		self.yScaleStart = 0
		self.yScaleEnd = 0
		self.scaleTimeStart = 0
		self.scaleTimeDur = 0

		self.SetWindowName("NONAME_ExpandedImageBox")

	def __del__(self):
		ImageBox.__del__(self)

	def LoadImage(self, imageName):
		ImageBox.LoadImage(self, imageName)

	def RegisterWindow(self, layer):
		self.hWnd = wndMgr.RegisterExpandedImageBox(self, layer)

	def SetAnimationDirectionRight(self):
		self.animationDirection = self.ANIMATION_DIRECTION_RIGHT

	def SetAnimationDirectionLeft(self):
		self.animationDirection = self.ANIMATION_DIRECTION_LEFT

	def SetPosition(self, x, y):
		ImageBox.SetPosition(self, x, y)

		self.baseX = x
		self.baseY = y

	def SetScale(self, xScale, yScale):
		wndMgr.SetScale(self.hWnd, xScale, yScale)

	def SetScaleOverTime(self, xScaleStart, xScaleEnd, yScaleStart, yScaleEnd, time):
		self.isScalingOverTime = True
		self.xScaleStart = xScaleStart
		self.xScaleEnd = xScaleEnd
		self.yScaleStart = yScaleStart
		self.yScaleEnd = yScaleEnd
		self.scaleTimeStart = app.GetTime()
		self.scaleTimeDur = float(time)
		self.SetScale(xScaleStart, yScaleStart)

	def SetOrigin(self, x, y):
		wndMgr.SetOrigin(self.hWnd, x, y)

	def SetRotation(self, rotation):
		wndMgr.SetRotation(self.hWnd, rotation)

	def SetRenderingMode(self, mode):
		wndMgr.SetRenderingMode(self.hWnd, mode)

	def SetRenderingRect(self, left, top, right, bottom):
		wndMgr.SetRenderingRect(self.hWnd, left, top, right, bottom)

	def SetExpandedRenderingRect(self, left_top, left_bottom, top_left, top_right, right_top, right_bottom, bottom_left, bottom_right):
		wndMgr.SetExpandedRenderingRect(self.hWnd, left_top, left_bottom, top_left, top_right, right_top, right_bottom, bottom_left, bottom_right)

	def SetTextureRenderingRect(self, left, top, right, bottom):
		wndMgr.SetTextureRenderingRect(self.hWnd, left, top, right, bottom)

	def GetPixelColor(self, x, y):
		if x < 0 or x >= self.GetWidth() or y < 0 or y >= self.GetHeight():
			return (0, 0, 0, 0)
		r, g, b, a = wndMgr.GetPixelColor(self.hWnd, x, y)
		return (r, g, b, a)

	def LoadFilterImage(self, filterImageName):
		self.filterName=filterImageName

		if len(self.eventDict)!=0:
			print "LOAD FILTER IMAGE", self, self.eventDict

	def SetPercentage(self, curValue, maxValue):
		if maxValue:
			self.SetRenderingRect(0.0, 0.0, -1.0 + float(curValue) / float(maxValue), 0.0)
		else:
			self.SetRenderingRect(0.0, 0.0, 0.0, 0.0)

	def SetVPercentage(self, curValue, maxValue):
		if maxValue:
			self.SetRenderingRect(0.0, -1.0 + float(curValue) / float(maxValue), 0.0, 0.0)
		else:
			self.SetRenderingRect(0.0, 0.0, 0.0, 0.0)

	def IsInRenderingPosition(self, xMouse = -1, yMouse = -1):
		if xMouse == -1 and yMouse == -1:
			xMouse, yMouse = self.GetMouseLocalPosition()
		color = self.GetPixelColor(xMouse, yMouse)

		if color[3] == 0.0:
			return FALSE

		return self.IsInPosition()

	def SetAnimated(self, duration):
		if duration > 0:
			self.isAnimated = True
			self.animationDuration = duration
			self.animationDurationCounter = 0
			self.animationIndex = 0
			self.OnUpdate()
		else:
			self.isAnimated = False

	def OnUpdate(self):
		if self.isAnimated == True:
			aniIndex = self.animationIndex

			self.animationDurationCounter += 1
			if self.animationDurationCounter >= self.animationDuration:
				self.animationDurationCounter = 0

				self.animationIndex += 1
				if self.animationIndex >= self.GetWidth():
					self.animationIndex = 0

			if self.GetWidth() > 0:
				if self.animationDirection == self.ANIMATION_DIRECTION_RIGHT:
					self.SetTextureRenderingRect((float(aniIndex) / float(self.GetWidth())), 0.0, -(float(aniIndex) / float(self.GetWidth())), 0.0)
				else:
					self.SetTextureRenderingRect(-(float(aniIndex) / float(self.GetWidth())), 0.0, (float(aniIndex) / float(self.GetWidth())), 0.0)

		if self.isScalingOverTime:
			perc = (app.GetTime() - self.scaleTimeStart) / float(self.scaleTimeDur)
			if perc >= 1.0:
				self.SetScale(self.xScaleEnd, self.yScaleEnd)
				self.isScalingOverTime = False
			else:
				self.SetScale(self.xScaleStart + (self.xScaleEnd - self.xScaleStart) * perc, self.yScaleStart + (self.yScaleEnd - self.yScaleStart) * perc)
			self.UpdateRect()

class AniImageBox(Window):

#Replace or expand with those functions which you will need in the future.

class AniImageBox(Window):
	def __init__(self, layer = "UI"):
		Window.__init__(self, layer)

		self.nextFrameEvent = None
		self.nextFrameArgs = None
		self.endFrameEvent = None
		self.endFrameArgs = None

		self.SetWindowName("NONAME_AniImageBox")

	def __del__(self):
		Window.__del__(self)

	def RegisterWindow(self, layer):
		self.hWnd = wndMgr.RegisterAniImageBox(self, layer)

	def SetAlpha(self, alpha):
		wndMgr.SetDiffuseColor(self.hWnd, 1.0, 1.0, 1.0, alpha)

	def SetDelay(self, delay):
		wndMgr.SetDelay(self.hWnd, delay)

	def SetSkipCount(self, skip_count):
		wndMgr.SetSkipCount(self.hWnd, skip_count)

	def ResetFrame(self):
		wndMgr.ResetFrame(self.hWnd)

	def GetFrameIndex(self):
		return wndMgr.GetFrameIndex(self.hWnd)

	def AppendImage(self, filename):
		wndMgr.AppendImage(self.hWnd, filename)

	def ClearImages(self):
		wndMgr.ClearImages(self.hWnd)

	def SetPercentage(self, curValue, maxValue):
		if maxValue == 0:
			import dbg
			dbg.TraceError("AniImageBox.SetPercentage(%d, %d) -> invalid max value", curValue, maxValue)
			maxValue = 1
		wndMgr.SetRenderingRect(self.hWnd, 0.0, 0.0, -1.0 + float(curValue) / float(maxValue), 0.0)

	def SetVPercentage(self, curValue, maxValue):
		if maxValue == 0:
			import dbg
			dbg.TraceError("AniImageBox.SetVPercentage(%d, %d) -> invalid max value", curValue, maxValue)
			maxValue = 1
		wndMgr.SetRenderingRect(self.hWnd, 0.0, -1.0 + float(curValue) / float(maxValue), 0.0, 0.0)

	def SAFE_SetNextFrameEvent(self, event, *args):
		self.nextFrameEvent = __mem_func__(event)
		self.nextFrameArgs = args

	def SAFE_SetEndFrameEvent(self, event, *args):
		self.endFrameEvent = __mem_func__(event)
		self.endFrameArgs = args

	def OnNextFrame(self):
		if self.nextFrameEvent:
			apply(self.nextFrameEvent, self.nextFrameArgs)

	def OnEndFrame(self):
		if self.endFrameEvent:
			apply(self.endFrameEvent, self.endFrameArgs)

class Button(Window):

#Replace or expand with those functions which you will need in the future.

class Button(Window):
	def __init__(self, layer = "UI"):
		Window.__init__(self, layer)

		self.eventFunc = None
		self.eventArgs = None

		self.ButtonText = None
		self.ToolTipText = None

	def __del__(self):
		Window.__del__(self)

		self.eventFunc = None
		self.eventArgs = None

	def RegisterWindow(self, layer):
		self.hWnd = wndMgr.RegisterButton(self, layer)

	def SetUpVisual(self, filename):
		wndMgr.SetUpVisual(self.hWnd, filename)

	def SetOverVisual(self, filename):
		wndMgr.SetOverVisual(self.hWnd, filename)

	def SetDownVisual(self, filename):
		wndMgr.SetDownVisual(self.hWnd, filename)

	def SetDisableVisual(self, filename):
		wndMgr.SetDisableVisual(self.hWnd, filename)

	def GetUpVisualFileName(self):
		return wndMgr.GetUpVisualFileName(self.hWnd)

	def GetOverVisualFileName(self):
		return wndMgr.GetOverVisualFileName(self.hWnd)

	def GetDownVisualFileName(self):
		return wndMgr.GetDownVisualFileName(self.hWnd)

	def Flash(self):
		wndMgr.Flash(self.hWnd)

	def Enable(self):
		wndMgr.Enable(self.hWnd)

	def Disable(self):
		wndMgr.Disable(self.hWnd)

	def Down(self):
		wndMgr.Down(self.hWnd)

	def SetUp(self):
		wndMgr.SetUp(self.hWnd)

	def SAFE_SetEvent(self, func, *args):
		self.eventFunc = __mem_func__(func)
		self.eventArgs = args

	def SetEvent(self, func, *args):
		self.eventFunc = func
		self.eventArgs = args

	def SetTextColor(self, color):
		if not self.ButtonText:
			return
		self.ButtonText.SetPackedFontColor(color)

	def SetText(self, text, height = 0):

		if not self.ButtonText:
			textLine = TextLine()
			textLine.SetParent(self)
			textLine.SetPosition(0, self.GetHeight()/2-1)
			textLine.SetVerticalAlignCenter()
			#textLine.SetHorizontalAlignCenter()
			textLine.SetWindowHorizontalAlignCenter()
			textLine.SetHorizontalAlignCenter()
			textLine.SetPackedFontColor(0xffe8b478)
			textLine.Show()
			self.ButtonText = textLine

		self.ButtonText.SetText(text)

	def SetFormToolTipText(self, type, text, x, y):
		if not self.ToolTipText:
			toolTip=createToolTipWindowDict[type]()
			toolTip.SetParent(self)
			toolTip.SetSize(0, 0)
			toolTip.SetHorizontalAlignCenter()
			toolTip.SetOutline()
			toolTip.Hide()
			toolTip.SetPosition(x + self.GetWidth()/2, y)
			self.ToolTipText=toolTip

		self.ToolTipText.SetText(text)

	def SetToolTipWindow(self, toolTip):
		self.ToolTipText=toolTip
		self.ToolTipText.SetParentProxy(self)

	def SetToolTipText(self, text, x=0, y = -19):
		self.SetFormToolTipText("TEXT", text, x, y)

	def CallEvent(self):
		snd.PlaySound("sound/ui/click.wav")

		if self.eventFunc:
			apply(self.eventFunc, self.eventArgs)

	def ShowToolTip(self):
		if self.ToolTipText:
			self.ToolTipText.Show()

	def HideToolTip(self):
		if self.ToolTipText:
			self.ToolTipText.Hide()

	def IsDown(self):
		return wndMgr.IsDown(self.hWnd)

 

 

Have fun with creating cool stuffs in Python! :) 

Edited by Ezrekith
Link to post
Share on other sites
Guest Ezrekith

It's just expanding the ui.py functions for future developing, like if you want to create + things for an ImageBox for example, but without knowledge it's just a bunch of code xD

For example this helped me a lot while i was coding the illumina design.

Edited by Ezrekith
Link to post
Share on other sites
  • 9 months later...
  • 1 year later...
  • 1 month later...
  • 7 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...