Package fife :: Package extensions :: Package librocket :: Module rocketbasicapplication
[hide private]
[frames] | no frames]

Source Code for Module fife.extensions.librocket.rocketbasicapplication

  1  # -*- coding: utf-8 -*- 
  2   
  3  # #################################################################### 
  4  #  Copyright (C) 2005-2019 by the FIFE team 
  5  #  http://www.fifengine.net 
  6  #  This file is part of FIFE. 
  7  # 
  8  #  FIFE is free software; you can redistribute it and/or 
  9  #  modify it under the terms of the GNU Lesser General Public 
 10  #  License as published by the Free Software Foundation; either 
 11  #  version 2.1 of the License, or (at your option) any later version. 
 12  # 
 13  #  This library is distributed in the hope that it will be useful, 
 14  #  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 15  #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
 16  #  Lesser General Public License for more details. 
 17  # 
 18  #  You should have received a copy of the GNU Lesser General Public 
 19  #  License along with this library; if not, write to the 
 20  #  Free Software Foundation, Inc., 
 21  #  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA 
 22  # #################################################################### 
 23   
 24  """ 
 25  The basic application and main loop. 
 26   
 27  See the L{ApplicationBase} documentation. 
 28  """ 
 29   
 30  from fife import fife 
 31  from fife.extensions.basicapplication import ApplicationBase 
 32   
 33  import rocket 
 34   
35 -class RocketEventListener(fife.IKeyListener, fife.ICommandListener):
36 """ 37 Default, rudimentary event listener. 38 39 Will cause the application to quit on pressing ESC. 40 """
41 - def __init__(self, app):
42 self.app = app 43 self.engine = app.engine 44 eventmanager = self.engine.getEventManager() 45 #eventmanager.setNonConsumableKeys([fife.Key.ESCAPE]) 46 fife.IKeyListener.__init__(self) 47 eventmanager.addKeyListener(self) 48 fife.ICommandListener.__init__(self) 49 eventmanager.addCommandListener(self) 50 self.quitrequested = False 51 self.debuggeractive = False
52
53 - def keyPressed(self, evt):
54 keyval = evt.getKey().getValue() 55 56 if keyval == fife.Key.ESCAPE: 57 self.app.quit()
58
59 - def keyReleased(self, evt):
60 keyval = evt.getKey().getValue() 61 62 if keyval == fife.Key.F12: 63 if not self.debuggeractive: 64 self.app.guimanager.showDebugger() 65 self.debuggeractive = True 66 else: 67 self.app.guimanager.hideDebugger() 68 self.debuggeractive = False
69
70 - def onCommand(self, command):
71 if command.getCommandType() == fife.CMD_QUIT_GAME: 72 self.quitrequested = True 73 command.consume()
74
75 -class RocketApplicationBase(ApplicationBase):
76 """ 77 PychanApplicationBase is an extendable class that provides a basic environment for a FIFE-based client. 78 This class should be extended if you 've built fife with librocket support and want to create a game 79 using it. 80 """
81 - def __init__(self, setting=None):
82 super(RocketApplicationBase, self).__init__(setting) 83 84 settings = self.engine.getSettings() 85 guimanager = fife.LibRocketManager() 86 87 #transfer ownership to the engine 88 guimanager.thisown = 0 89 90 #initialize gui manager and set it as the engine's active gui manager 91 guimanager.init(settings.getRenderBackend(), settings.getScreenWidth(), settings.getScreenHeight()) 92 self.engine.setGuiManager(guimanager) 93 self.guimanager = guimanager 94 self.engine.getEventManager().addSdlEventListener(guimanager) 95 96 #get reference to the active rocket context 97 self.rocketcontext = rocket.contexts['default']
98
99 - def createListener(self):
100 self._listener = RocketEventListener(self) 101 return self._listener
102
103 - def quit(self):
104 self.rocketcontext.UnloadAllDocuments() 105 self.rocketcontext.UnloadAllMouseCursors() 106 107 #release reference to rocket context 108 self.rocketcontext = None 109 110 #call parent's quit 111 super(RocketApplicationBase, self).quit()
112