コード例 #1
0
 def show(self):
     self.reparentTo(self.parent)
     self.setPos(0.1, 0, -0.018)
     newParent = self.parent.getParent().getParent()
     self.wrtReparentTo(newParent)
     if self.whosePartyLabel['text'] == ' ':
         host = base.cr.identifyAvatar(self.partyInfo.hostId)
         if host:
             name = host.getName()
             self.whosePartyLabel['text'] = name
     if self.whenTextLabel['text'] == ' ':
         time = myStrftime(self.partyInfo.startTime)
         self.whenTextLabel['text'] = time
     if self.partyStatusLabel['text'] == ' ':
         if self.partyInfo.status == PartyGlobals.PartyStatus.Cancelled:
             self.partyStatusLabel['text'] = TTLocalizer.CalendarPartyCancelled
         elif self.partyInfo.status == PartyGlobals.PartyStatus.Finished:
             self.partyStatusLabel['text'] = TTLocalizer.CalendarPartyFinished
         elif self.partyInfo.status == PartyGlobals.PartyStatus.Started:
             self.partyStatusLabel['text'] = TTLocalizer.CalendarPartyGo
         elif self.partyInfo.status == PartyGlobals.PartyStatus.NeverStarted:
             self.partyStatusLabel['text'] = TTLocalizer.CalendarPartyNeverStarted
         else:
             self.partyStatusLabel['text'] = TTLocalizer.CalendarPartyGetReady
     DirectFrame.show(self)
コード例 #2
0
 def show(self):
     self.reparentTo(self.parent)
     self.setPos(0.1, 0, -0.018)
     newParent = self.parent.getParent().getParent()
     self.wrtReparentTo(newParent)
     if self.whosePartyLabel['text'] == ' ':
         host = base.cr.identifyAvatar(self.partyInfo.hostId)
         if host:
             name = host.getName()
             self.whosePartyLabel['text'] = name
     if self.whenTextLabel['text'] == ' ':
         time = myStrftime(self.partyInfo.startTime)
         self.whenTextLabel['text'] = time
     if self.partyStatusLabel['text'] == ' ':
         if self.partyInfo.status == PartyGlobals.PartyStatus.Cancelled:
             self.partyStatusLabel[
                 'text'] = TTLocalizer.CalendarPartyCancelled
         elif self.partyInfo.status == PartyGlobals.PartyStatus.Finished:
             self.partyStatusLabel[
                 'text'] = TTLocalizer.CalendarPartyFinished
         elif self.partyInfo.status == PartyGlobals.PartyStatus.Started:
             self.partyStatusLabel['text'] = TTLocalizer.CalendarPartyGo
         elif self.partyInfo.status == PartyGlobals.PartyStatus.NeverStarted:
             self.partyStatusLabel[
                 'text'] = TTLocalizer.CalendarPartyNeverStarted
         else:
             self.partyStatusLabel[
                 'text'] = TTLocalizer.CalendarPartyGetReady
     DirectFrame.show(self)
コード例 #3
0
 def show(self):
     # we do this weirdness so it doesn't get clipped by the PlaneNode
     self.reparentTo(self.parent)
     self.setPos(0.1, 0, -0.018)
     newParent = self.parent.getParent().getParent()
     self.wrtReparentTo(newParent)
     if self.whosePartyLabel["text"] == " ":
         host = base.cr.identifyAvatar(self.partyInfo.hostId)
         if host:
             name = host.getName()
             if GMUtils.testGMIdentity(name):
                 name = GMUtils.handleGMName(name)
             self.whosePartyLabel["text"] = name
     if self.whenTextLabel["text"] == " ":
         time = myStrftime(self.partyInfo.startTime)
         self.whenTextLabel["text"] = time
     if self.partyStatusLabel["text"] == " ":
         if self.partyInfo.status == PartyGlobals.PartyStatus.Cancelled:
             self.partyStatusLabel[
                 "text"] = TTLocalizer.CalendarPartyCancelled
         elif self.partyInfo.status == PartyGlobals.PartyStatus.Finished:
             self.partyStatusLabel[
                 "text"] = TTLocalizer.CalendarPartyFinished
         elif self.partyInfo.status == PartyGlobals.PartyStatus.Started:
             self.partyStatusLabel["text"] = TTLocalizer.CalendarPartyGo
         elif self.partyInfo.status == PartyGlobals.PartyStatus.NeverStarted:
             self.partyStatusLabel[
                 "text"] = TTLocalizer.CalendarPartyNeverStarted
         else:
             self.partyStatusLabel[
                 "text"] = TTLocalizer.CalendarPartyGetReady
     DirectFrame.show(self)
コード例 #4
0
class Menu:
    def __init__(self):
        self.frameMain = DirectFrame(image="gui/BackGround.png",
                                     image_scale=(1.7778, 1, 1),
                                     frameSize=(base.a2dLeft, base.a2dRight,
                                                base.a2dBottom, base.a2dTop),
                                     frameColor=(0, 0, 0, 0))
        self.frameMain.setTransparency(1)

        # self.title = DirectLabel(
        #     scale = 0.3,
        #     text_align = TextNode.ALeft,
        #     pos = (-0.2, 0, 0.4),
        #     frameColor = (0, 0, 0, 0),
        #     text = "Arrival",
        #     text_fg = (1,0,0,1))
        # self.title.setTransparency(1)
        # self.title.reparentTo(self.frameMain)

        self.btn_newgame = self.createButton("Start", -.10, ["Menu-Game"])

        self.btn_option = self.createButton("Option", -.25, ["Menu-Option"])

        self.btnExit = self.createButton("Quit", -.40, ["Menu-Quit"])

        self.hide()

    def createButton(self, text, verticalPos, eventArgs):
        maps = loader.loadModel("gui/button_map")
        btnGeom = (maps.find("**/btn_ready"), maps.find("**/btn_click"),
                   maps.find("**/btn_rollover"), maps.find("**/btn_disabled"))
        sound = loader.loadSfx("Audio/click.wav")
        btn = DirectButton(
            text=text,
            text_fg=(1, 1, 1, 1),
            text_scale=0.05,
            text_pos=(0.25, -0.013),
            text_align=TextNode.ACenter,
            #text_font = loader.loadFont('DreamerOne Bold.ttf'),
            scale=2,
            pos=(base.a2dLeft + 1.8, 0, verticalPos),
            geom=btnGeom,
            relief=0,
            frameColor=(0, 0, 0, 0),
            command=base.messenger.send,
            extraArgs=eventArgs,
            pressEffect=True,
            rolloverSound=None,
            clickSound=sound)
        btn.reparentTo(self.frameMain)

    def show(self):
        self.frameMain.show()

    def hide(self):
        self.frameMain.hide()
コード例 #5
0
ファイル: notes.py プロジェクト: IlyaFaer/ForwardOnlyGame
class TeachingNotes:
    """GUI that shows teaching notes from time to time."""
    def __init__(self):
        self._note_text = base.labels.DEFAULT_NOTE  # noqa: F821

        self._fr = DirectFrame(
            parent=base.a2dBottomRight,  # noqa: F821
            frameSize=(-0.25, 0.25, -0.07, 0.07),
            pos=(-0.25, 0, 0.65),
            frameTexture=GUI_PIC + "metal1.png",
        )
        self._fr.setTransparency(TransparencyAttrib.MAlpha)

        self._note = DirectLabel(
            parent=self._fr,
            text="",
            text_fg=SILVER_COL,
            text_font=base.main_font,  # noqa: F821
            frameSize=(1, 1, 1, 1),
            text_scale=0.028,
            pos=(0, 0, 0.04),
        )
        self._fr.hide()

    def _hide_note(self, task):
        """Hide the current note and choose the next one."""
        self._fr.hide()
        self._note_text = random.choice(base.labels.NOTES)  # noqa: F821
        return task.done

    def _show_note(self, task):
        """Show the next teaching note."""
        self._note["text"] = self._note_text
        self._fr.show()

        taskMgr.doMethodLater(10, self._hide_note,
                              "hide_teaching_note")  # noqa: F821
        task.delayTime = 150
        return task.again

    def resume(self):
        """Resume showing teaching notes."""
        self._note_text = random.choice(base.labels.NOTES)  # noqa: F821
        taskMgr.doMethodLater(200, self._show_note,
                              "show_teaching_note")  # noqa: F821

    def start(self):
        """Start showing teaching notes in period."""
        taskMgr.doMethodLater(60, self._show_note,
                              "show_teaching_note")  # noqa: F821

    def stop(self):
        """Stop showing teaching notes."""
        self._fr.hide()
        taskMgr.remove("show_teaching_note")  # noqa: F821
        taskMgr.remove("hide_teaching_note")  # noqa: F821
コード例 #6
0
ファイル: journal.py プロジェクト: IlyaFaer/ForwardOnlyGame
    def show(self):
        """Show/hide the journal GUI."""
        if self._is_shown:
            self._main_fr.hide()
            self._close_snd.play()
            if not self._winned and self._read_coordinates:
                self._winned = True

                page = DirectFrame(
                    frameSize=(-0.73, 0.73, -0.9, 0.9),
                    frameTexture="gui/tex/paper1.png",
                    state=DGG.NORMAL,
                )
                page.setDepthTest(False)
                page.setTransparency(TransparencyAttrib.MAlpha)
                page.show()

                DirectLabel(
                    parent=page,
                    text=base.labels.UNTERRIFF_DISCOVERED_TITLE,  # noqa: F821
                    text_font=base.main_font,  # noqa: F821
                    frameSize=(0.6, 0.6, 0.6, 0.6),
                    text_scale=0.043,
                    pos=(0, 0, 0.65),
                )

                DirectLabel(
                    parent=page,
                    text=base.labels.UNTERRIFF_DISCOVERED,  # noqa: F821
                    text_font=base.main_font,  # noqa: F821
                    frameSize=(0.6, 0.6, 0.6, 0.6),
                    text_scale=0.037,
                    pos=(0, 0, 0.55),
                )

                DirectButton(  # Done
                    parent=page,
                    pos=(0, 0, -0.77),
                    text=base.labels.DISTINGUISHED[6],  # noqa: F821
                    text_font=base.main_font,  # noqa: F821
                    text_fg=RUST_COL,
                    text_shadow=(0, 0, 0, 1),
                    frameColor=(0, 0, 0, 0),
                    command=page.destroy,
                    extraArgs=[],
                    scale=(0.05, 0, 0.05),
                    clickSound=base.main_menu.click_snd,  # noqa: F821
                )

            self._read_coordinates = False
        else:
            self._main_fr.show()
            self._open_snd.play()

        self._is_shown = not self._is_shown
コード例 #7
0
ファイル: koscreen.py プロジェクト: jorjuato/panda3d-tutorial
class KoScreen(DirectObject):
    def __init__(self):
        self.frameMain = DirectFrame(
            frameSize = (base.a2dLeft, base.a2dRight,
                         base.a2dTop, base.a2dBottom),
            frameColor = (0, 0, 0, 0.75))
        self.frameMain.setTransparency(1)

        self.lbl_KO = DirectLabel(
            text = "K.O.",
            text_fg = (1,1,1,1),
            scale = 1,
            pos = (0, 0, 0),
            frameColor = (0,0,0,0))
        self.lbl_KO.setTransparency(1)
        self.lbl_KO.reparentTo(self.frameMain)

        self.lbl_PlayerXWon = DirectLabel(
            text = "PLAYER X WON",
            text_fg = (1,1,1,1),
            scale = 0.25,
            pos = (0, 0, -0.5),
            frameColor = (0,0,0,0))
        self.lbl_PlayerXWon.setTransparency(1)
        self.lbl_PlayerXWon.reparentTo(self.frameMain)

        self.btnContinue = DirectButton(
            text = "CONTINUE",
            text_fg = (1,1,1,1),
            scale = 0.1,
            pad = (0.15, 0.15),
            pos = (0, 0, -0.8),
            frameColor = (
                (0.2,0.2,0.2,0.8),
                (0.4,0.4,0.4,0.8),
                (0.4,0.4,0.4,0.8),
                (0.1,0.1,0.1,0.8),
                ),
            relief = 1,
            command = base.messenger.send,
            extraArgs = ["KoScreen-Back"],
            pressEffect = False,
            rolloverSound = None,
            clickSound = None)
        self.btnContinue.setTransparency(1)
        self.btnContinue.reparentTo(self.frameMain)

        self.hide()

    def show(self, succseedingPlayer):
        self.frameMain.show()
        self.lbl_PlayerXWon["text"] = "PLAYER %d WON" % succseedingPlayer

    def hide(self):
        self.frameMain.hide()
コード例 #8
0
class Death:
    def __init__(self):
        self.frameDeath = DirectFrame(image="assets/gui/BackGround_d.jpg",
                                      image_scale=(1.7778, 1, 1),
                                      frameSize=(base.a2dLeft, base.a2dRight,
                                                 base.a2dBottom, base.a2dTop),
                                      frameColor=(0, 0, 0, 0))
        self.frameDeath.setTransparency(1)

        self.title = DirectLabel(scale=0.15,
                                 text_align=TextNode.ACenter,
                                 pos=(0, 0, 0.4),
                                 frameColor=(0, 0, 0, 0),
                                 text="You Dead",
                                 text_fg=(1, 1, 1, 1))
        self.title.setTransparency(1)
        self.title.reparentTo(self.frameDeath)

        self.btn_newgame = self.createButton("Restart", -.10, ["Death-Game"])

        self.btn_option = self.createButton("Back", -.25, ["Death-Menu"])

        self.btnExit = self.createButton("Quit", -.40, ["Death-Quit"])

        self.hide()

    def createButton(self, text, verticalPos, eventArgs):
        maps = loader.loadModel("gui/button_map")
        btnGeom = (maps.find("**/btn_ready"), maps.find("**/btn_click"),
                   maps.find("**/btn_rollover"), maps.find("**/btn_disabled"))
        sound = loader.loadSfx("Audio/click.wav")
        sound.setVolume(0.1)
        btn = DirectButton(
            text=text,
            text_fg=(1, 1, 1, 1),
            text_scale=0.05,
            text_pos=(0.02, -0.013),
            text_align=TextNode.ACenter,
            scale=2,
            pos=(0, 0, verticalPos),
            #geom = btnGeom,
            relief=0,
            frameColor=(0, 0, 0, 0),
            command=base.messenger.send,
            extraArgs=eventArgs,
            pressEffect=True,
            rolloverSound=None,
            clickSound=sound)
        btn.reparentTo(self.frameDeath)

    def show(self):
        self.frameDeath.show()

    def hide(self):
        self.frameDeath.hide()
コード例 #9
0
class LoadingScreen():
    def __init__(self):
        # a fill panel so the player doesn't see how everything
        # gets loaded in the background
        self.frameMain = DirectFrame(
            # size of the frame
            frameSize = (base.a2dLeft, base.a2dRight,
                         base.a2dTop, base.a2dBottom),
			image = "Logo.png",
			image_scale = (0.612/2.0, 1, 0.495/2.0),
			image_pos = (0, 0, 0.7),
            # tramsparent bg color
            frameColor = (0, 0, 0, 1))
        self.frameMain.setTransparency(1)

        # the text Loading... on top
        self.lblLoading = DirectLabel(
            scale = 0.25,
            pos = (0, 0, 0),
            frameColor = (0, 0, 0, 0),
            text = _("Loading..."),
            text_align = TextNode.ACenter,
            text_fg = (1,1,1,1))
        self.lblLoading.reparentTo(self.frameMain)

        # the waitbar on the bottom
        self.wbLoading = DirectWaitBar(
            text = "0%",
            text_fg = (1,1,1,1),
            value = 0,
            pos = (0, 0, -0.5),
            barColor = (0.5, 0.4, 0.1, 1),
            frameColor = (0.1, 0.1, 0.1, 1))
        self.wbLoading.reparentTo(self.frameMain)

    def show(self):
        self.frameMain.show()
        # and render two frames so the loading screen
        # is realy shown on screen
        base.graphicsEngine.renderFrame()
        base.graphicsEngine.renderFrame()

    def hide(self):
        self.frameMain.hide()

    def setLoadingValue(self, value):
        """Set the waitbar value to the given value, where
        value has to be a integer from 0 to 100"""
        if value > 100: value = 100
        if value < 0: value = 0
        self.wbLoading["value"] = value
        self.wbLoading["text"] = "{0}%".format(value)
        base.graphicsEngine.renderFrame()
        base.graphicsEngine.renderFrame()
コード例 #10
0
class MainMenu(object):
    def __init__(self, framework: ShowBase):
        self.f = framework
        self.main_frame = DirectFrame(frameSize=(self.f.a2dLeft,
                                                 self.f.a2dRight,
                                                 self.f.a2dBottom,
                                                 self.f.a2dTop))
        self.main_frame.set_transparency(1)
        self.title = DirectLabel(scale=0.2,
                                 pos=(0, 0, self.f.a2dTop - 0.25),
                                 frameColor=(0, 0, 0, 0),
                                 text="Battle Tank",
                                 text_fg=(0, 0, 0, 1))
        self.title.set_transparency(1)
        self.title.reparent_to(self.main_frame)

        self.btn_start = self.create_btn("Start", 0.12,
                                         [settings.START_GAME_DRIVER])
        self.btn_quit = self.create_btn("Quit", -0.12,
                                        [settings.QUIT_GAME_DRIVER])
        self.hide()

    def create_btn(self, label, v_position, event_args):
        maps = self.f.loader.loadModel(settings.ass / "button_map")
        geom = (maps.find("**/btn_ready"), maps.find("**/btn_click"),
                maps.find("**/btn_rollover"), maps.find("**/btn_disabled"))
        btn = DirectButton(text=label,
                           text_fg=(0, 0, 0, 1),
                           text_scale=0.05,
                           text_pos=(0.02, -0.015),
                           text_align=TextNode.ALeft,
                           scale=2,
                           pos=(self.f.a2dLeft + 0.2, 0, v_position),
                           geom=geom,
                           relief=0,
                           frameColor=(0, 0, 0, 0),
                           command=self.f.messenger.send,
                           extraArgs=event_args,
                           pressEffect=False,
                           rolloverSound=None,
                           clickSound=None)
        btn.reparent_to(self.main_frame)
        return btn

    def show(self):
        self.main_frame.show()

    def hide(self):
        self.main_frame.hide()

    def hide_start_btn(self):
        self.btn_start.hide()
コード例 #11
0
class KoScreen(DirectObject):
    def __init__(self):
        self.frameMain = DirectFrame(frameSize=(base.a2dLeft, base.a2dRight,
                                                base.a2dBottom, base.a2dTop),
                                     frameColor=(0, 0, 0, 0.75))
        self.frameMain.setTransparency(1)

        self.lbl_KO = DirectLabel(text="K.O.",
                                  text_fg=(1, 1, 1, 1),
                                  scale=1,
                                  pos=(0, 0, 0),
                                  frameColor=(0, 0, 0, 0))
        self.lbl_KO.setTransparency(1)
        self.lbl_KO.reparentTo(self.frameMain)

        self.lbl_PlayerXWon = DirectLabel(text="PLAYER X WON",
                                          text_fg=(1, 1, 1, 1),
                                          scale=0.25,
                                          pos=(0, 0, -0.5),
                                          frameColor=(0, 0, 0, 0))
        self.lbl_PlayerXWon.setTransparency(1)
        self.lbl_PlayerXWon.reparentTo(self.frameMain)

        self.btnContinue = DirectButton(text="CONTINUE",
                                        text_fg=(1, 1, 1, 1),
                                        scale=0.1,
                                        pad=(0.15, 0.15),
                                        pos=(0, 0, -0.8),
                                        frameColor=(
                                            (0.2, 0.2, 0.2, 0.8),
                                            (0.4, 0.4, 0.4, 0.8),
                                            (0.4, 0.4, 0.4, 0.8),
                                            (0.1, 0.1, 0.1, 0.8),
                                        ),
                                        relief=1,
                                        command=base.messenger.send,
                                        extraArgs=["KoScreen-Back"],
                                        pressEffect=False,
                                        rolloverSound=None,
                                        clickSound=None)
        self.btnContinue.setTransparency(1)
        self.btnContinue.reparentTo(self.frameMain)

        self.hide()

    def show(self, succseedingPlayer):
        self.frameMain.show()
        self.lbl_PlayerXWon["text"] = "PLAYER {} WON".format(succseedingPlayer)

    def hide(self):
        self.frameMain.hide()
コード例 #12
0
class LoadingScreen():
    """Show a directWaitbar to display the current loading state of the
    application"""
    def __init__(self):
        # a fill panel so the player doesn't see how everything
        # gets loaded in the background
        self.frameMain = DirectFrame(
            image="gui/MenuBackground.png",
            image_scale=(1.7778, 1, 1),
            #image_pos=(0, 0, 0.25),
            frameSize=(
                base.a2dLeft, base.a2dRight,
                base.a2dTop, base.a2dBottom),
            frameColor=(0,0,0,0))
        self.frameMain.setTransparency(True)
        self.frameMain.setBin("fixed", 6000)
        self.frameMain.setDepthWrite(False)

        self.logo = DirectFrame(
            image="Logo.png",
            image_scale=0.25,
            image_pos=(0, 0, 0.55),
            frameSize=(
                base.a2dLeft, base.a2dRight,
                base.a2dTop, base.a2dBottom),
            frameColor=(0,0,0,0))
        self.logo.reparentTo(self.frameMain)


        # the text Loading...
        self.lblLoading = DirectLabel(
            scale=0.10,
            pos=(0, 0, -0.15),
            frameColor=(0, 0, 0, 0),
            text=_("Loading..."),
            text_align=TextNode.ACenter,
            text_fg=(1, 1, 1, 1))
        self.lblLoading.reparentTo(self.frameMain)

        self.stop()

    def start(self):
        self.frameMain.show()
        base.graphicsEngine.renderFrame()
        base.graphicsEngine.renderFrame()

    def stop(self):
        self.frameMain.hide()
コード例 #13
0
class Mainmenu():
    def __init__(self):
        self.frameMain = DirectFrame(
            image="gui/MenuBackground.png",
            image_scale=(1.7778, 1, 1),
            #image_pos=(0, 0, 0.25),
            frameSize=(
                base.a2dLeft, base.a2dRight,
                base.a2dTop, base.a2dBottom),
            frameColor=(0,0,0,0))
        self.frameMain.setTransparency(True)

        self.logo = DirectFrame(
            image="Logo.png",
            image_scale=0.45,
            image_pos=(0, 0, 0.35),
            frameSize=(
                base.a2dLeft, base.a2dRight,
                base.a2dTop, base.a2dBottom),
            frameColor=(0,0,0,0))
        self.logo.reparentTo(self.frameMain)

        btnGeom = "gui/button"

        self.btnStart = menuHelper.createButton(_("Start"), btnGeom, 0, -0.7, ["menu_start"])
        self.btnStart.reparentTo(self.frameMain)

        self.btnOptions = menuHelper.createButton(_("Options"), btnGeom, -1.0, -0.7, ["menu_options"])
        self.btnOptions.reparentTo(self.frameMain)

        self.btnQuit = menuHelper.createButton(_("Quit"), btnGeom, 1.0, -0.7, ["menu_quit"])
        self.btnQuit.reparentTo(self.frameMain)

        self.hide()

    def show(self):
        self.frameMain.show()

    def hide(self):
        self.frameMain.hide()
コード例 #14
0
ファイル: stratCam.py プロジェクト: croza/RR2
class GUI:
	def __init__(self, mainClass):
		self.unitFrame = DirectFrame(frameColor = (0,0,0,0.5), frameSize = (-0.25, 0.25, -1, 1), pos = (0.8, 0, 0))
		self.unitFrame.reparentTo(render2d)
		self.unitFrame.hide()
		
		self.wallFrame = DirectFrame(frameColor = (0,0,0,0.5), frameSize = (-0.25, 0.25, -1, 1), pos = (0.8, 0, 0))
		self.wallFrame.reparentTo(render2d)
	#	self.wallFrame.hide()
		
	#	self.drillWall = DirectButton(text = ('drill wall'), scale = 0.1, command = mainClass.cameraClass.mineWall, extraArgs = [mainClass])
	#	self.drillWall.reparentTo(self.wallFrame)
	#	self.drillWall.setPos(0,0,0.9)
		
		self.drillWall = DirectButton(text = 'Hi', scale = 0.1, command = self.queueMine, extraArgs = [mainClass])
	#	self.drillWall.reparentTo(self.wallFrame)
		self.drillWall.setPos(0,0,0.5)
		self.drillWall.hide()
		
	def hi(self):
		print 'HIII'
		
	def showWall(self, wall, mainClass):
		if (wall.selectable == True):
			
			self.hideUIs()
			self.drillWall.show()
			
		#	if (wall.dig != None):
		#		self.
		
#		uButton1 = DirectButton(text = ('need'), scale = 0.1)
#		uButton1.reparentTo(self.unitFrame)
#		uButton1.setPos(0,0,0.9)
#		
#		uButton2 = DirectButton(text = ('to'), scale = 0.1)
#		uButton2.reparentTo(self.unitFrame)
#		uButton2.setPos(0,0,0.7)
#		
#		uButton3 = DirectButton(text = ('finish'), scale = 0.1)
#		uButton3.reparentTo(self.unitFrame)
#		uButton3.setPos(0,0,0.5)
#		
#		uButton4 = DirectButton(text = ('GUI'), scale = 0.1)
#		uButton4.reparentTo(self.unitFrame)
#		uButton4.setPos(0,0,0.3)
		
		
	
	def unitGUI(self, mainClass, unitnumber):
		self.hideUIs()
		self.unitFrame.show()
	#	if (mainClass.parserClass.unit
	
	def wallGUI(self, mainClass, wallPos):
		pass
	#	self.unitFrame.hide()
	#	self.wallFrame.show()
	#	if (mainClass.mapLoaderClass.tileArray[wallPos[1]][wallPos[0]].drillTime != None):
	#		self.drillWall.show()
	
	def hideUIs(self):
		self.unitFrame.hide()
		
	def queueMine(self, mainClass):
	#	mainClass.cameraClass.clearSelection(mainClass)
		mainClass.priorities.queueMine(mainClass.mouseClass.tileSelected)
コード例 #15
0
class LaffMeter(DirectFrame):
    deathColor = Vec4(0.58039216, 0.80392157, 0.34117647, 1.0)

    def __init__(self, avdna, hp, maxHp):
        DirectFrame.__init__(self, relief=None, sortOrder=50)
        self.initialiseoptions(LaffMeter)
        self.container = DirectFrame(parent=self, relief=None)
        self.style = avdna
        self.av = None
        self.hp = hp
        self.maxHp = maxHp
        self.__obscured = 0
        if self.style.type == 't':
            self.isToon = 1
        else:
            self.isToon = 0
        self.load()
        return

    def obscure(self, obscured):
        self.__obscured = obscured
        if self.__obscured:
            self.hide()

    def isObscured(self):
        return self.__obscured

    def load(self):
        gui = loader.loadModel('phase_3/models/gui/laff_o_meter')
        if self.isToon:
            hType = self.style.getType()
            if hType == 'dog':
                headModel = gui.find('**/doghead')
            elif hType == 'cat':
                headModel = gui.find('**/cathead')
            elif hType == 'mouse':
                headModel = gui.find('**/mousehead')
            elif hType == 'horse':
                headModel = gui.find('**/horsehead')
            elif hType == 'rabbit':
                headModel = gui.find('**/bunnyhead')
            elif hType == 'duck':
                headModel = gui.find('**/duckhead')
            elif hType == 'monkey':
                headModel = gui.find('**/monkeyhead')
            elif hType == 'bear':
                headModel = gui.find('**/bearhead')
            elif hType == 'pig':
                headModel = gui.find('**/pighead')
            else:
                raise StandardError('unknown toon species: ', hType)
            self.color = self.style.getHeadColor()
            self.container['image'] = headModel
            self.container['image_color'] = self.color
            self.resetFrameSize()
            self.setScale(0.1)
            self.frown = DirectFrame(parent=self.container, relief=None, image=gui.find('**/frown'))
            self.frown.setY(-0.1)
            self.smile = DirectFrame(parent=self.container, relief=None, image=gui.find('**/smile'))
            self.eyes = DirectFrame(parent=self.container, relief=None, image=gui.find('**/eyes'))
            self.eyes.setY(-0.1)
            self.openSmile = DirectFrame(parent=self.container, relief=None, image=gui.find('**/open_smile'))
            self.openSmile.setY(-0.1)
            self.tooth1 = DirectFrame(parent=self.openSmile, relief=None, image=gui.find('**/tooth_1'))
            self.tooth2 = DirectFrame(parent=self.openSmile, relief=None, image=gui.find('**/tooth_2'))
            self.tooth3 = DirectFrame(parent=self.openSmile, relief=None, image=gui.find('**/tooth_3'))
            self.tooth4 = DirectFrame(parent=self.openSmile, relief=None, image=gui.find('**/tooth_4'))
            self.tooth5 = DirectFrame(parent=self.openSmile, relief=None, image=gui.find('**/tooth_5'))
            self.tooth6 = DirectFrame(parent=self.openSmile, relief=None, image=gui.find('**/tooth_6'))
            self.maxLabel = DirectLabel(parent=self.eyes, relief=None, pos=(0.442, 0, 0.051), text='120', text_scale=0.4, text_font=ToontownGlobals.getInterfaceFont())
            self.maxLabel.setY(-0.1)
            self.hpLabel = DirectLabel(parent=self.eyes, relief=None, pos=(-0.398, 0, 0.051), text='120', text_scale=0.4, text_font=ToontownGlobals.getInterfaceFont())
            self.hpLabel.setY(-0.1)
            self.teeth = [self.tooth6,
             self.tooth5,
             self.tooth4,
             self.tooth3,
             self.tooth2,
             self.tooth1]
            for tooth in self.teeth:
                tooth.setY(-0.1)
            self.fractions = [0.0,
             0.166666,
             0.333333,
             0.5,
             0.666666,
             0.833333]
        gui.removeNode()
        return

    def destroy(self):
        if self.av:
            ToontownIntervals.cleanup(self.av.uniqueName('laffMeterBoing') + '-' + str(self.this))
            ToontownIntervals.cleanup(self.av.uniqueName('laffMeterBoing') + '-' + str(self.this) + '-play')
            self.ignore(self.av.uniqueName('hpChange'))
        del self.style
        del self.av
        del self.hp
        del self.maxHp
        if self.isToon:
            del self.frown
            del self.smile
            del self.openSmile
            del self.tooth1
            del self.tooth2
            del self.tooth3
            del self.tooth4
            del self.tooth5
            del self.tooth6
            del self.teeth
            del self.fractions
            del self.maxLabel
            del self.hpLabel
        DirectFrame.destroy(self)

    def adjustTeeth(self):
        if self.isToon:
            for i in range(len(self.teeth)):
                if self.hp > self.maxHp * self.fractions[i]:
                    self.teeth[i].show()
                else:
                    self.teeth[i].hide()

    def adjustText(self):
        if self.isToon:
            if self.maxLabel['text'] != str(self.maxHp) or self.hpLabel['text'] != str(self.hp):
                self.maxLabel['text'] = str(self.maxHp)
                self.hpLabel['text'] = str(self.hp)

    def animatedEffect(self, delta):
        if delta == 0 or self.av == None:
            return
        name = self.av.uniqueName('laffMeterBoing') + '-' + str(self.this)
        ToontownIntervals.cleanup(name)
        if delta > 0:
            ToontownIntervals.start(ToontownIntervals.getPulseLargerIval(self.container, name))
        else:
            ToontownIntervals.start(ToontownIntervals.getPulseSmallerIval(self.container, name))
        return

    def adjustFace(self, hp, maxHp, quietly = 0):
        if self.isToon and self.hp != None:
            self.frown.hide()
            self.smile.hide()
            self.openSmile.hide()
            self.eyes.hide()
            for tooth in self.teeth:
                tooth.hide()

            delta = hp - self.hp
            self.hp = hp
            self.maxHp = maxHp
            if self.hp < 1:
                self.frown.show()
                self.container['image_color'] = self.deathColor
            elif self.hp >= self.maxHp:
                self.smile.show()
                self.eyes.show()
                self.container['image_color'] = self.color
            else:
                self.openSmile.show()
                self.eyes.show()
                self.maxLabel.show()
                self.hpLabel.show()
                self.container['image_color'] = self.color
                self.adjustTeeth()
            self.adjustText()
            if not quietly:
                self.animatedEffect(delta)
        return

    def start(self):
        if self.av:
            self.hp = self.av.hp
            self.maxHp = self.av.maxHp
        if self.isToon:
            if not self.__obscured:
                self.show()
            self.adjustFace(self.hp, self.maxHp, 1)
            if self.av:
                self.accept(self.av.uniqueName('hpChange'), self.adjustFace)

    def stop(self):
        if self.isToon:
            self.hide()
            if self.av:
                self.ignore(self.av.uniqueName('hpChange'))

    def setAvatar(self, av):
        if self.av:
            self.ignore(self.av.uniqueName('hpChange'))
        self.av = av
