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

Revision 659, 3.4 KB checked in by beliar, 9 years ago (diff)

Patch by Beliar.

  • Fixes the problem that the GUI is not fully drawn when loading a save game from the main menu.
  • Property svn:eol-style set to native
RevLine 
[653]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 controllerbase import ControllerBase
19from gamescenecontroller import GameSceneController
20from gamesceneview import GameSceneView
21
22#For debugging/code analysis
23if False:
24    from scripts.mainmenuview import MainMenuView
25    from fife import fife
26    from gamemodel import GameModel
27    from parpg import PARPGApplication
28
29class MainMenuController(ControllerBase):
30    """Controller for handling the main menu state"""
31
32    def __init__(self,
33                 engine, 
34                 view, 
35                 model, 
36                 application):
37        """Constructor"""
38        ControllerBase.__init__(self,
39                                engine,
40                                view,
41                                model,
42                                application)
43   
44        #this can be helpful for IDEs code analysis
45        if False:
46            assert(isinstance(self.engine, fife.Engine))
47            assert(isinstance(self.view, MainMenuView))
48            assert(isinstance(self.model, GameModel))
49            assert(isinstance(self.application, PARPGApplication))
50            assert(isinstance(self.event_manager, fife.EventManager))
51       
52        self.view.quit_callback = self.quitGame
53        self.view.new_game_callback = self.newGame
54        self.view.initalizeMainMenu(self.newGame, self.loadGame, self.quitGame)
55        self.view.showMenu()
56        self.resetMouseCursor()
57           
58    def newGame(self):
59        """Starts a new game"""
60        view = GameSceneView(self.engine,
61                             self.model)
62        controller = GameSceneController(self.engine,
63                                         view,
64                                         self.model,
65                                         self.application)       
66        self.application.view = view
67        self.application.switchController(controller)
68        start_map = self.model.settings.get("PARPG", "Map")
69        self.model.changeMap(start_map)
70
71    def loadGame(self, *args, **kwargs):
72        """Loads the game state
73           @return: None"""
74
75        view = GameSceneView(self.engine,
76                             self.model)
77        controller = GameSceneController(self.engine,
78                                         view,
79                                         self.model,
80                                         self.application)       
81        self.application.view = view
82        self.application.switchController(controller)
[659]83        controller.loadGame(*args, **kwargs)
[653]84       
85    def onStop(self):
86        """Called when the controller is removed from the list"""
87        self.view.hideMenu()
88                                         
89   
90    def quitGame(self):
91        """Quits the game
92           @return: None"""
93        self.application.listener.quitGame()
94
95
Note: See TracBrowser for help on using the repository browser.