def _create_build_buttons(self, id, container): building = Entities.buildings[id]( \ session=self.instance.session, \ x=0, y=0, \ rotation=45, owner=self.instance.owner, \ island=self.instance.island, \ instance=None) # Check if the level of the building is lower or same as the settler level if building.level <= self.instance.owner.settler_level: # Display Buildings build_button = TooltipButton(name="build"+str(id), tooltip=_("Build")+" "+_(unicode(building.name))) build_button_bg = pychan.widgets.Icon(image="content/gui/images/buttons/buildmenu_button_bg.png") buildmenu_image_path = "content/gui/icons/buildmenu/"; build_button.up_image=buildmenu_image_path+building.name.lower().replace(" ", "")+".png" build_button.down_image=buildmenu_image_path+building.name.lower().replace(" ", "")+"_h.png" build_button.hover_image=buildmenu_image_path+building.name.lower().replace(" ", "")+"_h.png" container.findChild(name="build_button_container").addChild(build_button) container.findChild(name="build_button_bg_container").addChild(build_button_bg) return (build_button.name, building) else: return None
def _create_build_buttons(self, id, container): building = Entities.buildings[id]( \ session=self.instance.session, \ x=0, y=0, \ rotation=45, owner=self.instance.owner, \ island=self.instance.island, \ instance=None) # Check if the level of the building is lower or same as the settler level if building.level <= self.instance.owner.settler_level: # Display Buildings build_button = TooltipButton(name="build" + str(id), tooltip=_("Build") + " " + _(unicode(building.name))) build_button_bg = pychan.widgets.Icon( image="content/gui/images/buttons/buildmenu_button_bg.png") buildmenu_image_path = "content/gui/icons/buildmenu/" build_button.up_image = buildmenu_image_path + building.name.lower( ).replace(" ", "") + ".png" build_button.down_image = buildmenu_image_path + building.name.lower( ).replace(" ", "") + "_h.png" build_button.hover_image = buildmenu_image_path + building.name.lower( ).replace(" ", "") + "_h.png" container.findChild( name="build_button_container").addChild(build_button) container.findChild( name="build_button_bg_container").addChild(build_button_bg) return (build_button.name, building) else: return None
def __init__(self, instance): super(ProductionOverviewTab, self).__init__(widget='overview_productionbuilding.xml', instance=instance) self.tooltip = _("Production overview") self.destruct_button = TooltipButton(name="destruct_button", \ up_image="content/gui/images/buttons/delete.png", \ down_image="content/gui/images/buttons/delete_h.png", \ hover_image="content/gui/images/buttons/delete_h.png", \ tooltip=_("Destroy building"), position=(190,330)) self.widget.addChild(self.destruct_button) self.widget.mapEvents({'destruct_button': self.destruct_building})
def _create_build_buttons(self, building_id, container): level = Entities.buildings[building_id].settler_level # Check if the level of the building is lower or same as the settler level if level <= self.instance.owner.settler_level: # {{mode}} in double braces because it is replaced as a second step path = "content/gui/icons/buildmenu/{id:03d}{{mode}}.png".format(id=building_id) tooltip = self.instance.session.db.get_building_tooltip(building_id) build_button = TooltipButton(name="build{id}".format(id=building_id), \ tooltip=tooltip) build_button.up_image = path.format(mode='') build_button.down_image = path.format(mode='_h') build_button.hover_image = path.format(mode='_h') build_button.capture(Callback(self.buildField, building_id)) container.findChild(name="build_button_container").addChild(build_button) build_button_bg = Icon(image="content/gui/images/buttons/buildmenu_button_bg.png") container.findChild(name="build_button_bg_container").addChild(build_button_bg) return True else: # No button built return False
def __init__(self, instance): super(ProductionOverviewTab, self).__init__( widget = 'buildings_gui/production_building_overview.xml', instance = instance ) self.button_up_image = 'content/gui/images/icons/hud/common/building_overview_u.png' self.button_active_image = 'content/gui/images/icons/hud/common/building_overview_a.png' self.button_down_image = 'content/gui/images/icons/hud/common/building_overview_d.png' self.button_hover_image = 'content/gui/images/icons/hud/common/building_overview_h.png' self.tooltip = u"Production Overview" self.destruct_button = TooltipButton(name="destruct_button", up_image="content/gui/images/background/delete.png", down_image="content/gui/images/background/delete_h.png", hover_image="content/gui/images/background/delete_h.png", tooltip=_("Destroy Building"), position=(190,330)) self.widget.addChild(self.destruct_button) self.widget.mapEvents( { 'destruct_button' : self.destruct_building } )
def _create_build_buttons(self, building_id, container): (level, name) = self.instance.session.db.get_building_level_name(building_id) # Check if the level of the building is lower or same as the settler level if level <= self.instance.owner.settler_level: buildmenu_image_path = "content/gui/icons/buildmenu/" path = buildmenu_image_path + name.lower().replace(" ", "") build_button = TooltipButton(name="build"+str(building_id), \ tooltip=_("Build")+" "+_(unicode(name))) build_button.up_image = path + ".png" build_button.down_image = path + "_h.png" build_button.hover_image = path + "_h.png" build_button.capture(Callback(self.buildField, building_id)) container.findChild(name="build_button_container").addChild(build_button) build_button_bg = Icon(image="content/gui/images/buttons/buildmenu_button_bg.png") container.findChild(name="build_button_bg_container").addChild(build_button_bg) return True else: # No button built return False
def _create_build_buttons(self, building_id, container): level = self.instance.session.db.get_building_level(building_id) # Check if the level of the building is lower or same as the settler level if level <= self.instance.owner.settler_level: path = "content/gui/icons/buildmenu/%03d" % building_id + "%s.png" tooltip = self.instance.session.db.get_building_tooltip(building_id) build_button = TooltipButton(name="build%s" % building_id, \ tooltip=tooltip) build_button.up_image = path % '' build_button.down_image = path % '_h' build_button.hover_image = path % '_h' build_button.capture(Callback(self.buildField, building_id)) container.findChild(name="build_button_container").addChild(build_button) build_button_bg = Icon(image="content/gui/images/buttons/buildmenu_button_bg.png") container.findChild(name="build_button_bg_container").addChild(build_button_bg) return True else: # No button built return False
class ProductionOverviewTab(OverviewTab): production_line_gui_xml = "tab_widget/tab_production_line.xml" def __init__(self, instance): super(ProductionOverviewTab, self).__init__( widget = 'buildings_gui/production_building_overview.xml', instance = instance ) self.button_up_image = 'content/gui/images/icons/hud/common/building_overview_u.png' self.button_active_image = 'content/gui/images/icons/hud/common/building_overview_a.png' self.button_down_image = 'content/gui/images/icons/hud/common/building_overview_d.png' self.button_hover_image = 'content/gui/images/icons/hud/common/building_overview_h.png' self.tooltip = u"Production Overview" self.destruct_button = TooltipButton(name="destruct_button", up_image="content/gui/images/background/delete.png", down_image="content/gui/images/background/delete_h.png", hover_image="content/gui/images/background/delete_h.png", tooltip=_("Destroy Building"), position=(190,330)) self.widget.addChild(self.destruct_button) self.widget.mapEvents( { 'destruct_button' : self.destruct_building } ) 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 destruct_building(self): self.instance.session.ingame_gui.hide_menu() if self.destruct_button.gui.isVisible(): self.destruct_button.hide_tooltip() Tear(self.instance).execute(self.instance.session)
class ProductionOverviewTab(OverviewTab): production_line_gui_xml = "overview_productionline.xml" def __init__(self, instance): super(ProductionOverviewTab, self).__init__(widget='overview_productionbuilding.xml', instance=instance) self.tooltip = _("Production overview") self.destruct_button = TooltipButton(name="destruct_button", \ up_image="content/gui/images/buttons/delete.png", \ down_image="content/gui/images/buttons/delete_h.png", \ hover_image="content/gui/images/buttons/delete_h.png", \ tooltip=_("Destroy building"), position=(190,330)) self.widget.addChild(self.destruct_button) self.widget.mapEvents({'destruct_button': self.destruct_building}) 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() def destruct_building(self): self.instance.session.ingame_gui.hide_menu() if self.destruct_button.gui.isVisible(): self.destruct_button.hide_tooltip() Tear(self.instance).execute(self.instance.session)