# HG changeset patch # User prock@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1274463068 0 # Node ID 6ddb1eb9dfa6e4ebb1e09d3a4b22fe7697a72789 # Parent 773dc1dbe69d28ed9d113ac895b972218d77c9c1 Added the Scene which loads the town map. It is no longer a black screen demo. Changed the keys to be more common. Screenshot is now the print screen key. The console is now the backtick key. Screenshots are now date/time stamped as well. Removed the scripts/common directory as I have removed the dependency on the EventListenerBase class. diff -r 773dc1dbe69d -r 6ddb1eb9dfa6 demos/rpg/maps/level1.xml --- a/demos/rpg/maps/level1.xml Fri May 21 13:48:49 2010 +0000 +++ b/demos/rpg/maps/level1.xml Fri May 21 17:31:08 2010 +0000 @@ -1,46 +1,154 @@ - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff -r 773dc1dbe69d -r 6ddb1eb9dfa6 demos/rpg/maps/town.xml --- a/demos/rpg/maps/town.xml Fri May 21 13:48:49 2010 +0000 +++ b/demos/rpg/maps/town.xml Fri May 21 17:31:08 2010 +0000 @@ -1,46 +1,154 @@ - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff -r 773dc1dbe69d -r 6ddb1eb9dfa6 demos/rpg/scripts/common/__init__.py diff -r 773dc1dbe69d -r 6ddb1eb9dfa6 demos/rpg/scripts/common/eventlistenerbase.py --- a/demos/rpg/scripts/common/eventlistenerbase.py Fri May 21 13:48:49 2010 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -# -*- coding: utf-8 -*- - -# #################################################################### -# Copyright (C) 2005-2010 by the FIFE team -# http://www.fifengine.net -# This file is part of FIFE. -# -# FIFE is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the -# Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -# #################################################################### - -from fife import fife - -class EventListenerBase(fife.IKeyListener, fife.ICommandListener, fife.IMouseListener, fife.ConsoleExecuter): - def __init__(self, engine, regKeys=False, regCmd=False, regMouse=False, regConsole=False, regWidget=False): - self.eventmanager = engine.getEventManager() - - fife.IKeyListener.__init__(self) - if regKeys: - self.eventmanager.addKeyListener(self) - fife.ICommandListener.__init__(self) - if regCmd: - self.eventmanager.addCommandListener(self) - fife.IMouseListener.__init__(self) - if regMouse: - self.eventmanager.addMouseListener(self) - fife.ConsoleExecuter.__init__(self) - if regConsole: - engine.getGuiManager().getConsole().setConsoleExecuter(self) - - - def mousePressed(self, evt): - pass - def mouseReleased(self, evt): - pass - def mouseEntered(self, evt): - pass - def mouseExited(self, evt): - pass - def mouseClicked(self, evt): - pass - def mouseWheelMovedUp(self, evt): - pass - def mouseWheelMovedDown(self, evt): - pass - def mouseMoved(self, evt): - pass - def mouseDragged(self, evt): - pass - def keyPressed(self, evt): - pass - def keyReleased(self, evt): - pass - def onCommand(self, command): - pass - def onToolsClick(self): - print "No tools set up yet" - def onConsoleCommand(self, command): - pass - def onWidgetAction(self, evt): - pass diff -r 773dc1dbe69d -r 6ddb1eb9dfa6 demos/rpg/scripts/gamecontroller.py --- a/demos/rpg/scripts/gamecontroller.py Fri May 21 13:48:49 2010 +0000 +++ b/demos/rpg/scripts/gamecontroller.py Fri May 21 17:31:08 2010 +0000 @@ -28,30 +28,117 @@ from fife import fife +from scripts.scene import Scene from scripts.guicontroller import GUIController +class GameListener(fife.IKeyListener, fife.IMouseListener): + def __init__(self, gamecontroller): + self._engine = gamecontroller.engine + self._gamecontroller = gamecontroller + self._settings = gamecontroller.settings + self._eventmanager = self._engine.getEventManager() + + fife.IMouseListener.__init__(self) + self._eventmanager.addMouseListener(self) + + fife.IKeyListener.__init__(self) + self._eventmanager.addKeyListener(self) + + self._attached = False + + def attach(self): + if not self._attached: + self._eventmanager.addMouseListenerFront(self) + self._eventmanager.addKeyListenerFront(self) + self._attached = True + + def detach(self): + if self._attached: + self._eventmanager.removeMouseListener(self) + self._eventmanager.removeKeyListener(self) + self._attached = False + + def mousePressed(self, event): + pass + def mouseReleased(self, event): + pass + def mouseEntered(self, event): + pass + def mouseExited(self, event): + pass + def mouseClicked(self, event): + pass + def mouseWheelMovedUp(self, event): + pass + def mouseWheelMovedDown(self, event): + pass + def mouseMoved(self, event): + pass + def mouseDragged(self, event): + pass + def keyPressed(self, event): + keyval = event.getKey().getValue() + keystr = event.getKey().getAsString().lower() + if keyval == fife.Key.ESCAPE: + self.detach() + self._gamecontroller.guicontroller.showMainMenu() + event.consume() + + def keyReleased(self, event): + pass + class GameController(object): def __init__(self, application, engine, settings): self._application = application self._engine = engine self._settings = settings - self._guicontroller = GUIController(self, self._engine, self._settings) + self._guicontroller = GUIController(self) + + self._listener = GameListener(self) self._guicontroller.showMainMenu() + + self._scene = None def onConsoleCommand(self, command): """ - Might be useful if you want to have the game parse a command + Might be useful if you want to have the game parse a command. + Not sure if I am going to keep this or not. """ result = "" return result def newGame(self): - pass + self._guicontroller.hideMainMenu() + + if self._scene: + self._scene.destroyScene() + self._scene = None + + self._scene = Scene(self) + self._scene.createScene(self._settings.get("RPG", "TownMapFile", "maps/town.xml")) + + #start listening to events + self._listener.attach() def quit(self): self._application.requestQuit() def pump(self): - pass + if self._scene: + self._scene.updateScene() + + + def _getGUIController(self): + return self._guicontroller + + def _getEngine(self): + return self._engine + + def _getSettings(self): + return self._settings + + guicontroller = property(_getGUIController) + engine = property(_getEngine) + settings = property(_getSettings) diff -r 773dc1dbe69d -r 6ddb1eb9dfa6 demos/rpg/scripts/guicontroller.py --- a/demos/rpg/scripts/guicontroller.py Fri May 21 13:48:49 2010 +0000 +++ b/demos/rpg/scripts/guicontroller.py Fri May 21 17:31:08 2010 +0000 @@ -31,10 +31,10 @@ from fife.extensions.pychan import widgets class MainMenu(object): - def __init__(self, guicontroller, gamecontroller, settings): - self._guicontroller = guicontroller + def __init__(self, gamecontroller): + self._guicontroller = gamecontroller.guicontroller self._gamecontroller = gamecontroller - self._settings = settings + self._settings = gamecontroller.settings self._widget = pychan.loadXML('gui/mainmenu.xml') self._newgame = self._widget.findChild(name="new_game") @@ -74,10 +74,10 @@ widget = property(_getWidget) class GUIController(object): - def __init__(self, gamecontroller, engine, settings): + def __init__(self, gamecontroller): self._gamecontroller = gamecontroller - self._engine = engine - self._settings = settings + self._engine = gamecontroller.engine + self._settings = gamecontroller.settings self._mainmenu = None self._credits = None @@ -87,7 +87,7 @@ self._mainmenu.widget.show() else: #load and show the main menu - self._mainmenu = MainMenu(self, self._gamecontroller, self._settings) + self._mainmenu = MainMenu(self._gamecontroller) self._mainmenu.widget.show() def hideMainMenu(self): diff -r 773dc1dbe69d -r 6ddb1eb9dfa6 demos/rpg/scripts/rpg.py --- a/demos/rpg/scripts/rpg.py Fri May 21 13:48:49 2010 +0000 +++ b/demos/rpg/scripts/rpg.py Fri May 21 17:31:08 2010 +0000 @@ -24,12 +24,12 @@ # #################################################################### # This is the rio de hola client for FIFE. -import sys, os, re, math, random, shutil +import sys, os, re, math, random, shutil, time +from datetime import datetime from fife import fife from fife.extensions import * from scripts.gamecontroller import GameController -from scripts.common import eventlistenerbase from fife.extensions.basicapplication import ApplicationBase from fife.extensions import pychan from fife.extensions.pychan import widgets @@ -43,32 +43,47 @@ def isFiltered(self, event): return event.getKey().getValue() in self._keys -class ApplicationListener(eventlistenerbase.EventListenerBase): +class ApplicationListener(fife.IKeyListener, fife.ICommandListener, fife.ConsoleExecuter): def __init__(self, engine, gamecontroller): - super(ApplicationListener, self).__init__(engine,regKeys=True,regCmd=True, regMouse=False, regConsole=True, regWidget=True) self._engine = engine self._gamecontroller = gamecontroller + self._eventmanager = self._engine.getEventManager() - keyfilter = KeyFilter([fife.Key.ESCAPE]) - keyfilter.__disown__() + fife.IKeyListener.__init__(self) + self._eventmanager.addKeyListener(self) + + fife.ICommandListener.__init__(self) + self._eventmanager.addCommandListener(self) - self._engine.getEventManager().setKeyFilter(keyfilter) - + fife.ConsoleExecuter.__init__(self) + self._engine.getGuiManager().getConsole().setConsoleExecuter(self) + + keyfilter = KeyFilter([fife.Key.ESCAPE, fife.Key.BACKQUOTE, fife.Key.PRINT_SCREEN]) + keyfilter.__disown__() + + self._eventmanager.setKeyFilter(keyfilter) + self.quit = False - def keyPressed(self, evt): - keyval = evt.getKey().getValue() - keystr = evt.getKey().getAsString().lower() - consumed = False + def keyPressed(self, event): + keyval = event.getKey().getValue() + keystr = event.getKey().getAsString().lower() + + if event.isConsumed(): + return + if keyval == fife.Key.ESCAPE: self.quit = True - evt.consume() - elif keyval == fife.Key.F10: + event.consume() + elif keyval == fife.Key.BACKQUOTE: self._engine.getGuiManager().getConsole().toggleShowHide() - evt.consume() - elif keystr == 'p': - self._engine.getRenderBackend().captureScreen('screenshot.png') - evt.consume() + event.consume() + elif keyval == fife.Key.PRINT_SCREEN: + self._engine.getRenderBackend().captureScreen(time.strftime("%Y%m%d_%H%M%S", time.localtime()) + ".png") + event.consume() + + def keyReleased(self, event): + pass def onCommand(self, command): self.quit = (command.getCommandType() == fife.CMD_QUIT_GAME) @@ -94,6 +109,9 @@ if not result: result = 'no result' return result + + def onToolsClick(self): + print "No tools set up yet" class RPGApplication(ApplicationBase): def __init__(self, TDS): diff -r 773dc1dbe69d -r 6ddb1eb9dfa6 demos/rpg/scripts/scene.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demos/rpg/scripts/scene.py Fri May 21 17:31:08 2010 +0000 @@ -0,0 +1,60 @@ +#!/usr/bin/env python + +# -*- coding: utf-8 -*- + +# #################################################################### +# Copyright (C) 2005-2010 by the FIFE team +# http://www.fifengine.net +# This file is part of FIFE. +# +# FIFE is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# #################################################################### +# This is the rio de hola client for FIFE. + +import sys, os, re, math, random, shutil + +from fife import fife +from fife.extensions.loaders import loadMapFile + +class Scene(object): + def __init__(self, gamecontroller): + self._gamecontroller = gamecontroller + + self._map = None + self._cameras = {} + + def createScene(self, mapfilename): + if not self._map: + self._map = loadMapFile(mapfilename, self._gamecontroller.engine) + else: + self.destroyScene() + + for cam in self._map.getCameras(): + self._cameras[cam.getId()] = cam + + self._cameras[self._gamecontroller.settings.get("RPG", "DefaultCameraName", "camera1")].setZoom(1.0) + + def destroyScene(self): + self._cameras.clear() + + if self._map: + self._gamecontroller.engine.getModel().deleteMap(self._map) + + self._map = None + + def updateScene(self): + pass + diff -r 773dc1dbe69d -r 6ddb1eb9dfa6 demos/rpg/settings-dist.xml --- a/demos/rpg/settings-dist.xml Fri May 21 13:48:49 2010 +0000 +++ b/demos/rpg/settings-dist.xml Fri May 21 17:31:08 2010 +0000 @@ -25,5 +25,6 @@ maps/town.xml maps/level1.xml + camera1