Beispiel #1
0
class PVPCompletePanel(BorderFrame):
    SUMMARY_PAGE = 1
    DETAILS_PAGE = 2
    
    def __init__(self, name, pvp):
        self.width = PiratesGuiGlobals.PVPCompletePanelWidth
        self.height = PiratesGuiGlobals.PVPCompletePanelHeight
        BorderFrame.__init__(self, frameSize = (self.width * 0.14999999999999999, self.width * 0.84999999999999998, self.height * 0.81999999999999995, self.height), modelName = 'pir_m_gui_frm_subframe', imageColorScale = VBase4(0.75, 0.75, 0.94999999999999996, 0.75))
        self.secondLayer = BorderFrame(parent = self, relief = None, frameSize = (self.width * 0.14999999999999999, self.width * 0.84999999999999998, self.height * 0.81999999999999995, self.height), modelName = 'pir_m_gui_frm_subframe', imageColorScale = VBase4(0.75, 0.75, 0.90000000000000002, 0.75))
        self.initialiseoptions(PVPCompletePanel)
        self.endButton = GuiButton(parent = self, text = PLocalizer.PVPExit, command = pvp.requestPVPLeave, pos = (1.25, 0, 0.10000000000000001), image = GuiButton.redGenericButton, image_scale = 0.59999999999999998)
        self.endButton.setBin('gui-popup', 0)
        self.name = name
        self.title = DirectLabel(parent = self, relief = None, text = name, text_align = TextNode.ACenter, text_scale = 0.070000000000000007, text_fg = PiratesGuiGlobals.TextFG1, text_shadow = PiratesGuiGlobals.TextShadow, textMayChange = 1, pos = (1.25, 0, 1.6200000000000001))
        if pvp.hasTeams():
            team1Score = '0'
            team2Score = '0'
            for stat in pvp.scoreboardHolder.getItemList():
                if stat['Team'] == 1:
                    team1Score = stat['Score']
                    continue
                if stat['Team'] == 2:
                    team2Score = stat['Score']
                    continue
            
            self.team1ScoreLabel = DirectLabel(parent = self, relief = None, text = PLocalizer.PVPTeamScore % (1, team1Score), text_align = TextNode.ACenter, text_scale = 0.040000000000000001, text_fg = PVPGlobals.getTeamColor(1), text_shadow = PiratesGuiGlobals.TextShadow, textMayChange = 1, pos = (1.05, 0, 1.55))
            self.team2ScoreLabel = DirectLabel(parent = self, relief = None, text = PLocalizer.PVPTeamScore % (2, team2Score), text_align = TextNode.ACenter, text_scale = 0.040000000000000001, text_fg = PVPGlobals.getTeamColor(2), text_shadow = PiratesGuiGlobals.TextShadow, textMayChange = 1, pos = (1.45, 0, 1.55))
        
        self.outcome = DirectLabel(parent = self, relief = None, text = '', text_align = TextNode.ACenter, text_scale = 0.059999999999999998, text_fg = PiratesGuiGlobals.TextFG1, text_shadow = PiratesGuiGlobals.TextShadow, textMayChange = 1, pos = (1.25, 0, 1.45))
        if pvp.hasTeams():
            if team1Score > team2Score:
                self.outcome['text_fg'] = PVPGlobals.getTeamColor(1)
            elif team2Score > team1Score:
                self.outcome['text_fg'] = PVPGlobals.getTeamColor(2)
            
        
        self.borderTwo = BorderFrame(parent = self, relief = None, frameSize = (self.width * 0.14999999999999999, self.width * 0.84999999999999998, 0, self.height * 0.80000000000000004), modelName = 'pir_m_gui_frm_subframe', imageColorScale = VBase4(0.75, 0.75, 0.90000000000000002, 0.75))
        self.borderTwoSecondLayer = BorderFrame(parent = self.borderTwo, relief = None, frameSize = (self.width * 0.14999999999999999, self.width * 0.84999999999999998, 0, self.height * 0.80000000000000004), modelName = 'pir_m_gui_frm_subframe', imageColorScale = VBase4(0.75, 0.75, 0.90000000000000002, 0.75))
        self.two = ScoreFrame(PiratesGuiGlobals.PVPCompletePageWidth - 1.0, PiratesGuiGlobals.PVPCompletePageHeight, pvp.statsHolder, 0, sortOrder = 2)
        self.two.reparentTo(self.borderTwo)
        self.two.setPos(0.45000000000000001, 0, -0.14999999999999999)
        self.two.setup()
        self.game = pvp

    
    def setOutcome(self, outcome):
        self.outcome['text'] = outcome

    
    def destroy(self):
        self.borderTwoSecondLayer.destroy()
        self.borderTwoSecondLayer = None
        self.borderTwo.destroy()
        self.borderTwo = None
        self.two.destroy()
        self.two = None
        self.secondLayer.destroy()
        self.secondLater = None
        self.game = None
        BorderFrame.destroy(self)
