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

Revision 774, 4.9 KB checked in by aspidites, 9 years ago (diff)

Patch by Aspidites

  • removed shebang from all python files except launcher scripts
  • added shebang to pychan_designer
  • 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
16from fife.extensions import pychan
17
18from viewbase import ViewBase
19from parpg.gui.filebrowser import FileBrowser
20from parpg.gui.menus import SettingsMenu
21
22class MainMenuView(ViewBase):
23    """View that is used to display the main menu"""
24
25    def __init__(self, engine, model):
26        """Constructor for MainMenuView
27           @param engine: A fife.Engine instance
28           @type engine: fife.Engine
29           @param model: a script.GameModel instance
30           @type model: script.GameModel
31           """       
32        ViewBase.__init__(self, engine, model)
33        self.quit_window = None
34        self.new_game_callback = None
35        self.load_game_callback = None
36        self.quit_callback = None
37        self.main_menu = None
38        self.character_screen = 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        # Set a simple background to display the main screen.
53        self.main_menu_background = pychan.loadXML("gui/main_menu_background.xml")
54       
55        # Initialize the main menu screen.
56        screen_mode = self.engine.getRenderBackend().getCurrentScreenMode()
57        self.main_menu_background.width = screen_mode.getWidth()
58        self.main_menu_background.height = screen_mode.getHeight()
59        self.main_menu = pychan.loadXML("gui/main_menu.xml")
60        self.main_menu.adaptLayout()
61        self.new_game_callback = new_game
62        self.load_game_callback = load_game
63        self.quit_callback = quit_game
64        menu_events = {}
65        menu_events["newButton"] = self.newGame
66        menu_events["loadButton"] = self.loadGame
67        menu_events["optionsButton"] = self.displaySettings
68        menu_events["quitButton"] = self.quitGame
69        self.main_menu.mapEvents(menu_events)
70       
71        self.initializeQuitDialog()
72        self.initializeSettingsMenu()
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       
93        self.quit_window = pychan.widgets.Window(title=unicode("Quit?"), \
94                                                 min_size=(200,0))
95
96        hbox = pychan.widgets.HBox()
97        are_you_sure = "Are you sure you want to quit?"
98        label = pychan.widgets.Label(text=unicode(are_you_sure))
99        yes_button = pychan.widgets.Button(name="yes_button", 
100                                           text=unicode("Yes"),
101                                           min_size=(90,20),
102                                           max_size=(90,20))
103        no_button = pychan.widgets.Button(name="no_button",
104                                          text=unicode("No"),
105                                          min_size=(90,20),
106                                          max_size=(90,20))
107
108        self.quit_window.addChild(label)
109        hbox.addChild(yes_button)
110        hbox.addChild(no_button)
111        self.quit_window.addChild(hbox)
112
113        events_to_map = { "yes_button": self.quit_callback,
114                          "no_button":  self.quit_window.hide }
115       
116        self.quit_window.mapEvents(events_to_map)
117
118
119    def quitGame(self):
120        """Called when user requests to quit game.
121           @return: None"""
122        self.quit_window.show()
123
124    def initializeSettingsMenu(self):
125        self.settings_menu = SettingsMenu(self.model.settings)
126
127    def displaySettings(self):
128        self.settings_menu.show()
Note: See TracBrowser for help on using the repository browser.