示例#1
0
	def init_widget(self):
		super(ShipOverviewTab, self).init_widget()
		self.ship_inv = self.instance.get_component(StorageComponent).inventory
		self.widget.child_finder('inventory').init(self.instance.session.db, self.ship_inv)

		# FIXME having to access the WindowManager this way is pretty ugly
		self._windows = self.instance.session.ingame_gui.windows
		self.route_menu = RouteConfig(self._windows, self.instance)
示例#2
0
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()
    def init_widget(self):
        super(ShipOverviewTab, self).init_widget()
        self.ship_inv = self.instance.get_component(StorageComponent).inventory
        self.widget.child_finder("inventory").init(self.instance.session.db, self.ship_inv)

        # FIXME having to access the WindowManager this way is pretty ugly
        self._windows = self.instance.session.ingame_gui.windows
        self.route_menu = RouteConfig(self._windows, self.instance)
示例#4
0
 def _configure_route(self):
     self.route_menu = RouteConfig(self.instance)
     self.route_menu.toggle_visibility()
示例#5
0
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):
		self.route_menu = RouteConfig(self.instance)
		self.route_menu.toggle_visibility()
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):
    widget = "overview_ship.xml"
    icon_path = "icons/tabwidget/ship/ship_inv"
    helptext = LazyT("Ship overview")

    def init_widget(self):
        super(ShipOverviewTab, self).init_widget()
        self.ship_inv = self.instance.get_component(StorageComponent).inventory
        self.widget.child_finder("inventory").init(self.instance.session.db, self.ship_inv)

        # FIXME having to access the WindowManager this way is pretty ugly
        self._windows = self.instance.session.ingame_gui.windows
        self.route_menu = RouteConfig(self._windows, self.instance)

    def _configure_route(self):
        self._windows.toggle(self.route_menu)

    def _refresh_found_settlement_button(self, events):
        island_without_player_settlement_found = False
        helptext = T("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 = T("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 = T("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 = T("Load/Unload")
            else:
                helptext = T("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 = T("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.ingame_gui.open_popup,
                    T("Cannot equip trade ship with weapons"),
                    T("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):
        events = {
            # show rename when you click on name
            "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 hide(self):
        self.route_menu.hide()
        super(ShipOverviewTab, self).hide()
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()
示例#10
0
class ShipOverviewTab(OverviewTab):
    widget = 'overview_ship.xml'
    icon_path = 'icons/tabwidget/ship/ship_inv'
    helptext = LazyT("Ship overview")

    def init_widget(self):
        super().init_widget()
        self.ship_inv = self.instance.get_component(StorageComponent).inventory
        self.widget.child_finder('inventory').init(self.instance.session.db,
                                                   self.ship_inv)

        # FIXME having to access the WindowManager this way is pretty ugly
        self._windows = self.instance.session.ingame_gui.windows
        self.route_menu = RouteConfig(self._windows, self.instance)

    def _configure_route(self):
        self._windows.toggle(self.route_menu)

    def _refresh_found_settlement_button(self, events):
        island_without_player_settlement_found = False
        helptext = T(
            "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 = T("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 = T(
                "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 = T('Load/Unload')
            else:
                helptext = T('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 = T(
                '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.ingame_gui.open_popup,
                    T("Cannot equip trade ship with weapons"),
                    T("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_traderoute_config_button(self, events):
        #verify if there are possible destinations for a traderoute
        warehouses = self.instance.session.world.settlements

        possible_warehouses = [
            warehouse for warehouse in warehouses
            if self.instance.session.world.diplomacy.can_trade(
                self.instance.session.world.player, warehouse.owner)
        ]

        if len(possible_warehouses) > 1:
            events['configure_route'] = Callback(self._configure_route)
            self.widget.findChild(name='configure_route').set_active()
            self.widget.findChild(
                name='configure_route').helptext = T("Configure trade route")
        else:
            events['configure_route'] = None
            self.widget.findChild(name='configure_route').set_inactive()
            self.widget.findChild(name='configure_route').helptext = T(
                "No available destinations for a trade route")

    def refresh(self):
        events = {
            # show rename when you click on name
            'name':
            Callback(self.instance.session.ingame_gui.show_change_name_dialog,
                     self.instance),
        }

        self._refresh_found_settlement_button(events)
        self._refresh_trade_button(events)
        self._refresh_traderoute_config_button(events)
        self.widget.mapEvents(events)

        self.widget.child_finder('inventory').update()
        self._refresh_combat()
        super().refresh()

    def hide(self):
        self.route_menu.hide()
        super().hide()