예제 #1
0
class QuestItemGui(InventoryItemGui):
    __module__ = __name__
    Width = PiratesGuiGlobals.InventoryPageWidth - PiratesGuiGlobals.GridSize
    Height = 0.2

    def __init__(self, quest):
        self.loadGui()
        questScroll = self.topGui.find('**/main_gui_quest_scroll')
        data = (UberDogGlobals.InventoryCategory.QUESTS, quest.getDoId())
        self.quest = quest
        InventoryItemGui.__init__(self,
                                  data,
                                  image=questScroll,
                                  image_color=(0.7, 0.7, 0.7, 1))
        self.initialiseoptions(QuestItemGui)
        self.accept(self.quest.getChangeEvent(), self._handleQuestChange)

    def destroy(self):
        self.destroyGui()
        DirectFrame.destroy(self)
        del self.quest
        self.ignoreAll()

    def createGui(self):
        reward = self.quest.getRewardText()
        if len(reward) > 1:
            if self.quest.isCompleteWithBonus():
                textFg = (0.1, 0.8, 0.1, 1)
                text = PLocalizer.QuestItemGuiCompleteFormat % {
                    'desc': self.quest.getStatusText(),
                    'return': self.quest.getReturnText(),
                    'reward': reward
                }
            else:
                textFg = PiratesGuiGlobals.TextFG2
                text = PLocalizer.QuestItemGuiIncompleteFormat % {
                    'desc': self.quest.getStatusText(),
                    'reward': reward
                }
        else:
            if self.quest.isCompleteWithBonus():
                textFg = (0.1, 0.8, 0.1, 1)
                text = PLocalizer.QuestItemGuiCompleteFormatNoReward % {
                    'desc': self.quest.getStatusText(),
                    'return': self.quest.getReturnText()
                }
            else:
                textFg = PiratesGuiGlobals.TextFG2
                text = PLocalizer.QuestItemGuiIncompleteFormatNoReward % {
                    'desc': self.quest.getStatusText()
                }
        self.descText = DirectLabel(
            parent=self,
            relief=None,
            text=text,
            text_align=TextNode.ALeft,
            text_scale=PiratesGuiGlobals.TextScaleLarge,
            text_fg=textFg,
            text_shadow=PiratesGuiGlobals.TextShadow,
            textMayChange=1,
            pos=(-0.1, 0, 0.1))
        bWidth = 0.2
        bHeight = 0.05
        bBorder = 0.005
        if self.quest.isDroppable():
            self.dropButton = GuiButton(parent=self,
                                        text=PLocalizer.Drop,
                                        pos=(0.8, 0, -0.02),
                                        command=self._dropQuest)
        else:
            self.dropButton = None
        self.shareButton = None
        return

    def destroyGui(self):
        self.descText.destroy()
        del self.descText
        if self.dropButton:
            self.dropButton.destroy()
            del self.dropButton
        if self.shareButton:
            self.shareButton.destroy()
            del self.shareButton

    def _handleQuestChange(self):
        self.destroyGui()
        self.createGui()

    def _dropQuest(self):
        self.dropButton.hide()
        localAvatar.requestDropQuest(self.quest.getQuestId())

    def _shareQuest(self):
        localAvatar.requestShareQuest(self.quest.getQuestId())
