Ejemplo n.º 1
0
	def __init__(self):
		self.page_widgets = {}
		self.dict_lt = {}
		self.dict_rt = {}
		self.widget = load_uh_widget(self.widget_xml, style=self.style)

		self.pickbelts_container_lt = self.widget.findChild(name="left_pickbelts")
		self.pickbelts_container_rt = self.widget.findChild(name="right_pickbelts")

		for i in range(len(self.sections)):
			self.page_widgets[i] = self.widget.findChild(name=self.sections[i][0])

		# Create the required pickbelts
		for side in ('lt', 'rt'):
			for i in range(len(self.sections)):
				pickbelt = ImageButton(is_focusable=False)
				pickbelt.name = self.sections[i][0] + '_' + side
				pickbelt.text = self.sections[i][1]
				pickbelt.font = "small_tooltip"
				pickbelt.position = (self.pickbelt_start_pos[0]+5*i, self.pickbelt_start_pos[1]+70*i)
				pickbelt.capture(Callback(self.update_view, i), event_name="mouseClicked")
				if side == 'lt':
					pickbelt.up_image='content/gui/images/background/pickbelt_l.png'
					self.pickbelts_container_lt.addChild(pickbelt)
					self.dict_lt[i] = pickbelt
				else:
					pickbelt.up_image='content/gui/images/background/pickbelt_r.png'
					self.pickbelts_container_rt.addChild(pickbelt)
					self.dict_rt[i] = pickbelt
		self.widget.show() # Hack to initially setup the pickbelts properly
		self.update_view()
		self.widget.hide() # Hack to initially setup the pickbelts properly
	def __init__(self):
		self.page_widgets = {}
		self.widget = load_uh_widget(self.widget_xml, center_widget=True)

		# Lists holding pickbelt ImageButtons, placed to the left/right of the book
		self.buttons = {'left': [], 'right': []}

		for i, (name, text) in enumerate(self.sections):
			self.page_widgets[i] = self.widget.findChild(name=name)

		# Create the required pickbelts
		for i, (name, text) in enumerate(self.sections):
			for side in self.buttons:
				pickbelt = ImageButton(is_focusable=False, text=text)
				pickbelt.name = name + '_' + side
				pickbelt.up_image = 'content/gui/images/background/pickbelt_%s.png' % side
				pickbelt.font = "small_tooltip"

				pickbelt.capture(Callback(self.update_view, i), event_name="mouseClicked")

				start_x, start_y = self.pickbelt_start_pos
				pickbelt.position = (start_x + 5*i, start_y + 70*i)

				container = self.widget.findChild(name="%s_pickbelts" % side)
				container.addChild(pickbelt)
				self.buttons[side].append(pickbelt)

		self.widget.show() # Hack to initially setup the pickbelts properly
		self.update_view()
		self.widget.hide() # Hack to initially setup the pickbelts properly
Ejemplo n.º 3
0
def create_resource_selection_dialog(
    on_click, inventory, db, widget="select_trade_resource.xml", res_filter=None, amount_per_line=None
):
    """Returns a container containing resource icons.
	@param on_click: called with resource id as parameter on clicks
	@param inventory: to determine fill status of resource slots
	@param db: main db instance
	@param widget: which xml file to use as a template. Default: tabwidget. Required
	               since the resource bar also uses this code (no tabs there though).
	@param res_filter: callback to decide which icons to use. Default: show all
	@param amount_per_line: how many resource icons per line. Default: try to fit layout
	"""
    from horizons.gui.widgets.imagefillstatusbutton import ImageFillStatusButton

    dummy_icon_path = "content/gui/icons/resources/none_gray.png"

    dlg = load_uh_widget(widget)

    button_width = ImageFillStatusButton.CELL_SIZE[0]  # used for dummy button
    vbox = dlg.findChild(name="resources")
    amount_per_line = amount_per_line or vbox.width // button_width
    # Add the zero element to the beginning that allows to remove the currently
    # sold/bought resource:
    resources = [0] + db.get_res(only_tradeable=True)
    current_hbox = HBox(name="hbox_0", padding=0)
    index = 1
    for res_id in resources:
        # don't show resources that are already in the list
        if res_filter is not None and not res_filter(res_id):
            continue
            # create button (dummy one or real one)
        if res_id == 0 or inventory is None:
            button = ImageButton(size=(button_width, button_width), name="resource_icon_00")
            button.up_image, button.down_image, button.hover_image = (dummy_icon_path,) * 3
        else:
            amount = inventory[res_id]
            filled = int(float(inventory[res_id]) / float(inventory.get_limit(res_id)) * 100.0)
            button = ImageFillStatusButton.init_for_res(
                db, res_id, amount=amount, filled=filled, uncached=True, use_inactive_icon=False
            )
            # on click: add this res
        cb = Callback(on_click, res_id)
        if hasattr(button, "button"):  # for imagefillstatusbuttons
            button.button.capture(cb)
            button.button.name = "resource_%d" % res_id
        else:
            button.capture(cb)
            button.name = "resource_%d" % res_id

        current_hbox.addChild(button)
        if index % amount_per_line == 0:
            vbox.addChild(current_hbox)
            box_id = index // amount_per_line
            current_hbox = HBox(name="hbox_%s" % box_id, padding=0)
        index += 1
    vbox.addChild(current_hbox)
    vbox.adaptLayout()

    return dlg
Ejemplo 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
Ejemplo 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
Ejemplo n.º 6
0
    def __init__(self):
        self.page_widgets = {}
        self.dict_lt = {}
        self.dict_rt = {}
        self.widget = load_uh_widget(self.widget_xml, style=self.style)

        self.pickbelts_container_lt = self.widget.findChild(
            name="left_pickbelts")
        self.pickbelts_container_rt = self.widget.findChild(
            name="right_pickbelts")

        for i in range(len(self.sections)):
            self.page_widgets[i] = self.widget.findChild(
                name=self.sections[i][0])

        # Create the required pickbelts
        for side in ('lt', 'rt'):
            for i in range(len(self.sections)):
                pickbelt = ImageButton(is_focusable=False)
                pickbelt.name = self.sections[i][0] + '_' + side
                pickbelt.text = self.sections[i][1]
                pickbelt.font = "small_tooltip"
                pickbelt.position = (self.pickbelt_start_pos[0] + 5 * i,
                                     self.pickbelt_start_pos[1] + 70 * i)
                pickbelt.capture(Callback(self.update_view, i),
                                 event_name="mouseClicked")
                if side == 'lt':
                    pickbelt.up_image = 'content/gui/images/background/pickbelt_l.png'
                    self.pickbelts_container_lt.addChild(pickbelt)
                    self.dict_lt[i] = pickbelt
                else:
                    pickbelt.up_image = 'content/gui/images/background/pickbelt_r.png'
                    self.pickbelts_container_rt.addChild(pickbelt)
                    self.dict_rt[i] = pickbelt
        self.widget.show()  # Hack to initially setup the pickbelts properly
        self.update_view()
        self.widget.hide()  # Hack to initially setup the pickbelts properly