Beispiel #2
0
class RepairGameGUI(DirectFrame):
    completeSound = None
    guiDownSound = None
    guiUpSound = None
    shipRepairMusic = None

    def __init__(self, repairGame):
        DirectFrame.__init__(self, parent=base.a2dBackground, relief=None)
        self.repairGame = repairGame
        base.loadingScreen.beginStep('Sound', 1, 10)
        self._initSound()
        base.loadingScreen.endStep('Sound')
        base.loadingScreen.beginStep('GUI', 1, 43)
        self._initGUI()
        base.loadingScreen.endStep('GUI')
        self.accept('clientLogout', self.handleExitGame)
        if base.localAvatar.guiMgr.seaChestActive:
            base.localAvatar.guiMgr.hideSeaChest()

        if base.localAvatar.guiMgr.minimap:
            base.localAvatar.guiMgr.hideMinimap()

        self.accept('seachestOpened', self.handleExitGame)
        self.accept('avatarDetailsOpened', self.handleExitGame)
        self.accept('minimapOpened', self.handleExitGame)
        self.setBin('fixed', 30)
        self.setZ(-0.20000000000000001)
        base.loadingScreen.beginStep('Intervals')
        self._initIntervals()
        base.loadingScreen.endStep('Intervals')

    def _initSound(self):
        if not self.completeSound:
            RepairGameGUI.completeSound = loadSfx(
                SoundGlobals.SFX_MINIGAME_REPAIR_GENERAL_CYCLECOMPLETE)
            RepairGameGUI.guiDownSound = loadSfx(
                SoundGlobals.SFX_MINIGAME_REPAIR_GENERAL_GUIDOWN)
            RepairGameGUI.guiUpSound = loadSfx(
                SoundGlobals.SFX_MINIGAME_REPAIR_GENERAL_GUIUP)
            RepairGameGUI.guiDownSound.setVolume(0.5)
            RepairGameGUI.guiUpSound.setVolume(0.5)
            RepairGameGUI.shipRepairMusic = [
                SoundGlobals.MUSIC_PERFORMERS_02,
                SoundGlobals.MUSIC_PERFORMERS_07,
                SoundGlobals.MUSIC_PERFORMERS_09
            ]

        base.musicMgr.request(random.choice(self.shipRepairMusic),
                              priority=1,
                              volume=0.5)

    def _initGUI(self):
        self.model = loader.loadModel('models/gui/pir_m_gui_srp_main')
        self.repairGamePicker = RepairGamePickerGUI(
            self, self.repairGame, self.model.find('**/group_picker'))
        self.staticElements = GUIFactory.generateStaticElements(
            self.model.getChild(0), self)
        self.textElements = {}
        self.textElements['title'] = DirectLabel(
            text='',
            text_fg=(1.0, 1.0, 1.0, 1.0),
            text_shadow=(0.0, 0.0, 0.0, 1.0),
            scale=(0.087499999999999994, 0.087499999999999994,
                   0.087499999999999994),
            pos=(0.0, 0.0, 0.91000000000000003),
            relief=None,
            textMayChange=1,
            text_font=PiratesGlobals.getPirateFont(),
            parent=self.staticElements['bg'])
        self.textElements['tutorial'] = DirectLabel(
            text='',
            text_fg=(1.0, 1.0, 1.0, 1.0),
            text_shadow=(0.0, 0.0, 0.0, 1.0),
            text_wordwrap=14,
            scale=(0.044999999999999998, 0.044999999999999998,
                   0.044999999999999998),
            pos=(0.0, 0.0, 0.79500000000000004),
            relief=None,
            textMayChange=1,
            text_font=PiratesGlobals.getPirateFont(),
            parent=self.staticElements['bg'])
        self.textElements['level'] = DirectLabel(
            text='',
            text_fg=(1.0, 1.0, 1.0, 1.0),
            scale=(0.052499999999999998, 0.052499999999999998,
                   0.052499999999999998),
            pos=(0.315, 0.0, 0.69999999999999996),
            relief=None,
            textMayChange=1,
            text_align=TextNode.ARight,
            text_font=PiratesGlobals.getPirateFont(),
            parent=self.staticElements['bg'])
        self.textElements['level'].stash()
        self.textElements['idleMessage'] = DirectLabel(
            text='',
            text_fg=(1.0, 1.0, 1.0, 1.0),
            text_shadow=(0.0, 0.0, 0.0, 1.0),
            text_wordwrap=15,
            scale=(0.087499999999999994, 0.087499999999999994,
                   0.087499999999999994),
            pos=(0.0, 0.0, 0.0),
            relief=None,
            textMayChange=1,
            text_font=PiratesGlobals.getPirateFont(),
            parent=self.staticElements['bg'])
        self.textElements['cycleCompleteMessage'] = DirectLabel(
            text='',
            text_fg=(1.0, 1.0, 1.0, 1.0),
            text_shadow=(0.0, 0.0, 0.0, 1.0),
            text_wordwrap=20,
            scale=(0.087499999999999994, 0.087499999999999994,
                   0.087499999999999994),
            pos=(0.0, 0.0, 0.0),
            relief=None,
            textMayChange=1,
            text_font=PiratesGlobals.getPirateFont(),
            parent=self.staticElements['bg'])
        self.closeButton = GuiButton(
            image=(self.model.find('**/esc_button/idle'),
                   self.model.find('**/esc_button/over'),
                   self.model.find('**/esc_button/over'),
                   self.model.find('**/esc_button/idle')),
            image_scale=(0.75, 0.75, 0.75),
            image_pos=(0.074999999999999997, 0, 0.080000000000000002),
            hotkeys=['Escape'],
            hotkeyLabel=PLocalizer.Minigame_Repair_Leave_Game_Text,
            pos=(-0.40000000000000002, 0.0, 0.01),
            parent=base.a2dBottomRight,
            command=self.handleExitGame)
        self.closeButton.setBin('background', -90)
        self.model.removeNode()
        del self.model

    def setPickerOutroStartPos(self):
        self.pickerOutroLerp.setStartPos(self.repairGamePicker.getPos())

    def setBGOutroStartPos(self):
        self.bgOutroLerp.setStartPos(self.staticElements['bg'].getPos())

    def _initIntervals(self):
        self.bgIntroLerp = LerpPosInterval(
            self.staticElements['bg'],
            duration=1.0,
            pos=self.staticElements['bg'].getPos(),
            startPos=(0.0, 0.0, 2.0))
        self.pickerIntroLerp = LerpPosInterval(
            self.repairGamePicker,
            duration=1.0,
            pos=self.repairGamePicker.getPos(),
            startPos=(0.0, 0.0, -1.0))
        self.introSequence = Sequence(
            Func(self.repairGamePicker.setEnabled, False),
            Parallel(Sequence(Wait(0.25), Func(self.guiDownSound.play)),
                     self.bgIntroLerp, self.pickerIntroLerp),
            Func(self.repairGamePicker.setEnabled, True),
            Func(self.repairGame.gameFSM.request, 'Idle'),
            name='RepairGame.introSequence')
        self.pickerOutroLerp = LerpPosInterval(
            self.repairGamePicker,
            duration=1.0,
            startPos=self.repairGamePicker.getPos(),
            pos=(0.0, 0.0, -1.0))
        self.bgOutroLerp = LerpPosInterval(
            self.staticElements['bg'],
            duration=1.0,
            startPos=self.repairGamePicker.getPos(),
            pos=(0.0, 0.0, 2.0))
        self.outroSequence = Sequence(
            Func(self.repairGamePicker.stashTab),
            Func(self.closeButton.stash),
            Parallel(Func(self.guiUpSound.play),
                     Func(self.setPickerOutroStartPos),
                     Func(self.setBGOutroStartPos), self.pickerOutroLerp,
                     self.bgOutroLerp),
            Func(self.repairGame.cleanup),
            name='RepairGame.outroSequence')
        self.cycleCompleteSequence = Sequence(
            Func(self.showCycleCompleteMessage),
            Func(self.repairGamePicker.stashTab),
            Wait(self.getCycleCompleteWaitTime()),
            Func(self.completeSound.play),
            Func(self.hideCycleCompleteMessage),
            LerpPosInterval(self.repairGamePicker,
                            duration=0.5,
                            pos=self.repairGamePicker.getPos() - (0, 0, 1.0)),
            Func(self.repairGame.resetMincroGameProgress),
            LerpPosInterval(self.repairGamePicker,
                            duration=0.5,
                            pos=self.repairGamePicker.getPos()),
            Func(self.repairGame.gameFSM.request, 'Idle'),
            name='RepairGame.cycleCompleteSequence')
        self.shakeSequence = Sequence(name='RepairGameGUI.shakeSequence')

    def handleExitGame(self):
        messenger.send('escape')

    def getCycleCompleteWaitTime(self):
        if self.repairGame.location == ON_LAND:
            return 5.5
        else:
            return 1.5

    def showCycleCompleteMessage(self):
        if self.repairGame.location == ON_LAND:
            tpMgr = TextPropertiesManager.getGlobalPtr()
            tpGold = TextProperties()
            tpGold.setTextColor(0.97999999999999998, 0.76000000000000001, 0, 1)
            tpMgr.setProperties('gold', tpGold)
            completionTime = self.repairGame.getCycleCompleteTime()
            seconds = completionTime % 60
            minutes = int(completionTime / 60.0)
            if minutes == 0:
                time = '\x1gold\x1%i %s\x2' % (
                    seconds, PLocalizer.Minigame_Repair_Seconds)
            elif seconds < 10:
                time = '\x1gold\x1%i:0%i %s\x2' % (
                    minutes, seconds, PLocalizer.Minigame_Repair_Minutes)
            else:
                time = '\x1gold\x1%i:%i %s\x2' % (
                    minutes, seconds, PLocalizer.Minigame_Repair_Minutes)
            goldAmount = self.repairGame.getReward(localAvatar.doId)
            goldBonus = self.repairGame.getGoldBonus()
            if goldBonus:
                reward = PLocalizer.Minigame_Repair_GoldBonus % (
                    str(goldAmount), str(goldBonus))
            else:
                reward = PLocalizer.Minigame_Repair_Gold % str(goldAmount)
            text = PLocalizer.Minigame_Repair_BenchOutro % (time, reward)
            self.textElements['cycleCompleteMessage'].setPos(
                0.0, 0.0, 0.34999999999999998)
        else:
            text = PLocalizer.Minigame_Repair_ShipOutro
            self.textElements['cycleCompleteMessage'].setPos(
                0.0, 0.0, 0.14999999999999999)
        self.textElements['cycleCompleteMessage']['text'] = text
        self.textElements['cycleCompleteMessage'].setText()

    def hideCycleCompleteMessage(self):
        self.textElements['cycleCompleteMessage']['text'] = ''
        self.textElements['cycleCompleteMessage'].setText()

    def showIdleMessage(self):
        if self.repairGame.location == ON_LAND:
            text = PLocalizer.Minigame_Repair_BenchIntro
            self.textElements['idleMessage'].setPos(0.0, 0.0,
                                                    0.34999999999999998)
        else:
            text = PLocalizer.Minigame_Repair_ShipIntro
            self.textElements['idleMessage'].setPos(0.0, 0.0,
                                                    0.17499999999999999)
        self.textElements['idleMessage']['text'] = text
        self.textElements['idleMessage'].setText()

    def hideIdleMessage(self):
        self.textElements['idleMessage']['text'] = ''
        self.textElements['idleMessage'].setText()

    def onShipDamaged(self, wasGrapeshot=False):
        if wasGrapeshot:
            shakeDelta = 0.050000000000000003
            randomX = random.random() * 2 * shakeDelta - shakeDelta
            randomZ = random.random() * 2 * shakeDelta - shakeDelta
            if self.shakeSequence.isPlaying():
                self.shakeSequence.finish()

            self.shakeSequence = Parallel(
                Sequence(
                    LerpColorScaleInterval(
                        self,
                        duration=0.5,
                        colorScale=(1.0, 0.20000000000000001,
                                    0.20000000000000001, 1.0)),
                    LerpColorScaleInterval(
                        self,
                        duration=RepairGlobals.Common.guiShakeCooldownTime /
                        2.0,
                        colorScale=(1.0, 1.0, 1.0, 1.0))),
                Sequence(
                    LerpPosInterval(self,
                                    duration=0.10000000000000001,
                                    pos=self.getPos() -
                                    (randomX, 0.0, randomZ)),
                    LerpPosInterval(self,
                                    duration=0.20000000000000001,
                                    pos=self.getPos() +
                                    (randomX, 0.0, randomZ)),
                    LerpPosInterval(self,
                                    duration=0.10000000000000001,
                                    pos=self.getPos()),
                    Wait(RepairGlobals.Common.guiShakeCooldownTime)),
                name='RepairGameGUI.shakeSequence')
            self.shakeSequence.start()
        else:
            shakeDelta = 0.025000000000000001
            randomX = random.random() * 2 * shakeDelta - shakeDelta
            randomZ = random.random() * 2 * shakeDelta - shakeDelta
            if not self.shakeSequence.isPlaying():
                self.shakeSequence = Sequence(
                    LerpPosInterval(self,
                                    duration=0.10000000000000001,
                                    pos=self.getPos() -
                                    (randomX, 0.0, randomZ)),
                    LerpPosInterval(self,
                                    duration=0.20000000000000001,
                                    pos=self.getPos() +
                                    (randomX, 0.0, randomZ)),
                    LerpPosInterval(self,
                                    duration=0.10000000000000001,
                                    pos=self.getPos()),
                    Wait(RepairGlobals.Common.guiShakeCooldownTime),
                    name='RepairGameGUI.shakeSequence')
                self.shakeSequence.start()

    def setTutorial(self, game, index=None):
        text = PLocalizer.Minigame_Tutorials[game]
        if index is not None:
            text = text[index]

        self.textElements['tutorial']['text'] = text
        self.textElements['tutorial'].setText()

    def clearTutorial(self):
        self.textElements['tutorial']['text'] = ''
        self.textElements['tutorial'].setText()

    def setRepairTitle(self):
        self.setTitle('repair')

    def setTitle(self, game):
        text = (PLocalizer.Minigame_Repair_Names[game], )
        self.textElements['title']['text'] = text
        self.textElements['title'].setText()

    def clearTitle(self):
        self.textElements['title']['text'] = ''
        self.textElements['title'].setText()

    def setDifficulty(self, difficulty):
        self.textElements['level'][
            'text'] = PLocalizer.Minigame_Repair_Level % str(difficulty + 1)
        self.textElements['level'].setText()

    def setReward(self, reward):
        self.currentReward = reward

    def setGames(self, gameList):
        self.repairGamePicker.setGames(gameList)

    def resetGames(self):
        self.repairGamePicker.setEnabled(True)

    def setProgress(self, gameIndex, percent):
        self.repairGamePicker.setProgress(gameIndex, percent)

    def updatePirateNamesPerMincrogame(self, avIds2CurrentGameIndex):
        self.repairGamePicker.updatePirateNamesPerMincrogame(
            avIds2CurrentGameIndex)

    def destroy(self):
        self.ignore('clientLogout')
        self.ignore('seachestOpened')
        self.ignore('avatarDetailsOpened')
        self.ignore('minimapOpened')
        self.introSequence.clearToInitial()
        self.outroSequence.clearToInitial()
        self.cycleCompleteSequence.clearToInitial()
        self.shakeSequence.clearToInitial()
        del self.introSequence
        del self.outroSequence
        del self.cycleCompleteSequence
        del self.shakeSequence
        self.closeButton.destroy()
        self.closeButton.removeNode()
        del self.closeButton
        GUIFactory.destroyDirectGUIDict(self.staticElements)
        del self.staticElements
        self.repairGamePicker.destroy()
        del self.repairGamePicker
        self.removeNode()
