Ejemplo n.º 1
0
def _start_campaign(campaign_name):
	"""Finds the first scenario in this campaign and
	loads it.
	@return: bool, whether loading succeded"""
	if os.path.exists(campaign_name):
		# a file was specified. In order to make sure everything works properly,
		# we need to copy the file over to the UH campaign directory.
		# This is not very clean, but it's safe.

		if not campaign_name.endswith(".yaml"):
			print _("Error: campaign filenames have to end in \".yaml\".")
			return False

		# check if the user specified a file in the UH campaign dir
		campaign_basename = os.path.basename( campaign_name )
		path_in_campaign_dir = os.path.join(SavegameManager.campaigns_dir, campaign_basename)
		if not (os.path.exists(path_in_campaign_dir) and \
		        os.path.samefile(campaign_name, path_in_campaign_dir)):
			print _("Due to technical reasons, the campaign file will be copied to the UH campaign directory (%s).") % SavegameManager.campaigns_dir + \
			      "\n" + _("This means that changes in the file you specified will not apply to the game directly.") + \
			      _("To see the changes, either always start UH with the current arguments or edit the file %s.") % path_in_campaign_dir
			shutil.copy(campaign_name, SavegameManager.campaigns_dir)
		# use campaign file name below
		campaign_name = os.path.splitext( campaign_basename )[0]
	campaign = SavegameManager.get_campaign_info(name = campaign_name)
	if not campaign:
		print _("Error: Cannot find campaign \"%s\".") % campaign_name
		return False
	scenarios = [sc.get('level') for sc in campaign.get('scenarios',[])]
	if not scenarios:
		return False
	return _start_map(scenarios[0], 0, False, is_scenario = True, campaign = {'campaign_name': campaign_name, 'scenario_index': 0, 'scenario_name': scenarios[0]})
	def show(self):
		# Campaign and scenarios data
		campaign_info = SavegameManager.get_campaign_info(name = self.session.campaign['campaign_name'])
		available_scenarios = SavegameManager.get_available_scenarios()[1] # [0] is the list of xml files, we don't need it
		scenarios = [s for s in campaign_info.get('scenario_names', []) if s in available_scenarios]
		self._gui.distributeInitialData({'scenario_list' : scenarios})
		# select the first one
		self._gui.distributeData({ 'scenario_list' : 0, })
		def _update_infos():
			self.selected_scenario = scenarios[self._gui.collectData("scenario_list")]
			data = SavegameManager.get_scenario_info(name = self.selected_scenario)
			#xgettext:python-format
			text = [_("Difficulty: {difficulty}").format(difficulty=data.get('difficulty', '')),
			        _("Author: {author}").format(author=data.get('author', '')),
			        _("Description: {desc}").format(desc=data.get('description', '')),
			       ]
			self._gui.findChild(name="scenario_details").text = u"\n".join(text)
		self._gui.findChild(name="scenario_list").mapEvents({
		  'scenario_list/action': _update_infos,
		  'scenario_list/mouseWheelMovedUp'   : _update_infos,
		  'scenario_list/mouseWheelMovedDown' : _update_infos
		})


		_update_infos()
		self._gui.show()
    def show(self):
        # Campaign and scenarios data
        scenario_list = self._gui.findChild(name="scenario_list")
        campaign_info = SavegameManager.get_campaign_info(name=self.session.campaign["campaign_name"])
        available_scenarios = SavegameManager.get_available_scenarios()[
            1
        ]  # [0] is the list of xml files, we don't need it
        scenarios = [s for s in campaign_info.get("scenario_names", []) if s in available_scenarios]
        self._gui.distributeInitialData({"scenario_list": scenarios})
        # select the first one
        self._gui.distributeData({"scenario_list": 0})

        def _update_infos():
            self.selected_scenario = scenarios[self._gui.collectData("scenario_list")]
            data = SavegameManager.get_scenario_info(name=self.selected_scenario)
            text = [
                _("Difficulty: ") + unicode(data.get("difficulty", "")),
                _("Author: ") + unicode(data.get("author", "")),
                _("Description: ") + unicode(data.get("description", "")),
            ]
            self._gui.findChild(name="scenario_details").text = u"\n".join(text)

        self._gui.findChild(name="scenario_list").capture(_update_infos)
        _update_infos()
        self._gui.show()
Ejemplo n.º 4
0
    def show(self):
        # Campaign and scenarios data
        scenario_list = self._gui.findChild(name="scenario_list")
        campaign_info = SavegameManager.get_campaign_info(
            name=self.session.campaign['campaign_name'])
        available_scenarios = SavegameManager.get_available_scenarios()[
            1]  # [0] is the list of xml files, we don't need it
        scenarios = [
            s for s in campaign_info.get('scenario_names', [])
            if s in available_scenarios
        ]
        self._gui.distributeInitialData({'scenario_list': scenarios})
        # select the first one
        self._gui.distributeData({
            'scenario_list': 0,
        })

        def _update_infos():
            self.selected_scenario = scenarios[self._gui.collectData(
                "scenario_list")]
            data = SavegameManager.get_scenario_info(
                name=self.selected_scenario)
            text = [
                _("Difficulty: ") + unicode(data.get('difficulty', '')),
                _("Author: ") + unicode(data.get('author', '')),
                _("Description: ") + unicode(data.get('description', '')),
            ]
            self._gui.findChild(
                name="scenario_details").text = u"\n".join(text)

        self._gui.findChild(name="scenario_list").capture(_update_infos)
        _update_infos()
        self._gui.show()
