source: branches/active/character_customization/game/parpg/mainmenuview.py @ 833

Revision 813, 5.1 KB checked in by aspidites, 8 years ago (diff)

Patch by Aspidites:

-updated all calls to settings.paths to the more readable settings.system_path and settings.user_path properties

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