""" Panel displaying a player's overall status. """ import wx import time import Config import Global import UIInfo import UIImages from Global import Log, LogException class OverallStausPanel(wx.Panel): def __init__(self, Parent, ID): wx.Panel.__init__(self, Parent, ID) self.BackgroundColor = "black" self.ForegroundColor = "white" self.SetBackgroundColour(self.BackgroundColor) self.BigFont = wx.Font(16, wx.SWISS, wx.NORMAL, wx.NORMAL) self.HugeFont = wx.Font(24, wx.SWISS, wx.NORMAL, wx.NORMAL) self.Bind(wx.EVT_SIZE, self.OnSize) def UpdateStatus(self): """ Show the current player's status. """ for Widget in self.GetChildren(): Widget.Destroy() Sizer = wx.FlexGridSizer(2, 2, 5, 5) self.BuildWidgetsNW() self.BuildWidgetsNE() self.BuildWidgetsSW() self.BuildWidgetsSE() Sizer.AddMany([(self.SizerNW, 3, wx.EXPAND | wx.ALL, 5), (self.SizerNE, 3, wx.EXPAND | wx.ALL, 5), (self.SizerSW, 1, wx.EXPAND | wx.ALL, 5), (self.SizerSE, 1, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5)]) Sizer.AddGrowableRow(0) Sizer.AddGrowableRow(1) Sizer.AddGrowableCol(0) Sizer.AddGrowableCol(1) self.SetAutoLayout(True) self.SetSizer(Sizer) #Sizer.Fit(self) #self.Fit() self.Layout() def BuildWidgetsNW(self): self.SizerNW = wx.BoxSizer(wx.VERTICAL) if not Global.Player: return # Player name (big letters) Text = wx.StaticText(self, -1, Global.Player.Name) Text.SetFont(self.HugeFont) Text.SetForegroundColour(self.ForegroundColor) self.SizerNW.Add(Text, 0, wx.EXPAND) # Grid with various player info: Sizer = wx.FlexGridSizer(4, 2, 2, 2) GoldSizer = UIInfo.GetMedalSizer(self, "Gold") SilverSizer = UIInfo.GetMedalSizer(self, "Silver") BronzeSizer = UIInfo.GetMedalSizer(self, "Bronze") QuestTriedCount = Global.Player.GetQuestTriedCount() AllQuestsText = wx.StaticText(self, -1, "Quests tried: %s"%QuestTriedCount) AllQuestsText.SetForegroundColour(self.ForegroundColor) MoneyText = wx.StaticText(self, -1, "Money: %sZ"%Global.Player.Money) MoneyText.SetForegroundColour(self.ForegroundColor) TimeText = wx.StaticText(self, -1, "Time left: %s"%Global.Player.GetTimeLeftString()) TimeText.SetForegroundColour(self.ForegroundColor) StartTimeText = wx.StaticText(self, -1, "Play start: %s"%time.asctime(time.localtime(Global.Player.PlayStartTime))) StartTimeText.SetForegroundColour(self.ForegroundColor) LivesSizer = UIInfo.GetLifeSizer(self) Sizer.AddMany([MoneyText, LivesSizer, GoldSizer, TimeText, SilverSizer, StartTimeText, BronzeSizer, (20, 20), AllQuestsText, (20, 20)]) self.SizerNW.Add(Sizer, 0, wx.EXPAND) def BuildWidgetsNE(self): self.SizerNE = wx.BoxSizer(wx.VERTICAL) if not Global.Player: return Text = wx.StaticText(self, -1, "Gear:") Text.SetFont(self.BigFont) Text.SetForegroundColour(self.ForegroundColor) self.SizerNE.Add(Text, 0, wx.CENTER) # %%% equipment items are listed here. def BuildWidgetsSW(self): self.SizerSW = wx.BoxSizer(wx.VERTICAL) if not Global.Player: return Text = wx.StaticText(self, -1, "Inventory:") Text.SetFont(self.BigFont) Text.SetForegroundColour(self.ForegroundColor) self.SizerSW.Add(Text, 0, wx.ALIGN_LEFT) def BuildWidgetsSE(self): self.SizerSE = wx.BoxSizer(wx.VERTICAL) if not Global.Player: return CompletionRate = Global.Player.GetCompletionRate() Text = wx.StaticText(self, -1, "Completion rate: %s%%"%CompletionRate) Text.SetFont(self.BigFont) Text.SetForegroundColour(self.ForegroundColor) self.SizerSE.Add(Text, 0, wx.CENTER) Text = wx.StaticText(self, -1, "Your rank:") Text.SetForegroundColour(self.ForegroundColor) self.SizerSE.Add(Text, 0, wx.CENTER) (RankImageStub, RankText) = self.GetRank(CompletionRate) Throbber = UIImages.Throbber(self, "Critters/%s"%RankImageStub, CacheFlag = 0) self.SizerSE.Add(Throbber, 1, wx.CENTER) Text = wx.StaticText(self, -1, RankText) Text.SetForegroundColour(self.ForegroundColor) self.SizerSE.Add(Text, 0, wx.CENTER) def GetRank(self, CompletionRate): if CompletionRate <= 1: return ("Slime", "Slime") elif CompletionRate < 10: return ("Goomba", "Goomba") elif CompletionRate < 20: return ("MappyCat", "Mappy Cat") elif CompletionRate < 20: return ("Trap", "Donkey Kong Jr. Trap") elif CompletionRate < 30: return ("Ultima3Skeleton", "Ultima III Skeleton") elif CompletionRate < 40: return ("IronKnuckle", "IronKnuckle") elif CompletionRate < 50: return ("CrashMan", "Crash Man") else: # Final case: 100% or better! return ("Dragon", "Dragon") def OnSize(self, Event): wx.LayoutAlgorithm().LayoutWindow(self) self.Refresh() def BuildWidgets(self): pass