Mercurial > parpg-source
changeset 8:708a6f651c31
Modifications to use the grease manager and modes
author | KarstenBock@gmx.net |
---|---|
date | Tue, 12 Jul 2011 12:31:53 +0200 |
parents | 710f299ed275 |
children | 3a9c97a75c5b |
files | application.py charactercreationcontroller.py controllerbase.py dialoguecontroller.py gamescenecontroller.py mainmenucontroller.py mode.py objects/action.py world.py |
diffstat | 9 files changed, 39 insertions(+), 59 deletions(-) [+] |
line wrap: on
line diff
--- a/application.py Tue Jul 12 12:30:41 2011 +0200 +++ b/application.py Tue Jul 12 12:31:53 2011 +0200 @@ -19,7 +19,6 @@ from fife import fife from fife.extensions import pychan from fife.extensions.serializers.xmlanimation import XMLAnimationLoader -from fife.extensions.basicapplication import ApplicationBase from parpg import console, vfs from parpg.font import PARPGFont @@ -32,6 +31,7 @@ from parpg.common.listeners.command_listener import CommandListener from parpg.common.listeners.console_executor import ConsoleExecuter from parpg.common.listeners.widget_listener import WidgetListener +from parpg.mode import FifeManager class KeyFilter(fife.IKeyFilter): """ @@ -103,7 +103,7 @@ self.quit = True command.consume() -class PARPGApplication(ApplicationBase): +class PARPGApplication(FifeManager): """Main Application class We use an MVC model model self.gamesceneview is our view,self.model is our model @@ -112,7 +112,8 @@ def __init__(self, setting): """Initialise the instance. @return: None""" - self._setting = setting + self.modes = [] + self._setting = setting self.engine = fife.Engine() self.loadSettings() self.engine.init() @@ -142,11 +143,10 @@ self.view = MainMenuView(self.engine, self.model) self.loadFonts() self.event_listener = EventListener(self.engine) - self.controllers = [] controller = MainMenuController(self.engine, self.view, self.model, self) #controller.initHud() - self.controllers.append(controller) + self.push_mode(controller) self.listener = ApplicationListener(self.event_listener, self.engine, self.view, @@ -204,27 +204,6 @@ """ pass - def pushController(self, controller): - """Adds a controller to the list to be the current active one.""" - self.controllers[-1].pause(True) - self.controllers.append(controller) - - def popController(self): - """Removes and returns the current active controller, unless its the last one""" - ret_controller = None - if self.controllers.count > 1: - ret_controller = self.controllers.pop() - self.controllers[-1].pause(False) - ret_controller.onStop() - return ret_controller - - def switchController(self, controller): - """Clears the controller list and adds a controller to be the current active one""" - for old_controller in self.controllers: - old_controller.onStop() - self.controllers = [] - self.controllers.append(controller) - def _pump(self): """Main game loop. There are in fact 2 main loops, this one and the one in GameSceneView. @@ -232,5 +211,4 @@ if self.listener.quit: self.breakRequested = True #pylint: disable-msg=C0103 else: - for controller in self.controllers: - controller.pump() + FifeManager._pump(self)
--- a/charactercreationcontroller.py Tue Jul 12 12:30:41 2011 +0200 +++ b/charactercreationcontroller.py Tue Jul 12 12:31:53 2011 +0200 @@ -144,7 +144,7 @@ controller = GameSceneController(self.engine, view, self.model, self.application) self.application.view = view - self.application.switchController(controller) + self.application.swap_modes(controller) start_map = self.settings.parpg.Map self.model.changeMap(start_map) @@ -159,9 +159,9 @@ controller = MainMenuController(self.engine, view, self.model, self.application) self.application.view = view - self.application.switchController(controller) + self.application.activate_mode(controller) - def onStop(self): + def on_deactivate(self): """Called when the controller is removed from the list. @return: None""" self.view.hide()
--- a/controllerbase.py Tue Jul 12 12:30:41 2011 +0200 +++ b/controllerbase.py Tue Jul 12 12:31:53 2011 +0200 @@ -17,8 +17,9 @@ from parpg.common.listeners.key_listener import KeyListener from parpg.common.listeners.mouse_listener import MouseListener from parpg.common.listeners.command_listener import CommandListener +from parpg.world import World -class ControllerBase(KeyListener, MouseListener, CommandListener): +class ControllerBase(World, KeyListener, MouseListener, CommandListener): """Base of Controllers""" def __init__(self, engine, @@ -41,6 +42,7 @@ KeyListener.__init__(self, application.event_listener) MouseListener.__init__(self, application.event_listener) CommandListener.__init__(self, application.event_listener) + World.__init__(self) self.engine = engine self.event_manager = engine.getEventManager() self.view = view @@ -85,12 +87,4 @@ image = '/'.join(['gui/cursors/', self.model.settings.parpg.CursorDefault]) self.setMouseCursor(image, image) - - def onStop(self): - """Called when the controller is removed from the list""" - pass - - def pump(self): - """This method gets called every frame""" - pass
--- a/dialoguecontroller.py Tue Jul 12 12:30:41 2011 +0200 +++ b/dialoguecontroller.py Tue Jul 12 12:31:53 2011 +0200 @@ -51,9 +51,10 @@ self.view.hud.enabled = False - def pump(self): + def pump(self, dt): + ControllerBase.pump(self, dt) if self.dialogue and not self.dialogue.active: - self.application.popController() + self.application.pop_mode() self.model.pause(False) self.view.hud.enabled = True
--- a/gamescenecontroller.py Tue Jul 12 12:30:41 2011 +0200 +++ b/gamescenecontroller.py Tue Jul 12 12:31:53 2011 +0200 @@ -516,12 +516,13 @@ elif(command.getCommandType() == fife.CMD_MOUSE_FOCUS_LOST): self.has_mouse_focus = False - def pump(self): + def pump(self, dt): """Routine called during each frame. Our main loop is in ./run.py""" # uncomment to instrument # t0 = time.time() if self.paused: return + ControllerBase.pump(self, dt) self.updateMouse() if self.model.active_map: self.view.highlightFrontObject(self.last_mousecoords)
--- a/mainmenucontroller.py Tue Jul 12 12:30:41 2011 +0200 +++ b/mainmenucontroller.py Tue Jul 12 12:31:53 2011 +0200 @@ -55,7 +55,7 @@ controller = CharacterCreationController(self.engine, view, self.model, self.application) self.application.view = view - self.application.switchController(controller) + self.application.swap_modes(controller) # def newGame(self): # """Starts a new game""" @@ -66,7 +66,7 @@ # self.model, # self.application) # self.application.view = view -# self.application.switchController(controller) +# self.application.swap_modes(controller) # start_map = self.model.settings.get("PARPG", "Map") # self.model.changeMap(start_map) @@ -81,10 +81,10 @@ self.model, self.application) self.application.view = view - self.application.switchController(controller) + self.application.swap_modes(controller) controller.loadGame(*args, **kwargs) - def onStop(self): + def on_deactivate(self): """Called when the controller is removed from the list""" self.view.hideMenu()
--- a/mode.py Tue Jul 12 12:30:41 2011 +0200 +++ b/mode.py Tue Jul 12 12:31:53 2011 +0200 @@ -1,5 +1,5 @@ -from grease.mode import * +from parpg.grease.mode import * from fife.extensions.basicapplication import ApplicationBase import abc @@ -8,7 +8,6 @@ def __init__(self, TDS): ApplicationBase.__init__(self, TDS) self.modes = [] - self._settings = TDS def _pump(self): if self.current_mode: @@ -16,6 +15,9 @@ class FifeMode(BaseMode): + def __init__(self): + BaseMode.__init__(self) + @abc.abstractmethod def pump(self, dt): """Performs actions every frame""" \ No newline at end of file
--- a/objects/action.py Tue Jul 12 12:30:41 2011 +0200 +++ b/objects/action.py Tue Jul 12 12:31:53 2011 +0200 @@ -315,7 +315,7 @@ self.view, self.model, self.controller.application) - self.controller.application.pushController(dialogue_controller) + self.controller.application.push_mode(dialogue_controller) dialogue_controller.startTalk(self.npc) else: self.npc.behaviour.agent.say("Leave me alone!", 1000)
--- a/world.py Tue Jul 12 12:30:41 2011 +0200 +++ b/world.py Tue Jul 12 12:31:53 2011 +0200 @@ -1,12 +1,16 @@ -from grease.world import * -from mode import FifeMode +from parpg.grease.world import * +from parpg.mode import FifeMode -class World(FifeModeMode, BaseWorld): +class World(FifeMode, BaseWorld): + + def __init__(self): + FifeMode.__init__(self) + BaseWorld.__init__(self) def pump(self, dt): - for component in self.components: - if hasattr(component, "step"): - component.step(dt) - for system in self.systems: - if hasattr(system, "step"): - system.step(dt) + for component in self.components: + if hasattr(component, "step"): + component.step(dt) + for system in self.systems: + if hasattr(system, "step"): + system.step(dt) \ No newline at end of file