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