Mercurial > parpg-core
comparison src/parpg/controllerbase.py @ 0:1fd2201f5c36
Initial commit of parpg-core.
author | M. George Hansen <technopolitica@gmail.com> |
---|---|
date | Sat, 14 May 2011 01:12:35 -0700 |
parents | |
children | d60f1dab8469 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1fd2201f5c36 |
---|---|
1 # This file is part of PARPG. | |
2 | |
3 # PARPG is free software: you can redistribute it and/or modify | |
4 # it under the terms of the GNU General Public License as published by | |
5 # the Free Software Foundation, either version 3 of the License, or | |
6 # (at your option) any later version. | |
7 | |
8 # PARPG is distributed in the hope that it will be useful, | |
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 # GNU General Public License for more details. | |
12 | |
13 # You should have received a copy of the GNU General Public License | |
14 # along with PARPG. If not, see <http://www.gnu.org/licenses/>. | |
15 import os | |
16 from fife import fife | |
17 | |
18 from parpg.common.listeners.key_listener import KeyListener | |
19 from parpg.common.listeners.mouse_listener import MouseListener | |
20 from parpg.common.listeners.command_listener import CommandListener | |
21 | |
22 class ControllerBase(KeyListener, MouseListener, CommandListener): | |
23 """Base of Controllers""" | |
24 def __init__(self, | |
25 engine, | |
26 view, | |
27 model, | |
28 application): | |
29 ''' | |
30 Constructor | |
31 @param engine: Instance of the active fife engine | |
32 @type engine: fife.Engine | |
33 @param view: Instance of a GameSceneView | |
34 @param type: parpg.GameSceneView | |
35 @param model: The model that has the current gamestate | |
36 @type model: parpg.GameModel | |
37 @param application: The application that created this controller | |
38 @type application: parpg.PARPGApplication | |
39 @param settings: The current settings of the application | |
40 @type settings: fife.extensions.fife_settings.Setting | |
41 ''' | |
42 KeyListener.__init__(self, application.event_listener) | |
43 MouseListener.__init__(self, application.event_listener) | |
44 CommandListener.__init__(self, application.event_listener) | |
45 self.engine = engine | |
46 self.event_manager = engine.getEventManager() | |
47 self.view = view | |
48 self.model = model | |
49 self.application = application | |
50 | |
51 def pause(self, paused): | |
52 """Stops receiving events""" | |
53 if paused: | |
54 KeyListener.detach(self) | |
55 MouseListener.detach(self) | |
56 else: | |
57 KeyListener.attach(self, self.application.event_listener) | |
58 MouseListener.attach(self, self.application.event_listener) | |
59 | |
60 def setMouseCursor(self, image, dummy_image, mc_type="native"): | |
61 """Set the mouse cursor to an image. | |
62 @type image: string | |
63 @param image: The image you want to set the cursor to | |
64 @type dummy_image: string | |
65 @param dummy_image: ??? | |
66 @type type: string | |
67 @param type: ??? | |
68 @return: None""" | |
69 cursor = self.engine.getCursor() | |
70 cursor_type = fife.CURSOR_IMAGE | |
71 img_pool = self.engine.getImagePool() | |
72 if(mc_type == "target"): | |
73 target_cursor_id = img_pool.addResourceFromFile(image) | |
74 dummy_cursor_id = img_pool.addResourceFromFile(dummy_image) | |
75 cursor.set(cursor_type, dummy_cursor_id) | |
76 cursor.setDrag(cursor_type, target_cursor_id, -16, -16) | |
77 else: | |
78 cursor_type = fife.CURSOR_IMAGE | |
79 zero_cursor_id = img_pool.addResourceFromFile(image) | |
80 cursor.set(cursor_type, zero_cursor_id) | |
81 cursor.setDrag(cursor_type, zero_cursor_id) | |
82 | |
83 def resetMouseCursor(self): | |
84 """Reset cursor to default image. | |
85 @return: None""" | |
86 image = os.path.join(self.model.settings.system_path, | |
87 self.model.settings.parpg.GuiPath, | |
88 self.model.settings.parpg.CursorPath, | |
89 self.model.settings.parpg.CursorDefault) | |
90 self.setMouseCursor(image, image) | |
91 | |
92 def onStop(self): | |
93 """Called when the controller is removed from the list""" | |
94 pass | |
95 | |
96 def pump(self): | |
97 """This method gets called every frame""" | |
98 pass | |
99 |