source: branches/active/character_customization/game/scripts/mainmenuview.py @ 712

Revision 693, 4.7 KB checked in by technomage, 9 years ago (diff)

Patch Technomage

  • Added a placeholder character creation screen accessible from the

main menu via the "New Game" button and an in-game character screen
using the same Pychan XML script.

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