def _start_map(map_name, is_scenario=False):
    """Start a map specified by user
	@return: bool, whether loading succeded"""
    maps = SavegameManager.get_scenarios(
    ) if is_scenario else SavegameManager.get_maps()
    map_file = None
    for i in xrange(0, len(maps[1])):
        # exact match
        if maps[1][i] == map_name:
            map_file = maps[0][i]
            break
        # check for partial match
        if maps[1][i].startswith(map_name):
            if map_file is not None:
                # multiple matches, collect all for output
                map_file += u'\n' + maps[0][i]
            else:
                map_file = maps[0][i]
    if map_file is None:
        print _("Error: Cannot find map \"%s\".") % map_name
        return False
    if len(map_file.splitlines()) > 1:
        print _("Error: Found multiple matches: ")
        for match in map_file.splitlines():
            print os.path.basename(match)
        return False
    load_game(map_file, is_scenario)
    return True
Beispiel #2
0
def _start_map(map_name, is_scenario = False):
	"""Start a map specified by user
	@return: bool, whether loading succeded"""
	maps = SavegameManager.get_scenarios() if is_scenario else SavegameManager.get_maps()
	map_file = None
	for i in xrange(0, len(maps[1])):
		# exact match
		if maps[1][i] == map_name:
			map_file = maps[0][i]
			break
		# check for partial match
		if maps[1][i].startswith(map_name):
			if map_file is not None:
				# multiple matches, collect all for output
				map_file += u'\n' + maps[0][i]
			else:
				map_file = maps[0][i]
	if map_file is None:
		print _("Error: Cannot find map \"%s\".") % map_name
		return False
	if len(map_file.splitlines()) > 1:
		print _("Error: Found multiple matches: ")
		for match in map_file.splitlines():
			print os.path.basename(match)
		return False
	load_game(map_file, is_scenario)
	return True
	def _init_gui(self, session):
		self._gui = load_uh_widget("stringpreviewwidget.xml")
		self._gui.mapEvents({ 'load' : self.load })
		self.scenarios = SavegameManager.get_scenarios()
		self.listbox = self._gui.findChild(name="scenario_list")
		self.listbox.items = self.scenarios[1]

		self.logbook = LogBook(session)
	def _init_gui(self):
		self._gui = load_xml_translated("stringpreviewwidget.xml")
		self._gui.mapEvents({ 'load' : self.load })
		self.scenarios = SavegameManager.get_scenarios()
		self.listbox = self._gui.findChild(name="scenario_list")
		self.listbox.items = self.scenarios[1]

		self.logbook = LogBook()
Beispiel #5
0
    def _init_gui(self, session):
        self._gui = load_uh_widget("stringpreviewwidget.xml")
        self._gui.mapEvents({'load': self.load})
        self.scenarios = SavegameManager.get_scenarios()
        self.listbox = self._gui.findChild(name="scenario_list")
        self.listbox.items = self.scenarios[1]
        self.listbox.capture(self.update_infos)

        self.statslabel = self._gui.findChild(name="stats")

        self.logbook = LogBook(session)
    def _init_gui(self, session):
        self._gui = load_uh_widget("stringpreviewwidget.xml")
        self._gui.mapEvents({"load": self.load})
        self.scenarios = SavegameManager.get_scenarios()
        self.listbox = self._gui.findChild(name="scenario_list")
        self.listbox.items = self.scenarios[1]
        self.listbox.distributeData({"scenario_list": 0})
        self.listbox.capture(self.update_infos)

        self.statslabel = self._gui.findChild(name="stats")

        self.windows = WindowManager()
        self.logbook = LogBook(session, self.windows)
        self.logbook._gui.mapEvents({OkButton.DEFAULT_NAME: self.logbook.hide})
        self.update_infos()
Beispiel #7
0
    def _init_gui(self, session):
        self._gui = load_uh_widget("stringpreviewwidget.xml")
        self._gui.mapEvents({'load': self.load})
        self.scenarios = SavegameManager.get_scenarios()
        self.listbox = self._gui.findChild(name="scenario_list")
        self.listbox.items = self.scenarios[1]
        self.listbox.distributeData({'scenario_list': 0})
        self.listbox.capture(self.update_infos)

        self.statslabel = self._gui.findChild(name="stats")

        self.windows = WindowManager()
        self.logbook = LogBook(session, self.windows)
        self.logbook._gui.mapEvents({
            OkButton.DEFAULT_NAME: self.logbook.hide,
        })
        self.update_infos()
	def show_single(self, show = 'scenario'): # tutorial
		"""
		@param show: string, which type of games to show
		"""
		assert show in ('random', 'scenario', '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'),
			'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: # scenario
				del eventMap['showScenario']
				self.current.findChild(name="showScenario").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 == '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()

					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', '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'),
            '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:  # scenario
                del eventMap['showScenario']
                self.current.findChild(name="showScenario").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 == '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()

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