""" UIInfo: Display various info about the player and about the current location. """ import os import sys import wx import Global import Config import GameMap import GameInfo import UIImages import Utils from Global import Log, LogException class UIInfo(wx.Panel): ForegroundColor = "white" BackgroundColor = "black" def __init__(self, Parent, App, ID): wx.Panel.__init__(self, Parent, ID) self.PlayerPanel = None self.RoomPanel = None self.App = App self.SetBackgroundColour(self.BackgroundColor) self.BuildWidgets() Global.UIInfo = self self.BigFont = wx.Font(16, wx.SWISS, wx.NORMAL, wx.NORMAL) def BuildPlayerWidgets(self): # Kill any old widgets: if self.PlayerPanel: Children = self.PlayerPanel.GetChildren() for Widget in Children: Widget.Destroy() else: self.PlayerPanel = wx.Panel(self, -1) if not Global.Player: Log("* No player widgets; Global.Player is null!") return StaticBox = wx.StaticBox(self.PlayerPanel, -1, "") StaticBox.SetForegroundColour(self.ForegroundColor) BoxSizer = wx.StaticBoxSizer(StaticBox, wx.VERTICAL) # Player name: PlayerNameText = wx.StaticText(self.PlayerPanel, -1, Global.Player.Name, style = wx.ALIGN_CENTER) PlayerNameText.SetForegroundColour(self.ForegroundColor) #TempFont = wx.Font(16, wx.SWISS, wx.NORMAL, wx.NORMAL) PlayerNameText.SetFont(self.BigFont) BoxSizer.Add(PlayerNameText, 2, wx.EXPAND) # Lives: LifeSizer = GetLifeSizer(self.PlayerPanel) BoxSizer.Add(LifeSizer, 2) # Time: TimeLeft = Global.Player.CurrentTime TimeString = "Time: %s"%Global.Player.GetTimeLeftString() TimeText = wx.StaticText(self.PlayerPanel, -1, TimeString) TimeText.SetForegroundColour(self.ForegroundColor) BoxSizer.Add(TimeText, 1) # Medal info: HorizSizer = GetMedalSizer(self.PlayerPanel, "Gold") BoxSizer.Add(HorizSizer, 3) HorizSizer = GetMedalSizer(self.PlayerPanel, "Silver") BoxSizer.Add(HorizSizer, 2) HorizSizer = GetMedalSizer(self.PlayerPanel, "Bronze") BoxSizer.Add(HorizSizer, 2) # Layout: self.PlayerPanel.SetAutoLayout(True) self.PlayerPanel.SetSizer(BoxSizer) self.PlayerPanel.Layout() def BuildRoomWidgets(self, Room): if self.RoomPanel: for Widget in self.RoomPanel.GetChildren(): Widget.Destroy() else: self.RoomPanel = wx.Panel(self, -1) if not Room: return Box = wx.BoxSizer(wx.VERTICAL) if Room.Type == GameMap.RoomTypes.Quest: self.BuildQuestRoomWidgets(Room, Box) elif Room.Type == GameMap.RoomTypes.Treasure: RoomName = "Treasure room" RoomNameText = wx.StaticText(self.RoomPanel, -1, RoomName) Box.Add(RoomNameText, 1, wx.EXPAND) elif Room.Type == GameMap.RoomTypes.Sign: self.BuildSignRoomWidgets(Room, Box) else: RoomName = "Empty room" RoomNameText = wx.StaticText(self.RoomPanel, -1, RoomName) Box.Add(RoomNameText, 1, wx.EXPAND) self.RoomPanel.SetAutoLayout(True) self.RoomPanel.SetSizer(Box) self.RoomPanel.Layout() def BuildSignRoomWidgets(self, Room, Box): # Quest name: SignTitle = wx.StaticText(self.RoomPanel, -1, "The sign reads:", style = wx.ALIGN_CENTER) SignTitle.SetForegroundColour(self.ForegroundColor) Box.Add(SignTitle, 1, wx.EXPAND) # Sign text: SignText = wx.StaticText(self.RoomPanel, -1, Room.Notes) SignText.SetForegroundColour(self.ForegroundColor) Box.Add(SignText, 5, wx.EXPAND) def BuildQuestRoomWidgets(self, Room, Box): Quest = Global.Metagame.Quests[Room.QuestID] # Quest name: RoomNameText = wx.StaticText(self.RoomPanel, -1, Quest.Name, style = wx.ALIGN_CENTER) RoomNameText.SetFont(self.BigFont) RoomNameText.SetForegroundColour(self.ForegroundColor) Box.Add(RoomNameText, 2, wx.EXPAND) # Completion status: Failed, untried, bronze, silver, gold: BestResult = Global.Player.GetBestCompletionString(Room.QuestID) ThrobberName = Utils.GetCompletionThrobberName(BestResult) Throbber = UIImages.Throbber(self.RoomPanel, ThrobberName) Box.Add(Throbber, 0, wx.ALIGN_CENTER) Throbber.Start() # Source game name: String = "From: %s"%Quest.Game.GameName GameNameText = wx.StaticText(self.RoomPanel, -1, String) GameNameText.SetForegroundColour(self.ForegroundColor) Box.Add(GameNameText, 1, wx.EXPAND) # Source game system: String = "System: %s"%GameInfo.GameType.PrettyNames[Quest.Game.GameType] SystemText = wx.StaticText(self.RoomPanel, -1, String) SystemText.SetForegroundColour(self.ForegroundColor) Box.Add(SystemText, 0) # Instructions: Instructions = Config.GetFixedInstructions(Quest.Instructions, Global.Config) #if not Instructions: # Instructions = "" InstructionsText = wx.StaticText(self.RoomPanel, -1, Instructions) InstructionsText.SetForegroundColour(self.ForegroundColor) Box.Add(InstructionsText, 7, wx.EXPAND | wx.TOP, 10) def BuildWidgets(self): try: self.BuildPlayerWidgets() self.BuildRoomWidgets(None) Box = wx.BoxSizer(wx.VERTICAL) Box.Add(self.PlayerPanel, 2, wx.EXPAND) Box.Add(self.RoomPanel, 3, wx.EXPAND) self.SetAutoLayout(True) self.SetSizer(Box) self.Layout() except: LogException() def GetLifeSizer(Parent): LifeSizer = wx.BoxSizer(wx.HORIZONTAL) LivesText = wx.StaticText(Parent, -1, "Lives:") LivesText.SetForegroundColour("white") LifeSizer.Add(LivesText) Image = Global.ImageHandler.GetImage("Heart.png") LifeCount = min(24, Global.Player.CurrentLives) LifeBlockCount = (LifeCount + 7) / 8 BlockSizer = wx.BoxSizer(wx.VERTICAL) HeartsRemaining = LifeCount for BlockIndex in range(LifeBlockCount): HeartSizer = wx.BoxSizer(wx.HORIZONTAL) HeartCount = min(HeartsRemaining, 8) HeartsRemaining -= 8 #Log("Build %s hearts on block %s"%(HeartCount, BlockIndex)) for LifeIndex in range(HeartCount): Heart = wx.StaticBitmap(Parent, -1, Image) HeartSizer.Add(Heart) BlockSizer.Add(HeartSizer) LifeSizer.Add(BlockSizer) return LifeSizer def GetMedalSizer(Parent, MedalType): # Bronze medals info: HorizSizer = wx.BoxSizer(wx.HORIZONTAL) if MedalType == "Bronze": String = "x %s"%Global.Player.MedalCountBronze elif MedalType == "Gold": String = "x %s"%Global.Player.MedalCountGold elif MedalType == "Silver": String = "x %s"%Global.Player.MedalCountSilver elif MedalType == "Failure": String = "x %s"%Global.Player.MedalCountFailure Throbber = UIImages.Throbber(Parent, MedalType, Delay = 0.1) HorizSizer.Add(Throbber, 1) Throbber.Start() Text = wx.StaticText(Parent, -1, String) Text.SetForegroundColour("white") HorizSizer.Add(Text, 0, wx.ALIGN_CENTER) return HorizSizer