Ejemplo n.º 5
0
	def start_single(self):
		""" Starts a single player horizons. """
		assert self.current is self.widgets['singleplayermenu']
		playername = self.current.playerdata.get_player_name()
		if len(playername) == 0:
			self.show_popup(_("Invalid player name"), _("You entered an invalid playername."))
			return
		playercolor = self.current.playerdata.get_player_color()
		self._save_player_name()

		if self.current.collectData('random'):
			map_file = self._get_random_map_file()
		else:
			assert self.active_right_side.collectData('maplist') != -1
			map_file = self._get_selected_map()

		is_scenario = bool(self.current.collectData('scenario'))
		is_campaign = bool(self.current.collectData('campaign'))
		if not is_scenario and not is_campaign:
			ai_players = int(self.current.aidata.get_ai_players())
			horizons.main.fife.set_uh_setting("AIPlayers", ai_players)
		horizons.main.fife.save_settings()

		self.show_loading_screen()
		if is_scenario:
			from horizons.scenario import InvalidScenarioFileFormat
			try:
				horizons.main.start_singleplayer(map_file, playername, playercolor, is_scenario=is_scenario)
			except InvalidScenarioFileFormat as e:
				self._show_invalid_scenario_file_popup(e)
				self._select_single(show = 'scenario')
		elif is_campaign:
			campaign_info = SavegameManager.get_campaign_info(filename = map_file)
			if not campaign_info:
				self._show_invalid_scenario_file_popup("Unknown Error")
				self._select_single(show = 'campaign')
			scenario = campaign_info.get('scenarios')[0].get('level')
			map_file = campaign_info.get('scenario_files').get(scenario)
			# TODO : why this does not work ?
			#
			#	horizons.main.start_singleplayer(map_file, playername, playercolor, is_scenario = True, campaign = {
			#		'campaign_name': campaign_info.get('codename'), 'scenario_index': 0, 'scenario_name': scenario
			#		})
			#
			horizons.main._start_map(scenario, ai_players=0, human_ai=False, is_scenario=True, campaign={
				'campaign_name': campaign_info.get('codename'), 'scenario_index': 0, 'scenario_name': scenario
			})
		else: # free play/random map
			horizons.main.start_singleplayer(
			  map_file, playername, playercolor, ai_players = ai_players, human_ai = AI.HUMAN_AI,
			  trader_enabled = self.widgets['game_settings'].findChild(name = 'free_trader').marked,
			  pirate_enabled = self.widgets['game_settings'].findChild(name = 'pirates').marked,
			  disasters_enabled = self.widgets['game_settings'].findChild(name = 'disasters').marked,
			  natural_resource_multiplier = self._get_natural_resource_multiplier()
			)

		ExtScheduler().rem_all_classinst_calls(self)
Ejemplo n.º 6
0
def _start_campaign(campaign_name):
	"""Finds the first scenario in this campaign and
	loads it.
	@return: bool, whether loading succeded"""
	campaign = SavegameManager.get_campaign_info(name = campaign_name)
	scenarios = [sc.get('level') for sc in campaign.get('scenarios',[])]
	if not scenarios:
		return False
	return _start_map(scenarios[0], is_scenario = True, campaign = {'campaign_name': campaign_name, 'scenario_index': 0, 'scenario_name': scenarios[0]})
Ejemplo n.º 7
0
					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', ''))
Ejemplo n.º 8
0
					def _update_infos():
						"""Fill in infos of selected campaign to label"""
						campaign_info = SavegameManager.get_campaign_info(filename = self._get_selected_map())
						if not campaign_info:
							self._show_invalid_scenario_file_popup("Unknown error")
							return
						self.current.findChild(name="map_difficulty").text = \
							_("Difficulty: {difficulty}").format(difficulty=campaign_info.get('difficulty', '')) #xgettext:python-format
						self.current.findChild(name="map_author").text = \
							_("Author: {author}").format(author=campaign_info.get('author', '')) #xgettext:python-format
						self.current.findChild(name="map_desc").text = \
							_("Description: {desc}").format(desc=campaign_info.get('description', '')) #xgettext:python-format
Ejemplo n.º 9
0
def _start_campaign(campaign_name):
    """Finds the first scenario in this campaign and
	loads it.
	@return: bool, whether loading succeded"""
    campaign = SavegameManager.get_campaign_info(name=campaign_name)
    scenarios = [sc.get('level') for sc in campaign.get('scenarios', [])]
    if not scenarios:
        return False
    return _start_map(scenarios[0],
                      is_scenario=True,
                      campaign={
                          'campaign_name': campaign_name,
                          'scenario_index': 0,
                          'scenario_name': scenarios[0]
                      })
