def show_resource_menu(self, slot_id): self.resources = load_xml_translated('select_trade_resource.xml') self.resources.position = self.widget.position button_width = 50 vbox = self.resources.findChild(name="resources") current_hbox = pychan.widgets.HBox(padding = 2) index = 1 resources = horizons.main.db.get_res_id_and_icon(True) # Add the zero element to the beginning that allows to remove the currently sold/bought resource for (res_id, icon) in [(0, self.dummy_icon_path)] + list(resources): if res_id in self.settlement.buy_list or res_id in self.settlement.sell_list: continue # don't show resources that are already in the list button = TooltipButton(size=(50, 50)) button.up_image, button.down_image, button.hover_image = icon, icon, icon if res_id == 0: button.tooltip = u"" else: button.tooltip = horizons.main.db.get_res_name(res_id) button.capture(Callback(self.add_resource, res_id, slot_id)) current_hbox.addChild(button) if index % (vbox.width/(button_width)) == 0 and index is not 0: vbox.addChild(current_hbox) current_hbox = pychan.widgets.HBox(padding=0) index += 1 vbox.addChild(current_hbox) vbox.adaptLayout() self.resources.addChild(vbox) self.resources.stylize('headline') self.hide() self.resources.show() self.settlement.session.ingame_gui.minimap_to_front()
def show_resource_menu(self, slot_id): self.resources = load_xml_translated('select_trade_resource.xml') self.resources.position = self.widget.position button_width = 50 vbox = self.resources.findChild(name="resources") amount_per_line = vbox.width / button_width current_hbox = pychan.widgets.HBox(name="hbox_0") index = 1 resources = horizons.main.db.get_res_id_and_icon(True) # Add the zero element to the beginning that allows to remove the currently sold/bought resource for (res_id, icon) in [(0, self.dummy_icon_path)] + list(resources): if res_id in self.settlement.buy_list or res_id in self.settlement.sell_list: continue # don't show resources that are already in the list button = TooltipButton( size=(button_width, button_width), \ name="resource_icon_%02d" % res_id ) button.up_image, button.down_image, button.hover_image = icon, icon, icon if res_id == 0: button.tooltip = u"" else: button.tooltip = horizons.main.db.get_res_name(res_id) button.capture(Callback(self.add_resource, res_id, slot_id)) current_hbox.addChild(button) if index % amount_per_line == 0 and index is not 0: vbox.addChild(current_hbox) current_hbox = pychan.widgets.HBox(name="hbox_%s" % (index / amount_per_line) ) index += 1 # current_hbox.addSpacer(pychan.widgets.layout.Spacer) #TODO: proper alignment vbox.addChild(current_hbox) vbox.adaptLayout() self.hide() # hides tab that invoked the selection widget self.resources.show() # show selection widget, still display old tab icons self.settlement.session.ingame_gui.minimap_to_front()
def show_resource_menu(self, slot_id): self.resources = load_xml_translated("select_trade_resource.xml") self.resources.position = self.widget.position button_width = 50 vbox = self.resources.findChild(name="resources") amount_per_line = vbox.width / button_width current_hbox = pychan.widgets.HBox(name="hbox_0") index = 1 resources = horizons.main.db.get_res_id_and_icon(True) # Add the zero element to the beginning that allows to remove the currently sold/bought resource for (res_id, icon) in [(0, self.dummy_icon_path)] + list(resources): if res_id in self.settlement.buy_list or res_id in self.settlement.sell_list: continue # don't show resources that are already in the list button = TooltipButton(size=(button_width, button_width), name="resource_icon_%02d" % res_id) button.up_image, button.down_image, button.hover_image = icon, icon, icon if res_id == 0: button.tooltip = u"" else: button.tooltip = horizons.main.db.get_res_name(res_id) button.capture(Callback(self.add_resource, res_id, slot_id)) current_hbox.addChild(button) if index % amount_per_line == 0 and index is not 0: vbox.addChild(current_hbox) current_hbox = pychan.widgets.HBox(name="hbox_%s" % (index / amount_per_line)) index += 1 # current_hbox.addSpacer(pychan.widgets.layout.Spacer) #TODO: proper alignment vbox.addChild(current_hbox) vbox.adaptLayout() self.hide() # hides tab that invoked the selection widget self.resources.show() # show selection widget, still display old tab icons self.settlement.session.ingame_gui.minimap_to_front()
def _init_tabs(self): """Add enough tabbuttons for all widgets.""" # Load buttons for index, tab in enumerate(self._tabs): container = pychan.Container() background = pychan.Icon() background.image = tab.button_background_image button = TooltipButton() button.name = index if self.current_tab is tab: button.up_image = tab.button_active_image else: button.up_image = tab.button_up_image button.down_image = tab.button_down_image button.hover_image = tab.button_hover_image button.size = (50, 50) button.capture(pychan.tools.callbackWithArguments(self._show_tab, index)) if hasattr(tab, 'tooltip') and tab.tooltip is not None: button.tooltip = unicode(tab.tooltip) container.size = background.size container.addChild(background) container.addChild(button) self.content.addChild(container) self.widget.size = (50, 200*len(self._tabs)) self.widget.adaptLayout()
def _init_tabs(self): """Add enough tabbuttons for all widgets.""" # Load buttons for index, tab in enumerate(self._tabs): tab.add_remove_listener(self.hide) container = pychan.Container() background = pychan.Icon() background.name = "bg_%s" % index button = TooltipButton() button.name = index if self.current_tab is tab: background.image = tab.button_background_image_active button.up_image = tab.button_active_image else: background.image = tab.button_background_image button.up_image = tab.button_up_image button.down_image = tab.button_down_image button.hover_image = tab.button_hover_image button.is_focusable = False button.size = (50, 50) button.capture(Callback(self._show_tab, index)) if hasattr(tab, "tooltip") and tab.tooltip is not None: button.tooltip = unicode(tab.tooltip) container.size = background.size container.addChild(background) container.addChild(button) self.content.addChild(container) self.widget.size = (50, 55 * len(self._tabs)) self.widget.adaptLayout()
def _init_tabs(self): """Add enough tabbuttons for all widgets.""" # Load buttons for index, tab in enumerate(self._tabs): container = pychan.Container() background = pychan.Icon() background.image = tab.button_background_image button = TooltipButton() button.name = index if self.current_tab is tab: button.up_image = tab.button_active_image else: button.up_image = tab.button_up_image button.down_image = tab.button_down_image button.hover_image = tab.button_hover_image button.is_focusable = False button.size = (50, 50) button.capture(Callback(self._show_tab, index)) if hasattr(tab, 'tooltip') and tab.tooltip is not None: button.tooltip = unicode(tab.tooltip) container.size = background.size container.addChild(background) container.addChild(button) self.content.addChild(container) self.widget.size = (50, 200 * len(self._tabs)) self.widget.adaptLayout()
def _add_line_to_gui(self, ship, sequence_number): sequence_number_label = widgets.Label(name = 'sequence_number_%d' % ship.worldid) sequence_number_label.text = unicode(sequence_number) sequence_number_label.min_size = sequence_number_label.max_size = (15, 20) ship_name = widgets.Label(name = 'ship_name_%d' % ship.worldid) ship_name.text = unicode(ship.get_component(NamedComponent).name) ship_name.min_size = ship_name.max_size = (100, 20) rename_icon = TooltipButton(name = 'rename_%d' % ship.worldid) rename_icon.up_image = "content/gui/images/background/rename_feather_20.png" rename_icon.hover_image = "content/gui/images/background/rename_feather_20_h.png" rename_icon.tooltip = _("Click to change the name of this ship") ship_type = widgets.Label(name = 'ship_type_%d' % ship.worldid) ship_type.text = unicode(ship.classname) ship_type.min_size = ship_type.max_size = (60, 20) weapons = widgets.Label(name = 'weapons_%d' % ship.worldid) if isinstance(ship, FightingShip): weapon_list = [] for weapon_id, amount in sorted(ship.get_weapon_storage()): weapon_list.append('%d %s' % (amount, self.session.db.get_res_name(weapon_id))) if weapon_list: weapons.text = unicode(', '.join(weapon_list)) else: #i18n There are no weapons equipped at the moment. weapons.text = _('None') else: weapons.text = _('N/A') weapons.min_size = weapons.max_size = (60, 20) health = widgets.Label(name = 'health_%d' % ship.worldid) health_component = ship.get_component(HealthComponent) health.text = unicode('%d/%d' % (health_component.health, health_component.max_health)) health.min_size = health.max_size = (65, 20) status = widgets.Label(name = 'status_%d' % ship.worldid) status.text, status_position = ship.get_status() status.min_size = status.max_size = (320, 20) hbox = widgets.HBox() hbox.addChild(sequence_number_label) hbox.addChild(ship_name) hbox.addChild(rename_icon) hbox.addChild(ship_type) hbox.addChild(weapons) hbox.addChild(health) hbox.addChild(status) self._content_vbox.addChild(hbox) return (ship_name, rename_icon, status, status_position)
def _add_line_to_gui(self, settlement, sequence_number): sequence_number_label = widgets.Label(name = 'sequence_number_%d' % settlement.worldid) sequence_number_label.text = unicode(sequence_number) sequence_number_label.min_size = sequence_number_label.max_size = (15, 20) name = widgets.Label(name = 'name_%d' % settlement.worldid) name.text = unicode(settlement.get_component(NamedComponent).name) name.min_size = name.max_size = (175, 20) rename_icon = TooltipButton(name = 'rename_%d' % settlement.worldid) rename_icon.up_image = "content/gui/images/background/rename_feather_20.png" rename_icon.hover_image = "content/gui/images/background/rename_feather_20_h.png" rename_icon.tooltip = _("Click to change the name of your settlement") self._add_generic_line_to_gui(settlement.worldid, [sequence_number_label, name, rename_icon], settlement.inhabitants, settlement.cumulative_taxes, settlement.cumulative_running_costs) return name, rename_icon
def show_resource_menu(self, slot, entry): position = self.widgets.index(entry) if self.resource_menu_shown: self.hide_resource_menu() self.resource_menu_shown = True vbox = self._gui.findChild(name="resources") label = self._gui.findChild(name="select_res_label") label.text = unicode("Select Resources") #hardcoded for 5 works better than vbox.width / button_width amount_per_line = 5 current_hbox = widgets.HBox() index = 1 for res_id in self.icon_for_resource: if res_id in self.instance.route.waypoints[position]['resource_list'] and\ slot.findChild(name='button').up_image.source is not self.icon_for_resource[res_id]: continue button = TooltipButton(size=(50,50)) icon = self.icon_for_resource[res_id] button.up_image, button.down_image, button.hover_image = icon, icon, icon button.capture(Callback(self.add_resource, slot, res_id, entry)) if res_id != 0: button.tooltip = horizons.main.db.get_res_name(res_id) current_hbox.addChild(button) if index > amount_per_line: index -= amount_per_line vbox.addChild(current_hbox) current_hbox = widgets.HBox() index += 1 vbox.addChild(current_hbox) self.hide() self.show()