def __init__(self, session, x, y):
        super(MessageWidget, self).__init__()
        self.session = session
        self.x_pos, self.y_pos = x, y
        self.active_messages = []  # for displayed messages
        self.archive = []  # messages, that aren't displayed any more
        self.widget = load_uh_widget("hud_messages.xml")
        self.widget.position = (5, horizons.main.fife.engine_settings.getScreenHeight() / 2 - self.widget.size[1] / 2)

        self.text_widget = load_uh_widget("hud_messages_text.xml")
        self.text_widget.position = (self.widget.x + self.widget.width, self.widget.y)
        self.widget.show()
        self.current_tick = 0
        self.position = 0  # number of current message
        ExtScheduler().add_new_object(self.tick, self, loops=-1)
	def __init__(self, ingame_gui, tabs=None, position=None, name=None, active_tab=None):
		"""
		@param ingame_gui: IngameGui instance
		@param tabs: tab instances to show
		@param position: position as tuple (x, y)
		@param name: optional name for the tabwidget
		@param active_tab: int id of tab, 0 <= active_tab < len(tabs)
		"""
		super(TabWidget, self).__init__()
		self.name = name
		self.ingame_gui = ingame_gui
		self._tabs = [] if not tabs else tabs
		self.current_tab = self._tabs[0] # Start with the first tab
		self.widget = load_uh_widget("tab_base.xml")
		if position is None:
			# add positioning here
			self.widget.position = (
				horizons.main.fife.engine_settings.getScreenWidth() - 290,
				209
			)
		else:
			self.widget.position = position
		self.content = self.widget.findChild(name='content')
		self._init_tabs()
		# select a tab to show (first one is default)
		if active_tab is not None:
			self._show_tab(active_tab)
	def position_tooltip(self, event):
		"""Calculates a nice position for the tooltip.
		@param event: mouse event from fife or tuple screenpoint
		"""
		# TODO: think about nicer way of handling the polymorphism here,
		# e.g. a position_tooltip_event and a position_tooltip_tuple
		where = event # fife forces this to be called event, but here it can also be a tuple
		if isinstance(where, tuple):
			x, y = where
		else:
			if (where.getType() == fife.MouseEvent.ENTERED):
				for i in self._entered_callbacks:
					i()
			if (where.getButton() == fife.MouseEvent.MIDDLE):
				return

			x, y = where.getX(), where.getY()

		if self.gui is None:
			self.gui = load_uh_widget('tooltip.xml')
		widget_position = self.getAbsolutePos()
		screen_width = horizons.main.fife.engine_settings.getScreenWidth()
		self.gui.y = widget_position[1] + y + 5
		if (widget_position[0] + x + self.gui.size[0] + 10) <= screen_width:
			self.gui.x = widget_position[0] + x + 10
		else:
			self.gui.x = widget_position[0] + x - self.gui.size[0] - 5
		if not self.tooltip_shown:
			ExtScheduler().add_new_object(self.show_tooltip, self, run_in=0.3, loops=0)
			self.tooltip_shown = True
		else:
			self.gui.show()
	def __get_new_container(self):
		"""
		Loads a background container xml file. Returns the loaded widget.
		"""
		gui = load_uh_widget(self.relatedfields_gui_xml)
		container = gui.findChild(name="fields_container")
		return container
    def add_gui_entry(self, warehouse, resource_list=None):
        vbox = self._gui.findChild(name="left_vbox")
        entry = load_uh_widget("route_entry.xml")
        entry.settlement = weakref.ref(warehouse.settlement)
        self.widgets.append(entry)

        settlement_name_label = entry.findChild(name="warehouse_name")
        settlement_name_label.text = unicode(warehouse.settlement.get_component(NamedComponent).name)
        player_name_label = entry.findChild(name="player_name")
        player_name_label.text = unicode(warehouse.owner.name)

        self.add_trade_slots(entry, self.slots_per_entry)

        index = 1
        resource_list = resource_list or {}
        for res_id in resource_list:
            if index > self.slots_per_entry:
                break
            self.add_resource(self.slots[entry][index - 1], res_id, entry, has_value=True, value=resource_list[res_id])
            index += 1

        entry.mapEvents(
            {
                "delete_warehouse/mouseClicked": Callback(self.remove_entry, entry),
                "move_up/mouseClicked": Callback(self.move_entry, entry, "up"),
                "move_down/mouseClicked": Callback(self.move_entry, entry, "down"),
            }
        )
        vbox.addChild(entry)
	def __init__(self):
		self.page_widgets = {}
		self.dict_lt = {}
		self.dict_rt = {}
		self.widget = load_uh_widget(self.widget_xml, style="book")

		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 = pychan.widgets.ImageButton()
				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 add_trade_slots(self, entry, num):
        x_position = 105
        # initialize slots with empty dict
        self.slots[entry] = {}
        for num in range(0, num):
            slot = load_uh_widget("trade_single_slot.xml")
            slot.position = x_position, 0

            slot.action = "load"

            slider = slot.findChild(name="slider")
            slider.scale_start = 0.0
            slider.scale_end = float(self.instance.get_component(StorageComponent).inventory.limit)

            slot.findChild(name="buysell").capture(Callback(self.toggle_load_unload, slot, entry))

            button = slot.findChild(name="button")
            button.capture(self.handle_resource_click, event_name="mouseClicked")
            button.up_image = self.dummy_icon_path
            button.down_image = self.dummy_icon_path
            button.hover_image = self.dummy_icon_path

            icon = slot.findChild(name="icon")
            fillbar = slot.findChild(name="fillbar")
            fillbar.position = (icon.width - fillbar.width - 1, icon.height)
            x_position += 60

            entry.addChild(slot)
            self.slots[entry][num] = slot
            self.show_load_icon(slot)
	def _init_gui(self):
		self._gui = load_uh_widget("players_overview.xml")
		self._gui.mapEvents({
		  'cancelButton' : self.hide,
		  })
		self._gui.position_technique = "automatic"
		self.refresh()
	def add_gui_entry(self, branch_office, resource_list = None):
		vbox = self._gui.findChild(name="left_vbox")
		entry = load_uh_widget("route_entry.xml")
		self.widgets.append(entry)

		settlement_name_label = entry.findChild(name = "bo_name")
		settlement_name_label.text = unicode(branch_office.settlement.name)
		player_name_label = entry.findChild(name = "player_name")
		player_name_label.text = unicode(branch_office.owner.name)

		self.add_trade_slots(entry, self.slots_per_entry)

		index = 1
		resource_list = resource_list or {}
		for res_id in resource_list:
			if index > self.slots_per_entry:
				break
			self.add_resource(self.slots[entry][index - 1],\
			                  res_id, \
			                  entry, \
			                  has_value = True, \
			                  value = resource_list[res_id])
			index += 1

		entry.mapEvents({
		  'delete_bo/mouseClicked' : Callback(self.remove_entry, entry),
		  'move_up/mouseClicked' : Callback(self.move_entry, entry, 'up'),
		  'move_down/mouseClicked' : Callback(self.move_entry, entry, 'down')
		  })
		vbox.addChild(entry)
	def _reset_gold_gui(self):
		if self.gold_gui is not None:
			self.gold_gui.hide()
		self.gold_gui = load_uh_widget(self.__class__.GOLD_ENTRY_GUI_FILE, style=self.__class__.STYLE)
		self.gold_gui.child_finder = PychanChildFinder(self.gold_gui)
		# set appropriate icon
		self.gold_gui.findChild(name="res_icon").image = get_res_icon(RES.GOLD_ID)[4] # the 32 one
	def _get_res_background_icon_position(self):
		# currently unused since always 0
		# can be used for relative positioning of labels
		# old formula: label.position = (icon.position[0] - label.size[0]/2 + xoffset, yoffset)
		gui = load_uh_widget( self.__class__.ENTRY_GUI_FILE )
		icon = gui.findChild(name="background_icon")
		return icon.position
	def add_trade_slots(self, entry, num):
		x_position = 105
		#initialize slots with empty dict
		self.slots[entry] = {}
		for num in range(0,num):
			slot = load_uh_widget('trade_single_slot.xml')
			slot.position = x_position, 0

			slot.action = "load"

			slider = slot.findChild(name="slider")
			slider.setScaleStart(0.0)
			slider.setScaleEnd(float(self.instance.inventory.limit))

			slot.findChild(name="buysell").capture(Callback(self.toggle_load_unload, slot, entry))

			button = slot.findChild(name="button")
			button.capture(Callback(self.show_resource_menu, slot, entry))
			button.up_image = self.dummy_icon_path
			button.down_image = self.dummy_icon_path
			button.hover_image = self.dummy_icon_path

			icon = slot.findChild(name="icon")
			fillbar = slot.findChild(name="fillbar")
			fillbar.position = (icon.width - fillbar.width -1, icon.height)
			x_position += 60

			entry.addChild(slot)
			self.slots[entry][num] = slot
			self.show_load_icon(slot)
