class ShipInventoryTab(InventoryTab): def __init__(self, instance = None, widget = 'ship_inventory.xml', icon_path = 'content/gui/icons/tabwidget/common/inventory_%s.png'): #if no other widget or icon path are passed via inheritance, use default ones super(ShipInventoryTab, self).__init__(instance, widget, icon_path) self.tooltip = _("Ship inventory") def configure_route(self): self.route_menu = RouteConfig(self.instance) self.route_menu.toggle_visibility() def refresh(self): session = self.instance.session branches = session.world.get_branch_offices(self.instance.position, \ self.instance.radius, self.instance.owner, True) events = {} events['configure_route/mouseClicked'] = Callback(self.configure_route) # TODO: use a better way to decide which label should be shown if len(branches) > 0 and branches[0].owner is self.instance.owner: events['trade'] = Callback(session.ingame_gui.show_menu, TradeWidget(self.instance)) self.widget.findChild(name='load_unload_label').text = _('Load/Unload:') self.widget.findChild(name='bg_button').set_active() self.widget.findChild(name='trade').set_active() elif len(branches) > 0: events['trade'] = Callback(session.ingame_gui.show_menu, InternationalTradeWidget(self.instance)) self.widget.findChild(name='load_unload_label').text = _('Buy/Sell:') self.widget.findChild(name='bg_button').set_active() self.widget.findChild(name='trade').set_active() else: events['trade'] = None self.widget.findChild(name='bg_button').set_inactive() self.widget.findChild(name='trade').set_inactive() self.widget.mapEvents(events) super(ShipInventoryTab, self).refresh() def show(self): if not self.instance.has_change_listener(self.refresh): self.instance.add_change_listener(self.refresh) super(ShipInventoryTab, self).show() def hide(self): if self.instance.has_change_listener(self.refresh): self.instance.remove_change_listener(self.refresh) super(ShipInventoryTab, self).hide()
class ShipOverviewTab(OverviewTab): def __init__(self, instance, widget='overview_trade_ship.xml', icon_path='content/gui/icons/tabwidget/ship/ship_inv_%s.png'): super(ShipOverviewTab, self).__init__(instance, widget, icon_path) self.widget.child_finder('inventory').init( self.instance.session.db, self.instance.get_component(StorageComponent).inventory) self.helptext = _("Ship overview") def _configure_route(self): self.route_menu = RouteConfig(self.instance) self.route_menu.toggle_visibility() def _refresh_found_settlement_button(self, events): island_without_player_settlement_found = False helptext = _( "The ship needs to be close to an island to found a settlement.") for island in self.instance.session.world.get_islands_in_radius( self.instance.position, self.instance.radius): if not any(settlement.owner.is_local_player for settlement in island.settlements): island_without_player_settlement_found = True else: helptext = _("You already have a settlement on this island.") if island_without_player_settlement_found: events['found_settlement'] = Callback( self.instance.session.ingame_gui._build, BUILDINGS.WAREHOUSE, weakref.ref(self.instance)) self.widget.child_finder('found_settlement_bg').set_active() self.widget.child_finder('found_settlement').set_active() self.widget.child_finder('found_settlement').helptext = _( "Build settlement") else: events['found_settlement'] = None self.widget.child_finder('found_settlement_bg').set_inactive() self.widget.child_finder('found_settlement').set_inactive() self.widget.child_finder('found_settlement').helptext = helptext cb = Callback( self.instance.session.ingame_gui.resource_overview. set_construction_mode, self.instance, Entities.buildings[BUILDINGS.WAREHOUSE].costs) events['found_settlement/mouseEntered'] = cb cb1 = Callback(self.instance.session.ingame_gui.resource_overview. close_construction_mode) cb2 = Callback( self.widget.child_finder('found_settlement').hide_tooltip) #TODO the tooltip should actually hide on its own. Ticket #1096 cb = Callback.ChainedCallbacks(cb1, cb2) events['found_settlement/mouseExited'] = cb def _refresh_trade_button(self, events): warehouses = self.instance.get_tradeable_warehouses() if warehouses: if warehouses[0].owner is self.instance.owner: helptext = _('Load/Unload') else: helptext = _('Buy/Sell') events['trade'] = Callback( self.instance.get_component(SelectableComponent).show_menu, TradeTab) self.widget.findChild(name='trade_bg').set_active() self.widget.findChild(name='trade').set_active() self.widget.findChild(name='trade').helptext = helptext else: events['trade'] = None self.widget.findChild(name='trade_bg').set_inactive() self.widget.findChild(name='trade').set_inactive() self.widget.findChild(name='trade').helptext = _( 'Too far from the nearest tradeable warehouse') def _refresh_combat(self): # no combat def click_on_cannons(button): button.button.capture( Callback( self.instance.session.gui.show_popup, _("Cannot equip trade ship with weapons"), _("It is not possible to equip a trade ship with weapons.") )) self.widget.findChild(name='inventory').apply_to_buttons( click_on_cannons, lambda b: b.res_id == WEAPONS.CANNON) def refresh(self): # show rename when you click on name events = { 'name': Callback(self.instance.session.ingame_gui.show_change_name_dialog, self.instance), 'configure_route/mouseClicked': Callback(self._configure_route) } self._refresh_found_settlement_button(events) self._refresh_trade_button(events) self.widget.mapEvents(events) self.widget.child_finder('inventory').update() self._refresh_combat() super(ShipOverviewTab, self).refresh()
class ShipOverviewTab(OverviewTab): def __init__(self, instance, widget='overview_trade_ship.xml', icon_path='content/gui/icons/tabwidget/ship/ship_inv_%s.png'): super(ShipOverviewTab, self).__init__(instance, widget, icon_path) self.widget.child_finder('inventory').init(self.instance.session.db, self.instance.get_component(StorageComponent).inventory) self.helptext = _("Ship overview") def _configure_route(self): self.route_menu = RouteConfig(self.instance) self.route_menu.toggle_visibility() def _refresh_found_settlement_button(self, events): island_without_player_settlement_found = False helptext = _("The ship needs to be close to an island to found a settlement.") for island in self.instance.session.world.get_islands_in_radius(self.instance.position, self.instance.radius): if not any(settlement.owner.is_local_player for settlement in island.settlements): island_without_player_settlement_found = True else: helptext = _("You already have a settlement on this island.") if island_without_player_settlement_found: events['found_settlement'] = Callback(self.instance.session.ingame_gui._build, BUILDINGS.WAREHOUSE, weakref.ref(self.instance) ) self.widget.child_finder('found_settlement_bg').set_active() self.widget.child_finder('found_settlement').set_active() self.widget.child_finder('found_settlement').helptext = _("Build settlement") else: events['found_settlement'] = None self.widget.child_finder('found_settlement_bg').set_inactive() self.widget.child_finder('found_settlement').set_inactive() self.widget.child_finder('found_settlement').helptext = helptext cb = Callback( self.instance.session.ingame_gui.resource_overview.set_construction_mode, self.instance, Entities.buildings[BUILDINGS.WAREHOUSE].costs) events['found_settlement/mouseEntered'] = cb cb1 = Callback(self.instance.session.ingame_gui.resource_overview.close_construction_mode) cb2 = Callback(self.widget.child_finder('found_settlement').hide_tooltip) #TODO the tooltip should actually hide on its own. Ticket #1096 cb = Callback.ChainedCallbacks(cb1, cb2) events['found_settlement/mouseExited'] = cb def _refresh_trade_button(self, events): warehouses = self.instance.get_tradeable_warehouses() if warehouses: if warehouses[0].owner is self.instance.owner: helptext = _('Load/Unload') else: helptext = _('Buy/Sell') events['trade'] = Callback(self.instance.get_component(SelectableComponent).show_menu, TradeTab) self.widget.findChild(name='trade_bg').set_active() self.widget.findChild(name='trade').set_active() self.widget.findChild(name='trade').helptext = helptext else: events['trade'] = None self.widget.findChild(name='trade_bg').set_inactive() self.widget.findChild(name='trade').set_inactive() self.widget.findChild(name='trade').helptext = _('Too far from the nearest tradeable warehouse') def _refresh_combat(self): # no combat def click_on_cannons(button): button.button.capture(Callback( self.instance.session.gui.show_popup, _("Cannot equip trade ship with weapons"), _("It is not possible to equip a trade ship with weapons.") )) self.widget.findChild(name='inventory').apply_to_buttons(click_on_cannons, lambda b: b.res_id == WEAPONS.CANNON) def refresh(self): # show rename when you click on name events = { 'name': Callback(self.instance.session.ingame_gui.show_change_name_dialog, self.instance), 'configure_route/mouseClicked': Callback(self._configure_route) } self._refresh_found_settlement_button(events) self._refresh_trade_button(events) self.widget.mapEvents(events) self.widget.child_finder('inventory').update() self._refresh_combat() super(ShipOverviewTab, self).refresh()
def configure_route(self): route_menu = RouteConfig(self.instance) route_menu.toggle_visibility()
class ShipInventoryTab(InventoryTab): def __init__(self, instance = None, widget = 'ship_inventory.xml', icon_path = 'content/gui/icons/tabwidget/common/inventory_%s.png'): #if no other widget or icon path are passed via inheritance, use default ones super(ShipInventoryTab, self).__init__(instance, widget, icon_path) self.tooltip = _("Ship inventory") def configure_route(self): self.route_menu = RouteConfig(self.instance) self.route_menu.toggle_visibility() def refresh(self): session = self.instance.session branches = session.world.get_branch_offices(self.instance.position, \ self.instance.radius, self.instance.owner, True) events = {} events['configure_route/mouseClicked'] = Callback(self.configure_route) # TODO: use a better way to decide which label should be shown if len(branches) > 0: if branches[0].owner is self.instance.owner: wdg = TradeWidget(self.instance) text = _('Load/Unload:') else: wdg = InternationalTradeWidget(self.instance) text = _('Buy/Sell:') events['trade'] = Callback(session.ingame_gui.show_menu, wdg) self.widget.findChild(name='load_unload_label').text = text self.widget.findChild(name='bg_button').set_active() self.widget.findChild(name='trade').set_active() else: events['trade'] = None self.widget.findChild(name='bg_button').set_inactive() self.widget.findChild(name='trade').set_inactive() self._refresh_combat() self.widget.mapEvents(events) super(ShipInventoryTab, self).refresh() def _refresh_combat(self): # no combat def click_on_cannons(button): button.button.capture(Callback( self.instance.session.gui.show_popup, _("Can't equip trade ship with weapons"), _("It is not possible to equip a trade ship with weapons") )) self.widget.findChild(name='inventory').apply_to_buttons(click_on_cannons, lambda b: b.res_id == WEAPONS.CANNON) def show(self): if not self.instance.has_change_listener(self.refresh): self.instance.add_change_listener(self.refresh) super(ShipInventoryTab, self).show() def hide(self): if self.instance.has_change_listener(self.refresh): self.instance.remove_change_listener(self.refresh) super(ShipInventoryTab, self).hide()