コード例 #16
0
class DistributedMoleField(DistributedNodePathEntity, MoleFieldBase.MoleFieldBase):
    notify = DirectNotifyGlobal.directNotify.newCategory('DistributedMoleField')
    ScheduleTaskName = 'moleFieldScheduler'

    def __init__(self, cr):
        DistributedNodePathEntity.__init__(self, cr)
        self.gameStarted = False
        self.moleHills = []
        self.numMolesWhacked = 0
        self.timer = None
        self.frame2D = None
        self.isToonInRange = 0
        self.detectCount = 0
        self.cameraHold = None
        self.activeField = 1
        self.dimensionX = 0.0
        self.dimensionY = 0.0
        self.gameText = TTLocalizer.MolesInstruction
        self.winText = TTLocalizer.MolesFinished
        self.pityWinText = TTLocalizer.MolesPityWin
        self.restartedText = TTLocalizer.MolesRestarted
        self.toonHitTracks = {}
        self.hasRestarted = 0
        self.hasEntered = 0
        self.MolesWhackedTarget = 1000
        self.GameDuration = 1000
        return

    def disable(self):
        self.cleanupTimer()
        for ival in self.toonHitTracks.values():
            ival.finish()

        self.toonHitTracks = {}
        DistributedNodePathEntity.disable(self)
        taskMgr.remove(self.detectName)
        self.ignoreAll()

    def delete(self):
        self.soundBomb = None
        self.soundBomb2 = None
        self.soundCog = None
        DistributedNodePathEntity.delete(self)
        self.stopScheduleTask()
        for mole in self.moleHills:
            mole.destroy()

        self.moleHills = []
        self.cleanupTimer()
        self.unloadGui()
        return

    def announceGenerate(self):
        DistributedNodePathEntity.announceGenerate(self)
        self.loadModel()
        self.loadGui()
        self.detectName = 'moleField %s' % self.doId
        taskMgr.doMethodLater(0.1, self.__detect, self.detectName)
        self.calcDimensions()
        self.notify.debug('announceGenerate doId=%d entId=%d' % (self.doId, self.entId))

    def setNumSquaresX(self, num):
        self.numSquaresX = num
        self.calcDimensions()

    def setNumSquaresY(self, num):
        self.numSquaresY = num
        self.calcDimensions()

    def setSpacingX(self, num):
        self.spacingX = num
        self.calcDimensions()

    def setSpacingY(self, num):
        self.spacingY = num
        self.calcDimensions()

    def calcDimensions(self):
        self.dimensionX = self.numSquaresX * self.spacingX
        self.dimensionY = self.numSquaresY * self.spacingY
        self.centerCenterNode()

    def loadModel(self):
        moleIndex = 0
        self.moleHills = []
        for indexY in xrange(self.numSquaresY):
            for indexX in xrange(self.numSquaresX):
                xPos = indexX * self.spacingX
                yPos = indexY * self.spacingY
                newMoleHill = MoleHill.MoleHill(xPos, yPos, 0, self, moleIndex)
                newMoleHill.reparentTo(self)
                self.moleHills.append(newMoleHill)
                moleIndex += 1

        self.numMoles = len(self.moleHills)
        self.centerNode = self.attachNewNode('center')
        self.centerCenterNode()
        self.soundBomb = base.loadSfx('phase_12/audio/sfx/Mole_Surprise.ogg')
        self.soundBomb2 = base.loadSfx('phase_3.5/audio/dial/AV_pig_howl.ogg')
        self.soundCog = base.loadSfx('phase_12/audio/sfx/Mole_Stomp.ogg')
        self.soundUp = base.loadSfx('phase_4/audio/sfx/MG_Tag_C.ogg')
        self.soundDown = base.loadSfx('phase_4/audio/sfx/MG_cannon_whizz.ogg')
        upInterval = SoundInterval(self.soundUp, loop=0)
        downInterval = SoundInterval(self.soundDown, loop=0)
        self.soundIUpDown = Sequence(upInterval, downInterval)

    def centerCenterNode(self):
        self.centerNode.setPos(self.dimensionX * 0.5, self.dimensionY * 0.5, 0.0)

    def loadGui(self):
        self.frame2D = DirectFrame(scale=1.0, pos=(0.0, 0, 0.9), relief=DGG.FLAT, parent=aspect2d, frameSize=(-0.3,
         0.3,
         -0.05,
         0.05), frameColor=(0.737, 0.573, 0.345, 0.3))
        self.scoreLabel = DirectLabel(parent=self.frame2D, relief=None, pos=(0, 0, 0), scale=1.0, text='', text_font=ToontownGlobals.getSignFont(), text0_fg=(1, 1, 1, 1), text_scale=0.075, text_pos=(0, -0.02))
        self.updateGuiScore()
        self.frame2D.hide()
        return

    def unloadGui(self):
        self.frame2D.destroy()
        self.frame2D = None
        return

    def setGameStart(self, timestamp, molesWhackTarget, totalTime):
        self.GameDuration = totalTime
        self.MolesWhackedTarget = molesWhackTarget
        self.activeField = 1
        self.isToonInRange = 0
        self.scheduleMoles()
        self.notify.debug('%d setGameStart: Starting game' % self.doId)
        self.gameStartTime = globalClockDelta.networkToLocalTime(timestamp)
        self.gameStarted = True
        for hill in self.moleHills:
            hill.setGameStartTime(self.gameStartTime)

        curGameTime = self.getCurrentGameTime()
        timeLeft = self.GameDuration - curGameTime
        self.cleanupTimer()
        self.timer = ToontownTimer.ToontownTimer()
        self.timer.posBelowTopRightCorner()
        self.timer.setTime(timeLeft)
        self.timer.countdown(timeLeft, self.timerExpired)
        self.startScheduleTask()
        self.frame2D.show()
        if self.hasRestarted:
            self.level.countryClub.showInfoText(self.restartedText)
            self.sendUpdate('damageMe', [])
        else:
            self.hasRestarted = 1
        self.updateGuiScore()

    def local2GameTime(self, timestamp):
        return timestamp - self.gameStartTime

    def game2LocalTime(self, timestamp):
        return timestamp + self.gameStartTime

    def getCurrentGameTime(self):
        return self.local2GameTime(globalClock.getFrameTime())

    def startScheduleTask(self):
        taskMgr.add(self.scheduleTask, self.ScheduleTaskName)

    def stopScheduleTask(self):
        taskMgr.remove(self.ScheduleTaskName)

    def scheduleTask(self, task):
        curTime = self.getCurrentGameTime()
        while self.schedule and self.schedule[0][0] <= curTime and self.activeField:
            popupInfo = self.schedule[0]
            self.schedule = self.schedule[1:]
            startTime, moleIndex, curMoveUpTime, curStayUpTime, curMoveDownTime, moleType = popupInfo
            hill = self.moleHills[moleIndex]
            hill.doMolePop(startTime, curMoveUpTime, curStayUpTime, curMoveDownTime, moleType)

        if self.schedule:
            return task.cont
        else:
            return task.done

    def handleEnterHill(self, colEntry):
        if not self.gameStarted:
            self.notify.debug('sending clientTriggered for %d' % self.doId)
            self.sendUpdate('setClientTriggered', [])

    def handleEnterMole(self, colEntry):
        if not self.gameStarted:
            self.notify.debug('sending clientTriggered for %d' % self.doId)
            self.sendUpdate('setClientTriggered', [])
        surfaceNormal = colEntry.getSurfaceNormal(render)
        self.notify.debug('surfaceNormal=%s' % surfaceNormal)
        into = colEntry.getIntoNodePath()
        moleIndex = int(into.getName().split('-')[-1])
        self.notify.debug('hit mole %d' % moleIndex)
        moleHill = self.moleHills[moleIndex]
        moleHill.stashMoleCollision()
        popupNum = moleHill.getPopupNum()
        if moleHill.hillType == MoleFieldBase.HILL_MOLE:
            timestamp = globalClockDelta.getFrameNetworkTime()
            moleHill.setHillType(MoleFieldBase.HILL_WHACKED)
            self.sendUpdate('whackedBomb', [moleIndex, popupNum, timestamp])
            self.__showToonHitByBomb(localAvatar.doId, moleIndex, timestamp)
        elif moleHill.hillType == MoleFieldBase.HILL_BOMB:
            moleHill.setHillType(MoleFieldBase.HILL_COGWHACKED)
            self.soundCog.play()
            self.sendUpdate('whackedMole', [moleIndex, popupNum])

    def updateMole(self, moleIndex, status):
        if status == self.WHACKED:
            moleHill = self.moleHills[moleIndex]
            if not moleHill.hillType == MoleFieldBase.HILL_COGWHACKED:
                moleHill.setHillType(MoleFieldBase.HILL_COGWHACKED)
                self.soundCog.play()
            moleHill.doMoleDown()

    def updateGuiScore(self):
        molesLeft = self.MolesWhackedTarget - self.numMolesWhacked
        if self.frame2D and hasattr(self, 'scoreLabel') and molesLeft >= 0:
            newText = TTLocalizer.MolesLeft % molesLeft
            self.scoreLabel['text'] = newText

    def setScore(self, score):
        self.notify.debug('score=%d' % score)
        self.numMolesWhacked = score
        self.updateGuiScore()
        molesLeft = self.MolesWhackedTarget - self.numMolesWhacked
        if molesLeft == 0:
            self.gameWon()

    def cleanupTimer(self):
        if self.timer:
            self.timer.stop()
            self.timer.destroy()
            self.timer = None
        return

    def timerExpired(self):
        self.cleanupTimer()
        self.cleanDetect()

    def gameWon(self):
        for hill in self.moleHills:
            hill.forceMoleDown()

        self.cleanupTimer()
        self.frame2D.hide()
        self.level.countryClub.showInfoText(self.winText)
        self.cleanDetect()

    def setPityWin(self):
        for hill in self.moleHills:
            hill.forceMoleDown()

        self.cleanupTimer()
        self.frame2D.hide()
        self.level.countryClub.showInfoText(self.pityWinText)
        self.cleanDetect()

    def cleanDetect(self):
        self.activeField = 0
        self.doToonOutOfRange()

    def __detect(self, task):
        distance = self.centerNode.getDistance(localAvatar)
        greaterDim = self.dimensionX
        if self.dimensionY > self.dimensionX:
            greaterDim = self.gridScaleY
        self.detectCount += 1
        if self.detectCount > 5:
            self.detectCount = 0
        if distance < greaterDim * 0.75:
            if not self.isToonInRange:
                self.doToonInRange()
        elif self.isToonInRange:
            self.doToonOutOfRange()
        taskMgr.doMethodLater(0.1, self.__detect, self.detectName)
        return Task.done

    def doToonInRange(self):
        if not self.gameStarted:
            self.notify.debug('sending clientTriggered for %d' % self.doId)
            self.sendUpdate('setClientTriggered', [])
        self.isToonInRange = 1
        if self.activeField:
            self.setUpCamera()
            if not self.hasEntered:
                self.level.countryClub.showInfoText(self.gameText)
                self.hasEntered = 1

    def setUpCamera(self):
        camHeight = base.localAvatar.getClampedAvatarHeight()
        heightScaleFactor = camHeight * 0.3333333333
        defLookAt = Point3(0.0, 1.5, camHeight)
        cameraPoint = Point3(0.0, -22.0 * heightScaleFactor, camHeight + 12.0)
        base.localAvatar.setIdealCameraPos(cameraPoint)

    def doToonOutOfRange(self):
        self.isToonInRange = 0
        base.localAvatar.setCameraPositionByIndex(base.localAvatar.cameraIndex)
        self.cameraHold = None
        return

    def reportToonHitByBomb(self, avId, moleIndex, timestamp):
        if avId != localAvatar.doId:
            self.__showToonHitByBomb(avId, moleIndex, timestamp)
            moleHill = self.moleHills[moleIndex]
            if not moleHill.hillType == MoleFieldBase.HILL_WHACKED:
                moleHill.setHillType(MoleFieldBase.HILL_WHACKED)
                self.soundCog.play()
            moleHill.doMoleDown()

    def __showToonHitByBomb(self, avId, moleIndex, timestamp = 0):
        toon = base.cr.doId2do.get(avId)
        moleHill = self.moleHills[moleIndex]
        if toon == None:
            return
        rng = random.Random(timestamp)
        curPos = toon.getPos(render)
        oldTrack = self.toonHitTracks.get(avId)
        if oldTrack:
            if oldTrack.isPlaying():
                oldTrack.finish()
        toon.setPos(curPos)
        toon.setZ(self.getZ())
        parentNode = render.attachNewNode('mazeFlyToonParent-' + `avId`)
        parentNode.setPos(toon.getPos(render))
        toon.reparentTo(parentNode)
        toon.setPos(0, 0, 0)
        startPos = parentNode.getPos()
        dropShadow = toon.dropShadow.copyTo(parentNode)
        dropShadow.setScale(toon.dropShadow.getScale(render))
        trajectory = Trajectory.Trajectory(0, Point3(0, 0, 0), Point3(0, 0, 50), gravMult=1.0)
        flyDur = trajectory.calcTimeOfImpactOnPlane(0.0)
        endTile = [rng.randint(0, self.numSquaresX - 1), rng.randint(0, self.numSquaresY - 1)]
        endWorldCoords = (self.getX(render) + endTile[0] * self.spacingX, self.getY(render) + endTile[1] * self.spacingY)
        endPos = Point3(endWorldCoords[0], endWorldCoords[1], startPos[2])

        def flyFunc(t, trajectory, startPos = startPos, endPos = endPos, dur = flyDur, moveNode = parentNode, flyNode = toon):
            u = t / dur
            moveNode.setX(startPos[0] + u * (endPos[0] - startPos[0]))
            moveNode.setY(startPos[1] + u * (endPos[1] - startPos[1]))
            if flyNode and not flyNode.isEmpty():
                flyNode.setPos(trajectory.getPos(t))

        def safeSetHpr(node, hpr):
            if node and not node.isEmpty():
                node.setHpr(hpr)

        flyTrack = Sequence(LerpFunctionInterval(flyFunc, fromData=0.0, toData=flyDur, duration=flyDur, extraArgs=[trajectory]), name=toon.uniqueName('hitBySuit-fly'))
        if avId != localAvatar.doId:
            cameraTrack = Sequence()
        else:
            base.localAvatar.stopUpdateSmartCamera()
            self.camParentHold = camera.getParent()
            self.camParent = base.localAvatar.attachNewNode('iCamParent')
            self.camParent.setPos(self.camParentHold.getPos())
            self.camParent.setHpr(self.camParentHold.getHpr())
            camera.reparentTo(self.camParent)
            self.camParent.reparentTo(parentNode)
            startCamPos = camera.getPos()
            destCamPos = camera.getPos()
            zenith = trajectory.getPos(flyDur / 2.0)[2]
            destCamPos.setZ(zenith * 1.3)
            destCamPos.setY(destCamPos[1] * 0.3)

            def camTask(task, zenith = zenith, flyNode = toon, startCamPos = startCamPos, camOffset = destCamPos - startCamPos):
                u = flyNode.getZ() / zenith
                camera.lookAt(toon)
                return Task.cont

            camTaskName = 'mazeToonFlyCam-' + `avId`
            taskMgr.add(camTask, camTaskName, priority=20)

            def cleanupCamTask(self = self, toon = toon, camTaskName = camTaskName, startCamPos = startCamPos):
                taskMgr.remove(camTaskName)
                self.camParent.reparentTo(toon)
                camera.setPos(startCamPos)
                camera.lookAt(toon)
                camera.reparentTo(self.camParentHold)
                base.localAvatar.startUpdateSmartCamera()
                self.setUpCamera()

            cameraTrack = Sequence(Wait(flyDur), Func(cleanupCamTask), name='hitBySuit-cameraLerp')
        geomNode = toon.getGeomNode()
        startHpr = geomNode.getHpr()
        destHpr = Point3(startHpr)
        hRot = rng.randrange(1, 8)
        if rng.choice([0, 1]):
            hRot = -hRot
        destHpr.setX(destHpr[0] + hRot * 360)
        spinHTrack = Sequence(LerpHprInterval(geomNode, flyDur, destHpr, startHpr=startHpr), Func(safeSetHpr, geomNode, startHpr), name=toon.uniqueName('hitBySuit-spinH'))
        parent = geomNode.getParent()
        rotNode = parent.attachNewNode('rotNode')
        geomNode.reparentTo(rotNode)
        rotNode.setZ(toon.getHeight() / 2.0)
        oldGeomNodeZ = geomNode.getZ()
        geomNode.setZ(-toon.getHeight() / 2.0)
        startHpr = rotNode.getHpr()
        destHpr = Point3(startHpr)
        pRot = rng.randrange(1, 3)
        if rng.choice([0, 1]):
            pRot = -pRot
        destHpr.setY(destHpr[1] + pRot * 360)
        spinPTrack = Sequence(LerpHprInterval(rotNode, flyDur, destHpr, startHpr=startHpr), Func(safeSetHpr, rotNode, startHpr), name=toon.uniqueName('hitBySuit-spinP'))
        soundTrack = Sequence()

        def preFunc(self = self, avId = avId, toon = toon, dropShadow = dropShadow):
            forwardSpeed = toon.forwardSpeed
            rotateSpeed = toon.rotateSpeed
            if avId == localAvatar.doId:
                toon.stopSmooth()
                base.cr.playGame.getPlace().fsm.request('stopped')
            else:
                toon.stopSmooth()
            if forwardSpeed or rotateSpeed:
                toon.setSpeed(forwardSpeed, rotateSpeed)
            toon.dropShadow.hide()

        def postFunc(self = self, avId = avId, oldGeomNodeZ = oldGeomNodeZ, dropShadow = dropShadow, parentNode = parentNode):
            if avId == localAvatar.doId:
                base.localAvatar.setPos(endPos)
                if hasattr(self, 'orthoWalk'):
                    self.orthoWalk.start()
            dropShadow.removeNode()
            del dropShadow
            if toon and toon.dropShadow:
                toon.dropShadow.show()
            geomNode = toon.getGeomNode()
            rotNode = geomNode.getParent()
            baseNode = rotNode.getParent()
            geomNode.reparentTo(baseNode)
            rotNode.removeNode()
            del rotNode
            geomNode.setZ(oldGeomNodeZ)
            toon.reparentTo(render)
            toon.setPos(endPos)
            parentNode.removeNode()
            del parentNode
            if avId == localAvatar.doId:
                toon.startSmooth()
                place = base.cr.playGame.getPlace()
                if place and hasattr(place, 'fsm'):
                    place.fsm.request('walk')
            else:
                toon.startSmooth()

        preFunc()
        hitTrack = Sequence(Func(toon.setPos, Point3(0.0, 0.0, 0.0)), Wait(0.25), Parallel(flyTrack, cameraTrack, self.soundIUpDown, spinHTrack, spinPTrack, soundTrack), Func(postFunc), name=toon.uniqueName('hitBySuit'))
        self.toonHitTracks[avId] = hitTrack
        hitTrack.start()
        posM = moleHill.getPos(render)
        posN = Point3(posM[0], posM[1], posM[2] + 4.0)
        self.soundBomb.play()
        self.soundBomb2.play()
        return
コード例 #17
0
 def show(self):
     DirectFrame.show(self)
     self._spinIval.loop()
コード例 #18
0
ファイル: FinalScoreGUI.py プロジェクト: coginvasion/src
class FinalScoreGUI:
    notify = directNotify.newCategory('FinalScoreGUI')

    def __init__(self):
        self.finalScoreBg = None
        self.finalScoreTitle = None
        self.finalScoreNameLbl = None
        self.finalScorePointLbl = None
        self.finalScoreContainer = None
        self.finalScores = []
        return

    def load(self):
        font = CIGlobals.getToonFont()
        box = DGG.getDefaultDialogGeom()
        self.finalScoreContainer = DirectFrame()
        self.finalScoreBg = OnscreenImage(image=box, color=(1, 1, 0.75, 1), scale=(1.9, 1.4, 1.4), parent=self.finalScoreContainer)
        self.finalScoreTitle = OnscreenText(text='Waiting for final scores...', pos=(0, 0.5, 0), font=font, scale=0.12, parent=self.finalScoreContainer)
        self.finalScoreNameLbl = OnscreenText(text='', scale=0.095, pos=(-0.85, 0.3, 0), font=font, align=TextNode.ALeft, parent=self.finalScoreContainer)
        self.finalScorePointLbl = OnscreenText(text='', scale=0.095, pos=(0.85, 0.3, 0), font=font, align=TextNode.ARight, parent=self.finalScoreContainer)
        self.finalScoreContainer.hide()
        self.finalScoreContainer.setBin('gui-popup', 60)
        del font
        del box

    def unload(self):
        if self.finalScoreContainer:
            self.finalScoreContainer.destroy()
            self.finalScoreContainer = None
        if self.finalScoreBg:
            self.finalScoreBg.destroy()
            self.finalScoreBg = None
        if self.finalScoreTitle:
            self.finalScoreTitle.destroy()
            self.finalScoreTitle = None
        if self.finalScoreNameLbl:
            self.finalScoreNameLbl.destroy()
            self.finalScoreNameLbl = None
        if self.finalScorePointLbl:
            self.finalScorePointLbl.destroy()
            self.finalScorePointLbl = None
        return

    def showFinalScores(self):
        self.finalScoreContainer.show()
        base.transitions.fadeScreen(0.5)

    def hideFinalScores(self):
        base.transitions.noTransitions()
        self.finalScoreContainer.hide()

    def handleFinalScores(self, avIdList, scoreList):
        for avId in avIdList:
            score = scoreList[avIdList.index(avId)]
            scoreObj = FinalScore(avId, score)
            self.finalScores.append(scoreObj)

        self.finalScores.sort(key=lambda x: x.score, reverse=True)
        for scoreObj in self.finalScores:
            name = base.cr.doId2do.get(scoreObj.avId).getName()
            self.finalScoreNameLbl['text'] += name + '\n'
            self.finalScorePointLbl['text'] += str(scoreObj.score) + ' Points\n'

        self.finalScoreTitle['text'] = 'Final Scores'
コード例 #19
0
ファイル: gameOverScreen.py プロジェクト: grimfang/owp_ajaw
class GameOverScreen():
    def __init__(self):
        # a fill panel so the player doesn't see how everything
        # gets loaded in the background
        self.frameMain = DirectFrame(
            # size of the frame
            frameSize = (base.a2dLeft, base.a2dRight,
                         base.a2dTop, base.a2dBottom),
            image = "Logo.png",
            image_scale = (0.612/2.0, 1, 0.495/2.0),
            image_pos = (0, 0, 0.7),
            # tramsparent bg color
            frameColor = (0, 0, 0, 1))
        self.frameMain.setTransparency(1)

        self.lblWin = DirectLabel(
            scale = 0.25,
            pos = (0, 0, 0.25),
            frameColor = (0, 0, 0, 0),
            text = _("You Succeeded"),
            text_align = TextNode.ACenter,
            text_fg = (1,1,1,1))
        self.lblWin.reparentTo(self.frameMain)

        self.lblTime = DirectLabel(
            scale = 0.07,
            pos = (0, 0, 0.00),
            frameColor = (0, 0, 0, 0),
            text = "your time",
            text_align = TextNode.ACenter,
            text_fg = (1,1,1,1))
        self.lblTime.reparentTo(self.frameMain)

        self.lblResult = DirectLabel(
            scale = 0.40,
            pos = (0, 0, -0.25),
            frameColor = (0, 0, 0, 0),
            text = "00:00",
            text_align = TextNode.ACenter,
            text_fg = (1,1,1,1))
        self.lblResult.reparentTo(self.frameMain)

        self.btnContinue = DirectButton(
            scale = (0.25, 0.25, 0.25),
            # some temp text
            text = _("Continue..."),
            text_scale = (0.5, 0.5, 0.5),
            # set the alignment to right
            text_align = TextNode.ACenter,
            # put the text on the right side of the button
            text_pos = (0, 0),
            # set the text color to black
            text_fg = (1,1,1,1),
            text_shadow = (0.3, 0.3, 0.1, 1),
            text_shadowOffset = (0.05, 0.05),
            relief = 1,
            frameColor = (0,0,0,0),
            pressEffect = False,
            pos = (0, 0, -0.65),
            command = lambda: base.messenger.send("Exit"),
            rolloverSound = None,
            clickSound = None)
        self.btnContinue.setTransparency(1)
        self.btnContinue.reparentTo(self.frameMain)
        self.hide()

    def show(self, winLoose, resulttime):
        if winLoose == "win":
            timestring = "%d:%02d" % (resulttime/60, resulttime%60)
            self.lblResult["text"] = timestring
            self.lblTime.show()
            self.lblResult.show()
        else:
            self.lblWin["text"] = _("You Loose")
            self.lblTime.hide()
            self.lblResult.hide()
        self.frameMain.show()

    def hide(self):
        self.frameMain.hide()
コード例 #20
0
ファイル: menu.py プロジェクト: grimfang/Paintball
class Menu(DirectObject):
    def __init__(self):
        #self.accept("RatioChanged", self.recalcAspectRatio)
        self.accept("window-event", self.recalcAspectRatio)

        self.frameMain = DirectFrame(
            # size of the frame
            frameSize = (base.a2dLeft, base.a2dRight,
                         base.a2dTop, base.a2dBottom),
            # position of the frame
            pos = (0, 0, 0),
            # tramsparent bg color
            frameColor = (0, 0, 0, 0),
            sortOrder = 0)

        self.background = OnscreenImage("MenuBGLogo.png")
        self.background.reparentTo(self.frameMain)

        self.nowPlaying = DirectLabel(
            scale = 0.05,
            text = "Now Playing: Eraplee Noisewall Orchestra - Bermuda Fire",
            pos = (base.a2dLeft + 0.025, 0.0, base.a2dBottom + 0.05),
            text_align = TextNode.ALeft,
            frameColor = (0, 0, 0, 0),
            text_fg = (1,1,1,1)
            )
        self.nowPlaying.setTransparency(1)
        self.nowPlaying.reparentTo(self.frameMain)

        maps = loader.loadModel('button_maps.egg')
        btnGeom = (maps.find('**/ButtonReady'),
                    maps.find('**/ButtonClick'),
                    maps.find('**/ButtonRollover'),
                    maps.find('**/ButtonDisabled'))

        self.btnStart = self.createButton("Start", btnGeom, 0.25, self.btnStart_Click)
        self.btnStart.reparentTo(self.frameMain)

        self.btnQuit = self.createButton("Quit", btnGeom, -0.25, self.btnQuit_Click)
        self.btnQuit.reparentTo(self.frameMain)

        self.recalcAspectRatio(base.win)

        # hide all buttons at startup
        self.hide()

    def show(self):
        self.frameMain.show()
        self.recalcAspectRatio(base.win)

    def hide(self):
        self.frameMain.hide()

    def recalcAspectRatio(self, window):
        """get the new aspect ratio to resize the mainframe"""
        screenResMultiplier = window.getXSize() / window.getYSize()
        self.frameMain["frameSize"] = (
            base.a2dLeft, base.a2dRight,
            base.a2dTop, base.a2dBottom)
        self.btnQuit["text_scale"] = (0.5*screenResMultiplier, 0.5, 0.5)
        self.btnStart["text_scale"] = (0.5*screenResMultiplier, 0.5, 0.5)


    def createButton(self, text, btnGeom, yPos, command):
        btn = DirectButton(
            scale = (0.25, 0.25, 0.25),
            # some temp text
            text = text,
            text_scale = (0.5, 0.5, 0.5),
            # set the alignment to right
            text_align = TextNode.ACenter,
            # put the text on the right side of the button
            text_pos = (0, -0.15),
            # set the text color to black
            text_fg = (1,1,0,1),
            text_shadow = (0.3, 0.3, 0.1, 1),
            text_shadowOffset = (0.05, 0.05),
            # set the buttons images
            geom = btnGeom,
            relief = 1,
            frameColor = (0,0,0,0),
            pressEffect = False,
            pos = (0, 0, yPos),
            command = command,
            rolloverSound = None,
            clickSound = None)
        btn.setTransparency(1)
        return btn

    def btnStart_Click(self):
        base.messenger.send("start")

    def btnQuit_Click(self):
        base.messenger.send("quit")
コード例 #21
0
class CharacterSelection:
    def __init__(self):

        self.frameMain = DirectFrame(frameSize=(base.a2dLeft, base.a2dRight,
                                                base.a2dBottom, base.a2dTop),
                                     frameColor=(0.05, 0.05, 0.05, 1))
        self.frameMain.setTransparency(1)

        width = abs(base.a2dLeft) + base.a2dRight

        red = loader.loadTexture("assets/gui/CharRedBG.png")
        red.setWrapU(Texture.WM_repeat)
        red.setWrapV(Texture.WM_repeat)
        self.char1Frame = DirectFrame(text="Player 1",
                                      text_fg=(1, 1, 1, 1),
                                      text_scale=0.1,
                                      text_pos=(0, base.a2dTop - 0.2),
                                      frameSize=(-width / 6.0, width / 6.0,
                                                 base.a2dBottom, base.a2dTop),
                                      frameTexture=red,
                                      pos=(base.a2dLeft + width / 6.0, 0, 0))
        self.char1Frame.updateFrameStyle()
        self.char1Frame.setTransparency(1)
        self.char1Frame.reparentTo(self.frameMain)

        blue = loader.loadTexture("assets/gui/CharBlueBG.png")
        blue.setWrapU(Texture.WM_repeat)
        blue.setWrapV(Texture.WM_repeat)
        self.char2Frame = DirectFrame(text="Player 2",
                                      text_fg=(1, 1, 1, 1),
                                      text_scale=0.1,
                                      text_pos=(0, base.a2dTop - 0.2),
                                      frameSize=(-width / 6.0, width / 6.0,
                                                 base.a2dBottom, base.a2dTop),
                                      frameTexture=blue,
                                      pos=(base.a2dRight - width / 6.0, 0, 0))
        self.char2Frame.setTransparency(1)
        self.char2Frame.reparentTo(self.frameMain)

        self.footerFrame = DirectFrame(text="PLAYER 1 - CHOOSE YOUR CHARACTER",
                                       text_fg=(1, 1, 1, 1),
                                       text_scale=0.08,
                                       text_pos=(0, -0.03),
                                       frameSize=(base.a2dLeft, base.a2dRight,
                                                  0.1, -0.1),
                                       pos=(0, 0, base.a2dBottom + 0.2),
                                       frameColor=(0, 0, 0, 0.5))
        self.footerFrame.setTransparency(1)
        self.footerFrame.reparentTo(self.frameMain)

        self.charSelectFrame = DirectFrame(
            text="VS",
            text_fg=(1, 1, 1, 1),
            text_scale=0.1,
            text_pos=(0, base.a2dTop - 0.2),
            frameSize=(-width / 6.0, width / 6.0, base.a2dBottom, base.a2dTop),
            frameColor=(0, 0, 0, 0))
        self.charSelectFrame.reparentTo(self.frameMain)

        self.btnChar1 = self.createCharacterButton(
            (-0.2, 0, 0), "assets/gui/Char1Button.png", 1)
        self.btnChar1.reparentTo(self.charSelectFrame)

        self.btnChar2 = self.createCharacterButton(
            (0.2, 0, 0), "assets/gui/Char2Button.png", 2)
        self.btnChar2.reparentTo(self.charSelectFrame)

        self.btnBack = DirectButton(text="BACK",
                                    text_fg=(1, 1, 1, 1),
                                    text_align=TextNode.ALeft,
                                    scale=0.1,
                                    pad=(0.15, 0.15),
                                    pos=(base.a2dLeft + 0.08, 0, -0.03),
                                    frameColor=((0.2, 0.2, 0.2,
                                                 0.8), (0.4, 0.4, 0.4, 0.8),
                                                (0.4, 0.4, 0.4,
                                                 0.8), (0.1, 0.1, 0.1, 0.8)),
                                    relief=1,
                                    command=base.messenger.send,
                                    extraArgs=["CharSelection-Back"],
                                    pressEffect=False,
                                    rolloverSound=None,
                                    clickSound=None)
        self.btnBack.setTransparency(1)
        self.btnBack.reparentTo(self.footerFrame)

        self.btnStart = DirectButton(text="START",
                                     text_fg=(1, 1, 1, 1),
                                     text_align=TextNode.ARight,
                                     scale=0.1,
                                     pad=(0.15, 0.15),
                                     pos=(base.a2dRight - 0.08, 0, -0.03),
                                     relief=1,
                                     frameColor=((0.2, 0.2, 0.2,
                                                  0.8), (0.4, 0.4, 0.4, 0.8),
                                                 (0.4, 0.4, 0.4,
                                                  0.8), (0.1, 0.1, 0.1, 0.8)),
                                     command=base.messenger.send,
                                     extraArgs=["CharSelection-Start"],
                                     pressEffect=False,
                                     rolloverSound=None,
                                     clickSound=None)
        self.btnStart.setTransparency(1)
        self.btnStart.reparentTo(self.footerFrame)
        self.btnStart["state"] = DGG.DISABLED

        self.hide()

    def createCharacterButton(self, pos, image, charNr):
        btn = DirectButton(scale=0.1,
                           relief=0,
                           frameColor=(0, 0, 0, 0),
                           pos=pos,
                           image=image,
                           command=self.selectCharacter,
                           extraArgs=[charNr],
                           rolloverSound=None,
                           clickSound=None)
        btn.setTransparency(1)
        return btn

    def selectCharacter(self, charNr):
        if self.char1Frame["image"] == None:
            self.char1Frame["image"] = "assets/gui/Char{}_L.png".format(charNr)
            self.char1Frame["image_scale"] = (0.5, 1, 1)
            self.selectedCharacter1 = charNr
            self.footerFrame["text"] = "PLAYER 2 - CHOOSE YOUR CHARACTER"
        elif self.char2Frame["image"] == None:
            self.char2Frame["image"] = "assets/gui/Char{}_R.png".format(charNr)
            self.char2Frame["image_scale"] = (0.5, 1, 1)
            self.selectedCharacter2 = charNr
            self.btnStart["state"] = DGG.NORMAL
            self.footerFrame["text"] = "START THE FIGHT >"

    def show(self):
        self.selectedCharacter1 = None
        self.selectedCharacter2 = None
        self.char1Frame["image"] = None
        self.char2Frame["image"] = None
        self.footerFrame["text"] = "PLAYER 1 - CHOOSE YOUR CHARACTER"
        self.btnStart["state"] = DGG.DISABLED
        self.frameMain.show()

    def hide(self):
        self.frameMain.hide()
コード例 #22
0
ファイル: mainmenu.py プロジェクト: grimfang/owp_ajaw
class Menu(DirectObject):
    def __init__(self):
        self.accept("window-event", self.recalcAspectRatio)

        self.frameMain = DirectFrame(
            # size of the frame
            frameSize=(base.a2dLeft, base.a2dRight, base.a2dTop, base.a2dBottom),
            # position of the frame
            image="LogoTextGlow.png",
            image_scale=(1.06, 1, 0.7),
            image_pos=(0, 0, 0.25),
            pos=(0, 0, 0),
            # tramsparent bg color
            frameColor=(0, 0, 0, 0),
            sortOrder=0,
        )
        self.frameMain.setTransparency(1)
        self.frameMain.setBin("fixed", 100)

        btnGeom = None

        self.btnStart = self.createButton(_("Start"), btnGeom, -0.6, self.btnStart_Click)
        self.btnStart.reparentTo(self.frameMain)

        self.btnOptions = self.createButton(_("Options"), btnGeom, 0, self.btnOptions_Click)
        self.btnOptions.reparentTo(self.frameMain)

        self.btnQuit = self.createButton(_("Quit"), btnGeom, 0.6, self.btnQuit_Click)
        self.btnQuit.reparentTo(self.frameMain)

        self.recalcAspectRatio(base.win)

        # hide all buttons at startup
        self.hide()

    def show(self):
        self.frameMain.show()
        self.recalcAspectRatio(base.win)

    def hide(self):
        self.frameMain.hide()

    def recalcAspectRatio(self, window):
        """get the new aspect ratio to resize the mainframe"""
        screenResMultiplier = window.getXSize() / window.getYSize()
        self.frameMain["frameSize"] = (base.a2dLeft, base.a2dRight, base.a2dTop, base.a2dBottom)
        self.btnQuit["text_scale"] = (0.5 * screenResMultiplier, 0.5, 0.5)
        self.btnStart["text_scale"] = (0.5 * screenResMultiplier, 0.5, 0.5)

    def createButton(self, text, btnGeom, xPos, command):
        btn = DirectButton(
            scale=(0.25, 0.25, 0.25),
            # some temp text
            text=text,
            text_scale=(0.5, 0.5, 0.5),
            # set the alignment to right
            text_align=TextNode.ACenter,
            # put the text on the right side of the button
            text_pos=(0, -0.15),
            # set the text color to black
            text_fg=(1, 1, 1, 1),
            text_shadow=(0.3, 0.3, 0.1, 1),
            text_shadowOffset=(0.05, 0.05),
            # set the buttons images
            # geom = btnGeom,
            relief=1,
            frameColor=(0, 0, 0, 0),
            pressEffect=False,
            pos=(xPos, 0, -0.65),
            command=command,
            rolloverSound=None,
            clickSound=None,
        )
        btn.setTransparency(1)
        return btn

    def btnStart_Click(self):
        base.messenger.send("menu_start")

    def btnOptions_Click(self):
        base.messenger.send("menu_options")

    def btnQuit_Click(self):
        base.messenger.send("menu_quit")
コード例 #23
0
ファイル: pregame.py プロジェクト: H3LLB0Y/Centipede
class Pregame():
	def __init__(self, showbase):
		self.showbase = showbase
		
		self.ready = False

		self.background = DirectFrame(
			frameSize = (-1, 1, -1, 1),
			frameTexture  = 'media/gui/mainmenu/menu.png',
			parent = self.showbase.render2d,
		)

		self.title = OnscreenText(
			text   = 'Lobby!',
			fg     = (1, 1, 1, 1),
			parent = self.background,
			pos    = (-0.6, 0.1),
			scale  = 0.06
		)

		self.buttons = []
		controlButtons = Vec3(-0.60, 0, -0.79)
		# Toggle ready
		p = controlButtons + Vec3(-0.25, 0, 0)
		self.toggleReadyButton = DirectButton(
			text = 'Ready/Unready',
			pos = p,
			scale = 0.048,
			relief = DGG.GROOVE,
			command = self.toggleReady,
		)
		self.buttons.append(self.toggleReadyButton)
		# Disconnect
		p = controlButtons + Vec3(0.0, 0.0, 0.0)
		self.disconnectButton = DirectButton(
			text = 'Disconnect',
			pos = p,
			scale = 0.048,
			relief = DGG.GROOVE,
			command = self.disconnect,
		)
		self.buttons.append(self.disconnectButton)

		# Send message
		p = controlButtons + Vec3(0.25, 0.0, 0.0)
		self.sendMessageButton = DirectButton(
			text = 'Send Message',
			pos = p,
			scale = 0.048,
			relief = DGG.GROOVE,
			command = self.sendMessage,
			extraArgs = [''],
		)
		self.buttons.append(self.sendMessageButton)
		# Message input
		self.message = DirectEntry(
			command = self.sendMessage,
			focusInCommand = self.clearText,
			frameSize   = (-3, 3, -.5, 1),
			initialText = '',
			parent      = self.buttons[2],
			pos         = (0, -0.6, -1.5),
			text_align  = TextNode.ACenter,
		)

		self.showbase.gameData = GameData()

		self.showbase.users = []

		self.hide()

	def clearText(self):
		self.message.set('')

	def reset(self):
		self.messages = []
		self.showbase.users = []

	def updateLobby(self, task):
		temp = self.showbase.client.getData()
		for package in temp:
			if len(package) == 2:
				print 'Received: ', str(package)
				if package[0] == 'chat':
					if len(package[1]) == 2:
						self.messages.append(package[1])
						print self.messages
				elif package[0] == 'client':
					self.showbase.users.append(User(package[1]))
					for user in self.showbase.users:
						print user.name, user.ready
					print 'all users'
				elif package[0] == 'ready':
					for user in self.showbase.users:
						if user.name == package[1][0]:
							user.ready = package[1][1]
					for user in self.showbase.users:
						print user.name, user.ready
					print 'all users'
				elif package[0] == 'disconnect':
					for user in self.showbase.users:
						if user.name == package[1]:
							self.showbase.users.remove(user)
					for user in self.showbase.users:
						print user.name, user.ready
					print 'all users'
				elif package[0] == 'gamedata':
					self.showbase.gameData.unpackageData(package[1])
				elif package[0] == 'state':
					print 'state: ', package[1]
					if package[1] == 'preround':
						self.showbase.startRound()
						return task.done
		return task.again
	
	def toggleReady(self):
		self.ready = not self.ready
		self.showbase.client.sendData(('ready', self.ready))
		
	def disconnect(self):
		self.showbase.client.sendData(('disconnect', 'disconnect'))
		self.showbase.authCon = self.showbase.client
		self.showbase.returnToMenu()
	
	def sendMessage(self, message):
		if message == '':
			message = self.message.get()
		if message != '':
			self.showbase.client.sendData(('chat', message))
			self.message.set('')

	def hide(self):
		self.background.hide()
		self.message.hide()
		for b in self.buttons:
			b.hide()

		self.showbase.taskMgr.remove('Update Lobby')
	
	def show(self):
		self.background.show()
		self.message.show()
		for b in self.buttons:
			b.show()

		# Add the game loop procedure to the task manager.
		self.showbase.taskMgr.add(self.updateLobby, 'Update Lobby')
