Exemplo n.º 1
0
	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)
			helptext = self.instance.session.db.get_building_tooltip(building_id)

			build_button = ImageButton(name="build{id}".format(id=building_id), \
			                             helptext=helptext)
			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 _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 = ship.get_component(NamedComponent).name
		ship_name.min_size = ship_name.max_size = (100, 20)

		rename_icon = ImageButton(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.helptext = _("Click to change the name of this ship")
		rename_icon.max_size = (20, 20) # (width, height)

		ship_type = widgets.Label(name = 'ship_type_%d' % ship.worldid)
		ship_type.text = 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 = u', '.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 = u'%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 = settlement.get_component(NamedComponent).name
		name.min_size = name.max_size = (175, 20)

		rename_icon = ImageButton(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.helptext = _("Click to change the name of your settlement")
		rename_icon.max_size = (20, 20) # (width, height)

		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
Exemplo n.º 4
0
    def draw_widget(self):
        """
		Updates whole messagewidget (all messages): draw icons.
		Inactive messages need their icon hovered to display their text again
		"""
        button_space = self.widget.findChild(name="button_space")
        button_space.removeAllChildren()  # Remove old buttons
        for index, message in enumerate(self.active_messages):
            if (self.item + index) >= len(self.active_messages):
                # Only display most recent notifications
                continue
            button = ImageButton()
            button.name = str(index)
            button.up_image = message.up_image
            button.hover_image = message.hover_image
            button.down_image = message.down_image
            button.is_focusable = False
            # show text on hover
            events = {
                button.name + "/mouseEntered": Callback(self.show_text, index),
                button.name + "/mouseExited": self.hide_text,
            }
            # init callback to something callable to improve robustness
            callback = Callback(lambda: None)
            if message.x is not None and message.y is not None:
                # move camera to source of event on click, if there is a source
                callback = Callback.ChainedCallbacks(
                    callback,  # this makes it so the order of callback assignment doesn't matter
                    Callback(self.session.view.center, message.x, message.y),
                    Callback(self.session.ingame_gui.minimap.highlight,
                             (message.x, message.y)))
            if message.type == "logbook":
                # open logbook to relevant page
                callback = Callback.ChainedCallbacks(
                    callback,  # this makes it so the order of callback assignment doesn't matter
                    Callback(self.session.ingame_gui.logbook.show,
                             message.created))
            if callback:
                events[button.name] = callback

            button.mapEvents(events)
            button_space.addChild(button)
        button_space.resizeToContent()
        self.widget.size = button_space.size
Exemplo n.º 5
0
	def draw_widget(self):
		"""
		Updates whole messagewidget (all messages): draw icons.
		Inactive messages need their icon hovered to display their text again
		"""
		button_space = self.widget.findChild(name="button_space")
		button_space.removeAllChildren() # Remove old buttons
		for index, message in enumerate(self.active_messages):
			if (self.item + index) >= len(self.active_messages):
				# Only display most recent notifications
				continue
			button = ImageButton()
			button.name = str(index)
			button.up_image = message.up_image
			button.hover_image = message.hover_image
			button.down_image = message.down_image
			button.is_focusable = False
			# show text on hover
			events = {
				button.name + "/mouseEntered": Callback(self.show_text, index),
				button.name + "/mouseExited": self.hide_text,
			}
			# init callback to something callable to improve robustness
			callback = Callback(lambda: None)
			if message.x is not None and message.y is not None:
				# move camera to source of event on click, if there is a source
				callback = Callback.ChainedCallbacks(
					   callback, # this makes it so the order of callback assignment doesn't matter
					   Callback(self.session.view.center, message.x, message.y),
					   Callback(self.session.ingame_gui.minimap.highlight, (message.x, message.y) )
				   )
			if message.type == "logbook":
				# open logbook to relevant page
				callback = Callback.ChainedCallbacks(
					   callback, # this makes it so the order of callback assignment doesn't matter
					   Callback(self.session.ingame_gui.logbook.show, message.created)
				)
			if callback:
				events[button.name] = callback

			button.mapEvents(events)
			button_space.addChild(button)
		button_space.resizeToContent()
		self.widget.size = button_space.size
Exemplo n.º 6
0
    def _init_tabs(self):
        """Add enough tabbuttons for all widgets."""
        def on_tab_removal(tabwidget):
            # called when a tab is being removed (via weakref since tabs shouldn't have references to the parent tabwidget)
            # If one tab is removed, the whole tabwidget will die..
            # This is easy usually the desired behaviour.
            if tabwidget():
                tabwidget().on_remove()

        # Load buttons
        for index, tab in enumerate(self._tabs):
            # don't add a reference to the
            tab.add_remove_listener(Callback(on_tab_removal,
                                             weakref.ref(self)))
            container = Container(name="container_%s" % index)
            background = Icon(name="bg_%s" % index)
            button = ImageButton(name=str(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, 'helptext') and tab.helptext is not None:
                button.helptext = tab.helptext
            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()

        self._apply_layout_hack()
Exemplo n.º 7
0
	def _init_tabs(self):
		"""Add enough tabbuttons for all widgets."""
		def on_tab_removal(tabwidget):
			# called when a tab is being removed (via weakref since tabs shouldn't have references to the parent tabwidget)
			# If one tab is removed, the whole tabwidget will die..
			# This is easy usually the desired behaviour.
			if tabwidget():
				tabwidget().on_remove()

		# Load buttons
		for index, tab in enumerate(self._tabs):
			# don't add a reference to the
			tab.add_remove_listener(Callback(on_tab_removal, weakref.ref(self)))
			container = Container(name="container_%s" % index)
			background = Icon(name="bg_%s" % index)
			button = ImageButton(name=str(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, 'helptext') and tab.helptext is not None:
				button.helptext = tab.helptext
			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()

		self._apply_layout_hack()