import app import net import player import item import ui import uiToolTip import mouseModule if app.ENABLE_CLIENT_OPTIMIZATION: import localeInfo as _localeInfo localeInfo = _localeInfo.localeInfo() else: import localeInfo import uiCommon import constInfo class RefineDialog(ui.ScriptWindow): makeSocketSuccessPercentage = ( 100, 33, 20, 15, 10, 5, 0 ) upgradeStoneSuccessPercentage = ( 30, 29, 28, 27, 26, 25, 24, 23, 22 ) upgradeArmorSuccessPercentage = ( 99, 66, 33, 33, 33, 33, 33, 33, 33 ) upgradeAccessorySuccessPercentage = ( 99, 88, 77, 66, 33, 33, 33, 33, 33 ) upgradeSuccessPercentage = ( 99, 66, 33, 33, 33, 33, 33, 33, 33 ) def __init__(self): ui.ScriptWindow.__init__(self) self.__LoadScript() self.scrollItemPos = 0 self.targetItemPos = 0 def __LoadScript(self): self.__LoadQuestionDialog() try: pyScrLoader = ui.PythonScriptLoader() pyScrLoader.LoadScriptFile(self, "uiscript/refinedialog.py") except: import exception exception.Abort("RefineDialog.__LoadScript.LoadObject") try: self.board = self.GetChild("Board") self.titleBar = self.GetChild("TitleBar") self.successPercentage = self.GetChild("SuccessPercentage") self.GetChild("AcceptButton").SetEvent(self.OpenQuestionDialog) self.GetChild("CancelButton").SetEvent(self.Close) except: import exception exception.Abort("RefineDialog.__LoadScript.BindObject") ##if 936 == app.GetDefaultCodePage(): if constInfo.ENABLE_REFINE_PCT: self.successPercentage.Show() else: self.successPercentage.Hide() toolTip = uiToolTip.ItemToolTip() toolTip.SetParent(self) toolTip.SetPosition(15, 38) toolTip.SetFollow(False) toolTip.Show() self.toolTip = toolTip self.titleBar.SetCloseEvent(ui.__mem_func__(self.Close)) def __del__(self): ui.ScriptWindow.__del__(self) def __LoadQuestionDialog(self): self.dlgQuestion = ui.ScriptWindow() try: pyScrLoader = ui.PythonScriptLoader() pyScrLoader.LoadScriptFile(self.dlgQuestion, "uiscript/questiondialog2.py") except: import exception exception.Abort("RefineDialog.__LoadQuestionDialog.LoadScript") try: GetObject=self.dlgQuestion.GetChild GetObject("message1").SetText(localeInfo.REFINE_DESTROY_WARNING) GetObject("message2").SetText(localeInfo.REFINE_WARNING2) GetObject("accept").SetEvent(ui.__mem_func__(self.Accept)) GetObject("cancel").SetEvent(ui.__mem_func__(self.dlgQuestion.Hide)) except: import exception exception.Abort("SelectCharacterWindow.__LoadQuestionDialog.BindObject") def Destroy(self): self.ClearDictionary() self.board = 0 self.successPercentage = 0 self.titleBar = 0 self.toolTip = 0 self.dlgQuestion = 0 def GetRefineSuccessPercentage(self, scrollSlotIndex, itemSlotIndex): if -1 != scrollSlotIndex: if player.IsRefineGradeScroll(scrollSlotIndex): curGrade = player.GetItemGrade(itemSlotIndex) itemIndex = player.GetItemIndex(itemSlotIndex) item.SelectItem(itemIndex) itemType = item.GetItemType() itemSubType = item.GetItemSubType() if item.ITEM_TYPE_METIN == itemType: if curGrade >= len(self.upgradeStoneSuccessPercentage): return 0 return self.upgradeStoneSuccessPercentage[curGrade] elif item.ITEM_TYPE_ARMOR == itemType: if item.ARMOR_BODY == itemSubType: if curGrade >= len(self.upgradeArmorSuccessPercentage): return 0 return self.upgradeArmorSuccessPercentage[curGrade] else: if curGrade >= len(self.upgradeAccessorySuccessPercentage): return 0 return self.upgradeAccessorySuccessPercentage[curGrade] else: if curGrade >= len(self.upgradeSuccessPercentage): return 0 return self.upgradeSuccessPercentage[curGrade] for i in xrange(player.METIN_SOCKET_MAX_NUM+1): if 0 == player.GetItemMetinSocket(itemSlotIndex, i): break return self.makeSocketSuccessPercentage[i] def Open(self, scrollItemPos, targetItemPos): self.scrollItemPos = scrollItemPos self.targetItemPos = targetItemPos percentage = self.GetRefineSuccessPercentage(scrollItemPos, targetItemPos) if 0 == percentage: return self.successPercentage.SetText(localeInfo.REFINE_SUCCESS_PROBALITY % (percentage)) itemIndex = player.GetItemIndex(targetItemPos) self.toolTip.ClearToolTip() metinSlot = [] for i in xrange(player.METIN_SOCKET_MAX_NUM): metinSlot.append(player.GetItemMetinSocket(targetItemPos, i)) self.toolTip.AddItemData(itemIndex, metinSlot) self.UpdateDialog() self.SetTop() self.Show() def UpdateDialog(self): newWidth = self.toolTip.GetWidth() + 30 newHeight = self.toolTip.GetHeight() + 98 self.board.SetSize(newWidth, newHeight) self.titleBar.SetWidth(newWidth-15) self.SetSize(newWidth, newHeight) (x, y) = self.GetLocalPosition() self.SetPosition(x, y) def OpenQuestionDialog(self): percentage = self.GetRefineSuccessPercentage(-1, self.targetItemPos) if 100 == percentage: self.Accept() return self.dlgQuestion.SetTop() self.dlgQuestion.Show() def Accept(self): net.SendItemUseToItemPacket(self.scrollItemPos, self.targetItemPos) self.Close() def Close(self): self.dlgQuestion.Hide() self.Hide() def OnPressEscapeKey(self): self.Close() return True class RefineDialogNew(ui.ScriptWindow): def __init__(self): ui.ScriptWindow.__init__(self) self.__Initialize() self.isLoaded = False if app.ENABLE_TRADABLE_ICON: self.wndInventory = None if app.ENABLE_WINDOW_SLIDE_EFFECT: self.EnableSlidingEffect() def __Initialize(self): self.dlgQuestion = None self.children = [] self.vnum = 0 self.targetItemPos = 0 self.dialogHeight = 0 self.cost = 0 self.percentage = 0 self.type = 0 if app.ENABLE_TRADABLE_ICON: self.lockedItem = (-1,-1) def __LoadScript(self): try: pyScrLoader = ui.PythonScriptLoader() pyScrLoader.LoadScriptFile(self, "uiscript/refinedialog.py") except: import exception exception.Abort("RefineDialog.__LoadScript.LoadObject") try: self.board = self.GetChild("Board") self.titleBar = self.GetChild("TitleBar") self.probText = self.GetChild("SuccessPercentage") self.costText = self.GetChild("Cost") self.successPercentage = self.GetChild("SuccessPercentage") self.GetChild("AcceptButton").SetEvent(self.OpenQuestionDialog) self.GetChild("CancelButton").SetEvent(self.CancelRefine) except: import exception exception.Abort("RefineDialog.__LoadScript.BindObject") ##if 936 == app.GetDefaultCodePage(): if constInfo.ENABLE_REFINE_PCT: self.successPercentage.Show() else: self.successPercentage.Hide() toolTip = uiToolTip.ItemToolTip() toolTip.SetParent(self) toolTip.SetFollow(False) toolTip.SetPosition(15, 38) toolTip.Show() self.toolTip = toolTip self.slotList = [] for i in xrange(3): slot = self.__MakeSlot() slot.SetParent(toolTip) slot.SetWindowVerticalAlignCenter() self.slotList.append(slot) itemImage = self.__MakeItemImage() itemImage.SetParent(toolTip) itemImage.SetWindowVerticalAlignCenter() itemImage.SetPosition(-35, 0) self.itemImage = itemImage self.titleBar.SetCloseEvent(ui.__mem_func__(self.CancelRefine)) self.isLoaded = True def __del__(self): ui.ScriptWindow.__del__(self) def __MakeSlot(self): slot = ui.ImageBox() slot.LoadImage("d:/ymir work/ui/public/slot_base.sub") slot.Show() self.children.append(slot) return slot def __MakeItemImage(self): itemImage = ui.ImageBox() itemImage.Show() self.children.append(itemImage) return itemImage def __MakeThinBoard(self): thinBoard = ui.ThinBoard() thinBoard.SetParent(self) thinBoard.Show() self.children.append(thinBoard) return thinBoard def Destroy(self): self.ClearDictionary() self.dlgQuestion = None self.board = 0 self.probText = 0 self.costText = 0 self.titleBar = 0 self.toolTip = 0 self.successPercentage = None self.slotList = [] self.children = [] if app.ENABLE_TRADABLE_ICON: self.wndInventory = None self.lockedItem = (-1,-1) def Open(self, targetItemPos, nextGradeItemVnum, cost, prob, type): if False == self.isLoaded: self.__LoadScript() self.__Initialize() self.targetItemPos = targetItemPos self.vnum = nextGradeItemVnum self.cost = cost self.percentage = prob self.type = type self.probText.SetText(localeInfo.REFINE_SUCCESS_PROBALITY % (self.percentage)) self.costText.SetText(localeInfo.REFINE_COST % (self.cost)) if app.ENABLE_TRADABLE_ICON: self.SetCantMouseEventSlot(targetItemPos) self.toolTip.ClearToolTip() metinSlot = [] for i in xrange(player.METIN_SOCKET_MAX_NUM): metinSlot.append(player.GetItemMetinSocket(targetItemPos, i)) attrSlot = [] for i in xrange(player.ATTRIBUTE_SLOT_MAX_NUM): attrSlot.append(player.GetItemAttribute(targetItemPos, i)) self.toolTip.AddRefineItemData(nextGradeItemVnum, metinSlot, attrSlot) item.SelectItem(nextGradeItemVnum) self.itemImage.LoadImage(item.GetIconImageFileName()) xSlotCount, ySlotCount = item.GetItemSize() for slot in self.slotList: slot.Hide() for i in xrange(min(3, ySlotCount)): self.slotList[i].SetPosition(-35, i*32 - (ySlotCount-1)*16) self.slotList[i].Show() self.dialogHeight = self.toolTip.GetHeight() + 46 self.UpdateDialog() self.SetTop() self.Show() def Close(self): self.dlgQuestion = None self.Hide() if app.ENABLE_TRADABLE_ICON: self.lockedItem = (-1, -1) self.SetCanMouseEventSlot(self.targetItemPos) def AppendMaterial(self, vnum, count): slot = self.__MakeSlot() slot.SetParent(self) slot.SetPosition(15, self.dialogHeight) itemImage = self.__MakeItemImage() itemImage.SetParent(slot) item.SelectItem(vnum) itemImage.LoadImage(item.GetIconImageFileName()) thinBoard = self.__MakeThinBoard() thinBoard.SetPosition(50, self.dialogHeight) thinBoard.SetSize(191, 20) textLine = ui.TextLine() textLine.SetParent(thinBoard) textLine.SetFontName(localeInfo.UI_DEF_FONT) if player.GetItemCountByVnum(vnum) < count: textLine.SetPackedFontColor(0xFFffffff) if app.ENABLE_EXTRA_INVENTORY: if player.GetItemCountbyVnumExtraInventory(vnum) < count: textLine.SetPackedFontColor(0xFFffffff) else: textLine.SetPackedFontColor(0xFFffffff) if app.ENABLE_EXTRA_INVENTORY: if player.GetItemCountByVnum(vnum) > count: textLine.SetText("%s x%d |cFF42f557(%d)" % (item.GetItemName(), count, player.GetItemCountByVnum(vnum))) elif player.GetItemCountByVnum(vnum) == count: textLine.SetText("%s x%d |cFFffce00(%d)" % (item.GetItemName(), count, player.GetItemCountByVnum(vnum))) else: textLine.SetText("%s x%d |cFFff0000(%d)" % (item.GetItemName(), count, player.GetItemCountByVnum(vnum))) if player.GetItemCountbyVnumExtraInventory(vnum) > count: textLine.SetText("%s x%d |cFF42f557(%d)" % (item.GetItemName(), count, player.GetItemCountbyVnumExtraInventory(vnum))) elif player.GetItemCountbyVnumExtraInventory(vnum) == count: textLine.SetText("%s x%d |cFFffce00(%d)" % (item.GetItemName(), count, player.GetItemCountbyVnumExtraInventory(vnum))) else: textLine.SetText("%s x%d |cFFff0000(%d)" % (item.GetItemName(), count, player.GetItemCountbyVnumExtraInventory(vnum))) else: if player.GetItemCountByVnum(vnum) > count: textLine.SetText("%s x%d |cFF42f557(%d)" % (item.GetItemName(), count, player.GetItemCountByVnum(vnum))) elif player.GetItemCountByVnum(vnum) == count: textLine.SetText("%s x%d |cFFffce00(%d)" % (item.GetItemName(), count, player.GetItemCountByVnum(vnum))) else: textLine.SetText("%s x%d |cFFff0000(%d)" % (item.GetItemName(), count, player.GetItemCountByVnum(vnum))) textLine.SetOutline() textLine.SetFeather(False) textLine.SetWindowVerticalAlignCenter() textLine.SetVerticalAlignCenter() if localeInfo.IsARABIC(): (x,y) = textLine.GetTextSize() textLine.SetPosition(x, 0) else: textLine.SetPosition(15, 0) textLine.Show() self.children.append(textLine) self.dialogHeight += 34 self.UpdateDialog() def UpdateDialog(self): newWidth = self.toolTip.GetWidth() + 60 newHeight = self.dialogHeight + 75 ##if 936 == app.GetDefaultCodePage(): newHeight -= 8 if localeInfo.IsARABIC(): self.board.SetPosition( newWidth, 0 ) (x, y) = self.titleBar.GetLocalPosition() self.titleBar.SetPosition( newWidth - 15, y ) self.board.SetSize(newWidth, newHeight) self.toolTip.SetPosition(15 + 35, 38) self.titleBar.SetWidth(newWidth-15) self.SetSize(newWidth, newHeight) (x, y) = self.GetLocalPosition() self.SetPosition(x, y) def OpenQuestionDialog(self): if 100 == self.percentage: self.Accept() return if 5 == self.type: self.Accept() return dlgQuestion = uiCommon.QuestionDialog2() dlgQuestion.SetText2(localeInfo.REFINE_WARNING2) dlgQuestion.SetAcceptEvent(ui.__mem_func__(self.Accept)) dlgQuestion.SetCancelEvent(ui.__mem_func__(dlgQuestion.Close)) if 3 == self.type: dlgQuestion.SetText1(localeInfo.REFINE_DESTROY_WARNING_WITH_BONUS_PERCENT_1) dlgQuestion.SetText2(localeInfo.REFINE_DESTROY_WARNING_WITH_BONUS_PERCENT_2) elif 2 == self.type: dlgQuestion.SetText1(localeInfo.REFINE_DOWN_GRADE_WARNING) else: dlgQuestion.SetText1(localeInfo.REFINE_DESTROY_WARNING) dlgQuestion.Open() self.dlgQuestion = dlgQuestion def Accept(self): net.SendRefinePacket(self.targetItemPos, self.type) self.Close() def CancelRefine(self): net.SendRefinePacket(255, 255) self.Close() def OnPressEscapeKey(self): self.CancelRefine() return True if app.ENABLE_TRADABLE_ICON: def SetCanMouseEventSlot(self, slotIndex): itemInvenPage = slotIndex / player.INVENTORY_PAGE_SIZE localSlotPos = slotIndex - (itemInvenPage * player.INVENTORY_PAGE_SIZE) self.lockedItem = (-1, -1) if itemInvenPage == self.wndInventory.GetInventoryPageIndex(): self.wndInventory.wndItem.SetCanMouseEventSlot(localSlotPos) def SetCantMouseEventSlot(self, slotIndex): itemInvenPage = slotIndex / player.INVENTORY_PAGE_SIZE localSlotPos = slotIndex - (itemInvenPage * player.INVENTORY_PAGE_SIZE) self.lockedItem = (itemInvenPage, localSlotPos) if itemInvenPage == self.wndInventory.GetInventoryPageIndex(): self.wndInventory.wndItem.SetCantMouseEventSlot(localSlotPos) def SetInven(self, wndInventory): from _weakref import proxy self.wndInventory = proxy(wndInventory) def RefreshLockedSlot(self): if self.wndInventory: itemInvenPage, itemSlotPos = self.lockedItem if self.wndInventory.GetInventoryPageIndex() == itemInvenPage: self.wndInventory.wndItem.SetCantMouseEventSlot(itemSlotPos) self.wndInventory.wndItem.RefreshSlot() def OverInItem(self, slot): if self.toolTipMaterial: self.toolTipMaterial.SetItemToolTip(self.materialList[slot]) def OverOutItem(self): if self.toolTipMaterial: self.toolTipMaterial.HideToolTip() def __OnSelectEmptySlot(self, selectedSlotPos): isAttached = mouseModule.mouseController.isAttached() if isAttached: attachedSlotType = mouseModule.mouseController.GetAttachedType() attachedSlotPos = mouseModule.mouseController.GetAttachedSlotNumber() attachedItemCount = mouseModule.mouseController.GetAttachedItemCount() attachedItemIndex = mouseModule.mouseController.GetAttachedItemIndex() mouseModule.mouseController.DeattachObject() if app.ENABLE_EXTRA_INVENTORY: if attachedSlotType != player.SLOT_TYPE_INVENTORY and attachedSlotType != player.SLOT_TYPE_EXTRA_INVENTORY: return else: if player.SLOT_TYPE_INVENTORY != attachedSlotType: return if IS_UPGRADE_ITEM(player.GetItemIndex(attachedSlotPos)): #fix 12.01.2017 item.SelectItem(self.vnum) if item.GetItemType() == item.ITEM_TYPE_METIN: chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.REFINE_ERROR_ADD_PERC_STONES) return if attachedItemCount > 1 or attachedItemCount <= 0: chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.REFINE_ERROR_ITEM_COUNT) return for it in xrange(3): if selectedSlotPos == it and attachedItemIndex != REFINE_VNUM[it]: chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.REFINE_ERROR_ITEM_VNUM) return for it in xrange(3): if selectedSlotPos == it: if self.percentage + REFINE_TOTAL_PERCENTAGE["update"] + REFINE_PERCENTAGE[it] > 100: chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.REFINE_ERROR_ITEM_OVERFLOW_PERCENTAGE) return REFINE_MODE[it] = 1 REFINE_TOTAL_PERCENTAGE["update"] += REFINE_PERCENTAGE[it] self.slot.ClearSlot(selectedSlotPos) self.slot.SetItemSlot(selectedSlotPos, player.GetItemIndex(attachedSlotPos), player.GetItemCount(attachedSlotPos)) else: chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.REFINE_ERROR_ITEM_VNUM) def __OnSelectItemSlot(self, selectedSlotPos): for it in xrange(3): if selectedSlotPos == it: self.slot.ClearSlot(selectedSlotPos) REFINE_MODE[it] = 0 REFINE_TOTAL_PERCENTAGE["update"] -= REFINE_PERCENTAGE[it] def __OnOverInItem(self, slotIndex): for it in xrange(3): if slotIndex == it: self.tooltipMode.SetItemToolTip(REFINE_VNUM[it]) def __OnOverOutItem(self): if self.tooltipMode: self.tooltipMode.HideToolTip()