コード例 #24
0
ファイル: optionsmenu.py プロジェクト: grimfang/owp_ajaw
class OptionsMenu(DirectObject):
    def __init__(self):
        """Default constructor"""
        # create a main frame as big as the window
        self.frameMain = DirectFrame(
            # set framesize the same size as the window
            frameSize = (base.a2dLeft, base.a2dRight,
                         base.a2dTop, base.a2dBottom),
            image = "LogoTextGlow.png",
            image_scale = (1.06/2.0, 1, 0.7/2.0),
            image_pos = (0, 0, 0.7),
            # position center
            pos = (0, 0, 0),
            # set tramsparent background color
            frameColor = (0, 0, 0, 0))
        self.frameMain.setTransparency(1)
        self.frameMain.setBin("fixed", 100)

        sliderscale = 0.5
        buttonScale = 0.25
        textscale = 0.1
        checkboxscale = 0.05
        left = -0.5
        right = 0.5

        self.sliderTextspeed = DirectSlider(
            scale = sliderscale,
            pos = (left, 0, 0.2),
            range = (0.2,0.01),
            scrollSize = 0.01,
            text = _("Textspeed %0.1f%%")%(base.textWriteSpeed * 10),
            text_scale = textscale,
            text_align = TextNode.ACenter,
            text_pos = (0.0, 0.15),
            text_fg = (1,1,1,1),
            thumb_frameColor = (0.65, 0.65, 0.0, 1),
            thumb_relief = DGG.FLAT,
            frameColor = (0.15, 0.15, 0.15, 1),
            value = base.textWriteSpeed,
            command = self.sliderTextspeed_ValueChanged)
        self.sliderTextspeed.reparentTo(self.frameMain)

        self.cbParticles = DirectCheckButton(
            text = _(" Enable Particles"),
            text_fg = (1, 1, 1, 1),
            text_shadow = (0, 0, 0, 0.35),
            pos = (left, 0, -0.0),
            scale = checkboxscale,
            frameColor = (0,0,0,0),
            command = self.cbParticles_CheckedChanged,
            rolloverSound = None,
            clickSound = None,
            pressEffect = False,
            boxPlacement = "below",
            boxBorder = 0.8,
            boxRelief = DGG.FLAT,
            indicator_scale = 1.5,
            indicator_text_fg = (0.65, 0.65, 0.0, 1),
            indicator_text_shadow = (0, 0, 0, 0.35),
            indicator_frameColor = (0.15, 0.15, 0.15, 1),
            indicatorValue = base.particleMgrEnabled
            )
        self.cbParticles.indicator['text'] = (' ', 'x')
        self.cbParticles.indicator['text_pos'] = (0, 0.1)
        #self.cbParticles.indicator.setX(self.cbParticles.indicator, -0.5)
        #self.cbParticles.indicator.setZ(self.cbParticles.indicator, -0.1)
        #self.cbParticles.setFrameSize()
        self.cbParticles.setTransparency(1)
        self.cbParticles.reparentTo(self.frameMain)

        volume = base.musicManager.getVolume()
        self.sliderVolume = DirectSlider(
            scale = sliderscale,
            pos = (left, 0, -0.35),
            range = (0,1),
            scrollSize = 0.01,
            text = _("Volume %d%%")%volume*100,
            text_scale = textscale,
            text_align = TextNode.ACenter,
            text_pos = (.0, 0.15),
            text_fg = (1,1,1,1),
            thumb_frameColor = (0.65, 0.65, 0.0, 1),
            thumb_relief = DGG.FLAT,
            frameColor = (0.15, 0.15, 0.15, 1),
            value = volume,
            command = self.sliderVolume_ValueChanged)
        self.sliderVolume.reparentTo(self.frameMain)

        self.lblControltype = DirectLabel(
            text = _("Control type"),
            text_fg = (1, 1, 1, 1),
            text_shadow = (0, 0, 0, 0.35),
            frameColor = (0, 0, 0, 0),
            scale = textscale/2,
            pos = (right, 0, 0.27))
        self.lblControltype.setTransparency(1)
        self.lblControltype.reparentTo(self.frameMain)
        selectedControlType = 0
        if base.controlType == "MouseAndKeyboard":
            selectedControlType = 1
        self.controltype = DirectOptionMenu(
            pos = (right, 0, 0.18),
            text_fg = (1, 1, 1, 1),
            scale = 0.1,
            items = [_("Keyboard"),_("Keyboard + Mouse")],
            initialitem = selectedControlType,
            frameColor = (0.15, 0.15, 0.15, 1),
            popupMarker_frameColor = (0.65, 0.65, 0.0, 1),
            popupMarker_relief = DGG.FLAT,
            highlightColor = (0.65, 0.65, 0.0, 1),
            relief = DGG.FLAT,
            command=self.controlType_Changed)
        self.controltype.reparentTo(self.frameMain)
        b = self.controltype.getBounds()
        xPos = right - ((b[1] - b[0]) / 2.0 * 0.1)
        self.controltype.setX(xPos)
        setItems(self.controltype)
        self.controltype.setItems = setItems
        self.controltype.showPopupMenu = showPopupMenu
        self.controltype.popupMarker.unbind(DGG.B1PRESS)
        self.controltype.popupMarker.bind(DGG.B1PRESS, showPopupMenu)
        self.controltype.unbind(DGG.B1PRESS)
        self.controltype.bind(DGG.B1PRESS, showPopupMenuExtra, [self.controltype])

        isChecked = not base.AppHasAudioFocus
        img = None
        if base.AppHasAudioFocus:
            img = "AudioSwitch_on.png"
        else:
            img = "AudioSwitch_off.png"
        self.cbVolumeMute = DirectCheckBox(
            text = _("Mute Audio"),
            text_scale = 0.5,
            text_align = TextNode.ACenter,
            text_pos = (0.0, 0.65),
            text_fg = (1,1,1,1),
            pos = (right, 0, -0.35),
            scale = 0.21/2.0,
            command = self.cbVolumeMute_CheckedChanged,
            rolloverSound = None,
            clickSound = None,
            relief = None,
            pressEffect = False,
            isChecked = isChecked,
            image = img,
            image_scale = 0.5,
            checkedImage = "AudioSwitch_off.png",
            uncheckedImage = "AudioSwitch_on.png")
        self.cbVolumeMute.setTransparency(1)
        self.cbVolumeMute.setImage()
        self.cbVolumeMute.reparentTo(self.frameMain)

        sensitivity = base.mouseSensitivity
        self.sliderSensitivity = DirectSlider(
            scale = sliderscale,
            pos = (right, 0, -0.075),
            range = (0.5,2),
            scrollSize = 0.01,
            text = _("Mouse Sensitivity %0.1fx")%sensitivity,
            text_scale = textscale,
            text_align = TextNode.ACenter,
            text_pos = (.0, 0.15),
            text_fg = (1,1,1,1),
            thumb_frameColor = (0.65, 0.65, 0.0, 1),
            thumb_relief = DGG.FLAT,
            frameColor = (0.15, 0.15, 0.15, 1),
            value = sensitivity,
            command = self.sliderSensitivity_ValueChanged)
        self.sliderSensitivity.reparentTo(self.frameMain)
        if base.controlType == "Gamepad":
            self.sliderSensitivity.hide()

        # create the back button
        self.btnBack = DirectButton(
            scale = buttonScale,
            # position on the window
            pos = (0, 0, base.a2dBottom + 0.15),
            frameColor = (0,0,0,0),
            # text properties
            text = _("Back"),
            text_scale = 0.5,
            text_fg = (1,1,1,1),
            text_pos = (0.0, -0.15),
            text_shadow = (0, 0, 0, 0.35),
            text_shadowOffset = (-0.05, -0.05),
            # sounds that should be played
            rolloverSound = None,
            clickSound = None,
            pressEffect = False,
            relief = None,
            # the event which is thrown on clickSound
            command = lambda: base.messenger.send("options_back"))
        self.btnBack.setTransparency(1)
        self.btnBack.reparentTo(self.frameMain)

        self.hide()


    def show(self, enableResume=False):
        self.frameMain.show()

    def hide(self):
        self.frameMain.hide()

    def cbVolumeMute_CheckedChanged(self, checked):
        if checked:
            base.disableAllAudio()
        else:
            base.enableAllAudio()

    def sliderVolume_ValueChanged(self):
        volume = round(self.sliderVolume["value"], 2)
        self.sliderVolume["text"] = _("Volume %d%%") % int(volume * 100)
        base.sfxManagerList[0].setVolume(volume)
        base.musicManager.setVolume(volume)

    def sliderSensitivity_ValueChanged(self):
        sensitivity = round(self.sliderSensitivity["value"], 2)
        self.sliderSensitivity["text"] = _("Mouse Sensitivity %0.1fx") % sensitivity
        base.mouseSensitivity = sensitivity

    def sliderTextspeed_ValueChanged(self):
        newSpeed = round(self.sliderTextspeed["value"], 2)
        displaySpeed = 1.0 / newSpeed
        self.sliderTextspeed["text"] = _("Textspeed %0.1f%%")%displaySpeed
        base.textWriteSpeed = newSpeed

    def cbParticles_CheckedChanged(self, unchecked):
        if unchecked:
            base.enableParticles()
        else:
            base.disableParticles()

    def controlType_Changed(self, arg):
        if arg == _("Keyboard"):
            self.sliderSensitivity.hide()
            base.controlType = "Gamepad"
        elif arg == _("Keyboard + Mouse"):
            self.sliderSensitivity.show()
            base.controlType = "MouseAndKeyboard"
コード例 #25
0
ファイル: ui.py プロジェクト: tgbugs/desc
class GuiFrame(DirectObject, HasKeybinds):
    #should be able to show/hide, do conditional show hide
    #position where you want
    #parent to other frames
    TEXT_MAGIC_NUMBER = .833333333334  #5/6 ?!?
    DRAW_ORDER={
        'frame':('unsorted',0),
        'frame_bg':('unsorted', 0),
        'items':('unsorted', 0),
        'title':('unsorted', 0),
        'border':('unsorted', 0),
    }

    def __init__(self, title,
                 shortcut = None,  # XXX obsolete, but needs a non deco replacement
                 x = 0,
                 y = .1,
                 width = .2,
                 height = .8,
                 #scale = .05,  # there is some black magic here :/
                 bdr_thickness = 2,
                 bdr_color = (.1, .1, .1, 1),
                 bg_color = (.7, .7, .7, .5),
                 text_color = (0, 0, 0, 1),
                 text_font = TextNode.getDefaultFont(),
                 #text_h = .05,  # do not use directly
                 text_height_mm = 4,
                 items = tuple(),
                ):
        #item_w_pad = 1
        #item_h_pad = 1

        self.title = title
        self.do_xywh(x, y, width, height)
        self.bdr_thickness = bdr_thickness  # FIXME ??
        self.bdr_color = bdr_color
        self.bg_color = bg_color
        self.text_color = text_color
        self.text_font = text_font
        self.text_height_mm = text_height_mm

        #set up variables
        self.__winx__ = base.win.getXSize() 
        self.__winy__ = base.win.getYSize()
        self.__ar__ = base.camLens.getAspectRatio()
        self.__was_dragging__ = False
        self.__first_item__ = None
        self.__add_head__ = None
        self.items = OrderedDict()  # ordered dict to allow sequential addition

        #self.BT = buttonThrower if buttonThrower else base.buttonThrowers[0].node()
        self.BT = base.buttonThrowers[0].node()

        # get our aspect ratio, and pixels per mm
        self.pixels_per_mm = render.getPythonTag('system_data')['max_ppmm']
        self.getWindowData()
        self.accept('window-event', self.getWindowData)

        #set the text height using the above data
        self.setTextHeight()

        # get the root for all frames in the scene
        self.frameRoot = aspect2d.find('frameRoot')
        if not self.frameRoot:
            self.frameRoot = aspect2d.attachNewNode('frameRoot')

        # create the parent node for this frame
        #parent = self.frameRoot.find('frame-*')
        #if not parent:
            #parent = self.frameRoot
        self.frame = self.frameRoot.attachNewNode('frame-%s-%s'%(title, id(self)))
        self.frame.setBin(*self.DRAW_ORDER['frame'])

        # background
        l,r,b,t = 0, self.width, 0, self.height
        self.frame_bg = DirectFrame(parent=self.frame,
                                    frameColor=self.bg_color,
                                    pos=LVecBase3f(self.x, 0, self.y),
                                    frameSize=(l,r,b,t),
                                    state=DGG.NORMAL,  # FIXME framesize is >_<
                                    suppressMouse=1)
        self.frame_bg.setBin(*self.DRAW_ORDER['frame_bg'])

        # border
        self.__make_border__(self.frame_bg, self.bdr_thickness, self.bdr_color, l, r, b, t)

        # setup for items
        self.itemsParent = self.frame_bg.attachNewNode('items parent')

        # title
        self.title_button = self.__create_item__(title, self.title_toggle_vis)
        
        # add any items that we got
        for item in items:
            self.__create_item__(*item)  # FIXME when we call frame adjust we will loose the record of any data items

        # dragging
        self.title_button.bind(DGG.B1PRESS, self.__startDrag)
        self.title_button.bind(DGG.B1RELEASE, self.__stopDrag)

        # raise if we click the frame background
        self.frame_bg.bind(DGG.B1PRESS, self.raise_)
        #self.frame_bg.bind(DGG.B1RELEASE, self.__stopDrag)  # this can cause problems w/ was dragging


        # toggle vis
        if shortcut:
            self.accept(shortcut, self.toggle_vis)

        # adjust the frame
        self.frame_adjust()

    @property
    def text_s(self):
        return self.text_h * self.TEXT_MAGIC_NUMBER

    def setTextHeight(self):
        h_units = 2 * base.a2dTop
        units_per_pixel = h_units / self.__winy__
        text_h = self.text_height_mm * self.pixels_per_mm * units_per_pixel
        self.text_h = text_h

    def do_xywh(self, x, y, w, h):
        """ makes negative wneg xidths and heights work
            as well as negative x and y (bottom right is 0)
        """
        if x < 0:
            x = 1 + x
        if y < 0:
            y = 1 + y
        if w < 0:
            x, w = x + w, -w
        if h < 0:
            y, h = y + h, -h

        self.x = self.fix_x(x)  # for top left
        self.y = self.fix_y(y)  # for top left
        self.width = self.fix_w(w)
        self.height = self.fix_h(h)

    def getWindowData(self, window=None):
        x = base.win.getXSize() 
        y = base.win.getYSize()
        if x != self.__winx__ or y != self.__winy__:
            self.__ar__ = base.camLens.getAspectRatio()  # w/h
            self.__winx__ = x
            self.__winy__ = y
            self.frame_adjust()

    def raise_(self, *args):
        """ function that raises windows
            call FIRST inside any function that should raise
        """
        self.frame.reparentTo(self.frameRoot)  # self.frame doesn't move so no wrt

    def frame_adjust(self):  # FIXME sometimes this fails to call, also calls too often at startup
        self.setTextHeight()
        MI = self.getMaxItems()  # does not count title >_<
        LI = len(self.items)
        DI = MI - LI
        if DI >= 0:
            for i in range(DI+1):
                self.__create_item__(' blank')
        else:
            for i in range(-(DI+1)):
                k,v = self.items.popitem()  # remove the last nodes in order
                v.removeNode()  # FIXME consider keeping these around?

        for k,b in self.items.items():
            if k == 'title':
                if self.frame_bg.isHidden():
                    x, y, z = self.frame_bg.getPos()
                    self.title_button.setPos(LVecBase3f(x, y , z-self.text_h))
                else:
                    self.title_button.setPos(LVecBase3f(0, 0, -self.text_h))
            elif k == self.__first_item__:
                b.setPos(LVecBase3f(0, 0, -(self.text_h * 2)))
            else:
                b.setPos(LVecBase3f(0, 0, -self.text_h))
            b['frameSize'] = 0, self.width, 0, self.text_h
            b['text_scale'] = self.text_s, self.text_s
            b['text_pos'] = 0, self.text_h - self.TEXT_MAGIC_NUMBER * self.text_s
        
    def getWindowSize(self, event=None):  # TODO see if we really need this
        self.__winx__ = base.win.getXSize()
        self.__winy__ = base.win.getYSize()
        m = max(self.__winx__, self.__winy__)
        self.__xscale__ = self.__winx__ / m
        self.__yscale__ = self.__winy__ / m

    # put origin in top left and positive down and right
    @staticmethod
    def fix_x(x): return (x - .5) *  2  # TODO * base.a2dLeft?
    @staticmethod
    def fix_y(y): return (y - .5) * -2  # TODO * base.a2dTop?
    @staticmethod
    def fix_w(n): return  n * 2
    @staticmethod
    def fix_h(n): return -n * 2

    def add_item(self, text, command = None, args = tuple()): 
        args = list(args)
        if text[0] != ' ':
            text = ' '+text
        items = list(self.items)
        last_slot = len(self.items)
        if self.__add_head__ == last_slot:
            print('all slots are full, cannot add item to %s'%self)
            return None
        button = self.items[items[self.__add_head__]]
        button['text'] = text
        button['command'] = command
        button['extraArgs'] = args + button['extraArgs']  # blank buttons always have [self,id]
        self.__add_head__ += 1


    def __create_item__(self, text, command = None, args = tuple()): 
        args = list(args)

        #if not len(self.items):
            #parent = self.frame
        if len(self.items) <= 1:
            parent = self.itemsParent  #everyone else parents off 2nd text
        else:
            parent = list(self.items.values())[-1]

        if command != None:
            def cmd(*args):
                """ any item should raise
                """
                self.raise_()
                command(*args)
        else:
            cmd = self.raise_


        b = DirectButton(
            parent=parent,
            frameColor=(1,1,1,.0),  # a = 0 => no border overlap
            frameSize=(0, self.width, 0, self.text_h),
            text=' '+text,  # hack to keep spacing from border
            text_font=self.text_font,
            text_fg=self.text_color,
            text_scale=self.text_s,
            text_pos=(0, self.text_h - self.TEXT_MAGIC_NUMBER * self.text_s),
            command=cmd,
            relief=DGG.FLAT,
            text_align=TextNode.ALeft,
        )

        b.setPos(LVecBase3f(0, 0, -self.text_h))
        b.setName('DirectButton-'+text)
        if not len(self.items):
            self.items['title'] = b
            b.setBin(*self.DRAW_ORDER['title'])
        else:
            b['extraArgs'] = args+[self, id(b)]
            b.node().setPythonTag('id', id(b))
            b.setBin(*self.DRAW_ORDER['items'])
            if len(self.items) is 1:  # the first item that is not the title
                b.setPos(LVecBase3f(0, 0, -(self.text_h * 2)))
                self.__first_item__ = id(b)

            self.items[id(b)] = b

        if text == ' blank':
            if self.__add_head__ is None:
                self.__add_head__ = 1

        return b

    def del_all(self):
        if self.__first_item__ != None:
            for id_, button in self.items.items():
                if id_ != 'title':
                    button['text'] = ' blank'
                    button['command'] = None
                    button['extraArgs'] = [self, id_]
            self.__add_head__ = 1

    def del_item(self, text):  # FIXME uniqueness problems
        #d = self.itemsParent.find('*%s*'%text)
        if text[0] != ' ':
            text = ' '+text
        d = [i for i in self.items.values() if i.getName().count(text)]
        try:
            self.__del_item__(d[0].getPythonTag('id'))
        except IndexError:
            print('that item does not seem to exist')
            # if we have a name then there shouldn't be key errors

    def __del_item__(self, index):
        """ I have no idea how this is going to work """
        out = self.items[index]
        p = out.getParent()
        if out.getNumChildren():  # avoid the printing of the AssertionError :/
            c = out.getChild(0)
            c.reparentTo(p)
            if index == self.__first_item__:  # XXX is fails, ints from id !=
                c.setPos(LVecBase3f(out.getPos()))
                id_ = c.getPythonTag('id')
                self.__first_item__ = id_
                out.setPos(LVecBase3f(0, 0, -self.text_h))
        self.items.pop(index)
        parent = list(self.items.values())[-1]
        out['text'] = ' del blank'
        #out['command'] = None
        out['extraArgs'] = [self, index]
        out.reparentTo(parent)
        self.items[index] = out
        if self.__add_head__ > 1:  # title is always at 0
            self.__add_head__ -= 1

    @classmethod
    def __make_border__(cls, parent, thickness, color, l, r , b, t):
        moveto_drawto = (
           ((l,0,t), (l,0,b)),
           ((r,0,t), (r,0,b)),
           ((l,0,b), (r,0,b)),
           ((l,0,t), (r,0,t)),
        )
        for moveto, drawto in moveto_drawto:
            Border = LineSegs()
            Border.setThickness(thickness)
            Border.setColor(*color)
            Border.moveTo(*moveto)
            Border.drawTo(*drawto)
            b = parent.attachNewNode(Border.create())
            b.setBin(*cls.DRAW_ORDER['border'])

    def getMaxItems(self):
        return int(abs(self.height / self.text_h) - 1)

    @event_callback
    def toggle_vis(self):
        if self.frame_bg.isHidden():
            self.frame_bg.show()
            self.raise_()
        else:
            self.frame_bg.hide()

    def title_toggle_vis(self):
        if not self.__was_dragging__:
            self.toggle_vis()
            if self.frame_bg.isHidden():
                self.title_button.wrtReparentTo(self.frame)
                self.title_button['frameColor'] = (1, 1, 1, .5)  # TODO
            else:
                self.title_button.wrtReparentTo(self.frame_bg)
                self.title_button['frameColor'] = (1, 1, 1, 0)  # TODO
        else:
            self.__was_dragging__ = False

    def __startDrag(self, crap):
        self.raise_()
        self._ox, self._oy = base.mouseWatcherNode.getMouse()
        taskMgr.add(self.__drag,'dragging %s'%self.title)
        self.origBTprefix=self.BT.getPrefix()
        self.BT.setPrefix('dragging frame')

    def __drag(self, task):
        if base.mouseWatcherNode.hasMouse():
            x, y = base.mouseWatcherNode.getMouse()
            if x != self._ox or y != self._oy:
                m_old = aspect2d.getRelativePoint(render2d, Point3(self._ox, self._oy, 0))
                m_new = aspect2d.getRelativePoint(render2d, Point3(x, y, 0))
                dx, dy, _ = m_new - m_old
                self.setPos(self.x + dx, self.y + dy)
                self._ox = x
                self._oy = y
                self.__was_dragging__ = True
        return task.cont

    def __stopDrag(self,crap):
        taskMgr.remove('dragging %s'%self.title)
        self.BT.setPrefix(self.origBTprefix)

    def setPos(self, x, y):
        """ actually sets the title button position
            since it is really the parent node
        """
        self.x = x
        self.y = y #- self.text_h  # FIXME is hard :/
        self.frame_bg.setPos(LVecBase3f(x, 0, y))
        if self.frame_bg.isHidden():
            self.title_button.setPos(LVecBase3f(x, 0, y - self.text_h))


    def __enter__(self):
        #load the position
        #load other saved state
        pass

    def __exit__(self):
        #save the position!
        #save other state
        pass
コード例 #26
0
ファイル: ChatBox.py プロジェクト: czorn/Modifire
class ChatBox(DirectObject):
    
    MESSAGE_LIFE = 10
    MAX_NUM_MESSAGES = 15
    
    (TYPE_GLOBAL,
     TYPE_TEAM,
     TYPE_CONSOLE) = range(3)
     
    messageTypeToPrefix = { TYPE_GLOBAL : 'Global:', 
                            TYPE_TEAM : 'Team:',
                            TYPE_CONSOLE : 'Console' }
    
    def __init__(self):
        self.textNodes = []
        self.messageType = None
        
        self.rootFrame = DirectFrame(pos = (0.03, 0, 0.2),
                                 frameColor = (0, 0, 0, 0),
                                 frameSize = (0, 1, 0, 1),
                                 parent = base.a2dBottomLeft)
        self.rootFrame.setBin('fixed', GUIOrder.ORDER[GUIOrder.CHAT])
        
        self.entryFrame = DirectFrame(pos = (0, 0, 0),
                                 frameColor = (0, 0, 0, 0.1),
                                 frameSize = (0, 1, 0, 0.1),
                                 parent = self.rootFrame)
        
        self.chatarea = DirectEntry(width = 27,
                                    scale = Settings.CHAT_HEIGHT,
                                    pos = (0, 0, 0),
                                    frameColor = (0, 0, 0, 0),
                                    text_fg = (1, 1, 1, 1),
                                    numLines = 1,
                                    cursorKeys = 1,
                                    rolloverSound = None,
                                    clickSound = None,
                                    focus = 0,
                                    command = self.OnChatEntered,
                                    parent = self.entryFrame)
        
        self.typeText = OnscreenText(text = '', 
                                     pos = (0, Settings.CHAT_HEIGHT + 0.01), 
                                     scale = Settings.CHAT_HEIGHT,
                                     fg = (1, 1, 1, 1),
                                     mayChange = True,
                                     align = TextNode.ALeft,
                                     parent = self.entryFrame)
        
        self.displayFrame = DirectFrame(pos = (0, 0, 0.1),
                                 frameColor = (0, 0, 0, 0),
                                 frameSize = (0, 1, 0, 0.42),
                                 parent = self.rootFrame)
        
        self.chatarea.enterText('')
        self.entryFrame.hide()
        self.chatarea['focus'] = 0
        self.chatarea.setFocus()    
        
    def OnChatEntered(self, enteredText):
        enteredText = enteredText.strip()
        self.Hide()
        if(len(enteredText) > 0):
            ChatEnteredEvent(self.messageType, enteredText).Fire()
        
    def AddMessage(self, prefix, prefixColor, message):
        parent = self.displayFrame.attachNewNode('messageParent')
        
        prefixTextNode = TextNode('prefixMessage')
        prefixTextNode.setText(prefix)
        prefixTextNode.setTextColor(prefixColor)
        prefixTextNode.setShadow(0.05, 0.05)
        prefixTextNode.setShadowColor(Globals.COLOR_BLACK)
        prefixTextNodePath = parent.attachNewNode(prefixTextNode)
        prefixTextNodePath.setScale(Settings.CHAT_HEIGHT)
        
        messageTextNode = TextNode('prefixMessage')
        messageTextNode.setText(message)
        messageTextNode.setTextColor(1, 1, 1, 1)
        messageTextNode.setShadow(0.05, 0.05)
        messageTextNode.setShadowColor(Globals.COLOR_BLACK)
        messageTextNodePath = parent.attachNewNode(messageTextNode)
        messageTextNodePath.setScale(Settings.CHAT_HEIGHT)
        messageTextNodePath.setPos(Vec3(prefixTextNode.calcWidth(prefix) * Settings.CHAT_HEIGHT, 0, 0))
        
        taskMgr.remove('HideMessageLog')
        taskMgr.doMethodLater(ChatBox.MESSAGE_LIFE, self.HideMessageLog, 'HideMessageLog') 
        self.ShowMessageLog()
        
        self.textNodes.append(parent)
        
        if(len(self.textNodes) > ChatBox.MAX_NUM_MESSAGES):
            self.RemoveMessage(self.textNodes[0])
            
        self.RedrawMessages()
        
    def RedrawMessages(self):
        n = len(self.textNodes)
        for i, textNode in enumerate(self.textNodes):
            LerpPosInterval(textNode, 0.5, (0, 0, (n-i) * (Settings.CHAT_HEIGHT + 0.01))).start()
            
    def RemoveMessage(self, textNode):
        self.textNodes.remove(textNode)
        textNode.removeNode()
        
    def HideMessageLog(self, task = None):
        self.displayFrame.hide()
        
    def ShowMessageLog(self):
        self.displayFrame.show()
        
    def Hide(self):
        self.chatarea.enterText('')
        self.entryFrame.hide()
        self.chatarea['focus'] = 0
        self.chatarea.setFocus()
        self.HideMessageLog()
        ChatCloseEvent().Fire()
        
    def Show(self, messageType):
        self.messageType = messageType
        self.entryFrame.show()
        self.chatarea['focus'] = 1
        self.chatarea.setFocus()
        self.typeText.setText(ChatBox.GetPrefix(self.messageType))
        self.ShowMessageLog()
        ChatOpenEvent().Fire()
        
    def EnableKeyboardListening(self):
        self.acceptOnce('escape', self.Hide)
        
    def DisableKeyboardListening(self):
        self.ignoreAll()
        
    @staticmethod
    def GetPrefix(messageType):
        return ChatBox.messageTypeToPrefix[messageType]
    
    def Destroy(self):
        taskMgr.remove('HideMessageLog')
        self.rootFrame.destroy()
        self.entryFrame.destroy()
        self.chatarea.destroy()
        self.typeText.destroy()
        self.displayFrame.destroy()
        self.ignoreAll()
        
コード例 #27
0
ファイル: QuestMap.py プロジェクト: CalebSmith376/src
 def show(self):
     taskMgr.add(self.initMarker, 'questMapInit')
     DirectFrame.show(self)
     self.mapOpenButton.hide()
     if self.container['image']:
         self.mapCloseButton.show()
コード例 #28
0
ファイル: menu.py プロジェクト: jorjuato/panda3d-tutorial
class Menu:
    def __init__(self):

        self.frameMain = DirectFrame(
            image = "gui/MenuBackground.png",
            image_scale = (1.7778, 1, 1),
            frameSize = (base.a2dLeft, base.a2dRight,
                         base.a2dTop, base.a2dBottom),
            frameColor = (0, 0, 0, 0))
        self.frameMain.setTransparency(1)

        self.title = DirectLabel(
            scale = 0.15,
            text_align = TextNode.ALeft,
            pos = (base.a2dLeft + 0.2, 0, 0),
            frameColor = (0, 0, 0, 0),
            text = "Main Menu",
            text_fg = (1,1,1,1))
        self.title.setTransparency(1)
        self.title.reparentTo(self.frameMain)

        self.btnStart = self.createButton(
            "Start",
            -.10,
            ["Menu-Start"])

        self.btnStart = self.createButton(
            "Credits",
            -.25,
            ["Menu-Credits"])

        self.btnExit = self.createButton(
           "Quit",
            -.40,
            ["Menu-Quit"])

        self.hide()

    def createButton(self, text, verticalPos, eventArgs):
        maps = loader.loadModel("gui/button_map")
        btnGeom = (maps.find("**/btn_ready"),
                    maps.find("**/btn_click"),
                    maps.find("**/btn_rollover"),
                    maps.find("**/btn_disabled"))
        btn = DirectButton(
            text = text,
            text_fg = (0,0,0,1),
            text_scale = 0.05,
            text_pos = (0.02, -0.015),
            text_align = TextNode.ALeft,
            scale = 2,
            pos = (base.a2dLeft + 0.2, 0, verticalPos),
            geom = btnGeom,
            relief = 0,
            frameColor = (0,0,0,0),
            command = base.messenger.send,
            extraArgs = eventArgs,
            pressEffect = False,
            rolloverSound = None,
            clickSound = None)
        btn.reparentTo(self.frameMain)

    def show(self):
        self.frameMain.show()

    def hide(self):
        self.frameMain.hide()
コード例 #29
0
class Credits:
    def __init__(self):

        self.frameMain = DirectFrame(
            frameSize = (base.a2dLeft, base.a2dRight,
                         base.a2dBottom, base.a2dTop),
            frameColor = (0.05, 0.05, 0.05, 1))
        self.frameMain.setTransparency(1)

        tpBig = TextProperties()
        tpBig.setTextScale(1.5)
        tpSmall = TextProperties()
        tpSmall.setTextScale(0.75)
        tpUs = TextProperties()
        tpUs.setUnderscore(True)
        tpMgr = TextPropertiesManager.getGlobalPtr()
        tpMgr.setProperties("big", tpBig)
        tpMgr.setProperties("small", tpSmall)
        tpMgr.setProperties("us", tpUs)

        creditsText = ""
        with open("credits.txt") as f:
            creditsText = f.read()
        self.lblCredits = DirectLabel(
            text = creditsText,
            text_fg = (1,1,1,1),
            text_bg = (0,0,0,0),
            frameColor = (0,0,0,0),
            text_align = TextNode.ACenter,
            scale = 0.1,
            pos = (0, 0, base.a2dTop - 0.2))
        self.lblCredits.setTransparency(1)
        self.lblCredits.reparentTo(self.frameMain)

        self.creditsScroll = LerpPosInterval(
            self.lblCredits,
            12.0,
            (0, 0, base.a2dTop + 3.5),
            startPos=(0, 0, base.a2dBottom),
            name="CreditsScroll")

        self.btnBack = DirectButton(
            text = "BACK",
            text_fg = (1,1,1,1),
            text_align = TextNode.ALeft,
            scale = 0.1,
            pad = (0.15, 0.15),
            pos = (base.a2dLeft + 0.08, 0, base.a2dBottom + 0.05),
            frameColor = (
                (0.2,0.2,0.2,0.8),
                (0.4,0.4,0.4,0.8),
                (0.4,0.4,0.4,0.8),
                (0.1,0.1,0.1,0.8),
                ),
            relief = 1,
            command = base.messenger.send,
            extraArgs = ["Credits-Back"],
            pressEffect = False,
            rolloverSound = None,
            clickSound = None)
        self.btnBack.setTransparency(1)
        self.btnBack.reparentTo(self.frameMain)

        self.hide()

    def show(self):
        self.frameMain.show()
        self.creditsScroll.loop()

    def hide(self):
        self.frameMain.hide()
        self.creditsScroll.finish()
コード例 #30
0
ファイル: developerconsole.py プロジェクト: karlexceed/naith
class DeveloperConsole(InteractiveInterpreter, DirectObject):
    """The name says it all."""
    def __init__(self, manager, xml):
        sys.stdout = PseudoFile(self.writeOut)
        sys.stderr = PseudoFile(self.writeErr)
        tpErr = TextProperties()
        tpErr.setTextColor(1, 0.5, 0.5, 1)
        TextPropertiesManager.getGlobalPtr().setProperties("err", tpErr)
        self.manager = manager
        font = loader.loadFont("cmss12")
        self.frame = DirectFrame(parent=base.a2dTopCenter,
                                 text_align=TextNode.ALeft,
                                 text_pos=(-base.getAspectRatio() +
                                           TEXT_MARGIN[0], TEXT_MARGIN[1]),
                                 text_scale=0.05,
                                 text_fg=(1, 1, 1, 1),
                                 frameSize=(-2.0, 2.0, -0.5, 0.0),
                                 frameColor=(0, 0, 0, 0.5),
                                 text='',
                                 text_font=font)
        self.entry = DirectEntry(parent=base.a2dTopLeft,
                                 command=self.command,
                                 scale=0.05,
                                 width=1000.0,
                                 pos=(-0.02, 0, -0.48),
                                 relief=None,
                                 text_pos=(1.5, 0, 0),
                                 text_fg=(1, 1, 0.5, 1),
                                 rolloverSound=None,
                                 clickSound=None,
                                 text_font=font)
        self.otext = OnscreenText(parent=self.entry,
                                  scale=1,
                                  align=TextNode.ALeft,
                                  pos=(1, 0, 0),
                                  fg=(1, 1, 0.5, 1),
                                  text=':',
                                  font=font)
        self.lines = [''] * 9
        self.commands = []  # All previously sent commands
        self.cscroll = None  # Index of currently navigated command, None if current
        self.command = ''  # Currently entered command
        self.block = ''  # Temporarily stores a block of commands
        self.hide()
        self.initialized = False

    def prevCommand(self):
        if self.hidden: return
        if len(self.commands) == 0: return
        if self.cscroll == None:
            self.cscroll = len(self.commands)
            self.command = self.entry.get()
        elif self.cscroll <= 0:
            return
        else:
            self.commands[self.cscroll] = self.entry.get()
        self.cscroll -= 1
        self.entry.set(self.commands[self.cscroll])
        self.entry.setCursorPosition(len(self.commands[self.cscroll]))

    def nextCommand(self):
        if self.hidden: return
        if len(self.commands) == 0: return
        if self.cscroll == None: return
        self.commands[self.cscroll] = self.entry.get()
        self.cscroll += 1
        if self.cscroll >= len(self.commands):
            self.cscroll = None
            self.entry.set(self.command)
            self.entry.setCursorPosition(len(self.command))
        else:
            self.entry.set(self.commands[self.cscroll])
            self.entry.setCursorPosition(len(self.commands[self.cscroll]))

    def writeOut(self, line, copy=True):
        if copy: sys.__stdout__.write(line)
        lines = line.split('\n')
        firstline = lines.pop(0)
        self.lines[-1] += firstline
        self.lines += lines
        self.frame['text'] = '\n'.join(self.lines[-9:])

    def writeErr(self, line, copy=True):
        if copy: sys.__stderr__.write(line)
        line = '\1err\1%s\2' % line
        lines = line.split('\n')
        firstline = lines.pop(0)
        self.lines[-1] += firstline
        self.lines += lines
        self.frame['text'] = '\n'.join(self.lines[-9:])

    def command(self, text):
        if not self.hidden:
            self.cscroll = None
            self.command = ''
            self.entry.set('')
            self.entry['focus'] = True
            self.writeOut(self.otext['text'] + ' ' + text + '\n', False)
            if text != '' and (len(self.commands) == 0
                               or self.commands[-1] != text):
                self.commands.append(text)

            # Insert plugins into the local namespace
            locals = __main__.__dict__
            locals['manager'] = self.manager
            for plugin in self.manager.named.keys():
                locals[plugin] = self.manager.named[plugin]
            locals['panda3d'] = panda3d

            # Run it and print the output.
            if not self.initialized:
                InteractiveInterpreter.__init__(self, locals=locals)
                self.initialized = True
            try:
                if self.runsource(self.block + '\n' + text) and text != '':
                    self.otext['text'] = '.'
                    self.block += '\n' + text
                else:
                    self.otext['text'] = ':'
                    self.block = ''
            except Exception:  # Not just "except", it will also catch SystemExit
                # Whoops! Print out a traceback.
                self.writeErr(traceback.format_exc())

    def toggle(self):
        if self.hidden:
            self.show()
        else:
            self.hide()

    def show(self):
        self.accept('arrow_up', self.prevCommand)
        self.accept('arrow_up-repeat', self.prevCommand)
        self.accept('arrow_down', self.nextCommand)
        self.accept('arrow_down-repeat', self.nextCommand)
        self.hidden = False
        self.entry['focus'] = True
        self.frame.show()
        self.entry.show()
        self.otext.show()

    def hide(self):
        self.ignoreAll()
        self.hidden = True
        self.entry['focus'] = False
        self.frame.hide()
        self.entry.hide()
        self.otext.hide()

    def destroy(self):
        sys.stdout = sys.__stdout__
        sys.stderr = sys.__stderr__
        self.ignoreAll()
        self.frame.destroy()
        self.entry.destroy()
        self.otext.destroy()
