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

Revision 753, 4.8 KB checked in by aspidites, 9 years ago (diff)

Patch by Aspidites:

  • disabled options button as functionality was previously defined in fife's Setting object. Rather than reimplement in settings.py, I think it would be wiser to implement in the gui package or similar.
  • continued further integration of settings.py in rest of project
  • 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 parpg.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        #TODO: reimplement fife's Setting.onoptionsPress in a more suitable place
69        #menu_events["optionsButton"] = self.model.settings.onOptionsPress
70        menu_events["optionsButton"] = None
71        menu_events["quitButton"] = self.quitGame
72        self.main_menu.mapEvents(menu_events)
73       
74        self.initializeQuitDialog()
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        load_browser = FileBrowser(self.engine,
85                                   self.load_game_callback,
86                                   save_file=False,
87                                   gui_xml_path='gui/loadbrowser.xml',
88                                   extensions=('.dat'))
89        load_browser.showBrowser()
90   
91    def initializeQuitDialog(self):
92        """Creates the quit confirmation dialog
93           @return: None"""
94        self.quit_window = pychan.widgets.Window(title=unicode("Quit?"), \
95                                                 min_size=(200,0))
96
97        hbox = pychan.widgets.HBox()
98        are_you_sure = "Are you sure you want to quit?"
99        label = pychan.widgets.Label(text=unicode(are_you_sure))
100        yes_button = pychan.widgets.Button(name="yes_button", 
101                                           text=unicode("Yes"),
102                                           min_size=(90,20),
103                                           max_size=(90,20))
104        no_button = pychan.widgets.Button(name="no_button",
105                                          text=unicode("No"),
106                                          min_size=(90,20),
107                                          max_size=(90,20))
108
109        self.quit_window.addChild(label)
110        hbox.addChild(yes_button)
111        hbox.addChild(no_button)
112        self.quit_window.addChild(hbox)
113
114        events_to_map = { "yes_button": self.quit_callback,
115                          "no_button":  self.quit_window.hide }
116       
117        self.quit_window.mapEvents(events_to_map)
118
119
120    def quitGame(self):
121        """Called when user requests to quit game.
122           @return: None"""
123        self.quit_window.show()
124   
Note: See TracBrowser for help on using the repository browser.