def toggle_pause(self): """Shows in-game pause menu if the game is currently not paused. Else unpauses and hides the menu. Multiple layers of the 'paused' concept exist; if two widgets are opened which would both pause the game, we do not want to unpause after only one of them is closed. Uses PauseCommand and UnPauseCommand. """ # TODO: logically, this now belongs to the ingame_gui (it used to be different) # this manifests itself by the need for the __pause_displayed hack below # in the long run, this should be moved, therefore eliminating the hack, and # ensuring correct setup/teardown. if self.__pause_displayed: self.__pause_displayed = False self.hide() self.current = None UnPauseCommand(suggestion=True).execute(self.session) self.on_escape = self.toggle_pause else: self.__pause_displayed = True # reload the menu because caching creates spacing problems # see http://trac.unknown-horizons.org/t/ticket/1047 self.widgets.reload('ingamemenu') def do_load(): did_load = self.load_game() if did_load: self.__pause_displayed = False def do_quit(): did_quit = self.quit_session() if did_quit: self.__pause_displayed = False events = { # needed twice, save only once here 'e_load' : do_load, 'e_save' : self.save_game, 'e_sett' : self.show_settings, 'e_help' : self.on_help, 'e_start': self.toggle_pause, 'e_quit' : do_quit, } self._switch_current_widget('ingamemenu', center=True, show=False, event_map={ # icons 'loadgameButton' : events['e_load'], 'savegameButton' : events['e_save'], 'settingsLink' : events['e_sett'], 'helpLink' : events['e_help'], 'startGame' : events['e_start'], 'closeButton' : events['e_quit'], # labels 'loadgame' : events['e_load'], 'savegame' : events['e_save'], 'settings' : events['e_sett'], 'help' : events['e_help'], 'start' : events['e_start'], 'quit' : events['e_quit'], }) self.show_modal_background() self.current.show() PauseCommand(suggestion=True).execute(self.session) self.on_escape = self.toggle_pause
def hide(self): if not self._hiding_widget: self._hiding_widget = True self._hide_statswidgets() self._gui.hide() self._hiding_widget = False self.display_messages() self._message_log.extend(self._messages_to_display) self._messages_to_display = [] # Make sure the game is unpaused always and in any case UnPauseCommand(suggestion=False).execute(self.session)
def do_win(session): """The player wins the current scenario.""" PauseCommand().execute(session) show_db_message(session, 'YOU_HAVE_WON') horizons.globals.fife.play_sound('effects', "content/audio/sounds/events/scenario/win.ogg") continue_playing = session.gui.show_popup(_("You have won!"), _("You have completed this scenario.") + u" " + _("Do you want to continue playing?"), show_cancel_button=True) if not continue_playing: Scheduler().add_new_object(Callback(session.gui.quit_session, force=True), session, run_in=0) else: UnPauseCommand().execute(session)
def hide(self): if not self._hiding_widget: self._hiding_widget = True self._hide_statswidgets() self._gui.hide() self._hiding_widget = False for message in self._messages_to_display: # show all messages (except those already displayed) and map them to the current logbook page if message in self._displayed_messages: continue for msg_id in show_message(self.session, "logbook", message): self._page_ids[msg_id] = self._cur_entry self._displayed_messages.append(message) self._message_log.extend(self._messages_to_display) self._messages_to_display = [] # Make sure the game is unpaused always and in any case UnPauseCommand(suggestion=False).execute(self.session)
def on_help(self): """Called on help action. Toggles help screen via static variable *help_is_displayed*. Can be called both from main menu and in-game interface. """ help_dlg = self.widgets['help'] if not self._help_is_displayed: self._help_is_displayed = True # make game pause if there is a game and we're not in the main menu if self.session is not None and self.current != self.widgets['ingamemenu']: PauseCommand().execute(self.session) if self.session is not None: self.session.ingame_gui.on_escape() # close dialogs that might be open self.show_dialog(help_dlg, {OkButton.DEFAULT_NAME : True}) self.on_help() # toggle state else: self._help_is_displayed = False if self.session is not None and self.current != self.widgets['ingamemenu']: UnPauseCommand().execute(self.session) help_dlg.hide()
def hide(self): self._gui.hide() UnPauseCommand(suggestion=True).execute(self._session)
def hide(self): if self._session: UnPauseCommand().execute(self._session) self.widget.hide()
def close(self): super(PauseMenu, self).close() UnPauseCommand(suggestion=True).execute(self._session)