annotate mainmenuview.py @ 170:0296f5f74a0f

Fixed saving and loading that broke with changing of the settings module.
author Beliar <KarstenBock@gmx.net>
date Sat, 25 Feb 2012 22:05:39 +0100
parents 06145a6ee387
children
rev   line source
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
1 # This file is part of PARPG.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
2
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
3 # PARPG is free software: you can redistribute it and/or modify
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
4 # it under the terms of the GNU General Public License as published by
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
5 # the Free Software Foundation, either version 3 of the License, or
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
6 # (at your option) any later version.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
7
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
8 # PARPG is distributed in the hope that it will be useful,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
11 # GNU General Public License for more details.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
12
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
13 # You should have received a copy of the GNU General Public License
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
14 # along with PARPG. If not, see <http://www.gnu.org/licenses/
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
15
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
16 from fife.extensions import pychan
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
17
2
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
18 from parpg import vfs
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
19 from viewbase import ViewBase
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
20 from parpg.gui.filebrowser import FileBrowser
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
21 from parpg.gui.menus import SettingsMenu
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
22
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
23 class MainMenuView(ViewBase):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
24 """View that is used to display the main menu"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
25
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
26 def __init__(self, engine, model):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
27 """Constructor for MainMenuView
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
28 @param engine: A fife.Engine instance
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
29 @type engine: fife.Engine
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
30 @param model: a script.GameModel instance
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
31 @type model: script.GameModel
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
32 """
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
33 ViewBase.__init__(self, engine, model)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
34 self.quit_window = None
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
35 self.new_game_callback = None
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
36 self.load_game_callback = None
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
37 self.quit_callback = None
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
38 self.main_menu = None
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
39 self.character_screen = None
2
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
40
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
41 def showMenu(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
42 """"Shows the main menu"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
43 self.main_menu_background.show()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
44 self.main_menu.show()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
45
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
46 def hideMenu(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
47 """"Hides the main menu"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
48 self.main_menu.hide()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
49 self.main_menu_background.hide()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
50
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
51 def initalizeMainMenu(self, new_game, load_game, quit_game):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
52 """Initialized the main menu and sets the callbacks"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
53 # Set a simple background to display the main screen.
2
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
54 xml_file = vfs.VFS.open('gui/main_menu_background.xml')
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
55 self.main_menu_background = pychan.loadXML(xml_file)
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
56
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
57 # Initialize the main menu screen.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
58 screen_mode = self.engine.getRenderBackend().getCurrentScreenMode()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
59 self.main_menu_background.width = screen_mode.getWidth()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
60 self.main_menu_background.height = screen_mode.getHeight()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
61
2
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
62 xml_file = vfs.VFS.open('gui/main_menu.xml')
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
63 self.main_menu = pychan.loadXML(xml_file)
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
64
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
65 self.main_menu.adaptLayout()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
66 self.new_game_callback = new_game
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
67 self.load_game_callback = load_game
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
68 self.quit_callback = quit_game
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
69 menu_events = {}
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
70 menu_events["newButton"] = self.newGame
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
71 menu_events["loadButton"] = self.loadGame
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
72 menu_events["settingsButton"] = self.displaySettings
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
73 menu_events["quitButton"] = self.quitGame
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
74 self.main_menu.mapEvents(menu_events)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
75
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
76 self.initializeQuitDialog()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
77 self.initializeSettingsMenu()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
78
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
79 def newGame(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
80 """Called when user request to start a new game.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
81 @return: None"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
82 self.new_game_callback()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
83
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
84 def loadGame(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
85 """ Called when the user wants to load a game.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
86 @return: None"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
87 load_browser = FileBrowser(self.engine,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
88 self.model.settings,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
89 self.load_game_callback,
2
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
90 gui_xml_path='gui/loadbrowser.xml',
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
91 save_file=False,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
92 extensions=('.dat'))
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
93 load_browser.showBrowser()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
94
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
95 def initializeQuitDialog(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
96 """Creates the quit confirmation dialog
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
97 @return: None"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
98
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
99 self.quit_window = pychan.widgets.Window(title=unicode("Quit?"), \
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
100 min_size=(200,0))
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
101
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
102 hbox = pychan.widgets.HBox()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
103 are_you_sure = "Are you sure you want to quit?"
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
104 label = pychan.widgets.Label(text=unicode(are_you_sure))
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
105 yes_button = pychan.widgets.Button(name="yes_button",
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
106 text=unicode("Yes"),
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
107 min_size=(90,20),
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
108 max_size=(90,20))
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
109 no_button = pychan.widgets.Button(name="no_button",
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
110 text=unicode("No"),
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
111 min_size=(90,20),
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
112 max_size=(90,20))
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
113
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
114 self.quit_window.addChild(label)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
115 hbox.addChild(yes_button)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
116 hbox.addChild(no_button)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
117 self.quit_window.addChild(hbox)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
118
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
119 events_to_map = { "yes_button": self.quit_callback,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
120 "no_button": self.quit_window.hide }
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
121
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
122 self.quit_window.mapEvents(events_to_map)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
123
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
124
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
125 def quitGame(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
126 """Called when user requests to quit game.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
127 @return: None"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
128 self.quit_window.show()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
129
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
130 def initializeSettingsMenu(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
131 self.settings_menu = SettingsMenu(self.engine, self.model.settings)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
132
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
133 def displaySettings(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
134 self.settings_menu.show()