def __init__(self, session): from horizons.session import Session assert isinstance(session, Session) self.session = session # special slot because of special properties self.gold_gui = load_uh_widget(self.__class__.GOLD_ENTRY_GUI_FILE, style=self.__class__.STYLE) self.gold_gui.balance_visible = False self.gold_gui.child_finder = PychanChildFinder(self.gold_gui) gold_icon = self.gold_gui.child_finder("res_icon") gold_icon.image = get_res_icon_path(RES.GOLD) gold_icon.max_size = gold_icon.min_size = gold_icon.size = (32, 32) self.gold_gui.mapEvents({ "resbar_gold_container/mouseClicked/stats" : self._toggle_stats, }) self.gold_gui.helptext = _("Click to show statistics") self.stats_gui = None self.gui = [] # list of slots self.resource_configurations = weakref.WeakKeyDictionary() self.current_instance = weakref.ref(self) # can't weakref to None self.construction_mode = False self._last_build_costs = None self._do_show_dummy = False self._update_default_configuration() NewPlayerSettlementHovered.subscribe(self._on_different_settlement) TabWidgetChanged.subscribe(self._on_tab_widget_changed) # set now and then every few sec ExtScheduler().add_new_object(self._update_balance_display, self, run_in=0) ExtScheduler().add_new_object(self._update_balance_display, self, run_in=Player.STATS_UPDATE_INTERVAL, loops=-1)
def _setup_widget(self): """Gets the widget and sets up some attributes and helper. This is called when the Tab is created, or, when lazy loading is active once the tab is about to be shown. """ self.widget = self.get_widget() self.widget.child_finder = PychanChildFinder(self.widget) self.init_widget()
def __init__(self, ingame_gui): self._ingame_gui = ingame_gui self._widget = load_uh_widget('city_info.xml', 'resource_bar') self._child_finder = PychanChildFinder(self._widget) self._settlement = None HoverSettlementChanged.subscribe(self._on_hover_settlement_change) SettlerInhabitantsChanged.subscribe(self._on_settler_inhabitant_change) ResourceBarResize.subscribe(self._on_resourcebar_resize)
def _show_stats(self): """Show data below gold icon when balance label is clicked""" if self.stats_gui is None: reference_icon = self.gold_gui.child_finder("balance_background") self.stats_gui = load_uh_widget(self.__class__.STATS_GUI_FILE) self.stats_gui.child_finder = PychanChildFinder(self.stats_gui) self.stats_gui.position = (reference_icon.x + self.gold_gui.x, reference_icon.y + self.gold_gui.y) self.stats_gui.mapEvents({ 'resbar_stats_container/mouseClicked/stats': self._toggle_stats }) images = [ # these must correspond to the entries in _update_stats "content/gui/images/resbar_stats/expense.png", "content/gui/images/resbar_stats/income.png", "content/gui/images/resbar_stats/buy.png", "content/gui/images/resbar_stats/sell.png", "content/gui/images/resbar_stats/scales_icon.png", ] for num, image in enumerate(images): # keep in sync with comment there until we can use that data: # ./content/gui/xml/ingame/hud/resource_overview_bar_stats.xml box = HBox(padding=0, min_size=(70, 0), name="resbar_stats_line_%s" % num) box.addChild(Icon(image=image)) box.addSpacer(Spacer()) box.addChild(Label(name="resbar_stats_entry_%s" % num)) # workaround for fife font bug, probably http://fife.trac.cloudforge.com/engine/ticket/666 box.addChild(Label(text=u" ")) if num < len(images) - 1: # regular one self.stats_gui.child_finder("entries_box").addChild(box) else: # last one self.stats_gui.child_finder("bottom_box").addChild(box) self.stats_gui.child_finder("bottom_box").stylize( 'resource_bar') self._update_stats() self.stats_gui.show() ExtScheduler().add_new_object(self._update_stats, self, run_in=Player.STATS_UPDATE_INTERVAL, loops=-1)
def _init_stats_gui(self): reference_icon = self.gold_gui.child_finder("balance_background") self.stats_gui = load_uh_widget(self.__class__.STATS_GUI_FILE) self.stats_gui.child_finder = PychanChildFinder(self.stats_gui) self.stats_gui.position = (reference_icon.x + self.gold_gui.x, reference_icon.y + self.gold_gui.y) self.stats_gui.mapEvents({ 'resbar_stats_container/mouseClicked/stats': self._toggle_stats, }) # This list must correspond to `figures` in _update_stats images = [ ("content/gui/images/resbar_stats/expense.png", T("Running costs")), ("content/gui/images/resbar_stats/income.png", T("Taxes")), ("content/gui/images/resbar_stats/buy.png", T("Buy expenses")), ("content/gui/images/resbar_stats/sell.png", T("Sell income")), ("content/gui/images/resbar_stats/scales_icon.png", T("Balance")), ] for num, (image, helptext) in enumerate(images): # Keep in sync with comment there until we can use that data: # ./content/gui/xml/ingame/hud/resource_overview_bar_stats.xml box = HBox(padding=0, min_size=(70, 0)) box.name = "resbar_stats_line_{}".format(num) box.helptext = helptext #TODO Fix icon size; looks like not 16x16 a surprising amount of times. box.addChild(Icon(image=image)) box.addChild(Spacer()) box.addChild(Label(name="resbar_stats_entry_{}".format(num))) #TODO This label is a workaround for some fife font bug, # probably http://github.com/fifengine/fifengine/issues/666. templabel = Label(name="resbar_stats_whatever_{}".format(num)) box.addChild(templabel) if num == len(images) - 1: # The balance line (last one) gets bold font. box.stylize('resource_bar') self.stats_gui.child_finder("entries_box").addChild(box)
def _load_widget(self, widget): widget = load_uh_widget(widget) widget.child_finder = PychanChildFinder(widget) return widget
def __init__(self, session, gui): super(IngameGui, self).__init__() self.session = session assert isinstance(self.session, horizons.session.Session) self.main_gui = gui self.main_widget = None self.tabwidgets = {} self.settlement = None self.resource_source = None self.resources_needed, self.resources_usable = {}, {} self._old_menu = None self.widgets = LazyWidgetsDict(self.styles, center_widgets=False) self.cityinfo = self.widgets['city_info'] self.cityinfo.child_finder = PychanChildFinder(self.cityinfo) self.logbook = LogBook(self.session) self.message_widget = MessageWidget(self.session) self.players_overview = PlayersOverview(self.session) self.players_settlements = PlayersSettlements(self.session) self.players_ships = PlayersShips(self.session) # self.widgets['minimap'] is the guichan gui around the actual minimap, # which is saved in self.minimap minimap = self.widgets['minimap'] minimap.position_technique = "right+0:top+0" icon = minimap.findChild(name="minimap") self.minimap = Minimap( icon, targetrenderer=horizons.globals.fife.targetrenderer, imagemanager=horizons.globals.fife.imagemanager, session=self.session, view=self.session.view) def speed_up(): SpeedUpCommand().execute(self.session) def speed_down(): SpeedDownCommand().execute(self.session) minimap.mapEvents({ 'zoomIn': self.session.view.zoom_in, 'zoomOut': self.session.view.zoom_out, 'rotateRight': Callback.ChainedCallbacks(self.session.view.rotate_right, self.minimap.rotate_right), 'rotateLeft': Callback.ChainedCallbacks(self.session.view.rotate_left, self.minimap.rotate_left), 'speedUp': speed_up, 'speedDown': speed_down, 'destroy_tool': self.session.toggle_destroy_tool, 'build': self.show_build_menu, 'diplomacyButton': self.show_diplomacy_menu, 'gameMenuButton': self.main_gui.toggle_pause, 'logbook': self.logbook.toggle_visibility }) minimap.show() #minimap.position_technique = "right+15:top+153" self.widgets['tooltip'].hide() self.resource_overview = ResourceOverviewBar(self.session) ResourceBarResize.subscribe(self._on_resourcebar_resize) # Register for messages SettlerUpdate.subscribe(self._on_settler_level_change) SettlerInhabitantsChanged.subscribe(self._on_settler_inhabitant_change) HoverSettlementChanged.subscribe(self._cityinfo_set)
def _load_widget(self, widget): widget = load_uh_widget(widget, style="menu_black") widget.child_finder = PychanChildFinder(widget) return widget