Пример #1
0
	def show_main(self):
		"""Shows the main menu """
		self._switch_current_widget('mainmenu', center=True, show=True, event_map = {
			'startSingle'    : self.show_single,
			'startMulti'     : self.show_multi,
			'settingsLink'   : self.show_settings,
			'helpLink'       : self.on_help,
			'closeButton'    : self.show_quit,
			'dead_link'      : self.on_chime, # call for help; SoC information
			'creditsLink'    : self.show_credits,
			'loadgameButton' : horizons.main.load_game
		})

		self.on_escape = self.show_quit

		adjust_widget_black_background(self.widgets['mainmenu'])
Пример #2
0
	def show_pause(self):
		"""
		Show Pause menu
		"""
		self._switch_current_widget('gamemenu', center=True, show=True, event_map={
			'startGame'      : self.return_to_game,
			'savegameButton' : self.save_game,
			'settingsLink'   : self.show_settings,
			'helpLink'       : self.on_help,
			'closeButton'    : self.quit_session,
			'dead_link'      : self.on_chime,
			'creditsLink'    : self.show_credits,
			'loadgameButton' : horizons.main.load_game
		})

		adjust_widget_black_background(self.widgets['gamemenu'])

		self.session.speed_pause()
		self.on_escape = self.return_to_game
	def show_single(self, show = 'scenario'): # tutorial
		"""
		@param show: string, which type of games to show
		"""
		assert show in ('random', 'scenario', 'campaign', 'free_maps')
		self.hide()
		# reload since the gui is changed at runtime
		self.widgets.reload('singleplayermenu')
		self._switch_current_widget('singleplayermenu', center=True)
		eventMap = {
			'cancel'   : self.show_main,
			'okay'     : self.start_single,
			'showScenario' : Callback(self.show_single, show='scenario'),
			'showCampaign' : Callback(self.show_single, show='campaign'),
			'showRandom' : Callback(self.show_single, show='random'),
			'showMaps' : Callback(self.show_single, show='free_maps')
		}

		adjust_widget_black_background(self.widgets['singleplayermenu'])

		# init gui for subcategory
		if show == 'random':
			del eventMap['showRandom']
			self.current.findChild(name="showRandom").marked = True
			to_remove = self.current.findChild(name="map_list_area")
			to_remove.parent.removeChild(to_remove)
			to_remove = self.current.findChild(name="choose_map_lbl")
			to_remove.parent.removeChild(to_remove)
			# need to add some options here (generation algo, size, ... )
		else:
			if show == 'free_maps':
				del eventMap['showMaps']
				self.current.findChild(name="showMaps").marked = True
				self.current.files, maps_display = SavegameManager.get_maps()
			elif show == 'campaign':
				del eventMap['showCampaign']
				self.current.findChild(name="showCampaign").marked = True
				self.current.files, maps_display = SavegameManager.get_campaigns()
			else: # scenario
				del eventMap['showScenario']
				self.current.findChild(name="showScenario").marked = True
				choosable_locales = ['en',horizons.main.fife.get_locale()]
				self.current.files, maps_display = SavegameManager.get_available_scenarios(locales = choosable_locales)

			# get the map files and their display names
			self.current.distributeInitialData({ 'maplist' : maps_display, })
			if len(maps_display) > 0:
				# select first entry
				self.current.distributeData({ 'maplist' : 0, })

				if show == 'scenario': # update infos for scenario
					from horizons.scenario import ScenarioEventHandler, InvalidScenarioFileFormat
					def _update_infos():
						"""Fill in infos of selected scenario to label"""
						try:
							difficulty = ScenarioEventHandler.get_difficulty_from_file( self.__get_selected_map() )
							desc = ScenarioEventHandler.get_description_from_file( self.__get_selected_map() )
							author = ScenarioEventHandler.get_author_from_file( self.__get_selected_map() )
						except InvalidScenarioFileFormat, e:
							self.__show_invalid_scenario_file_popup(e)
							return
						self.current.findChild(name="map_difficulty").text = _("Difficulty: ") + unicode( difficulty )
						self.current.findChild(name="map_author").text = _("Author: ") + unicode( author )
						self.current.findChild(name="map_desc").text =  _("Description: ") + unicode( desc )
						#self.current.findChild(name="map_desc").parent.adaptLayout()
				elif show == 'campaign': # update infos for campaign
					def _update_infos():
						"""Fill in infos of selected campaign to label"""
						campaign_info = SavegameManager.get_campaign_info(file = self.__get_selected_map())
						if not campaign_info:
							# TODO : an "invalid campaign popup"
							self.__show_invalid_scenario_file_popup(e)
							return
						self.current.findChild(name="map_difficulty").text = _("Difficulty: ") + unicode(campaign_info.get('difficulty', ''))
						self.current.findChild(name="map_author").text = _("Author: ") + unicode(campaign_info.get('author', ''))
						self.current.findChild(name="map_desc").text = _("Description: ") + unicode(campaign_info.get('description', ''))

				if show in ('scenario', 'campaign'):
					self.current.findChild(name="maplist").capture(_update_infos)
					_update_infos()
    def show_single(self, show='scenario'):  # tutorial
        """
		@param show: string, which type of games to show
		"""
        assert show in ('random', 'scenario', 'campaign', 'free_maps')
        self.hide()
        # reload since the gui is changed at runtime
        self.widgets.reload('singleplayermenu')
        self._switch_current_widget('singleplayermenu', center=True)
        eventMap = {
            'cancel': self.show_main,
            'okay': self.start_single,
            'showScenario': Callback(self.show_single, show='scenario'),
            'showCampaign': Callback(self.show_single, show='campaign'),
            'showRandom': Callback(self.show_single, show='random'),
            'showMaps': Callback(self.show_single, show='free_maps')
        }

        adjust_widget_black_background(self.widgets['singleplayermenu'])

        # init gui for subcategory
        if show == 'random':
            del eventMap['showRandom']
            self.current.findChild(name="showRandom").marked = True
            to_remove = self.current.findChild(name="map_list_area")
            to_remove.parent.removeChild(to_remove)
            to_remove = self.current.findChild(name="choose_map_lbl")
            to_remove.parent.removeChild(to_remove)
            # need to add some options here (generation algo, size, ... )
        else:
            if show == 'free_maps':
                del eventMap['showMaps']
                self.current.findChild(name="showMaps").marked = True
                self.current.files, maps_display = SavegameManager.get_maps()
            elif show == 'campaign':
                del eventMap['showCampaign']
                self.current.findChild(name="showCampaign").marked = True
                self.current.files, maps_display = SavegameManager.get_campaigns(
                )
            else:  # scenario
                del eventMap['showScenario']
                self.current.findChild(name="showScenario").marked = True
                choosable_locales = ['en', horizons.main.fife.get_locale()]
                self.current.files, maps_display = SavegameManager.get_available_scenarios(
                    locales=choosable_locales)

            # get the map files and their display names
            self.current.distributeInitialData({
                'maplist': maps_display,
            })
            if len(maps_display) > 0:
                # select first entry
                self.current.distributeData({
                    'maplist': 0,
                })

                if show == 'scenario':  # update infos for scenario
                    from horizons.scenario import ScenarioEventHandler, InvalidScenarioFileFormat

                    def _update_infos():
                        """Fill in infos of selected scenario to label"""
                        try:
                            difficulty = ScenarioEventHandler.get_difficulty_from_file(
                                self.__get_selected_map())
                            desc = ScenarioEventHandler.get_description_from_file(
                                self.__get_selected_map())
                            author = ScenarioEventHandler.get_author_from_file(
                                self.__get_selected_map())
                        except InvalidScenarioFileFormat, e:
                            self.__show_invalid_scenario_file_popup(e)
                            return
                        self.current.findChild(
                            name="map_difficulty"
                        ).text = _("Difficulty: ") + unicode(difficulty)
                        self.current.findChild(
                            name="map_author"
                        ).text = _("Author: ") + unicode(author)
                        self.current.findChild(
                            name="map_desc"
                        ).text = _("Description: ") + unicode(desc)
                        #self.current.findChild(name="map_desc").parent.adaptLayout()
                elif show == 'campaign':  # update infos for campaign

                    def _update_infos():
                        """Fill in infos of selected campaign to label"""
                        campaign_info = SavegameManager.get_campaign_info(
                            file=self.__get_selected_map())
                        if not campaign_info:
                            # TODO : an "invalid campaign popup"
                            self.__show_invalid_scenario_file_popup(e)
                            return
                        self.current.findChild(
                            name="map_difficulty"
                        ).text = _("Difficulty: ") + unicode(
                            campaign_info.get('difficulty', ''))
                        self.current.findChild(
                            name="map_author").text = _("Author: ") + unicode(
                                campaign_info.get('author', ''))
                        self.current.findChild(
                            name="map_desc"
                        ).text = _("Description: ") + unicode(
                            campaign_info.get('description', ''))

                if show in ('scenario', 'campaign'):
                    self.current.findChild(
                        name="maplist").capture(_update_infos)
                    _update_infos()
	def show_single(self, show = 'campaign'): # tutorial
		"""
		@param show: string, which type of games to show
		"""
		assert show in ('random', 'campaign', 'free_maps')
		self.hide()
		# reload since the gui is changed at runtime
		self.widgets.reload('singleplayermenu')
		self._switch_current_widget('singleplayermenu', center=True)
		eventMap = {
			'cancel'   : self.show_main,
			'okay'     : self.start_single,
			'showCampaign' : Callback(self.show_single, show='campaign'),
			'showRandom' : Callback(self.show_single, show='random'),
			'showMaps' : Callback(self.show_single, show='free_maps')
		}

		adjust_widget_black_background(self.widgets['singleplayermenu'])

		# init gui for subcategory
		if show == 'random':
			del eventMap['showRandom']
			self.current.findChild(name="showRandom").marked = True
			to_remove = self.current.findChild(name="map_list_area")
			to_remove.parent.removeChild(to_remove)
			to_remove = self.current.findChild(name="choose_map_lbl")
			to_remove.parent.removeChild(to_remove)
			self.show_popup(_('Warning'), \
			                _('The random map feature is still in active development. It is to be considered a pre testing version. Problems are to be expected.'))
			# need to add some options here (generation algo, size, ... )
		else:
			if show == 'free_maps':
				del eventMap['showMaps']
				self.current.findChild(name="showMaps").marked = True
				self.current.files, maps_display = SavegameManager.get_maps()
			else: # campaign
				del eventMap['showCampaign']
				self.current.findChild(name="showCampaign").marked = True
				self.current.files, maps_display = SavegameManager.get_scenarios()

			# get the map files and their display names
			self.current.distributeInitialData({ 'maplist' : maps_display, })
			if len(maps_display) > 0:
				# select first entry
				self.current.distributeData({ 'maplist' : 0, })

				if show == 'campaign': # update infos for campaign
					from horizons.campaign import CampaignEventHandler, InvalidScenarioFileFormat
					def _update_infos():
						"""Fill in infos of selected scenario to label"""
						try:
							difficulty = CampaignEventHandler.get_difficulty_from_file( self.__get_selected_map() )
							desc = CampaignEventHandler.get_description_from_file( self.__get_selected_map() )
							author = CampaignEventHandler.get_author_from_file( self.__get_selected_map() )
						except InvalidScenarioFileFormat, e:
							self.__show_invalid_scenario_file_popup(e)
							return
						self.current.findChild(name="map_difficulty").text = _("Difficulty: ") + unicode( difficulty )
						self.current.findChild(name="map_author").text = _("Author: ") + unicode( author )
						self.current.findChild(name="map_desc").text =  _("Description: ") + unicode( desc )
						#self.current.findChild(name="map_desc").parent.adaptLayout()

					self.current.findChild(name="maplist").capture(_update_infos)
					_update_infos()