class QuestItemGui(InventoryItemGui):
    Width = PiratesGuiGlobals.InventoryPageWidth - PiratesGuiGlobals.GridSize
    Height = 0.20000000000000001
    
    def __init__(self, quest):
        self.loadGui()
        questScroll = self.topGui.find('**/main_gui_quest_scroll')
        data = (UberDogGlobals.InventoryCategory.QUESTS, quest.getDoId())
        self.quest = quest
        InventoryItemGui.__init__(self, data, image = questScroll, image_color = (0.69999999999999996, 0.69999999999999996, 0.69999999999999996, 1))
        self.initialiseoptions(QuestItemGui)
        self.accept(self.quest.getChangeEvent(), self._handleQuestChange)

    
    def destroy(self):
        self.destroyGui()
        DirectFrame.destroy(self)
        del self.quest
        self.ignoreAll()

    
    def createGui(self):
        reward = self.quest.getRewardText()
        if len(reward) > 1:
            if self.quest.isCompleteWithBonus():
                textFg = (0.10000000000000001, 0.80000000000000004, 0.10000000000000001, 1)
                text = PLocalizer.QuestItemGuiCompleteFormat % {
                    'desc': self.quest.getStatusText(),
                    'return': self.quest.getReturnText(),
                    'reward': reward }
            else:
                textFg = PiratesGuiGlobals.TextFG2
                text = PLocalizer.QuestItemGuiIncompleteFormat % {
                    'desc': self.quest.getStatusText(),
                    'reward': reward }
        elif self.quest.isCompleteWithBonus():
            textFg = (0.10000000000000001, 0.80000000000000004, 0.10000000000000001, 1)
            text = PLocalizer.QuestItemGuiCompleteFormatNoReward % {
                'desc': self.quest.getStatusText(),
                'return': self.quest.getReturnText() }
        else:
            textFg = PiratesGuiGlobals.TextFG2
            text = PLocalizer.QuestItemGuiIncompleteFormatNoReward % {
                'desc': self.quest.getStatusText() }
        self.descText = DirectLabel(parent = self, relief = None, text = text, text_align = TextNode.ALeft, text_scale = PiratesGuiGlobals.TextScaleLarge, text_fg = textFg, text_shadow = PiratesGuiGlobals.TextShadow, textMayChange = 1, pos = (-0.10000000000000001, 0, 0.10000000000000001))
        bWidth = 0.20000000000000001
        bHeight = 0.050000000000000003
        bBorder = 0.0050000000000000001
        if self.quest.isDroppable():
            self.dropButton = GuiButton(parent = self, text = PLocalizer.Drop, pos = (0.80000000000000004, 0, -0.02), command = self._dropQuest)
        else:
            self.dropButton = None
        self.shareButton = None

    
    def destroyGui(self):
        self.descText.destroy()
        del self.descText
        if self.dropButton:
            self.dropButton.destroy()
            del self.dropButton
        
        if self.shareButton:
            self.shareButton.destroy()
            del self.shareButton
        

    
    def _handleQuestChange(self):
        self.destroyGui()
        self.createGui()

    
    def _dropQuest(self):
        self.dropButton.hide()
        localAvatar.requestDropQuest(self.quest.getQuestId())

    
    def _shareQuest(self):
        localAvatar.requestShareQuest(self.quest.getQuestId())
