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

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