Exemple #13
0
	def add_slots(self, num):
		"""
		Adds num amount of slots to the buysellmenu.
		@param num: amount of slots that are to be added.
		"""
		content = self.widget.findChild(name="content")
		assert(content is not None)
		for num in range(0, num):
			slot = load_uh_widget('trade_single_slot.xml')
			self.slots[num] = slot
			slot.id = num
			slot.action = 'buy'
			slot.res = None
			slot.findChild(name='button').capture(self.handle_click, event_name = 'mouseClicked')
			slot.findChild(name='button').up_image = self.dummy_icon_path
			slot.findChild(name='button').down_image = self.dummy_icon_path
			slot.findChild(name='button').hover_image = self.dummy_icon_path
			slot.findChild(name='amount').stylize('menu_black')
			slider = slot.findChild(name="slider")
			slider.scale_start = 0.0
			slider.scale_end = float(self.tradepost.get_inventory().limit)
			# Set scale according to the settlement inventory size
			slot.findChild(name="buysell").capture(Callback(self.toggle_buysell, num))
			fillbar = slot.findChild(name="fillbar")
			# hide fillbar by setting position
			icon = slot.findChild(name="icon")
			fillbar.position = (icon.width - fillbar.width - 1, icon.height)
			content.addChild(slot)
		self.widget.adaptLayout()
