class LegendaryFishingGameGUI: def __init__(self, gameObject = None): base.loadingScreen.beginStep('LegendaryGameGUI', 4, 20) self.gameObject = gameObject self.guiImage = loader.loadModel('models/minigames/pir_m_gam_fsh_legendaryGui') self.UICompoments = { } self.uiBaseNode = NodePath('baseNode') self.uiBaseNode.reparentTo(aspect2d) self.uiBaseNode.show() self.leftBaseNode = NodePath('leftBaseNode') self.leftBaseNode.reparentTo(base.a2dLeftCenter) self.leftBaseNode.show() self.fishActor = None self.actorAnim = { } self.scaleSize = { InventoryType.Collection_Set11_Part1: 0.059999999999999998, InventoryType.Collection_Set11_Part2: 0.055, InventoryType.Collection_Set11_Part3: 0.12, InventoryType.Collection_Set11_Part4: 0.086999999999999994, InventoryType.Collection_Set11_Part5: 0.080000000000000002 } self.meterFrame = DirectFrame(parent = self.leftBaseNode, frameSize = (-0.29999999999999999, 0.29999999999999999, -1.0, 0.0), frameColor = (1.0, 1.0, 1.0, 0.0), relief = None, state = DGG.DISABLED, pos = (1.0, 0.0, -0.45000000000000001), hpr = (0, 0, 0), scale = (1.3, 0.0, 1.3), image = self.guiImage.find('**/pir_t_gui_fsh_meter'), image_scale = (0.20000000000000001, 0.0, 0.80000000000000004), image_pos = (0, 0, 0), text = '', textMayChange = 1, text_scale = PiratesGuiGlobals.TextScaleTitleLarge, text_pos = (-0.55000000000000004, 0.10000000000000001), text_shadow = PiratesGuiGlobals.TextShadow) self.UICompoments['meterFrame'] = self.meterFrame self.fishingRod = DirectFrame(parent = self.meterFrame, frameSize = (-0.29999999999999999, 0.29999999999999999, -1.0, 0.0), relief = None, state = DGG.DISABLED, pos = FishingGlobals.fishingRodScreenPosition, image = self.guiImage.find('**/pir_t_gui_fsh_fullRod'), image_scale = (1.0, 0.0, 0.125), image_pos = (0.20000000000000001, 0, 0)) self.fishingRod.setR(FishingGlobals.fishingRodInitSlope) self.UICompoments['fishingRod'] = self.fishingRod base.loadingScreen.tick() self.fishingHandleBaseFrame = DirectFrame(parent = self.uiBaseNode, frameSize = (-0.29999999999999999, 0.29999999999999999, -1.5, 1.5), frameColor = (1.0, 1.0, 1.0, 0.0), relief = None, state = DGG.DISABLED, pos = (0.0, 0.0, 0.0), hpr = (0, 0, 0), scale = (0.71999999999999997, 0.0, 0.71999999999999997), image = self.guiImage.find('**/pir_t_gui_fsh_partialRod'), image_scale = (3.7999999999999998, 0.0, 1.8999999999999999), image_pos = (0, 0, 0), image_hpr = (0.0, 0.0, 0)) self.fishingHandleBaseFrame.hide() self.UICompoments['fishingHandleBaseFrame'] = self.fishingHandleBaseFrame self.fishingHandle = DirectFrame(parent = self.fishingHandleBaseFrame, frameSize = (-0.080000000000000002, 0.080000000000000002, -0.20000000000000001, 0.20000000000000001), relief = None, state = DGG.DISABLED, pos = (-0.10000000000000001, 0.0, -0.050000000000000003), hpr = (0, 0, 0), image = self.guiImage.find('**/pir_t_gui_fsh_handleArm'), image_scale = (1.0, 0.0, 1.0), image_pos = (-0.042000000000000003, 0, -0.115), image_hpr = (0.0, 0.0, 0)) self.UICompoments['fishingHandle'] = self.fishingHandle self.arrowImage = DirectFrame(parent = self.fishingHandleBaseFrame, frameSize = (-0.40000000000000002, 0.40000000000000002, -0.40000000000000002, 0.40000000000000002), relief = None, state = DGG.DISABLED, pos = (0.0, 0.0, 0.0), hpr = (0, 0, 0), scale = (1.2, 0.0, 1.2), image = self.guiImage.find('**/pir_t_gui_fsh_arrow'), image_scale = (1.0, 0.0, 1.0), image_pos = (0.0, 0, 0.0), image_hpr = (0.0, 0.0, 0.0)) self.arrowImage.hide() self.UICompoments['arrowImage'] = self.arrowImage btnGeom = (self.guiImage.find('**/pir_t_gui_fsh_handle'), self.guiImage.find('**/pir_t_gui_fsh_handle'), self.guiImage.find('**/pir_t_gui_fsh_handleOn')) self.fishingHandleButton = GuiButton(pos = (-0.29999999999999999, 0, -0.55000000000000004), hpr = (0, 0, 0), scale = 0.45000000000000001, image = btnGeom, image_pos = (0, 0, 0), image_scale = 1.0, sortOrder = 2) self.fishingHandleButton.bind(DGG.B1PRESS, self.handleButtonClicked) self.fishingHandleButton.reparentTo(self.fishingHandle) self.UICompoments['fishingHandleButton'] = self.fishingHandleButton self.fishingHandleBaseFrame.setTransparency(TransparencyAttrib.MAlpha) self.meterFrame.setTransparency(TransparencyAttrib.MAlpha) self.lineOneTransitTextNode = TextNode('lineOneTransitText') self.lineOneTransitTextNode.setFont(PiratesGlobals.getPirateFont()) self.lineOneTransitTextNode.setText('') self.lineOneTransitTextNode.setAlign(TextNode.ACenter) self.lineOneTransitTextNode.setTextColor(1.0, 1.0, 1.0, 0.5) self.lineOneTransitTextNodePath = NodePath(self.lineOneTransitTextNode) self.lineOneTransitTextNodePath.setPos(0.0, 0.0, -0.80000000000000004) self.lineOneTransitTextNodePath.setScale(0.34999999999999998, 0.34999999999999998, 0.34999999999999998) self.lineOneTransitTextNodePath.reparentTo(self.uiBaseNode) self.lineOneTransitTextNodePath.hide() self.UICompoments['lineOneTransitText'] = self.lineOneTransitTextNodePath self.lineTwoTransitTextNode = TextNode('lineTwoTransitText') self.lineTwoTransitTextNode.setFont(PiratesGlobals.getPirateFont()) self.lineTwoTransitTextNode.setText('') self.lineTwoTransitTextNode.setAlign(TextNode.ACenter) self.lineTwoTransitTextNode.setTextColor(1.0, 1.0, 1.0, 0.5) self.lineTwoTransitTextNodePath = NodePath(self.lineTwoTransitTextNode) self.lineTwoTransitTextNodePath.setPos(-0.40000000000000002, 0.0, -0.94999999999999996) self.lineTwoTransitTextNodePath.setScale(0.12, 0.12, 0.12) self.lineTwoTransitTextNodePath.reparentTo(self.uiBaseNode) self.lineTwoTransitTextNodePath.hide() self.UICompoments['lineTwoTransitText'] = self.lineTwoTransitTextNodePath base.loadingScreen.tick() self.test_guiImage = loader.loadModel('models/gui/toplevel_gui') self.buttonIcon = (self.test_guiImage.find('**/treasure_chest_closed'), self.test_guiImage.find('**/treasure_chest_closed'), self.test_guiImage.find('**/treasure_chest_closed_over')) self.winImagePanel = GuiPanel.GuiPanel('', 2.6000000000000001, 1.8999999999999999, True) self.winImagePanel.setPos(-1.3, 0.0, -0.94999999999999996) self.winImagePanel.reparentTo(self.uiBaseNode) self.winImagePanel.background = OnscreenImage(parent = self.winImagePanel, scale = (2.3999999999999999, 0, 1.8), image = self.guiImage.find('**/pir_t_gui_fsh_posterBackground'), hpr = (0, 0, 0), pos = (1.3, 0, 0.94999999999999996)) self.winImagePanel.setBin('gui-popup', -4) self.winTitleTextNode = TextNode('winTitleTextNode') self.winTitleTextNode.setText('Congratulations!') self.winTitleTextNode.setAlign(TextNode.ACenter) self.winTitleTextNode.setFont(PiratesGlobals.getPirateFont()) self.winTitleTextNode.setTextColor(0.23000000000000001, 0.089999999999999997, 0.029999999999999999, 1.0) self.winTitleTextNodePath = NodePath(self.winTitleTextNode) self.winTitleTextNodePath.setPos(1.3500000000000001, 0.0, 1.6699999999999999) self.winTitleTextNodePath.setScale(0.17999999999999999) self.winTitleTextNodePath.reparentTo(self.winImagePanel) self.wholeStoryTextNode = TextNode('storyTextNode') self.wholeStoryTextNode.setText('') self.wholeStoryTextNode.setWordwrap(19.0) self.wholeStoryTextNode.setTextColor(0.23000000000000001, 0.089999999999999997, 0.029999999999999999, 1.0) self.wholeStoryTextNodePath = NodePath(self.wholeStoryTextNode) self.wholeStoryTextNodePath.setPos(0.33000000000000002, 0.0, 1.6399999999999999) self.wholeStoryTextNodePath.setScale(0.050000000000000003) self.wholeStoryTextNodePath.reparentTo(self.winImagePanel) self.winImagePanel.closeButton['command'] = self.closeDialogGotNextState self.winImagePanel.closeButton['extraArgs'] = [ 'winImagePanel', 'FarewellLegendaryFish', False] self.UICompoments['winImagePanel'] = self.winImagePanel self.winImagePanel.hide() self.luiCloseDialogSequence = Sequence() self.arrowImageRotationInterval = LerpHprInterval(self.arrowImage, 2.2000000000000002, self.arrowImage.getHpr() + Point3(0.0, 0.0, 280.0), self.arrowImage.getHpr()) self.luiArrowRotatingSequence = Sequence(Func(self.showGui, [ 'arrowImage']), Parallel(Func(self.arrowImageRotationInterval.start), Wait(2.2000000000000002)), Func(self.hideGui, [ 'arrowImage']), Func(self.arrowImage.setHpr, self.arrowImage.getHpr() + Point3(0.0, 0.0, 5.0)), name = self.gameObject.distributedFishingSpot.uniqueName('luiArrowRotatingSequence')) self.lineOneColorChange = LerpColorScaleInterval(self.lineOneTransitTextNodePath, FishingGlobals.legendaryTransitionTextDuration, (1.0, 1.0, 1.0, 0.0), (1.0, 1.0, 1.0, 1.0), blendType = 'easeOut') self.lineOnePosChange = LerpPosInterval(self.lineOneTransitTextNodePath, FishingGlobals.legendaryTransitionTextDuration, (0.0, 0.0, -0.20000000000000001), (0.0, 0.0, -0.80000000000000004), blendType = 'easeOut') self.lineTwoCholorChange = LerpColorScaleInterval(self.lineTwoTransitTextNodePath, FishingGlobals.legendaryTransitionTextDuration, (1.0, 1.0, 1.0, 1.0), (1.0, 1.0, 1.0, 1.0), blendType = 'easeOut') self.lineTwoPosChange = LerpPosInterval(self.lineTwoTransitTextNodePath, FishingGlobals.legendaryTransitionTextDuration, (0.0, 0.0, -0.32000000000000001), (0.0, 0.0, -0.94999999999999996), blendType = 'easeOut') self.transitionTextMovingSequence = Sequence(Func(self.lineOneTransitTextNodePath.show), Func(self.lineTwoTransitTextNodePath.show), Parallel(self.lineOnePosChange, self.lineTwoPosChange, self.lineOneColorChange, self.lineTwoCholorChange), Func(self.lineOneTransitTextNodePath.hide), Func(self.lineTwoTransitTextNodePath.hide), name = self.gameObject.distributedFishingSpot.uniqueName('transitionTextMovingSequence')) self.meterFadeInInterval = Sequence(Func(self.meterFrame.show), LerpColorScaleInterval(self.meterFrame, FishingGlobals.legendaryTransitionTextDuration, colorScale = (1.0, 1.0, 1.0, 1.0), startColorScale = (1.0, 1.0, 1.0, 0.0), blendType = 'easeOut'), name = 'FadeInLegendaryMeter') self.meterFadeOutInterval = Sequence(LerpColorScaleInterval(self.meterFrame, FishingGlobals.legendaryTransitionTextDuration, colorScale = (1.0, 1.0, 1.0, 0.0), startColorScale = (1.0, 1.0, 1.0, 1.0), blendType = 'easeOut'), Func(self.meterFrame.hide), name = 'FadeOutLegendaryMeter') self.rodFadeInInterval = Sequence(Func(self.fishingHandleBaseFrame.show), LerpColorScaleInterval(self.fishingHandleBaseFrame, FishingGlobals.legendaryTransitionTextDuration, colorScale = (1.0, 1.0, 1.0, 1.0), startColorScale = (1.0, 1.0, 1.0, 0.0), blendType = 'easeOut'), name = 'FadeInLegendaryRodInterface') self.rodFadeOutInterval = Sequence(LerpColorScaleInterval(self.fishingHandleBaseFrame, FishingGlobals.legendaryTransitionTextDuration, colorScale = (1.0, 1.0, 1.0, 0.0), startColorScale = (1.0, 1.0, 1.0, 1.0), blendType = 'easeOut'), Func(self.fishingHandleBaseFrame.hide), name = 'FadeOutLegendaryRodInterface') base.loadingScreen.tick() smallScale = self.fishingHandleButton['scale'] bigScale = self.fishingHandleButton['scale'] * 1.2 self.buttonGrowUpInterval = LerpScaleInterval(self.fishingHandleButton, 1.0, bigScale, smallScale) self.luiFightTransitSequence = Sequence(Parallel(Func(self.fishingHandleBaseFrame.show), Func(self.meterFadeOutInterval.start), Func(self.rodFadeInInterval.start), Func(self.buttonGrowUpInterval.start)), Wait(1.0), Func(self.meterFrame.hide), name = self.gameObject.distributedFishingSpot.uniqueName('luiFightTransitSequence')) self.luiReelTransitSequence = Sequence(Parallel(Func(self.fishingHandleBaseFrame.show), Func(self.meterFadeOutInterval.start), Func(self.rodFadeInInterval.start)), Wait(1.0), Func(self.meterFrame.hide), name = self.gameObject.distributedFishingSpot.uniqueName('luiReelTransitSequence')) self.luiStruggleTransitSequence = Sequence(Parallel(Func(self.meterFrame.show), Func(self.resetFishingRod), self.meterFadeInInterval, self.rodFadeOutInterval), Wait(1.0), Func(self.fishingHandleBaseFrame.hide), name = self.gameObject.distributedFishingSpot.uniqueName('luiStruggleTransitSequence')) self.meterFadeOutInterval.start() self.rodFadeOutInterval.start() self.hideAllGUI() base.loadingScreen.endStep('LegendaryGameGUI') def hideAllGUI(self): self.uiBaseNode.reparentTo(hidden) self.leftBaseNode.reparentTo(hidden) def showAllGUI(self): self.uiBaseNode.reparentTo(aspect2d) self.leftBaseNode.reparentTo(base.a2dLeftCenter) def hideGui(self, nameList): for ui in nameList: self.UICompoments[ui].hide() def showGui(self, nameList): for ui in nameList: self.UICompoments[ui].show() def destroy(self): self.arrowImageRotationInterval.pause() self.arrowImageRotationInterval.clearToInitial() self.luiArrowRotatingSequence.pause() self.luiArrowRotatingSequence.clearToInitial() self.luiCloseDialogSequence.pause() self.luiCloseDialogSequence.clearToInitial() totalKey = self.UICompoments.keys() for iKey in totalKey: del self.UICompoments[iKey] self.fishingHandle = None self.fishingHandleButton = None self.fishingRod.removeNode() self.leftBaseNode.removeNode() self.uiBaseNode.removeNode() if self.fishActor: self.fishActor.destroy() self.fishActor = None def handleButtonClicked(self, mouseKey): if self.gameObject.lfgFsm.getCurrentOrNextState() in [ 'CatchIt']: self.gameObject.lfgFsm.request('Transition', 'Struggle') self.gameObject.sfx['legendaryGreen'].play() def setTransitionText(self, state): self.lineOneTransitTextNode.setText(PLocalizer.LegendaryFishingGui[state][0]) self.lineTwoTransitTextNode.setText(PLocalizer.LegendaryFishingGui[state][1]) def resetInterval(self): self.transitionTextMovingSequence.pause() self.transitionTextMovingSequence.clearToInitial() self.lineOneColorChange.pause() self.lineOneColorChange.clearToInitial() self.lineOnePosChange.pause() self.lineOnePosChange.clearToInitial() self.lineTwoCholorChange.pause() self.lineTwoCholorChange.clearToInitial() self.lineTwoPosChange.pause() self.lineTwoPosChange.clearToInitial() self.luiReelTransitSequence.pause() self.luiReelTransitSequence.clearToInitial() self.luiStruggleTransitSequence.pause() self.luiStruggleTransitSequence.clearToInitial() self.luiFightTransitSequence.pause() self.luiFightTransitSequence.clearToInitial() self.buttonGrowUpInterval.pause() self.buttonGrowUpInterval.clearToInitial() self.meterFadeOutInterval.pause() self.meterFadeOutInterval.clearToInitial() self.rodFadeInInterval.pause() self.rodFadeInInterval.clearToInitial() self.meterFadeInInterval.pause() self.meterFadeInInterval.clearToInitial() self.rodFadeOutInterval.pause() self.rodFadeOutInterval.clearToInitial() def fightingTransit(self): self.luiFightTransitSequence.start() def reelTransit(self): self.luiReelTransitSequence.start() def struggleTransit(self): self.luiStruggleTransitSequence.start() def resetFishingRod(self): self.fishingRod.setR(FishingGlobals.fishingRodInitSlope) def showWinImage(self, fish): self.hideGui([ 'meterFrame', 'fishingHandleBaseFrame']) result = fish.myData['name'].split(' ') fileName = str(result[0]).capitalize() imgName = 'pir_t_gui_fsh_render%s' % fileName self.actorAnim['swimIdleOpposite'] = 'models/char/pir_a_gam_fsh_%s_%s.bam' % (fish.myData['model'], 'swimIdleOpposite') self.fishActor = BlendActor('models/char/pir_r_gam_fsh_%s.bam' % fish.myData['model'], self.actorAnim, FishingGlobals.defaultFishBlendTime, FishingGlobals.fishBlendTimeDict) self.fishActor.setPlayRate(fish.myData['speed'] * fish.myData['swimAnimationMultiplier'], 'swimIdleOpposite') self.fishActor.changeAnimationTo('swimIdleOpposite') self.fishActor.reparentTo(self.winImagePanel) self.fishActor.setScale(self.scaleSize[fish.myData['id']]) self.fishActor.setPos(1.7, 0, 1.0) self.fishActor.setHpr(0, 0, 35) self.fishActor.setDepthWrite(True) self.fishActor.setDepthTest(True) self.wholeStoryTextNode.setText(PLocalizer.LegendSelectionGui['wholeStory'][fish.myData['id']]) self.winImagePanel.show() def closeDialogGotNextState(self, object, targetState, ifFadeInAgain): if self.fishActor: self.fishActor.destroy() self.fishActor = None self.luiCloseDialogSequence = Sequence(Func(self.gameObject.distributedFishingSpot.fadeOut), Wait(0.40000000000000002), Func(self.UICompoments[object].hide), Func(self.gameObject.lfgFsm.request, targetState), name = self.gameObject.distributedFishingSpot.uniqueName('luiCloseDialogSequence')) self.luiCloseDialogSequence.start() def updateStruggleTimerText(self, time, percent): self.meterFrame['text'] = str(time) self.meterFrame['text_fg'] = (1.0 - percent, percent, 0.0, 1.0)
class LegendaryFishingGameGUI: def __init__(self, gameObject=None): base.loadingScreen.beginStep('LegendaryGameGUI', 4, 20) self.gameObject = gameObject self.guiImage = loader.loadModel( 'models/minigames/pir_m_gam_fsh_legendaryGui') self.UICompoments = {} self.uiBaseNode = NodePath('baseNode') self.uiBaseNode.reparentTo(aspect2d) self.uiBaseNode.show() self.leftBaseNode = NodePath('leftBaseNode') self.leftBaseNode.reparentTo(base.a2dLeftCenter) self.leftBaseNode.show() self.fishActor = None self.actorAnim = {} self.scaleSize = { InventoryType.Collection_Set11_Part1: 0.059999999999999998, InventoryType.Collection_Set11_Part2: 0.055, InventoryType.Collection_Set11_Part3: 0.12, InventoryType.Collection_Set11_Part4: 0.086999999999999994, InventoryType.Collection_Set11_Part5: 0.080000000000000002 } self.meterFrame = DirectFrame( parent=self.leftBaseNode, frameSize=(-0.29999999999999999, 0.29999999999999999, -1.0, 0.0), frameColor=(1.0, 1.0, 1.0, 0.0), relief=None, state=DGG.DISABLED, pos=(1.0, 0.0, -0.45000000000000001), hpr=(0, 0, 0), scale=(1.3, 0.0, 1.3), image=self.guiImage.find('**/pir_t_gui_fsh_meter'), image_scale=(0.20000000000000001, 0.0, 0.80000000000000004), image_pos=(0, 0, 0), text='', textMayChange=1, text_scale=PiratesGuiGlobals.TextScaleTitleLarge, text_pos=(-0.55000000000000004, 0.10000000000000001), text_shadow=PiratesGuiGlobals.TextShadow) self.UICompoments['meterFrame'] = self.meterFrame self.fishingRod = DirectFrame( parent=self.meterFrame, frameSize=(-0.29999999999999999, 0.29999999999999999, -1.0, 0.0), relief=None, state=DGG.DISABLED, pos=FishingGlobals.fishingRodScreenPosition, image=self.guiImage.find('**/pir_t_gui_fsh_fullRod'), image_scale=(1.0, 0.0, 0.125), image_pos=(0.20000000000000001, 0, 0)) self.fishingRod.setR(FishingGlobals.fishingRodInitSlope) self.UICompoments['fishingRod'] = self.fishingRod base.loadingScreen.tick() self.fishingHandleBaseFrame = DirectFrame( parent=self.uiBaseNode, frameSize=(-0.29999999999999999, 0.29999999999999999, -1.5, 1.5), frameColor=(1.0, 1.0, 1.0, 0.0), relief=None, state=DGG.DISABLED, pos=(0.0, 0.0, 0.0), hpr=(0, 0, 0), scale=(0.71999999999999997, 0.0, 0.71999999999999997), image=self.guiImage.find('**/pir_t_gui_fsh_partialRod'), image_scale=(3.7999999999999998, 0.0, 1.8999999999999999), image_pos=(0, 0, 0), image_hpr=(0.0, 0.0, 0)) self.fishingHandleBaseFrame.hide() self.UICompoments[ 'fishingHandleBaseFrame'] = self.fishingHandleBaseFrame self.fishingHandle = DirectFrame( parent=self.fishingHandleBaseFrame, frameSize=(-0.080000000000000002, 0.080000000000000002, -0.20000000000000001, 0.20000000000000001), relief=None, state=DGG.DISABLED, pos=(-0.10000000000000001, 0.0, -0.050000000000000003), hpr=(0, 0, 0), image=self.guiImage.find('**/pir_t_gui_fsh_handleArm'), image_scale=(1.0, 0.0, 1.0), image_pos=(-0.042000000000000003, 0, -0.115), image_hpr=(0.0, 0.0, 0)) self.UICompoments['fishingHandle'] = self.fishingHandle self.arrowImage = DirectFrame( parent=self.fishingHandleBaseFrame, frameSize=(-0.40000000000000002, 0.40000000000000002, -0.40000000000000002, 0.40000000000000002), relief=None, state=DGG.DISABLED, pos=(0.0, 0.0, 0.0), hpr=(0, 0, 0), scale=(1.2, 0.0, 1.2), image=self.guiImage.find('**/pir_t_gui_fsh_arrow'), image_scale=(1.0, 0.0, 1.0), image_pos=(0.0, 0, 0.0), image_hpr=(0.0, 0.0, 0.0)) self.arrowImage.hide() self.UICompoments['arrowImage'] = self.arrowImage btnGeom = (self.guiImage.find('**/pir_t_gui_fsh_handle'), self.guiImage.find('**/pir_t_gui_fsh_handle'), self.guiImage.find('**/pir_t_gui_fsh_handleOn')) self.fishingHandleButton = GuiButton(pos=(-0.29999999999999999, 0, -0.55000000000000004), hpr=(0, 0, 0), scale=0.45000000000000001, image=btnGeom, image_pos=(0, 0, 0), image_scale=1.0, sortOrder=2) self.fishingHandleButton.bind(DGG.B1PRESS, self.handleButtonClicked) self.fishingHandleButton.reparentTo(self.fishingHandle) self.UICompoments['fishingHandleButton'] = self.fishingHandleButton self.fishingHandleBaseFrame.setTransparency(TransparencyAttrib.MAlpha) self.meterFrame.setTransparency(TransparencyAttrib.MAlpha) self.lineOneTransitTextNode = TextNode('lineOneTransitText') self.lineOneTransitTextNode.setFont(PiratesGlobals.getPirateFont()) self.lineOneTransitTextNode.setText('') self.lineOneTransitTextNode.setAlign(TextNode.ACenter) self.lineOneTransitTextNode.setTextColor(1.0, 1.0, 1.0, 0.5) self.lineOneTransitTextNodePath = NodePath(self.lineOneTransitTextNode) self.lineOneTransitTextNodePath.setPos(0.0, 0.0, -0.80000000000000004) self.lineOneTransitTextNodePath.setScale(0.34999999999999998, 0.34999999999999998, 0.34999999999999998) self.lineOneTransitTextNodePath.reparentTo(self.uiBaseNode) self.lineOneTransitTextNodePath.hide() self.UICompoments[ 'lineOneTransitText'] = self.lineOneTransitTextNodePath self.lineTwoTransitTextNode = TextNode('lineTwoTransitText') self.lineTwoTransitTextNode.setFont(PiratesGlobals.getPirateFont()) self.lineTwoTransitTextNode.setText('') self.lineTwoTransitTextNode.setAlign(TextNode.ACenter) self.lineTwoTransitTextNode.setTextColor(1.0, 1.0, 1.0, 0.5) self.lineTwoTransitTextNodePath = NodePath(self.lineTwoTransitTextNode) self.lineTwoTransitTextNodePath.setPos(-0.40000000000000002, 0.0, -0.94999999999999996) self.lineTwoTransitTextNodePath.setScale(0.12, 0.12, 0.12) self.lineTwoTransitTextNodePath.reparentTo(self.uiBaseNode) self.lineTwoTransitTextNodePath.hide() self.UICompoments[ 'lineTwoTransitText'] = self.lineTwoTransitTextNodePath base.loadingScreen.tick() self.test_guiImage = loader.loadModel('models/gui/toplevel_gui') self.buttonIcon = ( self.test_guiImage.find('**/treasure_chest_closed'), self.test_guiImage.find('**/treasure_chest_closed'), self.test_guiImage.find('**/treasure_chest_closed_over')) self.winImagePanel = GuiPanel.GuiPanel('', 2.6000000000000001, 1.8999999999999999, True) self.winImagePanel.setPos(-1.3, 0.0, -0.94999999999999996) self.winImagePanel.reparentTo(self.uiBaseNode) self.winImagePanel.background = OnscreenImage( parent=self.winImagePanel, scale=(2.3999999999999999, 0, 1.8), image=self.guiImage.find('**/pir_t_gui_fsh_posterBackground'), hpr=(0, 0, 0), pos=(1.3, 0, 0.94999999999999996)) self.winImagePanel.setBin('gui-popup', -4) self.winTitleTextNode = TextNode('winTitleTextNode') self.winTitleTextNode.setText('Congratulations!') self.winTitleTextNode.setAlign(TextNode.ACenter) self.winTitleTextNode.setFont(PiratesGlobals.getPirateFont()) self.winTitleTextNode.setTextColor(0.23000000000000001, 0.089999999999999997, 0.029999999999999999, 1.0) self.winTitleTextNodePath = NodePath(self.winTitleTextNode) self.winTitleTextNodePath.setPos(1.3500000000000001, 0.0, 1.6699999999999999) self.winTitleTextNodePath.setScale(0.17999999999999999) self.winTitleTextNodePath.reparentTo(self.winImagePanel) self.wholeStoryTextNode = TextNode('storyTextNode') self.wholeStoryTextNode.setText('') self.wholeStoryTextNode.setWordwrap(19.0) self.wholeStoryTextNode.setTextColor(0.23000000000000001, 0.089999999999999997, 0.029999999999999999, 1.0) self.wholeStoryTextNodePath = NodePath(self.wholeStoryTextNode) self.wholeStoryTextNodePath.setPos(0.33000000000000002, 0.0, 1.6399999999999999) self.wholeStoryTextNodePath.setScale(0.050000000000000003) self.wholeStoryTextNodePath.reparentTo(self.winImagePanel) self.winImagePanel.closeButton[ 'command'] = self.closeDialogGotNextState self.winImagePanel.closeButton['extraArgs'] = [ 'winImagePanel', 'FarewellLegendaryFish', False ] self.UICompoments['winImagePanel'] = self.winImagePanel self.winImagePanel.hide() self.luiCloseDialogSequence = Sequence() self.arrowImageRotationInterval = LerpHprInterval( self.arrowImage, 2.2000000000000002, self.arrowImage.getHpr() + Point3(0.0, 0.0, 280.0), self.arrowImage.getHpr()) self.luiArrowRotatingSequence = Sequence( Func(self.showGui, ['arrowImage']), Parallel(Func(self.arrowImageRotationInterval.start), Wait(2.2000000000000002)), Func(self.hideGui, ['arrowImage']), Func(self.arrowImage.setHpr, self.arrowImage.getHpr() + Point3(0.0, 0.0, 5.0)), name=self.gameObject.distributedFishingSpot.uniqueName( 'luiArrowRotatingSequence')) self.lineOneColorChange = LerpColorScaleInterval( self.lineOneTransitTextNodePath, FishingGlobals.legendaryTransitionTextDuration, (1.0, 1.0, 1.0, 0.0), (1.0, 1.0, 1.0, 1.0), blendType='easeOut') self.lineOnePosChange = LerpPosInterval( self.lineOneTransitTextNodePath, FishingGlobals.legendaryTransitionTextDuration, (0.0, 0.0, -0.20000000000000001), (0.0, 0.0, -0.80000000000000004), blendType='easeOut') self.lineTwoCholorChange = LerpColorScaleInterval( self.lineTwoTransitTextNodePath, FishingGlobals.legendaryTransitionTextDuration, (1.0, 1.0, 1.0, 1.0), (1.0, 1.0, 1.0, 1.0), blendType='easeOut') self.lineTwoPosChange = LerpPosInterval( self.lineTwoTransitTextNodePath, FishingGlobals.legendaryTransitionTextDuration, (0.0, 0.0, -0.32000000000000001), (0.0, 0.0, -0.94999999999999996), blendType='easeOut') self.transitionTextMovingSequence = Sequence( Func(self.lineOneTransitTextNodePath.show), Func(self.lineTwoTransitTextNodePath.show), Parallel(self.lineOnePosChange, self.lineTwoPosChange, self.lineOneColorChange, self.lineTwoCholorChange), Func(self.lineOneTransitTextNodePath.hide), Func(self.lineTwoTransitTextNodePath.hide), name=self.gameObject.distributedFishingSpot.uniqueName( 'transitionTextMovingSequence')) self.meterFadeInInterval = Sequence( Func(self.meterFrame.show), LerpColorScaleInterval( self.meterFrame, FishingGlobals.legendaryTransitionTextDuration, colorScale=(1.0, 1.0, 1.0, 1.0), startColorScale=(1.0, 1.0, 1.0, 0.0), blendType='easeOut'), name='FadeInLegendaryMeter') self.meterFadeOutInterval = Sequence(LerpColorScaleInterval( self.meterFrame, FishingGlobals.legendaryTransitionTextDuration, colorScale=(1.0, 1.0, 1.0, 0.0), startColorScale=(1.0, 1.0, 1.0, 1.0), blendType='easeOut'), Func(self.meterFrame.hide), name='FadeOutLegendaryMeter') self.rodFadeInInterval = Sequence( Func(self.fishingHandleBaseFrame.show), LerpColorScaleInterval( self.fishingHandleBaseFrame, FishingGlobals.legendaryTransitionTextDuration, colorScale=(1.0, 1.0, 1.0, 1.0), startColorScale=(1.0, 1.0, 1.0, 0.0), blendType='easeOut'), name='FadeInLegendaryRodInterface') self.rodFadeOutInterval = Sequence( LerpColorScaleInterval( self.fishingHandleBaseFrame, FishingGlobals.legendaryTransitionTextDuration, colorScale=(1.0, 1.0, 1.0, 0.0), startColorScale=(1.0, 1.0, 1.0, 1.0), blendType='easeOut'), Func(self.fishingHandleBaseFrame.hide), name='FadeOutLegendaryRodInterface') base.loadingScreen.tick() smallScale = self.fishingHandleButton['scale'] bigScale = self.fishingHandleButton['scale'] * 1.2 self.buttonGrowUpInterval = LerpScaleInterval(self.fishingHandleButton, 1.0, bigScale, smallScale) self.luiFightTransitSequence = Sequence( Parallel(Func(self.fishingHandleBaseFrame.show), Func(self.meterFadeOutInterval.start), Func(self.rodFadeInInterval.start), Func(self.buttonGrowUpInterval.start)), Wait(1.0), Func(self.meterFrame.hide), name=self.gameObject.distributedFishingSpot.uniqueName( 'luiFightTransitSequence')) self.luiReelTransitSequence = Sequence( Parallel(Func(self.fishingHandleBaseFrame.show), Func(self.meterFadeOutInterval.start), Func(self.rodFadeInInterval.start)), Wait(1.0), Func(self.meterFrame.hide), name=self.gameObject.distributedFishingSpot.uniqueName( 'luiReelTransitSequence')) self.luiStruggleTransitSequence = Sequence( Parallel(Func(self.meterFrame.show), Func(self.resetFishingRod), self.meterFadeInInterval, self.rodFadeOutInterval), Wait(1.0), Func(self.fishingHandleBaseFrame.hide), name=self.gameObject.distributedFishingSpot.uniqueName( 'luiStruggleTransitSequence')) self.meterFadeOutInterval.start() self.rodFadeOutInterval.start() self.hideAllGUI() base.loadingScreen.endStep('LegendaryGameGUI') def hideAllGUI(self): self.uiBaseNode.reparentTo(hidden) self.leftBaseNode.reparentTo(hidden) def showAllGUI(self): self.uiBaseNode.reparentTo(aspect2d) self.leftBaseNode.reparentTo(base.a2dLeftCenter) def hideGui(self, nameList): for ui in nameList: self.UICompoments[ui].hide() def showGui(self, nameList): for ui in nameList: self.UICompoments[ui].show() def destroy(self): self.arrowImageRotationInterval.pause() self.arrowImageRotationInterval.clearToInitial() self.luiArrowRotatingSequence.pause() self.luiArrowRotatingSequence.clearToInitial() self.luiCloseDialogSequence.pause() self.luiCloseDialogSequence.clearToInitial() totalKey = self.UICompoments.keys() for iKey in totalKey: del self.UICompoments[iKey] self.fishingHandle = None self.fishingHandleButton = None self.fishingRod.removeNode() self.leftBaseNode.removeNode() self.uiBaseNode.removeNode() if self.fishActor: self.fishActor.destroy() self.fishActor = None def handleButtonClicked(self, mouseKey): if self.gameObject.lfgFsm.getCurrentOrNextState() in ['CatchIt']: self.gameObject.lfgFsm.request('Transition', 'Struggle') self.gameObject.sfx['legendaryGreen'].play() def setTransitionText(self, state): self.lineOneTransitTextNode.setText( PLocalizer.LegendaryFishingGui[state][0]) self.lineTwoTransitTextNode.setText( PLocalizer.LegendaryFishingGui[state][1]) def resetInterval(self): self.transitionTextMovingSequence.pause() self.transitionTextMovingSequence.clearToInitial() self.lineOneColorChange.pause() self.lineOneColorChange.clearToInitial() self.lineOnePosChange.pause() self.lineOnePosChange.clearToInitial() self.lineTwoCholorChange.pause() self.lineTwoCholorChange.clearToInitial() self.lineTwoPosChange.pause() self.lineTwoPosChange.clearToInitial() self.luiReelTransitSequence.pause() self.luiReelTransitSequence.clearToInitial() self.luiStruggleTransitSequence.pause() self.luiStruggleTransitSequence.clearToInitial() self.luiFightTransitSequence.pause() self.luiFightTransitSequence.clearToInitial() self.buttonGrowUpInterval.pause() self.buttonGrowUpInterval.clearToInitial() self.meterFadeOutInterval.pause() self.meterFadeOutInterval.clearToInitial() self.rodFadeInInterval.pause() self.rodFadeInInterval.clearToInitial() self.meterFadeInInterval.pause() self.meterFadeInInterval.clearToInitial() self.rodFadeOutInterval.pause() self.rodFadeOutInterval.clearToInitial() def fightingTransit(self): self.luiFightTransitSequence.start() def reelTransit(self): self.luiReelTransitSequence.start() def struggleTransit(self): self.luiStruggleTransitSequence.start() def resetFishingRod(self): self.fishingRod.setR(FishingGlobals.fishingRodInitSlope) def showWinImage(self, fish): self.hideGui(['meterFrame', 'fishingHandleBaseFrame']) result = fish.myData['name'].split(' ') fileName = str(result[0]).capitalize() imgName = 'pir_t_gui_fsh_render%s' % fileName self.actorAnim[ 'swimIdleOpposite'] = 'models/char/pir_a_gam_fsh_%s_%s.bam' % ( fish.myData['model'], 'swimIdleOpposite') self.fishActor = BlendActor( 'models/char/pir_r_gam_fsh_%s.bam' % fish.myData['model'], self.actorAnim, FishingGlobals.defaultFishBlendTime, FishingGlobals.fishBlendTimeDict) self.fishActor.setPlayRate( fish.myData['speed'] * fish.myData['swimAnimationMultiplier'], 'swimIdleOpposite') self.fishActor.changeAnimationTo('swimIdleOpposite') self.fishActor.reparentTo(self.winImagePanel) self.fishActor.setScale(self.scaleSize[fish.myData['id']]) self.fishActor.setPos(1.7, 0, 1.0) self.fishActor.setHpr(0, 0, 35) self.fishActor.setDepthWrite(True) self.fishActor.setDepthTest(True) self.wholeStoryTextNode.setText( PLocalizer.LegendSelectionGui['wholeStory'][fish.myData['id']]) self.winImagePanel.show() def closeDialogGotNextState(self, object, targetState, ifFadeInAgain): if self.fishActor: self.fishActor.destroy() self.fishActor = None self.luiCloseDialogSequence = Sequence( Func(self.gameObject.distributedFishingSpot.fadeOut), Wait(0.40000000000000002), Func(self.UICompoments[object].hide), Func(self.gameObject.lfgFsm.request, targetState), name=self.gameObject.distributedFishingSpot.uniqueName( 'luiCloseDialogSequence')) self.luiCloseDialogSequence.start() def updateStruggleTimerText(self, time, percent): self.meterFrame['text'] = str(time) self.meterFrame['text_fg'] = (1.0 - percent, percent, 0.0, 1.0)
class CameraController: """Object to configure camera and its controls.""" def __init__(self): self._np = None # the main camera node self._target = Vec3(2, 0, MAX_Z) # the current movement final pos self._move_int = None # current move interval self._turn_int = None # current rotation interval self._with_mouse_move = None # camera is on move by mouse self._with_mouse_move_x = None # camera position before toggling centered view self._last_pos = None self._last_hpr = None self._last_np_pos = None self._last_np_hpr = None self._is_centered = False base.camLens.setNear(0.25) # noqa: F821 base.camLens.setFar(8) # noqa: F821 def _disable_ctrl_keys(self): """Ignore all the camera control keys.""" for key in ( "arrow_up", "arrow_down", "arrow_left", "arrow_right", "arrow_up-up", "arrow_down-up", "arrow_left-up", "arrow_right-up", "alt-arrow_left", "alt-arrow_right", "alt-arrow_up", "alt-arrow_down", "+", "-", "+-up", "--up", "wheel_up", "wheel_down", "mouse2", "mouse2-up", ): base.ignore(key) # noqa: F821 def _move(self, x, y, time): """Start camera movement with an interval (on key press). Args: x (float): Translation along x axis. y (float): Translation along y axis. time (float): Interval length. """ if self._move_int is not None: self._move_int.pause() if x: # if camera moves forward, consider Z coordinate # to calibrate move limits when zoomed if x == 1: x -= MAX_Z - base.cam.getZ() # noqa: F821 self._target.setX(x) else: self._target.setY(y) self._move_int = LerpPosInterval( base.cam, time, self._target, other=self._np # noqa: F821 ) self._move_int.start() def _move_with_mouse(self, task): """Implement moving camera with mouse. If mouse pointer touches a screen edge, move the camera in this direction. """ if not base.mouseWatcherNode.hasMouse(): # noqa: F821 return task.again x = base.mouseWatcherNode.getMouseX() # noqa: F821 if abs(x) > 0.98: self._with_mouse_move = True self._move(*(MAX_RIGHT_MOVE if x > 0 else MAX_LEFT_MOVE)) self._with_mouse_move_x = False return task.again z = base.mouseWatcherNode.getMouseY() # noqa: F821 if abs(z) > 0.98: self._with_mouse_move = True self._move(*MAX_UP_MOVE if z > 0 else MAX_DOWN_MOVE) self._with_mouse_move_x = True return task.again if self._with_mouse_move: self._stop(self._with_mouse_move_x) self._with_mouse_move = False return task.again def _rotate_camera_with_mouse(self, x, z, task): """Rotate the main camera according to the mouse movement. Args: x (float): The original mouse X position. z (float): The original mouse Y position. """ if not base.mouseWatcherNode.hasMouse(): # noqa: F821 return new_x = base.mouseWatcherNode.getMouseX() # noqa: F821 new_z = base.mouseWatcherNode.getMouseY() # noqa: F821 if new_x - x <= -0.125: self._np.setH(self._np.getH() - 1.5) elif new_x - x >= 0.125: self._np.setH(self._np.getH() + 1.5) elif new_z - z <= -0.125: r = self._np.getR() if r < 20: self._np.setR(r + 1.5) elif new_z - z >= 0.125: r = self._np.getR() if r > -30: self._np.setR(r - 1.5) return task.again def _set_move_keys(self): """Set camera move and rotate keys.""" # key pressed - start movement base.accept("arrow_up", self._move, MAX_UP_MOVE) # noqa: F821 base.accept("arrow_down", self._move, MAX_DOWN_MOVE) # noqa: F821 base.accept("arrow_left", self._move, MAX_LEFT_MOVE) # noqa: F821 base.accept("arrow_right", self._move, MAX_RIGHT_MOVE) # noqa: F821 # key released - stop base.accept("arrow_up-up", self._stop, [True]) # noqa: F821 base.accept("arrow_down-up", self._stop, [True]) # noqa: F821 base.accept("arrow_left-up", self._stop, [False]) # noqa: F821 base.accept("arrow_right-up", self._stop, [False]) # noqa: F821 # key pressed - start turning base.accept("alt-arrow_left", self._turn, [-360, 0]) # noqa: F821 base.accept("alt-arrow_right", self._turn, [360, 0]) # noqa: F821 base.accept("alt-arrow_up", self._turn, [0, -60]) # noqa: F821 base.accept("alt-arrow_down", self._turn, [0, 25]) # noqa: F821 # camera zooming controls base.accept("+", self._zoom, [0.7, 1.2, 1.75]) # noqa: F821 base.accept("-", self._zoom, [2, 3, 1.75]) # noqa: F821 base.accept("+-up", self._stop, [False, True, True]) # noqa: F821 base.accept("--up", self._stop, [False, True, True]) # noqa: F821 base.accept("wheel_up", self._zoom_with_mouse, [-0.25]) # noqa: F821 base.accept("wheel_down", self._zoom_with_mouse, [0.25]) # noqa: F821 base.accept("mouse2", self._turn_camera_with_mouse) # noqa: F821 base.accept( # noqa: F821 "mouse2-up", taskMgr.remove, # noqa: F821 extraArgs=["rotate_camera_with_mouse"], ) def _stop(self, stop_x, stop_zoom=False, is_hard=False): """Stop moving and rotating camera (on key release). Args: stop_x (bool): True - movement along x axis should be stopped. False - movement along y axis should be stopped. stop_zoom (bool): True if camera stopped zoom movement. is_hard (bool): If False, camera will be stopped with an deceleration interval. If True, stopping will be immediate. """ if self._move_int is not None: self._move_int.pause() if self._turn_int is not None: self._turn_int.pause() if stop_zoom: self._target = base.cam.getPos() # noqa: F821 elif stop_x: self._target.setX(base.cam.getX()) # noqa: F821 else: self._target.setY(base.cam.getY()) # noqa: F821 if not is_hard: self._move_int = LerpPosInterval( base.cam, 0.75, self._target, other=self._np # noqa: F821 ) self._move_int.start() def _toggle_centered_view(self): """Set camera onto default position. Centered position is optimal for characters manipulations. Press repeating returns camera to the previous position. """ if not self._is_centered: self._stop(False, is_hard=True) self._last_pos = base.cam.getPos() # noqa: F821 self._last_hpr = base.cam.getHpr() # noqa: F821 self._last_np_hpr = self._np.getHpr() base.cam.wrtReparentTo(base.train.model) # noqa: F821 base.cam.setPosHpr(0, 0, 1.8, 90, -90, 0) # noqa: F821 self._np.setHpr(0) self._disable_ctrl_keys() taskMgr.remove("move_camera_with_mouse") # noqa: F821 else: base.cam.wrtReparentTo(self._np) # noqa: F821 self._set_move_keys() base.cam.setPosHpr(*self._last_pos, *self._last_hpr) # noqa: F821 self._np.setHpr(*self._last_np_hpr) taskMgr.doMethodLater( # noqa: F821 0.1, self._move_with_mouse, "move_camera_with_mouse", appendTask=True) self._is_centered = not self._is_centered def _turn(self, h, r): """Turn camera with a single interval (on key press). Args: h (int): Translation for camera heading, angle. r (int): Translation for camera rolling, angle. """ if self._turn_int is not None and self._turn_int.isPlaying(): return self._turn_int = LerpHprInterval(self._np, 4, (self._np.getH() + h, 0, r)) self._turn_int.start() def _turn_camera_with_mouse(self): """Start the main camera movement by mouse.""" if not base.mouseWatcherNode.hasMouse(): # noqa: F821 return taskMgr.doMethodLater( # noqa: F821 0.01, self._rotate_camera_with_mouse, "rotate_camera_with_mouse", extraArgs=[ base.mouseWatcherNode.getMouseX(), # noqa: F821 base.mouseWatcherNode.getMouseY(), # noqa: F821 ], appendTask=True, ) def _zoom(self, x, z, zoom_time): """Zoom camera. Args: x (float): Translation along x axis. z (float): Translation along z axis. zoom_time (float): Time to zoom. """ if self._move_int is not None: self._move_int.pause() self._target.setX(x) self._target.setZ(z) self._move_int = LerpPosInterval( base.cam, zoom_time, self._target, other=self._np # noqa: F821 ) self._move_int.start() def _zoom_with_mouse(self, shift): """Zoom camera with mouse. Args: shift (float): Direction and coefficient of move. """ x, _, z = base.cam.getPos() # noqa: F821 new_x = x + shift new_z = z + shift if 2 >= new_x >= 0.7: x = new_x if 3 >= new_z >= 1.2: z = new_z self._zoom(x, z, 0.2) def enable_ctrl_keys(self): """Enable all the camera control keys.""" self._set_move_keys() base.accept("c", self._toggle_centered_view) # noqa: F821 taskMgr.doMethodLater( # noqa: F821 0.1, self._move_with_mouse, "move_camera_with_mouse", appendTask=True) def push(self): """Camera push caused by a kick/explosion.""" if self._move_int is not None: self._move_int.pause() if self._turn_int is not None: self._turn_int.pause() self._move_int = Sequence() self._target.setZ(base.cam.getZ() - random.uniform(-0.02, 0.02)) # noqa: F821 self._target.setX(base.cam.getX() + random.uniform(-0.03, 0.03)) # noqa: F821 self._target.setY(base.cam.getY() + random.uniform(-0.03, 0.03)) # noqa: F821 self._move_int.append( Parallel( LerpPosInterval( base.cam, 0.15, self._target, bakeInStart=False, # noqa: F821 ), LerpHprInterval( self._np, 0.15, ( self._np.getH() + random.uniform(-1, 1), self._np.getP() + random.uniform(-2, 2), self._np.getR() + random.uniform(-3, 3), ), ), )) self._target.setX(base.cam.getX()) # noqa: F821 self._target.setY(base.cam.getY()) # noqa: F821 self._target.setZ(base.cam.getZ()) # noqa: F821 self._move_int.append( Parallel( LerpPosInterval( base.cam, # noqa: F821 0.5, self._target, bakeInStart=False, blendType="easeOut", ), LerpHprInterval( self._np, 0.5, (self._np.getH(), 0, self._np.getR()), blendType="easeOut", ), )) self._move_int.start() def set_controls(self, train): """Configure the main camera and its controls. Args: train (train.Train): The Train object. """ base.disableMouse() # noqa: F821 self._np = train.node.attachNewNode("camera_node") base.cam.reparentTo(self._np) # noqa: F821 base.cam.setPos(self._target) # noqa: F821 base.cam.lookAt(train.model) # noqa: F821 self._set_move_keys() base.accept("c", self._toggle_centered_view) # noqa: F821 taskMgr.doMethodLater( # noqa: F821 0.1, self._move_with_mouse, "move_camera_with_mouse", appendTask=True) def set_hangar_pos(self, hangar): """Set camera to hangar position. Args: hangar (panda3d.core.NodePath): Hangar model. """ self._disable_ctrl_keys() self._stop(True, is_hard=True) base.ignore("c") # noqa: F821 self._last_pos = base.cam.getPos() # noqa: F821 self._last_hpr = base.cam.getHpr() # noqa: F821 self._last_np_pos = self._np.getPos() self._last_np_hpr = self._np.getHpr() base.cam.setPos(0) # noqa: F821 base.cam.setHpr(0) # noqa: F821 self._np.reparentTo(hangar) self._np.setPosHpr(-0.35, 1.36, 0.12, -163, 5, 0) def unset_hangar_pos(self): """Return camera back to normal position.""" base.cam.setPosHpr(*self._last_pos, *self._last_hpr) # noqa: F821 self._np.reparentTo(base.train.node) # noqa: F821 self._np.setPosHpr(*self._last_np_pos, *self._last_np_hpr)