コード例 #31
0
class ToonFPSGui:

    def __init__(self, base):
        self.base = base
        self.noAmmoLabel = None
        self.ammo_gui = None
        self.hp_meter = None
        self.crosshair = None
        self.stats_container = None
        self.stats_bg = None
        self.stats_lbl = None
        self.kills_lbl = None
        self.deaths_lbl = None
        self.points_lbl = None
        return

    def load(self):
        self.ammo_gui = loader.loadModel('phase_4/models/minigames/gun_ammo_gui.egg')
        self.ammo_gui.setScale(0.15)
        self.ammo_gui.setPos(0.38, 0, 0.1)
        self.hp_meter = DirectWaitBar(text=str(self.base.hp), text_roll=-90, text_scale=0.2, text_pos=(-0.025,
                                                                                                       0), relief=DGG.RAISED, barColor=(1,
                                                                                                                                        0,
                                                                                                                                        0,
                                                                                                                                        1), range=self.base.max_hp, value=self.base.hp, parent=base.a2dBottomRight, scale=0.4, pos=(-0.12,
                                                                                                                                                                                                                                    0,
                                                                                                                                                                                                                                    0.2), frameSize=(-0.4,
                                                                                                                                                                                                                                                     0.4,
                                                                                                                                                                                                                                                     -0.2,
                                                                                                                                                                                                                                                     0.2))
        self.hp_meter.setR(-90)
        self.hp_meter.hide()
        self.crosshair = getCrosshair()
        font = CIGlobals.getToonFont()
        box = DGG.getDefaultDialogGeom()
        if self.base.__class__.__name__ == 'GunGameToonFPS':
            self.stats_container = DirectFrame(parent=base.a2dTopLeft, pos=(0.3, 0.2,
                                                                            -0.185))
            self.stats_bg = OnscreenImage(image=box, color=(1, 1, 0.75, 1), scale=(0.5,
                                                                                   0.3,
                                                                                   0.3), parent=self.stats_container)
            self.stats_lbl = OnscreenText(font=font, text='Stats', pos=(-0.01, 0.08,
                                                                        0), parent=self.stats_container)
            self.kills_lbl = OnscreenText(font=font, text='Kills: ' + str(self.base.kills), pos=(-0.235,
                                                                                                 0.025,
                                                                                                 0), scale=0.055, parent=self.stats_container, align=TextNode.ALeft)
            self.deaths_lbl = OnscreenText(font=font, text='Deaths: ' + str(self.base.deaths), pos=(-0.235,
                                                                                                    -0.04,
                                                                                                    0), scale=0.055, parent=self.stats_container, align=TextNode.ALeft)
            self.points_lbl = OnscreenText(font=font, text='Points: ' + str(self.base.points), pos=(-0.235,
                                                                                                    -0.105,
                                                                                                    0), scale=0.055, parent=self.stats_container, align=TextNode.ALeft)
            self.stats_container.hide()
            del font
            del box

    def start(self):
        self.ammo_gui.reparentTo(base.a2dBottomLeft)
        self.crosshair.show()
        self.hp_meter.show()
        if self.base.__class__.__name__ == 'GunGameToonFPS':
            self.stats_container.show()

    def end(self):
        self.ammo_gui.reparentTo(hidden)
        if self.base.__class__.__name__ == 'GunGameToonFPS':
            self.stats_container.hide()
        self.crosshair.hide()
        self.hp_meter.hide()

    def cleanup(self):
        self.ammo_gui.removeNode()
        self.ammo_gui = None
        self.hp_meter.destroy()
        self.hp_meter = None
        self.crosshair.destroy()
        self.crosshair = None
        self.deleteNoAmmoLabel()
        self.deleteStatsGui()
        return

    def deleteStatsGui(self):
        if self.stats_container:
            self.stats_container.destroy()
            self.stats_container = None
        if self.stats_bg:
            self.stats_bg.destroy()
            self.stats_bg = None
        if self.stats_lbl:
            self.stats_lbl.destroy()
            self.stats_lbl = None
        if self.kills_lbl:
            self.kills_lbl.destroy()
            self.kills_lbl = None
        if self.deaths_lbl:
            self.deaths_lbl.destroy()
            self.deaths_lbl = None
        if self.points_lbl:
            self.points_lbl.destroy()
            self.points_lbl = None
        return

    def updateStats(self):
        self.kills_lbl['text'] = 'Kills: ' + str(self.base.kills)
        self.deaths_lbl['text'] = 'Deaths: ' + str(self.base.deaths)
        self.points_lbl['text'] = 'Points: ' + str(self.base.points)

    def deleteNoAmmoLabel(self):
        if self.noAmmoLabel:
            self.noAmmoLabel.destroy()
            self.noAmmoLabel = None
        return

    def adjustAmmoGui(self):
        self.ammo_gui.find('**/bar_' + str(self.base.ammo + 1)).hide()

    def adjustHpMeter(self):
        self.hp_meter['text'] = str(self.base.hp)
        self.hp_meter['value'] = self.base.hp
        if self.base.hp <= 40:
            self.hp_meter['barColor'] = (1, 0, 0, 1)
        else:
            self.hp_meter['barColor'] = (1, 1, 1, 1)

    def resetAmmo(self):
        for bar in self.ammo_gui.findAllMatches('**/bar_*'):
            bar.show()

    def notifyNoAmmo(self):
        self.deleteNoAmmoLabel()
        self.noAmmoLabel = DirectLabel(text='Press R to reload!', relief=None, text_scale=0.1, text_pos=(0,
                                                                                                         0.5,
                                                                                                         0), text_fg=(1,
                                                                                                                      1,
                                                                                                                      1,
                                                                                                                      1), text_shadow=(0,
                                                                                                                                       0,
                                                                                                                                       0,
                                                                                                                                       1))
        return
コード例 #32
0
ファイル: JournalUI.py プロジェクト: wpesetti/RedPanda
class JournalUI(UIBase):
    '''
    This is the UI of journal
    '''

    def __init__(self,world):
        '''
        Constructor
        '''
        UIBase.__init__(self, world)

              
        '''
        init variables
        '''
        #load skin of journal button and scrollbar as egg files
        self.button_maps = self.world.loader.loadModel("./LEGameAssets/Models/button") 
        self.scrollbar_maps = self.world.loader.loadModel("./LEGameAssets/Models/scrollbar")

        #skin for the journal tray
        self.img_files = ["./LEGameAssets/Textures/journal_rollout_tray.png"]

        #variables that store the UI elements which are going to be created
        self.journal_window_frame = None
        self.window_show = True  
        self.journal_window = None
        self.frame = None
        self.canvas = None
        
        #variables that store list of title and statement of journal from journalMrg
        self.journal_entries= []
        self.quest_text = []

        #size of the screen
        self.screen_size_x = base.win.getXSize()
        self.screen_size_y = base.win.getYSize()
        
        
        #variables that help to make the popout window and arrange the text
        self.count = [0,0,0,0]
        self.char_size = 0.05
        self.last_char_size = None
        self.line_space = 0.2
        self.top_line = 0.1
        self.longest_line = {"menu":[0,0],"quest":[0,0]}
        self.buttons_1 = []
        self.buttons_2 = []
    
        self.page_canvas_size= {"menu": (0,0,0,0), "quest": (0,0,0,0)}
        self.page_buttons = {"menu": self.buttons_1, "quest": self.buttons_2}
        self.showing_page = "menu" 
                
        #set the default canvas size and frame size
        self.canvas_size = (0.3, 1.25, 0.015, 0.75)
        self.frame_size = (0.3, 1.25, 0.015, 0.75)
           
        #add button
        self.b = DirectButton( geom = (self.button_maps.find("**/ok"),self.button_maps.find("**/click"),self.button_maps.find("**/rolling_over"),self.button_maps.find("**/disable")),
                          text_scale = (0.15,0.15), pos = (-0.23, 0, -0.12), relief=None, scale=0.38, command=self.popoutWindow, parent= base.a2dTopRight)
        
        

        
    def update(self):
        self.journal_entries = self.world.journalMgr.getOpenedJournalEntries()
        #self.journal_entries = [("title1","Now if I take out the task argument all is fine obviously. However I need a way to access the time the task runs.This will give you a scrollbar at the lower left side of the screen. If you want to parent the scrollbar to a determined frame, you add the keyword parent to the set of keyboards like so.DirectScrollBar is available beginning in Panda3D 1.1. It consists of a long trough, a thumb that slides along the trough, and a pair of buttons on either side of the trough to scroll one line at a time. A DirectScrollBar can be oriented either vertically or horizontally."),("title2","Completed"),("title3","statement3")]
        #print base.win.getXSize(),base.win.getYSize()
        #print "update"

        
    #Create a popout window        
    def popoutWindow(self):
        if self.window_show:
            self.longest_line = {"menu":[0,0],"quest":[0,0]}
            self.count = [0,0,0,0]
            self.update()
            self.journal_window_frame = DirectFrame(frameColor=(0, 0, 0, 0.12),frameSize=(0.28, 1.27, -0.005, 0.77), parent= base.a2dTopRight, pos = (-1.3,0,-1))
            self.journal_window = DirectScrolledFrame(canvasSize = (self.canvas_size), frameSize = (self.frame_size),frameColor=(0, 0, 0, 0.12),
                                                      autoHideScrollBars = True, manageScrollBars = True, parent = self.journal_window_frame ) 
            self.changeSkin(self.img_files)
            self.changeScrollbarSkin()
            self.canvas= self.journal_window.getCanvas()        
            self.createMenu()
            self.createQuest()
            self.showMenu()
            self.changeButtonColor()


            
      
        else:
            self.destroy()       
        self.window_show = not self.window_show
    
    #destroy the popout window
    def destroy(self):
        self.journal_window_frame.destroy()
        # if the button list has been detached when the parent(journal_window) is destroyed, them won't be destroyed
        for button in self.buttons_1:
            button.destroy()
        for button in self.buttons_2:
            button.destroy()
        for label in self.quest_text:
            label.destroy()
        # clean up the button list
        for i in range(len(self.buttons_1)):
            self.buttons_1.pop()
        for j in range(len(self.buttons_2)):
            self.buttons_2.pop()
        for k in range(len(self.quest_text)):
            self.quest_text.pop()
            
    '''
    These functions are for the other parts to call to hide/show the JournalUI
    '''        
#----------------------------------------------
    def hideAll(self):
        self.b.hide()
        if not self.window_show:
            self.journal_window_frame.hide()
            

    def showAll(self):
        self.b.show()
        if not self.window_show:
            self.journal_window_frame.show()
            

#-------------------------------------------------
    def destroyAll(self):
        self.destroy()
        self.b.destroy()
    
    def createAll(self):
        pass
#-----------------------------------------------------------------------------------------           
        
        
    def switchPage(self, page):
        self.journal_window['canvasSize']=(self.page_canvas_size[page])
        self.hideButton(self.page_buttons[self.showing_page])
        self.showButton(self.page_buttons[page]) 
        self.showing_page = page
        
        #------------quest------------------
        if page == "quest":
            for label in self.quest_text:
                label.reparentTo(self.canvas)
        else :
            self.hideText()
            
 
            
    def hideButton(self, page):                   
        for button in page:
            button.detachNode()
            
            
    def showButton(self, page):
        for button in page:
            button.reparentTo(self.canvas)
        
    def hideText(self):

        for label in self.quest_text:
            label.detachNode()
        
        for k in range(len(self.quest_text)):
            self.quest_text.pop()

     
  
    def showMenu(self):
        self.switchPage("menu")

    
    def showQuest(self, tag):   
        for entry in self.journal_entries:
            if entry[0] == tag:
                temp_text = entry[1]                
                self.addText(temp_text, 0.05, "quest")
                break           
        self.switchPage("quest")  
       

    def addButton(self, text, position, scale, func_call, type, page):     
        if type  == 1:
            button =  DirectButton(text = (text),text_fg =(1,0,0,1),text_bg =(0,0,0,0),pos =(position),text_scale = (scale), relief = None,command=func_call, extraArgs = [text])
        else:
            button =  DirectButton(text = (text),text_fg =(1,0,0,1),text_bg =(0,0,0,0),pos =(position),text_scale = (scale), relief = None,command=func_call)

        if(position[0] - button.getWidth()/2.0 < self.longest_line[page][0]):
            '''
            something different here -0.02 for the right side 
            ''' 
            self.count[0] = position[0] - button.getWidth()/2.0 - 0.02 #right
            self.longest_line[page][0] = self.count[0]
        if(position[1] + button.getWidth()/2.0 > self.longest_line[page][1]):
            self.count[1] = position[1] + button.getWidth()/2.0 #left
            self.longest_line[page][1] = self.count[1]  
        self.count[2] = position[2]-button.getHeight()#bottom
        self.journal_window['canvasSize']=(self.count[0],self.count[1],self.count[2],self.count[3])
        
        button.detachNode()  #make sure buttons won't be shown at the first time it is created           
        self.page_buttons[page].append(button)
        self.page_canvas_size[page] = (self.count[0],self.count[1],self.count[2],self.count[3])
    
    def addText(self, show_text, text_scale, page):

        self.page_canvas_size[page]=(self.canvas_size)
        
        max_window_width = abs(self.canvas_size[1] - self.canvas_size[0])
        
        # the width of the DirectLabel object is only changing with the length of the string in text attribute, but this width is different from the width of the DriectFrame and DriectButton,
        # so I don't know what is the unit of this DriectLable width, if you change the scale of the label, the width is not going to change, and the text will going out of the boundary,
        # I should change the max number of character with scale
        text_len =  len(show_text)        

        offset = text_scale - 0.05
        
        if(offset > 0):
            max_text_len = 35 - offset * 500
        if(offset <= 0):
            max_text_len = 35 + abs(offset) * 500

        
        text_lines = []
        
        if  text_len > max_text_len:
            wrapper = TextWrapper(initial_indent="* ", width = max_text_len)
            text_lines = wrapper.wrap(show_text)
        
        else:
            text_lines.append(show_text)
     
        line_space  = 0.0
        for t in text_lines:
            temp_text = DirectLabel(text = t,pos = (0.75,0,0.52-line_space),scale = text_scale, text_bg = (0,1,1,0.0),text_fg=(0,0,0,1),frameColor=(0,0,0,0))
            self.quest_text.append(temp_text)
            if (0.5 - line_space)< self.canvas_size[2]:
                self.page_canvas_size[page]=(self.canvas_size[0],self.canvas_size[1]-0.1, 0.48 - line_space,self.canvas_size[3])
            line_space +=0.08

        for label in self.quest_text:    
            label.detachNode()  
   
    def createMenu(self):
              
        #initialize value for the beginning line, this will never change
        self.count[3]= self.top_line
        #add button
        offset = 0
        #self.journal_entries= [("title1","Now if I take out the task argument all is fine obviously. However I need a way to access the time the task runs."),("title2","statement2"),("title3","statement3")]
        for entry in self.journal_entries:
            self.addButton(entry[0],(-0.08, 0, -0.02+offset),(0.05,0.05),self.showQuest,1 ,"menu")
            offset += -0.08
           

    def createQuest(self):    
        self.addButton("Back",(0.45, 0, 0.62),(0.08,0.08),self.showMenu,0,"quest" )
        
        
        
    def changeSkin(self, img_files):
        if len(img_files) == 1:
            self.journal_window['image']=(img_files[0])
            #self.journal_window['image_scale']=(0.43,0,0.43) #old scale without size 800*600
            #self.journal_window['image_pos']=(0.75,0,0.33) #old position without size 800*600
            self.journal_window['image_scale']=(1.335,1,1)
            self.journal_window['image_pos']=(0,0,0)
            self.journal_window.setTransparency(1) 
            self.journal_window['frameColor']=(0,0,0,0)
        if len (img_files) == 2:
            self.journal_window_frame['image']=(img_files[1])
            #self.journal_window_frame['image_scale']=(0.44,0,0.44)#old scale without size 800*600
            #self.journal_window_frame['image_pos']=(0.75,0,0.33)#old position without size 800*600
            self.journal_window_frame['image_scale']=(1.335,1,1)
            self.journal_window_frame['image_pos']=(0,0,0)
            self.journal_window_frame.setTransparency(1)
            self.journal_window_frame['frameColor']=(0,0,0,0)
            
    def changeScrollbarSkin(self):
        self.journal_window['verticalScroll_relief']= None#  Relief appearance of the frame
        self.journal_window['verticalScroll_image']= ("./LEGameAssets/Textures/journal_scrollbar.png")
        self.journal_window.verticalScroll['image_pos']=(1.21,0.1,0.36)
        self.journal_window.verticalScroll['image_scale']=(0.05,0.1,0.38)
        self.journal_window.verticalScroll.incButton['geom']=(self.scrollbar_maps.find("**/journal_scrollbutton_down"))
        self.journal_window.verticalScroll.incButton['relief']=None#  Relief appearance of the frame
        self.journal_window.verticalScroll.incButton['geom_scale']=(0.15,0.15,0.15)
        self.journal_window.verticalScroll.decButton['geom']=(self.scrollbar_maps.find("**/journal_scrollbutton_up"))
        self.journal_window.verticalScroll.decButton['relief']=None#  Relief appearance of the frame
        self.journal_window.verticalScroll.decButton['geom_scale']=(0.15,0.15,0.15)
        self.journal_window.verticalScroll.thumb['geom']=(self.scrollbar_maps.find("**/journal_scroll_button_updown"))
        self.journal_window.verticalScroll.thumb['relief']=None#  Relief appearance of the frame
        self.journal_window.verticalScroll.thumb['geom_scale']=(0.2,0.2,0.2)
        self.journal_window.verticalScroll.thumb['frameVisibleScale']=(0.5,0.25)#Relative scale of the visible frame to its clickable bounds. Useful for creating things like the paging region of a slider, which is visibly smaller than the acceptable click region 
        self.journal_window.verticalScroll['resizeThumb']=(True)
        self.journal_window.verticalScroll['scrollSize']=(0.1) #change the amount to jump the thumb when user click up/right and down/left
        self.journal_window.verticalScroll['range']=(-1,1)# change the (min, max) range of the thumb
        
        
    #--------UI feedback-----------------    
    def changeButtonColor(self):
        for entry in self.journal_entries:
            if (entry[1] == "Completed"):
                for b in self.buttons_1:
                    if (b['text'] == entry[0]):
                        b['text_fg'] = (0,1,0,1)
                        
    def flashJournalButton(self,task):
        if task.time <= 0.5:
            self.b['geom_scale']=(0.01,0.01,0.01)
            return task.cont
        
        elif task.time <=1.0:
            self.b['geom_scale']=(1.0,1.0,1.0)
            return task.cont
        elif self.window_show != True:
            return task.done
        else:
            return task.again

    def startFlash(self):   
        self.task = taskMgr.add(self.flashJournalButton, 'flashJournalButton') 
        
コード例 #33
0
class MainMenu(DirectObject):
    """This class represents the main menu as seen directly after the
    application has been started"""
    def __init__(self):

        # loading music
        self.menuMusic = loader.loadMusic("music/01Menu.mp3")
        self.menuMusic.setLoop(True)

        # create a main frame as big as the window
        self.frameMain = DirectFrame(
            # set framesize the same size as the window
            frameSize = (base.a2dLeft, base.a2dRight,
                         base.a2dTop, base.a2dBottom),
            # position center
            pos = (0, 0, 0),
            # set tramsparent background color
            frameColor = (0.15, 0.15, 0.15, 1))
        #self.frameMain.reparentTo(render2d)

        self.menuBackground = OnscreenImage(
            image = 'gui/Background.png',
            scale = (1.66, 1, 1),
            pos = (0, 0, 0))
        self.menuBackground.reparentTo(self.frameMain)

        self.defaultBtnMap = base.loader.loadModel("gui/button_map")
        self.buttonGeom = (
            self.defaultBtnMap.find("**/button_ready"),
            self.defaultBtnMap.find("**/button_click"),
            self.defaultBtnMap.find("**/button_rollover"),
            self.defaultBtnMap.find("**/button_disabled"))
        self.defaultTxtMap = base.loader.loadModel("gui/textbox_map")
        self.textboxGeom = self.defaultTxtMap.find("**/textbox")

        monospace = loader.loadFont('gui/DejaVuSansMono.ttf')
        defaultFont = loader.loadFont('gui/eufm10.ttf')

        # create the title
        self.textscale = 0.25
        self.title = DirectLabel(
            # scale and position
            scale = self.textscale,
            pos = (0.0, 0.0, base.a2dTop - self.textscale),
            # frame
            frameColor = (0, 0, 0, 0),
            # Text
            text = "Dungeon Crawler",
            text_align = TextNode.ACenter,
            text_fg = (0.82,0.85,0.87,1),
            text_shadow = (0, 0, 0, 1),
            text_shadowOffset = (-0.02, -0.02),
            text_font = defaultFont)
        self.title.setTransparency(1)
        self.title.reparentTo(self.frameMain)

        # create a host button
        self.btnHostPos = Vec3(0, 0, .45)
        self.btnHostScale = 0.25
        self.btnHost = DirectButton(
            # Scale and position
            scale = self.btnHostScale,
            pos = self.btnHostPos,
            # Text
            text = "Host",
            text_scale = 0.8,
            text_pos = (0, -0.2),
            text_fg = (0.82,0.85,0.87,1),
            text_shadow = (0, 0, 0, 1),
            text_shadowOffset = (-0.02, -0.02),
            text_font = defaultFont,
            # Frame
            geom = self.buttonGeom,
            frameColor = (0, 0, 0, 0),
            relief = 0,
            pressEffect = False,
            # Functionality
            command = self.host,
            rolloverSound = None,
            clickSound = None)
        self.btnHost.setTransparency(1)
        self.btnHost.reparentTo(self.frameMain)

        # create a join button
        self.btnJoinPos = Vec3(0, 0, 0)
        self.btnJoinScale = 0.25
        self.btnJoin = DirectButton(
            scale = self.btnJoinScale,
            pos = self.btnJoinPos,
            text = "Join",
            text_scale = 0.8,
            text_pos = (0, -0.2),
            text_fg = (0.82,0.85,0.87,1),
            text_shadow = (0, 0, 0, 1),
            text_shadowOffset = (-0.02, -0.02),
            text_font = defaultFont,
            geom = self.buttonGeom,
            frameColor = (0, 0, 0, 0),
            relief = 0,
            pressEffect = False,
            command = self.join,
            rolloverSound = None,
            clickSound = None)
        self.btnJoin.setTransparency(1)
        self.btnJoin.reparentTo(self.frameMain)

        # create the IP input field
        self.txtIPPos = Vec3(0, 0, -.30)
        self.txtIPScale = 0.25
        self.txtIPWidth = 9
        self.txtIP = DirectEntry(
            # scale and position
            pos = self.txtIPPos,
            scale = self.txtIPScale,
            width = self.txtIPWidth,
            # Text
            entryFont = monospace,
            text_align = TextNode.ACenter,
            text = "",
            text_scale = 0.5,
            text_pos = (0, -0.2),
            text_fg = (0.82,0.85,0.87,1),
            text_shadow = (0, 0, 0, 1),
            text_shadowOffset = (0.04, 0.04),
            initialText = "127.0.0.1",
            numLines = 1,
            # Frame
            geom = self.textboxGeom,
            frameColor = (0, 0, 0, 0),
            relief = 0,
            # Functionality
            command = self.join,
            focusInCommand = self.clearText)
        self.txtIP.reparentTo(self.frameMain)

        # create an exit button
        self.btnExitPos = Vec3(0, 0, -.75)
        self.btnExitScale = 0.25
        self.btnExit = DirectButton(
            scale = self.btnExitScale,
            pos = self.btnExitPos,
            text = "Exit",
            text_scale = 0.8,
            text_pos = (0, -0.2),
            text_fg = (0.82,0.85,0.87,1),
            text_shadow = (0, 0, 0, 1),
            text_shadowOffset = (-0.02, -0.02),
            text_font = defaultFont,
            geom = self.buttonGeom,
            frameColor = (0, 0, 0, 0),
            relief = 0,
            pressEffect = False,
            command = lambda: base.messenger.send("escape"),
            rolloverSound = None,
            clickSound = None)
        self.btnExit.setTransparency(1)
        self.btnExit.reparentTo(self.frameMain)

        # create a mute checkbox
        self.cbVolumeMute = DirectCheckBox(
            # set size
            scale = (0.1, 0.1, 0.1),
            frameSize = (-1, 1, 1, -1),
            # functionality and visuals
            command = self.cbVolumeMute_CheckedChanged,
            isChecked = True,
            checkedImage = "gui/SoundSwitch_off.png",
            uncheckedImage = "gui/SoundSwitch_on.png",
            # mouse behaviour
            relief = 0,
            pressEffect = False,
            rolloverSound = None,
            clickSound = None
            )
        self.cbVolumeMute.setTransparency(1)
        self.cbVolumeMute.reparentTo(self.frameMain)
        self.cbVolumeMute.commandFunc(None)

        # catch window resizes and recalculate the aspectration
        self.accept("window-event", self.recalcAspectRatio)
        self.accept("showerror", self.showError)

        # show the menu right away
        self.show()

    def host(self):
        """Function which will be called by pressing the host button"""
        self.hide()
        base.messenger.send("start_server")

    def join(self, ip=None):
        """Function which will be called by pressing the join button"""
        if ip == None: ip = self.txtIP.get(True)
        if ip == "": return
        self.hide()
        base.messenger.send("start_client", [ip])

    def showError(self, msg):
        self.show()
        self.dialog = OkDialog(
            dialogName="ErrorDialog",
            text="Error: {}".format(msg),
            command=self.closeDialog)

    def closeDialog(self, args):
        self.dialog.hide()

    def show(self):
        """Show the GUI"""
        self.frameMain.show()
        self.menuMusic.play()

    def hide(self):
        """Hide the GUI"""
        self.frameMain.hide()
        self.menuMusic.stop()

    def clearText(self):
        """Function to clear the text that was previously entered in the
        IP input field"""
        self.txtIP.enterText("")

    def cbVolumeMute_CheckedChanged(self, checked):
        if bool(checked):
            base.disableAllAudio()
        else:
            base.enableAllAudio()

    def recalcAspectRatio(self, window):
        """get the new aspect ratio to resize the mainframe"""
        # set the mainframe size to the window borders again
        self.frameMain["frameSize"] = (
            base.a2dLeft, base.a2dRight,
            base.a2dTop, base.a2dBottom)

        # calculate new aspec tratio
        wp = window.getProperties()
        aspX = 1.0
        aspY = 1.0
        wpXSize = wp.getXSize()
        wpYSize = wp.getYSize()
        if wpXSize > wpYSize:
            aspX = wpXSize / float(wpYSize)
        else:
            aspY = wpYSize / float(wpXSize)
        # calculate new position/size/whatever of the gui items
        self.title.setPos(0.0, 0.0, base.a2dTop - self.textscale)
        self.menuBackground.setScale(1.0 * aspX, 1.0, 1.0 * aspY)
        self.cbVolumeMute.setPos(base.a2dRight - 0.15, 0, base.a2dBottom + 0.15)
コード例 #34
0
class FinalScoreGUI:
    notify = directNotify.newCategory('FinalScoreGUI')

    def __init__(self):
        self.finalScoreBg = None
        self.finalScoreTitle = None
        self.finalScoreNameLbl = None
        self.finalScorePointLbl = None
        self.finalScoreContainer = None
        self.finalScores = []
        return

    def load(self):
        font = CIGlobals.getToonFont()
        box = DGG.getDefaultDialogGeom()
        self.finalScoreContainer = DirectFrame()
        self.finalScoreBg = OnscreenImage(image=box, color=(1, 1, 0.75, 1), scale=(1.9,
                                                                                   1.4,
                                                                                   1.4), parent=self.finalScoreContainer)
        self.finalScoreTitle = OnscreenText(text='Waiting for final scores...', pos=(0,
                                                                                     0.5,
                                                                                     0), font=font, scale=0.12, parent=self.finalScoreContainer)
        self.finalScoreNameLbl = OnscreenText(text='', scale=0.095, pos=(-0.85, 0.3,
                                                                         0), font=font, align=TextNode.ALeft, parent=self.finalScoreContainer)
        self.finalScorePointLbl = OnscreenText(text='', scale=0.095, pos=(0.85, 0.3,
                                                                          0), font=font, align=TextNode.ARight, parent=self.finalScoreContainer)
        self.finalScoreContainer.hide()
        self.finalScoreContainer.setBin('gui-popup', 60)
        del font
        del box

    def unload(self):
        if self.finalScoreContainer:
            self.finalScoreContainer.destroy()
            self.finalScoreContainer = None
        if self.finalScoreBg:
            self.finalScoreBg.destroy()
            self.finalScoreBg = None
        if self.finalScoreTitle:
            self.finalScoreTitle.destroy()
            self.finalScoreTitle = None
        if self.finalScoreNameLbl:
            self.finalScoreNameLbl.destroy()
            self.finalScoreNameLbl = None
        if self.finalScorePointLbl:
            self.finalScorePointLbl.destroy()
            self.finalScorePointLbl = None
        return

    def showFinalScores(self):
        self.finalScoreContainer.show()
        base.transitions.fadeScreen(0.5)

    def hideFinalScores(self):
        base.transitions.noTransitions()
        self.finalScoreContainer.hide()

    def handleFinalScores(self, avIdList, scoreList):
        for avId in avIdList:
            score = scoreList[avIdList.index(avId)]
            scoreObj = FinalScore(avId, score)
            self.finalScores.append(scoreObj)

        self.finalScores.sort(key=lambda x: x.score, reverse=True)
        for scoreObj in self.finalScores:
            name = base.cr.doId2do.get(scoreObj.avId).getName()
            self.finalScoreNameLbl['text'] += name + '\n'
            self.finalScorePointLbl['text'] += str(scoreObj.score) + ' Points\n'

        self.finalScoreTitle['text'] = 'Final Scores'
コード例 #35
0
class OptionsMenu():
    def __init__(self):
        self.frameMain = DirectFrame(image="optionsmenu.png",
                                     image_scale=(1.7778, 1, 1),
                                     frameSize=(base.a2dLeft, base.a2dRight,
                                                base.a2dBottom, base.a2dTop),
                                     frameColor=(0, 0, 0, 0))
        self.frameMain.setTransparency(True)

        volume = base.musicManager.getVolume()
        self.sliderMusicVolume = DirectSlider(
            scale=0.5,
            pos=(0, 0, -0.1),
            range=(0, 1),
            scrollSize=0.01,
            text="Music Volume: %d%%" % volume * 100,
            text_scale=0.15,
            text_align=TextNode.ACenter,
            text_pos=(.0, 0.15),
            text_fg=(240 / 255.0, 255 / 255.0, 240 / 255.0, 1),
            thumb_frameColor=(0.8, 0, 1, 0.75),
            thumb_relief=DGG.FLAT,
            frameColor=(0.25, 0.25, 0.55, 1),
            value=volume,
            command=self.sliderMusicVolume_ValueChanged)
        self.sliderMusicVolume.reparentTo(self.frameMain)

        volume = base.sfxManagerList[0].getVolume()
        self.sliderSFXVolume = DirectSlider(
            scale=0.5,
            pos=(0, 0, -0.3),
            range=(0, 1),
            scrollSize=0.01,
            text="SFX Volume: %d%%" % volume * 100,
            text_scale=0.15,
            text_align=TextNode.ACenter,
            text_pos=(.0, 0.15),
            text_fg=(240 / 255.0, 255 / 255.0, 240 / 255.0, 1),
            thumb_frameColor=(0.8, 0, 1, 0.75),
            thumb_relief=DGG.FLAT,
            frameColor=(0.25, 0.25, 0.55, 1),
            value=volume,
            command=self.sliderSFXVolume_ValueChanged)
        self.sliderSFXVolume.reparentTo(self.frameMain)

        isChecked = not base.AppHasAudioFocus
        img = None
        imgON = "AudioSwitch_on.png"
        imgOFF = "AudioSwitch_off.png"
        if base.AppHasAudioFocus:
            img = imgON
        else:
            img = imgOFF
        self.cbVolumeMute = DirectCheckBox(
            scale=0.5,
            text="Mute Audio",
            text_scale=0.15,
            text_align=TextNode.ACenter,
            text_pos=(0.0, 0.15),
            text_fg=(240 / 255.0, 255 / 255.0, 240 / 255.0, 1),
            pos=(0, 0, -0.5),
            command=self.cbVolumeMute_CheckedChanged,
            rolloverSound=None,
            clickSound=None,
            relief=None,
            pressEffect=False,
            isChecked=isChecked,
            image=img,
            image_scale=0.1,
            checkedImage=imgOFF,
            uncheckedImage=imgON)
        self.cbVolumeMute.setTransparency(True)
        self.cbVolumeMute.setImage()
        self.cbVolumeMute.reparentTo(self.frameMain)

        radio = base.loader.loadModel("radioBtn")
        radioGeom = (radio.find("**/RadioButtonReady"),
                     radio.find("**/RadioButtonChecked"))

        self.lblDifficulty = DirectLabel(text="Difficulty",
                                         text_fg=(240 / 255.0, 255 / 255.0,
                                                  240 / 255.0, 1),
                                         text_scale=0.6,
                                         scale=0.15,
                                         frameColor=(0, 0, 0, 0),
                                         pos=(-0.5, 0, -0.6))
        self.lblDifficulty.reparentTo(self.frameMain)
        self.difficulty = [base.difficulty]

        def createDifficultyDRB(self, text, value, initialValue, xPos):
            drb = DirectRadioButton(
                text=text,
                text_fg=(240 / 255.0, 255 / 255.0, 240 / 255.0, 1),
                variable=self.difficulty,
                value=value,
                indicatorValue=initialValue,
                boxGeom=radioGeom,
                boxGeomScale=0.5,
                #indicator_pad = (0.1, 0.1),
                scale=0.05,
                frameColor=(0.5, 0.5, 0.5, 1),
                pressEffect=False,
                relief=1,
                pad=(0.5, 0, 0.5, 0.5),
                pos=(xPos, 0, -0.6),
                command=self.rbDifficulty_ValueChanged)
            drb.indicator.setX(drb.indicator.getX() + 0.1)
            drb.indicator.setZ(drb.indicator.getZ() + 0.1)
            drb.reparentTo(self.frameMain)
            return drb

        self.difficultyButtons = [
            createDifficultyDRB(self, "Easy", [0],
                                1 if base.difficulty == 0 else 0, 0.5 - 0.3),
            createDifficultyDRB(self, "Medium", [1],
                                1 if base.difficulty == 1 else 0, 0.5),
            createDifficultyDRB(self, "Hard", [2],
                                1 if base.difficulty == 2 else 0, 0.5 + 0.3)
        ]
        for button in self.difficultyButtons:
            button.setOthers(self.difficultyButtons)

        self.btnBack = DirectButton(text="Back",
                                    scale=0.15,
                                    text_pos=(-0.3, -0.2),
                                    text_scale=0.6,
                                    text_fg=(240 / 255.0, 255 / 255.0,
                                             240 / 255.0, 1),
                                    frameColor=(0, 0, 0, 0),
                                    image=("btnExit.png", "btnExit_hover.png",
                                           "btnExit_hover.png",
                                           "btnExit_hover.png"),
                                    image_scale=(1, 1, 0.5),
                                    pos=(0, 0, -0.8),
                                    command=base.messenger.send,
                                    extraArgs=["menu_Back"])
        self.btnBack.setTransparency(True)
        self.btnBack.reparentTo(self.frameMain)

        self.hide()

    def show(self):
        self.frameMain.show()

    def hide(self):
        self.frameMain.hide()

    def cbVolumeMute_CheckedChanged(self, checked):
        if checked:
            base.disableAllAudio()
        else:
            base.enableAllAudio()

    def sliderMusicVolume_ValueChanged(self):
        volume = round(self.sliderMusicVolume["value"], 2)
        self.sliderMusicVolume["text"] = "Music Volume: %d%%" % int(
            volume * 100)
        base.musicManager.setVolume(volume)

    def sliderSFXVolume_ValueChanged(self):
        volume = round(self.sliderSFXVolume["value"], 2)
        self.sliderSFXVolume["text"] = "SFX Volume: %d%%" % int(volume * 100)
        base.sfxManagerList[0].setVolume(volume)

    def rbDifficulty_ValueChanged(self):
        base.difficulty = self.difficulty[0]
コード例 #36
0
 def show(self):
     DirectFrame.show(self)
     self._spinIval.loop()
コード例 #37
0
class Pause:
  def __init__(self):
    self.framePause = DirectFrame(
        image = "gui/BackGround.png",
        image_scale = (1.7778, 1, 1),
        frameSize = (base.a2dLeft, base.a2dRight,
                     base.a2dBottom, base.a2dTop),
        frameColor = (0, 0, 0, 0))
    self.framePause.setTransparency(1)

    self.title = DirectLabel(
        scale = 0.15,
        text_align = TextNode.ALeft,
        pos = (-0.2, 0, 0.5),
        frameColor = (0, 0, 0, 0),
        text = "Pause",
        text_fg = (1,1,1,1))
    self.title.setTransparency(1)
    self.title.reparentTo(self.framePause)

    self.btn_continue = self.createButton(
        "Continue",
        -.25,
        ["Pause-Continue"])

    self.btn_option = self.createButton(
        "Option",
        -.40,
        ["Pause-Option"])

    self.btnExit = self.createButton(
       "Back",
        -.55,
        ["Pause-Back"])

    self.hide()

  def createButton(self, text, verticalPos, eventArgs):
        maps = loader.loadModel("gui/button_map")
        btnGeom = (maps.find("**/btn_ready"),
                    maps.find("**/btn_click"),
                    maps.find("**/btn_rollover"),
                    maps.find("**/btn_disabled"))
        btn = DirectButton(
            text = text,
            text_fg = (1,1,1,1),
            text_scale = 0.05,
            text_pos = (0.02, -0.013),
            text_align = TextNode.ACenter,
            scale = 2,
            pos = (0, 0, verticalPos),
            #geom = btnGeom,
            relief = 0,
            frameColor = (0,0,0,0),
            command = base.messenger.send,
            extraArgs = eventArgs,
            pressEffect = False,
            rolloverSound = None,
            clickSound = None)
        btn.reparentTo(self.framePause)

  def show(self):
      self.framePause.show()

  def hide(self):
      self.framePause.hide()
