Esempio n. 1
0
    def _show_stats(self):
        """Show data below gold icon when balance label is clicked"""
        if self.stats_gui is None:
            reference_icon = self.gold_gui.child_finder("balance_background")
            self.stats_gui = load_uh_widget(self.__class__.STATS_GUI_FILE)
            self.stats_gui.child_finder = PychanChildFinder(self.stats_gui)
            self.stats_gui.position = (reference_icon.x + self.gold_gui.x,
                                       reference_icon.y + self.gold_gui.y)
            self.stats_gui.mapEvents({
                'resbar_stats_container/mouseClicked/stats':
                self._toggle_stats
            })

            images = [  # these must correspond to the entries in _update_stats
                "content/gui/images/resbar_stats/expense.png",
                "content/gui/images/resbar_stats/income.png",
                "content/gui/images/resbar_stats/buy.png",
                "content/gui/images/resbar_stats/sell.png",
                "content/gui/images/resbar_stats/scales_icon.png",
            ]

            for num, image in enumerate(images):
                # keep in sync with comment there until we can use that data:
                # ./content/gui/xml/ingame/hud/resource_overview_bar_stats.xml
                box = HBox(padding=0,
                           min_size=(70, 0),
                           name="resbar_stats_line_%s" % num)
                box.addChild(Icon(image=image))
                box.addSpacer(Spacer())
                box.addChild(Label(name="resbar_stats_entry_%s" % num))
                # workaround for fife font bug, probably http://fife.trac.cloudforge.com/engine/ticket/666
                box.addChild(Label(text=u" "))

                if num < len(images) - 1:  # regular one
                    self.stats_gui.child_finder("entries_box").addChild(box)
                else:  # last one
                    self.stats_gui.child_finder("bottom_box").addChild(box)
                    self.stats_gui.child_finder("bottom_box").stylize(
                        'resource_bar')

        self._update_stats()
        self.stats_gui.show()

        ExtScheduler().add_new_object(self._update_stats,
                                      self,
                                      run_in=Player.STATS_UPDATE_INTERVAL,
                                      loops=-1)
	def _show_stats(self):
		"""Show data below gold icon when balance label is clicked"""
		if self.stats_gui is None:
			reference_icon = self.gold_gui.child_finder("balance_background")
			self.stats_gui = load_uh_widget( self.__class__.STATS_GUI_FILE )
			self.stats_gui.child_finder = PychanChildFinder(self.stats_gui)
			self.stats_gui.position = (reference_icon.x + self.gold_gui.x,
			                           reference_icon.y + self.gold_gui.y)
			self.stats_gui.mapEvents({
			  'resbar_stats_container/mouseClicked/stats' : self._toggle_stats
			  })

			images = [ # these must correspond to the entries in _update_stats
				"content/gui/images/resbar_stats/expense.png",
				"content/gui/images/resbar_stats/income.png",
				"content/gui/images/resbar_stats/buy.png",
				"content/gui/images/resbar_stats/sell.png",
				"content/gui/images/resbar_stats/scales_icon.png",
			  ]

			for num, image in enumerate(images):
				# keep in sync with comment there until we can use that data:
				# ./content/gui/xml/ingame/hud/resource_overview_bar_stats.xml
				box = HBox(padding=0, min_size=(70, 0), name="resbar_stats_line_%s"%num)
				box.addChild(Icon(image=image))
				box.addSpacer(Spacer())
				box.addChild(Label(name="resbar_stats_entry_%s"%num))
				# workaround for fife font bug, probably http://fife.trac.cloudforge.com/engine/ticket/666
				box.addChild(Label(text=u" "))

				if num < len(images)-1: # regular one
					self.stats_gui.child_finder("entries_box").addChild(box)
				else: # last one
					self.stats_gui.child_finder("bottom_box").addChild(box)
					self.stats_gui.child_finder("bottom_box").stylize('resource_bar')

		self._update_stats()
		self.stats_gui.show()

		ExtScheduler().add_new_object(self._update_stats, self, run_in=Player.STATS_UPDATE_INTERVAL, loops=-1)
    def _init_stats_gui(self):
        reference_icon = self.gold_gui.child_finder("balance_background")
        self.stats_gui = load_uh_widget(self.__class__.STATS_GUI_FILE)
        self.stats_gui.child_finder = PychanChildFinder(self.stats_gui)
        self.stats_gui.position = (reference_icon.x + self.gold_gui.x,
                                   reference_icon.y + self.gold_gui.y)
        self.stats_gui.mapEvents({
            'resbar_stats_container/mouseClicked/stats':
            self._toggle_stats,
        })

        # This list must correspond to `figures` in _update_stats
        images = [
            ("content/gui/images/resbar_stats/expense.png",
             _("Running costs")),
            ("content/gui/images/resbar_stats/income.png", _("Taxes")),
            ("content/gui/images/resbar_stats/buy.png", _("Buy expenses")),
            ("content/gui/images/resbar_stats/sell.png", _("Sell income")),
            ("content/gui/images/resbar_stats/scales_icon.png", _("Balance")),
        ]

        for num, (image, helptext) in enumerate(images):
            # Keep in sync with comment there until we can use that data:
            # ./content/gui/xml/ingame/hud/resource_overview_bar_stats.xml
            box = HBox(padding=0, min_size=(70, 0))
            box.name = "resbar_stats_line_%s" % num
            box.helptext = helptext
            #TODO Fix icon size; looks like not 16x16 a surprising amount of times.
            box.addChild(Icon(image=image))
            box.addSpacer(Spacer())
            box.addChild(Label(name="resbar_stats_entry_%s" % num))
            #TODO This label is a workaround for some fife font bug,
            # probably http://github.com/fifengine/fifengine/issues/666.
            templabel = Label(name="resbar_stats_whatever_%s" % num)
            box.addChild(templabel)
            if num == len(images) - 1:
                # The balance line (last one) gets bold font.
                box.stylize('resource_bar')
            self.stats_gui.child_finder("entries_box").addChild(box)
	def _init_stats_gui(self):
		reference_icon = self.gold_gui.child_finder("balance_background")
		self.stats_gui = load_uh_widget(self.__class__.STATS_GUI_FILE)
		self.stats_gui.child_finder = PychanChildFinder(self.stats_gui)
		self.stats_gui.position = (reference_icon.x + self.gold_gui.x,
		                           reference_icon.y + self.gold_gui.y)
		self.stats_gui.mapEvents({
			'resbar_stats_container/mouseClicked/stats': self._toggle_stats,
		})

		# This list must correspond to `figures` in _update_stats
		images = [
			("content/gui/images/resbar_stats/expense.png",     _("Running costs")),
			("content/gui/images/resbar_stats/income.png",      _("Taxes")),
			("content/gui/images/resbar_stats/buy.png",         _("Buy expenses")),
			("content/gui/images/resbar_stats/sell.png",        _("Sell income")),
			("content/gui/images/resbar_stats/scales_icon.png", _("Balance")),
		]

		for num, (image, helptext) in enumerate(images):
			# Keep in sync with comment there until we can use that data:
			# ./content/gui/xml/ingame/hud/resource_overview_bar_stats.xml
			box = HBox(padding=0, min_size=(70, 0))
			box.name = "resbar_stats_line_%s" % num
			box.helptext = helptext
			#TODO Fix icon size; looks like not 16x16 a surprising amount of times.
			box.addChild(Icon(image=image))
			box.addSpacer(Spacer())
			box.addChild(Label(name="resbar_stats_entry_%s"%num))
			#TODO This label is a workaround for some fife font bug,
			# probably http://github.com/fifengine/fifengine/issues/666.
			templabel = Label(name="resbar_stats_whatever_%s"%num)
			box.addChild(templabel)
			if num == len(images) - 1:
				# The balance line (last one) gets bold font.
				box.stylize('resource_bar')
			self.stats_gui.child_finder("entries_box").addChild(box)