Guest User

Untitled

a guest
Apr 15th, 2020
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. import wndMgr
  2. import ui
  3. import ime
  4. import localeInfo
  5. import constInfo
  6.  
  7.  
  8. class PickMoneyDialog(ui.ScriptWindow):
  9. def __init__(self):
  10. ui.ScriptWindow.__init__(self)
  11.  
  12. self.unitValue = 1
  13. self.maxValue = 0
  14. self.eventAccept = 0
  15.  
  16. def __del__(self):
  17. ui.ScriptWindow.__del__(self)
  18.  
  19. def LoadDialog(self):
  20. try:
  21. pyScrLoader = ui.PythonScriptLoader()
  22. pyScrLoader.LoadScriptFile(self, "UIScript/PickMoneyDialog.py")
  23. except:
  24. import exception
  25. exception.Abort("MoneyDialog.LoadDialog.LoadScript")
  26.  
  27. try:
  28. self.board = self.GetChild("board")
  29. self.maxValueTextLine = self.GetChild("max_value")
  30. self.pickValueEditLine = self.GetChild("money_value")
  31. self.acceptButton = self.GetChild("accept_button")
  32. self.cancelButton = self.GetChild("cancel_button")
  33. except:
  34. import exception
  35. exception.Abort("MoneyDialog.LoadDialog.BindObject")
  36.  
  37. self.pickValueEditLine.SetReturnEvent(ui.__mem_func__(self.OnAccept))
  38. self.pickValueEditLine.SetEscapeEvent(ui.__mem_func__(self.Close))
  39. self.acceptButton.SetEvent(ui.__mem_func__(self.OnAccept))
  40. self.cancelButton.SetEvent(ui.__mem_func__(self.Close))
  41. self.board.SetCloseEvent(ui.__mem_func__(self.Close))
  42.  
  43. def Destroy(self):
  44. self.ClearDictionary()
  45. self.eventAccept = 0
  46. self.maxValue = 0
  47. self.pickValueEditLine = 0
  48. self.acceptButton = 0
  49. self.cancelButton = 0
  50. self.board = None
  51.  
  52. def SetTitleName(self, text):
  53. self.board.SetTitleName(text)
  54.  
  55. def SetAcceptEvent(self, event):
  56. self.eventAccept = event
  57.  
  58. def SetMax(self, max):
  59. self.pickValueEditLine.SetMax(max)
  60.  
  61. def Open(self, maxValue, unitValue=1):
  62.  
  63. if localeInfo.IsYMIR() or localeInfo.IsCHEONMA() or localeInfo.IsHONGKONG():
  64. unitValue = ""
  65.  
  66. width = self.GetWidth()
  67. (mouseX, mouseY) = wndMgr.GetMousePosition()
  68.  
  69. if mouseX + width/2 > wndMgr.GetScreenWidth():
  70. xPos = wndMgr.GetScreenWidth() - width
  71. elif mouseX - width/2 < 0:
  72. xPos = 0
  73. else:
  74. xPos = mouseX - width/2
  75.  
  76. self.SetPosition(xPos, mouseY - self.GetHeight() - 20)
  77.  
  78. if localeInfo.IsARABIC():
  79. self.maxValueTextLine.SetText("/" + str(maxValue))
  80. else:
  81. self.maxValueTextLine.SetText(" / " + str(maxValue))
  82.  
  83. self.pickValueEditLine.SetText(str(unitValue))
  84. self.pickValueEditLine.SetFocus()
  85.  
  86. ime.SetCursorPosition(1)
  87.  
  88. self.unitValue = unitValue
  89. self.maxValue = maxValue
  90. self.Show()
  91. self.SetTop()
  92.  
  93. def Close(self):
  94. self.pickValueEditLine.KillFocus()
  95. self.Hide()
  96.  
  97. def OnAccept(self):
  98. money_text = self.pickValueEditLine.GetText()
  99. if constInfo.USE_KMB_MONEY_FORMAT:
  100. if money_text:
  101. moneyValue = min(constInfo.__ConvertMoneyText(text), self.maxValue)
  102. if moneyValue:
  103. if self.eventAccept:
  104. self.eventAccept(moneyValue)
  105.  
  106. text = self.pickValueEditLine.GetText()
  107. if constInfo.USE_KMB_MONEY_FORMAT:
  108. if text:
  109. moneyValue = min(constInfo.__ConvertMoneyText(text), self.maxValue)
  110. if moneyValue:
  111. if self.eventAccept:
  112. self.eventAccept(moneyValue)
  113. if len(text) > 0 and text.isdigit():
  114.  
  115. money = long(text)
  116. money = min(money, self.maxValue)
  117.  
  118. if money > 0:
  119. if self.eventAccept:
  120. self.eventAccept(money)
  121.  
  122. self.Close()
Advertisement
Add Comment
Please, Sign In to add comment