Esempio n. 1
0
    def setUpgrade(self, upgradeType, player):
        self.player = player
        self.upgrade = upgradeType
        if player is None or upgradeType is None:
            self.elements = [self.coinsText]
        else:
            pos = Location(Screen(0.6, 0), 'midtop')
            image = self.app.theme.sprites.upgradeImage(upgradeType)
            area = Area(
                RelativePoint(Screen(0.6, 0), (0, 52)),
                ScaledSize(50, 10), 'midtop')
            self.elements = [
                PictureElement(self.app, image, pos),
                self.coinsText,
            ]

            if upgradeType.enabled:
                self.elements.append(
                    CoinGauge(self.app, area, player, upgradeType))
            else:
                self.elements.append(
                    TextElement(self.app, 'DISABLED',
                        self.app.screenManager.fonts.ingameMenuFont,
                        Location(CanvasX(620, 68), 'midbottom'),
                        self.app.theme.colours.errorMessageColour))
Esempio n. 2
0
 def __init__(self, app):
     super(UpgradeDisplay, self).__init__(app)
     self.player = None
     self.upgrade = None
     self.coinsText = TextElement(
         self.app, '', self.app.screenManager.fonts.coinsDisplayFont,
         Location(Screen(0.65, 0.01), 'midtop'),
         self.app.theme.colours.coinsDisplayColour,
         shadow=True)
     self.elements = [self.coinsText]
Esempio n. 3
0
 def __init__(self, app):
     super(WinnerMsg, self).__init__(app)
     self.winnerMsg = TextElement(app, '',
                                  app.screenManager.fonts.winMessageFont,
                                  Location(Screen(0.5, 0.05),
                                           'midtop'), (64, 64, 64))
     self.background = SolidRect(
         app, (128, 128, 128), 150,
         PaddedRegion(self.winnerMsg, ScaledScalar(15)))
     self.elements = []
Esempio n. 4
0
    def toggleTerminal(self):
        if self.terminal is None:
            locs = {'app': self.app}
            if hasattr(self.app, 'getConsoleLocals'):
                locs.update(self.app.getConsoleLocals())
            self.terminal = console.TrosnothInteractiveConsole(
                self.app,
                self.app.screenManager.fonts.consoleFont,
                Region(size=Screen(1, 0.4), bottomright=Screen(1, 1)),
                locals=locs)
            self.terminal.interact().addCallback(self._terminalQuit)

        from trosnoth.utils.utils import timeNow
        if self.terminal in self.elements:
            if timeNow() > self._termWaitTime:
                self.elements.remove(self.terminal)
        else:
            self._termWaitTime = timeNow() + 0.1
            self.elements.append(self.terminal)
            self.setFocus(self.terminal)
Esempio n. 5
0
    def __init__(self,
                 app,
                 game,
                 onDisconnectRequest=None,
                 onConnectionLost=None,
                 replay=False,
                 authTag=0):
        super(GameInterface, self).__init__(app, game=game)
        self.localState.onShoxwave.addListener(self.localShoxwaveFired)
        self.localState.onGameInfoChanged.addListener(self.gameInfoChanged)
        self.world.onOpenChatReceived.addListener(self.openChat)
        self.world.onTeamChatReceived.addListener(self.teamChat)
        self.world.onReset.addListener(self.worldReset)
        self.world.onGrenadeExplosion.addListener(self.grenadeExploded)
        self.world.onTrosballExplosion.addListener(self.trosballExploded)
        self.world.onBomberExplosion.addListener(self.trosballExploded)
        self.world.uiOptions.onChange.addListener(self.uiOptionsChanged)

        self.authTag = authTag

        self.subscribedPlayers = set()

        self.onDisconnectRequest = Event()
        if onDisconnectRequest is not None:
            self.onDisconnectRequest.addListener(onDisconnectRequest)

        self.onConnectionLost = Event()
        if onConnectionLost is not None:
            self.onConnectionLost.addListener(onConnectionLost)
        self.game = game

        self.joinDialogReason = None

        self.keyMapping = keyboard.KeyboardMapping(keymap.default_game_keys)
        self.runningPlayerInterface = None
        self.updateKeyMapping()
        self.gameViewer = viewManager.GameViewer(self.app, self, game, replay)
        if replay:
            self.joinController = None
        else:
            self.joinController = JoinGameController(self.app, self, self.game)
        self.detailsInterface = DetailsInterface(self.app, self)
        self.winnerMsg = WinnerMsg(app)
        self.timingInfo = TimingInfo(
            app,
            self,
            Location(Canvas(307, 768), 'midbottom'),
            app.screenManager.fonts.consoleFont,
        )
        self.gameInfoDisplay = GameInfoDisplay(
            app, self, Region(topleft=Screen(0.01, 0.05),
                              size=Canvas(330, 200)))
        self.hotkeys = hotkey.Hotkeys(self.app, self.keyMapping,
                                      self.detailsInterface.doAction)
        self.terminal = None

        self.joinInProgress = False

        self.vcInterface = None
        if replay:
            self.vcInterface = ViewControlInterface(self.app, self)

        self.ready = False
        defer.maybeDeferred(game.addAgent, self).addCallback(self.addedAgent)

        self.setElements()