Package horizons :: Package gui :: Package widgets :: Module playersoverview
[hide private]
[frames] | no frames]

Source Code for Module horizons.gui.widgets.playersoverview

 1  # ################################################### 
 2  # Copyright (C) 2008-2017 The Unknown Horizons Team 
 3  # team@unknown-horizons.org 
 4  # This file is part of Unknown Horizons. 
 5  # 
 6  # Unknown Horizons is free software; you can redistribute it and/or modify 
 7  # it under the terms of the GNU General Public License as published by 
 8  # the Free Software Foundation; either version 2 of the License, or 
 9  # (at your option) any later version. 
10  # 
11  # This program is distributed in the hope that it will be useful, 
12  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
14  # GNU General Public License for more details. 
15  # 
16  # You should have received a copy of the GNU General Public License 
17  # along with this program; if not, write to the 
18  # Free Software Foundation, Inc., 
19  # 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
20  # ################################################### 
21   
22  from fife.extensions.pychan import widgets 
23   
24  from horizons.gui.widgets.statswidget import StatsWidget 
25   
26   
27 -class PlayersOverview(StatsWidget):
28 """Widget that shows the scores of every player in the game.""" 29 30 widget_file_name = 'players_overview.xml' 31
32 - def __init__(self, session):
33 super().__init__(session)
34 # this is supposed to run on the tick after the stats update 35
36 - def refresh(self):
37 super().refresh() 38 for player in sorted(self.session.world.players, key=lambda player: (-player.get_latest_stats().total_score, player.worldid)): 39 self._add_line_to_gui(player) 40 self._content_vbox.adaptLayout()
41
42 - def _add_line_to_gui(self, player):
43 stats = player.get_latest_stats() 44 45 emblem = widgets.Label(name='emblem_{:d}'.format(player.worldid), text=" ") 46 emblem.background_color = player.color 47 emblem.min_size = (12, 20) 48 49 name = widgets.Label(name='player_{:d}'.format(player.worldid)) 50 name.text = player.name 51 name.min_size = (108, 20) 52 53 money_score = widgets.Label(name='money_score_{:d}'.format(player.worldid)) 54 money_score.text = str(stats.money_score) 55 money_score.min_size = (60, 20) 56 57 land_score = widgets.Label(name='land_score_{:d}'.format(player.worldid)) 58 land_score.text = str(stats.land_score) 59 land_score.min_size = (50, 20) 60 61 resource_score = widgets.Label(name='resource_score_{:d}'.format(player.worldid)) 62 resource_score.text = str(stats.resource_score) 63 resource_score.min_size = (90, 20) 64 65 building_score = widgets.Label(name='building_score_{:d}'.format(player.worldid)) 66 building_score.text = str(stats.building_score) 67 building_score.min_size = (70, 20) 68 69 settler_score = widgets.Label(name='settler_score_{:d}'.format(player.worldid)) 70 settler_score.text = str(stats.settler_score) 71 settler_score.min_size = (60, 20) 72 73 unit_score = widgets.Label(name='unit_score_{:d}'.format(player.worldid)) 74 unit_score.text = str(stats.unit_score) 75 unit_score.min_size = (50, 20) 76 77 total_score = widgets.Label(name='total_score_{:d}'.format(player.worldid)) 78 total_score.text = str(stats.total_score) 79 total_score.min_size = (70, 20) 80 81 hbox = widgets.HBox() 82 hbox.addChild(emblem) 83 hbox.addChild(name) 84 hbox.addChild(money_score) 85 hbox.addChild(land_score) 86 hbox.addChild(resource_score) 87 hbox.addChild(building_score) 88 hbox.addChild(settler_score) 89 hbox.addChild(unit_score) 90 hbox.addChild(total_score) 91 self._content_vbox.addChild(hbox)
92