import ui import grp import net import app import wndMgr import localeInfo import item import constInfo import mouseModule import uiToolTip import player import uiCommon class FirsatYakalaWindow(ui.ScriptWindow): def __init__(self): ui.ScriptWindow.__init__(self) self.tooltipItem = None self.itemSlotWindow = None self.LoadWindow() def __del__(self): ui.ScriptWindow.__del__(self) self.tooltipItem = None self.itemSlotWindow = None def LoadWindow(self): try: PythonScriptLoader = ui.PythonScriptLoader() PythonScriptLoader.LoadScriptFile(self, "UIScript/FirsatYakalaWindow.py") except: import exception exception.Abort("FirsatYakalaWindow.LoadWindow.LoadObject") try: self.titleBar = self.GetChild("titlebar") self.itemSlotWindow = self.GetChild("ItemSlot") except: import exception exception.Abort("FirsatYakalaWindow.__LoadWindow.BindObject") self.titleBar.SetCloseEvent(ui.__mem_func__(self.Close)) self.itemSlotWindow.SetSlotStyle(wndMgr.SLOT_STYLE_NONE) self.itemSlotWindow.SAFE_SetButtonEvent("LEFT", "EMPTY", self.SelectEmptySlot) self.itemSlotWindow.SAFE_SetButtonEvent("LEFT", "EXIST", self.SelectItemSlot) self.itemSlotWindow.SetOverInItemEvent(ui.__mem_func__(self.OverInItem)) self.itemSlotWindow.SetOverOutItemEvent(ui.__mem_func__(self.OverOutItem)) self.tooltipItem = uiToolTip.ItemToolTip() self.Refresh() def Refresh(self): for i in xrange(len(constInfo.firsatYakalaInfo)): itemPos = constInfo.firsatYakalaInfo[i]['itemPos'] self.itemSlotWindow.ClearSlot(itemPos) for i in xrange(len(constInfo.firsatYakalaInfo)): itemPos = constInfo.firsatYakalaInfo[i]['itemPos'] itemVnum = constInfo.firsatYakalaInfo[i]['itemVnum'] itemCount = constInfo.firsatYakalaInfo[i]['itemCount'] itemStok = constInfo.firsatYakalaInfo[i]['itemStok'] if itemCount <= 1: itemCount = 0 self.itemSlotWindow.SetItemSlot(itemPos, itemVnum, itemCount) if itemStok == 0: self.itemSlotWindow.NewDisableSlot(itemPos) wndMgr.RefreshSlot(self.itemSlotWindow.GetWindowHandle()) def SelectEmptySlot(self, slotIndex): mouseModule.mouseController.DeattachObject() def SelectItemSlot(self, slotIndex): if constInfo.GET_ITEM_QUESTION_DIALOG_STATUS() == 1: return isAttached = mouseModule.mouseController.isAttached() if not isAttached: self.AskBuyItem(slotIndex) def SetItemToolTip(self, tooltip): self.tooltipItem = tooltip def OverInItem(self, slotIndex): if mouseModule.mouseController.isAttached(): return self.ShowToolTip(slotIndex) def OverOutItem(self): if None != self.tooltipItem: self.tooltipItem.HideToolTip() def ShowToolTip(self, slotIndex): self.tooltipItem.ClearToolTip() itemVnum = 0 itemEskiFiyat = 0 itemYeniFiyat = 0 itemStok = 0 for i in xrange(len(constInfo.firsatYakalaInfo)): itemPos = constInfo.firsatYakalaInfo[i]['itemPos'] if itemPos == slotIndex: itemVnum = constInfo.firsatYakalaInfo[i]['itemVnum'] itemEskiFiyat = constInfo.firsatYakalaInfo[i]['itemEskiFiyat'] itemYeniFiyat = constInfo.firsatYakalaInfo[i]['itemYeniFiyat'] itemStok = constInfo.firsatYakalaInfo[i]['itemStok'] itemStokLimit = constInfo.firsatYakalaInfo[i]['itemStokLimit'] break if 0 == itemVnum: return self.AppendFirsatFiyat(itemEskiFiyat, itemYeniFiyat, itemStok, itemStokLimit) metinSlot = [] for i in xrange(player.METIN_SOCKET_MAX_NUM): metinSlot.append(0) attrSlot = [] for i in xrange(player.ATTRIBUTE_SLOT_MAX_NUM): attrSlot.append([0, 0]) self.tooltipItem.AddItemData(itemVnum, metinSlot, attrSlot) def AppendFirsatFiyat(self, itemEskiFiyat, itemYeniFiyat, itemStok, itemStokLimit): self.tooltipItem.AppendTextLine("Nesne Market Fiyatı: %s" % (self.FiyatNumber(itemEskiFiyat)), 0xffffb6b6) self.tooltipItem.AppendSpace(5) self.tooltipItem.AppendTextLine("Fırsat Fiyatı: %s" % (self.FiyatNumber(itemYeniFiyat)), 0xffffec0b) self.tooltipItem.AppendSpace(5) if itemStokLimit == 1: self.tooltipItem.AppendTextLine("Kalan Stok: %s" % (str(itemStok)), 0xfffbffa4) self.tooltipItem.AppendSpace(5) def FiyatNumber(self, n): return "%s EP" % ('.'.join([ i-3<0 and str(n)[:i] or str(n)[i-3:i] for i in range(len(str(n))%3, len(str(n))+1, 3) if i ])) def AskBuyItem(self, slotIndex): itemPos = 0 itemVnum = 0 itemEskiFiyat = 0 itemYeniFiyat = 0 itemStok = 0 for i in xrange(len(constInfo.firsatYakalaInfo)): itemPos = constInfo.firsatYakalaInfo[i]['itemPos'] if itemPos == slotIndex: itemVnum = constInfo.firsatYakalaInfo[i]['itemVnum'] itemEskiFiyat = constInfo.firsatYakalaInfo[i]['itemEskiFiyat'] itemYeniFiyat = constInfo.firsatYakalaInfo[i]['itemYeniFiyat'] itemStok = constInfo.firsatYakalaInfo[i]['itemStok'] break if 0 == itemVnum: return if 0 == itemStok: return item.SelectItem(itemVnum) itemName = item.GetItemName() itemBuyQuestionDialog = uiCommon.QuestionDialog() itemBuyQuestionDialog.SetText("|cffffec0b[" + itemName + "]|r" + " satin almak istiyormusunuz? Fiyat: " + self.FiyatNumber(itemYeniFiyat)) itemBuyQuestionDialog.SetAcceptEvent(lambda arg = True: self.AnswerBuyItem(arg)) itemBuyQuestionDialog.SetCancelEvent(lambda arg = False: self.AnswerBuyItem(arg)) itemBuyQuestionDialog.Open() itemBuyQuestionDialog.pos = slotIndex self.itemBuyQuestionDialog = itemBuyQuestionDialog constInfo.SET_ITEM_QUESTION_DIALOG_STATUS(1) def AnswerBuyItem(self, flag): if flag: slotIndex = self.itemBuyQuestionDialog.pos net.SendChatPacket("/firsatyakalabuy %d" % int(slotIndex)) self.itemBuyQuestionDialog.Close() self.itemBuyQuestionDialog = None constInfo.SET_ITEM_QUESTION_DIALOG_STATUS(0) def Open(self): self.LoadWindow() self.SetCenterPosition() ui.ScriptWindow.Show(self) def Close(self): if self.tooltipItem: self.tooltipItem.HideToolTip() self.Hide() return True def OnPressEscapeKey(self): self.Close() return True