コード例 #38
0
class QuestMap(DirectFrame):
    def __init__(self, av, **kw):
        DirectFrame.__init__(self, relief=None, sortOrder=50)
        self.initialiseoptions(QuestMap)
        self.container = DirectFrame(parent=self, relief=None)
        self.marker = DirectFrame(parent=self.container, relief=None)
        self.cogInfoFrame = DirectFrame(parent=self.container, relief=None)
        cm = CardMaker('bg')
        cm.setFrame(-0.5, 0.5, -0.5, 0.5)
        bg = self.cogInfoFrame.attachNewNode(cm.generate())
        bg.setTransparency(1)
        bg.setColor(0.5, 0.5, 0.5, 0.5)
        bg.setBin('fixed', 0)
        self.cogInfoFrame['geom'] = bg
        self.cogInfoFrame['geom_pos'] = (0, 0, 0)
        self.cogInfoFrame['geom_scale'] = (6, 1, 2)
        self.cogInfoFrame.setScale(0.05)
        self.cogInfoFrame.setPos(0, 0, 0.6)
        self.buildingMarkers = []
        self.av = av
        self.wantToggle = False
        if base.config.GetBool('want-toggle-quest-map', True):
            self.wantToggle = True
        self.updateMarker = True
        self.cornerPosInfo = None
        self.hqPosInfo = None
        self.fishingSpotInfo = None
        self.load()
        self.setScale(1.5)
        bg.removeNode()
        self.hoodId = None
        self.zoneId = None
        self.suitPercentage = {}
        for currHoodInfo in SuitPlannerBase.SuitPlannerBase.SuitHoodInfo:
            tracks = currHoodInfo[
                SuitPlannerBase.SuitPlannerBase.SUIT_HOOD_INFO_TRACK]
            self.suitPercentage[currHoodInfo[
                SuitPlannerBase.SuitPlannerBase.SUIT_HOOD_INFO_ZONE]] = tracks

        return

    def load(self):
        gui = loader.loadModel('phase_4/models/questmap/questmap_gui')
        icon = gui.find('**/tt_t_gui_qst_arrow')
        iconNP = aspect2d.attachNewNode('iconNP')
        icon.reparentTo(iconNP)
        icon.setR(90)
        self.marker['geom'] = iconNP
        self.marker['image'] = iconNP
        self.marker.setScale(0.05)
        iconNP.removeNode()
        self.mapOpenButton = DirectButton(
            image=(gui.find('**/tt_t_gui_qst_mapClose'),
                   gui.find('**/tt_t_gui_qst_mapClose'),
                   gui.find('**/tt_t_gui_qst_mapTryToOpen')),
            relief=None,
            pos=(-0.084, 0, 0.37),
            parent=base.a2dBottomRight,
            scale=0.205,
            command=self.show)
        self.mapCloseButton = DirectButton(
            image=(gui.find('**/tt_t_gui_qst_mapOpen'),
                   gui.find('**/tt_t_gui_qst_mapOpen'),
                   gui.find('**/tt_t_gui_qst_mapTryToClose')),
            relief=None,
            pos=(-0.084, 0, 0.37),
            parent=base.a2dBottomRight,
            scale=0.205,
            command=self.hide)
        self.mapOpenButton.hide()
        self.mapCloseButton.hide()
        gui.removeNode()
        icons = loader.loadModel('phase_3/models/gui/cog_icons')
        cIcon = icons.find('**/CorpIcon')
        lIcon = icons.find('**/LegalIcon')
        mIcon = icons.find('**/MoneyIcon')
        sIcon = icons.find('**/SalesIcon')
        cogInfoTextColor = (0.2, 0.2, 0.2, 1)
        textPos = (1.2, -0.2)
        textScale = 0.8
        self.cInfo = DirectLabel(parent=self.cogInfoFrame,
                                 text='',
                                 text_fg=cogInfoTextColor,
                                 text_pos=textPos,
                                 text_scale=textScale,
                                 geom=cIcon,
                                 geom_pos=(-0.2, 0, 0),
                                 geom_scale=0.8,
                                 relief=None)
        self.cInfo.setPos(-2.2, 0, 0.5)
        self.lInfo = DirectLabel(parent=self.cogInfoFrame,
                                 text_fg=cogInfoTextColor,
                                 text='',
                                 text_pos=textPos,
                                 text_scale=textScale,
                                 geom=lIcon,
                                 geom_pos=(-0.2, 0, 0),
                                 geom_scale=0.8,
                                 relief=None)
        self.lInfo.setPos(-2.2, 0, -0.5)
        self.mInfo = DirectLabel(parent=self.cogInfoFrame,
                                 text_fg=cogInfoTextColor,
                                 text='',
                                 text_pos=textPos,
                                 text_scale=textScale,
                                 geom=mIcon,
                                 geom_pos=(-0.2, 0, 0),
                                 geom_scale=0.8,
                                 relief=None)
        self.mInfo.setPos(0.8, 0, 0.5)
        self.sInfo = DirectLabel(parent=self.cogInfoFrame,
                                 text_fg=cogInfoTextColor,
                                 text='',
                                 text_pos=textPos,
                                 text_scale=textScale,
                                 geom=sIcon,
                                 geom_pos=(-0.2, 0, 0),
                                 geom_scale=0.8,
                                 relief=None)
        self.sInfo.setPos(0.8, 0, -0.5)
        icons.removeNode()
        return

    def updateCogInfo(self):
        currPercentage = self.suitPercentage.get(self.zoneId)
        if currPercentage is None:
            return
        self.cInfo['text'] = '%s%%' % currPercentage[0]
        self.lInfo['text'] = '%s%%' % currPercentage[1]
        self.mInfo['text'] = '%s%%' % currPercentage[2]
        self.sInfo['text'] = '%s%%' % currPercentage[3]
        return

    def destroy(self):
        self.ignore('questPageUpdated')
        self.mapOpenButton.destroy()
        self.mapCloseButton.destroy()
        del self.mapOpenButton
        del self.mapCloseButton
        DirectFrame.destroy(self)

    def putBuildingMarker(self, pos, hpr=(0, 0, 0), mapIndex=None):
        marker = DirectLabel(parent=self.container,
                             text='',
                             text_pos=(-0.05, -0.15),
                             text_fg=(1, 1, 1, 1),
                             relief=None)
        gui = loader.loadModel(
            'phase_4/models/parties/schtickerbookHostingGUI')
        icon = gui.find('**/startPartyButton_inactive')
        iconNP = aspect2d.attachNewNode('iconNP')
        icon.reparentTo(iconNP)
        icon.setX(-12.0792 / 30.48)
        icon.setZ(-9.7404 / 30.48)
        marker['text'] = '%s' % mapIndex
        marker['text_scale'] = 0.7
        marker['image'] = iconNP
        marker['image_color'] = (1, 0, 0, 1)
        marker['image_scale'] = 6
        marker.setScale(0.05)
        relX, relY = self.transformAvPos(pos)
        marker.setPos(relX, 0, relY)
        self.buildingMarkers.append(marker)
        iconNP.removeNode()
        gui.removeNode()
        return

    def updateQuestInfo(self):
        for marker in self.buildingMarkers:
            marker.destroy()

        self.buildingMarkers = []
        dnaStore = base.cr.playGame.dnaStore
        for questIndex in self.av.questPage.quests.keys():
            questDesc = self.av.questPage.quests.get(questIndex)
            if questDesc is None:
                continue
            mapIndex = questIndex + 1
            questId, fromNpcId, toNpcId, rewardId, toonProgress = questDesc
            quest = Quests.getQuest(questId)
            fComplete = quest.getCompletionStatus(self.av,
                                                  questDesc) == Quests.COMPLETE
            if not fComplete:
                if quest.getType() == Quests.RecoverItemQuest:
                    if quest.getHolder() == Quests.AnyFish:
                        self.putBuildingMarker(self.fishingSpotInfo,
                                               mapIndex=mapIndex)
                    continue
                elif quest.getType(
                ) != Quests.DeliverGagQuest and quest.getType(
                ) != Quests.DeliverItemQuest and quest.getType(
                ) != Quests.VisitQuest and quest.getType(
                ) != Quests.TrackChoiceQuest:
                    continue
            if toNpcId == Quests.ToonHQ:
                self.putBuildingMarker(self.hqPosInfo, mapIndex=mapIndex)
            else:
                npcZone = NPCToons.getNPCZone(toNpcId)
                hoodId = ZoneUtil.getCanonicalHoodId(npcZone)
                branchId = ZoneUtil.getCanonicalBranchZone(npcZone)
                if self.hoodId == hoodId and self.zoneId == branchId:
                    for blockIndex in xrange(dnaStore.getNumBlockTitles()):
                        blockNumber = dnaStore.getTitleBlockAt(blockIndex)
                        zone = dnaStore.getZoneFromBlockNumber(blockNumber)
                        branchZone = zone - zone % 100
                        finalZone = branchZone + 500 + blockNumber
                        buildingType = dnaStore.getBlockBuildingType(
                            blockNumber)
                        if npcZone == finalZone:
                            self.putBuildingMarker(
                                dnaStore.getDoorPosHprFromBlockNumber(
                                    blockNumber).getPos(),
                                dnaStore.getDoorPosHprFromBlockNumber(
                                    blockNumber).getHpr(),
                                mapIndex=mapIndex)

        return

    def transformAvPos(self, pos):
        if self.cornerPosInfo is None:
            return (0, 0)
        topRight = self.cornerPosInfo[0]
        bottomLeft = self.cornerPosInfo[1]
        relativeX = (pos.getX() - bottomLeft.getX()) / (
            topRight.getX() - bottomLeft.getX()) - 0.5
        relativeY = (pos.getY() - bottomLeft.getY()) / (
            topRight.getY() - bottomLeft.getY()) - 0.5
        return (relativeX, relativeY)

    def update(self, task):
        if self.av:
            if self.updateMarker:
                relX, relY = self.transformAvPos(self.av.getPos())
                self.marker.setPos(relX, 0, relY)
                self.marker.setHpr(0, 0, -180 - self.av.getH())
        i = 0
        for buildingMarker in self.buildingMarkers:
            buildingMarker.setScale(
                (math.sin(task.time * 16.0 + i * math.pi / 3.0) + 1) * 0.005 +
                0.04)
            i = i + 1

        return Task.cont

    def updateMap(self):
        if self.av:
            try:
                hoodId = ZoneUtil.getCanonicalHoodId(self.av.getLocation()[1])
                zoneId = ZoneUtil.getCanonicalBranchZone(
                    self.av.getLocation()[1])
                mapsGeom = loader.loadModel('phase_4/models/questmap/%s_maps' %
                                            ToontownGlobals.dnaMap[hoodId])
                mapImage = mapsGeom.find(
                    '**/%s_%s_english' %
                    (ToontownGlobals.dnaMap[hoodId], zoneId))
                if not mapImage.isEmpty():
                    self.container['image'] = mapImage
                    self.resetFrameSize()
                    self.cornerPosInfo = QuestMapGlobals.CornerPosTable.get(
                        '%s_%s_english' %
                        (ToontownGlobals.dnaMap[hoodId], zoneId))
                    self.hqPosInfo = QuestMapGlobals.HQPosTable.get(
                        '%s_%s_english' %
                        (ToontownGlobals.dnaMap[hoodId], zoneId))
                    self.fishingSpotInfo = QuestMapGlobals.FishingSpotPosTable.get(
                        '%s_%s_english' %
                        (ToontownGlobals.dnaMap[hoodId], zoneId))
                    self.cogInfoPos = QuestMapGlobals.CogInfoPosTable.get(
                        '%s_%s_english' %
                        (ToontownGlobals.dnaMap[hoodId], zoneId))
                    self.cogInfoFrame.setPos(self.cogInfoPos)
                    self.hide()
                    self.hoodId = hoodId
                    self.zoneId = zoneId
                    self.updateQuestInfo()
                    self.updateCogInfo()
                    taskMgr.add(self.update, 'questMapUpdate')
                else:
                    self.stop()
                mapsGeom.removeNode()
            except:
                self.stop()

    def start(self):
        self.container.show()
        self.accept('questPageUpdated', self.updateMap)
        self.handleMarker()
        self.updateMap()

    def initMarker(self, task):
        if self.av:
            if not hasattr(base.cr.playGame.getPlace(), 'isInterior'
                           ) or not base.cr.playGame.getPlace().isInterior:
                relX, relY = self.transformAvPos(self.av.getPos())
                self.marker.setPos(relX, 0, relY)
                self.marker.setHpr(0, 0, -180 - self.av.getH())
            self.marker['geom_scale'] = 1.4 * task.time % 0.5 * 10 + 1
            self.marker['geom_color'] = (1, 1, 1, 0.8 -
                                         1.4 * task.time % 0.5 * 2 / 0.8 + 0.2)
        if task.time < 1:
            return Task.cont
        else:
            self.marker['geom_color'] = (1, 1, 1, 0)
            return Task.done

    def show(self):
        taskMgr.add(self.initMarker, 'questMapInit')
        DirectFrame.show(self)
        self.mapOpenButton.hide()
        if self.container['image']:
            self.mapCloseButton.show()

    def hide(self):
        taskMgr.remove('questMapInit')
        DirectFrame.hide(self)
        if self.container['image']:
            self.mapOpenButton.show()
        self.mapCloseButton.hide()

    def toggle(self):
        if self.isHidden():
            self.show()
        else:
            self.hide()

    def obscureButton(self):
        self.mapOpenButton.hide()
        self.mapCloseButton.hide()

    def stop(self):
        self.container['image'] = None
        for marker in self.buildingMarkers:
            marker.destroy()

        self.buildingMarkers = []
        self.container.hide()
        self.hide()
        self.obscureButton()
        self.ignore('questPageUpdated')
        taskMgr.remove('questMapUpdate')
        return

    def handleMarker(self):
        if hasattr(base.cr.playGame.getPlace(),
                   'isInterior') and base.cr.playGame.getPlace().isInterior:
            self.updateMarker = False
        else:
            self.updateMarker = True

    def acceptOnscreenHooks(self):
        if self.wantToggle:
            self.accept(ToontownGlobals.MapHotkey, self.toggle)
        else:
            self.accept(ToontownGlobals.MapHotkeyOn, self.show)
            self.accept(ToontownGlobals.MapHotkeyOff, self.hide)
        self.updateMap()

    def ignoreOnscreenHooks(self):
        self.ignore(ToontownGlobals.MapHotkey)
        self.ignore(ToontownGlobals.MapHotkeyOn)
        self.ignore(ToontownGlobals.MapHotkeyOff)
        self.obscureButton()
class CannonGui(DirectObject):
    notify = directNotify.newCategory('CannonGui')
    FIRE_KEY = base.JUMP
    UP_KEY = base.MOVE_UP
    DOWN_KEY = base.MOVE_DOWN
    LEFT_KEY = base.MOVE_LEFT
    RIGHT_KEY = base.MOVE_RIGHT
    FIRE_PRESSED = 'cannongui_fire_pressed'

    def __init__(self):
        self.__loaded = False
        self.leftPressed = 0
        self.rightPressed = 0
        self.upPressed = 0
        self.downPressed = 0
        self.__aimPad = None
        self.__timerPad = None
        return

    def load(self):
        if self.__loaded:
            return
        self.__timerPad = PartyUtils.getNewToontownTimer()
        guiModel = 'phase_4/models/gui/cannon_game_gui'
        guiNode = loader.loadModel(guiModel)
        self.__aimPad = DirectFrame(image=guiNode.find('**/CannonFire_PAD'), relief=None, pos=(0.7, 0, -0.553333), scale=0.8)
        guiNode.removeNode()
        self.fireButton = DirectButton(parent=self.__aimPad, image=((guiModel, '**/Fire_Btn_UP'), (guiModel, '**/Fire_Btn_DN'), (guiModel, '**/Fire_Btn_RLVR')), relief=None, pos=(0.0115741, 0, 0.00505051), scale=1.0, command=self.__firePressed)
        self.upButton = DirectButton(parent=self.__aimPad, image=((guiModel, '**/Cannon_Arrow_UP'), (guiModel, '**/Cannon_Arrow_DN'), (guiModel, '**/Cannon_Arrow_RLVR')), relief=None, pos=(0.0115741, 0, 0.221717))
        self.downButton = DirectButton(parent=self.__aimPad, image=((guiModel, '**/Cannon_Arrow_UP'), (guiModel, '**/Cannon_Arrow_DN'), (guiModel, '**/Cannon_Arrow_RLVR')), relief=None, pos=(0.0136112, 0, -0.210101), image_hpr=(0, 0, 180))
        self.leftButton = DirectButton(parent=self.__aimPad, image=((guiModel, '**/Cannon_Arrow_UP'), (guiModel, '**/Cannon_Arrow_DN'), (guiModel, '**/Cannon_Arrow_RLVR')), relief=None, pos=(-0.199352, 0, -0.000505269), image_hpr=(0, 0, -90))
        self.rightButton = DirectButton(parent=self.__aimPad, image=((guiModel, '**/Cannon_Arrow_UP'), (guiModel, '**/Cannon_Arrow_DN'), (guiModel, '**/Cannon_Arrow_RLVR')), relief=None, pos=(0.219167, 0, -0.00101024), image_hpr=(0, 0, 90))
        self.__aimPad.setColor(1, 1, 1, 0.9)

        def bindButton(button, upHandler, downHandler):
            button.bind(DGG.B1PRESS, lambda x, handler = upHandler: handler())
            button.bind(DGG.B1RELEASE, lambda x, handler = downHandler: handler())

        bindButton(self.upButton, self.__upPressed, self.__upReleased)
        bindButton(self.downButton, self.__downPressed, self.__downReleased)
        bindButton(self.leftButton, self.__leftPressed, self.__leftReleased)
        bindButton(self.rightButton, self.__rightPressed, self.__rightReleased)
        self.__loaded = True
        return

    def unload(self):
        self.ignoreAll()
        if not self.__loaded:
            return
        self.disable()
        self.upButton.unbind(DGG.B1PRESS)
        self.upButton.unbind(DGG.B1RELEASE)
        self.downButton.unbind(DGG.B1PRESS)
        self.downButton.unbind(DGG.B1RELEASE)
        self.leftButton.unbind(DGG.B1PRESS)
        self.leftButton.unbind(DGG.B1RELEASE)
        self.rightButton.unbind(DGG.B1PRESS)
        self.rightButton.unbind(DGG.B1RELEASE)
        self.fireButton.destroy()
        self.__aimPad.destroy()
        del self.__aimPad
        del self.fireButton
        del self.upButton
        del self.downButton
        del self.leftButton
        del self.rightButton
        self.__timerPad.destroy()
        del self.__timerPad
        self.__loaded = False

    def enable(self, timer = 0):
        self.__aimPad.show()
        base.setCellsAvailable([base.bottomCells[3], base.bottomCells[4]], 0)
        base.setCellsAvailable([base.rightCells[1]], 0)
        if timer > 0:
            self.__timerPad.setTime(timer)
            self.__timerPad.countdown(timer)
            self.__timerPad.show()
        self.enableKeys()

    def disable(self):
        self.__aimPad.hide()
        base.setCellsAvailable([base.bottomCells[3], base.bottomCells[4]], 1)
        base.setCellsAvailable([base.rightCells[1]], 1)
        self.__timerPad.hide()
        self.disableKeys()

    def enableKeys(self):
        self.enableAimKeys()
        self.enableFireKey()

    def disableKeys(self):
        self.__aimPad.hide()
        self.disableAimKeys()
        self.disableFireKey()

    def enableAimKeys(self):
        self.leftPressed = 0
        self.rightPressed = 0
        self.upPressed = 0
        self.downPressed = 0
        self.accept(self.UP_KEY, self.__upKeyPressed)
        self.accept(self.DOWN_KEY, self.__downKeyPressed)
        self.accept(self.LEFT_KEY, self.__leftKeyPressed)
        self.accept(self.RIGHT_KEY, self.__rightKeyPressed)

    def disableAimKeys(self):
        self.ignore(self.UP_KEY)
        self.ignore(self.DOWN_KEY)
        self.ignore(self.LEFT_KEY)
        self.ignore(self.RIGHT_KEY)
        messenger.send(self.UP_KEY + '-up')
        messenger.send(self.DOWN_KEY + '-up')
        messenger.send(self.LEFT_KEY + '-up')
        messenger.send(self.RIGHT_KEY + '-up')
        self.ignore(self.UP_KEY + '-up')
        self.ignore(self.DOWN_KEY + '-up')
        self.ignore(self.LEFT_KEY + '-up')
        self.ignore(self.RIGHT_KEY + '-up')

    def enableFireKey(self):
        self.accept(self.FIRE_KEY, self.__fireKeyPressed)

    def disableFireKey(self):
        self.ignore(self.FIRE_KEY)
        self.ignore(self.FIRE_KEY + '-up')

    def __fireKeyPressed(self):
        self.ignore(self.FIRE_KEY)
        self.accept(self.FIRE_KEY + '-up', self.__fireKeyReleased)
        self.__firePressed()

    def __upKeyPressed(self):
        self.ignore(self.UP_KEY)
        self.accept(self.UP_KEY + '-up', self.__upKeyReleased)
        self.__upPressed()

    def __downKeyPressed(self):
        self.ignore(self.DOWN_KEY)
        self.accept(self.DOWN_KEY + '-up', self.__downKeyReleased)
        self.__downPressed()

    def __leftKeyPressed(self):
        self.ignore(self.LEFT_KEY)
        self.accept(self.LEFT_KEY + '-up', self.__leftKeyReleased)
        self.__leftPressed()

    def __rightKeyPressed(self):
        self.ignore(self.RIGHT_KEY)
        self.accept(self.RIGHT_KEY + '-up', self.__rightKeyReleased)
        self.__rightPressed()

    def __fireKeyReleased(self):
        self.ignore(self.FIRE_KEY + '-up')
        self.accept(self.FIRE_KEY, self.__fireKeyPressed)

    def __leftKeyReleased(self):
        self.ignore(self.LEFT_KEY + '-up')
        self.accept(self.LEFT_KEY, self.__leftKeyPressed)
        self.__leftReleased()

    def __rightKeyReleased(self):
        self.ignore(self.RIGHT_KEY + '-up')
        self.accept(self.RIGHT_KEY, self.__rightKeyPressed)
        self.__rightReleased()

    def __upKeyReleased(self):
        self.ignore(self.UP_KEY + '-up')
        self.accept(self.UP_KEY, self.__upKeyPressed)
        self.__upReleased()

    def __downKeyReleased(self):
        self.ignore(self.DOWN_KEY + '-up')
        self.accept(self.DOWN_KEY, self.__downKeyPressed)
        self.__downReleased()

    def __upPressed(self):
        self.notify.debug('up pressed')
        self.upPressed = self.__enterControlActive(self.upPressed)

    def __downPressed(self):
        self.notify.debug('down pressed')
        self.downPressed = self.__enterControlActive(self.downPressed)

    def __leftPressed(self):
        self.notify.debug('left pressed')
        self.leftPressed = self.__enterControlActive(self.leftPressed)

    def __rightPressed(self):
        self.notify.debug('right pressed')
        self.rightPressed = self.__enterControlActive(self.rightPressed)

    def __upReleased(self):
        self.notify.debug('up released')
        self.upPressed = self.__exitControlActive(self.upPressed)

    def __downReleased(self):
        self.notify.debug('down released')
        self.downPressed = self.__exitControlActive(self.downPressed)

    def __leftReleased(self):
        self.notify.debug('left released')
        self.leftPressed = self.__exitControlActive(self.leftPressed)

    def __rightReleased(self):
        self.notify.debug('right released')
        self.rightPressed = self.__exitControlActive(self.rightPressed)

    def __firePressed(self):
        self.notify.debug('fire pressed')
        messenger.send(CannonGui.FIRE_PRESSED)

    def __enterControlActive(self, control):
        return control + 1

    def __exitControlActive(self, control):
        return max(0, control - 1)
コード例 #40
0
ファイル: optionsmenu.py プロジェクト: grimfang/pyweek21
class Optionsmenu():
    def __init__(self):
        self.frameMain = DirectFrame(
            image="gui/MenuBackground.png",
            image_scale=(1.7778, 1, 1),
            #image_pos=(0, 0, 0.25),
            frameSize=(
                base.a2dLeft, base.a2dRight,
                base.a2dTop, base.a2dBottom),
            frameColor=(0,0,0,0))
        self.frameMain.setTransparency(True)

        self.logo = DirectFrame(
            image="Logo.png",
            image_scale=0.25,
            image_pos=(0, 0, 0.55),
            frameSize=(
                base.a2dLeft, base.a2dRight,
                base.a2dTop, base.a2dBottom),
            frameColor=(0,0,0,0))
        self.logo.reparentTo(self.frameMain)


        btnGeom = "gui/button"

        self.btnBack = menuHelper.createButton(_("Back"), btnGeom, 0, -0.7, ["options_back"])
        self.btnBack.reparentTo(self.frameMain)


        volume = base.musicManager.getVolume()
        self.sliderVolume = DirectSlider(
            scale=0.5,
            pos=(-0.5, 0, 0),
            range=(0, 1),
            scrollSize=0.01,
            text=_("Volume %d%%") % volume*100,
            text_scale=0.1,
            text_pos=(0, 0.15),
            text_fg=(1, 1, 1, 1),
            thumb_frameColor=(0,0.75, 0.25, 1),
            frameColor=(0.35, 0.15, 0.05, 1),
            value=volume,
            command=self.sliderVolume_ValueChanged)
        self.sliderVolume.reparentTo(self.frameMain)

        isChecked = not base.AppHasAudioFocus
        img = None
        imgON = "gui/AudioSwitch_on.png"
        imgOFF = "gui/AudioSwitch_off.png"
        if base.AppHasAudioFocus:
            img = imgON
        else:
            img = imgOFF
        self.cbVolumeMute = DirectCheckBox(
            text=_("Mute Audio"),
            text_scale=0.5,
            text_align=TextNode.ACenter,
            text_pos=(0, 0.65),
            text_fg=(1, 1, 1, 1),
            scale=0.105,
            pos=(0.5, 0, 0),
            command=self.cbVolumeMute_CheckedChanged,
            relief=None,
            pressEffect=False,
            isChecked=isChecked,
            image=img,
            image_scale=0.5,
            checkedImage=imgOFF,
            uncheckedImage=imgON)
        self.cbVolumeMute.setTransparency(True)
        self.cbVolumeMute.setImage()
        self.cbVolumeMute.reparentTo(self.frameMain)

        prcPath = os.path.join(basedir, "%s.prc"%appName)
        self.advancedOptions = DirectLabel(
            text=_("Advanced options can be made in the following text file\n%s")%prcPath,
            text_scale=0.5,
            text_fg=(1, 1, 1, 1),
            scale=0.1,
            pos=(0, 0, -0.25),
            frameColor=(0, 0, 0, 0))
        self.advancedOptions.setTransparency(True)
        self.advancedOptions.reparentTo(self.frameMain)

        self.hide()

    def show(self):
        self.frameMain.show()

    def hide(self):
        self.frameMain.hide()

    def cbVolumeMute_CheckedChanged(self, checked):
        if checked:
            base.disableAllAudio()
        else:
            base.enableAllAudio()

    def sliderVolume_ValueChanged(self):
        volume = round(self.sliderVolume["value"], 2)
        self.sliderVolume["text"] = _("Volume %d%%") % int(volume * 100)
        base.sfxManagerList[0].setVolume(volume)
        base.musicManager.setVolume(volume)
コード例 #41
0
ファイル: craftingGui.py プロジェクト: PlumpMath/OWP_Miner
class CraftInventory(DirectObject):
    def __init__(self):
        self.itemFrame = DirectScrolledFrame(
            text="Inventory",
            text_scale=0.25,
            text_pos=(0, 0.75, 0),
            text_bg=(1, 1, 1, 1),
            # make the frame occupy the whole window
            frameSize=(-0.6, 0.6, -0.8, 0.8),
            pos=(-0.7, 0, 0),
            # make the canvas as big as the frame
            canvasSize=(-0.6, 0.6, -0.8, 0.8),
            # set the frames color to white
            frameColor=(1, 1, 1, 1))
        self.itemList = []

        self.craftFrame = DirectFrame(
            text="Crafting",
            text_scale=0.25,
            text_pos=(0, 0.75, 0),
            text_bg=(1, 1, 1, 1),
            # make the frame occupy the whole window
            frameSize=(-0.6, 0.6, -0.8, 0.8),
            pos=(0.7, 0, 0),
            # set the frames color to white
            frameColor=(1, 1, 1, 1))
        self.craftDrop = DirectFrame(text="drop ore",
                                     text_scale=0.1,
                                     pos=(0, 0.4, 0),
                                     frameSize=(-0.25, 0.25, -0.25, 0.25),
                                     frameColor=(1, 0, 0, 1))
        self.craftDrop.reparentTo(self.craftFrame)

    def show(self):
        self.itemFrame.show()
        self.craftFrame.show()

    def hide(self):
        self.itemFrame.hide()
        self.craftFrame.hide()

    def __makeItem(self, item):
        obj = DirectLabel(
            text=str(item.giveLoot()) + "x " + item.giveType(),
            text_scale=0.5,
            text_pos=(0, -1, 0),
            image=("item.png", "item_hover.png",
                   "item.png"),  #normal, hover, disabled
            scale=0.16,
            numStates=2,
            state=DGG.NORMAL,
            relief=DGG.GROOVE)
        obj.setTransparency(True)
        obj["activeState"] = 0
        obj.reparentTo(self.itemFrame.getCanvas())
        obj.bind(DGG.B1PRESS, self.dragStart, [obj])
        obj.bind(DGG.B1RELEASE, self.dragStop)
        obj.bind(DGG.ENTER, self.inObject, [obj])
        obj.bind(DGG.EXIT, self.outObject, [obj])
        return obj

    def updateList(self, items):
        for item in self.itemList:
            item.destroy()
        i = 1
        j = 0
        pad = 0.2
        numItemsPerRow = 2
        itemWidth = 0.32
        itemHeight = 0.32
        #left = -(itemWidth * (numItemsPerRow/2.0)) - 0.16
        left = self.itemFrame.getX()  # + (itemWidth + 0.16)
        xStep = itemWidth + 0.13
        yStep = -(itemHeight + 0.13)
        top = 0.8 - (0.16 + pad)
        for item in items:
            self.itemList.append(self.__makeItem(item))
            x = left + i * xStep
            y = top + j * yStep
            self.itemList[-1].setPos(x, 0.0, y)
            if i == numItemsPerRow:
                i = 0
                j += 1
            i += 1
        if i == 1: j -= 1
        height = ((j) * -yStep) - 0.16
        # resize the canvas. This will make the scrollbars dis-/appear,
        # dependent on if the canvas is bigger than the frame size.
        self.itemFrame["canvasSize"] = (-0.6, 0.6, -height, 0.8)

    def inObject(self, element, event):
        # Can be used to highlight objects
        element["activeState"] = 1
        element.setActiveState()
        #print "over object"

    def outObject(self, element, event):
        # Can be used to unhighlight objects
        #element["state"] = 0
        element["activeState"] = 0
        element.setActiveState()

    def dragStart(self, element, event):
        print "start drag"
        taskMgr.remove('dragDropTask')
        vWidget2render2d = element.getPos(render2d)
        vMouse2render2d = Point3(event.getMouse()[0], 0, event.getMouse()[1])
        editVec = Vec3(vWidget2render2d - vMouse2render2d)
        t = taskMgr.add(self.dragTask, 'dragDropTask')
        element.reparentTo(aspect2d)
        t.element = element
        t.editVec = editVec
        t.elementStartPos = element.getPos()

    def dragTask(self, state):
        mwn = base.mouseWatcherNode
        if mwn.hasMouse():
            vMouse2render2d = Point3(mwn.getMouse()[0], 0, mwn.getMouse()[1])
            newPos = vMouse2render2d + state.editVec
            state.element.setPos(render2d, newPos)
        return Task.cont

    def dragStop(self, event):
        print "stop drag with:", event
        isInArea = False

        t = taskMgr.getTasksNamed('dragDropTask')[0]
        #for dropArea in self.dropAreas:
        #    if self.isInBounds(event.getMouse(), dropArea["frameSize"], dropArea.getPos(render)):
        #        print "inside Area:", dropArea["text"], dropArea.getPos(render)
        #        isInArea = True
        #        t.element.setPos(dropArea.getPos(render))
        #        t.element.setX(t.element.getX() * self.ratio)
        #        #t.element.setX(t.element.getX() - t.element.getWidth() / 2.0)
        #        break

        if not isInArea:
            t.element.setPos(t.elementStartPos)
            t.element.reparentTo(self.itemFrame.getCanvas())
        taskMgr.remove('dragDropTask')

    def isInBounds(self, location, bounds, posShift=None):
        x = 0 if posShift is None else posShift.getX()
        y = 0 if posShift is None else posShift.getZ()

        left = x + bounds[0]
        right = x + bounds[1]
        bottom = y + bounds[2]
        top = y + bounds[3]

        # are we outside of the bounding box from the left
        if location[0] < left: return False
        # are we outside of the bounding box from the right
        if location[0] > right: return False
        # are we outside of the bounding box from the bottom
        if location[1] < bottom: return False
        # are we outside of the bounding box from the top
        if location[1] > top: return False
        # the location is inside the bbox
        return True
