Guest User

Untitled

a guest
Feb 21st, 2021
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.86 KB | None | 0 0
  1. import ServerStateChecker
  2. import serverInfo
  3. import constInfo
  4.  
  5. import net
  6. import app
  7. import ui
  8. import uiOption
  9. import networkModule
  10. import localeInfo
  11.  
  12. class SwitchChannelDialog(ui.ScriptWindow):
  13.     def __init__(self):
  14.         ui.ScriptWindow.__init__(self)
  15.         self.channelButtons = []
  16.  
  17.         self.serverID = None
  18.         self.channel = 0
  19.         self.regionID = None
  20.        
  21.         self.__LoadWindow()
  22.         self.Open()    
  23.  
  24.     def __del__(self):
  25.         ui.ScriptWindow.__del__(self)
  26.         print " -------------------------------------- DELETE SWITCH CHANNEL DIALOG"
  27.  
  28.     def Destroy(self):
  29.         self.Hide()
  30.         self.ClearDictionary()
  31.         print " -------------------------------------- DESTROY SWITCH CHANNEL DIALOG"  
  32.  
  33.     def OnUpdate(self):
  34.         ServerStateChecker.Update()
  35.  
  36.     def __LoadWindow(self):
  37.         pyScrLoader = ui.PythonScriptLoader()
  38.         try:
  39.             pyScrLoader.LoadScriptFile(self, "uiscript/SwitchChannelDialog.py")
  40.         except:
  41.             import exception
  42.             exception.Abort("SwitchChannelDialog.__LoadDialog.LoadObject")
  43.  
  44.         file = open("channel.inf", "r")
  45.         lines = file.readlines()
  46.         file.close()
  47.        
  48.         if len(lines):
  49.             tokens = lines[0].split()
  50.             self.serverID = int(tokens[0])
  51.             self.channel = int(tokens[1])
  52.             if len(tokens) == 3:
  53.                 self.regionID = int(tokens[2])
  54.             else:
  55.                 self.regionID = 0
  56.  
  57.     def Open(self):
  58.         try:
  59.             GetObject=self.GetChild
  60.             self.switchChannelBoard = GetObject("SwitchChannelBoard")
  61.             self.blackBoard = GetObject("BlackBoard")
  62.  
  63.             self.GetChild("SwitchChannelTitle").SetCloseEvent(ui.__mem_func__(self.Close))
  64.  
  65.             for ch in range(constInfo.CHANNELS):
  66.                 btn = ui.Button()
  67.                 btn.SetUpVisual("d:/ymir work/ui/public/select_btn_01.sub")
  68.                 btn.SetOverVisual("d:/ymir work/ui/public/select_btn_02.sub")
  69.                 btn.SetDownVisual("d:/ymir work/ui/public/select_btn_03.sub")
  70.                 btn.SetText("Channel %d" % (int(ch)+1))
  71.                 btn.SetParent(self.blackBoard)
  72.                 btn.SetPosition(6, 6 + (28 * (ch)))
  73.                 btn.SetEvent(ui.__mem_func__(self.__SelectChannel), ch)
  74.  
  75.                 self.channelButtons.append(btn)
  76.                 self.channelButtons[ch].Show()         
  77.  
  78.             self.closeButton = ui.Button()
  79.             self.closeButton.SetUpVisual("d:/ymir work/ui/public/large_button_01.sub")
  80.             self.closeButton.SetOverVisual("d:/ymir work/ui/public/large_button_02.sub")
  81.             self.closeButton.SetDownVisual("d:/ymir work/ui/public/large_button_03.sub")
  82.             self.closeButton.SetParent(self.switchChannelBoard)
  83.             self.closeButton.SetPosition(114/2-6, 22 + (28 * (len(self.channelButtons) + 1)))
  84.             self.closeButton.SetText(localeInfo.SWITCHCHANNEL_CANCEL)
  85.             self.closeButton.SAFE_SetEvent(self.Close)
  86.             self.closeButton.Show()    
  87.  
  88.             self.SetSize(190, len(self.channelButtons)* 28 + 74 + 9)   
  89.             self.switchChannelBoard.SetSize(190, len(self.channelButtons) * 28 + 74 + 9)   
  90.             self.blackBoard.SetSize(161, len(self.channelButtons) * 28 + 8)            
  91.         except:
  92.             import exception
  93.             exception.Abort("SwitchChannelDialog.Open.BindObject")
  94.  
  95.         ui.ScriptWindow.Show(self)
  96.                
  97.                
  98.     def __SelectChannel(self, channel):
  99.         ServerStateChecker.Update()
  100.        
  101.         new_ch = int(channel)+1
  102.         state = serverInfo.REGION_DICT[self.regionID][self.serverID]["channel"][new_ch]["state"]
  103.         if state == serverInfo.STATE_NONE:
  104.             self.Popup = ui.ChannelSwitcherUI().Popup(localeInfo.SWITCHCHANNEL_CLOSED)
  105.             return
  106.         elif state == serverInfo.STATE_DICT[3]:
  107.             self.Popup = ui.ChannelSwitcherUI().Popup(localeInfo.SWITCHCHANNEL_FULL)
  108.             return
  109.         elif self.channel == new_ch:
  110.             self.Popup = ui.ChannelSwitcherUI().Popup(localeInfo.SWITCHCHANNEL_SAME)
  111.             return
  112.            
  113.         file=open("channel.inf", "w")
  114.         file.write("%d %d %d" % (self.serverID, new_ch, self.regionID))
  115.         file.close()
  116.        
  117.         self.Close()
  118.         net.SendChatPacket("/ch %d" % new_ch)
  119.  
  120.     def Close(self):
  121.         self.Hide()
  122.         print "close"
  123.         return True
  124.            
  125.     def Show(self):
  126.         ui.ScriptWindow.Show(self)
  127.  
  128.         self.SetCenterPosition()
  129.            
  130.     def OnPressEscapeKey(self):
  131.         self.Close()
  132.         return True
  133.    
  134.    
  135.  
  136.            
  137.  
Advertisement
Add Comment
Please, Sign In to add comment