Package horizons :: Package gui :: Package modules :: Module pausemenu
[hide private]
[frames] | no frames]

Source Code for Module horizons.gui.modules.pausemenu

  1  # ################################################### 
  2  # Copyright (C) 2008-2017 The Unknown Horizons Team 
  3  # team@unknown-horizons.org 
  4  # This file is part of Unknown Horizons. 
  5  # 
  6  # Unknown Horizons is free software; you can redistribute it and/or modify 
  7  # it under the terms of the GNU General Public License as published by 
  8  # the Free Software Foundation; either version 2 of the License, or 
  9  # (at your option) any later version. 
 10  # 
 11  # This program is distributed in the hope that it will be useful, 
 12  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 14  # GNU General Public License for more details. 
 15  # 
 16  # You should have received a copy of the GNU General Public License 
 17  # along with this program; if not, write to the 
 18  # Free Software Foundation, Inc., 
 19  # 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
 20  # ################################################### 
 21   
 22  import horizons.main 
 23  from horizons.command.game import PauseCommand, UnPauseCommand 
 24  from horizons.gui.modules.editorstartmenu import EditorStartMenu 
 25  from horizons.gui.modules.select_savegame import SelectSavegameDialog 
 26  from horizons.gui.modules.settings import SettingsDialog 
 27  from horizons.gui.util import load_uh_widget 
 28  from horizons.gui.windows import Window 
 29  from horizons.i18n import gettext as T 
 30  from horizons.util.startgameoptions import StartGameOptions 
 31   
 32   
33 -class PauseMenu(Window):
34
35 - def __init__(self, session, ingame_gui, windows, in_editor_mode=False):
36 super().__init__(windows) 37 38 self._session = session 39 self._ingame_gui = ingame_gui 40 self._in_editor_mode = in_editor_mode 41 42 self.settings_dialog = SettingsDialog(self._windows) 43 44 name = 'editor_pause_menu.xml' if in_editor_mode else 'ingamemenu.xml' 45 self._gui = load_uh_widget(name) 46 self._gui.position_technique = 'center:center' 47 48 events = { 49 'load': self._load_game, 50 'save': self._save_game, 51 'sett': lambda: self._windows.open(self.settings_dialog), 52 'help': ingame_gui.toggle_help, 53 'start': self._windows.close, 54 'quit': self._do_quit, 55 } 56 57 self._gui.mapEvents({ 58 # icons 59 'loadgameButton': events['load'], 60 'savegameButton': events['save'], 61 'settingsLink': events['sett'], 62 'helpLink': events['help'], 63 'startGame': events['start'], 64 'closeButton': events['quit'], 65 # labels 66 'loadgame': events['load'], 67 'savegame': events['save'], 68 'settings': events['sett'], 69 'help': events['help'], 70 'start': events['start'], 71 'quit': events['quit'], 72 })
73
74 - def open(self):
75 super().open() 76 PauseCommand(suggestion=True).execute(self._session)
77
78 - def show(self):
79 self._gui.show()
80
81 - def hide(self):
82 self._gui.hide()
83
84 - def close(self):
85 super().close() 86 UnPauseCommand(suggestion=True).execute(self._session)
87
88 - def _do_quit(self):
89 message = T("Are you sure you want to abort the running session?") 90 if self._windows.open_popup(T("Quit Session"), message, show_cancel_button=True): 91 self._session.quit()
92
93 - def _save_game(self):
94 if self._in_editor_mode: 95 self._ingame_gui.show_save_map_dialog() 96 else: 97 success = self._session.save() 98 if not success: 99 # There was a problem during the 'save game' procedure. 100 self._windows.open_popup(T('Error'), T('Failed to save.'))
101
102 - def _load_game(self):
103 if self._in_editor_mode: 104 editor_start_menu = EditorStartMenu(self._windows) 105 self._windows.open(editor_start_menu) 106 else: 107 window = SelectSavegameDialog('load', self._windows) 108 saved_game = self._windows.open(window) 109 if saved_game is None: 110 return 111 112 options = StartGameOptions(saved_game) 113 horizons.main.start_singleplayer(options) 114 return True
115