コード例 #42
0
class CannonGui(DirectObject):
    notify = directNotify.newCategory('CannonGui')
    FIRE_KEY = 'control'
    UP_KEY = 'arrow_up'
    DOWN_KEY = 'arrow_down'
    LEFT_KEY = 'arrow_left'
    RIGHT_KEY = 'arrow_right'
    FIRE_PRESSED = 'cannongui_fire_pressed'

    def __init__(self):
        self.__loaded = False
        self.leftPressed = 0
        self.rightPressed = 0
        self.upPressed = 0
        self.downPressed = 0
        self.__aimPad = None
        self.__timerPad = None
        return

    def load(self):
        if self.__loaded:
            return
        self.__timerPad = PartyUtils.getNewToontownTimer()
        guiModel = 'phase_4/models/gui/cannon_game_gui'
        guiNode = loader.loadModel(guiModel)
        self.__aimPad = DirectFrame(image=guiNode.find('**/CannonFire_PAD'), relief=None, pos=(0.7, 0, -0.553333), scale=0.8)
        guiNode.removeNode()
        self.fireButton = DirectButton(parent=self.__aimPad, image=((guiModel, '**/Fire_Btn_UP'), (guiModel, '**/Fire_Btn_DN'), (guiModel, '**/Fire_Btn_RLVR')), relief=None, pos=(0.0115741, 0, 0.00505051), scale=1.0, command=self.__firePressed)
        self.upButton = DirectButton(parent=self.__aimPad, image=((guiModel, '**/Cannon_Arrow_UP'), (guiModel, '**/Cannon_Arrow_DN'), (guiModel, '**/Cannon_Arrow_RLVR')), relief=None, pos=(0.0115741, 0, 0.221717))
        self.downButton = DirectButton(parent=self.__aimPad, image=((guiModel, '**/Cannon_Arrow_UP'), (guiModel, '**/Cannon_Arrow_DN'), (guiModel, '**/Cannon_Arrow_RLVR')), relief=None, pos=(0.0136112, 0, -0.210101), image_hpr=(0, 0, 180))
        self.leftButton = DirectButton(parent=self.__aimPad, image=((guiModel, '**/Cannon_Arrow_UP'), (guiModel, '**/Cannon_Arrow_DN'), (guiModel, '**/Cannon_Arrow_RLVR')), relief=None, pos=(-0.199352, 0, -0.000505269), image_hpr=(0, 0, -90))
        self.rightButton = DirectButton(parent=self.__aimPad, image=((guiModel, '**/Cannon_Arrow_UP'), (guiModel, '**/Cannon_Arrow_DN'), (guiModel, '**/Cannon_Arrow_RLVR')), relief=None, pos=(0.219167, 0, -0.00101024), image_hpr=(0, 0, 90))
        self.__aimPad.setColor(1, 1, 1, 0.9)

        def bindButton(button, upHandler, downHandler):
            button.bind(DGG.B1PRESS, lambda x, handler = upHandler: handler())
            button.bind(DGG.B1RELEASE, lambda x, handler = downHandler: handler())

        bindButton(self.upButton, self.__upPressed, self.__upReleased)
        bindButton(self.downButton, self.__downPressed, self.__downReleased)
        bindButton(self.leftButton, self.__leftPressed, self.__leftReleased)
        bindButton(self.rightButton, self.__rightPressed, self.__rightReleased)
        self.__loaded = True
        return

    def unload(self):
        self.ignoreAll()
        if not self.__loaded:
            return
        self.disable()
        self.upButton.unbind(DGG.B1PRESS)
        self.upButton.unbind(DGG.B1RELEASE)
        self.downButton.unbind(DGG.B1PRESS)
        self.downButton.unbind(DGG.B1RELEASE)
        self.leftButton.unbind(DGG.B1PRESS)
        self.leftButton.unbind(DGG.B1RELEASE)
        self.rightButton.unbind(DGG.B1PRESS)
        self.rightButton.unbind(DGG.B1RELEASE)
        self.fireButton.destroy()
        self.__aimPad.destroy()
        del self.__aimPad
        del self.fireButton
        del self.upButton
        del self.downButton
        del self.leftButton
        del self.rightButton
        self.__timerPad.destroy()
        del self.__timerPad
        self.__loaded = False

    def enable(self, timer = 0):
        self.__aimPad.show()
        base.setCellsAvailable([base.bottomCells[3], base.bottomCells[4]], 0)
        base.setCellsAvailable([base.rightCells[1]], 0)
        if timer > 0:
            self.__timerPad.setTime(timer)
            self.__timerPad.countdown(timer)
            self.__timerPad.show()
        self.enableKeys()

    def disable(self):
        self.__aimPad.hide()
        base.setCellsAvailable([base.bottomCells[3], base.bottomCells[4]], 1)
        base.setCellsAvailable([base.rightCells[1]], 1)
        self.__timerPad.hide()
        self.disableKeys()

    def enableKeys(self):
        self.enableAimKeys()
        self.enableFireKey()

    def disableKeys(self):
        self.__aimPad.hide()
        self.disableAimKeys()
        self.disableFireKey()

    def enableAimKeys(self):
        self.leftPressed = 0
        self.rightPressed = 0
        self.upPressed = 0
        self.downPressed = 0
        self.accept(self.UP_KEY, self.__upKeyPressed)
        self.accept(self.DOWN_KEY, self.__downKeyPressed)
        self.accept(self.LEFT_KEY, self.__leftKeyPressed)
        self.accept(self.RIGHT_KEY, self.__rightKeyPressed)

    def disableAimKeys(self):
        self.ignore(self.UP_KEY)
        self.ignore(self.DOWN_KEY)
        self.ignore(self.LEFT_KEY)
        self.ignore(self.RIGHT_KEY)
        messenger.send(self.UP_KEY + '-up')
        messenger.send(self.DOWN_KEY + '-up')
        messenger.send(self.LEFT_KEY + '-up')
        messenger.send(self.RIGHT_KEY + '-up')
        self.ignore(self.UP_KEY + '-up')
        self.ignore(self.DOWN_KEY + '-up')
        self.ignore(self.LEFT_KEY + '-up')
        self.ignore(self.RIGHT_KEY + '-up')

    def enableFireKey(self):
        self.accept(self.FIRE_KEY, self.__fireKeyPressed)

    def disableFireKey(self):
        self.ignore(self.FIRE_KEY)
        self.ignore(self.FIRE_KEY + '-up')

    def __fireKeyPressed(self):
        self.ignore(self.FIRE_KEY)
        self.accept(self.FIRE_KEY + '-up', self.__fireKeyReleased)
        self.__firePressed()

    def __upKeyPressed(self):
        self.ignore(self.UP_KEY)
        self.accept(self.UP_KEY + '-up', self.__upKeyReleased)
        self.__upPressed()

    def __downKeyPressed(self):
        self.ignore(self.DOWN_KEY)
        self.accept(self.DOWN_KEY + '-up', self.__downKeyReleased)
        self.__downPressed()

    def __leftKeyPressed(self):
        self.ignore(self.LEFT_KEY)
        self.accept(self.LEFT_KEY + '-up', self.__leftKeyReleased)
        self.__leftPressed()

    def __rightKeyPressed(self):
        self.ignore(self.RIGHT_KEY)
        self.accept(self.RIGHT_KEY + '-up', self.__rightKeyReleased)
        self.__rightPressed()

    def __fireKeyReleased(self):
        self.ignore(self.FIRE_KEY + '-up')
        self.accept(self.FIRE_KEY, self.__fireKeyPressed)

    def __leftKeyReleased(self):
        self.ignore(self.LEFT_KEY + '-up')
        self.accept(self.LEFT_KEY, self.__leftKeyPressed)
        self.__leftReleased()

    def __rightKeyReleased(self):
        self.ignore(self.RIGHT_KEY + '-up')
        self.accept(self.RIGHT_KEY, self.__rightKeyPressed)
        self.__rightReleased()

    def __upKeyReleased(self):
        self.ignore(self.UP_KEY + '-up')
        self.accept(self.UP_KEY, self.__upKeyPressed)
        self.__upReleased()

    def __downKeyReleased(self):
        self.ignore(self.DOWN_KEY + '-up')
        self.accept(self.DOWN_KEY, self.__downKeyPressed)
        self.__downReleased()

    def __upPressed(self):
        self.notify.debug('up pressed')
        self.upPressed = self.__enterControlActive(self.upPressed)

    def __downPressed(self):
        self.notify.debug('down pressed')
        self.downPressed = self.__enterControlActive(self.downPressed)

    def __leftPressed(self):
        self.notify.debug('left pressed')
        self.leftPressed = self.__enterControlActive(self.leftPressed)

    def __rightPressed(self):
        self.notify.debug('right pressed')
        self.rightPressed = self.__enterControlActive(self.rightPressed)

    def __upReleased(self):
        self.notify.debug('up released')
        self.upPressed = self.__exitControlActive(self.upPressed)

    def __downReleased(self):
        self.notify.debug('down released')
        self.downPressed = self.__exitControlActive(self.downPressed)

    def __leftReleased(self):
        self.notify.debug('left released')
        self.leftPressed = self.__exitControlActive(self.leftPressed)

    def __rightReleased(self):
        self.notify.debug('right released')
        self.rightPressed = self.__exitControlActive(self.rightPressed)

    def __firePressed(self):
        self.notify.debug('fire pressed')
        messenger.send(CannonGui.FIRE_PRESSED)

    def __enterControlActive(self, control):
        return control + 1

    def __exitControlActive(self, control):
        return max(0, control - 1)
コード例 #43
0
ファイル: QuestMap.py プロジェクト: CalebSmith376/src
class QuestMap(DirectFrame):

    def __init__(self, av, **kw):
        DirectFrame.__init__(self, relief=None, sortOrder=50)
        self.initialiseoptions(QuestMap)
        self.container = DirectFrame(parent=self, relief=None)
        self.marker = DirectFrame(parent=self.container, relief=None)
        self.cogInfoFrame = DirectFrame(parent=self.container, relief=None)
        cm = CardMaker('bg')
        cm.setFrame(-0.5, 0.5, -0.5, 0.5)
        bg = self.cogInfoFrame.attachNewNode(cm.generate())
        bg.setTransparency(1)
        bg.setColor(0.5, 0.5, 0.5, 0.5)
        bg.setBin('fixed', 0)
        self.cogInfoFrame['geom'] = bg
        self.cogInfoFrame['geom_pos'] = (0, 0, 0)
        self.cogInfoFrame['geom_scale'] = (6, 1, 2)
        self.cogInfoFrame.setScale(0.05)
        self.cogInfoFrame.setPos(0, 0, 0.6)
        self.buildingMarkers = []
        self.av = av
        self.wantToggle = False
        if base.config.GetBool('want-toggle-quest-map', True):
            self.wantToggle = True
        self.updateMarker = True
        self.cornerPosInfo = None
        self.hqPosInfo = None
        self.fishingSpotInfo = None
        self.load()
        self.setScale(1.5)
        bg.removeNode()
        self.hoodId = None
        self.zoneId = None
        self.suitPercentage = {}
        for currHoodInfo in SuitPlannerBase.SuitPlannerBase.SuitHoodInfo:
            tracks = currHoodInfo[SuitPlannerBase.SuitPlannerBase.SUIT_HOOD_INFO_TRACK]
            self.suitPercentage[currHoodInfo[SuitPlannerBase.SuitPlannerBase.SUIT_HOOD_INFO_ZONE]] = tracks

        return

    def load(self):
        gui = loader.loadModel('phase_4/models/questmap/questmap_gui')
        icon = gui.find('**/tt_t_gui_qst_arrow')
        iconNP = aspect2d.attachNewNode('iconNP')
        icon.reparentTo(iconNP)
        icon.setR(90)
        self.marker['geom'] = iconNP
        self.marker['image'] = iconNP
        self.marker.setScale(0.05)
        iconNP.removeNode()
        self.mapOpenButton = DirectButton(image=(gui.find('**/tt_t_gui_qst_mapClose'), gui.find('**/tt_t_gui_qst_mapClose'), gui.find('**/tt_t_gui_qst_mapTryToOpen')), relief=None, pos=(-0.08, 0, 0.37), parent=base.a2dBottomRight, scale=0.205, command=self.show)
        self.mapCloseButton = DirectButton(image=(gui.find('**/tt_t_gui_qst_mapOpen'), gui.find('**/tt_t_gui_qst_mapOpen'), gui.find('**/tt_t_gui_qst_mapTryToClose')), relief=None, pos=(-0.08, 0, 0.37), parent=base.a2dBottomRight, scale=0.205, command=self.hide)
        self.mapOpenButton.hide()
        self.mapCloseButton.hide()
        gui.removeNode()
        icons = loader.loadModel('phase_3/models/gui/cog_icons')
        cIcon = icons.find('**/CorpIcon')
        lIcon = icons.find('**/LegalIcon')
        mIcon = icons.find('**/MoneyIcon')
        sIcon = icons.find('**/SalesIcon')
        cogInfoTextColor = (0.2, 0.2, 0.2, 1)
        textPos = (1.2, -0.2)
        textScale = 0.8
        self.cInfo = DirectLabel(parent=self.cogInfoFrame, text='', text_fg=cogInfoTextColor, text_pos=textPos, text_scale=textScale, geom=cIcon, geom_pos=(-0.2, 0, 0), geom_scale=0.8, relief=None)
        self.cInfo.setPos(-2.2, 0, 0.5)
        self.lInfo = DirectLabel(parent=self.cogInfoFrame, text_fg=cogInfoTextColor, text='', text_pos=textPos, text_scale=textScale, geom=lIcon, geom_pos=(-0.2, 0, 0), geom_scale=0.8, relief=None)
        self.lInfo.setPos(-2.2, 0, -0.5)
        self.mInfo = DirectLabel(parent=self.cogInfoFrame, text_fg=cogInfoTextColor, text='', text_pos=textPos, text_scale=textScale, geom=mIcon, geom_pos=(-0.2, 0, 0), geom_scale=0.8, relief=None)
        self.mInfo.setPos(0.8, 0, 0.5)
        self.sInfo = DirectLabel(parent=self.cogInfoFrame, text_fg=cogInfoTextColor, text='', text_pos=textPos, text_scale=textScale, geom=sIcon, geom_pos=(-0.2, 0, 0), geom_scale=0.8, relief=None)
        self.sInfo.setPos(0.8, 0, -0.5)
        icons.removeNode()
        return

    def updateCogInfo(self):
        currPercentage = self.suitPercentage.get(self.zoneId)
        if currPercentage is None:
            return
        self.cInfo['text'] = '%s%%' % currPercentage[0]
        self.lInfo['text'] = '%s%%' % currPercentage[1]
        self.mInfo['text'] = '%s%%' % currPercentage[2]
        self.sInfo['text'] = '%s%%' % currPercentage[3]
        return

    def destroy(self):
        self.ignore('questPageUpdated')
        self.mapOpenButton.destroy()
        self.mapCloseButton.destroy()
        del self.mapOpenButton
        del self.mapCloseButton
        DirectFrame.destroy(self)

    def putBuildingMarker(self, pos, hpr = (0, 0, 0), mapIndex = None):
        marker = DirectLabel(parent=self.container, text='', text_pos=(-0.05, -0.15), text_fg=(1, 1, 1, 1), relief=None)
        gui = loader.loadModel('phase_4/models/parties/schtickerbookHostingGUI')
        icon = gui.find('**/startPartyButton_inactive')
        iconNP = aspect2d.attachNewNode('iconNP')
        icon.reparentTo(iconNP)
        icon.setX(-12.0792 / 30.48)
        icon.setZ(-9.7404 / 30.48)
        marker['text'] = '%s' % mapIndex
        marker['text_scale'] = 0.7
        marker['image'] = iconNP
        marker['image_color'] = (1, 0, 0, 1)
        marker['image_scale'] = 6
        marker.setScale(0.05)
        relX, relY = self.transformAvPos(pos)
        marker.setPos(relX, 0, relY)
        self.buildingMarkers.append(marker)
        iconNP.removeNode()
        gui.removeNode()
        return

    def updateQuestInfo(self):
        for marker in self.buildingMarkers:
            marker.destroy()

        self.buildingMarkers = []

        for (i, questDesc) in enumerate(self.av.quests):
            mapIndex = i + 1
            quest = Quests.getQuest(questDesc[0])
            toNpcId = questDesc[2]

            completed = quest.getCompletionStatus(self.av, questDesc) == Quests.COMPLETE
            if not completed:
                if quest.getType() == Quests.RecoverItemQuest:
                    if quest.getHolder() == Quests.AnyFish:
                        self.putBuildingMarker(self.fishingSpotInfo, mapIndex=mapIndex)
                    continue
                elif quest.getType() not in (
                    Quests.DeliverGagQuest, Quests.DeliverItemQuest,
                    Quests.VisitQuest, Quests.TrackChoiceQuest):
                    continue

            if toNpcId == Quests.ToonHQ:
                self.putBuildingMarker(self.hqPosInfo, mapIndex=mapIndex)
                continue

            npcZoneId = NPCToons.getNPCZone(toNpcId)
            hoodId = ZoneUtil.getCanonicalHoodId(npcZoneId)
            branchId = ZoneUtil.getCanonicalBranchZone(npcZoneId)

            if (self.hoodId != hoodId) or (self.zoneId != branchId):
                continue

            for blockIndex in xrange(base.cr.playGame.dnaStore.getNumBlockNumbers()):
                blockNumber = base.cr.playGame.dnaStore.getBlockNumberAt(blockIndex)
                zoneId = base.cr.playGame.dnaStore.getZoneFromBlockNumber(blockNumber)
                interiorZoneId = (zoneId - (zoneId%100)) + 500 + blockNumber
                if npcZoneId == interiorZoneId:
                    self.putBuildingMarker(
                        base.cr.playGame.dnaStore.getDoorPosHprFromBlockNumber(blockNumber).getPos(render),
                        base.cr.playGame.dnaStore.getDoorPosHprFromBlockNumber(blockNumber).getHpr(render),
                        mapIndex=mapIndex)

    def transformAvPos(self, pos):
        if self.cornerPosInfo is None:
            return (0, 0)
        topRight = self.cornerPosInfo[0]
        bottomLeft = self.cornerPosInfo[1]
        relativeX = (pos.getX() - bottomLeft.getX()) / (topRight.getX() - bottomLeft.getX()) - 0.5
        relativeY = (pos.getY() - bottomLeft.getY()) / (topRight.getY() - bottomLeft.getY()) - 0.5
        return (relativeX, relativeY)

    def update(self, task):
        if self.av:
            if self.updateMarker:
                relX, relY = self.transformAvPos(self.av.getPos())
                self.marker.setPos(relX, 0, relY)
                self.marker.setHpr(0, 0, -180 - self.av.getH())
        i = 0
        for buildingMarker in self.buildingMarkers:
            buildingMarker.setScale((math.sin(task.time * 16.0 + i * math.pi / 3.0) + 1) * 0.005 + 0.04)
            i = i + 1

        return Task.cont

    def updateMap(self):
        if self.av:
            hoodId = ZoneUtil.getCanonicalHoodId(self.av.getLocation()[1])
            zoneId = ZoneUtil.getCanonicalBranchZone(self.av.getLocation()[1])
            try:
                mapsGeom = loader.loadModel('phase_4/models/questmap/%s_maps' % ToontownGlobals.dnaMap[hoodId])
            except:
                self.stop()
                return
            mapImage = mapsGeom.find('**/%s_%s_english' % (ToontownGlobals.dnaMap[hoodId], zoneId))
            if not mapImage.isEmpty():
                self.container['image'] = mapImage
                self.resetFrameSize()
                self.cornerPosInfo = QuestMapGlobals.CornerPosTable.get('%s_%s_english' % (ToontownGlobals.dnaMap[hoodId], zoneId))
                self.hqPosInfo = QuestMapGlobals.HQPosTable.get('%s_%s_english' % (ToontownGlobals.dnaMap[hoodId], zoneId))
                self.fishingSpotInfo = QuestMapGlobals.FishingSpotPosTable.get('%s_%s_english' % (ToontownGlobals.dnaMap[hoodId], zoneId))
                self.cogInfoPos = QuestMapGlobals.CogInfoPosTable.get('%s_%s_english' % (ToontownGlobals.dnaMap[hoodId], zoneId))
                self.cogInfoFrame.setPos(self.cogInfoPos)
                self.hide()
                self.hoodId = hoodId
                self.zoneId = zoneId
                self.updateQuestInfo()
                self.updateCogInfo()
                taskMgr.add(self.update, 'questMapUpdate')
            else:
                self.stop()
                mapsGeom.removeNode()

    def start(self):
        self.container.show()
        self.accept('questPageUpdated', self.updateMap)
        self.handleMarker()
        self.updateMap()

    def initMarker(self, task):
        if self.av:
            if not hasattr(base.cr.playGame.getPlace(), 'isInterior') or not base.cr.playGame.getPlace().isInterior:
                relX, relY = self.transformAvPos(self.av.getPos())
                self.marker.setPos(relX, 0, relY)
                self.marker.setHpr(0, 0, -180 - self.av.getH())
            self.marker['geom_scale'] = 1.4 * task.time % 0.5 * 10 + 1
            self.marker['geom_color'] = (1,
             1,
             1,
             0.8 - 1.4 * task.time % 0.5 * 2 / 0.8 + 0.2)
        if task.time < 1:
            return Task.cont
        else:
            self.marker['geom_color'] = (1, 1, 1, 0)
            return Task.done

    def show(self):
        taskMgr.add(self.initMarker, 'questMapInit')
        DirectFrame.show(self)
        self.mapOpenButton.hide()
        if self.container['image']:
            self.mapCloseButton.show()

    def hide(self):
        taskMgr.remove('questMapInit')
        DirectFrame.hide(self)
        if self.container['image']:
            self.mapOpenButton.show()
        self.mapCloseButton.hide()

    def toggle(self):
        if self.isHidden():
            self.show()
        else:
            self.hide()

    def obscureButton(self):
        self.mapOpenButton.hide()
        self.mapCloseButton.hide()

    def stop(self):
        self.container['image'] = None
        for marker in self.buildingMarkers:
            marker.destroy()

        self.buildingMarkers = []
        self.container.hide()
        self.hide()
        self.obscureButton()
        self.ignore('questPageUpdated')
        taskMgr.remove('questMapUpdate')
        return

    def handleMarker(self):
        if hasattr(base.cr.playGame.getPlace(), 'isInterior') and base.cr.playGame.getPlace().isInterior:
            self.updateMarker = False
        else:
            self.updateMarker = True

    def acceptOnscreenHooks(self):
        if self.wantToggle:
            self.accept(ToontownGlobals.MapHotkey, self.toggle)
        else:
            self.accept(ToontownGlobals.MapHotkeyOn, self.show)
            self.accept(ToontownGlobals.MapHotkeyOff, self.hide)
        self.updateMap()

    def ignoreOnscreenHooks(self):
        self.ignore(ToontownGlobals.MapHotkey)
        self.ignore(ToontownGlobals.MapHotkeyOn)
        self.ignore(ToontownGlobals.MapHotkeyOff)
        self.obscureButton()
コード例 #44
0
class QuestPoster(DirectFrame):
    notify = directNotify.newCategory('QuestPoster')

    # We need to declare and initialize these variables here
    # because some methods use them as default arguments.
    auxIcon = None

    # Requires one parameter, quest, this must be a Quest instance.
    # The next argument, parent, is where to reparent the DirectFrame to.
    # The next arguments are simply additional options when setting up the DirectFrame.
    def __init__(self, quest, parent=aspect2d, **kw):
        # The quest this poster is representing.
        self.quest = quest
        self.accessibleObjectives = quest.accessibleObjectives if quest else []
        self.viewObjective = quest.accessibleObjectives.seek(
        ) if quest else None

        isObjComplete = False if not quest else (
            self.accessibleObjectives.isComplete() or quest.isComplete())

        # Let's define our options for the DirectFrame.
        bookModel = loader.loadModel(
            'phase_3.5/models/gui/stickerbook_gui.bam')
        optiondefs = (('relief', None,
                       None), ('image', bookModel.find('**/questCard'),
                               None), ('image_scale', (0.8, 1.0, 0.58), None),
                      ('image_color', (1.0, 1.0, 1.0,
                                       1.0) if not isObjComplete else Vec4(
                                           *QuestGlobals.LIGHT_GREEN),
                       None), ('state', DGG.NORMAL, None))
        self.defineoptions(kw, optiondefs)

        # Finally, initialize the DirectFrame.
        DirectFrame.__init__(self, parent, relief=None)
        self.initialiseoptions(QuestPoster)

        # Let's declare and initialize our barebone GUI element variables.
        questTitle = '' if not self.quest else self.quest.name
        self.titleLabel = DirectLabel(parent=self,
                                      relief=None,
                                      text=questTitle,
                                      text_font=CIGlobals.getMinnieFont(),
                                      text_fg=QuestGlobals.TEXT_COLOR,
                                      text_scale=0.05,
                                      text_align=TextNode.ACenter,
                                      text_wordwrap=25.0,
                                      textMayChange=1,
                                      pos=(0, 0, 0.23))

        ##########################################################################
        #           THE FOLLOWING ELEMENTS BELOW ARE GROUPED TOGETHER            #
        ##########################################################################

        # The background frame where the objective image is displayed.
        # This is the colored background frame.

        circleGui = loader.loadModel(
            'phase_4/models/gui/CircleIconBackgroundGui.bam')
        self.auxFrame = DirectFrame(
            parent=self,
            relief=None,
            image=circleGui.find('**/circle_display_interior'),
            image_scale=0.18,
            text='',
            text_pos=(0, -0.11),
            text_fg=QuestGlobals.TEXT_COLOR,
            text_scale=QuestGlobals.QPtextScale,
            text_align=TextNode.ACenter,
            text_wordwrap=11.0,
            pos=QuestGlobals.DEFAULT_LEFT_PICTURE_POS)

        if self.quest and len(
                self.quest.accessibleObjectives) > 1 and not isObjComplete:
            # We can only use arrows when we have more than one objective available.
            arrowGui = loader.loadModel('phase_4/models/gui/QuestArrowGui.bam')
            self.prevObjArrow = DirectButton(
                parent=self.auxFrame,
                relief=None,
                geom=((arrowGui.find('**/quest_arrow_enabled'),
                       arrowGui.find('**/quest_arrow_click'),
                       arrowGui.find('**/quest_arrow_mouseover'),
                       arrowGui.find('**/quest_arrow_disabled'))),
                scale=0.08,
                command=self.switchObjective,
                extraArgs=[0],
                hpr=(180, 0, 0),
                pos=QuestGlobals.DEFAULT_LEFT_ARROW_POS)

            self.nextObjArrow = DirectButton(
                parent=self.auxFrame,
                relief=None,
                geom=((arrowGui.find('**/quest_arrow_enabled'),
                       arrowGui.find('**/quest_arrow_click'),
                       arrowGui.find('**/quest_arrow_mouseover'),
                       arrowGui.find('**/quest_arrow_disabled'))),
                scale=0.08,
                command=self.switchObjective,
                pos=QuestGlobals.DEFAULT_RIGHT_ARROW_POS)

        # The icon that goes on top of the aux frame.
        self.auxIcon = DirectFrame(parent=self.auxFrame,
                                   relief=None,
                                   text=' ',
                                   text_font=CIGlobals.getSuitFont(),
                                   text_pos=(0, -0.03),
                                   text_fg=QuestGlobals.TEXT_COLOR,
                                   text_scale=0.13,
                                   text_align=TextNode.ACenter,
                                   text_wordwrap=13.0,
                                   textMayChange=1)
        self.auxIcon.setColorOff(-1)

        self.auxOutline = DirectLabel(
            parent=self.auxFrame,
            relief=None,
            image=circleGui.find('**/circle_display_outline'),
            image_scale=0.18)

        # The aux text saying: DEFEAT, RECOVER, etc.
        self.auxText = DirectLabel(parent=self,
                                   relief=None,
                                   text=QuestGlobals.RECOVER,
                                   text_font=CIGlobals.getToonFont(),
                                   text_scale=QuestGlobals.QPauxText,
                                   text_fg=QuestGlobals.TEXT_COLOR,
                                   text_align=TextNode.ACenter,
                                   textMayChange=1,
                                   pos=QuestGlobals.DEFAULT_AUX_POS)
        self.auxText.hide()

        ##########################################################################

        # Information displayed about the objective.
        self.objectiveInfo = DirectLabel(
            parent=self,
            relief=None,
            text='',
            text_font=CIGlobals.getToonFont(),
            text_fg=QuestGlobals.TEXT_COLOR,
            text_scale=0.04,
            text_align=TextNode.ACenter,
            text_wordwrap=QuestGlobals.QPtextWordwrap,
            textMayChange=1,
            pos=(QuestGlobals.DEFAULT_INFO_POS))
        self.objectiveInfo.hide()

        # Information displayed showing the location.
        self.locationInfo = DirectLabel(
            parent=self,
            relief=None,
            text='N/A',
            text_font=CIGlobals.getToonFont(),
            text_fg=QuestGlobals.TEXT_COLOR,
            text_scale=QuestGlobals.QPtextScale,
            text_align=TextNode.ACenter,
            text_wordwrap=QuestGlobals.QPtextWordwrap,
            textMayChange=1,
            pos=(0, 0, -0.115))
        self.locationInfo.hide()

        # The progress bar showing the objective's progress
        self.progressBar = DirectWaitBar(parent=self,
                                         relief=DGG.SUNKEN,
                                         frameSize=(-0.95, 0.95, -0.1, 0.12),
                                         borderWidth=(0.025, 0.025),
                                         scale=0.2,
                                         frameColor=(0.945, 0.875, 0.706, 1.0),
                                         barColor=(0.5, 0.7, 0.5, 1),
                                         text='0/0',
                                         text_font=CIGlobals.getToonFont(),
                                         text_scale=0.19,
                                         text_fg=(0.05, 0.14, 0.4, 1),
                                         text_align=TextNode.ACenter,
                                         text_pos=(0, -0.05),
                                         pos=(0, 0, -0.2425))
        self.progressBar.hide()

        # The wood panel at the bottom where rewards are displayed.
        rewardFrameGeom = loader.loadModel(
            'phase_4/models/gui/gag_shop_purchase_gui.bam')
        self.rewardFrame = DirectFrame(
            parent=self,
            relief=None,
            geom=rewardFrameGeom.find('**/Goofys_Sign'),
            geom_scale=(0.62, 0, 0.4),
            pos=(-0.015, 0, -0.25))

        # Let's setup our reward frames.
        reward = None

        if self.quest and len(self.quest.rewards) > 0:
            reward = self.quest.rewards[0]
        self.lReward = QuestRewardFrame(self, reward)

        # The text displayed on the right side of the frame with additional information, if necessary.
        self.sideInfo = DirectLabel(parent=self,
                                    relief=None,
                                    text=QuestGlobals.JUST_FOR_FUN,
                                    text_fg=(0.0, 0.439, 1.0, 1.0),
                                    text_shadow=(0, 0, 0, 1),
                                    pos=(-0.2825, 0, 0.2),
                                    scale=0.03)
        self.sideInfo.setR(-30)

        # This side information is usually not needed, let's hide it.
        self.sideInfo.hide()

        # Remove the nodes of the loaded models we no longer need.
        circleGui.removeNode()
        bookModel.removeNode()
        rewardFrameGeom.removeNode()

        # We are only removing this node if we generated arrows.
        if hasattr(self, 'arrowGui'):
            arrowGui.removeNode()

        # Let's hide this until it is needed.
        self.hide()
        return

    def switchObjective(self, forward=1):
        if forward:
            self.accessibleObjectives.nextObjective()
        else:
            self.accessibleObjectives.lastObjective()
        self.viewObjective = self.accessibleObjectives.seek()
        self.setup()

    def setup(self):
        if self.quest:
            objective = self.viewObjective
            complete = self.accessibleObjectives.isComplete()

            # Let's reset our positioning of elements.
            self.auxFrame.setPos(QuestGlobals.DEFAULT_LEFT_PICTURE_POS)
            self.auxText.setPos(QuestGlobals.DEFAULT_AUX_POS)
            self.objectiveInfo.setPos(QuestGlobals.DEFAULT_INFO_POS)

            # Let's reset our icon.
            self.auxIcon.setScale(1, 1, 1)
            self.auxIcon.setPos(0, 0, 0)
            self.auxIcon.setHpr(0, 0, 0)

            self.objectiveInfo.show()
            self.auxFrame.show()

            # Let's setup the quest progress bar
            progress = objective.progress if hasattr(objective,
                                                     'progress') else None

            if objective.goal > 1:
                self.progressBar['range'] = objective.goal
                self.progressBar['value'] = progress & pow(2, 16) - 1

            if objective.HasProgress and objective.goal > 1 and not complete:
                self.progressBar.show()

            self.auxText.show()

            # Let's handle the objectives.
            if not complete:
                if objective.__class__ == CogObjective:
                    self.handleCogObjective()
                elif objective.__class__ == CogBuildingObjective:
                    self.handleCogBuildingObjective()
                elif objective.__class__ == MinigameObjective:
                    self.handleMinigameObjective()
                elif objective.__class__ == VisitNPCObjective:
                    self.handleNPCObjective()
            else:
                bgColor = QuestGlobals.RED

                if objective.type in DefeatObjectives:
                    bgColor = QuestGlobals.BLUE

                self.handleNPCObjective(auxText=QuestGlobals.RETURN + ' to',
                                        frameColor=bgColor)

            self.lReward.setup()

            newLineInObjInfo = '\n' in self.objectiveInfo['text']
            isShopLoc = QuestGlobals.isShopLocation(
                objective.area) if not complete else True

            if complete:
                locationText = QuestGlobals.getLocationText(None, objective)
            else:
                locationText = QuestGlobals.getLocationText(objective.area)

            self.locationInfo['text'] = locationText
            self.locationInfo['text_pos'] = (0.0, (0.025 if isShopLoc else (
                -0.025 if newLineInObjInfo else 0.0)))
            self.locationInfo.show()
        else:
            # We want to be able to show empty quest posters.
            self.titleLabel.hide()
            self.auxFrame.hide()
            self.auxIcon.hide()

        self.titleLabel.initialiseoptions(DirectLabel)
        self.auxIcon.initialiseoptions(DirectFrame)
        self.auxText.initialiseoptions(DirectLabel)
        self.objectiveInfo.initialiseoptions(DirectLabel)
        self.locationInfo.initialiseoptions(DirectLabel)
        self.rewardFrame.initialiseoptions(DirectFrame)
        self.sideInfo.initialiseoptions(DirectLabel)
        self.lReward.initialiseoptions(DirectFrame)

        # Handle arrow stuff if necessary.
        if hasattr(self, 'prevObjArrow'):
            index = self.accessibleObjectives.seeker
            self.prevObjArrow['state'] = DGG.NORMAL
            self.nextObjArrow['state'] = DGG.NORMAL
            self.prevObjArrow.setPos(QuestGlobals.DEFAULT_LEFT_ARROW_POS)
            self.nextObjArrow.setPos(QuestGlobals.DEFAULT_RIGHT_ARROW_POS)

            if index == 0:
                self.prevObjArrow['state'] = DGG.DISABLED
            elif index == len(self.accessibleObjectives) - 1:
                self.nextObjArrow['state'] = DGG.DISABLED

            self.prevObjArrow.initialiseoptions(DirectButton)
            self.nextObjArrow.initialiseoptions(DirectButton)

    # Changes geometry and scale of an icon.
    def handleSimpleIcon(self, geom, scale, icon):
        icon['geom'] = geom
        icon['geom_scale'] = scale

    def handleComplexIcon(self,
                          geom,
                          icon,
                          scale=QuestGlobals.IMAGE_SCALE_SMALL):
        geom.setDepthWrite(1)
        geom.setDepthTest(1)
        self.fitGeometry(geom, fFlip=1)
        self.handleSimpleIcon(geom, scale, icon)

        # We have to rotate the head and set the scale of the icon.
        if CIGlobals.Suit in geom.getName():
            cogName = geom.getPythonTag('Settings')
            data = QuestGlobals.Suit2PosterZNDScale.get(cogName)
            zOffset = data[0]
            headScale = data[1]
            icon.setScale(headScale)
            icon.setZ(icon.getZ() + zOffset)
            icon.setH(180)
        else:
            icon.setZ(icon.getZ() - 0.01)

    def handleCogObjective(self,
                           iconElement=auxIcon,
                           auxText=QuestGlobals.DEFEAT,
                           frameColor=QuestGlobals.BLUE):
        objective = self.viewObjective
        infoText = objective.getTaskInfo()

        if objective.__class__ == RecoverItemObjective:
            infoText = CIGlobals.makePlural(objective.cog)

        if not iconElement:
            iconElement = self.auxIcon

        # Let's make sure we have a current objective that is
        # an instance of the CogObjective class and this poster isn't destroyed.
        if not objective or not hasattr(self, 'titleLabel') or not isinstance(
                objective, CogObjective):
            return

        if objective.dept:
            icons = loader.loadModel('phase_3/models/gui/cog_icons.bam')
            deptIcon = None

            if objective.dept == Dept.BOSS:
                deptIcon = icons.find('**/CorpIcon')
            else:
                deptIcon = icons.find('**/%sIcon' %
                                      objective.dept.getTie().title())

            # Correct the medallion color.
            deptIcon.setColor(SuitGlobals.medallionColors[objective.dept])

            # Setup the icon and remove the icons node.
            self.handleSimpleIcon(deptIcon, 0.13, iconElement)
            icons.removeNode()
        elif objective.cog == QuestGlobals.Any:
            # We aren't fighting a Cog in particular.
            cogIcon = QuestGlobals.getCogIcon()
            self.handleSimpleIcon(cogIcon, 0.13, iconElement)

        # We're fighting a Cog in particular.
        if not objective.cog == QuestGlobals.Any:
            cogHeadInstance = SuitBank.getSuitByName(objective.cog).getHead()
            cogHead = cogHeadInstance.generate()
            cogHead.setName('%sHead' % CIGlobals.Suit)
            cogHead.setPythonTag('Settings', cogHeadInstance.head)
            cogHead.setScale(2)
            cogHead.setLightOff()
            self.handleComplexIcon(cogHead, iconElement)

            # HACK FIX: Corrects the buggy Flunky glasses.
            glasses = cogHead.find('**/glasses')
            if glasses and not glasses.isEmpty():
                glasses.setScale(1)
                glasses.reparentTo(cogHead)

        if not iconElement is self.auxIcon:
            if hasattr(self, 'goalInfo'):
                # We're working with the second frame, on the right.
                # Let's update the information pertaining to this side.
                self.goalInfo['text'] = infoText
                self.goalInfo.setPos(QuestGlobals.RECOVER_INFO2_POS)
                self.auxText.setPos(QuestGlobals.RECOVER_AUX_POS)
            else:
                raise AttributeError(
                    'Attempted to setup DoubleFrame information for poster using default style.'
                )
        else:
            self.objectiveInfo['text'] = infoText

        # Let's set the progress bar text
        pgBarText = '%d of %d %s' % (objective.progress, objective.goal,
                                     CIGlobals.makePastTense(auxText))
        self.progressBar['text'] = pgBarText

        self.auxText['text'] = auxText

        # Let's set the color of the poster.
        frame = self.auxFrame if iconElement is self.auxIcon else self.goalFrame
        frame['image_color'] = Vec4(*frameColor)

    def handleCogBuildingObjective(self,
                                   iconElement=auxIcon,
                                   auxText=QuestGlobals.DEFEAT,
                                   frameColor=QuestGlobals.BLUE):
        objective = self.viewObjective
        infoText = objective.getTaskInfo()

        if not iconElement:
            iconElement = self.auxIcon

        # Let's make sure we have a current objective that is
        # an instance of the CogBuildingObjective class and this poster isn't destroyed.
        if not objective or not hasattr(self, 'titleLabel') or not isinstance(
                objective, CogBuildingObjective):
            return

        # If we aren't looking for any specific department of building.
        if objective.dept == QuestGlobals.Any:
            # Let's just use the good ol' generic building icon.
            self.handleSimpleIcon(QuestGlobals.getCogBuildingIcon(),
                                  QuestGlobals.SIMPLE_IMAGE_SCALE, iconElement)
        else:
            # Ah geez, we're looking for a specific department.
            # Bossbot tie names are messed up, so we need this if statement.
            dept = objective.dept.getTie(
            ) if not objective.dept == Dept.BOSS else 'corp'
            bldgMdl = loader.loadModel(
                'phase_4/models/modules/suit_landmark_%s.bam' % dept)

            # Next, we need to load the building elevator.
            elevator = loader.loadModel('phase_4/models/modules/elevator.bam')
            elevator.reparentTo(bldgMdl.find('**/*_door_origin'))

            self.handleComplexIcon(bldgMdl, iconElement)

        # Let's set the progress bar text
        pgBarText = '%d of %d %s' % (objective.progress, objective.goal,
                                     CIGlobals.makePastTense(auxText))
        self.progressBar['text'] = pgBarText

        self.objectiveInfo['text'] = infoText
        self.auxText['text'] = auxText
        self.auxFrame['image_color'] = Vec4(*frameColor)

    def handleMinigameObjective(self,
                                iconElement=auxIcon,
                                auxText=QuestGlobals.PLAY,
                                frameColor=QuestGlobals.RED):
        objective = self.viewObjective
        infoText = objective.getTaskInfo()

        if not iconElement:
            iconElement = self.auxIcon

        # Let's make sure we have a current objective that is
        # an instance of the MinigameObjective class and this poster isn't destroyed.
        if not objective or not hasattr(self, 'titleLabel') or not isinstance(
                objective, MinigameObjective):
            return

        # Let's set the icon to the minigame icon.
        self.handleSimpleIcon(QuestGlobals.getTrolleyIcon(),
                              QuestGlobals.SIMPLE_IMAGE_SCALE, iconElement)

        # Let's set the progress bar text
        pgBarText = '%d of %d %s' % (objective.progress, objective.goal,
                                     CIGlobals.makePastTense(auxText))
        self.progressBar['text'] = pgBarText

        self.objectiveInfo['text'] = infoText
        self.auxText['text'] = auxText
        self.auxFrame['image_color'] = Vec4(*frameColor)

    def handleNPCObjective(self,
                           iconElement=auxIcon,
                           auxText=QuestGlobals.VISIT,
                           frameColor=QuestGlobals.BROWN):
        objective = self.viewObjective
        npcId = 0

        if self.accessibleObjectives.isComplete() and not hasattr(
                objective, 'npcId'):
            npcId = objective.assigner
        elif hasattr(objective, 'npcId'):
            npcId = objective.npcId

        if npcId == 0:
            infoText = 'A %s' % NPCGlobals.lHQOfficerF
        else:
            infoText = NPCGlobals.NPCToonNames[npcId]

        if not iconElement:
            iconElement = self.auxIcon

        # Let's generate the head.
        if not npcId == 0:
            dna = ToonDNA()
            dna.setDNAStrand(NPCGlobals.NPCToonDict.get(npcId)[2])
            head = ToonGlobals.generateGuiHead(dna)
            self.handleComplexIcon(head,
                                   iconElement,
                                   scale=QuestGlobals.IMAGE_SCALE_SMALL - 0.01)
        else:
            self.handleSimpleIcon(QuestGlobals.getHQIcon(),
                                  QuestGlobals.SIMPLE_IMAGE_SCALE, iconElement)

        self.auxText['text'] = auxText

        if not iconElement is self.auxIcon:
            if hasattr(self, 'goalInfo'):
                # We're working with the second frame, on the right.
                # Let's update the information pertaining to this side.
                self.goalInfo['text'] = infoText
                self.goalInfo.setPos(QuestGlobals.RECOVER_INFO2_POS)
                self.auxText.setPos(QuestGlobals.RECOVER_AUX_POS)
                self.goalFrame['image_color'] = frameColor
            else:
                raise AttributeError(
                    'Attempted to setup DoubleFrame information for poster using default style.'
                )
        else:
            self.objectiveInfo['text'] = infoText
            self.auxFrame['image_color'] = frameColor

    def fitGeometry(self, geom, fFlip=0, dimension=0.8):
        p1 = Point3()
        p2 = Point3()
        geom.calcTightBounds(p1, p2)
        if fFlip:
            t = p1[0]
            p1.setX(-p2[0])
            p2.setX(-t)
        d = p2 - p1
        biggest = max(d[0], d[2])
        s = dimension / biggest
        mid = (p1 + d / 2.0) * s
        geomXform = hidden.attachNewNode('geomXform')
        for child in geom.getChildren():
            child.reparentTo(geomXform)

        geomXform.setPosHprScale(-mid[0], -mid[1] + 1, -mid[2], 180, 0, 0, s,
                                 s, s)
        geomXform.reparentTo(geom)

    def destroy(self):
        if hasattr(self, 'titleLabel'):
            self.titleLabel.destroy()
            self.auxFrame.destroy()
            self.auxIcon.destroy()
            self.auxOutline.destroy()
            self.auxText.destroy()
            self.objectiveInfo.destroy()
            self.locationInfo.destroy()
            self.progressBar.destroy()
            self.rewardFrame.destroy()
            self.sideInfo.destroy()
            self.lReward.destroy()

            # We need to cleanup our arrows if they were created.
            if hasattr(self, 'prevObjArrow'):
                self.prevObjArrow.destroy()
                self.nextObjArrow.destroy()
                del self.prevObjArrow
                del self.nextObjArrow

            del self.titleLabel
            del self.auxFrame
            del self.auxIcon
            del self.auxOutline
            del self.auxText
            del self.objectiveInfo
            del self.locationInfo
            del self.progressBar
            del self.rewardFrame
            del self.sideInfo
            del self.lReward
            del self.accessibleObjectives
            del self.viewObjective
            DirectFrame.destroy(self)
            self.notify.debug('Destroyed all elements.')