Exemple #14
0
	def show_tooltip(self):
		if self.helptext not in ("", None):
			# recreate full tooltip since new text needs to be relayouted

			if self.gui is None:
				self.gui = load_uh_widget('tooltip.xml')
			else:
				self.gui.removeAllChildren()
			translated_tooltip = _(self.helptext)
			#HACK this looks better than splitting into several lines & joining
			# them. works because replace_whitespace in fill defaults to True:
			replaced = translated_tooltip.replace(r'\n', self.CHARS_PER_LINE*' ')
			replaced = replaced.replace(r'[br]', self.CHARS_PER_LINE*' ')
			tooltip = textwrap.fill(replaced, self.CHARS_PER_LINE)
			#----------------------------------------------------------------
			line_count = len(tooltip.splitlines())-1
			top_image = pychan.widgets.Icon(image='content/gui/images/background/widgets/tooltip_bg_top.png', position=(0, 0))
			self.gui.addChild(top_image)
			for i in xrange(0, line_count):
				middle_image = pychan.widgets.Icon( \
				        image='content/gui/images/background/widgets/tooltip_bg_middle.png',
				        position=(top_image.position[0], \
				                  top_image.position[1] + self.SIZE_BG_TOP + self.LINE_HEIGHT * i))
				self.gui.addChild(middle_image)
			bottom_image = pychan.widgets.Icon( \
			        image='content/gui/images/background/widgets/tooltip_bg_bottom.png',
			        position=(top_image.position[0], \
			                  top_image.position[1] + self.SIZE_BG_TOP + self.LINE_HEIGHT * line_count))
			self.gui.addChild(bottom_image)
			label = pychan.widgets.Label(text=u"", position=(10, 5))
			label.text = tooltip
			self.gui.addChild(label)
			self.gui.stylize('tooltip')
			self.gui.size = (145, self.SIZE_BG_TOP + self.LINE_HEIGHT * line_count + self.SIZE_BG_BOTTOM)
			self.gui.show()
    def _init_gui(self):
        """Initial init of gui."""
        self._gui = load_uh_widget("choose_next_scenario.xml")
        self._gui.mapEvents({"choose_scenario": Callback(self.validate_choice), "cancelButton": Callback(self.hide)})
        self._gui.position_technique = "automatic"  # "center:center"

        # SavegameManager.get_campaign_info(cls, name = "", file = "")
        self.choose_scenario = self._gui.findChild(name="choose_scenario")
	def _init_gui(self, session):
		self._gui = load_uh_widget("stringpreviewwidget.xml")
		self._gui.mapEvents({ 'load' : self.load })
		self.scenarios = SavegameManager.get_scenarios()
		self.listbox = self._gui.findChild(name="scenario_list")
		self.listbox.items = self.scenarios[1]

		self.logbook = LogBook(session)
	def set_inventory_instance(self, instance, keep_construction_mode=False, force_update=False):
		"""Display different inventory. May change resources that are displayed"""
		if self.current_instance() is instance and not self.construction_mode and not force_update:
			return # caller is drunk yet again
		if self.construction_mode and not keep_construction_mode:
			# stop construction mode, immediately update view, which will be a normal view
			self.close_construction_mode(update_slots=False)

		# reconstruct general gui

		# remove old gui
		for i in self.gui:
			i.hide()
		self._hide_resource_selection_dialog()
		self.gui = []

		inv = self._get_current_inventory()
		if inv is not None:
			inv.remove_change_listener(self._update_resources)

		if instance in (None, self): # show nothing instead
			self.current_instance = weakref.ref(self) # can't weakref to None
			self._do_show_dummy = False # don't save dummy value
			return

		self.current_instance = weakref.ref(instance)

		# construct new slots (fill values later)
		initial_offset = 93
		offset = 52
		resources = self._get_current_resources()
		addition = [-1] if self._do_show_dummy or not resources else [] # add dummy at end for adding stuff
		for i, res in enumerate( resources + addition ):
			entry = load_uh_widget(self.ENTRY_GUI_FILE, style=self.__class__.STYLE)
			entry.findChild(name="entry").position = (initial_offset + offset * i, 17)
			background_icon = entry.findChild(name="background_icon")
			background_icon.add_entered_callback( Callback(self._show_resource_selection_dialog, i) )

			if res != -1:
				helptext = self.session.db.get_res_name(res)
				icon = entry.findChild(name="res_icon")
				icon.num = i
				icon.image = get_res_icon(res)[2] # the 24 one
				icon.capture(self._on_res_slot_click, event_name = 'mouseClicked')
			else:
				helptext = _("Click to add a new slot")
				entry.show() # this will not be filled as the other res
			background_icon.helptext = helptext

			self.gui.append(entry)
			# show it just when values are entered, this appeases pychan

		# fill values
		inv = self._get_current_inventory()
		# update on all changes as well as now
		inv.add_change_listener(self._update_resources, call_listener_now=True)
	def show_stance_widget(self):
		stance_widget = load_uh_widget('stancewidget.xml')
		self.widget.findChild(name='stance').addChild(stance_widget)
		self.toggle_stance()
		self.widget.mapEvents({
			'aggressive': Callback(self.set_stance, 'aggressive'),
			'hold_ground': Callback(self.set_stance, 'hold_ground'),
			'none': Callback(self.set_stance, 'none'),
			'flee': Callback(self.set_stance, 'flee')
		})