class PVPCompletePanel(BorderFrame):
    SUMMARY_PAGE = 1
    DETAILS_PAGE = 2

    def __init__(self, name, pvp):
        self.width = PiratesGuiGlobals.PVPCompletePanelWidth
        self.height = PiratesGuiGlobals.PVPCompletePanelHeight
        BorderFrame.__init__(self,
                             frameSize=(self.width * 0.14999999999999999,
                                        self.width * 0.84999999999999998,
                                        self.height * 0.81999999999999995,
                                        self.height),
                             modelName='pir_m_gui_frm_subframe',
                             imageColorScale=VBase4(0.75, 0.75,
                                                    0.94999999999999996, 0.75))
        self.secondLayer = BorderFrame(
            parent=self,
            relief=None,
            frameSize=(self.width * 0.14999999999999999,
                       self.width * 0.84999999999999998,
                       self.height * 0.81999999999999995, self.height),
            modelName='pir_m_gui_frm_subframe',
            imageColorScale=VBase4(0.75, 0.75, 0.90000000000000002, 0.75))
        self.initialiseoptions(PVPCompletePanel)
        self.endButton = GuiButton(parent=self,
                                   text=PLocalizer.PVPExit,
                                   command=pvp.requestPVPLeave,
                                   pos=(1.25, 0, 0.10000000000000001),
                                   image=GuiButton.redGenericButton,
                                   image_scale=0.59999999999999998)
        self.endButton.setBin('gui-popup', 0)
        self.name = name
        self.title = DirectLabel(parent=self,
                                 relief=None,
                                 text=name,
                                 text_align=TextNode.ACenter,
                                 text_scale=0.070000000000000007,
                                 text_fg=PiratesGuiGlobals.TextFG1,
                                 text_shadow=PiratesGuiGlobals.TextShadow,
                                 textMayChange=1,
                                 pos=(1.25, 0, 1.6200000000000001))
        if pvp.hasTeams():
            team1Score = '0'
            team2Score = '0'
            for stat in pvp.scoreboardHolder.getItemList():
                if stat['Team'] == 1:
                    team1Score = stat['Score']
                    continue
                if stat['Team'] == 2:
                    team2Score = stat['Score']
                    continue

            self.team1ScoreLabel = DirectLabel(
                parent=self,
                relief=None,
                text=PLocalizer.PVPTeamScore % (1, team1Score),
                text_align=TextNode.ACenter,
                text_scale=0.040000000000000001,
                text_fg=PVPGlobals.getTeamColor(1),
                text_shadow=PiratesGuiGlobals.TextShadow,
                textMayChange=1,
                pos=(1.05, 0, 1.55))
            self.team2ScoreLabel = DirectLabel(
                parent=self,
                relief=None,
                text=PLocalizer.PVPTeamScore % (2, team2Score),
                text_align=TextNode.ACenter,
                text_scale=0.040000000000000001,
                text_fg=PVPGlobals.getTeamColor(2),
                text_shadow=PiratesGuiGlobals.TextShadow,
                textMayChange=1,
                pos=(1.45, 0, 1.55))

        self.outcome = DirectLabel(parent=self,
                                   relief=None,
                                   text='',
                                   text_align=TextNode.ACenter,
                                   text_scale=0.059999999999999998,
                                   text_fg=PiratesGuiGlobals.TextFG1,
                                   text_shadow=PiratesGuiGlobals.TextShadow,
                                   textMayChange=1,
                                   pos=(1.25, 0, 1.45))
        if pvp.hasTeams():
            if team1Score > team2Score:
                self.outcome['text_fg'] = PVPGlobals.getTeamColor(1)
            elif team2Score > team1Score:
                self.outcome['text_fg'] = PVPGlobals.getTeamColor(2)

        self.borderTwo = BorderFrame(
            parent=self,
            relief=None,
            frameSize=(self.width * 0.14999999999999999,
                       self.width * 0.84999999999999998, 0,
                       self.height * 0.80000000000000004),
            modelName='pir_m_gui_frm_subframe',
            imageColorScale=VBase4(0.75, 0.75, 0.90000000000000002, 0.75))
        self.borderTwoSecondLayer = BorderFrame(
            parent=self.borderTwo,
            relief=None,
            frameSize=(self.width * 0.14999999999999999,
                       self.width * 0.84999999999999998, 0,
                       self.height * 0.80000000000000004),
            modelName='pir_m_gui_frm_subframe',
            imageColorScale=VBase4(0.75, 0.75, 0.90000000000000002, 0.75))
        self.two = ScoreFrame(PiratesGuiGlobals.PVPCompletePageWidth - 1.0,
                              PiratesGuiGlobals.PVPCompletePageHeight,
                              pvp.statsHolder,
                              0,
                              sortOrder=2)
        self.two.reparentTo(self.borderTwo)
        self.two.setPos(0.45000000000000001, 0, -0.14999999999999999)
        self.two.setup()
        self.game = pvp

    def setOutcome(self, outcome):
        self.outcome['text'] = outcome

    def destroy(self):
        self.borderTwoSecondLayer.destroy()
        self.borderTwoSecondLayer = None
        self.borderTwo.destroy()
        self.borderTwo = None
        self.two.destroy()
        self.two = None
        self.secondLayer.destroy()
        self.secondLater = None
        self.game = None
        BorderFrame.destroy(self)
