class Button(Window):
def __init__(self, layer = "UI"):
Window.__init__(self, layer)
self.eventDict = {}
self.eventFunc = {"mouse_click" : None, "mouse_over_in" : None, "mouse_over_out" : None}
self.eventArgs = {"mouse_click" : None, "mouse_over_in" : None, "mouse_over_out" : None}
self.showtooltipevent = None
self.showtooltiparg = None
self.hidetooltipevent = None
self.hidetooltiparg = None
self.ButtonText = None
self.ToolTipText = None
if app.ENABLE_DETAILS_UI:
self.overFunc = None
self.overArgs = None
self.overOutFunc = None
self.overOutArgs = None
if app.ENABLE_OFFICAL_CHARACTER_SCREEN:
self.TextChild = []
def __del__(self):
Window.__del__(self)
self.eventDict = {}
self.eventFunc = {"mouse_click" : None, "mouse_over_in" : None, "mouse_over_out" : None}
self.eventArgs = {"mouse_click" : None, "mouse_over_in" : None, "mouse_over_out" : None}
self.showtooltipevent = None
self.showtooltiparg = None
self.hidetooltipevent = None
self.hidetooltiparg = None
if app.ENABLE_DETAILS_UI:
self.overFunc = None
self.overArgs = None
self.overOutFunc = None
self.overOutArgs = 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 SetOutline(self, Value=True):
if not self.ButtonText:
return
self.ButtonText.SetOutline(Value)
def SetTextAddPos(self, text, x_add = 0, y_add = 0, height = 4):
if not self.ButtonText:
textLine = TextLine()
textLine.SetParent(self)
textLine.SetPosition(self.GetWidth() / 2 + x_add, self.GetHeight() / 2 + y_add)
textLine.SetVerticalAlignCenter()
textLine.SetHorizontalAlignCenter()
textLine.Show()
self.ButtonText = textLine
self.ButtonText.SetText(text)
def SetText(self, text, height = 4):
if not self.ButtonText:
textLine = TextLine()
textLine.SetParent(self)
textLine.SetPosition(self.GetWidth()/2, self.GetHeight()/2)
textLine.SetVerticalAlignCenter()
textLine.SetHorizontalAlignCenter()
textLine.Show()
self.ButtonText = textLine
self.ButtonText.SetText(text)
def SetText2(self, text, height = 4):
if not self.ButtonText:
textLine = TextLine()
textLine.SetParent(self)
textLine.SetPosition(15, self.GetHeight()/2)
textLine.SetHorizontalAlignCenter()
textLine.Show()
self.ButtonText = textLine
self.ButtonText.SetText(text)
def SetText4(self, text, height = 4):
if not self.ButtonText:
textLine = TextLine()
textLine.SetParent(self)
textLine.SetPosition(self.GetWidth()/2, self.GetHeight()/2)
textLine.SetVerticalAlignCenter()
textLine.SetHorizontalAlignCenter()
textLine.Show()
self.ButtonText = textLine
self.ButtonText.SetText(text)
def SetText3(self, text, height = 4):
if not self.ButtonText:
textLine = TextLine()
textLine.SetParent(self)
textLine.SetPosition(self.GetWidth()/2, self.GetHeight()/2)
textLine.SetVerticalAlignCenter()
textLine.SetHorizontalAlignCenter()
textLine.Hide()
self.ButtonText = textLine
self.ButtonText.SetText(text)
if constInfo.EXTRA_UI_FEATURE:
def GetText(self):
if not self.ButtonText:
return ""
return self.ButtonText.GetText()
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)
if app.ENABLE_ITEM_DELETE_SYSTEM:
def SetToolTipWindow2(self, toolTip):
self.ToolTipText=toolTip
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)
def SetEvent(self, func, *args):
self.eventFunc = func
self.eventArgs = args
def SAFE_SetEvent(self, func, *args):
self.eventFunc = __mem_func__(func)
self.eventArgs = args
def SAFE_SetStringEvent(self, event, func, *args):
self.eventDict[event] =__mem_func__(func)
self.eventArgs[event] = args
def SetMouseOverInEvent(self, func, *args):
self.eventDict["MOUSE_OVER_IN"] = func
self.eventArgs["MOUSE_OVER_IN"] = args
def SetMouseOverOutEvent(self, func, *args):
self.eventDict["MOUSE_OVER_OUT"] = func
self.eventArgs["MOUSE_OVER_OUT"] = args
if app.ENABLE_DETAILS_UI:
def OnMouseOverIn(self):
if self.overFunc:
apply(self.overFunc, self.overArgs)
def OnMouseOverOut(self):
if self.overOutFunc:
apply(self.overOutFunc, self.overOutArgs)
def SetOverEvent(self, func, *args):
self.overFunc = func
self.overArgs = args
def SetOverOutEvent(self, func, *args):
self.overOutFunc = func
self.overOutArgs = args
if app.ENABLE_OFFICAL_CHARACTER_SCREEN:
def AppendTextLineAllClear(self) :
self.TextChild = []
def SetAppendTextChangeText(self, idx, text):
if not len(self.TextChild) :
return
self.TextChild[idx].SetText(text)
def SetAppendTextColor(self, idx, color) :
if not len(self.TextChild) :
return
self.TextChild[idx].SetPackedFontColor(color)
def AppendTextLine(self, text, font_size = localeInfo.UI_DEF_FONT, font_color = grp.GenerateColor(0.7607, 0.7607, 0.7607, 1.0), text_sort = "center", pos_x = None, pos_y = None):
textLine = TextLine()
textLine.SetParent(self)
textLine.SetFontName(font_size)
textLine.SetPackedFontColor(font_color)
textLine.SetText(text)
textLine.Show()
if not pos_x and not pos_y :
textLine.SetPosition(self.GetWidth()/2, self.GetHeight()/2)
else :
textLine.SetPosition(pos_x, pos_y)
textLine.SetVerticalAlignCenter()
if "center" == text_sort :
textLine.SetHorizontalAlignCenter()
elif "right" == text_sort :
textLine.SetHorizontalAlignRight()
elif "left" == text_sort :
textLine.SetHorizontalAlignLeft()
self.TextChild.append(textLine)
if app.ENABLE_QUEST_CATEGORY_SYSTEM or app.ENABLE_SKILL_COLOR_SYSTEM:
def GetText(self):
if not self.ButtonText:
return# ""
return self.ButtonText.GetText()
def SetTextShop(self, text, x = 31, height = 4):
if not self.ButtonText:
textLine = TextLine()
textLine.SetParent(self)
textLine.SetPosition(x, self.GetHeight()/2-1)
textLine.SetVerticalAlignCenter()
textLine.SetHorizontalAlignLeft()
textLine.Show()
self.ButtonText = textLine
self.ButtonText.SetText(text)
self.ButtonText.SetPosition(x, self.GetHeight()/2-1)
self.ButtonText.SetVerticalAlignCenter()
self.ButtonText.SetHorizontalAlignLeft()
def SetTextAlignLeft(self, text, x = 27, height = 4):
if not self.ButtonText:
textLine = TextLine()
textLine.SetParent(self)
textLine.SetPosition(x, self.GetHeight()/2)
textLine.SetVerticalAlignCenter()
textLine.SetHorizontalAlignLeft()
textLine.Show()
self.ButtonText = textLine
self.ButtonText.SetText(text)
self.ButtonText.SetPosition(x, self.GetHeight()/2)
self.ButtonText.SetVerticalAlignCenter()
self.ButtonText.SetHorizontalAlignLeft()
def SetShowToolTipEvent(self, func, *args):
self.showtooltipevent = func
self.showtooltiparg = args
def SetHideToolTipEvent(self, func, *args):
self.hidetooltipevent = func
self.hidetooltiparg = args
if app.ENABLE_SKILL_COLOR_SYSTEM:
def SetListText(self, text, x = 8):
if not self.ButtonText:
textLine = TextLine()
textLine.SetParent(self)
textLine.SetPosition(x, self.GetHeight()/2)
textLine.SetVerticalAlignCenter()
textLine.SetHorizontalAlignLeft()
textLine.Show()
self.ButtonText = textLine
self.ButtonText.SetText(text)
def SAFE_SetEvent(self, func, *args):
self.eventFunc = __mem_func__(func)
self.eventArgs = args
def SAFE_SetStringEvent(self, event, func, *args):
self.eventDict[event] =__mem_func__(func)
self.eventArgs[event] = args
def SetMouseOverInEvent(self, func, *args):
self.eventDict["MOUSE_OVER_IN"] = func
self.eventArgs["MOUSE_OVER_IN"] = args
def SetMouseOverOutEvent(self, func, *args):
self.eventDict["MOUSE_OVER_OUT"] = func
self.eventArgs["MOUSE_OVER_OUT"] = args
def OnMouseLeftButtonUp(self) :
if self.eventFunc["mouse_click"]:
apply(self.eventFunc["mouse_click"], self.eventArgs["mouse_click"])
Window.OnMouseLeftButtonUp(self)
def OnMouseOverIn(self):
if self.eventFunc["mouse_over_in"]:
apply(self.eventFunc["mouse_over_in"], self.eventArgs["mouse_over_in"])
if self.eventDict.has_key("MOUSE_OVER_IN"):
if self.eventArgs["MOUSE_OVER_IN"]:
apply(self.eventDict["MOUSE_OVER_IN"], self.eventArgs["MOUSE_OVER_IN"])
else:
self.eventDict["MOUSE_OVER_IN"]()
def OnMouseOverOut(self):
if self.eventFunc["mouse_over_out"]:
apply(self.eventFunc["mouse_over_out"], self.eventArgs["mouse_over_out"])
if self.eventDict.has_key("MOUSE_OVER_OUT"):
if self.eventArgs["MOUSE_OVER_OUT"]:
apply(self.eventDict["MOUSE_OVER_OUT"], self.eventArgs["MOUSE_OVER_OUT"])
else:
self.eventDict["MOUSE_OVER_OUT"]()