def __init__(self, app, game): super(GameTimer, self).__init__(app) self.world = game.world self.app = app # Change these constants to say where the box goes self.area = Area(FullScreenAttachedPoint(ScaledSize(0, -3), 'midtop'), ScaledSize(110, 35), 'midtop') self.lineWidth = max(int(3 * self.app.screenManager.scaleFactor), 1) # Anything more than width 2 looks way too thick if self.lineWidth > 2: self.lineWidth = 2 self.gameClock = clock.Clock( self.app, self.getTimeString, Location(FullScreenAttachedPoint(ScaledSize(0, 0), 'midtop'), 'midtop'), self.app.screenManager.fonts.timerFont, self.app.theme.colours.timerFontColour) self.elements = [self.gameClock] self.running = False # Seconds for half a flash self.flashCycle = 0.5 # Value the countdown has to get to before it starts to flash self.flashValue = 30
def refresh(self): if not self.isOpen(): return self.elements = [self.sayToTeam, self.input] initialY = 470 count = 0 for text, nick, colour, firstLine in reversed(self.messageBuffer): currentY = initialY - count * self.MESSAGE_GAP if currentY < 200 or count >= 10: break if firstLine and nick is not None: person = TextElement( self.app, text=nick, font=self.font, pos=Location( FullScreenAttachedPoint((20, currentY), 'topleft'), 'topleft'), colour=colour, shadow=True, ) xOffset = person._getRect().width self.elements.append(person) text = text[len(nick):] else: xOffset = 0 if nick is None: colour = self.app.theme.colours.serverChat else: colour = self.textColour message = TextElement( self.app, text=text, font=self.font, pos=Location( FullScreenAttachedPoint((20 + xOffset, currentY), 'topleft'), 'topleft'), colour=colour, shadow=True, ) self.elements.append(message) count += 1
def __init__(self, app, gameInterface): super(DetailsInterface, self).__init__(app) self.gameInterface = gameInterface # Maximum number of messages viewable at any one time maxView = 8 self.world = gameInterface.world self.player = None font = app.screenManager.fonts.messageFont self.currentMessages = MessageBank(self.app, maxView, 50, Location(FullScreenAttachedPoint(ScaledSize(-40,-40), 'bottomright'), 'bottomright'), 'right', 'bottom', font) # If we want to keep a record of all messages and their senders self.input = None self.inputText = None self.unobtrusiveGetter = None self.turretGauge = None self.reloadGauge = GunGauge(self.app, Area( FullScreenAttachedPoint(ScaledSize(0,-60), 'midbottom'), ScaledSize(100,30), 'midbottom')) self.respawnGauge = None self.itemGauge = ItemGauge(self.app, self.player) self.achievementBox = None self.currentUpgrade = None self.settingsMenu = SettingsMenu(app, onClose=self.hideSettings, showThemes=False) self.chatBox = ChatBox(app, self.world, self.gameInterface) menuloc = Location(FullScreenAttachedPoint((0,0), 'bottomleft'), 'bottomleft') self.menuManager = mainMenu.MainMenu(self.app, menuloc, self, self.gameInterface.keyMapping) self.upgradeDisplay = UpgradeDisplay(app) self.trajectoryOverlay = TrajectoryOverlay(app, gameInterface.gameViewer.viewManager, self.upgradeDisplay) self.gameVoteMenu = GameVoteMenu( app, self.world, onChange=self._castGameVote) self._gameVoteUpdateCounter = 0 self.elements = [ self.currentMessages, self.upgradeDisplay, self.reloadGauge, self.gameVoteMenu, self.chatBox, self.trajectoryOverlay, self.menuManager, self.itemGauge, ] self.upgradeMap = dict((upgradeClass.action, upgradeClass) for upgradeClass in allUpgrades)
def update(self, loop=False): self._resetPlayers() if not self.world.uiOptions.showReadyStates: yPos = self.yPos else: yPos = self.yPos + int(50 * self.scale) self.playerTable.pos = Location( FullScreenAttachedPoint((self.xPos, yPos), 'topright'), 'topright') try: pi = self.gameViewer.interface.runningPlayerInterface self.friendlyTeam = pi.player.team self.spectator = False except (AttributeError, KeyError): # This will occur if the player is not yet on a team self.friendlyTeam = self.world.teamWithId['A'] self.spectator = True for player in self.world.players: # getDetailsForLeaderBoard() returns dict with pID, nick, team, dead, coins etc. details = player.getDetailsForLeaderBoard() self.players[details['team']].append(details) self._sortTeam('A') self._sortTeam('B') self._sortTeam(NEUTRAL_TEAM_ID) self._updateTable() if loop: self.callDef = WeakCallLater(UPDATE_DELAY, self, 'update', True)
def __init__(self, app, world, interface): super(ChatBox, self).__init__(app) self.world = world self.app = app self.interface = interface self.font = self.app.screenManager.fonts.newChatFont self.frameColour = self.app.theme.colours.chatFrameColour self.insideColour = self.app.theme.colours.chatInsideColour self.textColour = self.app.theme.colours.chatNormalColour self.sayToTeam = TextElement( self.app, text="Say to team:", font=self.font, pos=Location(FullScreenAttachedPoint((20, 501), 'topleft'), 'topleft'), colour=self.textColour, shadow=True, ) self.inputPosition = Area( FullScreenAttachedPoint((145, 500), 'topleft'), (370, 20), 'topleft') self.input = InputBox(self.app, self.inputPosition, font=self.font) self.input.onEnter.addListener( lambda sender: self.hitEnter(sender.value)) self.input.onEsc.addListener(lambda sender: self.close()) self.input.onClick.addListener(self.setFocus) self.messages = MessageBank( self.app, 10, 100, Location(FullScreenAttachedPoint((20, 470), 'topleft'), 'topleft'), 'left', 'bottom', self.font) self._chatOpen = False self.teamChat = True self.player = None self.messageBuffer = [] self.MESSAGE_GAP = self.font.getHeight(self.app) self.elements = [self.messages]
def __init__(self, app, player, achievementId): super(AchievementBox, self).__init__(app) self.app = app self.player = player self.achievements = [achievementId] self.width = 453 self.height = 75 self._setColours() self.area = Area( FullScreenAttachedPoint(ScaledSize(0, -100), 'midbottom'), ScaledSize(self.width, self.height), 'midbottom') self.smlBox = Area( FullScreenAttachedPoint(ScaledSize(-self.width / 2 + 6, -104), 'midbottom'), ScaledSize(66, 66), 'bottomleft') self.titleText = TextElement( self.app, "ACHIEVEMENT UNLOCKED!", self.fonts.achievementTitleFont, Location( FullScreenAttachedPoint( ScaledSize(73 / 2, -100 - self.height + 10), 'midbottom'), 'midtop'), self.borderColour) self.nameText = TextElement( self.app, self.achievementDefs.getAchievementDetails(achievementId)[0], self.fonts.achievementNameFont, Location( FullScreenAttachedPoint(ScaledSize(73 / 2, -100 - 13), 'midbottom'), 'midbottom'), self.colours.black) self.elements = [self.titleText, self.nameText] self._updateImage() self.cycler = WeakLoopingCall(self, 'cycleAchievements') self.cycler.start(5.0, now=False)
def _updateRespawnGauge(self): player = self.player if self.respawnGauge is None: if player.dead: self.respawnGauge = RespawnGauge(self.app, Area( FullScreenAttachedPoint(ScaledSize(0,-20), 'midbottom'), ScaledSize(100,30), 'midbottom'), player, self.world) self.elements.append(self.respawnGauge) elif not player.dead: self.elements.remove(self.respawnGauge) self.respawnGauge = None
def _updateTurretGauge(self): player = self.player if self.turretGauge is None: if player.turret: self.turretGauge = TurretGauge(self.app, Area( FullScreenAttachedPoint(ScaledSize(0,-100), 'midbottom'), ScaledSize(100,30), 'midbottom'), player) self.elements.append(self.turretGauge) elif not player.turret: self.elements.remove(self.turretGauge) self.turretGauge = None
def __init__(self, app, game, gameViewer, shadow=False): super(LeaderBoard, self).__init__(app) self.world = game.world self.shadow = shadow self.gameViewer = gameViewer self.app = app self.scale = self.app.screenManager.scaleFactor self.xPos = 4 self.yPos = (self.gameViewer.miniMap.getRect().bottom + self.gameViewer.zoneBarHeight + 5) position = Location( FullScreenAttachedPoint((self.xPos, self.yPos), 'topright'), 'topright') # Create the table and set all the appropriate style attributes self.playerTable = table.Table(app, position, columns=4, topPadding=4) self.playerTable.setBorderWidth(0) self.playerTable.setBorderColour((0, 0, 0)) self.playerTable.style.backColour = None self.playerTable.style.foreColour = app.theme.colours.leaderboardNormal self.playerTable.style.font = app.screenManager.fonts.leaderboardFont self.playerTable.style.padding = (4, 1) self.playerTable.style.hasShadow = shadow self.playerTable.style.shadowColour = (0, 0, 0) self.playerTable.getColumn(0).style.textAlign = 'midright' self.playerTable.getColumn(1).style.textAlign = 'midright' self.playerTable.getColumn(2).style.textAlign = 'midright' self.rowHeight = Scalar(25) self.playerTable.getColumn(0).setWidth(30) # Flags self.playerTable.getColumn(1).setWidth(100) # Name self.playerTable.getColumn(2).setWidth(70) # Score self.playerTable.getColumn(3).setWidth(30) # Padding self._resetPlayers() self.elements = [self.playerTable] bgColour = app.theme.colours.leaderboardBackground if bgColour[3]: background = SolidRect(app, bgColour, bgColour[3], self.playerTable) self.elements.insert(0, background) self.update(True)
def __init__(self, app): super(TrosnothBackdrop, self).__init__(app) backdropPath = app.theme.getPath('startupMenu', 'blackdrop.png') backdrop = Backdrop(app, backdropPath, app.theme.colours.backgroundFiller) # Things that will be part of the backdrop of the entire startup menu # system. verFont = self.app.screenManager.fonts.versionFont self.elements = [ backdrop, TextElement(self.app, titleVersion, verFont, Location(FullScreenAttachedPoint(ScaledSize(-10,-10), 'bottomright'), 'bottomright'), app.theme.colours.versionColour), ]
def _updateImage(self): try: filepath = self.app.theme.getPath('achievements', '%s.png' % self.achievements[0]) except IOError: filepath = self.app.theme.getPath('achievements', 'default.png') image = pygame.image.load(filepath) image = pygame.transform.smoothscale(image, ScaledSize(64, 64).getSize(self.app)).convert() if type(self.elements[-1]) == PictureElement: self.elements.pop() self.image = PictureElement(self.app, image, Location(FullScreenAttachedPoint( ScaledSize(-self.width / 2 + 7, -105), 'midbottom'), 'bottomleft')) self.elements.append(self.image)
def makeGauge(self, item, x): return SingleUpgradeGauge(self.app, Area( FullScreenAttachedPoint(ScaledSize(x, -20), 'midbottom'), ScaledSize(40, 10), 'midbottom'), item)
def __init__(self, app, image, pos=None): super(PictureElement, self).__init__(app) self.setImage(image) if pos is None: pos = Location(FullScreenAttachedPoint((0, 0), 'center'), 'center') self.pos = pos