def load_gui(self): if self.gui is None: self.gui = load_xml_translated("place_building.xml") self.gui.stylize('menu_black') self.gui.findChild(name='headline').stylize('headline') self.gui.findChild(name='building_name').stylize('headline') top_bar = self.gui.findChild(name='top_bar') top_bar.position = (self.gui.size[0] / 2 - top_bar.size[0] / 2 - 16, 50) self.gui.position = ( horizons.main.fife.engine_settings.getScreenWidth() - self.gui.size[0] - 14, 157) self.gui.mapEvents({ "rotate_left": self.rotate_left, "rotate_right": self.rotate_right }) # set translated building name in gui self.gui.findChild( name='building_name').text = u' ' + _(self._class._name) self.gui.findChild(name='running_costs').text = unicode( self._class.running_costs) head_box = self.gui.findChild(name='head_box') head_box.adaptLayout() # recalculates size for new content head_box.position = ( # calculate and set new center (pychan doesn't support it) self.gui.size[0] / 2 - head_box.size[0] / 2, head_box.position[1]) head_box.adaptLayout() self.draw_gui() self.session.view.add_change_listener(self.draw_gui)
def refresh(self): """This function is called by the TabWidget to redraw the widget.""" # remove old field data parent_container = self.widget.child_finder('related_fields') while len(parent_container.children) > 0: parent_container.removeChild(parent_container.children[0]) # Load all related Fields of this Farm building_ids = self.instance.session.db.cached_query( "SELECT related_building FROM related_buildings where building = ?", self.instance.id) build_buttons = list() gui = load_xml_translated(self.relatedfields_gui_xml) container = gui.findChild(name="fields_container") for x, building_id in enumerate(sorted(building_ids)): retVal = self._create_build_buttons(building_id[0], container) if retVal != None: build_buttons.append(retVal) if x % 3 == 0: container.stylize('menu_black') parent_container.addChild(container) else: container = gui.findChild(name="fields_container") for name, cls in build_buttons: self.widget.mapEvents({name: Callback(self.buildField, cls)}) super(BuildRelatedTab, self).refresh()
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 refresh(self): """This function is called by the TabWidget to redraw the widget.""" # remove old field data parent_container = self.widget.child_finder('related_fields') while len(parent_container.children) > 0: parent_container.removeChild(parent_container.children[0]) # Load all related Fields of this Farm building_ids = self.instance.session.db.cached_query("SELECT related_building FROM related_buildings where building = ?", self.instance.id) build_buttons = list() gui = load_xml_translated(self.relatedfields_gui_xml) container = gui.findChild(name="fields_container") for x,building_id in enumerate(sorted(building_ids)): retVal = self._create_build_buttons(building_id[0], container) if retVal != None: build_buttons.append(retVal) if x%3==0: container.stylize('menu_black') parent_container.addChild(container) else: container = gui.findChild(name="fields_container") for name, cls in build_buttons: self.widget.mapEvents({ name: Callback(self.buildField, cls) }) super(BuildRelatedTab, self).refresh()
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 load_gui(self): if self.gui is None: self.gui = load_xml_translated("build_menu/hud_builddetail.xml") self.gui.stylize('menu_black') self.gui.findChild(name='headline').stylize('headline') self.gui.findChild(name='building_name').stylize('headline') top_bar = self.gui.findChild(name='top_bar') top_bar.position = (self.gui.size[0]/2 - top_bar.size[0]/2 -16, 50) self.gui.position = ( horizons.main.fife.engine_settings.getScreenWidth() - self.gui.size[0] - 14, 157 ) self.gui.mapEvents( { "rotate_left": self.rotate_left, "rotate_right": self.rotate_right } ) # set building name in gui self.gui.findChild(name='building_name').text = u' ' + unicode(self._class._name) self.gui.findChild(name='running_costs').text = unicode(self._class.running_costs) head_box = self.gui.findChild(name='head_box') head_box.adaptLayout() # recalculates size for new content head_box.position = ( # calculate and set new center (pychan doesn't support it) self.gui.size[0]/2 - head_box.size[0]/2, head_box.position[1] ) head_box.adaptLayout() self.draw_gui() self.session.view.add_change_listener(self.draw_gui)
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 add_gui_entry(self, branch_office, resource_list = {}): vbox = self._gui.findChild(name="left_vbox") entry = load_xml_translated("route_entry.xml") self.widgets.append(entry) label = entry.findChild(name="bo_name") label.text = unicode(branch_office.settlement.name) self.add_trade_slots(entry, self.slots_per_entry) index = 1 for res_id in resource_list: if index > self.slots_per_entry: break self.add_resource(self.slots[entry][index - 1],\ res_id, \ entry, \ has_value = True, \ value = resource_list[res_id]) index += 1 entry.mapEvents({ 'delete_bo/mouseClicked' : Callback(self.remove_entry, entry), 'move_up/mouseClicked' : Callback(self.move_entry, entry, 'up'), 'move_down/mouseClicked' : Callback(self.move_entry, entry, 'down') }) vbox.addChild(entry)
def __init__(self, ingame_gui, tabs=[], position=None, name=None, active_tab=None): """ @param ingame_gui: IngameGui instance @param tabs: tab instances to show @param position: position as tuple (x, y) @param name: optional name for the tabwidget @param active_tab: int id of tab, 0 <= active_tab < len(tabs) """ super(TabWidget, self).__init__() self.name = name self.ingame_gui = ingame_gui self._tabs = tabs self.current_tab = self._tabs[0] # Start with the first tab self.widget = load_xml_translated("tab_widget/tab_base.xml") if position is None: # add positioning here self.widget.position = ( horizons.main.fife.engine_settings.getScreenWidth() - 303, 209 ) else: self.widget.position = position self.content = self.widget.findChild(name='content') self._init_tabs() # select a tab to show (first one is default) if active_tab is not None: self._show_tab(active_tab)
def add_trade_slots(self, entry, num): x_position = 105 #initialize slots with empty dict self.slots[entry] = {} for num in range(0,num): slot = load_xml_translated('trade_single_slot.xml') slot.position = x_position, 0 slot.action = "load" slider = slot.findChild(name="slider") slider.setScaleStart(0.0) slider.setScaleEnd(float(self.instance.inventory.limit)) slot.findChild(name="buysell").capture(Callback(self.toggle_load_unload, slot, entry)) button = slot.findChild(name="button") button.capture(Callback(self.show_resource_menu, slot, entry)) button.up_image = self.dummy_icon_path button.down_image = self.dummy_icon_path button.hover_image = self.dummy_icon_path icon = slot.findChild(name="icon") fillbar = slot.findChild(name="fillbar") fillbar.position = (icon.width - fillbar.width -1, icon.height) x_position += 60 entry.addChild(slot) self.slots[entry][num] = slot
def _init_gui(self): """Initial init of gui.""" self._gui = load_xml_translated("configure_route.xml") self.listbox = self._gui.findChild(name="branch_office_list") self.listbox._setItems(list(self.branch_offices)) vbox = self._gui.findChild(name="left_vbox") for entry in self.instance.route.waypoints: hbox = widgets.HBox() label = widgets.Label() label.text = unicode(entry['branch_office'].settlement.name) hbox.addChild(label) vbox.addChild(hbox) # we want escape key to close the widget, what needs to be fixed here? self._gui.on_escape = self.hide # needs to check the current state and set the button state afterwards # self._gui.findChild(name='start_route').set_inactive() self._gui.mapEvents({ 'cancelButton' : self.hide, 'add_bo/mouseClicked' : self.append_bo, 'start_route/mouseClicked' : self.instance.route.enable, # 'start_route/mouseClicked' : self.toggle_route }) center_widget(self._gui)
def _init_gui(self): """Initial init of gui.""" self._gui = load_xml_translated("configure_route.xml") self.listbox = self._gui.findChild(name="branch_office_list") self.listbox._setItems(list(self.branch_offices)) vbox = self._gui.findChild(name="left_vbox") for entry in self.instance.route.waypoints: hbox = widgets.HBox() label = widgets.Label() label.text = unicode(entry['branch_office'].settlement.name) hbox.addChild(label) vbox.addChild(hbox) # we want escape key to close the widget, what needs to be fixed here? self._gui.on_escape = self.hide # needs to check the current state and set the button state afterwards # self._gui.findChild(name='start_route').set_inactive() self._gui.mapEvents({ 'cancelButton': self.hide, 'add_bo/mouseClicked': self.append_bo, 'start_route/mouseClicked': self.instance.route.enable, # 'start_route/mouseClicked' : self.toggle_route }) center_widget(self._gui)
def __init__(self, ingame_gui, tabs=[], position=None, name=None, active_tab=None): """ @param ingame_gui: IngameGui instance @param tabs: tab instances to show @param position: position as tuple (x, y) @param name: optional name for the tabwidget @param active_tab: int id of tab, 0 <= active_tab < len(tabs) """ super(TabWidget, self).__init__() self.name = name self.ingame_gui = ingame_gui self._tabs = tabs self.current_tab = self._tabs[0] # Start with the first tab self.widget = load_xml_translated("tab_base.xml") if position is None: # add positioning here self.widget.position = ( horizons.main.fife.engine_settings.getScreenWidth() - 303, 209) else: self.widget.position = position self.content = self.widget.findChild(name='content') self._init_tabs() # select a tab to show (first one is default) if active_tab is not None: self._show_tab(active_tab)
def add_slots(self, num): """Adds num amount of slots to the buysellmenu. @param num: amount of slots that are to be added.""" content = self.widget.findChild(name="content") assert(content is not None) for num in range(0, num): slot = load_xml_translated('trade_single_slot.xml') self.slots[num] = slot slot.id = num slot.action = 'buy' slot.res = None slot.findChild(name='button').capture(Callback(self.show_resource_menu, num)) slot.findChild(name='button').up_image = self.dummy_icon_path slot.findChild(name='button').down_image = self.dummy_icon_path slot.findChild(name='button').hover_image = self.dummy_icon_path slot.findChild(name='amount').stylize('menu_black') slider = slot.findChild(name="slider") slider.setScaleStart(0.0) slider.setScaleEnd(float(self.settlement.inventory.limit))# Set scale according to the settlements inventory size slot.findChild(name="buysell").capture(Callback(self.toggle_buysell, num)) fillbar = slot.findChild(name="fillbar") # hide fillbar by setting position icon = slot.findChild(name="icon") fillbar.position = (icon.width - fillbar.width - 1, icon.height) content.addChild(slot) self.widget.adaptLayout()
def refresh(self): """This function is called by the TabWidget to redraw the widget.""" cap_util = 0 if hasattr(self.instance, 'capacity_utilisation'): cap_util = int(round( self.instance.capacity_utilisation * 100)) self.widget.child_finder('capacity_utilisation').text = unicode(cap_util) + u'%' # remove old production line data parent_container = self.widget.child_finder('production_lines') while len(parent_container.children) > 0: parent_container.removeChild(parent_container.children[0]) # create a container for each production # sort by production line id to have a consistent (basically arbitrary) order for production in sorted(self.instance._get_productions(), \ key=(lambda x: x.get_production_line_id())): gui = load_xml_translated(self.production_line_gui_xml) # fill in values to gui reflecting the current game state container = gui.findChild(name="production_line_container") if production.is_paused(): container.removeChild( container.findChild(name="toggle_active_active") ) container.findChild(name="toggle_active_inactive").name = "toggle_active" else: container.removeChild( container.findChild(name="toggle_active_inactive") ) container.findChild(name="toggle_active_active").name = "toggle_active" # fill it with input and output resources in_res_container = container.findChild(name="input_res") for in_res in production.get_consumed_resources(): filled = float(self.instance.inventory[in_res]) * 100 / \ self.instance.inventory.get_limit(in_res) in_res_container.addChild( \ ImageFillStatusButton.init_for_res(self.instance.session.db,\ in_res, \ self.instance.inventory[in_res], \ filled, \ use_inactive_icon=False) \ ) out_res_container = container.findChild(name="output_res") for out_res in production.get_produced_res(): filled = float(self.instance.inventory[out_res]) * 100 / \ self.instance.inventory.get_limit(out_res) out_res_container.addChild( \ ImageFillStatusButton.init_for_res(self.instance.session.db, \ out_res, \ self.instance.inventory[out_res], \ filled, \ use_inactive_icon=False) \ ) # active toggle_active button container.mapEvents( \ { 'toggle_active': \ Callback(ToggleActive(self.instance, production).execute, self.instance.session) \ } ) # NOTE: this command causes a refresh, so we needn't change the toggle_active-button-image container.stylize('menu_black') parent_container.addChild(container) super(ProductionOverviewTab, self).refresh()
def __init__(self, session, x, y): super(LivingObject, self).__init__() self.session = session self.x_pos, self.y_pos = x, y self.active_messages = [] # for displayed messages self.archive = [] # messages, that aren't displayed any more self.widget = load_xml_translated('hud_messages.xml') self.widget.position = ( 5, horizons.main.fife.engine_settings.getScreenHeight()/2 - self.widget.size[1]/2) self.text_widget = load_xml_translated('hud_messages_text.xml') self.text_widget.position = (self.widget.x + self.widget.width, self.widget.y) self.widget.show() self.current_tick = 0 self.position = 0 # number of current message ExtScheduler().add_new_object(self.tick, self, loops=-1)
def _init_gui(self): self._gui = load_xml_translated("stringpreviewwidget.xml") self._gui.mapEvents({ 'load' : self.load }) self.scenarios = SavegameManager.get_scenarios() self.listbox = self._gui.findChild(name="scenario_list") self.listbox.items = self.scenarios[1] self.logbook = LogBook()
def _init_gui(self): """Initial init of gui.""" self._gui = load_xml_translated("captains_log.xml") self._gui.mapEvents({ 'backwardButton' : Callback(self._scroll, -2), 'forwardButton' : Callback(self._scroll, 2), 'cancelButton' : self.hide }) center_widget(self._gui)
def _load_widget(self, widgetname): widget = load_xml_translated(widgetname + ".xml") if self.center_widgets: center_widget(widget) headline = widget.findChild(name="headline") if headline: headline.stylize("headline") if widgetname in self.styles: widget.stylize(self.styles[widgetname]) self[widgetname] = widget
def _load_widget(self, widgetname): widget = load_xml_translated(widgetname+'.xml') if self.center_widgets: center_widget(widget) headlines = widget.findChildren(name='headline') for headline in headlines: headline.stylize('headline') if widgetname in self.styles: widget.stylize(self.styles[widgetname]) self[widgetname] = widget
def _init_gui(self): """Initial init of gui.""" self._gui = load_xml_translated("choose_next_scenario.xml") self._gui.mapEvents({ 'choose_scenario' : Callback(self.validate_choice), 'cancelButton' : Callback(self.hide), }) self._gui.position_technique = "automatic" # "center:center" #SavegameManager.get_campaign_info(cls, name = "", file = "") self.choose_scenario = self._gui.findChild(name="choose_scenario")
def _init_gui(self): """Initial init of gui.""" self._gui = load_xml_translated("choose_next_scenario.xml") self._gui.mapEvents({ 'choose_scenario': Callback(self.validate_choice), 'cancelButton': Callback(self.hide), }) self._gui.position_technique = "automatic" # "center:center" #SavegameManager.get_campaign_info(cls, name = "", file = "") self.choose_scenario = self._gui.findChild(name="choose_scenario")
def _init_gui(self): """Initial init of gui.""" self._gui = load_xml_translated("captains_log.xml") self._gui.mapEvents({ 'backwardButton' : Callback(self._scroll, -2), 'forwardButton' : Callback(self._scroll, 2), 'cancelButton' : self.hide }) self._gui.position_technique = "automatic" # "center:center" self.backward_button = self._gui.findChild(name="backwardButton") self.forward_button = self._gui.findChild(name="forwardButton")
def _init_gui(self): """Initial init of gui.""" self._gui = load_xml_translated("captains_log.xml") self._gui.mapEvents({ 'backwardButton': Callback(self._scroll, -2), 'forwardButton': Callback(self._scroll, 2), 'cancelButton': self.hide }) center_widget(self._gui) self.backward_button = self._gui.findChild(name="backwardButton") self.forward_button = self._gui.findChild(name="forwardButton")
def __init__(self, widget = None, **kwargs): super(TabInterface, self).__init__() if widget is not None: self.widget = load_xml_translated(widget) self.widget.child_finder = PychanChildFinder(self.widget) else: self.widget = None # You can override these if you want to use separate images for your tab self.button_up_image = 'content/gui/images/tabwidget/tab.png' # TabButtons upimage self.button_down_image = 'content/gui/images/tabwidget/tab.png' # TabButtons downimage self.button_hover_image = 'content/gui/images/tabwidget/tab_a.png' # TabButtons hoverimage self.button_active_image = 'content/gui/images/tabwidget/tab.png' # TabButtons active image self.button_background_image = 'content/gui/images/tabwidget/tab.png' # TabButtons background image
def init_tooltip(self, tooltip): self.gui = load_xml_translated('tooltip.xml') self.gui.hide() self.tooltip = tooltip self.mapEvents({ self.name + '/mouseEntered' : self.position_tooltip, self.name + '/mouseExited' : self.hide_tooltip, self.name + '/mousePressed' : self.hide_tooltip, self.name + '/mouseMoved' : self.position_tooltip, #self.name + '/mouseReleased' : self.position_tooltip, self.name + '/mouseDragged' : self.hide_tooltip }) self.tooltip_shown = False self.tooltip_items = []
def _load_widget(self, widgetname): """ We do styling before setting headlines to the default headline style. If you want your headlines to not be styled, rename them. """ widget = load_xml_translated(widgetname+'.xml') if widgetname in self.styles: widget.stylize(self.styles[widgetname]) for w in widget.findChildren(): if w.name.startswith("headline") or \ w.name is "name": w.stylize('headline') if self.center_widgets: widget.position_technique = "automatic" # "center:center" self[widgetname] = widget
def _load_widget(self, widgetname): """ We do styling before setting headlines to the default headline style. If you want your headlines to not be styled, rename them. """ widget = load_xml_translated(widgetname + '.xml') if widgetname in self.styles: widget.stylize(self.styles[widgetname]) for w in widget.findChildren(): if w.name.startswith("headline") or \ w.name is "name": w.stylize('headline') if self.center_widgets: widget.position_technique = "automatic" # "center:center" self[widgetname] = widget
def __init__(self, instance): """ @param instance: ship instance used for trading """ self.widget = load_xml_translated('exchange_goods.xml') self.widget.position_technique = "right:top+157" events = {} for k, v in self.exchange_size_buttons.iteritems(): events[v] = Callback(self.set_exchange, k) self.widget.mapEvents(events) self.instance = instance self.partner = None self.set_exchange(50, initial=True) self.draw_widget() if hasattr(self.instance, 'radius'): self.radius = self.instance.radius
def __init__(self, instance): """ @param instance: ship instance used for trading """ self.widget = load_xml_translated("exchange_goods.xml") self.widget.position_technique = "right:top+157" events = {} for k, v in self.exchange_size_buttons.iteritems(): events[v] = Callback(self.set_exchange, k) self.widget.mapEvents(events) self.instance = instance self.partner = None self.set_exchange(50, initial=True) self.draw_widget() if hasattr(self.instance, "radius"): self.radius = self.instance.radius
def load_gui(self): if self.gui is None: self.gui = load_xml_translated("place_building.xml") top_bar = self.gui.findChild(name="top_bar") top_bar.position = (self.gui.size[0] / 2 - top_bar.size[0] / 2 - 16, 50) self.gui.position_technique = "right-14:top+157" self.gui.mapEvents({"rotate_left": self.rotate_left, "rotate_right": self.rotate_right}) # set translated building name in gui self.gui.findChild(name="headline").text = _("Build") + u" " + _(self._class._name) self.gui.findChild(name="running_costs").text = unicode(self._class.running_costs) head_box = self.gui.findChild(name="head_box") head_box.adaptLayout() # recalculates size of new content head_box.position = ( # calculate and set new center (we cause pychan to not support it) max(self.gui.size[0] / 2 - head_box.size[0] / 2, 25), head_box.position[1], ) head_box.adaptLayout() self.draw_gui() self.session.view.add_change_listener(self.draw_gui)
def __init__(self, instance): """ @param instance: ship instance used for trading """ self.widget = load_xml_translated('exchange_goods.xml') self.widget.position = ( horizons.main.fife.engine_settings.getScreenWidth() - self.widget.size[0], 157) self.widget.stylize('menu_black') self.widget.findChild(name='headline').stylize( 'headline') # style definition for headline events = {} for k, v in self.exchange_size_buttons.iteritems(): events[v] = Callback(self.set_exchange, k) self.widget.mapEvents(events) self.instance = instance self.partner = None self.set_exchange(50, initial=True) self.draw_widget() if hasattr(self.instance, 'radius'): self.radius = self.instance.radius
def __init__(self, instance): """ @param instance: ship instance used for trading """ self.widget = load_xml_translated('exchange_goods.xml') self.widget.position = ( horizons.main.fife.engine_settings.getScreenWidth() - self.widget.size[0], 157 ) self.widget.stylize('menu_black') self.widget.findChild(name='headline').stylize('headline') # style definition for headline events = {} for k, v in self.exchange_size_buttons.iteritems(): events[v] = pychan.tools.callbackWithArguments(self.set_exchange, k) self.widget.mapEvents(events) self.instance = instance self.partner = None self.set_exchange(10, initial=True) self.draw_widget() if hasattr(self.instance, 'radius'): self.radius = self.instance.radius
def _init_gui(self): """ Initial init of gui. widgets : list of route entry widgets slots : dict with slots for each entry """ self._gui = load_xml_translated("configure_route.xml") self.listbox = self._gui.findChild(name="branch_office_list") self.listbox._setItems(list(self.branch_offices)) self.widgets=[] self.slots={} self.slots_per_entry = 3 resources = horizons.main.db.get_res_id_and_icon(True) #map an icon for a resource #map a resource for an icon self.resource_for_icon = {} self.icon_for_resource = {} for res_id, icon in list(resources) + [(0, self.dummy_icon_path)]: self.resource_for_icon[icon] = res_id self.icon_for_resource[res_id] = icon #don't do any actions if the resource menu is shown self.resource_menu_shown = False for entry in self.instance.route.waypoints: self.add_gui_entry(entry['branch_office'], entry['resource_list']) # we want escape key to close the widget, what needs to be fixed here? #self._gui.on_escape = self.hide self.start_button_set_active() if self.instance.route.enabled: self.start_button_set_inactive() self._gui.mapEvents({ 'cancelButton' : self.hide, 'add_bo/mouseClicked' : self.append_bo, 'start_route/mouseClicked' : self.toggle_route }) self._gui.position_technique = "automatic" # "center:center"
def load_gui(self): if self.gui is None: self.gui = load_xml_translated("place_building.xml") top_bar = self.gui.findChild(name='top_bar') top_bar.position = (self.gui.size[0] / 2 - top_bar.size[0] / 2 - 16, 50) self.gui.position_technique = "right-14:top+157" self.gui.mapEvents({ "rotate_left": self.rotate_left, "rotate_right": self.rotate_right }) # set translated building name in gui self.gui.findChild( name='headline').text = _('Build') + u' ' + _(self._class._name) self.gui.findChild(name='running_costs').text = unicode( self._class.running_costs) head_box = self.gui.findChild(name='head_box') head_box.adaptLayout() # recalculates size of new content head_box.position = ( # calculate and set new center (we cause pychan to not support it) max(self.gui.size[0] / 2 - head_box.size[0] / 2, 25), head_box.position[1]) head_box.adaptLayout() self.draw_gui() self.session.view.add_change_listener(self.draw_gui)
def _loadWidget(self, dialog): return load_xml_translated(dialog)
def refresh(self): """This function is called by the TabWidget to redraw the widget.""" cap_util = 0 if hasattr(self.instance, 'capacity_utilisation'): cap_util = int(round( self.instance.capacity_utilisation * 100)) self.widget.child_finder('capacity_utilisation').text = unicode(cap_util) + u'%' # remove old production line data parent_container = self.widget.child_finder('production_lines') while len(parent_container.children) > 0: parent_container.removeChild(parent_container.children[0]) # create a container for each production # sort by production line id to have a consistent (basically arbitrary) order for production in sorted(self.instance._get_productions(), \ key=(lambda x: x.get_production_line_id())): gui = load_xml_translated(self.production_line_gui_xml) # fill in values to gui reflecting the current game state container = gui.findChild(name="production_line_container") if production.is_paused(): container.removeChild( container.findChild(name="toggle_active_active") ) container.findChild(name="toggle_active_inactive").name = "toggle_active" else: container.removeChild( container.findChild(name="toggle_active_inactive") ) container.findChild(name="toggle_active_active").name = "toggle_active" # fill it with input and output resources in_res_container = container.findChild(name="input_res") for in_res in production.get_consumed_resources(): filled = float(self.instance.inventory[in_res]) * 100 / \ self.instance.inventory.get_limit(in_res) in_res_container.addChild( \ ImageFillStatusButton.init_for_res(self.instance.session.db,\ in_res, \ self.instance.inventory[in_res], \ filled, \ use_inactive_icon=False) \ ) out_res_container = container.findChild(name="output_res") for out_res in production.get_produced_res(): filled = float(self.instance.inventory[out_res]) * 100 / \ self.instance.inventory.get_limit(out_res) out_res_container.addChild( \ ImageFillStatusButton.init_for_res(self.instance.session.db, \ out_res, \ self.instance.inventory[out_res], \ filled, \ use_inactive_icon=False) \ ) # fix pychans lack of dynamic container sizing # the container in the xml must provide a height attribute, that is valid for # one resource. max_res_in_one_line = max(len(production.get_produced_res()), \ len(production.get_consumed_resources())) container.height = max_res_in_one_line * container.height # active toggle_active button container.mapEvents( \ { 'toggle_active': \ Callback(ToggleActive(self.instance, production).execute, self.instance.session) \ } ) # NOTE: this command causes a refresh, so we needn't change the toggle_active-button-image container.stylize('menu_black') parent_container.addChild(container) super(ProductionOverviewTab, self).refresh()