Ejemplo n.º 10
0
def _start_campaign(campaign_name, force_player_id=None):
    """Finds the first scenario in this campaign and
	loads it.
	@return: bool, whether loading succeded"""
    if os.path.exists(campaign_name):
        # a file was specified. In order to make sure everything works properly,
        # we need to copy the file over to the UH campaign directory.
        # This is not very clean, but it's safe.

        if not campaign_name.endswith(".yaml"):
            print 'Error: campaign filenames have to end in ".yaml".'
            return False

            # check if the user specified a file in the UH campaign dir
        campaign_basename = os.path.basename(campaign_name)
        path_in_campaign_dir = os.path.join(SavegameManager.campaigns_dir, campaign_basename)
        if not (os.path.exists(path_in_campaign_dir) and os.path.samefile(campaign_name, path_in_campaign_dir)):
            # xgettext:python-format
            string = _(
                "Due to technical reasons, the campaign file will be copied to the UH campaign directory ({path})."
            ).format(path=SavegameManager.campaigns_dir)
            string += "\n"
            string += _("This means that changes in the file you specified will not apply to the game directly.")
            # xgettext:python-format
            string += _(
                "To see the changes, either always start UH with the current arguments or edit the file {filename}."
            ).format(filename=path_in_campaign_dir)
            print string

            shutil.copy(campaign_name, SavegameManager.campaigns_dir)
            # use campaign file name below
        campaign_name = os.path.splitext(campaign_basename)[0]
    campaign = SavegameManager.get_campaign_info(name=campaign_name)
    if not campaign:
        # xgettext:python-format
        print u"Error: Cannot find campaign '{name}'.".format(campaign_name)
        return False
    scenarios = [sc.get("level") for sc in campaign.get("scenarios", [])]
    if not scenarios:
        return False
    return _start_map(
        scenarios[0],
        0,
        False,
        is_scenario=True,
        campaign={"campaign_name": campaign_name, "scenario_index": 0, "scenario_name": scenarios[0]},
        force_player_id=force_player_id,
    )
Ejemplo n.º 11
0
 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', ''))
Ejemplo n.º 12
0
		else:
			assert self.current.collectData('maplist') != -1
			map_file = self.__get_selected_map()

		is_scenario = bool(self.current.collectData('showScenario'))
		is_campaign = bool(self.current.collectData('showCampaign'))
		self.show_loading_screen()
		if is_scenario:
			from horizons.scenario import InvalidScenarioFileFormat
			try:
				horizons.main.start_singleplayer(map_file, playername, playercolor, is_scenario=is_scenario)
			except InvalidScenarioFileFormat, e:
				self.__show_invalid_scenario_file_popup(e)
				self.show_single(show = 'scenario')
		elif is_campaign:
			campaign_info = SavegameManager.get_campaign_info(file = map_file)
			if not campaign_info:
				# TODO : an "invalid campaign popup"
				self.__show_invalid_scenario_file_popup(e)
				self.show_single(show = 'campaign')
			scenario = campaign_info.get('scenarios')[0].get('level')
			map_file = campaign_info.get('scenario_files').get(scenario)
			# TODO : why this does not work ?
			#
			#	horizons.main.start_singleplayer(map_file, playername, playercolor, is_scenario = True, campaign = {
			#		'campaign_name': campaign_info.get('codename'), 'scenario_index': 0, 'scenario_name': scenario
			#		})
			#
			horizons.main._start_map(scenario, is_scenario = True, campaign = {
				'campaign_name': campaign_info.get('codename'), 'scenario_index': 0, 'scenario_name': scenario
				})
Ejemplo n.º 13
0
        is_scenario = bool(self.current.collectData('showScenario'))
        is_campaign = bool(self.current.collectData('showCampaign'))
        self.show_loading_screen()
        if is_scenario:
            from horizons.scenario import InvalidScenarioFileFormat
            try:
                horizons.main.start_singleplayer(map_file,
                                                 playername,
                                                 playercolor,
                                                 is_scenario=is_scenario)
            except InvalidScenarioFileFormat, e:
                self.__show_invalid_scenario_file_popup(e)
                self.show_single(show='scenario')
        elif is_campaign:
            campaign_info = SavegameManager.get_campaign_info(file=map_file)
            if not campaign_info:
                # TODO : an "invalid campaign popup"
                self.__show_invalid_scenario_file_popup(e)
                self.show_single(show='campaign')
            scenario = campaign_info.get('scenarios')[0].get('level')
            map_file = campaign_info.get('scenario_files').get(scenario)
            # TODO : why this does not work ?
            #
            #	horizons.main.start_singleplayer(map_file, playername, playercolor, is_scenario = True, campaign = {
            #		'campaign_name': campaign_info.get('codename'), 'scenario_index': 0, 'scenario_name': scenario
            #		})
            #
            horizons.main._start_map(scenario,
                                     is_scenario=True,
                                     campaign={