source: trunk/game/scripts/mainmenuview.py @ 683

Revision 656, 4.5 KB checked in by beliar, 9 years ago (diff)

Patch by Beliar

  • Made parpg run with current fife svn.
  • 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       
40    def showMenu(self):
41        """"Shows the main menu"""
42        self.main_menu_background.show()
43        self.main_menu.show()
44       
45    def hideMenu(self):
46        """"Hides the main menu"""
47        self.main_menu.hide()
48        self.main_menu_background.hide()
49
50    def initalizeMainMenu(self, new_game, load_game, quit_game):
51        """Initialized the main menu and sets the callbacks"""
52        self.main_menu_background = pychan.loadXML("gui/main_menu_background.xml")
53        screen_mode = self.engine.getRenderBackend().getCurrentScreenMode()
54        self.main_menu_background.width = screen_mode.getWidth()
55        self.main_menu_background.height = screen_mode.getHeight()
56        self.main_menu = pychan.loadXML("gui/main_menu.xml")
57        self.main_menu.adaptLayout()
58        self.new_game_callback = new_game
59        self.load_game_callback = load_game
60        self.quit_callback = quit_game
61        menu_events = {}
62        menu_events["newButton"] = self.newGame
63        menu_events["loadButton"] = self.loadGame
64        menu_events["optionsButton"] = self.model.settings.onOptionsPress
65        menu_events["quitButton"] = self.quitGame
66        self.main_menu.mapEvents(menu_events)
67        self.initializeQuitDialog()
68   
69       
70    def newGame(self):
71        """Called when user request to start a new game.
72           @return: None"""
73        self.new_game_callback()
74           
75    def loadGame(self):
76        """ Called when the user wants to load a game.
77            @return: None"""
78        load_browser = FileBrowser(self.engine,
79                                   self.load_game_callback,
80                                   save_file=False,
81                                   gui_xml_path='gui/loadbrowser.xml',
82                                   extensions=('.dat'))
83        load_browser.showBrowser()
84   
85    def initializeQuitDialog(self):
86        """Creates the quit confirmation dialog
87           @return: None"""
88        self.quit_window = pychan.widgets.Window(title=unicode("Quit?"), \
89                                                 min_size=(200,0))
90
91        hbox = pychan.widgets.HBox()
92        are_you_sure = "Are you sure you want to quit?"
93        label = pychan.widgets.Label(text=unicode(are_you_sure))
94        yes_button = pychan.widgets.Button(name="yes_button", 
95                                           text=unicode("Yes"),
96                                           min_size=(90,20),
97                                           max_size=(90,20))
98        no_button = pychan.widgets.Button(name="no_button",
99                                          text=unicode("No"),
100                                          min_size=(90,20),
101                                          max_size=(90,20))
102
103        self.quit_window.addChild(label)
104        hbox.addChild(yes_button)
105        hbox.addChild(no_button)
106        self.quit_window.addChild(hbox)
107
108        events_to_map = { "yes_button": self.quit_callback,
109                          "no_button":  self.quit_window.hide }
110       
111        self.quit_window.mapEvents(events_to_map)
112
113
114    def quitGame(self):
115        """Called when user requests to quit game.
116           @return: None"""
117        self.quit_window.show()
118   
Note: See TracBrowser for help on using the repository browser.