Facebook
From Mehmet, 4 Years ago, written in Python.
Embed
Download Paste or View Raw
Hits: 129
  1. import ui
  2. import wndMgr
  3. import os as _server
  4. import player as p
  5. import net as server
  6. import uiCommon as message
  7. import localeInfo as translate
  8.  
  9. Y_PASS_ELEMENTS = 65
  10.  
  11. GET_LOCALIZATION_IMG = {
  12.         0       : "d:/ymir work/ui/public/parameter_slot_06.sub",
  13.         1       : "d:/ymir work/ui/game/localization_btn/btn_edit_01.tga",
  14.         2       : "d:/ymir work/ui/game/localization_btn/btn_edit_02.tga",
  15.         3       : "d:/ymir work/ui/game/localization_btn/btn_edit_03.tga",
  16.         4       : "d:/ymir work/ui/public/Large_Button_01.sub",
  17.         5       : "d:/ymir work/ui/public/Large_Button_02.sub",
  18.         6       : "d:/ymir work/ui/public/Large_Button_03.sub"
  19. }
  20.  
  21. class Initializate(ui.ScriptWindow):
  22.         def __init__(self):    
  23.                 ui.ScriptWindow.__init__(self)
  24.                 self.LoadWindowLocalization()
  25.  
  26.         def __del__(self):
  27.                 ui.ScriptWindow.__del__(self)
  28.  
  29.         def EditLocalizationBtn(self, parent, buttonName, tooltipText, x, y, func, UpVisual, OverVisual, DownVisual):
  30.                 btn = ui.Button()
  31.                 if parent != None:
  32.                         btn.SetParent(parent)
  33.                 btn.SetPosition(x, y)
  34.                 btn.SetUpVisual(UpVisual)
  35.                 btn.SetOverVisual(OverVisual)
  36.                 btn.SetDownVisual(DownVisual)
  37.                 btn.SetText(buttonName)
  38.                 btn.SetToolTipText(tooltipText)
  39.                 btn.Show()
  40.                 btn.SetEvent(func)
  41.                 return btn
  42.  
  43.         def LoadWindowLocalization(self):
  44.                 pyScrLoader = ui.PythonScriptLoader()
  45.                 pyScrLoader.LoadScriptFile(self, "uiscript/script_localization.py")
  46.                 getObject = self.GetChild
  47.  
  48.                 self.Board = getObject("board")
  49.                 self.Board.SetSize(450, 60 + (7 * 40))
  50.                 self.Board.SetTitleName(translate.LOCALIZATION_TITLE)
  51.                 self.Board.SetCloseEvent(self.Close)
  52.  
  53.                 self.btnEdit = {}
  54.                 idx = 1
  55.                 posY = 1 + Y_PASS_ELEMENTS
  56.                 while idx <= 7:
  57.                         self.btnEdit[idx] = self.EditLocalizationBtn(self.Board, "", translate.LOCALIZATION_DESC_BTN_EDIT, 233, posY-3, (lambda arg1 = "%d" % (idx-1), boolSave = "%d" % (999): self.RenameLocation(int(arg1), int(boolSave))), GET_LOCALIZATION_IMG[1], GET_LOCALIZATION_IMG[2], GET_LOCALIZATION_IMG[3])
  58.                         idx = idx + 1
  59.                         posY = posY + 40
  60.  
  61.                 self.tmpBtn = []
  62.                 self.tmpFieldLocation = []
  63.                 self.tmpFieldPosition = []
  64.  
  65.                 for tmp in xrange(0, 7):
  66.                         btn = ui.Button()
  67.                         btn.SetParent(self.Board)
  68.                         btn.SetPosition(10, Y_PASS_ELEMENTS + (tmp * 40))
  69.                         btn.SetUpVisual(GET_LOCALIZATION_IMG[0])
  70.                         btn.SetOverVisual(GET_LOCALIZATION_IMG[0])
  71.                         btn.SetDownVisual(GET_LOCALIZATION_IMG[0])
  72.                         btn.Show()
  73.  
  74.                         textLine_Location = ui.EditLine()
  75.                         textLine_Location.SetParent(btn)
  76.                         textLine_Location.SetPosition(1, 1)
  77.                         textLine_Location.SetText("")
  78.                         textLine_Location.Disable()
  79.                         textLine_Location.Show()
  80.  
  81.                         textLine_Position = ui.EditLine()
  82.                         textLine_Position.SetParent(btn)
  83.                         textLine_Position.SetPosition(166, 1)
  84.                         textLine_Position.SetText("(x, y)")
  85.                         textLine_Position.Disable()
  86.                         textLine_Position.Show()
  87.  
  88.                         self.tmpBtn.append(btn)
  89.                         self.tmpFieldLocation.append(textLine_Location)
  90.                         self.tmpFieldPosition.append(textLine_Position)
  91.  
  92.                         btn = ui.Button()
  93.                         btn.SetParent(self.Board)
  94.                         btn.SetPosition(263, Y_PASS_ELEMENTS + (tmp * 40))
  95.                         btn.SetUpVisual(GET_LOCALIZATION_IMG[4])
  96.                         btn.SetOverVisual(GET_LOCALIZATION_IMG[5])
  97.                         btn.SetDownVisual(GET_LOCALIZATION_IMG[6])
  98.                         btn.SetEvent(lambda ch = "/localization teleport %d" % (tmp): server.SendChatPacket(ch))
  99.                         btn.SetText(translate.LOCALIZATION_TELEPORT)
  100.                         btn.Show()
  101.  
  102.                         self.tmpBtn.append(btn)
  103.  
  104.                         btn = ui.Button()
  105.                         btn.SetParent(self.Board)
  106.                         btn.SetPosition(353, Y_PASS_ELEMENTS + (tmp*40))
  107.                         btn.SetUpVisual(GET_LOCALIZATION_IMG[4])
  108.                         btn.SetOverVisual(GET_LOCALIZATION_IMG[5])
  109.                         btn.SetDownVisual(GET_LOCALIZATION_IMG[6])
  110.                         btn.SetEvent(lambda arg = "%d" % (tmp), boolSave = "%d" % (tmp): self.RenameLocation(int(arg), int(boolSave)))
  111.                         btn.SetText(translate.LOCALIZATION_SAVE)
  112.                         btn.Show()
  113.  
  114.                         self.tmpBtn.append(btn)
  115.  
  116.         def Close(self):
  117.                 self.Hide()
  118.                 for rmf in xrange(1, 8):
  119.                         self.btnEdit[rmf].Hide()
  120.  
  121.         def Show(self):
  122.                 wndMgr.Show(self.hWnd)
  123.                 self.Board.Show()
  124.  
  125.         def Destroy(self):
  126.                 self.Hide()
  127.                 self.tmpFieldLocation = []
  128.                 self.tmpFieldPosition = []
  129.                 self.tmpBtn = []
  130.  
  131.         def OnPressEscapeKey(self):
  132.                 self.Close()
  133.  
  134.         def Append(self, arg):
  135.                 myPathFile = "lib//localization//save_localization__%s.txt" % str(p.GetName())
  136.                 myPathCreate = "lib//localization"
  137.  
  138.                 if not _server.path.exists("lib"):
  139.                         _server.mkdir("lib")
  140.  
  141.                 if not _server.path.exists(myPathCreate):
  142.                         _server.mkdir(myPathCreate)
  143.  
  144.                 if not _server.path.exists(myPathFile):
  145.                         tmpCreateFile = open(myPathFile, 'w')
  146.                         tmpCreateFile.write('-\n-\n-\n-\n-\n-\n-\n')
  147.                         tmpCreateFile.close()
  148.  
  149.                 for idx in xrange(0, 7):
  150.                         lines = pack_open(myPathFile, "r").readlines()
  151.                         result = lines[idx]
  152.                         self.tmpFieldLocation[idx].SetText(result)     
  153.  
  154.                 self.tmpFieldPosition[0].SetText("(%s, %s)" % (str(arg[1]), str(arg[2])))
  155.                 self.tmpFieldPosition[1].SetText("(%s, %s)" % (str(arg[3]), str(arg[4])))
  156.                 self.tmpFieldPosition[2].SetText("(%s, %s)" % (str(arg[5]), str(arg[6])))
  157.                 self.tmpFieldPosition[3].SetText("(%s, %s)" % (str(arg[7]), str(arg[8])))
  158.                 self.tmpFieldPosition[4].SetText("(%s, %s)" % (str(arg[9]), str(arg[10])))
  159.                 self.tmpFieldPosition[5].SetText("(%s, %s)" % (str(arg[11]), str(arg[12])))
  160.                 self.tmpFieldPosition[6].SetText("(%s, %s)" % (str(arg[13]), str(arg[14])))
  161.  
  162.                 for i in xrange(1, 8):
  163.                         self.btnEdit[i].Show()
  164.  
  165.                 if int(arg[0]) < 1:
  166.                         wndMgr.Show(self.hWnd)
  167.                         self.Board.Show()
  168.  
  169.         def CloseDialog(self):
  170.                 self.inputDialog.Hide()
  171.  
  172.         def RenameLocation(self, tmpIndex, boolSave):
  173.                 myPathFile = "lib//localization//save_localization__%s.txt" % str(p.GetName())
  174.  
  175.                 for mex in range(tmpIndex + 1):
  176.                         lines = pack_open(myPathFile, "r").readlines()
  177.                         result = lines[mex]
  178.  
  179.                 self.inputDialog = message.EditLineLocalization()
  180.                 self.inputDialog.SetMaxLength(35)
  181.  
  182.                 if int(boolSave) == 999:
  183.                         self.inputDialog.SetAcceptEvent(lambda arg = "%d" % (tmpIndex), boolSave = "%d" % (tmpIndex): self.Get(int(arg), int(999)))
  184.                 else:
  185.                         self.inputDialog.SetAcceptEvent(lambda arg = "%d" % (tmpIndex), boolSave = "%d" % (tmpIndex): self.Get(int(arg), int(boolSave)))
  186.  
  187.                 self.inputDialog.SetCancelEvent(ui.__mem_func__(self.CloseDialog))
  188.                 self.inputDialog.SetAcceptText(translate.LOCALIZATION_EDIT)
  189.                 self.inputDialog.SetCancelText(translate.LOCALIZATION_CANCEL)
  190.                 self.inputDialog.SetTitle(translate.LOCALIZATION_CHANGE_NAME)
  191.                 self.inputDialog.SetDescription(translate.LOCALIZATION_CURRENT_LINE + " " + str(result))
  192.                 self.inputDialog.Open()
  193.  
  194.         def Get(self, tmpIndex, boolSave):
  195.                 myPathFile = "lib//localization//save_localization__%s.txt" % str(p.GetName())
  196.  
  197.                 textLine = self.inputDialog.GetText()
  198.                 saveLocationArray = []
  199.  
  200.                 if _server.path.exists(myPathFile):
  201.                         tmpFile = open(myPathFile, "r")
  202.  
  203.                         for mLine in tmpFile:
  204.                                 saveLocationArray.append(mLine)
  205.                         tmpFile.close()
  206.  
  207.                 while len(saveLocationArray) < int(tmpIndex+1):
  208.                         saveLocationArray.append("")
  209.  
  210.                 saveLocationArray[int(tmpIndex + 1)-1] = str(textLine)
  211.                 tmpFile = open(myPathFile, "w")
  212.  
  213.                 for mLine in saveLocationArray:
  214.                         tmpFile.write(mLine)
  215.  
  216.                         if (len(mLine) > 0 and mLine[-1:] != "\n") or len(mLine) == 0:
  217.                                 tmpFile.write("\n")
  218.                 tmpFile.close()
  219.  
  220.                 if int(boolSave) != 999:
  221.                         server.SendChatPacket("/localization save %d" % (int(boolSave)))
  222.                         server.SendChatPacket("/localization refresh")
  223.  
  224.                 self.CloseDialog()
  225.                 self.RefreshCurrentLine()
  226.  
  227.         def RefreshCurrentLine(self):
  228.                 myPathFile = "lib//localization//save_localization__%s.txt" % str(p.GetName())
  229.  
  230.                 for ret in xrange(0, 7):
  231.                         lines = pack_open(myPathFile, "r").readlines()
  232.                         result = lines[ret]
  233.                         self.tmpFieldLocation[ret].SetText(result)
  234.