コード例 #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()
コード例 #2
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()
コード例 #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()
コード例 #4
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()