Exemple #19
0
	def _loadWidget(self, dialog):
		wdg = load_uh_widget(dialog, style="book")
		# HACK: fife settings call stylize, which breaks our styling on widget load
		no_restyle_str = "do_not_restyle_this"
		self.setGuiStyle(no_restyle_str)
		def no_restyle(style):
			if style != no_restyle_str:
				wdg.stylize(style)
		wdg.stylize = no_restyle
		return wdg
	def __init__(self, session):
		super(MessageWidget, self).__init__()
		self.session = session
		self.active_messages = [] # for displayed messages
		self.archive = [] # messages, that aren't displayed any more
		self.widget = load_uh_widget(self.ICON_TEMPLATE)
		self.widget.position = (
			 5,
			 horizons.main.fife.engine_settings.getScreenHeight()/2 - self.widget.size[1]/2)

		self.text_widget = load_uh_widget(self.MSG_TEMPLATE)
		self.text_widget.position = (self.widget.x + self.widget.width, self.widget.y)

		self.current_tick = 0
		self.widget.show()
		self.item = 0 # number of current message
		ExtScheduler().add_new_object(self.tick, self, loops=-1)
		# buttons to toggle through messages

		self._last_message = {} # used to detect fast subsequent messages in add()
		self.draw_widget()
	def _init_gui(self):
		"""Initial init of gui."""
		self._gui = load_uh_widget("captains_log.xml")
		self._gui.mapEvents({
		  'backwardButton' : Callback(self._scroll, -2),
		  'forwardButton' : Callback(self._scroll, 2),
		  'cancelButton' : self.hide
		  })
		self._gui.position_technique = "automatic" # "center:center"

		self.backward_button = self._gui.findChild(name="backwardButton")
		self.forward_button = self._gui.findChild(name="forwardButton")
	def _init_gui(self):
		"""
		Initial init of gui.
		widgets : list of route entry widgets
		slots : dict with slots for each entry
		"""
		self._gui = load_uh_widget("configure_route.xml")
		self.listbox = self._gui.findChild(name="branch_office_list")
		self.listbox._setItems(list(self.branch_offices))

		self.widgets = []
		self.slots = {}
		self.slots_per_entry = 3

		resources = horizons.main.db.get_res_id_and_icon(True)
		#map an icon for a resource
		#map a resource for an icon
		self.resource_for_icon = {}
		self.icon_for_resource = {}
		for res_id, icon in list(resources) + [(0, self.dummy_icon_path)]:
			self.resource_for_icon[icon] = res_id
			self.icon_for_resource[res_id] = icon

		#don't do any actions if the resource menu is shown
		self.resource_menu_shown = False
		for entry in self.instance.route.waypoints:
			self.add_gui_entry(entry['branch_office'], entry['resource_list'])
		# we want escape key to close the widget, what needs to be fixed here?
		#self._gui.on_escape = self.hide
		self.start_button_set_active()
		if self.instance.route.enabled:
			self.start_button_set_inactive()

		wait_at_unload_box = self._gui.findChild(name="wait_at_unload")
		wait_at_unload_box.marked = self.instance.route.wait_at_unload
		def toggle_wait_at_unload():
			self.instance.route.wait_at_unload = not self.instance.route.wait_at_unload
		wait_at_unload_box.capture(toggle_wait_at_unload)

		wait_at_load_box = self._gui.findChild(name="wait_at_load")
		wait_at_load_box.marked = self.instance.route.wait_at_load
		def toggle_wait_at_load():
			self.instance.route.wait_at_load = not self.instance.route.wait_at_load
			print 'set to', self.instance.route.wait_at_load
		wait_at_load_box.capture(toggle_wait_at_load)

		self._gui.mapEvents({
		  'cancelButton' : self.hide,
		  'add_bo/mouseClicked' : self.append_bo,
		  'start_route/mouseClicked' : self.toggle_route
		  })
		self._gui.position_technique = "automatic" # "center:center"
	def init_tooltip(self, tooltip):
		self.gui = load_uh_widget('tooltip.xml')
		self.gui.hide()
		self.tooltip = tooltip
		self.mapEvents({
			self.name + '/mouseEntered' : self.position_tooltip,
			self.name + '/mouseExited' : self.hide_tooltip,
			self.name + '/mousePressed' : self.hide_tooltip,
			self.name + '/mouseMoved' : self.position_tooltip,
			#self.name + '/mouseReleased' : self.position_tooltip,
			self.name + '/mouseDragged' : self.hide_tooltip
			})
		self.tooltip_shown = False
		self.tooltip_items = []
	def __init__(self, instance):
		"""
		@param instance: ship instance used for trading
		"""
		self.widget = load_uh_widget('exchange_goods.xml')
		self.widget.position_technique = "right:top+157"
		events = {}
		for k, v in self.exchange_size_buttons.iteritems():
			events[v] = Callback(self.set_exchange, k)
		self.widget.mapEvents(events)
		self.instance = instance
		self.partner = None
		self.set_exchange(50, initial=True)
		if hasattr(self.instance, 'radius'):
			self.radius = self.instance.radius
	def __init__(self, instances, show_number = True):
		self.instances = instances
		self.widget = load_uh_widget("unit_entry_widget.xml")
		# get the icon of the first instance
		self.widget.findChild(name="unit_button").up_image = self.get_thumbnail_icon(instances[0].id)
		if show_number:
			self.widget.findChild(name="instance_number").text = unicode(str(len(self.instances)))
		# only two callbacks are needed so drop unwanted changelistener inheritance
		for i in instances:
			if not i.has_remove_listener(Callback(self.on_instance_removed, i)):
				i.add_remove_listener(Callback(self.on_instance_removed, i))
			health_component = i.get_component("health")
			if not health_component.has_damage_dealt_listener(self.draw_health):
				health_component.add_damage_dealt_listener(self.draw_health)
		self.draw_health()
	def _init_gui(self):
		"""
		Initial init of gui.
		resource_entries : dict of all resources and their respective values
		                   that will be displayed
		"""
		self._gui = load_uh_widget("island_production.xml")
		self._gui.mapEvents({
		  'cancelButton' : self.hide,
		  'refreshButton' : self.refresh
		  })
		self._gui.position_technique = "automatic" # "center:center"

		self.backward_button = self._gui.findChild(name="backwardButton")
		self.forward_button = self._gui.findChild(name="forwardButton")
		self.refresh()
	def __init__(self, widget=None, **kwargs):
		"""
		@param widget: filename of a widget. Set this to None if you create your own widget at self.widget
		"""
		super(TabInterface, self).__init__()
		if widget is not None:
			self.widget = load_uh_widget(widget, style="menu_black")
			self.widget.child_finder = PychanChildFinder(self.widget)
		else:
			self.widget = None
		# You can override these if you want to use separate images for your tab
		self.button_up_image = 'content/gui/images/tabwidget/tab.png' # TabButtons usual image
		self.button_down_image = 'content/gui/images/tabwidget/tab.png' # TabButtons image when mouse is pressed
		self.button_hover_image = 'content/gui/images/tabwidget/tab_a.png' # TabButtons hoverimage
		self.button_active_image = 'content/gui/images/tabwidget/tab.png' # TabButtons active image
		self.button_background_image = 'content/gui/images/tabwidget/tab_dark.png' # TabButtons background image
		self.button_background_image_active = 'content/gui/images/tabwidget/tab_active_xxl.png' # TabButtons background image when selected
 def load_gui(self):
     if self.gui is None:
         self.gui = load_uh_widget("place_building.xml")
         top_bar = self.gui.findChild(name="top_bar")
         top_bar.position = (self.gui.size[0] / 2 - top_bar.size[0] / 2 - 16, 50)
         self.gui.position_technique = "right-1:top+157"
     self.gui.mapEvents({"rotate_left": self.rotate_left, "rotate_right": self.rotate_right})
     # set translated building name in gui
     self.gui.findChild(name="headline").text = _("Build") + u" " + _(self._class.name)
     self.gui.findChild(name="running_costs").text = unicode(self._class.running_costs)
     head_box = self.gui.findChild(name="head_box")
     head_box.adaptLayout()  # recalculates size of new content
     head_box.position = (  # calculate and set new center (we cause pychan to not support it)
         max(self.gui.size[0] / 2 - head_box.size[0] / 2, 25),
         head_box.position[1],
     )
     head_box.adaptLayout()
     self.draw_gui()
     self.session.view.add_change_listener(self.draw_gui)
	def __init__(self, session):
		from horizons.session import Session
		assert isinstance(session, Session)
		self.session = session

		# special slot because of special properties
		self.gold_gui = load_uh_widget(self.__class__.GOLD_ENTRY_GUI_FILE, style=self.__class__.STYLE)
		self.gold_gui.child_finder = PychanChildFinder(self.gold_gui)
		self.gold_gui.findChild(name="res_icon").image = get_res_icon_path(RES.GOLD_ID, 32)

		self.gui = [] # list of slots
		self.resource_configurations = weakref.WeakKeyDictionary()
		self.current_instance = weakref.ref(self) # can't weakref to None
		self.construction_mode = False
		self._last_build_costs = None
		self._do_show_dummy = False

		self._update_default_configuration()

		self.session.message_bus.subscribe_globally(NewPlayerSettlementHovered, self._on_different_settlement)
Exemple #30
0
	def position_tooltip(self, event):
		if (event.getType() == fife.MouseEvent.ENTERED):
			for i in self._entered_callbacks:
				i()
		if (event.getButton() == fife.MouseEvent.MIDDLE):
			return

		if self.gui is None:
			self.gui = load_uh_widget('tooltip.xml')
		widget_position = self.getAbsolutePos()
		screen_width = horizons.main.fife.engine_settings.getScreenWidth()
		self.gui.y = widget_position[1] + event.getY() + 5
		if (widget_position[0] + event.getX() +self.gui.size[0] + 10) <= screen_width:
			self.gui.x = widget_position[0] + event.getX() + 10
		else:
			self.gui.x = widget_position[0] + event.getX() - self.gui.size[0] - 5
		if not self.tooltip_shown:
			ExtScheduler().add_new_object(self.show_tooltip, self, run_in=0.3, loops=0)
			self.tooltip_shown = True
		else:
			self.gui.show()