def __update_game_details(self, game=None): """Set map name and other misc data in a widget. Only possible in certain states""" if game is None: game = self.__get_selected_game() if game is None: return #xgettext:python-format self.current.findChild(name="game_map").text = _("Map: {map_name}").format(map_name=game.get_map_name()) self.current.findChild(name="game_name").text = _("Name: {game_name}").format(game_name=game.get_name()) self.current.findChild(name="game_creator").text = _("Creator: {game_creator}").format(game_creator=game.get_creator()) #xgettext:python-format self.current.findChild(name="game_playersnum").text = _("Players: {player_amount}/{player_limit}").format( player_amount=game.get_player_count(), player_limit=game.get_player_limit()) vbox_inner = self.current.findChild(name="game_info") if game.is_savegame(): # work around limitations of current systems via messages path = SavegameManager.get_multiplayersave_map(game.mapname) btn_name = "save_missing_help_button" btn = vbox_inner.findChild(name=btn_name) if SavegameAccessor.get_hash(path) != game.get_map_hash(): text = "" if btn is None: btn = Button(name=btn_name) btn.text = _("This savegame is missing (click here)") last_elem = vbox_inner.findChild(name="game_info_last") if last_elem is None: # no last elem -> we are last vbox_inner.addChild( btn ) else: vbox_inner.insertChildBefore( btn, last_elem ) btn_text = _(u"For multiplayer load, it is necessary for you to have the correct savegame file.") + u"\n" btn_text += _(u"The file will be downloaded when the game starts.") btn.btn_text = btn_text def show(): self.show_popup(_("Help"), btn_text, size=1) btn.capture(show) else: text = _(u"This is a savegame.") if btn is not None: btn.hide() if text: self.current.findChild(name="game_isloaded").text = text self.__update_players_box(game) vbox_inner.adaptLayout() # inner vbox always exists vbox = self.current.findChild(name="gamedetailsbox") if vbox is not None: vbox.adaptLayout()
def __actual_join(self, game=None, password=""): """Does the actual joining to the game. This method is called after everything is OK for joining.""" if game is None: return False self.__apply_new_nickname() self.__apply_new_color() fetch = False if game.is_savegame() and SavegameAccessor.get_hash(SavegameManager.get_multiplayersave_map(game.mapname)) != game.get_map_hash(): fetch = True if not NetworkInterface().joingame(game.get_uuid(), password, fetch): return False self.__show_gamelobby() return True
def __actual_join(self, game=None, password=""): """Does the actual joining to the game. This method is called after everything is OK for joining.""" if game is None: return False self.__apply_new_nickname() self.__apply_new_color() fetch = False if game.is_savegame() and SavegameAccessor.get_hash( SavegameManager.get_multiplayersave_map( game.mapname)) != game.get_map_hash(): fetch = True if not NetworkInterface().joingame(game.get_uuid(), password, fetch): return False self.__show_gamelobby() return True
def __create_game(self, load=None, chosen_map=None): """ Actually create a game, join it, and display the lobby. @param load: game data tuple for creating loaded games @param chosen_map: the name of the map to start a new game on (overrides the gui) """ # create the game if load: mapname, gamename, gamepassword = load path = SavegameManager.get_multiplayersave_map(mapname) maxplayers = SavegameAccessor.get_players_num(path) password = gamepassword maphash = SavegameAccessor.get_hash(path) else: mapindex = None if chosen_map is not None: for i, map in enumerate(self.maps_display): if map == chosen_map: mapindex = i break if mapindex is None: mapindex = self.current.collectData('maplist') mapname = self.maps_display[mapindex] maxplayers = self.current.collectData( 'playerlimit') + 2 # 1 is the first entry gamename = self.current.collectData('gamename') password = self.current.collectData('password') maphash = "" password = hashlib.sha1(password).hexdigest() if password != "" else "" game = NetworkInterface().creategame(mapname, maxplayers, gamename, maphash, password) if game is None: return self.__show_gamelobby()
def __create_game(self, load=None, chosen_map=None): """ Actually create a game, join it, and display the lobby. @param load: game data tuple for creating loaded games @param chosen_map: the name of the map to start a new game on (overrides the gui) """ # create the game if load: mapname, gamename, gamepassword = load path = SavegameManager.get_multiplayersave_map(mapname) maxplayers = SavegameAccessor.get_players_num(path) password = gamepassword maphash = SavegameAccessor.get_hash(path) else: mapindex = None if chosen_map is not None: for i, map in enumerate(self.maps_display): if map == chosen_map: mapindex = i break if mapindex is None: mapindex = self.current.collectData('maplist') mapname = self.maps_display[mapindex] maxplayers = self.current.collectData('playerlimit') + 2 # 1 is the first entry gamename = self.current.collectData('gamename') password = self.current.collectData('password') maphash = "" password = hashlib.sha1(password).hexdigest() if password != "" else "" game = NetworkInterface().creategame(mapname, maxplayers, gamename, maphash, password) if game is None: return self.__show_gamelobby()
def __update_game_details(self, game=None): """Set map name and other misc data in a widget. Only possible in certain states""" if game is None: game = self.__get_selected_game() if game is None: return #xgettext:python-format self.current.findChild( name="game_map").text = _("Map: {map_name}").format( map_name=game.get_map_name()) self.current.findChild( name="game_name").text = _("Name: {game_name}").format( game_name=game.get_name()) self.current.findChild( name="game_creator").text = _("Creator: {game_creator}").format( game_creator=game.get_creator()) #xgettext:python-format self.current.findChild(name="game_playersnum").text = _( "Players: {player_amount}/{player_limit}").format( player_amount=game.get_player_count(), player_limit=game.get_player_limit()) vbox_inner = self.current.findChild(name="game_info") if game.is_savegame( ): # work around limitations of current systems via messages path = SavegameManager.get_multiplayersave_map(game.mapname) btn_name = "save_missing_help_button" btn = vbox_inner.findChild(name=btn_name) if SavegameAccessor.get_hash(path) != game.get_map_hash(): text = "" if btn is None: btn = Button(name=btn_name) btn.text = _("This savegame is missing (click here)") last_elem = vbox_inner.findChild(name="game_info_last") if last_elem is None: # no last elem -> we are last vbox_inner.addChild(btn) else: vbox_inner.insertChildBefore(btn, last_elem) btn_text = _( u"For multiplayer load, it is necessary for you to have the correct savegame file." ) + u"\n" btn_text += _( u"The file will be downloaded when the game starts.") btn.btn_text = btn_text def show(): self.show_popup(_("Help"), btn_text, size=1) btn.capture(show) else: text = _(u"This is a savegame.") if btn is not None: btn.hide() if text: self.current.findChild(name="game_isloaded").text = text self.__update_players_box(game) vbox_inner.adaptLayout() # inner vbox always exists vbox = self.current.findChild(name="gamedetailsbox") if vbox is not None: vbox.adaptLayout()