1. import ui
  2. import net
  3. import app
  4. import chat
  5. import math
  6. import wndMgr
  7. import localeInfo
  8. import serverInfo
  9. import background
  10. import ServerStateChecker
  11. class ChannelChanger(ui.ScriptWindow):
  12. def __init__(self):
  13. ui.ScriptWindow.__init__(self)
  14. self.__MakeWindow()
  15. self.__MakeBoard()
  16. self.__Fill_Up_ChannelList()
  17. def __del__(self):
  18. ui.ScriptWindow.__del__(self)
  19. def Destroy(self):
  20. self.Hide()
  21. return TRUE
  22. def __MakeWindow(self):
  23. ServerStateChecker.Create(self)
  24. self.SetSize(150, 195)
  25. self.SetPosition((wndMgr.GetScreenWidth() / 2) - int(math.floor(self.GetWidth() / 2.)), (wndMgr.GetScreenHeight() / 2) - int(math.floor(self.GetHeight() / 2.)))
  26. self.AddFlag("float")
  27. self.Show()
  28. def __MakeBoard(self):
  29. self.Board = ui.Board()
  30. self.Board.SetParent(self)
  31. self.Board.SetSize(self.GetWidth(), self.GetHeight())
  32. self.Board.SetPosition(0, 0)
  33. self.Board.AddFlag("float")
  34. self.Board.Show()
  35. self.TitleBar = ui.TitleBar()
  36. self.TitleBar.SetParent(self.Board)
  37. self.TitleBar.SetPosition(7, 7)
  38. self.TitleBar.MakeTitleBar(self.GetWidth() - 2 * 7, "red")
  39. self.TitleBar.SetCloseEvent(self.Close)
  40. self.TitleBar.Show()
  41. self.TitleText = ui.TextLine()
  42. self.TitleText.SetParent(self.TitleBar)
  43. self.TitleText.SetPosition(0, 4)
  44. self.TitleText.SetText(localeInfo.UI_CHANNEL_CHOOSE)
  45. self.TitleText.SetWindowHorizontalAlignCenter()
  46. self.TitleText.SetHorizontalAlignCenter()
  47. self.TitleText.Show()
  48. self.RefreshButton = ui.Button()
  49. self.RefreshButton.SetParent(self.Board)
  50. self.RefreshButton.SetPosition(self.Board.GetWidth() / 2 - 8, self.TitleBar.GetHeight() + 9)
  51. self.RefreshButton.SetUpVisual("d:/ymir work/ui/game/guild/refresh_button_01.sub")
  52. self.RefreshButton.SetOverVisual("d:/ymir work/ui/game/guild/refresh_button_02.sub")
  53. self.RefreshButton.SetDownVisual("d:/ymir work/ui/game/guild/refresh_button_03.sub")
  54. self.RefreshButton.SetToolTipText(localeInfo.UI_CHANNEL_REFRESH, 0, - 23)
  55. self.RefreshButton.SetEvent(lambda : self.__Fill_Up_ChannelList())
  56. self.RefreshButton.Show()
  57. self.ChannelListBase = ui.SlotBar()
  58. self.ChannelListBase.SetParent(self.Board)
  59. self.ChannelListBase.SetSize(self.Board.GetWidth() - 2 * 16, 5 * 18 - 4)
  60. self.ChannelListBase.SetPosition(16 , 7 + self.TitleBar.GetHeight() + 6 + 10 + 6)
  61. self.ChannelListBase.Show()
  62. self.ChannelList = ui.ListBox()
  63. self.ChannelList.SetParent(self.ChannelListBase)
  64. self.ChannelList.SetSize(self.ChannelListBase.GetWidth()- 20, self.ChannelListBase.GetHeight())
  65. self.ChannelList.SetPosition(0, 0)
  66. self.ChannelList.SetEvent(ui.__mem_func__(self.__OnSelectChannel))
  67. self.ChannelList.Show()
  68. self.ChangeButton = ui.Button()
  69. self.ChangeButton.SetParent(self.Board)
  70. self.ChangeButton.SetPosition(self.Board.GetWidth() / 2 - 44, self.Board.GetHeight() - 52)
  71. self.ChangeButton.SetUpVisual("d:/ymir work/ui/public/Large_button_01.sub")
  72. self.ChangeButton.SetOverVisual("d:/ymir work/ui/public/Large_button_02.sub")
  73. self.ChangeButton.SetDownVisual("d:/ymir work/ui/public/Large_button_03.sub")
  74. self.ChangeButton.SetEvent(lambda : self.__OnClickConnectButton())
  75. self.ChangeButton.SetText(localeInfo.UI_CHANNEL_GO)
  76. self.ChangeButton.Show()
  77. self.ClsButton = ui.Button()
  78. self.ClsButton.SetParent(self.Board)
  79. self.ClsButton.SetPosition(self.Board.GetWidth() / 2 - 44, self.Board.GetHeight() - 29)
  80. self.ClsButton.SetUpVisual("d:/ymir work/ui/public/Large_button_01.sub")
  81. self.ClsButton.SetOverVisual("d:/ymir work/ui/public/Large_button_02.sub")
  82. self.ClsButton.SetDownVisual("d:/ymir work/ui/public/Large_button_03.sub")
  83. self.ClsButton.SetEvent(lambda : self.Close())
  84. self.ClsButton.SetText(localeInfo.UI_CHANNEL_CLOSE)
  85. self.ClsButton.ButtonText.SetFontColor(1, 1, 1)
  86. self.ClsButton.Show()
  87. self.DisableChangeButton()
  88. self.ChannelListScrollBar = ui.ScrollBar()
  89. self.ChannelListScrollBar.SetParent(self.ChannelListBase)
  90. self.ChannelListScrollBar.SetPosition(18, 3)
  91. self.ChannelListScrollBar.SetScrollBarSize(83)
  92. self.ChannelListScrollBar.SetWindowHorizontalAlignRight()
  93. self.ChannelListScrollBar.SetScrollEvent(ui.__mem_func__(self.__OnScrollChannelList))
  94. self.ChannelListScrollBar.Show()
  95. def DisableChangeButton(self):
  96. self.ChangeButton.Disable()
  97. self.ChangeButton.Down()
  98. self.ChangeButton.ButtonText.SetFontColor(0.4, 0.4, 0.4)
  99. def EnableChangeButton(self):
  100. self.ChangeButton.Enable()
  101. self.ChangeButton.SetUp()
  102. self.ChangeButton.ButtonText.SetFontColor(1, 1, 1)
  103. def __GetRegionID(self):
  104. return 0
  105. def __GetServerID(self):
  106. regionID = self.__GetRegionID()
  107. serverID = 0
  108. for i in serverInfo.REGION_DICT[regionID].keys():
  109. if serverInfo.REGION_DICT[regionID][i]["name"] == net.GetServerInfo().split(",")[0]:
  110. serverID = int(i)
  111. break
  112. return serverID
  113. def __Fill_Up_ChannelList(self):
  114. self.__RequestServerStateList()
  115. self.__RefreshServerStateList()
  116. def __RequestServerStateList(self):
  117. regionID = self.__GetRegionID()
  118. serverID = self.__GetServerID()
  119. try:
  120. channelDict = serverInfo.REGION_DICT[regionID][serverID]["channel"]
  121. except:
  122. return
  123. ServerStateChecker.Initialize(self)
  124. for id, channelDataDict in channelDict.items():
  125. key = channelDataDict["key"]
  126. ip = channelDataDict["ip"]
  127. udp_port = channelDataDict["udp_port"]
  128. ServerStateChecker.AddChannel(key, ip, udp_port)
  129. ServerStateChecker.Request()
  130. def __RefreshServerStateList(self):
  131. regionID = self.__GetRegionID()
  132. serverID = self.__GetServerID()
  133. bakChannelID = self.ChannelList.GetSelectedItem()
  134. self.ChannelList.ClearItem()
  135. try:
  136. channelDict = serverInfo.REGION_DICT[regionID][serverID]["channel"]
  137. except:
  138. return
  139. for channelID, channelDataDict in channelDict.items():
  140. channelName = channelDataDict["name"]
  141. channelState = channelDataDict["state"]
  142. self.ChannelList.InsertItem(channelID, "%s %s" % (channelName, channelState))
  143. self.ChannelList.SelectItem(bakChannelID-1)
  144. def NotifyChannelState(self, addrKey, state):
  145. try:
  146. stateName = serverInfo.STATE_DICT[state]
  147. except:
  148. stateName = serverInfo.STATE_NONE
  149. regionID = int(addrKey / 1000)
  150. serverID = int(addrKey / 10) % 100
  151. channelID = addrKey % 10
  152. try:
  153. serverInfo.REGION_DICT[regionID][serverID]["channel"][channelID]["state"] = stateName
  154. self.__RefreshChannelStateList()
  155. except:
  156. pass
  157. def __OnSelectChannel(self):
  158. if self.ChangeButton.IsDown():
  159. self.EnableChangeButton()
  160. def __OnScrollChannelList(self):
  161. viewItemCount = self.ChannelList.GetViewItemCount()
  162. itemCount = self.ChannelList.GetItemCount()
  163. pos = self.ChannelListScrollBar.GetPos() * (itemCount - viewItemCount)
  164. self.ChannelList.SetBasePos(int(pos))
  165. def __OnClickConnectButton(self):
  166. ServerStateChecker.Update()
  167. channelID = self.ChannelList.GetSelectedItem()
  168. if not channelID:
  169. return
  170. if net.GetServerInfo().strip().split(", ")[1] == self.ChannelList.textDict[self.ChannelList.selectedLine].strip().split(" ")[0]:
  171. chat.AppendChat(1, localeInfo.UI_CHANNEL_YET_ON_THIS_CH)
  172. return
  173. self.Close()
  174. net.SendChatPacket("/channel "+ str(channelID))
  175. def DirectConnect(self, ChannelIP, ChannelPort, AuthServerIP, AuthServerPort):
  176. net.SetLoginInfo(decode_string(net.ACCOUNT_ID), decode_string(net.ACCOUNT_PW))
  177. net.ConnectToAccountServer(ChannelIP, ChannelPort, AuthServerIP, AuthServerPort)
  178. net.DirectEnter(0)
  179. net.SendSelectCharacterPacket(0)
  180. net.SendEnterGamePacket()
  181. def Show(self):
  182. ui.ScriptWindow.Show(self)
  183. def Close(self):
  184. ServerStateChecker.Initialize(self)
  185. self.Hide()
  186. def OnPressEscapeKey(self):
  187. self.Close()
  188. return TRUE
  189. def OnUpdate(self):
  190. ServerStateChecker.Update()

uiChannel.py