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 __init__(self, app): super(Interface, self).__init__(app) backdrop = pygame.Surface(app.screenManager.scaledSize) backdrop.fill((128, 0, 128)) i1 = prompt.InputBox(self.app, Area((40, 40), (300, 50)), 'Mouse Over', font=Font("KLEPTOCR.TTF", 36)) i1.onClick.addListener(self.setFocus) i2 = prompt.InputBox(self.app, Area((340, 140), (200, 50)), 'Mouse Over', font=Font("KLEPTOCR.TTF", 36)) i2.onClick.addListener(self.setFocus) h1 = hint.Hint(self.app, "You absolutely\nRULE!", i1, Font("KLEPTOCR.TTF", 24)) h2 = hint.Hint(self.app, "Like, amazingly so!! TROSNOTH!@!!@!", i2, Font("KLEPTOCR.TTF", 24)) h3 = hint.Hint( self.app, "A secret!\nWell done, you have found a magical land of wonder and amazement!! \nYou win absolutely nothing, but at least you have a good story to tell now.", pygame.Rect(500, 400, 100, 50), Font("KLEPTOCR.TTF", 24)) self.elements = [ elements.PictureElement(app, backdrop), i1, h1, i2, h2, h3 ]
def __init__(self, app): super(FirstPlayNotificationBar, self).__init__( app, message= 'First time playing Trosnoth? Click here to learn the rules.', url='http://www.trosnoth.org/how-to-play', font=app.fonts.default, area=Area(ScaledPoint(0, 0), ScaledSize(1024, 30), 'topleft'), buttonPos=Location(ScaledPoint(1024, 0), 'topright'), textPos=Area(ScaledPoint(512, 15), ScaledSize(1024, 30), 'centre'), ) self.onClick.addListener(self.hide) self.onClose.addListener(app.identitySettings.notFirstTime)
def _makeUpdateNotificationBar(self): from trosnoth.gui.common import Location, Area, ScaledPoint, ScaledSize from trosnoth.gui.notify import NotificationBar bar = NotificationBar( self.app, message='This is not the latest stable release. Click for info.', url='https://trosnoth.org/download', font=self.app.fonts.default, area=Area(ScaledPoint(0, 0), ScaledSize(1024, 30), 'topleft'), buttonPos=Location(ScaledPoint(1024, 0), 'topright'), textPos=Area(ScaledPoint(512, 15), ScaledSize(1024, 30), 'centre'), ) bar.onClick.addListener(bar.hide) return bar
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))
def __init__(self, app, host, port, onClose): super(AccountSettingsScreen, self).__init__(app) self.onClose = onClose self.host = host self.port = port area = ScaledArea(50, 140, 924, 570) alpha = 192 if app.displaySettings.alphaOverlays else 255 font = app.screenManager.fonts.bigMenuFont self.tabContainer = TabContainer(self.app, area, font, app.theme.colours.playTabBorder) self.background = elements.SolidRect( self.app, app.theme.colours.playMenu, alpha, Area(AttachedPoint((0, 0), self.tabContainer._getTabRect), TabSize(self.tabContainer))) self.passwordTab = ChangePasswordTab(app, host, onClose=self.close, onSave=self.save) self.tabContainer.addTab(self.passwordTab) self.passwordGetter = self.passwordGUIFactory(self.app) self.elements = [self.background, self.tabContainer] self.protocol = None d = ClientCreator(reactor, amp.AMP).connectTCP(host, port) d.addCallbacks(self.connectionEstablished, self.connectionFailed)
class GameTimer(framework.CompoundElement): 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 getTimeString(self): return self.world.clock.getTimeString() def _flash(self, flashState): if flashState == 0: self.gameClock.setColours(self.app.theme.colours.timerFlashColour) else: self.gameClock.setColours(self.app.theme.colours.timerFontColour) def _getRect(self): return self.area.getRect(self.app) def tick(self, deltaT): super(GameTimer, self).tick(deltaT) if self.world.clock.shouldFlash(): self._flash(int((self.world.clock.value / self.flashCycle) % 2)) else: self._flash(1) def draw(self, surface): timerBox = self._getRect() # Box background surface.fill(self.app.theme.colours.timerBackground, timerBox) # Box border pygame.draw.rect(surface, self.app.theme.colours.black, timerBox, self.lineWidth) super(GameTimer, self).draw(surface)
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 __init__(self, app): super(Interface, self).__init__(app) backdrop = pygame.Surface(app.screenManager.scaledSize) backdrop.fill((128,0,128)) con = console.TrosnothInteractiveConsole(app, Font(None, 18), Area((0, 200), (500, 200))) con.interact().addCallback(self.done) self.elements = [elements.PictureElement(app, backdrop), con] self.setFocus(con)
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, textBoxText): super(FunBox, self).__init__(app, ScaledSize(300, 200), "Dialog!!") h = prompt.InputBox(app, Area((10, 10), (280, 50)), textBoxText, font=app.screenManager.fonts.bigMenuFont) h.onClick.addListener(self.setFocus) font = ScaledFont("KLEPTOCR.TTF", 30) b = elements.TextButton(app, (150, 100), "Close", font, (255, 0, 0), (20, 100, 200)) b.onClick.addListener(lambda sender: self.close()) self.elements = [h, b] self.setColours(titleColour=(255, 0, 0), backgroundColour=(255, 128, 0))
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 __init__(self, app, row, column): super(TextBoxCell, self).__init__(app, row, column) textAlign = self.styleGet('textAlign') self.inputBox = InputBox( self.app, Area( CellAttachedPoint((0, 0), self, textAlign), self._getUsableRect().size, textAlign), font=self.styleGet('font'), colour=self.styleGet('foreColour')) self.inputBox.onEdit.addListener(self._valueChanged) self.elements = [self.inputBox] self._oldText = '' self._readOnly = True self.setReadOnly(False) self.onValueChanged = Event()
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, onClose): super(ServerSelectionScreen, self).__init__(app) self.onClose = onClose area = ScaledArea(50, 140, 924, 570) if app.displaySettings.alphaOverlays: alpha = 192 else: alpha = 255 font = app.screenManager.fonts.bigMenuFont self.tabContainer = TabContainer(self.app, area, font, app.theme.colours.playTabBorder) self.background = elements.SolidRect( self.app, app.theme.colours.playMenu, alpha, Area(AttachedPoint((0, 0), self.tabContainer._getTabRect), TabSize(self.tabContainer))) self.tab = ServerSelectionTab(app, onClose=onClose, onJoin=self.join, onAccountSettings=self.accountSettings) self.tabContainer.addTab(self.tab) self.setElements()
def makeGauge(self, item, x): return SingleUpgradeGauge(self.app, Area( FullScreenAttachedPoint(ScaledSize(x, -20), 'midbottom'), ScaledSize(40, 10), 'midbottom'), item)
def __init__(self, app, controller, world): super(JoinGameDialog, self).__init__(app, ScaledSize(512, 314), 'Join Game') self.result = None self.controller = controller self.selectedTeam = None fonts = self.app.screenManager.fonts self.nickBox = prompt.InputBox( self.app, Area(DialogBoxAttachedPoint(self, ScaledSize(0, 40), 'midtop'), ScaledSize(200, 60), 'midtop'), '', font=fonts.menuFont, maxLength=30, ) self.nickBox.onClick.addListener(self.setFocus) self.nickBox.onTab.addListener(lambda sender: self.clearFocus()) name = app.identitySettings.nick if name is not None: self.nickBox.setValue(name) colours = app.theme.colours self.cantJoinYet = elements.TextElement( self.app, '', fonts.ingameMenuFont, ScaledLocation(256, 115, 'center'), colours.cannotJoinColour, ) teamA = world.teams[0] teamB = world.teams[1] self.elements = [ elements.TextElement( self.app, 'Please enter your nick:', fonts.smallMenuFont, Location( DialogBoxAttachedPoint(self, ScaledSize(0, 10), 'midtop'), 'midtop'), colours.black, ), self.nickBox, self.cantJoinYet, elements.TextElement( self.app, 'Select team:', fonts.smallMenuFont, Location( DialogBoxAttachedPoint(self, ScaledSize(0, 130), 'midtop'), 'midtop'), colours.black, ), elements.TextButton(self.app, Location( DialogBoxAttachedPoint( self, ScaledSize(-25, 160), 'midtop'), 'topright'), str(teamA), fonts.menuFont, colours.team1msg, colours.white, onClick=lambda obj: self.joinTeam(teamA)), elements.TextButton(self.app, Location( DialogBoxAttachedPoint( self, ScaledSize(25, 160), 'midtop'), 'topleft'), str(teamB), fonts.menuFont, colours.team2msg, colours.white, onClick=lambda obj: self.joinTeam(teamB)), elements.TextButton(self.app, Location( DialogBoxAttachedPoint( self, ScaledSize(-25, 210), 'midtop'), 'topright'), 'Automatic', fonts.menuFont, colours.inGameButtonColour, colours.white, onClick=lambda obj: self.joinTeam()), elements.TextButton(self.app, Location( DialogBoxAttachedPoint( self, ScaledSize(25, 210), 'midtop'), 'topleft'), 'Spectator', fonts.menuFont, colours.inGameButtonColour, colours.white, onClick=lambda obj: self.spectate()), elements.TextButton(self.app, Location( DialogBoxAttachedPoint( self, ScaledSize(0, -10), 'midbottom'), 'midbottom'), 'Cancel', fonts.menuFont, colours.inGameButtonColour, colours.white, onClick=self.cancel) ] self.setColours(colours.joinGameBorderColour, colours.joinGameTitleColour, colours.joinGameBackgroundColour) self.setFocus(self.nickBox)