コード例 #45
0
class LaffMeter(DirectFrame):
    deathColor = Vec4(0.58039216, 0.80392157, 0.34117647, 1.0)

    def __init__(self, avdna, hp, maxHp):
        DirectFrame.__init__(self, relief=None, sortOrder=50)
        self.initialiseoptions(LaffMeter)
        self.container = DirectFrame(parent=self, relief=None)
        self.style = avdna
        self.av = None
        self.hp = hp
        self.maxHp = maxHp
        self.__obscured = 0
        if self.style.type == 't':
            self.isToon = 1
        else:
            self.isToon = 0

        self.load()

    def obscure(self, obscured):
        self.__obscured = obscured
        if self.__obscured:
            self.hide()
            base.localAvatar.expBar.hide(
            )  # Hacky, I know, but I'll figure out a better way to hide the exp bar

    def isObscured(self):
        return self.__obscured

    def load(self):
        gui = loader.loadModel('phase_3/models/gui/laff_o_meter')
        if self.isToon:
            hType = self.style.getType()
            if hType == 'dog':
                headModel = gui.find('**/doghead')
            elif hType == 'cat':
                headModel = gui.find('**/cathead')
            elif hType == 'mouse':
                headModel = gui.find('**/mousehead')
            elif hType == 'horse':
                headModel = gui.find('**/horsehead')
            elif hType == 'rabbit':
                headModel = gui.find('**/bunnyhead')
            elif hType == 'duck':
                headModel = gui.find('**/duckhead')
            elif hType == 'monkey':
                headModel = gui.find('**/monkeyhead')
            elif hType == 'bear':
                headModel = gui.find('**/bearhead')
            elif hType == 'pig':
                headModel = gui.find('**/pighead')
            elif hType == 'deer':
                headModel = gui.find('**/deerhead')
            else:
                raise StandardError('unknown toon species: ', hType)
            self.color = self.style.getHeadColor()
            self.container['image'] = headModel
            self.container['image_color'] = self.color
            self.resetFrameSize()
            self.setScale(0.1)
            self.frown = DirectFrame(parent=self.container,
                                     relief=None,
                                     image=gui.find('**/frown'))
            self.frown.setY(-0.1)
            self.smile = DirectFrame(parent=self.container,
                                     relief=None,
                                     image=gui.find('**/smile'))
            self.smile.setY(-0.1)
            self.eyes = DirectFrame(parent=self.container,
                                    relief=None,
                                    image=gui.find('**/eyes'))
            self.eyes.setY(-0.1)
            self.openSmile = DirectFrame(parent=self.container,
                                         relief=None,
                                         image=gui.find('**/open_smile'))
            self.tooth1 = DirectFrame(parent=self.openSmile,
                                      relief=None,
                                      image=gui.find('**/tooth_1'))
            self.tooth2 = DirectFrame(parent=self.openSmile,
                                      relief=None,
                                      image=gui.find('**/tooth_2'))
            self.tooth3 = DirectFrame(parent=self.openSmile,
                                      relief=None,
                                      image=gui.find('**/tooth_3'))
            self.tooth4 = DirectFrame(parent=self.openSmile,
                                      relief=None,
                                      image=gui.find('**/tooth_4'))
            self.tooth5 = DirectFrame(parent=self.openSmile,
                                      relief=None,
                                      image=gui.find('**/tooth_5'))
            self.tooth6 = DirectFrame(parent=self.openSmile,
                                      relief=None,
                                      image=gui.find('**/tooth_6'))
            self.maxLabel = DirectLabel(
                parent=self.eyes,
                relief=None,
                pos=(0.442, 0, 0.051),
                text='120',
                text_scale=0.4,
                text_font=ToontownGlobals.getInterfaceFont())
            self.maxLabel.setY(-0.1)
            self.hpLabel = DirectLabel(
                parent=self.eyes,
                relief=None,
                pos=(-0.398, 0, 0.051),
                text='120',
                text_scale=0.4,
                text_font=ToontownGlobals.getInterfaceFont())
            self.hpLabel.setY(-0.1)
            self.teeth = [
                self.tooth6, self.tooth5, self.tooth4, self.tooth3,
                self.tooth2, self.tooth1
            ]
            for tooth in self.teeth:
                tooth.setY(-0.1)
            self.fractions = [0.0, 0.166666, 0.333333, 0.5, 0.666666, 0.833333]
        gui.removeNode()

    def destroy(self):
        if self.av:
            ToontownIntervals.cleanup(
                self.av.uniqueName('laffMeterBoing') + '-' + str(self.this))
            ToontownIntervals.cleanup(
                self.av.uniqueName('laffMeterBoing') + '-' + str(self.this) +
                '-play')
            self.ignore(self.av.uniqueName('hpChange'))
        del self.style
        del self.av
        del self.hp
        del self.maxHp
        if self.isToon:
            del self.frown
            del self.smile
            del self.openSmile
            del self.tooth1
            del self.tooth2
            del self.tooth3
            del self.tooth4
            del self.tooth5
            del self.tooth6
            del self.teeth
            del self.fractions
            del self.maxLabel
            del self.hpLabel
        DirectFrame.destroy(self)

    def adjustTeeth(self):
        if self.isToon:
            for i in xrange(len(self.teeth)):
                if self.hp > self.maxHp * self.fractions[i]:
                    self.teeth[i].show()
                else:
                    self.teeth[i].hide()

    def adjustText(self):
        if self.isToon:
            if self.maxLabel['text'] != str(
                    self.maxHp) or self.hpLabel['text'] != str(self.hp):
                self.maxLabel['text'] = str(self.maxHp)
                self.hpLabel['text'] = str(self.hp)

    def animatedEffect(self, delta):
        if delta == 0 or self.av == None:
            return
        name = self.av.uniqueName('laffMeterBoing') + '-' + str(self.this)
        ToontownIntervals.cleanup(name)
        if delta > 0:
            ToontownIntervals.start(
                ToontownIntervals.getPulseLargerIval(self.container, name))
        else:
            ToontownIntervals.start(
                ToontownIntervals.getPulseSmallerIval(self.container, name))

    def adjustFace(self, hp, maxHp, quietly=0):
        if self.isToon and self.hp != None:
            self.frown.hide()
            self.smile.hide()
            self.openSmile.hide()
            self.eyes.hide()
            for tooth in self.teeth:
                tooth.hide()

            delta = hp - self.hp
            self.hp = hp
            self.maxHp = maxHp
            if self.hp < 1:
                self.frown.show()
                self.container['image_color'] = self.deathColor
            elif self.hp >= self.maxHp:
                self.smile.show()
                self.eyes.show()
                self.container['image_color'] = self.color
            else:
                self.openSmile.show()
                self.eyes.show()
                self.maxLabel.show()
                self.hpLabel.show()
                self.container['image_color'] = self.color
                self.adjustTeeth()
            self.adjustText()
            if not quietly:
                self.animatedEffect(delta)

    def start(self):
        if self.av:
            self.hp = self.av.hp
            self.maxHp = self.av.maxHp
        if self.isToon:
            if not self.__obscured:
                self.show()
            self.adjustFace(self.hp, self.maxHp, 1)
            if self.av:
                self.accept(self.av.uniqueName('hpChange'), self.adjustFace)

    def stop(self):
        if self.isToon:
            self.hide()
            if self.av:
                self.ignore(self.av.uniqueName('hpChange'))

    def setAvatar(self, av):
        if self.av:
            self.ignore(self.av.uniqueName('hpChange'))

        self.av = av
コード例 #46
0
class JukeboxGui(DirectObject):
    notify = directNotify.newCategory('JukeboxGui')
    CLOSE_EVENT = 'JukeboxGui_CLOSE_EVENT'
    SONG_SELECT_EVENT = 'JukeboxGui_SONG_SELECT_EVENT'
    QUEUE_SELECT_EVENT = 'JukeboxGui_QUEUE_SELECT_EVENT'
    ADD_SONG_CLICK_EVENT = 'JukeboxGui_ADD_SONG_CLICK_EVENT'
    MOVE_TO_TOP_CLICK_EVENT = 'JukeboxGUI_MOVE_TO_TOP_EVENT'
    
    def __init__(self, phaseToMusicData):
        self._loaded = False
        self._timerGui = None
        self._windowFrame = None
        self.phaseToMusicData = phaseToMusicData

    
    def load(self):
        if self.isLoaded():
            return None
        
        guiNode = loader.loadModel('phase_13/models/parties/jukeboxGUI')
        self._timerGui = PartyUtils.getNewToontownTimer()
        self._windowFrame = DirectFrame(image = guiNode.find('**/background'), relief = None, pos = (0, 0, 0), scale = 0.69999999999999996)
        self._songFrame = DirectFrame(image = guiNode.find('**/songTitle_background'), parent = self._windowFrame, relief = None)
        self._currentlyPlayingLabel = self._JukeboxGui__createLabel(guiNode, 'currentlyPlaying', parent = self._windowFrame, text = TTLocalizer.JukeboxCurrentlyPlayingNothing, scale = TTLocalizer.JGcurrentlyPlayingLabel)
        self._songNameLabel = self._JukeboxGui__createLabel(guiNode, 'songName', parent = self._windowFrame, text = TTLocalizer.JukeboxCurrentSongNothing, scale = TTLocalizer.JGsongNameLabel)
        (self._queueList, self._queueLabel) = self._JukeboxGui__createLabeledScrolledList(guiNode, 'queue', label = TTLocalizer.JukeboxQueueLabel, parent = self._windowFrame)
        (self._songsList, self._songsLabel) = self._JukeboxGui__createLabeledScrolledList(guiNode, 'songs', label = TTLocalizer.JukeboxSongsLabel, parent = self._windowFrame)
        pos = guiNode.find('**/addButton_text_locator').getPos()
        self._addSongButton = self._JukeboxGui__createButton(guiNode, 'addSongButton', parent = self._windowFrame, command = self._JukeboxGui__handleAddSongButtonClick, image3_color = Vec4(0.59999999999999998, 0.59999999999999998, 0.59999999999999998, 0.59999999999999998), text = TTLocalizer.JukeboxAddSong, text_align = TextNode.ACenter, text_pos = (pos[0], pos[2]), text_scale = TTLocalizer.JGaddSongButton)
        self._closeButton = self._JukeboxGui__createButton(guiNode, 'can_cancelButton', parent = self._windowFrame, command = self._JukeboxGui__handleCloseButtonClick)
        pos = guiNode.find('**/close_text_locator').getPos()
        self._closeButton = self._JukeboxGui__createButton(guiNode, 'close', parent = self._windowFrame, command = self._JukeboxGui__handleCloseButtonClick, text = TTLocalizer.JukeboxClose, text_align = TextNode.ACenter, text_pos = (pos[0], pos[2]), text_scale = 0.080000000000000002)
        self._moveToTopButton = self._JukeboxGui__createButton(guiNode, 'moveToTop', command = self._JukeboxGui__handleMoveToTopButtonClick)
        guiNode.removeNode()
        self._loaded = True

    
    def _JukeboxGui__createButton(self, guiNode, imagePrefix, parent = hidden, **kwargs):
        return DirectButton(parent = parent, relief = None, image = (guiNode.find('**/%s_up' % imagePrefix), guiNode.find('**/%s_down' % imagePrefix), guiNode.find('**/%s_rollover' % imagePrefix)), **None)

    
    def _JukeboxGui__createLabel(self, guiNode, locatorPrefix, parent = hidden, **kwargs):
        return DirectLabel(parent = parent, relief = None, pos = guiNode.find('**/%s_text_locator' % locatorPrefix).getPos(), **None)

    
    def _JukeboxGui__createLabeledScrolledList(self, guiNode, namePrefix, label, parent = hidden, **kwargs):
        return (DirectScrolledList(parent = parent, relief = None, incButton_image = (guiNode.find('**/%sButtonDown_up' % namePrefix), guiNode.find('**/%sButtonDown_down' % namePrefix), guiNode.find('**/%sButtonDown_rollover' % namePrefix)), incButton_relief = None, incButton_image3_color = Vec4(0.59999999999999998, 0.59999999999999998, 0.59999999999999998, 0.59999999999999998), decButton_image = (guiNode.find('**/%sButtonUp_up' % namePrefix), guiNode.find('**/%sButtonUp_down' % namePrefix), guiNode.find('**/%sButtonUp_rollover' % namePrefix)), decButton_relief = None, decButton_image3_color = Vec4(0.59999999999999998, 0.59999999999999998, 0.59999999999999998, 0.59999999999999998), image = guiNode.find('**/%s_background' % namePrefix), itemFrame_relief = None, itemFrame_pos = guiNode.find('**/%sList_locator' % namePrefix).getPos(), itemFrame_scale = 0.070000000000000007, numItemsVisible = TTLocalizer.JGnumItemsVisible, items = [], **None), self._JukeboxGui__createLabel(guiNode, namePrefix, parent = parent, text = label, text_fg = (0.5, 1.0, 1.0, 1.0), text_shadow = (0.0, 0.0, 0.0, 1.0), scale = 0.12))

    
    def enable(self, timer = 0):
        if not self.isLoaded():
            self.load()
            phase = 13
            tunes = self.phaseToMusicData[13]
            for (filename, info) in tunes.items():
                self.addToSongList(info[0], phase, filename, info[1])
            
            for (phase, tunes) in self.phaseToMusicData.items():
                if phase == 13:
                    continue
                
                for (filename, info) in tunes.items():
                    self.addToSongList(info[0], phase, filename, info[1])
                
            
        
        self._windowFrame.show()
        if timer > 0:
            self._timerGui.setTime(timer)
            self._timerGui.countdown(timer)
            self._timerGui.show()
        

    
    def disable(self):
        self._windowFrame.hide()
        self._timerGui.hide()

    
    def unload(self):
        self.ignoreAll()
        if not self.isLoaded():
            return None
        
        if self._windowFrame is not None:
            self._windowFrame.destroy()
            self._windowFrame = None
            self._moveToTopButton.destroy()
            del self._moveToTopButton
        
        if self._timerGui is not None:
            self._timerGui.destroy()
            self._timerGui = None
        
        self._loaded = False

    
    def isLoaded(self):
        return self._loaded

    
    def addToSongList(self, text, phase, filename, length):
        listItem = DirectScrolledListItem(relief = None, parent = self._songsList, text = text, text_align = TextNode.ALeft, text_pos = (0.0, 0.0, 0.0), text_scale = TTLocalizer.JGlistItem, text_fg = (0.0, 0.0, 0.0, 1.0), text1_fg = (1.0, 1.0, 1.0, 1.0), text1_bg = (0.0, 0.0, 1.0, 1.0), text2_fg = (0.0, 0.0, 1.0, 1.0), text3_bg = (0.0, 0.80000000000000004, 0.0, 1.0), command = self._JukeboxGui__handleSongListItemSelect, extraArgs = [])
        listItem.setPythonTag('value', (phase, filename, length))
        self._songsList.addItem(listItem)
        return listItem

    
    def _JukeboxGui__handleCloseButtonClick(self):
        self.disable()
        messenger.send(JukeboxGui.CLOSE_EVENT)

    
    def _JukeboxGui__handleMoveToTopButtonClick(self):
        messenger.send(JukeboxGui.MOVE_TO_TOP_CLICK_EVENT)

    
    def _JukeboxGui__handleSongListItemSelect(self):
        pass

    
    def _JukeboxGui__handleAddSongButtonClick(self):
        if hasattr(self._songsList, 'currentSelected'):
            song = self._songsList.currentSelected
            messenger.send(JukeboxGui.ADD_SONG_CLICK_EVENT, [
                song['text'],
                song.getPythonTag('value')])
        

    
    def disableAddSongButton(self):
        self._addSongButton['state'] = DirectGuiGlobals.DISABLED

    
    def enableAddSongButton(self):
        self._addSongButton['state'] = DirectGuiGlobals.NORMAL

    
    def addSongToQueue(self, text, highlight = False, moveToTopButton = False):
        listItem = DirectLabel(relief = None, parent = self._queueList, text = text, text_align = TextNode.ALeft, text_pos = (0.0, 0.0, 0.0), text_scale = TTLocalizer.JGlistItem)
        self._queueList.addItem(listItem)
        if highlight:
            listItem['text_fg'] = (0.0, 0.5, 0.0, 1.0)
            self._addSongButton['text'] = TTLocalizer.JukeboxReplaceSong
            listItem.setPythonTag('highlighted', True)
        
        if moveToTopButton and len(self._queueList['items']) > 1:
            self._moveToTopButton.reparentTo(listItem)
            self._moveToTopButton.setScale(self._windowFrame, 1.0)
            self._moveToTopButton.setPos(10.0, 0.0, 0.25)
            self._queueList.scrollTo(len(self._queueList['items']) - 1)
        
        return listItem

    
    def popSongFromQueue(self):
        if len(self._queueList['items']) > 0:
            item = self._queueList['items'][0]
            self._queueList.removeItem(item)
            if self._moveToTopButton.getParent() == item:
                self._moveToTopButton.reparentTo(hidden)
            
            if self._moveToTopButton.getParent() == item:
                self._moveToTopButton.reparentTo(hidden)
            
            if item.getPythonTag('highlighted') == True:
                self._addSongButton['text'] = TTLocalizer.JukeboxAddSong
            
            item.removeNode()
            return item
        

    
    def setSongCurrentlyPlaying(self, phase, filename):
        songs = self.phaseToMusicData.get(phase / 1)
        if songs:
            songName = songs.get(filename)
            if songName:
                self._songNameLabel['text'] = songName
                self._currentlyPlayingLabel['text'] = TTLocalizer.JukeboxCurrentlyPlaying
            
        

    
    def clearSongCurrentlyPlaying(self):
        self._currentlyPlayingLabel['text'] = TTLocalizer.JukeboxCurrentlyPlayingNothing
        self._songNameLabel['text'] = TTLocalizer.JukeboxCurrentSongNothing

    
    def pushQueuedItemToTop(self, item):
        self._queueList['items'].remove(item)
        self._queueList['items'].insert(0, item)
        if self._moveToTopButton.getParent() == item:
            self._moveToTopButton.reparentTo(hidden)
        
        self._queueList.refresh()
コード例 #47
0
class InviteVisual(DirectFrame):
    notify = directNotify.newCategory('InviteVisual')

    def __init__(self, parent):
        DirectFrame.__init__(self, parent=parent)
        self.gui = loader.loadModel('phase_5.5/models/parties/partyInviteGUI')
        self.inviteThemesIdToInfo = {PartyGlobals.InviteTheme.Birthday: (self.gui.find('**/birthdayPage'), TTLocalizer.PartyPlannerBirthdayTheme, (0.0,
                                              0.0,
                                              0.0,
                                              1.0)),
         PartyGlobals.InviteTheme.GenericMale: (self.gui.find('**/genericMalePage'), TTLocalizer.PartyPlannerGenericMaleTheme, (0.7,
                                                 0.7,
                                                 0.0,
                                                 1.0)),
         PartyGlobals.InviteTheme.GenericFemale: (self.gui.find('**/genericFemalePage'), TTLocalizer.PartyPlannerGenericFemaleTheme, (0.0,
                                                   1.0,
                                                   0.5,
                                                   1.0)),
         PartyGlobals.InviteTheme.Racing: (self.gui.find('**/racingPage'), TTLocalizer.PartyPlannerRacingTheme, (0.0,
                                            0.0,
                                            0.0,
                                            1.0)),
         PartyGlobals.InviteTheme.Valentoons: (self.gui.find('**/valentinePage1'), TTLocalizer.PartyPlannerValentoonsTheme, (0.0,
                                                0.0,
                                                0.0,
                                                1.0)),
         PartyGlobals.InviteTheme.VictoryParty: (self.gui.find('**/victoryPartyPage'), TTLocalizer.PartyPlannerVictoryPartyTheme, (0.0,
                                                  0.0,
                                                  0.0,
                                                  1.0)),
         PartyGlobals.InviteTheme.Winter: (self.gui.find('**/winterPartyPage1'), TTLocalizer.PartyPlannerWinterPartyTheme, (1.0,
                                            1.0,
                                            1.0,
                                            1.0))}
        self.inviteThemeBackground = DirectFrame(parent=self, image=self.inviteThemesIdToInfo[0][0], relief=None)
        self.whosePartyLabel = DirectLabel(parent=self, relief=None, pos=self.gui.find('**/who_locator').getPos(), text='.', text_scale=0.067, textMayChange=True)
        self.activityTextLabel = DirectLabel(parent=self, relief=None, text='.\n.\n.\n.', pos=self.gui.find('**/what_locator').getPos(), text_scale=TTLocalizer.IVactivityTextLabel, textMayChange=True)
        self.whenTextLabel = DirectLabel(parent=self, relief=None, text='.\n.\n.', pos=self.gui.find('**/when_locator').getPos(), text_scale=TTLocalizer.IVwhenTextLabel, textMayChange=True)
        self.noFriends = False
        return None

    def setNoFriends(self, noFriends):
        self.noFriends = noFriends
        self.inviteThemeBackground.show()

    def updateInvitation(self, hostsName, partyInfo):
        self.partyInfo = partyInfo
        hostsName = TTLocalizer.GetPossesive(hostsName)
        self.whosePartyLabel['text'] = TTLocalizer.PartyPlannerInvitationWhoseSentence % hostsName
        if self.partyInfo.isPrivate:
            publicPrivateText = TTLocalizer.PartyPlannerPrivate.lower()
        else:
            publicPrivateText = TTLocalizer.PartyPlannerPublic.lower()
        activities = self.getActivitiesFormattedCorrectly()
        if self.noFriends:
            self.activityTextLabel['text'] = TTLocalizer.PartyPlannerInvitationThemeWhatSentenceNoFriends % (publicPrivateText, activities)
        else:
            self.activityTextLabel['text'] = TTLocalizer.PartyPlannerInvitationThemeWhatSentence % (publicPrivateText, activities)
        if self.noFriends:
            self.whenTextLabel['text'] = TTLocalizer.PartyPlannerInvitationWhenSentenceNoFriends % (PartyUtils.formatDate(self.partyInfo.startTime.year, self.partyInfo.startTime.month, self.partyInfo.startTime.day), PartyUtils.formatTime(self.partyInfo.startTime.hour, self.partyInfo.startTime.minute))
        else:
            self.whenTextLabel['text'] = TTLocalizer.PartyPlannerInvitationWhenSentence % (PartyUtils.formatDate(self.partyInfo.startTime.year, self.partyInfo.startTime.month, self.partyInfo.startTime.day), PartyUtils.formatTime(self.partyInfo.startTime.hour, self.partyInfo.startTime.minute))
        self.changeTheme(partyInfo.inviteTheme)

    def getActivitiesFormattedCorrectly(self):
        activitiesString = ''
        activityList = []
        for activity in self.partyInfo.activityList:
            text = TTLocalizer.PartyActivityNameDict[activity.activityId]['invite']
            if text not in activityList:
                activityList.append(text)

        if len(activityList) == 1:
            return '\n' + TTLocalizer.PartyPlannerInvitationThemeWhatActivitiesBeginning + activityList[0]
        conjunction = TTLocalizer.PartyActivityConjunction
        for activity in activityList:
            activitiesString = '%s, %s' % (activitiesString, activity)

        activitiesString = activitiesString[2:]
        activitiesString = activitiesString[:activitiesString.rfind(',')] + conjunction + activitiesString[activitiesString.rfind(',') + 1:]
        activitiesString = TTLocalizer.PartyPlannerInvitationThemeWhatActivitiesBeginning + activitiesString
        return self.insertCarriageReturn(activitiesString)

    def insertCarriageReturn(self, stringLeft, stringDone = ''):
        desiredNumberOfCharactersInLine = 42
        if len(stringLeft) < desiredNumberOfCharactersInLine:
            return stringDone + '\n' + stringLeft
        for i in xrange(desiredNumberOfCharactersInLine - 6, len(stringLeft)):
            if stringLeft[i] == ' ':
                return self.insertCarriageReturn(stringLeft[i:], stringDone + '\n' + stringLeft[:i])

        return stringDone + '\n' + stringLeft

    def changeTheme(self, newTheme):
        self.inviteThemeBackground['image'] = self.inviteThemesIdToInfo[newTheme][0]
        self.whosePartyLabel['text_fg'] = self.inviteThemesIdToInfo[newTheme][2]
        self.activityTextLabel['text_fg'] = self.inviteThemesIdToInfo[newTheme][2]
        self.whenTextLabel['text_fg'] = self.inviteThemesIdToInfo[newTheme][2]

    def close(self):
        self.destroy()
        del self
コード例 #48
0
class CharacterSelection:
    def __init__(self):

        self.frameMain = DirectFrame(
            frameSize = (base.a2dLeft, base.a2dRight,
                         base.a2dBottom, base.a2dTop),
            frameColor = (0.05, 0.05, 0.05, 1))
        self.frameMain.setTransparency(1)

        width = abs(base.a2dLeft) + base.a2dRight

        red = loader.loadTexture("assets/gui/CharRedBG.png")
        red.setWrapU(Texture.WM_repeat)
        red.setWrapV(Texture.WM_repeat)
        self.char1Frame = DirectFrame(
            text = "Player 1",
            text_fg = (1,1,1,1),
            text_scale = 0.1,
            text_pos = (0, base.a2dTop - 0.2),
            frameSize = (-width/6.0, width/6.0,
                         base.a2dBottom, base.a2dTop),
            frameTexture = red,
            pos = (base.a2dLeft+width/6.0, 0, 0))
        self.char1Frame.updateFrameStyle()
        self.char1Frame.setTransparency(1)
        self.char1Frame.reparentTo(self.frameMain)

        blue = loader.loadTexture("assets/gui/CharBlueBG.png")
        blue.setWrapU(Texture.WM_repeat)
        blue.setWrapV(Texture.WM_repeat)
        self.char2Frame = DirectFrame(
            text = "Player 2",
            text_fg = (1,1,1,1),
            text_scale = 0.1,
            text_pos = (0, base.a2dTop - 0.2),
            frameSize = (-width/6.0, width/6.0,
                         base.a2dBottom, base.a2dTop),
            frameTexture = blue,
            pos = (base.a2dRight-width/6.0, 0, 0))
        self.char2Frame.setTransparency(1)
        self.char2Frame.reparentTo(self.frameMain)

        self.footerFrame = DirectFrame(
            text = "PLAYER 1 - CHOOSE YOUR CHARACTER",
            text_fg = (1,1,1,1),
            text_scale = 0.08,
            text_pos = (0, -0.03),
            frameSize = (base.a2dLeft, base.a2dRight,
                         0.1, -0.1),
            pos = (0, 0, base.a2dBottom + 0.2),
            frameColor = (0, 0, 0, 0.5))
        self.footerFrame.setTransparency(1)
        self.footerFrame.reparentTo(self.frameMain)

        self.charSelectFrame = DirectFrame(
            text = "VS",
            text_fg = (1,1,1,1),
            text_scale = 0.1,
            text_pos = (0, base.a2dTop - 0.2),
            frameSize = (-width/6.0, width/6.0,
                         base.a2dBottom, base.a2dTop),
            frameColor = (0,0,0,0))
        self.charSelectFrame.reparentTo(self.frameMain)

        self.btnChar1 = self.createCharacterButton(
            (-0.2, 0, 0),
            "assets/gui/Char1Button.png",
            1)
        self.btnChar1.reparentTo(self.charSelectFrame)

        self.btnChar2 = self.createCharacterButton(
            (0.2, 0, 0),
            "assets/gui/Char2Button.png",
            2)
        self.btnChar2.reparentTo(self.charSelectFrame)

        self.btnBack = DirectButton(
            text = "BACK",
            text_fg = (1,1,1,1),
            text_align = TextNode.ALeft,
            scale = 0.1,
            pad = (0.15, 0.15),
            pos = (base.a2dLeft + 0.08, 0, -0.03),
            frameColor = (
                (0.2,0.2,0.2,0.8),
                (0.4,0.4,0.4,0.8),
                (0.4,0.4,0.4,0.8),
                (0.1,0.1,0.1,0.8)),
            relief = 1,
            command = base.messenger.send,
            extraArgs = ["CharSelection-Back"],
            pressEffect = False,
            rolloverSound = None,
            clickSound = None)
        self.btnBack.setTransparency(1)
        self.btnBack.reparentTo(self.footerFrame)

        self.btnStart = DirectButton(
            text = "START",
            text_fg = (1,1,1,1),
            text_align = TextNode.ARight,
            scale = 0.1,
            pad = (0.15, 0.15),
            pos = (base.a2dRight - 0.08, 0, -0.03),
            relief = 1,
            frameColor = (
                (0.2,0.2,0.2,0.8),
                (0.4,0.4,0.4,0.8),
                (0.4,0.4,0.4,0.8),
                (0.1,0.1,0.1,0.8)),
            command = base.messenger.send,
            extraArgs = ["CharSelection-Start"],
            pressEffect = False,
            rolloverSound = None,
            clickSound = None)
        self.btnStart.setTransparency(1)
        self.btnStart.reparentTo(self.footerFrame)
        self.btnStart["state"] = DGG.DISABLED

        self.hide()

    def createCharacterButton(self, pos, image, charNr):
        btn = DirectButton(
            scale = 0.1,
            relief = 0,
            frameColor = (0,0,0,0),
            pos = pos,
            image = image,
            command = self.selectCharacter,
            extraArgs = [charNr],
            rolloverSound = None,
            clickSound = None)
        btn.setTransparency(1)
        return btn

    def selectCharacter(self, charNr):
        if self.char1Frame["image"] == None:
            self.char1Frame["image"] = "assets/gui/Char{}_L.png".format(charNr)
            self.char1Frame["image_scale"] = (0.5,1, 1)
            self.selectedCharacter1 = charNr
            self.footerFrame["text"] = "PLAYER 2 - CHOOSE YOUR CHARACTER"
        elif self.char2Frame["image"] == None:
            self.char2Frame["image"] = "assets/gui/Char{}_R.png".format(charNr)
            self.char2Frame["image_scale"] = (0.5,1, 1)
            self.selectedCharacter2 = charNr
            self.btnStart["state"] = DGG.NORMAL
            self.footerFrame["text"] = "START THE FIGHT >"

    def show(self):
        self.selectedCharacter1 = None
        self.selectedCharacter2 = None
        self.char1Frame["image"] = None
        self.char2Frame["image"] = None
        self.footerFrame["text"] = "PLAYER 1 - CHOOSE YOUR CHARACTER"
        self.btnStart["state"] = DGG.DISABLED
        self.frameMain.show()

    def hide(self):
        self.frameMain.hide()
コード例 #49
0
class GUIDialog:
    def __init__(self):
        self.mainFrame = DirectFrame(frameColor=(0, 0, 0, 0.5),
                                     borderWidth=(10, 10),
                                     frameSize=(-2, 2, -1, -0.45))
        self.textIndex = 0
        self.isCalling = False
        self.frameText = None
        self.frameActor = None
        self.frameChoices = None
        self.textList = []
        self.hide()

    def setLabel(self, labelName):
        base.textEngine.setTextLabel(labelName)
        self.textList = base.textEngine.getDialogue()
        self.processLine(self.textList[self.textIndex])

    def processLine(self, line):
        if line['type'] == 'text':
            self.dialogueLine(line)
        elif line['type'] == 'menu':
            self.choiceLine(line)

    def choiceLine(self, lineObj):
        self.setFrameText(lineObj['text'])
        self.setFrameChoices(lineObj)
        self.show()

    def dialogueLine(self, lineObj):
        self.setFrameActor(lineObj['actor'])
        self.setFrameText(lineObj['line'])
        self.show()

    def showMessage(self, txt):
        self.setFrameText(txt)
        self.show()

    def setFrameChoices(self, lineObj):
        base.resetButtons()
        if self.frameChoices:
            self.frameChoices.quit()

        optionsList = lineObj['options']
        self.frameChoices = GUIDialogOptions(optionsList)
        self.frameChoices.reparentTo(self.mainFrame)
        taskMgr.add(self.frameChoices.readKeys, "readKeysTask")
        for option in optionsList:
            index = optionsList.index(option)
            base.accept("TextChoice-{}".format(index), self.chooseOption,
                        [lineObj, index])

    def destroyFrameChoices(self, optionsList):
        self.frameChoices.quit()
        self.frameChoices = None
        taskMgr.remove("readKeysTask")
        for option in optionsList:
            index = optionsList.index(option)
            base.ignore("TextChoice-{}".format(index))

    def chooseOption(self, lineObj, index):
        base.textEngine.chooseFromMenu(lineObj, index)
        self.destroyFrameChoices(lineObj['options'])
        self.textList = base.textEngine.getDialogue()
        self.textIndex = 0
        self.processLine(self.textList[self.textIndex])

    def setFrameActor(self, text):
        if self.frameActor:
            self.frameActor.detach_node()
        self.frameActor = OnscreenText(text=text,
                                       pos=(-1.2, -0.55),
                                       scale=0.07,
                                       wordwrap=35,
                                       mayChange=False,
                                       align=TextNode.ALeft,
                                       fg=(1, 1, 1, 1),
                                       shadow=(0, 0, 0, 1),
                                       shadowOffset=(0.05, 0.05))
        self.frameActor.reparentTo(self.mainFrame)

    def setFrameText(self, text):
        if self.frameText:
            self.frameText.detach_node()
        self.frameText = OnscreenText(text=text,
                                      pos=(-1.2, -0.65),
                                      scale=0.07,
                                      wordwrap=35,
                                      mayChange=False,
                                      align=TextNode.ALeft,
                                      fg=(1, 1, 1, 1),
                                      shadow=(0, 0, 0, 1),
                                      shadowOffset=(0.05, 0.05))
        self.frameText.reparentTo(self.mainFrame)

    def show(self):
        self.mainFrame.show()

    def hide(self):
        self.mainFrame.hide()
        if self.frameText:
            self.frameText.detach_node()
        if self.frameActor:
            self.frameActor.detach_node()
        self.textIndex = 0
        self.frameText = None

    def next(self):
        if not self.isCalling:
            self.isCalling = True
            taskMgr.doMethodLater(.1, self.nextText, 'Next Text')

    def nextText(self, task):
        if self.textIndex < len(self.textList) - 1:
            self.textIndex += 1
            self.processLine(self.textList[self.textIndex])
        else:
            self.hide()

        self.isCalling = False
        return task.done

    @property
    def isShowing(self):
        return self.frameText != None

    @property
    def isChoices(self):
        return self.frameChoices != None

    def reparentTo(self, target):
        self.mainFrame.reparentTo(target)

    def removeNode(self):
        self.mainFrame.removeNode()