class WeaponPage(InventoryPage.InventoryPage):
    
    def __init__(self):
        InventoryPage.InventoryPage.__init__(self)
        self.initialiseoptions(WeaponPage)
        self.weaponPanels = { }
        self.tonicButtons = { }
        self.fishingIcon = None
        self.potionIcon = None
        self.fishingRepMeter = None
        self.potionRepMeter = None
        self.fishingPoleName = None
        self.fishingChangeMsg = None
        self.needRefresh = 1
        self.showing = 0

    
    def show(self):
        self.showing = 1
        InventoryPage.InventoryPage.show(self)
        if self.needRefresh:
            self.refreshList()
            self.needRefresh = 0
        

    
    def hide(self):
        self.showing = 0
        self.equipStatus = 0
        InventoryPage.InventoryPage.hide(self)

    
    def tonicCallback(self, skillId):
        localAvatar.guiMgr.combatTray.trySkill(InventoryType.UseItem, skillId, 0)

    
    def rePanel(self, inventory):
        if not self.showing:
            self.needRefresh = 1
            return None
        
        skillTokens = {
            InventoryType.CutlassToken: (ItemGlobals.RUSTY_CUTLASS,),
            InventoryType.PistolToken: (ItemGlobals.FLINTLOCK_PISTOL,),
            InventoryType.DollToken: (ItemGlobals.VOODOO_DOLL,),
            InventoryType.DaggerToken: (ItemGlobals.BASIC_DAGGER,),
            InventoryType.GrenadeToken: (ItemGlobals.GRENADE_POUCH,),
            InventoryType.WandToken: (ItemGlobals.CURSED_STAFF,) }
        zIndex = 1
        for skillTokenKey in TOKEN_LIST:
            quantity = 0
            if localAvatar.getInventory().stacks.get(skillTokenKey):
                quantity = 1
            
            skillData = skillTokens[skillTokenKey]
            weaponId = skillData[0]
            key = None
            panel = WeaponPanel.WeaponPanel((weaponId, quantity), key)
            panel.reparentTo(self)
            panel.setZ(PiratesGuiGlobals.InventoryPanelHeight - 0.17999999999999999 - zIndex * panel.height)
            zIndex += 1
            repCat = WeaponGlobals.getRepId(weaponId)
            self.weaponPanels[repCat] = panel
            self.ignore('inventoryQuantity-%s' % inventory.getDoId())
            self.acceptOnce('inventoryQuantity-%s-%s' % (inventory.getDoId(), skillTokenKey), self.refreshList)
        
        repIcon_gui = loader.loadModel('models/textureCards/skillIcons')
        repIcon = repIcon_gui.find('**/box_base')
        if config.GetBool('want-fishing-game', 0):
            self.fishingIcon = GuiButton(pos = (0.16600000000000001, 0, 0.044999999999999998 + (PiratesGuiGlobals.InventoryPanelHeight - 0.17999999999999999) - zIndex * panel.height), helpText = PLocalizer.FishingRepDescription, helpOpaque = True, image = (repIcon, repIcon, repIcon, repIcon), image_scale = (0.14399999999999999, 0.14399999999999999, 0.14399999999999999))
            fishIconCard = loader.loadModel('models/textureCards/fishing_icons')
            inv = localAvatar.getInventory()
            fishingChangeMsg = InventoryGlobals.getCategoryQuantChangeMsg(inv.doId, InventoryType.FishingRod)
            if self.fishingChangeMsg:
                self.ignore(fishingChangeMsg)
            
            self.fishingChangeMsg = fishingChangeMsg
            self.acceptOnce(fishingChangeMsg, self.refreshList)
            rodIcons = [
                'pir_t_gui_fsh_smRodIcon',
                'pir_t_gui_fsh_mdRodIcon',
                'pir_t_gui_fsh_lgRodIcon']
            rodLvl = inv.getStackQuantity(InventoryType.FishingRod)
            rodIcon = rodIcons[rodLvl - 1]
            rodText = PLocalizer.FishingRodNames[rodLvl]
            if rodLvl >= 1:
                self.fishingIcon['geom'] = fishIconCard.find('**/' + rodIcon)
            
            self.fishingIcon['geom_scale'] = 0.10000000000000001
            self.fishingIcon['geom_pos'] = (0, 0, 0)
            self.fishingIcon.reparentTo(self)
            fishingRepValue = localAvatar.getInventory().getReputation(InventoryType.FishingRep)
            self.fishingRepMeter = ReputationMeter(InventoryType.FishingRep, width = 0.66000000000000003)
            self.fishingRepMeter.setPos(0.62, 0, 0.041000000000000002 + (PiratesGuiGlobals.InventoryPanelHeight - 0.17999999999999999) - zIndex * panel.height)
            self.fishingRepMeter.update(fishingRepValue)
            self.fishingRepMeter.reparentTo(self)
            self.fishingRepMeter.flattenLight()
            self.fishingPoleName = DirectLabel(parent = self, relief = None, state = DGG.DISABLED, text = rodText, text_scale = PiratesGuiGlobals.TextScaleSmall, text_align = TextNode.ALeft, text_fg = PiratesGuiGlobals.TextFG2, text_shadow = PiratesGuiGlobals.TextShadow, pos = (0.28999999999999998, 0, -0.0050000000000000001 + (PiratesGuiGlobals.InventoryPanelHeight - 0.17999999999999999) - 7 * panel.height), text_font = PiratesGlobals.getInterfaceFont())
            self.fishingPoleName.reparentTo(self)
            zIndex += 1
        
        iconCard = loader.loadModel('models/textureCards/skillIcons')
        if config.GetBool('want-potion-game', 0):
            self.potionIcon = GuiButton(pos = (0.16600000000000001, 0, 0.044999999999999998 + (PiratesGuiGlobals.InventoryPanelHeight - 0.17999999999999999) - zIndex * panel.height), helpText = PLocalizer.PotionRepDescription, helpOpaque = True, image = (repIcon, repIcon, repIcon, repIcon), image_scale = (0.14399999999999999, 0.14399999999999999, 0.14399999999999999))
            self.potionIcon['geom'] = iconCard.find('**/pir_t_gui_pot_base')
            self.potionIcon['geom_scale'] = 0.10000000000000001
            self.potionIcon['geom_pos'] = (0, 0, 0)
            self.potionIcon.reparentTo(self)
            potionRepValue = localAvatar.getInventory().getReputation(InventoryType.PotionsRep)
            self.potionRepMeter = ReputationMeter(InventoryType.PotionsRep, width = 0.66000000000000003)
            self.potionRepMeter.setPos(0.62, 0, 0.041000000000000002 + (PiratesGuiGlobals.InventoryPanelHeight - 0.17999999999999999) - zIndex * panel.height)
            self.potionRepMeter.update(potionRepValue)
            self.potionRepMeter.reparentTo(self)
            self.potionRepMeter.flattenLight()
            zIndex += 1
        
        items = dict(map(lambda x: (x.getType(), x.getCount()), inventory.getConsumables().values()))
        possibleItems = ItemGlobals.getAllHealthIds()
        havePorky = items.get(ItemGlobals.ROAST_PORK)
        if not havePorky and ItemGlobals.ROAST_PORK in possibleItems:
            possibleItems.remove(ItemGlobals.ROAST_PORK)
        
        offset = 0
        if base.config.GetBool('want-potion-game', 0):
            items = inventory.getConsumables()
            listLength = len(InventoryType.PotionMinigamePotions)
            count = 0
            for i in range(listLength):
                tonicId = InventoryType.PotionMinigamePotions[i]
                if items.get(tonicId):
                    button = SkillButton(tonicId, self.tonicCallback, items.get(tonicId), showQuantity = True, showHelp = True, showRing = True)
                    button.skillButton['geom_scale'] = 0.080000000000000002
                    x = 0.16 * (count % 6) + -1.2
                    z = 1.0 - int(count / 6) * 0.16
                    button.setPos(x, 0, z)
                    button.reparentTo(self)
                    self.tonicButtons[tonicId] = button
                    count += 1
                    continue
            
        

    
    def refreshList(self, newWeaponId = None):
        for panel in self.weaponPanels.values():
            panel.destroy()
        
        for panel in self.tonicButtons.values():
            panel.destroy()
        
        if self.fishingIcon is not None:
            self.fishingIcon.destroy()
        
        if self.potionIcon is not None:
            self.potionIcon.destroy()
        
        if self.fishingRepMeter is not None:
            self.fishingRepMeter.destroy()
        
        if self.potionRepMeter is not None:
            self.potionRepMeter.destroy()
        
        if self.fishingPoleName is not None:
            self.fishingPoleName.destroy()
        
        inventory = localAvatar.getInventory()
        if inventory:
            if inventory.isReady():
                self.rePanel(inventory)
            else:
                self.ignore('inventoryReady-%s' % inventory.getDoId())
                self.acceptOnce('inventoryReady-%s' % inventory.getDoId(), self.rePanel)
        

    
    def destroy(self):
        if self.fishingChangeMsg:
            self.ignore(self.fishingChangeMsg)
        
        InventoryPage.InventoryPage.destroy(self)

    
    def updateTonics(self):
        if not hasattr(base, 'localAvatar'):
            return None
        
        inv = localAvatar.getInventory()
        if not inv:
            return None
        
        possibleTonics = ItemGlobals.getAllHealthIds()
        for tonicId in possibleTonics:
            tonicAmt = inv.getItemQuantity(InventoryType.ItemTypeConsumable, tonicId)
            if self.tonicButtons.has_key(tonicId):
                self.tonicButtons[tonicId].updateQuantity(tonicAmt)
                self.tonicButtons[tonicId].checkAmount()
                continue