Exemplo n.º 1
0
	def refresh(self):
		happinesses = []
		needed_res = {}
		for building in self.settlement.buildings:
			if hasattr(building, 'happiness'):
				happinesses.append(building.happiness)
				for res in building.get_currently_not_consumed_resources():
					try:
						needed_res[res] += 1
					except KeyError:
						needed_res[res] = 1

		num_happinesses = max(len(happinesses), 1) # make sure not to divide by 0
		avg_happiness = int( sum(happinesses, 0.0) / num_happinesses )
		self.widget.child_finder('avg_happiness').text = unicode(avg_happiness) + u'/100'

		container = self.widget.child_finder('most_needed_res_container')
		if self._old_most_needed_res_icon is not None:
			container.removeChild(self._old_most_needed_res_icon)
			self._old_most_needed_res_icon = None

		if len(needed_res) > 0:
			most_need_res = heapq.nlargest(1, needed_res.iteritems(), operator.itemgetter(1))[0][0]
			most_needed_res_icon = create_resource_icon(most_need_res, horizons.main.db)
			container.addChild(most_needed_res_icon)
			self._old_most_needed_res_icon = most_needed_res_icon
		container.adaptLayout()
    def _add_line_to_gui(self, resource_id, amount, show_all=False):
        # later we will modify which resources to be displayed (e.g. all
        # settlements) via the switch show_all
        res_name = self.db.get_res_name(resource_id, only_if_inventory=True)
        # above code returns None if not shown in inventories
        displayed = (res_name is not None) or show_all
        if not displayed:
            return

        icon = create_resource_icon(resource_id, self.db, size=16)
        icon.name = "icon_%s" % resource_id
        icon.max_size = icon.min_size = icon.size = (16, 16)

        label = widgets.Label(name="resource_%s" % resource_id)
        label.text = unicode(res_name)
        label.min_size = (100, 20)

        amount_label = widgets.Label(name="produced_sum_%s" % resource_id)
        amount_label.text = unicode(amount)

        hbox = widgets.HBox()
        hbox.addChild(icon)
        hbox.addChild(label)
        hbox.addChild(amount_label)
        self._content_vbox.addChild(hbox)
Exemplo n.º 3
0
	def update_consumed_res(self):
		"""Updates the container that displays the needed resources of the settler"""
		container = self.widget.findChild(name="needed_res")
		# remove icons from the container
		container.removeChildren(*container.children)

		# create new ones
		resources = self.instance.get_currently_not_consumed_resources()
		for res in resources:
			icon = create_resource_icon(res, self.instance.session.db)
			container.addChild(icon)

		container.adaptLayout()
Exemplo n.º 4
0
	def _add_resource_line_to_gui(self, gui, res_id, amount=0, show_all=False):
		# later we will modify which resources to be displayed (e.g. all
		# settlements) via the switch show_all
		res_name = self.db.get_res_name(res_id, only_if_inventory=True)
		# above code returns None if not shown in inventories
		displayed = (res_name is not None) or show_all
		if displayed:
			icon = create_resource_icon(res_id, self.db, size=16)
			icon.name = 'icon_%s' % res_id
			label = widgets.Label(name='resource_%s' % res_id)
			label.text = unicode(res_name)
			amount_label = widgets.Label(name='produced_sum_%s' % res_id)
			amount_label.text = unicode(amount)
			hbox = widgets.HBox()
			hbox.addChild(icon)
			hbox.addChild(label)
			hbox.addChild(amount_label)
			gui.addChild(hbox)
			gui.adaptLayout()