class RepairGameGUI(DirectFrame):
    completeSound = None
    guiDownSound = None
    guiUpSound = None
    shipRepairMusic = None
    
    def __init__(self, repairGame):
        DirectFrame.__init__(self, parent = base.a2dBackground, relief = None)
        self.repairGame = repairGame
        base.loadingScreen.beginStep('Sound', 1, 10)
        self._initSound()
        base.loadingScreen.endStep('Sound')
        base.loadingScreen.beginStep('GUI', 1, 43)
        self._initGUI()
        base.loadingScreen.endStep('GUI')
        self.accept('clientLogout', self.handleExitGame)
        if base.localAvatar.guiMgr.seaChestActive:
            base.localAvatar.guiMgr.hideSeaChest()
        
        if base.localAvatar.guiMgr.minimap:
            base.localAvatar.guiMgr.hideMinimap()
        
        self.accept('seachestOpened', self.handleExitGame)
        self.accept('avatarDetailsOpened', self.handleExitGame)
        self.accept('minimapOpened', self.handleExitGame)
        self.setBin('fixed', 30)
        self.setZ(-0.20000000000000001)
        base.loadingScreen.beginStep('Intervals')
        self._initIntervals()
        base.loadingScreen.endStep('Intervals')

    
    def _initSound(self):
        if not self.completeSound:
            RepairGameGUI.completeSound = loadSfx(SoundGlobals.SFX_MINIGAME_REPAIR_GENERAL_CYCLECOMPLETE)
            RepairGameGUI.guiDownSound = loadSfx(SoundGlobals.SFX_MINIGAME_REPAIR_GENERAL_GUIDOWN)
            RepairGameGUI.guiUpSound = loadSfx(SoundGlobals.SFX_MINIGAME_REPAIR_GENERAL_GUIUP)
            RepairGameGUI.guiDownSound.setVolume(0.5)
            RepairGameGUI.guiUpSound.setVolume(0.5)
            RepairGameGUI.shipRepairMusic = [
                SoundGlobals.MUSIC_PERFORMERS_02,
                SoundGlobals.MUSIC_PERFORMERS_07,
                SoundGlobals.MUSIC_PERFORMERS_09]
        
        base.musicMgr.request(random.choice(self.shipRepairMusic), priority = 1, volume = 0.5)

    
    def _initGUI(self):
        self.model = loader.loadModel('models/gui/pir_m_gui_srp_main')
        self.repairGamePicker = RepairGamePickerGUI(self, self.repairGame, self.model.find('**/group_picker'))
        self.staticElements = GUIFactory.generateStaticElements(self.model.getChild(0), self)
        self.textElements = { }
        self.textElements['title'] = DirectLabel(text = '', text_fg = (1.0, 1.0, 1.0, 1.0), text_shadow = (0.0, 0.0, 0.0, 1.0), scale = (0.087499999999999994, 0.087499999999999994, 0.087499999999999994), pos = (0.0, 0.0, 0.91000000000000003), relief = None, textMayChange = 1, text_font = PiratesGlobals.getPirateFont(), parent = self.staticElements['bg'])
        self.textElements['tutorial'] = DirectLabel(text = '', text_fg = (1.0, 1.0, 1.0, 1.0), text_shadow = (0.0, 0.0, 0.0, 1.0), text_wordwrap = 14, scale = (0.044999999999999998, 0.044999999999999998, 0.044999999999999998), pos = (0.0, 0.0, 0.79500000000000004), relief = None, textMayChange = 1, text_font = PiratesGlobals.getPirateFont(), parent = self.staticElements['bg'])
        self.textElements['level'] = DirectLabel(text = '', text_fg = (1.0, 1.0, 1.0, 1.0), scale = (0.052499999999999998, 0.052499999999999998, 0.052499999999999998), pos = (0.315, 0.0, 0.69999999999999996), relief = None, textMayChange = 1, text_align = TextNode.ARight, text_font = PiratesGlobals.getPirateFont(), parent = self.staticElements['bg'])
        self.textElements['level'].stash()
        self.textElements['idleMessage'] = DirectLabel(text = '', text_fg = (1.0, 1.0, 1.0, 1.0), text_shadow = (0.0, 0.0, 0.0, 1.0), text_wordwrap = 15, scale = (0.087499999999999994, 0.087499999999999994, 0.087499999999999994), pos = (0.0, 0.0, 0.0), relief = None, textMayChange = 1, text_font = PiratesGlobals.getPirateFont(), parent = self.staticElements['bg'])
        self.textElements['cycleCompleteMessage'] = DirectLabel(text = '', text_fg = (1.0, 1.0, 1.0, 1.0), text_shadow = (0.0, 0.0, 0.0, 1.0), text_wordwrap = 20, scale = (0.087499999999999994, 0.087499999999999994, 0.087499999999999994), pos = (0.0, 0.0, 0.0), relief = None, textMayChange = 1, text_font = PiratesGlobals.getPirateFont(), parent = self.staticElements['bg'])
        self.closeButton = GuiButton(image = (self.model.find('**/esc_button/idle'), self.model.find('**/esc_button/over'), self.model.find('**/esc_button/over'), self.model.find('**/esc_button/idle')), image_scale = (0.75, 0.75, 0.75), image_pos = (0.074999999999999997, 0, 0.080000000000000002), hotkeys = [
            'Escape'], hotkeyLabel = PLocalizer.Minigame_Repair_Leave_Game_Text, pos = (-0.40000000000000002, 0.0, 0.01), parent = base.a2dBottomRight, command = self.handleExitGame)
        self.closeButton.setBin('background', -90)
        self.model.removeNode()
        del self.model

    
    def setPickerOutroStartPos(self):
        self.pickerOutroLerp.setStartPos(self.repairGamePicker.getPos())

    
    def setBGOutroStartPos(self):
        self.bgOutroLerp.setStartPos(self.staticElements['bg'].getPos())

    
    def _initIntervals(self):
        self.bgIntroLerp = LerpPosInterval(self.staticElements['bg'], duration = 1.0, pos = self.staticElements['bg'].getPos(), startPos = (0.0, 0.0, 2.0))
        self.pickerIntroLerp = LerpPosInterval(self.repairGamePicker, duration = 1.0, pos = self.repairGamePicker.getPos(), startPos = (0.0, 0.0, -1.0))
        self.introSequence = Sequence(Func(self.repairGamePicker.setEnabled, False), Parallel(Sequence(Wait(0.25), Func(self.guiDownSound.play)), self.bgIntroLerp, self.pickerIntroLerp), Func(self.repairGamePicker.setEnabled, True), Func(self.repairGame.gameFSM.request, 'Idle'), name = 'RepairGame.introSequence')
        self.pickerOutroLerp = LerpPosInterval(self.repairGamePicker, duration = 1.0, startPos = self.repairGamePicker.getPos(), pos = (0.0, 0.0, -1.0))
        self.bgOutroLerp = LerpPosInterval(self.staticElements['bg'], duration = 1.0, startPos = self.repairGamePicker.getPos(), pos = (0.0, 0.0, 2.0))
        self.outroSequence = Sequence(Func(self.repairGamePicker.stashTab), Func(self.closeButton.stash), Parallel(Func(self.guiUpSound.play), Func(self.setPickerOutroStartPos), Func(self.setBGOutroStartPos), self.pickerOutroLerp, self.bgOutroLerp), Func(self.repairGame.cleanup), name = 'RepairGame.outroSequence')
        self.cycleCompleteSequence = Sequence(Func(self.showCycleCompleteMessage), Func(self.repairGamePicker.stashTab), Wait(self.getCycleCompleteWaitTime()), Func(self.completeSound.play), Func(self.hideCycleCompleteMessage), LerpPosInterval(self.repairGamePicker, duration = 0.5, pos = self.repairGamePicker.getPos() - (0, 0, 1.0)), Func(self.repairGame.resetMincroGameProgress), LerpPosInterval(self.repairGamePicker, duration = 0.5, pos = self.repairGamePicker.getPos()), Func(self.repairGame.gameFSM.request, 'Idle'), name = 'RepairGame.cycleCompleteSequence')
        self.shakeSequence = Sequence(name = 'RepairGameGUI.shakeSequence')

    
    def handleExitGame(self):
        messenger.send('escape')

    
    def getCycleCompleteWaitTime(self):
        if self.repairGame.location == ON_LAND:
            return 5.5
        else:
            return 1.5

    
    def showCycleCompleteMessage(self):
        if self.repairGame.location == ON_LAND:
            tpMgr = TextPropertiesManager.getGlobalPtr()
            tpGold = TextProperties()
            tpGold.setTextColor(0.97999999999999998, 0.76000000000000001, 0, 1)
            tpMgr.setProperties('gold', tpGold)
            completionTime = self.repairGame.getCycleCompleteTime()
            seconds = completionTime % 60
            minutes = int(completionTime / 60.0)
            if minutes == 0:
                time = 'gold %i %s' % (seconds, PLocalizer.Minigame_Repair_Seconds)
            elif seconds < 10:
                time = 'gold %i:0%i %s' % (minutes, seconds, PLocalizer.Minigame_Repair_Minutes)
            else:
                time = 'gold %i:%i %s' % (minutes, seconds, PLocalizer.Minigame_Repair_Minutes)
            goldAmount = self.repairGame.getReward(localAvatar.doId)
            goldBonus = self.repairGame.getGoldBonus()
            if goldBonus:
                reward = PLocalizer.Minigame_Repair_GoldBonus % (str(goldAmount), str(goldBonus))
            else:
                reward = PLocalizer.Minigame_Repair_Gold % str(goldAmount)
            text = PLocalizer.Minigame_Repair_BenchOutro % (time, reward)
            self.textElements['cycleCompleteMessage'].setPos(0.0, 0.0, 0.34999999999999998)
        else:
            text = PLocalizer.Minigame_Repair_ShipOutro
            self.textElements['cycleCompleteMessage'].setPos(0.0, 0.0, 0.14999999999999999)
        self.textElements['cycleCompleteMessage']['text'] = text
        self.textElements['cycleCompleteMessage'].setText()

    
    def hideCycleCompleteMessage(self):
        self.textElements['cycleCompleteMessage']['text'] = ''
        self.textElements['cycleCompleteMessage'].setText()

    
    def showIdleMessage(self):
        if self.repairGame.location == ON_LAND:
            text = PLocalizer.Minigame_Repair_BenchIntro
            self.textElements['idleMessage'].setPos(0.0, 0.0, 0.34999999999999998)
        else:
            text = PLocalizer.Minigame_Repair_ShipIntro
            self.textElements['idleMessage'].setPos(0.0, 0.0, 0.17499999999999999)
        self.textElements['idleMessage']['text'] = text
        self.textElements['idleMessage'].setText()

    
    def hideIdleMessage(self):
        self.textElements['idleMessage']['text'] = ''
        self.textElements['idleMessage'].setText()

    
    def onShipDamaged(self, wasGrapeshot = False):
        if wasGrapeshot:
            shakeDelta = 0.050000000000000003
            randomX = random.random() * 2 * shakeDelta - shakeDelta
            randomZ = random.random() * 2 * shakeDelta - shakeDelta
            if self.shakeSequence.isPlaying():
                self.shakeSequence.finish()
            
            self.shakeSequence = Parallel(Sequence(LerpColorScaleInterval(self, duration = 0.5, colorScale = (1.0, 0.20000000000000001, 0.20000000000000001, 1.0)), LerpColorScaleInterval(self, duration = RepairGlobals.Common.guiShakeCooldownTime / 2.0, colorScale = (1.0, 1.0, 1.0, 1.0))), Sequence(LerpPosInterval(self, duration = 0.10000000000000001, pos = self.getPos() - (randomX, 0.0, randomZ)), LerpPosInterval(self, duration = 0.20000000000000001, pos = self.getPos() + (randomX, 0.0, randomZ)), LerpPosInterval(self, duration = 0.10000000000000001, pos = self.getPos()), Wait(RepairGlobals.Common.guiShakeCooldownTime)), name = 'RepairGameGUI.shakeSequence')
            self.shakeSequence.start()
        else:
            shakeDelta = 0.025000000000000001
            randomX = random.random() * 2 * shakeDelta - shakeDelta
            randomZ = random.random() * 2 * shakeDelta - shakeDelta
            if not self.shakeSequence.isPlaying():
                self.shakeSequence = Sequence(LerpPosInterval(self, duration = 0.10000000000000001, pos = self.getPos() - (randomX, 0.0, randomZ)), LerpPosInterval(self, duration = 0.20000000000000001, pos = self.getPos() + (randomX, 0.0, randomZ)), LerpPosInterval(self, duration = 0.10000000000000001, pos = self.getPos()), Wait(RepairGlobals.Common.guiShakeCooldownTime), name = 'RepairGameGUI.shakeSequence')
                self.shakeSequence.start()
            

    
    def setTutorial(self, game, index = None):
        text = PLocalizer.Minigame_Tutorials[game]
        if index is not None:
            text = text[index]
        
        self.textElements['tutorial']['text'] = text
        self.textElements['tutorial'].setText()

    
    def clearTutorial(self):
        self.textElements['tutorial']['text'] = ''
        self.textElements['tutorial'].setText()

    
    def setRepairTitle(self):
        self.setTitle('repair')

    
    def setTitle(self, game):
        text = (PLocalizer.Minigame_Repair_Names[game],)
        self.textElements['title']['text'] = text
        self.textElements['title'].setText()

    
    def clearTitle(self):
        self.textElements['title']['text'] = ''
        self.textElements['title'].setText()

    
    def setDifficulty(self, difficulty):
        self.textElements['level']['text'] = PLocalizer.Minigame_Repair_Level % str(difficulty + 1)
        self.textElements['level'].setText()

    
    def setReward(self, reward):
        self.currentReward = reward

    
    def setGames(self, gameList):
        self.repairGamePicker.setGames(gameList)

    
    def resetGames(self):
        self.repairGamePicker.setEnabled(True)

    
    def setProgress(self, gameIndex, percent):
        self.repairGamePicker.setProgress(gameIndex, percent)

    
    def updatePirateNamesPerMincrogame(self, avIds2CurrentGameIndex):
        self.repairGamePicker.updatePirateNamesPerMincrogame(avIds2CurrentGameIndex)

    
    def destroy(self):
        self.ignore('clientLogout')
        self.ignore('seachestOpened')
        self.ignore('avatarDetailsOpened')
        self.ignore('minimapOpened')
        self.introSequence.clearToInitial()
        self.outroSequence.clearToInitial()
        self.cycleCompleteSequence.clearToInitial()
        self.shakeSequence.clearToInitial()
        del self.introSequence
        del self.outroSequence
        del self.cycleCompleteSequence
        del self.shakeSequence
        self.closeButton.destroy()
        self.closeButton.removeNode()
        del self.closeButton
        GUIFactory.destroyDirectGUIDict(self.staticElements)
        del self.staticElements
        self.repairGamePicker.destroy()
        del self.repairGamePicker
        self.removeNode()