コード例 #50
0
class GroupTrackerPage(ShtikerPage.ShtikerPage):
    notify = directNotify.newCategory('GroupTrackerPage')

    def __init__(self):
        ShtikerPage.ShtikerPage.__init__(self)
        self.groupWidgets = []
        self.playerWidgets = []
        self.images = []  # image nodes: Possible images to apply on groups
        self.scrollList = None  # DirectScrolledList: Holds the GroupTrackerGroup widgets
        self.scrollTitle = None  # DirectLabel: Title of the list that holds the groups
        self.playerList = None  # DirectScrolledList: Holds players when showing a specific group details
        self.playerListTitle = None  # DirectLabel: Title of the playerList
        self.groupInfoTitle = None  # DirectLabel: holds the group detail title to show on the right
        self.groupInfoDistrict = None  # DirectLabel: shows group detail district on the right
        self.statusMessage = None  # DirectLabel: Shows important messages like Loading... or "No boarding groups available"
        self.groupIcon = None  # DirectButton: Icon to associate with the group ex. sellbot icon or cashbot icon depending on group info
        self.wantGroupToggle = None  # DirectButton: Allows the toon to toggle his listing

    def load(self):
        self.listXorigin = -0.02
        self.listFrameSizeX = 0.67
        self.listZorigin = -0.96
        self.listFrameSizeZ = 1.04
        self.arrowButtonScale = 1.3
        self.itemFrameXorigin = -0.237
        self.itemFrameZorigin = 0.365
        self.buttonXstart = self.itemFrameXorigin + 0.293
        self.gui = loader.loadModel('phase_3.5/models/gui/friendslist_gui')
        guiButton = loader.loadModel('phase_3/models/gui/quit_button')
        self.scrollList = DirectScrolledList(
            parent=self,
            relief=None,
            pos=(-0.5, 0, 0),
            incButton_image=(self.gui.find('**/FndsLst_ScrollUp'),
                             self.gui.find('**/FndsLst_ScrollDN'),
                             self.gui.find('**/FndsLst_ScrollUp_Rllvr'),
                             self.gui.find('**/FndsLst_ScrollUp')),
            incButton_relief=None,
            incButton_scale=(self.arrowButtonScale, self.arrowButtonScale,
                             -self.arrowButtonScale),
            incButton_pos=(self.buttonXstart, 0,
                           self.itemFrameZorigin - 0.999),
            incButton_image3_color=Vec4(1, 1, 1, 0.2),
            decButton_image=(self.gui.find('**/FndsLst_ScrollUp'),
                             self.gui.find('**/FndsLst_ScrollDN'),
                             self.gui.find('**/FndsLst_ScrollUp_Rllvr'),
                             self.gui.find('**/FndsLst_ScrollUp')),
            decButton_relief=None,
            decButton_scale=(self.arrowButtonScale, self.arrowButtonScale,
                             self.arrowButtonScale),
            decButton_pos=(self.buttonXstart, 0,
                           self.itemFrameZorigin + 0.227),
            decButton_image3_color=Vec4(1, 1, 1, 0.2),
            itemFrame_pos=(self.itemFrameXorigin, 0, self.itemFrameZorigin),
            itemFrame_scale=1.0,
            itemFrame_relief=DGG.SUNKEN,
            itemFrame_frameSize=(self.listXorigin,
                                 self.listXorigin + self.listFrameSizeX,
                                 self.listZorigin,
                                 self.listZorigin + self.listFrameSizeZ),
            itemFrame_frameColor=(0.85, 0.95, 1, 1),
            itemFrame_borderWidth=(0.01, 0.01),
            numItemsVisible=15,
            forceHeight=0.065,
            items=self.groupWidgets)

        self.scrollTitle = DirectFrame(parent=self.scrollList,
                                       text=TTLocalizer.GroupTrackerListTitle,
                                       text_scale=0.06,
                                       text_align=TextNode.ACenter,
                                       relief=None,
                                       pos=(self.buttonXstart, 0,
                                            self.itemFrameZorigin + 0.127))

        self.playerList = DirectScrolledList(
            parent=self,
            relief=None,
            pos=(0.45, 0, 0.1),
            incButton_image=(self.gui.find('**/FndsLst_ScrollUp'),
                             self.gui.find('**/FndsLst_ScrollDN'),
                             self.gui.find('**/FndsLst_ScrollUp_Rllvr'),
                             self.gui.find('**/FndsLst_ScrollUp')),
            incButton_relief=None,
            incButton_scale=(1.0, 1.0, -1.0),
            incButton_pos=(0, 0, -0.28),
            incButton_image3_color=Vec4(1, 1, 1, 0.05),
            decButton_image=(self.gui.find('**/FndsLst_ScrollUp'),
                             self.gui.find('**/FndsLst_ScrollDN'),
                             self.gui.find('**/FndsLst_ScrollUp_Rllvr'),
                             self.gui.find('**/FndsLst_ScrollUp')),
            decButton_relief=None,
            decButton_scale=(1.0, 1.0, 1.0),
            decButton_pos=(0.0, 0, 0.04),
            decButton_image3_color=Vec4(1, 1, 1, 0.25),
            itemFrame_pos=(0, 0, -0.05),
            itemFrame_scale=1.0,
            itemFrame_relief=DGG.SUNKEN,
            itemFrame_frameSize=(
                -0.3,
                0.3,  #x
                -0.2,
                0.06),  #z
            itemFrame_frameColor=(0.85, 0.95, 1, 1),
            itemFrame_borderWidth=(0.01, 0.01),
            numItemsVisible=4,
            forceHeight=0.05,
            items=self.playerWidgets)

        self.playerListTitle = DirectFrame(parent=self.playerList,
                                           text='',
                                           text_scale=0.05,
                                           text_align=TextNode.ACenter,
                                           relief=None,
                                           pos=(0, 0, 0.08))
        self.groupInfoTitle = DirectLabel(parent=self,
                                          text='',
                                          text_scale=0.080,
                                          text_align=TextNode.ACenter,
                                          text_wordwrap=15,
                                          relief=None,
                                          pos=(0.45, 0, 0.5))
        self.groupInfoDistrict = DirectLabel(parent=self,
                                             text='',
                                             text_scale=0.050,
                                             text_align=TextNode.ACenter,
                                             text_wordwrap=15,
                                             relief=None,
                                             pos=(0.45, 0, 0.4))

        self.statusMessage = DirectLabel(parent=self,
                                         text='',
                                         text_scale=0.060,
                                         text_align=TextNode.ACenter,
                                         text_wordwrap=5,
                                         relief=None,
                                         pos=(0.45, 0, 0.1))

        # Group Image:
        self.groupIcon = DirectButton(parent=self,
                                      relief=None,
                                      state=DGG.DISABLED,
                                      image=None,
                                      image_scale=(0.35, 1, 0.35),
                                      image_color=Vec4(1.0, 1.0, 1.0, 0.75),
                                      pos=(0.45, 10, -0.45),
                                      command=self.doNothing)

        # Group Toggle:
        self.wantGroupToggle = DirectButton(
            parent=self,
            relief=None,
            image=(guiButton.find('**/QuitBtn_UP'),
                   guiButton.find('**/QuitBtn_DN'),
                   guiButton.find('**/QuitBtn_RLVR')),
            image_scale=(0.7, 1, 1),
            text='',
            text_scale=0.052,
            text_pos=(0, -0.02),
            pos=(0.2, 0, -0.65),
            command=self.toggleWantGroup)
        self.updateWantGroupButton()

        # Loading possible group icons
        suitIcons = loader.loadModel('phase_3/models/gui/cog_icons')
        bossbotIcon = suitIcons.find('**/CorpIcon')
        bossbotIcon.setColor(SUIT_ICON_COLORS[0])
        self.images.append(bossbotIcon)

        lawbotIcon = suitIcons.find('**/LegalIcon')
        lawbotIcon.setColor(SUIT_ICON_COLORS[1])
        self.images.append(lawbotIcon)

        cashbotIcon = suitIcons.find('**/MoneyIcon')
        cashbotIcon.setColor(SUIT_ICON_COLORS[2])
        self.images.append(cashbotIcon)

        sellbotIcon = suitIcons.find('**/SalesIcon')
        sellbotIcon.setColor(SUIT_ICON_COLORS[3])
        self.images.append(sellbotIcon)

        # Clean up
        self.clearGroupInfo()
        self.statusMessage.hide()

        suitIcons.removeNode()
        self.gui.removeNode()
        guiButton.removeNode()

        self.accept('GroupTrackerResponse', self.updatePage)

    def unload(self):
        self.scrollList.destroy()
        self.groupInfoDistrict.destroy()
        self.playerList.destroy()
        self.groupInfoTitle.destroy()
        self.groupIcon.destroy()
        self.wantGroupToggle.destroy()
        for widget in self.playerWidgets:
            widget.destroy()
        for widget in self.groupWidgets:
            widget.destroy()
        self.playerWidgets = []

        del self.scrollList
        del self.groupInfoDistrict
        del self.playerList
        del self.groupInfoTitle
        del self.groupIcon
        del self.wantGroupToggle
        ShtikerPage.ShtikerPage.unload(self)

    def enter(self):
        ShtikerPage.ShtikerPage.enter(self)
        self.setGroups([])  # CLEAR IT ALL
        self.setPlayers()  # CLEAR IT ALL
        if (self.scrollList['items'] == []):
            self.statusMessage['text'] = TTLocalizer.GroupTrackerLoading
            self.statusMessage.show()
        base.cr.globalGroupTracker.requestGroups()
        taskMgr.doMethodLater(3, self.displayNoGroupsTaskHandler,
                              self.uniqueName('timeout'))

    def displayNoGroups(self):
        self.statusMessage['text'] = TTLocalizer.GroupTrackerEmpty
        self.statusMessage.show()
        self.clearGroupInfo()

    def displayNoGroupsTaskHandler(self, task):
        self.displayNoGroups()
        return task.done

    def updatePage(self):
        taskMgr.remove(self.uniqueName('timeout'))
        groups = base.cr.globalGroupTracker.getGroupInfo()
        self.setGroups(groups)

    def exit(self):
        self.clearGroupInfo()
        ShtikerPage.ShtikerPage.exit(self)
        base.cr.globalGroupTracker.doneRequesting()

    def updateGroupInfoEventHandle(self, groupWidget, mouseEvent):
        self.updateGroupInfo(groupWidget)

    def updateGroupInfo(self, groupWidget):
        ''' Updates the Right Page of the Group Tracker Page with new Info '''
        self.statusMessage.hide()

        # Update the Player List
        self.setPlayers(groupWidget)
        self.playerList.show()

        # Update the Player List Title
        self.playerListTitle['text'] = ('Players ' +
                                        str(groupWidget.getCurrentPlayers()) +
                                        '/' +
                                        str(groupWidget.getMaxPlayers()) + ':')
        self.playerListTitle.show()

        # Update the District
        self.groupInfoDistrict[
            'text'] = TTLocalizer.BoardingGroupDistrictInformation % {
                'district': groupWidget.getDistrict()
            }
        self.groupInfoDistrict.show()

        # Update the Title
        self.groupInfoTitle['text'] = groupWidget.getTitle()
        self.groupInfoTitle.show()

        # Update the Image
        self.groupIcon['image'] = self.images[
            GroupTrackerGlobals.CATEGORY_TO_IMAGE_ID[
                groupWidget.getCategory()]]
        self.groupIcon['image_scale'] = (0.35, 1, 0.35)
        self.groupIcon.show()

    def clearGroupInfo(self):
        self.playerList.hide()
        self.playerListTitle.hide()
        self.groupInfoDistrict.hide()
        self.groupInfoTitle.hide()
        self.groupIcon.hide()

    def setPlayers(self, groupWidget=None):
        ''' Calls updatePlayerList '''

        # Clear the Widgets that were held in the listings
        for playerWidget in self.playerWidgets:
            playerWidget.destroy()
        self.playerWidgets = []

        # Make a player widget for each player
        # TODO: Edit this stuff when avIds come from players
        if groupWidget:
            leaderId = groupWidget.getLeaderId()
            playerNames = groupWidget.getMemberNames()
            playerIds = groupWidget.getMemberIds()
            for playerName in playerNames:
                playerId = playerIds[playerNames.index(playerName)]
                isLeader = playerId == leaderId
                self.playerWidgets.append(
                    GroupTrackerPlayer(parent=self,
                                       avId=playerId,
                                       name=playerName,
                                       isLeader=isLeader))

        self.updatePlayerList()

    def reconsiderGroupInfo(self, groupWidget):
        ''' If someone is viewing this info and it was updated, we also want to update the info being viewed '''
        if self.playerWidgets is None or self.playerList['items'] == []:
            return  # No Info is being viewed at the moment since you cant have an empty group

        # We have to update if this group's leader is the leader in the playerlist being viewed right now
        leaderId = groupWidget.getLeaderId()

        # Check all the players in the playerList being viewed for the same leader
        for playerWidget in self.playerWidgets:
            if playerWidget.getLeader():
                if leaderId == playerWidget.getId():
                    self.updateGroupInfo(groupWidget)
                    return False

        return True

    def setGroups(self, groups):
        ''' Calls updateGroupList '''

        # Clear our Group Widgets
        for group in self.groupWidgets:
            group.destroy()
        self.groupWidgets = []

        wantReconsiderInfo = True

        # Create a new group widget for each group
        for group in groups:
            if not group[GroupTrackerGlobals.SHOW] or len(
                    group[GroupTrackerGlobals.MEMBER_IDS]) == 0:
                continue  # We are using this to see if this group is dead or if someone doesnt want it up
            leaderId = 0
            for i, g in base.cr.globalGroupTracker.leader2Group.items():
                if g == group:
                    leaderId = i
            if not leaderId:
                continue

            leaderName = group[GroupTrackerGlobals.LEADER_NAME]
            shardName = group[GroupTrackerGlobals.SHARD_NAME]
            category = group[GroupTrackerGlobals.CATEGORY]
            memberIds = group[GroupTrackerGlobals.MEMBER_IDS]
            memberNames = group[GroupTrackerGlobals.MEMBER_NAMES]

            groupWidget = GroupTrackerGroup(parent=self,
                                            leaderId=leaderId,
                                            leaderName=leaderName,
                                            shardName=shardName,
                                            category=category,
                                            memberIds=memberIds,
                                            memberNames=memberNames)
            groupWidget.bind(DGG.WITHIN,
                             self.updateGroupInfoEventHandle,
                             extraArgs=[groupWidget])
            self.groupWidgets.append(groupWidget)
            if wantReconsiderInfo:
                wantReconsiderInfo = self.reconsiderGroupInfo(groupWidget)

        # Edge case where a group that was removed, info might remain on the screen if it didn't exist any more
        if wantReconsiderInfo:
            self.clearGroupInfo()

        # There are no groups, hide the information
        if len(self.groupWidgets) == 0:
            self.displayNoGroups()
        self.updateGroupList()

    def updateGroupList(self):
        self.statusMessage.hide()
        if self.scrollList is None:
            return

        # Clear the Group Listing
        for item in self.scrollList['items']:
            if item:
                self.scrollList.removeItem(item, refresh=True)
        self.scrollList['items'] = []

        # Re-populate the Group Listing
        for groupWidget in self.groupWidgets:
            self.scrollList.addItem(groupWidget, refresh=True)

        if len(self.groupWidgets) == 0:
            self.displayNoGroups()

    def updatePlayerList(self):
        if self.playerList is None:
            return

        # Clear the Player Listing
        for item in self.playerList['items']:
            if item:
                self.playerList.removeItem(item)
        self.playerList['items'] = []

        # Re-Populate the List
        for playerWidget in self.playerWidgets:
            self.playerList.addItem(playerWidget)

    def toggleWantGroup(self):
        if settings.get('grouptracker', False):
            settings['grouptracker'] = False
            base.cr.globalGroupTracker.showMe(False)
        else:
            settings['grouptracker'] = True
            base.cr.globalGroupTracker.showMe(True)

        base.localAvatar.wantGroupTracker()

        base.localAvatar.wantGroupTracker(
        )  # Updates the ai toon so the boarding group AI could know what he wants
        self.updateWantGroupButton()

    def updateWantGroupButton(self):
        if settings.get('grouptracker', False):
            self.wantGroupToggle['text'] = 'Hide Me'
        else:
            self.wantGroupToggle['text'] = 'Show Me'

    def doNothing(self):
        pass
コード例 #51
0
ファイル: developerconsole.py プロジェクト: Joelone/IsisWorld
class DeveloperConsole(InteractiveInterpreter, DirectObject):
  """The name says it all."""
  def __init__(self):
    sys.stdout = PseudoFile(self.writeOut)
    sys.stderr = PseudoFile(self.writeErr)
    tpErr = TextProperties()
    tpErr.setTextColor(1, 0.5, 0.5, 1)
    TextPropertiesManager.getGlobalPtr().setProperties("err", tpErr)
    #font = loader.loadFont("cmss12")
    self.frame = DirectFrame(parent = base.a2dTopCenter, text_align = TextNode.ALeft, text_pos = (-base.getAspectRatio() + TEXT_MARGIN[0], TEXT_MARGIN[1]), text_scale = 0.05, text_fg = (1, 1, 1, 1), frameSize = (-2.0, 2.0, -0.5, 0.0), frameColor = (0, 0, 0, 0.5), text = '')#, text_font = font)
    self.entry = DirectEntry(parent = base.a2dTopLeft, command = self.command, scale = 0.05, width = 1000.0, pos = (-0.02, 0, -0.48), relief = None, text_pos = (1.5, 0, 0), text_fg = (1, 1, 0.5, 1), rolloverSound = None, clickSound = None)#, text_font = font)
    self.otext = OnscreenText(parent = self.entry, scale = 1, align = TextNode.ALeft, pos = (1, 0, 0), fg = (1, 1, 0.5, 1), text = ':')#, font = font)
    self.lines = [''] * 9
    self.commands = []  # All previously sent commands
    self.cscroll = None # Index of currently navigated command, None if current
    self.command = ''   # Currently entered command
    self.block = ''     # Temporarily stores a block of commands
    self.hide()
    self.initialized = False
  
  def prevCommand(self):
    if self.hidden: return
    if len(self.commands) == 0: return
    if self.cscroll == None:
      self.cscroll = len(self.commands)
      self.command = self.entry.get()
    elif self.cscroll <= 0:
      return
    else:
      self.commands[self.cscroll] = self.entry.get()
    self.cscroll -= 1
    self.entry.set(self.commands[self.cscroll])
    self.entry.setCursorPosition(len(self.commands[self.cscroll]))
  
  def nextCommand(self):
    if self.hidden: return
    if len(self.commands) == 0: return
    if self.cscroll == None: return
    self.commands[self.cscroll] = self.entry.get()
    self.cscroll += 1
    if self.cscroll >= len(self.commands):
      self.cscroll = None
      self.entry.set(self.command)
      self.entry.setCursorPosition(len(self.command))
    else:
      self.entry.set(self.commands[self.cscroll])
      self.entry.setCursorPosition(len(self.commands[self.cscroll]))

  def writeOut(self, line, copy = True):
    if copy: sys.__stdout__.write(line)
    lines = line.split('\n')
    firstline = lines.pop(0)
    self.lines[-1] += firstline
    self.lines += lines
    self.frame['text'] = '\n'.join(self.lines[-9:])

  def writeErr(self, line, copy = True):
    if copy: sys.__stderr__.write(line)
    line = '\1err\1%s\2' % line
    lines = line.split('\n')
    firstline = lines.pop(0)
    self.lines[-1] += firstline
    self.lines += lines
    self.frame['text'] = '\n'.join(self.lines[-9:])

  def command(self, text):
    if not self.hidden:
      self.cscroll = None
      self.command = ''
      self.entry.set('')
      self.entry['focus'] = True
      self.writeOut(self.otext['text'] + ' ' + text + '\n', False)
      if text != '' and (len(self.commands) == 0 or self.commands[-1] != text):
        self.commands.append(text)
      
      # Insert plugins into the local namespace
      locals = __main__.__dict__
      #locals['manager'] = self.manager
      #for plugin in self.manager.named.keys():
      #  locals[plugin] = self.manager.named[plugin]
      locals['panda3d'] = panda3d
      
      # Run it and print the output.
      if not self.initialized:
        InteractiveInterpreter.__init__(self, locals = locals)
        self.initialized = True
      try:
        if self.runsource(self.block + '\n' + text) and text != '':
          self.otext['text'] = '.'
          self.block += '\n' + text
        else:
          self.otext['text'] = ':'
          self.block = ''      
      except Exception: # Not just "except", it will also catch SystemExit
        # Whoops! Print out a traceback.
        self.writeErr(traceback.format_exc())

  def toggle(self):
    if self.hidden:
      self.show()
    else:
      self.hide()

  def show(self):
    self.accept('arrow_up', self.prevCommand)
    self.accept('arrow_up-repeat', self.prevCommand)
    self.accept('arrow_down', self.nextCommand)
    self.accept('arrow_down-repeat', self.nextCommand)
    self.hidden = False
    self.entry['focus'] = True
    self.frame.show()
    self.entry.show()
    self.otext.show()

  def hide(self):
    self.ignoreAll()
    self.hidden = True
    self.entry['focus'] = False
    self.frame.hide()
    self.entry.hide()
    self.otext.hide()

  def destroy(self):
    sys.stdout = sys.__stdout__
    sys.stderr = sys.__stderr__
    self.ignoreAll()
    self.frame.destroy()
    self.entry.destroy()
    self.otext.destroy()
コード例 #52
0
ファイル: craftingGui.py プロジェクト: grimfang/OWP_Miner
class CraftInventory(DirectObject):
    def __init__(self):
        self.itemFrame = DirectScrolledFrame(
            text="Inventory",
            text_scale=0.25,
            text_pos=(0, 0.75, 0),
            text_bg=(1, 1, 1, 1),
            # make the frame occupy the whole window
            frameSize=(-0.6, 0.6, -0.8, 0.8),
            pos=(-0.7, 0, 0),
            # make the canvas as big as the frame
            canvasSize=(-0.6, 0.6, -0.8, 0.8),
            # set the frames color to white
            frameColor=(1, 1, 1, 1),
        )
        self.itemList = []

        self.craftFrame = DirectFrame(
            text="Crafting",
            text_scale=0.25,
            text_pos=(0, 0.75, 0),
            text_bg=(1, 1, 1, 1),
            # make the frame occupy the whole window
            frameSize=(-0.6, 0.6, -0.8, 0.8),
            pos=(0.7, 0, 0),
            # set the frames color to white
            frameColor=(1, 1, 1, 1),
        )
        self.craftDrop = DirectFrame(
            text="drop ore",
            text_scale=0.1,
            pos=(0, 0.4, 0),
            frameSize=(-0.25, 0.25, -0.25, 0.25),
            frameColor=(1, 0, 0, 1),
        )
        self.craftDrop.reparentTo(self.craftFrame)

    def show(self):
        self.itemFrame.show()
        self.craftFrame.show()

    def hide(self):
        self.itemFrame.hide()
        self.craftFrame.hide()

    def __makeItem(self, item):
        obj = DirectLabel(
            text=str(item.giveLoot()) + "x " + item.giveType(),
            text_scale=0.5,
            text_pos=(0, -1, 0),
            image=("item.png", "item_hover.png", "item.png"),  # normal, hover, disabled
            scale=0.16,
            numStates=2,
            state=DGG.NORMAL,
            relief=DGG.GROOVE,
        )
        obj.setTransparency(True)
        obj["activeState"] = 0
        obj.reparentTo(self.itemFrame.getCanvas())
        obj.bind(DGG.B1PRESS, self.dragStart, [obj])
        obj.bind(DGG.B1RELEASE, self.dragStop)
        obj.bind(DGG.ENTER, self.inObject, [obj])
        obj.bind(DGG.EXIT, self.outObject, [obj])
        return obj

    def updateList(self, items):
        for item in self.itemList:
            item.destroy()
        i = 1
        j = 0
        pad = 0.2
        numItemsPerRow = 2
        itemWidth = 0.32
        itemHeight = 0.32
        # left = -(itemWidth * (numItemsPerRow/2.0)) - 0.16
        left = self.itemFrame.getX()  # + (itemWidth + 0.16)
        xStep = itemWidth + 0.13
        yStep = -(itemHeight + 0.13)
        top = 0.8 - (0.16 + pad)
        for item in items:
            self.itemList.append(self.__makeItem(item))
            x = left + i * xStep
            y = top + j * yStep
            self.itemList[-1].setPos(x, 0.0, y)
            if i == numItemsPerRow:
                i = 0
                j += 1
            i += 1
        if i == 1:
            j -= 1
        height = ((j) * -yStep) - 0.16
        # resize the canvas. This will make the scrollbars dis-/appear,
        # dependent on if the canvas is bigger than the frame size.
        self.itemFrame["canvasSize"] = (-0.6, 0.6, -height, 0.8)

    def inObject(self, element, event):
        # Can be used to highlight objects
        element["activeState"] = 1
        element.setActiveState()
        # print "over object"

    def outObject(self, element, event):
        # Can be used to unhighlight objects
        # element["state"] = 0
        element["activeState"] = 0
        element.setActiveState()

    def dragStart(self, element, event):
        print "start drag"
        taskMgr.remove("dragDropTask")
        vWidget2render2d = element.getPos(render2d)
        vMouse2render2d = Point3(event.getMouse()[0], 0, event.getMouse()[1])
        editVec = Vec3(vWidget2render2d - vMouse2render2d)
        t = taskMgr.add(self.dragTask, "dragDropTask")
        element.reparentTo(aspect2d)
        t.element = element
        t.editVec = editVec
        t.elementStartPos = element.getPos()

    def dragTask(self, state):
        mwn = base.mouseWatcherNode
        if mwn.hasMouse():
            vMouse2render2d = Point3(mwn.getMouse()[0], 0, mwn.getMouse()[1])
            newPos = vMouse2render2d + state.editVec
            state.element.setPos(render2d, newPos)
        return Task.cont

    def dragStop(self, event):
        print "stop drag with:", event
        isInArea = False

        t = taskMgr.getTasksNamed("dragDropTask")[0]
        # for dropArea in self.dropAreas:
        #    if self.isInBounds(event.getMouse(), dropArea["frameSize"], dropArea.getPos(render)):
        #        print "inside Area:", dropArea["text"], dropArea.getPos(render)
        #        isInArea = True
        #        t.element.setPos(dropArea.getPos(render))
        #        t.element.setX(t.element.getX() * self.ratio)
        #        #t.element.setX(t.element.getX() - t.element.getWidth() / 2.0)
        #        break

        if not isInArea:
            t.element.setPos(t.elementStartPos)
            t.element.reparentTo(self.itemFrame.getCanvas())
        taskMgr.remove("dragDropTask")

    def isInBounds(self, location, bounds, posShift=None):
        x = 0 if posShift is None else posShift.getX()
        y = 0 if posShift is None else posShift.getZ()

        left = x + bounds[0]
        right = x + bounds[1]
        bottom = y + bounds[2]
        top = y + bounds[3]

        # are we outside of the bounding box from the left
        if location[0] < left:
            return False
        # are we outside of the bounding box from the right
        if location[0] > right:
            return False
        # are we outside of the bounding box from the bottom
        if location[1] < bottom:
            return False
        # are we outside of the bounding box from the top
        if location[1] > top:
            return False
        # the location is inside the bbox
        return True
コード例 #53
0
 def show(self):
     taskMgr.add(self.initMarker, 'questMapInit')
     DirectFrame.show(self)
     self.mapOpenButton.hide()
     if self.container['image']:
         self.mapCloseButton.show()
コード例 #54
0
class JukeboxGui(DirectObject):
    notify = directNotify.newCategory('JukeboxGui')
    CLOSE_EVENT = 'JukeboxGui_CLOSE_EVENT'
    SONG_SELECT_EVENT = 'JukeboxGui_SONG_SELECT_EVENT'
    QUEUE_SELECT_EVENT = 'JukeboxGui_QUEUE_SELECT_EVENT'
    ADD_SONG_CLICK_EVENT = 'JukeboxGui_ADD_SONG_CLICK_EVENT'
    MOVE_TO_TOP_CLICK_EVENT = 'JukeboxGUI_MOVE_TO_TOP_EVENT'

    def __init__(self, phaseToMusicData):
        self._loaded = False
        self._timerGui = None
        self._windowFrame = None
        self.phaseToMusicData = phaseToMusicData
        return

    def load(self):
        if self.isLoaded():
            return
        guiNode = loader.loadModel('phase_13/models/parties/jukeboxGUI')
        self._timerGui = PartyUtils.getNewToontownTimer()
        self._windowFrame = DirectFrame(image=guiNode.find('**/background'), relief=None, pos=(0, 0, 0), scale=0.7)
        self._songFrame = DirectFrame(image=guiNode.find('**/songTitle_background'), parent=self._windowFrame, relief=None)
        self._currentlyPlayingLabel = self.__createLabel(guiNode, 'currentlyPlaying', parent=self._windowFrame, text=TTLocalizer.JukeboxCurrentlyPlayingNothing, scale=TTLocalizer.JGcurrentlyPlayingLabel)
        self._songNameLabel = self.__createLabel(guiNode, 'songName', parent=self._windowFrame, text=TTLocalizer.JukeboxCurrentSongNothing, scale=TTLocalizer.JGsongNameLabel)
        self._queueList, self._queueLabel = self.__createLabeledScrolledList(guiNode, 'queue', label=TTLocalizer.JukeboxQueueLabel, parent=self._windowFrame)
        self._songsList, self._songsLabel = self.__createLabeledScrolledList(guiNode, 'songs', label=TTLocalizer.JukeboxSongsLabel, parent=self._windowFrame)
        pos = guiNode.find('**/addButton_text_locator').getPos()
        self._addSongButton = self.__createButton(guiNode, 'addSongButton', parent=self._windowFrame, command=self.__handleAddSongButtonClick, image3_color=Vec4(0.6, 0.6, 0.6, 0.6), text=TTLocalizer.JukeboxAddSong, text_align=TextNode.ACenter, text_pos=(pos[0], pos[2]), text_scale=TTLocalizer.JGaddSongButton)
        self._closeButton = self.__createButton(guiNode, 'can_cancelButton', parent=self._windowFrame, command=self.__handleCloseButtonClick)
        pos = guiNode.find('**/close_text_locator').getPos()
        self._closeButton = self.__createButton(guiNode, 'close', parent=self._windowFrame, command=self.__handleCloseButtonClick, text=TTLocalizer.JukeboxClose, text_align=TextNode.ACenter, text_pos=(pos[0], pos[2]), text_scale=0.08)
        self._moveToTopButton = self.__createButton(guiNode, 'moveToTop', command=self.__handleMoveToTopButtonClick)
        guiNode.removeNode()
        self._loaded = True
        return

    def __createButton(self, guiNode, imagePrefix, parent = hidden, **kwargs):
        return DirectButton(parent=parent, relief=None, image=(guiNode.find('**/%s_up' % imagePrefix), guiNode.find('**/%s_down' % imagePrefix), guiNode.find('**/%s_rollover' % imagePrefix)), **kwargs)

    def __createLabel(self, guiNode, locatorPrefix, parent = hidden, **kwargs):
        return DirectLabel(parent=parent, relief=None, pos=guiNode.find('**/%s_text_locator' % locatorPrefix).getPos(), **kwargs)

    def __createLabeledScrolledList(self, guiNode, namePrefix, label, parent = hidden, **kwargs):
        return (DirectScrolledList(parent=parent, relief=None, incButton_image=(guiNode.find('**/%sButtonDown_up' % namePrefix), guiNode.find('**/%sButtonDown_down' % namePrefix), guiNode.find('**/%sButtonDown_rollover' % namePrefix)), incButton_relief=None, incButton_image3_color=Vec4(0.6, 0.6, 0.6, 0.6), decButton_image=(guiNode.find('**/%sButtonUp_up' % namePrefix), guiNode.find('**/%sButtonUp_down' % namePrefix), guiNode.find('**/%sButtonUp_rollover' % namePrefix)), decButton_relief=None, decButton_image3_color=Vec4(0.6, 0.6, 0.6, 0.6), image=guiNode.find('**/%s_background' % namePrefix), itemFrame_relief=None, itemFrame_pos=guiNode.find('**/%sList_locator' % namePrefix).getPos(), itemFrame_scale=0.07, numItemsVisible=TTLocalizer.JGnumItemsVisible, items=[], **kwargs), self.__createLabel(guiNode, namePrefix, parent=parent, text=label, text_fg=(0.5, 1.0, 1.0, 1.0), text_shadow=(0.0, 0.0, 0.0, 1.0), scale=0.12))

    def enable(self, timer = 0):
        if not self.isLoaded():
            self.load()
            phase = 13
            tunes = self.phaseToMusicData[13]
            for filename, info in tunes.items():
                self.addToSongList(info[0], phase, filename, info[1])

            for phase, tunes in self.phaseToMusicData.items():
                if phase == 13:
                    continue
                for filename, info in tunes.items():
                    self.addToSongList(info[0], phase, filename, info[1])

        self._windowFrame.show()
        if timer > 0:
            self._timerGui.setTime(timer)
            self._timerGui.countdown(timer)
            self._timerGui.show()

    def disable(self):
        self._windowFrame.hide()
        self._timerGui.hide()

    def unload(self):
        self.ignoreAll()
        if not self.isLoaded():
            return
        if self._windowFrame is not None:
            self._windowFrame.destroy()
            self._windowFrame = None
            self._moveToTopButton.destroy()
            del self._moveToTopButton
        if self._timerGui is not None:
            self._timerGui.destroy()
            self._timerGui = None
        self._loaded = False
        return

    def isLoaded(self):
        return self._loaded

    def addToSongList(self, text, phase, filename, length):
        listItem = DirectScrolledListItem(relief=None, parent=self._songsList, text=text, text_align=TextNode.ALeft, text_pos=(0.0, 0.0, 0.0), text_scale=TTLocalizer.JGlistItem, text_fg=(0.0, 0.0, 0.0, 1.0), text1_fg=(1.0, 1.0, 1.0, 1.0), text1_bg=(0.0, 0.0, 1.0, 1.0), text2_fg=(0.0, 0.0, 1.0, 1.0), text3_bg=(0.0, 0.8, 0.0, 1.0), command=self.__handleSongListItemSelect, extraArgs=[])
        listItem.setPythonTag('value', (phase, filename, length))
        self._songsList.addItem(listItem)
        return listItem

    def __handleCloseButtonClick(self):
        self.disable()
        messenger.send(JukeboxGui.CLOSE_EVENT)

    def __handleMoveToTopButtonClick(self):
        messenger.send(JukeboxGui.MOVE_TO_TOP_CLICK_EVENT)

    def __handleSongListItemSelect(self):
        pass

    def __handleAddSongButtonClick(self):
        if hasattr(self._songsList, 'currentSelected'):
            song = self._songsList.currentSelected
            messenger.send(JukeboxGui.ADD_SONG_CLICK_EVENT, [song['text'], song.getPythonTag('value')])

    def disableAddSongButton(self):
        self._addSongButton['state'] = DirectGuiGlobals.DISABLED

    def enableAddSongButton(self):
        self._addSongButton['state'] = DirectGuiGlobals.NORMAL

    def addSongToQueue(self, text, highlight = False, moveToTopButton = False):
        listItem = DirectLabel(relief=None, parent=self._queueList, text=text, text_align=TextNode.ALeft, text_pos=(0.0, 0.0, 0.0), text_scale=TTLocalizer.JGlistItem)
        self._queueList.addItem(listItem)
        if highlight:
            listItem['text_fg'] = (0.0, 0.5, 0.0, 1.0)
            self._addSongButton['text'] = TTLocalizer.JukeboxReplaceSong
            listItem.setPythonTag('highlighted', True)
        if moveToTopButton and len(self._queueList['items']) > 1:
            self._moveToTopButton.reparentTo(listItem)
            self._moveToTopButton.setScale(self._windowFrame, 1.0)
            self._moveToTopButton.setPos(10.0, 0.0, 0.25)
            self._queueList.scrollTo(len(self._queueList['items']) - 1)
        return listItem

    def popSongFromQueue(self):
        if len(self._queueList['items']) > 0:
            item = self._queueList['items'][0]
            self._queueList.removeItem(item)
            if self._moveToTopButton.getParent() == item:
                self._moveToTopButton.reparentTo(hidden)
            if self._moveToTopButton.getParent() == item:
                self._moveToTopButton.reparentTo(hidden)
            if item.getPythonTag('highlighted') == True:
                self._addSongButton['text'] = TTLocalizer.JukeboxAddSong
            item.removeNode()
            return item
        return None

    def setSongCurrentlyPlaying(self, phase, filename):
        songs = self.phaseToMusicData.get(phase / 1)
        if songs:
            songName = songs.get(filename)
            if songName:
                self._songNameLabel['text'] = songName
                self._currentlyPlayingLabel['text'] = TTLocalizer.JukeboxCurrentlyPlaying

    def clearSongCurrentlyPlaying(self):
        self._currentlyPlayingLabel['text'] = TTLocalizer.JukeboxCurrentlyPlayingNothing
        self._songNameLabel['text'] = TTLocalizer.JukeboxCurrentSongNothing

    def pushQueuedItemToTop(self, item):
        self._queueList['items'].remove(item)
        self._queueList['items'].insert(0, item)
        if self._moveToTopButton.getParent() == item:
            self._moveToTopButton.reparentTo(hidden)
        self._queueList.refresh()