Advertisement
Guest User

uiexchange.py

a guest
Apr 21st, 2019
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 15.02 KB | None | 0 0
  1. import player
  2. import exchange
  3. import net
  4. import localeInfo
  5. import chat
  6. import item
  7.  
  8. import ui
  9. import mouseModule
  10. import uiPickMoney
  11. import wndMgr
  12. import app
  13.  
  14. if app.ENABLE_NEW_EXCHANGE_WINDOW:
  15.     import playerSettingModule
  16.     import uiCommon
  17.     import time
  18.  
  19. ###################################################################################################
  20. ## Exchange
  21. class ExchangeDialog(ui.ScriptWindow):
  22.  
  23.     if app.ENABLE_NEW_EXCHANGE_WINDOW:
  24.         FACE_IMAGE_DICT = {
  25.                             playerSettingModule.RACE_WARRIOR_M : "d:/ymir work/bin/icon/face/warrior_m.tga",
  26.                             playerSettingModule.RACE_WARRIOR_W : "d:/ymir work/bin/icon/face/warrior_w.tga",
  27.                             playerSettingModule.RACE_ASSASSIN_M : "d:/ymir work/bin/icon/face/assassin_m.tga",
  28.                             playerSettingModule.RACE_ASSASSIN_W : "d:/ymir work/bin/icon/face/assassin_w.tga",
  29.                             playerSettingModule.RACE_SURA_M : "d:/ymir work/bin/icon/face/sura_m.tga",
  30.                             playerSettingModule.RACE_SURA_W : "d:/ymir work/bin/icon/face/sura_w.tga",
  31.                             playerSettingModule.RACE_SHAMAN_M : "d:/ymir work/bin/icon/face/shaman_m.tga",
  32.                             playerSettingModule.RACE_SHAMAN_W : "d:/ymir work/bin/icon/face/shaman_w.tga",
  33.         }
  34.         if app.ENABLE_WOLFMAN_CHARACTER:
  35.             FACE_IMAGE_DICT.update({playerSettingModule.RACE_WOLFMAN_M : "d:/ymir work/bin/icon/face/wolfman_m.tga",})
  36.  
  37.     def __init__(self):
  38.         ui.ScriptWindow.__init__(self)
  39.         self.TitleName = 0
  40.         self.tooltipItem = 0
  41.         self.xStart = 0
  42.         self.yStart = 0
  43.  
  44.     def __del__(self):
  45.         ui.ScriptWindow.__del__(self)
  46.  
  47.     if app.ENABLE_NEW_EXCHANGE_WINDOW:
  48.         class Item(ui.ListBoxEx.Item):
  49.             def __init__(self,parent, text, value=0):
  50.                 ui.ListBoxEx.Item.__init__(self)
  51.                 self.textBox=ui.TextLine()
  52.                 self.textBox.SetParent(self)
  53.                 self.textBox.SetText(text)
  54.                 self.textBox.Show()
  55.                 self.value = value
  56.  
  57.             def GetValue(self):
  58.                 return self.value
  59.  
  60.             def __del__(self):
  61.                 ui.ListBoxEx.Item.__del__(self)
  62.  
  63.     def LoadDialog(self):
  64.         PythonScriptLoader = ui.PythonScriptLoader()
  65.         if app.ENABLE_NEW_EXCHANGE_WINDOW:
  66.             PythonScriptLoader.LoadScriptFile(self, "UIScript/exchangedialog_new.py")
  67.         else:
  68.             PythonScriptLoader.LoadScriptFile(self, "UIScript/exchangedialog.py")
  69.  
  70.         ## Owner
  71.         self.OwnerSlot = self.GetChild("Owner_Slot")
  72.         self.OwnerSlot.SetSelectEmptySlotEvent(ui.__mem_func__(self.SelectOwnerEmptySlot))
  73.         self.OwnerSlot.SetSelectItemSlotEvent(ui.__mem_func__(self.SelectOwnerItemSlot))
  74.         self.OwnerSlot.SetOverInItemEvent(ui.__mem_func__(self.OverInOwnerItem))
  75.         self.OwnerSlot.SetOverOutItemEvent(ui.__mem_func__(self.OverOutItem))
  76.         self.OwnerMoney = self.GetChild("Owner_Money_Value")
  77.         if app.ENABLE_NEW_EXCHANGE_WINDOW:
  78.             self.OwnerMoneyIcon = self.GetChild("Owner_Money_Icon")
  79.         else:
  80.             self.OwnerAcceptLight = self.GetChild("Owner_Accept_Light")
  81.             self.OwnerAcceptLight.Disable()
  82.         self.OwnerMoneyButton = self.GetChild("Owner_Money")
  83.         self.OwnerMoneyButton.SetEvent(ui.__mem_func__(self.OpenPickMoneyDialog))
  84.         if app.ENABLE_CHEQUE_SYSTEM:
  85.             self.OwnerChequeIcon = self.GetChild("Owner_Cheque_Icon")
  86.             self.OwnerCheque = self.GetChild("Owner_Cheque_Value")
  87.             self.OwnerChequeButton = self.GetChild("Owner_Cheque")
  88.             self.OwnerChequeButton.SetEvent(ui.__mem_func__(self.OpenPickChequeDialog))
  89.  
  90.         ## Target
  91.         self.TargetSlot = self.GetChild("Target_Slot")
  92.         self.TargetSlot.SetOverInItemEvent(ui.__mem_func__(self.OverInTargetItem))
  93.         self.TargetSlot.SetOverOutItemEvent(ui.__mem_func__(self.OverOutItem))
  94.         self.TargetMoney = self.GetChild("Target_Money_Value")
  95.         if app.ENABLE_NEW_EXCHANGE_WINDOW:
  96.             self.TargetMoneyIcon = self.GetChild("Target_Money_Icon")
  97.         else:
  98.             self.TargetAcceptLight = self.GetChild("Target_Accept_Light")
  99.             self.TargetAcceptLight.Disable()
  100.         if app.ENABLE_CHEQUE_SYSTEM:
  101.             self.TargetCheque = self.GetChild("Target_Cheque_Value")
  102.             self.TargetChequeIcon = self.GetChild("Target_Cheque_Icon")
  103.  
  104.         ## PickMoneyDialog
  105.         dlgPickMoney = uiPickMoney.PickMoneyDialog()
  106.         dlgPickMoney.LoadDialog()
  107.         dlgPickMoney.SetAcceptEvent(ui.__mem_func__(self.OnPickMoney))
  108.         dlgPickMoney.SetTitleName(localeInfo.EXCHANGE_MONEY)
  109.         if app.ENABLE_NEW_EXCHANGE_WINDOW:
  110.             dlgPickMoney.SetMax(9)
  111.         else:
  112.             dlgPickMoney.SetMax(7)
  113.         if app.ENABLE_CHEQUE_SYSTEM:
  114.             dlgPickMoney.SetMaxCheque(2)
  115.         dlgPickMoney.Hide()
  116.         self.dlgPickMoney = dlgPickMoney
  117.  
  118.         ## Button
  119.         self.AcceptButton = self.GetChild("Owner_Accept_Button")
  120.         self.AcceptButton.SetToggleDownEvent(ui.__mem_func__(self.AcceptExchange))
  121.  
  122.         if app.ENABLE_NEW_EXCHANGE_WINDOW:
  123.             self.TargetAcceptButton = self.GetChild("Target_Accept_Button")
  124.  
  125.         self.TitleName = self.GetChild("TitleName")
  126.         self.GetChild("TitleBar").SetCloseEvent(net.SendExchangeExitPacket)
  127.  
  128.         if app.ENABLE_NEW_EXCHANGE_WINDOW:
  129.             self.FaceOwnerImage = self.GetChild("FaceOwner_Image")
  130.             self.FaceTargetImage = self.GetChild("FaceTarget_Image")
  131.             self.TargetName = self.GetChild("target_NameText")
  132.             self.TargetLevel = self.GetChild("target_LvText")
  133.             self.ExchangeLogs = self.GetChild("ExchangeLogs")
  134.             self.LogsScrollBar = ui.ThinScrollBar()
  135.             self.LogsScrollBar.SetParent(self.ExchangeLogs)
  136.             self.LogsScrollBar.SetPosition(367, 17)
  137.             self.LogsScrollBar.SetScrollBarSize(50)
  138.             self.LogsScrollBar.Show()
  139.             self.LogsDropList = ui.ListBoxEx()
  140.             self.LogsDropList.SetParent(self.ExchangeLogs)
  141.             self.LogsDropList.itemHeight = 12
  142.             self.LogsDropList.itemStep = 13
  143.             self.LogsDropList.SetPosition(35, 27)
  144.             self.LogsDropList.SetSize(0, 45)
  145.             self.LogsDropList.SetScrollBar(self.LogsScrollBar)
  146.             self.LogsDropList.SetViewItemCount(2)
  147.             self.LogsDropList.Show()
  148.             self.LogsScrollBar.Show()
  149.             self.listOwnerSlot = []
  150.             self.listTargetSlot = []
  151.  
  152.     def Destroy(self):
  153.         print "---------------------------------------------------------------------------- DESTROY EXCHANGE"
  154.         self.ClearDictionary()
  155.         self.dlgPickMoney.Destroy()
  156.         self.dlgPickMoney = 0
  157.         self.OwnerSlot = 0
  158.         self.OwnerMoney = 0
  159.         if not app.ENABLE_NEW_EXCHANGE_WINDOW:
  160.             self.OwnerAcceptLight = 0
  161.         self.OwnerMoneyIcon = 0
  162.         self.OwnerMoneyButton = 0
  163.         if app.ENABLE_CHEQUE_SYSTEM:
  164.             self.OwnerChequeIcon = 0
  165.         self.TargetSlot = 0
  166.         self.TargetMoney = 0
  167.         if not app.ENABLE_NEW_EXCHANGE_WINDOW:
  168.             self.TargetAcceptLight = 0
  169.         self.TitleName = 0
  170.         self.AcceptButton = 0
  171.         if app.ENABLE_NEW_EXCHANGE_WINDOW:
  172.             self.TargetAcceptButton = 0
  173.             self.FaceOwnerImage = None
  174.             self.FaceTargetImage = None
  175.             self.TargetName = None
  176.             self.TargetLevel = None
  177.             self.ExchangesLogsWindow = None
  178.             self.LogsDropList.RemoveAllItems()
  179.             self.LogsScrollBar = None
  180.             self.LogsDropList = None
  181.         self.tooltipItem = 0
  182.  
  183.     def OpenDialog(self):
  184.         if app.ENABLE_LEVEL_IN_TRADE:
  185.             self.TitleName.SetText(localeInfo.EXCHANGE_TITLE % (exchange.GetNameFromTarget(), exchange.GetLevelFromTarget()))
  186.         else:
  187.             self.TitleName.SetText(localeInfo.EXCHANGE_TITLE % (exchange.GetNameFromTarget()))
  188.         self.AcceptButton.Enable()
  189.         self.AcceptButton.SetUp()
  190.         if app.ENABLE_NEW_EXCHANGE_WINDOW:
  191.             self.TargetAcceptButton.Disable()
  192.             self.TargetAcceptButton.SetUp()
  193.             self.FaceOwnerImage.LoadImage(self.FACE_IMAGE_DICT[exchange.GetRaceFromSelf()])
  194.             self.FaceTargetImage.LoadImage(self.FACE_IMAGE_DICT[exchange.GetRaceFromTarget()])
  195.             self.TargetName.SetText(exchange.GetNameFromTarget())
  196.             self.TargetLevel.SetText(localeInfo.NEW_EXCHANGE_LEVEL % (exchange.GetLevelFromTarget()))
  197.             self.LogsDropList.RemoveAllItems()
  198.             self.LogsDropList.AppendItem(self.Item(self, localeInfo.NEW_EXCHANGE_YOU_READY % (str(time.strftime("[%H:%M:%S]"))), 0))
  199.         self.Show()
  200.  
  201.         (self.xStart, self.yStart, z) = player.GetMainCharacterPosition()
  202.  
  203.     def CloseDialog(self):
  204.         wndMgr.OnceIgnoreMouseLeftButtonUpEvent()
  205.  
  206.         if 0 != self.tooltipItem:
  207.             self.tooltipItem.HideToolTip()
  208.  
  209.         self.dlgPickMoney.Close()
  210.         self.Hide()
  211.  
  212.     def SetItemToolTip(self, tooltipItem):
  213.         self.tooltipItem = tooltipItem
  214.  
  215.     def OpenPickMoneyDialog(self):
  216.         if exchange.GetElkFromSelf() > 0:
  217.             chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.EXCHANGE_CANT_EDIT_MONEY)
  218.             return
  219.         if app.ENABLE_CHEQUE_SYSTEM:
  220.             self.dlgPickMoney.Open(player.GetElk(),player.GetCheque())
  221.             self.dlgPickMoney.SetFocus(0)
  222.         else:
  223.             self.dlgPickMoney.Open(player.GetElk())
  224.  
  225.     if app.ENABLE_CHEQUE_SYSTEM:
  226.         def OpenPickChequeDialog(self):
  227.             if exchange.GetChequeFromSelf() > 0:
  228.                 chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.EXCHANGE_CANT_EDIT_MONEY)
  229.                 return
  230.             self.dlgPickMoney.Open(player.GetElk(),player.GetCheque())
  231.             self.dlgPickMoney.SetFocus(1)
  232.  
  233.         def OnPickMoney(self, money, cheque):
  234.             if exchange.GetChequeFromSelf() <=0:
  235.                 net.SendExchangeChequeAddPacket(cheque)
  236.             if exchange.GetElkFromSelf() <= 0:
  237.                 net.SendExchangeElkAddPacket(money)
  238.     else:
  239.         def OnPickMoney(self, money):
  240.             net.SendExchangeElkAddPacket(money)
  241.  
  242.     def AcceptExchange(self):
  243.         if app.ENABLE_NEW_EXCHANGE_WINDOW:
  244.             atLeastOneItem = 0
  245.             atLeastOneYang = 0
  246.             for i in xrange(exchange.EXCHANGE_ITEM_MAX_NUM):
  247.                 itemCount = exchange.GetItemCountFromTarget(i)
  248.                 if itemCount >= 1:
  249.                     atLeastOneYang = 1
  250.                     break
  251.            
  252.             if exchange.GetElkFromTarget() >= 1:
  253.                 atLeastOneYang = 1
  254.            
  255.             if atLeastOneItem or atLeastOneYang:
  256.                 net.SendExchangeAcceptPacket()
  257.                 self.AcceptButton.Disable()
  258.             else:
  259.                 atLeastOneItem = 0
  260.                 atLeastOneYang = 0
  261.                 for i in xrange(exchange.EXCHANGE_ITEM_MAX_NUM):
  262.                     itemCount = exchange.GetItemCountFromSelf(i)
  263.                     if itemCount >= 1:
  264.                         atLeastOneYang = 1
  265.                         break
  266.                
  267.                 if exchange.GetElkFromSelf() >= 1:
  268.                     atLeastOneYang = 1
  269.                
  270.                 if atLeastOneItem or atLeastOneYang:
  271.                     self.questionDialog = uiCommon.QuestionDialog2()
  272.                     self.questionDialog.SetText1(localeInfo.NEW_EXCHANGE_ALERT1)
  273.                     self.questionDialog.SetText2(localeInfo.NEW_EXCHANGE_ALERT2)
  274.                     self.questionDialog.SetAcceptEvent(ui.__mem_func__(self.AcceptQuestion))
  275.                     self.questionDialog.SetCancelEvent(ui.__mem_func__(self.OnCloseQuestionDialog))
  276.                     self.questionDialog.Open()
  277.                 else:
  278.                     net.SendExchangeAcceptPacket()
  279.                     self.AcceptButton.Disable()
  280.         else:
  281.             net.SendExchangeAcceptPacket()
  282.             self.AcceptButton.Disable()
  283.  
  284.     if app.ENABLE_NEW_EXCHANGE_WINDOW:
  285.         def AcceptQuestion(self):
  286.             net.SendExchangeAcceptPacket()
  287.             self.AcceptButton.Disable()
  288.             if self.questionDialog:
  289.                 self.questionDialog.Close()
  290.             self.questionDialog = None
  291.  
  292.         def OnCloseQuestionDialog(self):
  293.             if self.questionDialog:
  294.                 self.questionDialog.Close()
  295.             self.questionDialog = None
  296.             self.AcceptButton.Enable()
  297.             self.AcceptButton.SetUp()
  298.  
  299.     def SelectOwnerEmptySlot(self, SlotIndex):
  300.  
  301.         if False == mouseModule.mouseController.isAttached():
  302.             return
  303.  
  304.         if mouseModule.mouseController.IsAttachedMoney():
  305.             net.SendExchangeElkAddPacket(mouseModule.mouseController.GetAttachedMoneyAmount())
  306.         else:
  307.             attachedSlotType = mouseModule.mouseController.GetAttachedType()
  308.             if (player.SLOT_TYPE_INVENTORY == attachedSlotType
  309.                 or player.SLOT_TYPE_DRAGON_SOUL_INVENTORY == attachedSlotType):
  310.  
  311.                 attachedInvenType = player.SlotTypeToInvenType(attachedSlotType)
  312.                 SrcSlotNumber = mouseModule.mouseController.GetAttachedSlotNumber()
  313.                 DstSlotNumber = SlotIndex
  314.  
  315.                 itemID = player.GetItemIndex(attachedInvenType, SrcSlotNumber)
  316.                 item.SelectItem(itemID)
  317.  
  318.                 if item.IsAntiFlag(item.ANTIFLAG_GIVE):
  319.                     chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.EXCHANGE_CANNOT_GIVE)
  320.                     mouseModule.mouseController.DeattachObject()
  321.                     return
  322.  
  323.                 net.SendExchangeItemAddPacket(attachedInvenType, SrcSlotNumber, DstSlotNumber)
  324.  
  325.         mouseModule.mouseController.DeattachObject()
  326.  
  327.     def SelectOwnerItemSlot(self, SlotIndex):
  328.  
  329.         if player.ITEM_MONEY == mouseModule.mouseController.GetAttachedItemIndex():
  330.  
  331.             money = mouseModule.mouseController.GetAttachedItemCount()
  332.             net.SendExchangeElkAddPacket(money)
  333.  
  334.     def RefreshOwnerSlot(self):
  335.         for i in xrange(exchange.EXCHANGE_ITEM_MAX_NUM):
  336.             itemIndex = exchange.GetItemVnumFromSelf(i)
  337.             itemCount = exchange.GetItemCountFromSelf(i)
  338.             if 1 == itemCount:
  339.                 itemCount = 0
  340.             self.OwnerSlot.SetItemSlot(i, itemIndex, itemCount)
  341.         self.OwnerSlot.RefreshSlot()
  342.  
  343.     def RefreshTargetSlot(self):
  344.         for i in xrange(exchange.EXCHANGE_ITEM_MAX_NUM):
  345.             itemIndex = exchange.GetItemVnumFromTarget(i)
  346.             itemCount = exchange.GetItemCountFromTarget(i)
  347.             if 1 == itemCount:
  348.                 itemCount = 0
  349.             self.TargetSlot.SetItemSlot(i, itemIndex, itemCount)
  350.         self.TargetSlot.RefreshSlot()
  351.  
  352.     def Refresh(self):
  353.         self.RefreshOwnerSlot()
  354.         self.RefreshTargetSlot()
  355.  
  356.         if app.ENABLE_CHEQUE_SYSTEM:
  357.             self.OwnerMoney.SetText(localeInfo.NumberToGoldNotText(exchange.GetElkFromSelf()))
  358.             self.TargetMoney.SetText(localeInfo.NumberToGoldNotText(exchange.GetElkFromTarget()))
  359.  
  360.             self.OwnerCheque.SetText(str(exchange.GetChequeFromSelf()))
  361.             self.TargetCheque.SetText(str(exchange.GetChequeFromTarget()))
  362.         else:
  363.             self.OwnerMoney.SetText(str(exchange.GetElkFromSelf()))
  364.             self.TargetMoney.SetText(str(exchange.GetElkFromTarget()))
  365.  
  366.         if True == exchange.GetAcceptFromSelf():
  367.             if app.ENABLE_NEW_EXCHANGE_WINDOW:
  368.                 self.TargetSlot.SetSlotBaseImage("d:/ymir work/ui/public/slot_base.sub", 0.3500, 0.8500, 0.3500, 1.0)
  369.                 self.LogsDropList.AppendItem(self.Item(self, localeInfo.NEW_EXCHANGE_YOU_ACCEPT % (str((time.strftime("[%H:%M:%S]")))), 0))
  370.             else:
  371.                 self.OwnerAcceptLight.Down()
  372.         else:
  373.             self.AcceptButton.Enable()
  374.             self.AcceptButton.SetUp()
  375.             if app.ENABLE_NEW_EXCHANGE_WINDOW:
  376.                 self.TargetSlot.SetSlotBaseImage("d:/ymir work/ui/public/slot_base.sub", 0.3500, 0.8500, 0.3500, 1.0)
  377.             else:
  378.                 self.OwnerAcceptLight.SetUp()
  379.  
  380.         if True == exchange.GetAcceptFromTarget():
  381.             if app.ENABLE_NEW_EXCHANGE_WINDOW:
  382.                 self.TargetAcceptButton.Down()
  383.                 self.TargetSlot.SetSlotBaseImage("d:/ymir work/ui/public/slot_base.sub", 0.3500, 0.8500, 0.3500, 1.0)
  384.                 self.LogsDropList.AppendItem(self.Item(self, localeInfo.NEW_EXCHANGE_ACCEPT % (str((time.strftime("[%H:%M:%S]"))), exchange.GetNameFromTarget()), 0))
  385.             else:
  386.                 self.TargetAcceptLight.Down()
  387.         else:
  388.             if app.ENABLE_NEW_EXCHANGE_WINDOW:
  389.                 if self.TargetAcceptButton.IsDown() == True:
  390.                     self.LogsDropList.AppendItem(self.Item(self, localeInfo.NEW_EXCHANGE_ABORT % (str((time.strftime("[%H:%M:%S]"))), exchange.GetNameFromTarget()), 0))
  391.                
  392.                 self.TargetAcceptButton.SetUp()
  393.                 self.TargetSlot.SetSlotBaseImage("d:/ymir work/ui/public/slot_base.sub", 1.0, 1.0, 1.0, 1.0)
  394.             else:
  395.                 self.TargetAcceptLight.SetUp()
  396.  
  397.     def OverInOwnerItem(self, slotIndex):
  398.  
  399.         if 0 != self.tooltipItem:
  400.             self.tooltipItem.SetExchangeOwnerItem(slotIndex)
  401.  
  402.     def OverInTargetItem(self, slotIndex):
  403.  
  404.         if 0 != self.tooltipItem:
  405.             self.tooltipItem.SetExchangeTargetItem(slotIndex)
  406.  
  407.     def OverOutItem(self):
  408.  
  409.         if 0 != self.tooltipItem:
  410.             self.tooltipItem.HideToolTip()
  411.  
  412.     def OnTop(self):
  413.         self.tooltipItem.SetTop()
  414.  
  415.     def OnUpdate(self):
  416.  
  417.         USE_EXCHANGE_LIMIT_RANGE = 1000
  418.  
  419.         (x, y, z) = player.GetMainCharacterPosition()
  420.         if abs(x - self.xStart) > USE_EXCHANGE_LIMIT_RANGE or abs(y - self.yStart) > USE_EXCHANGE_LIMIT_RANGE:
  421.             (self.xStart, self.yStart, z) = player.GetMainCharacterPosition()
  422.             net.SendExchangeExitPacket()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement