Mercurial > parpg-core
comparison src/parpg/application.py @ 30:94cb5843dcbb
Modifications to use the grease manager and modes
author | KarstenBock@gmx.net |
---|---|
date | Tue, 12 Jul 2011 12:31:53 +0200 |
parents | d60f1dab8469 |
children | 8b3890f17f94 |
comparison
equal
deleted
inserted
replaced
29:ad18c3f912c5 | 30:94cb5843dcbb |
---|---|
17 import sys | 17 import sys |
18 | 18 |
19 from fife import fife | 19 from fife import fife |
20 from fife.extensions import pychan | 20 from fife.extensions import pychan |
21 from fife.extensions.serializers.xmlanimation import XMLAnimationLoader | 21 from fife.extensions.serializers.xmlanimation import XMLAnimationLoader |
22 from fife.extensions.basicapplication import ApplicationBase | |
23 | 22 |
24 from parpg import console, vfs | 23 from parpg import console, vfs |
25 from parpg.font import PARPGFont | 24 from parpg.font import PARPGFont |
26 from parpg.gamemodel import GameModel | 25 from parpg.gamemodel import GameModel |
27 from parpg.mainmenuview import MainMenuView | 26 from parpg.mainmenuview import MainMenuView |
30 from parpg.common.listeners.key_listener import KeyListener | 29 from parpg.common.listeners.key_listener import KeyListener |
31 from parpg.common.listeners.mouse_listener import MouseListener | 30 from parpg.common.listeners.mouse_listener import MouseListener |
32 from parpg.common.listeners.command_listener import CommandListener | 31 from parpg.common.listeners.command_listener import CommandListener |
33 from parpg.common.listeners.console_executor import ConsoleExecuter | 32 from parpg.common.listeners.console_executor import ConsoleExecuter |
34 from parpg.common.listeners.widget_listener import WidgetListener | 33 from parpg.common.listeners.widget_listener import WidgetListener |
34 from parpg.mode import FifeManager | |
35 | 35 |
36 class KeyFilter(fife.IKeyFilter): | 36 class KeyFilter(fife.IKeyFilter): |
37 """ | 37 """ |
38 This is the implementation of the fife.IKeyFilter class. | 38 This is the implementation of the fife.IKeyFilter class. |
39 | 39 |
101 @return: None""" | 101 @return: None""" |
102 if(command.getCommandType() == fife.CMD_QUIT_GAME): | 102 if(command.getCommandType() == fife.CMD_QUIT_GAME): |
103 self.quit = True | 103 self.quit = True |
104 command.consume() | 104 command.consume() |
105 | 105 |
106 class PARPGApplication(ApplicationBase): | 106 class PARPGApplication(FifeManager): |
107 """Main Application class | 107 """Main Application class |
108 We use an MVC model model | 108 We use an MVC model model |
109 self.gamesceneview is our view,self.model is our model | 109 self.gamesceneview is our view,self.model is our model |
110 self.controller is the controller""" | 110 self.controller is the controller""" |
111 | 111 |
112 def __init__(self, setting): | 112 def __init__(self, setting): |
113 """Initialise the instance. | 113 """Initialise the instance. |
114 @return: None""" | 114 @return: None""" |
115 self._setting = setting | 115 self.modes = [] |
116 self._setting = setting | |
116 self.engine = fife.Engine() | 117 self.engine = fife.Engine() |
117 self.loadSettings() | 118 self.loadSettings() |
118 self.engine.init() | 119 self.engine.init() |
119 # KLUDGE M. George Hansen 2011-06-04: See parpg/vfs.py. | 120 # KLUDGE M. George Hansen 2011-06-04: See parpg/vfs.py. |
120 vfs.VFS = self.engine.getVFS() | 121 vfs.VFS = self.engine.getVFS() |
140 # scripts to locate their resources. | 141 # scripts to locate their resources. |
141 os.chdir(setting.parpg.DataPath) | 142 os.chdir(setting.parpg.DataPath) |
142 self.view = MainMenuView(self.engine, self.model) | 143 self.view = MainMenuView(self.engine, self.model) |
143 self.loadFonts() | 144 self.loadFonts() |
144 self.event_listener = EventListener(self.engine) | 145 self.event_listener = EventListener(self.engine) |
145 self.controllers = [] | |
146 controller = MainMenuController(self.engine, self.view, self.model, | 146 controller = MainMenuController(self.engine, self.view, self.model, |
147 self) | 147 self) |
148 #controller.initHud() | 148 #controller.initHud() |
149 self.controllers.append(controller) | 149 self.push_mode(controller) |
150 self.listener = ApplicationListener(self.event_listener, | 150 self.listener = ApplicationListener(self.event_listener, |
151 self.engine, | 151 self.engine, |
152 self.view, | 152 self.view, |
153 self.model) | 153 self.model) |
154 #start_map = self._setting.fife.get("PARPG", "Map") | 154 #start_map = self._setting.fife.get("PARPG", "Map") |
202 overriding it, the program quit's on esc press, rather than | 202 overriding it, the program quit's on esc press, rather than |
203 invoking the main menu | 203 invoking the main menu |
204 """ | 204 """ |
205 pass | 205 pass |
206 | 206 |
207 def pushController(self, controller): | |
208 """Adds a controller to the list to be the current active one.""" | |
209 self.controllers[-1].pause(True) | |
210 self.controllers.append(controller) | |
211 | |
212 def popController(self): | |
213 """Removes and returns the current active controller, unless its the last one""" | |
214 ret_controller = None | |
215 if self.controllers.count > 1: | |
216 ret_controller = self.controllers.pop() | |
217 self.controllers[-1].pause(False) | |
218 ret_controller.onStop() | |
219 return ret_controller | |
220 | |
221 def switchController(self, controller): | |
222 """Clears the controller list and adds a controller to be the current active one""" | |
223 for old_controller in self.controllers: | |
224 old_controller.onStop() | |
225 self.controllers = [] | |
226 self.controllers.append(controller) | |
227 | |
228 def _pump(self): | 207 def _pump(self): |
229 """Main game loop. | 208 """Main game loop. |
230 There are in fact 2 main loops, this one and the one in GameSceneView. | 209 There are in fact 2 main loops, this one and the one in GameSceneView. |
231 @return: None""" | 210 @return: None""" |
232 if self.listener.quit: | 211 if self.listener.quit: |
233 self.breakRequested = True #pylint: disable-msg=C0103 | 212 self.breakRequested = True #pylint: disable-msg=C0103 |
234 else: | 213 else: |
235 for controller in self.controllers: | 214 FifeManager._pump(self) |
236 controller.pump() |