Mercurial > parpg-source
annotate gamescenecontroller.py @ 104:c9afad46091b
Added actions for lockable components (Open, Close, Lock and Unlock).
author | KarstenBock@gmx.net |
---|---|
date | Fri, 30 Sep 2011 14:05:16 +0200 |
parents | 824f3068ef2a |
children | 100a39fa64a2 |
rev | line source |
---|---|
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
1 # This file is part of PARPG. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
2 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
3 # PARPG is free software: you can redistribute it and/or modify |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
4 # it under the terms of the GNU General Public License as published by |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
5 # the Free Software Foundation, either version 3 of the License, or |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
6 # (at your option) any later version. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
7 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
8 # PARPG is distributed in the hope that it will be useful, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
11 # GNU General Public License for more details. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
12 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
13 # You should have received a copy of the GNU General Public License |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
14 # along with PARPG. If not, see <http://www.gnu.org/licenses/>. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
15 """This file contains the GameSceneController that handles input when the game |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
16 is exploring a scene""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
17 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
18 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
19 from datetime import datetime |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
20 import random |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
21 import glob |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
22 import os |
57
ba85e5aff370
Removed the pos value from the fifeagent component. getItemActions of Gamescenecontroller gets the position by calling a method of the behaviour.
KarstenBock@gmx.net
parents:
53
diff
changeset
|
23 import logging |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
24 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
25 from fife import fife |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
26 from fife import extensions |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
27 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
28 from controllerbase import ControllerBase |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
29 from parpg.gui.hud import Hud |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
30 from parpg.gui import drag_drop_data as data_drag |
104
c9afad46091b
Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents:
101
diff
changeset
|
31 from objects.action import (ChangeMapAction, ExamineAction, TalkAction, |
c9afad46091b
Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents:
101
diff
changeset
|
32 OpenAction, CloseAction, UnlockAction, LockAction, |
c9afad46091b
Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents:
101
diff
changeset
|
33 PickUpAction, DropItemAction, |
c9afad46091b
Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents:
101
diff
changeset
|
34 ) |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
35 |
88 | 36 from parpg.world import World |
37 | |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
38 #For debugging/code analysis |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
39 if False: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
40 from gamesceneview import GameSceneView |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
41 from gamemodel import GameModel |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
42 from parpg import PARPGApplication |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
43 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
44 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
45 logger = logging.getLogger('gamescenecontroller') |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
46 |
88 | 47 class GameSceneController(World, ControllerBase): |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
48 ''' |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
49 This controller handles inputs when the game is in "scene" state. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
50 "Scene" state is when the player can move around and interact |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
51 with objects. Like, talking to a npc or examining the contents of a box. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
52 ''' |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
53 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
54 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
55 def __init__(self, engine, view, model, application): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
56 ''' |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
57 Constructor |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
58 @param engine: Instance of the active fife engine |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
59 @type engine: fife.Engine |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
60 @param view: Instance of a GameSceneView |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
61 @param type: parpg.GameSceneView |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
62 @param model: The model that has the current gamestate |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
63 @type model: parpg.GameModel |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
64 @param application: The application that created this controller |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
65 @type application: parpg.PARPGApplication |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
66 @param settings: The current settings of the application |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
67 @type settings: fife.extensions.fife_settings.Setting |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
68 ''' |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
69 ControllerBase.__init__(self, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
70 engine, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
71 view, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
72 model, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
73 application) |
88 | 74 World.__init__(self) |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
75 #this can be helpful for IDEs code analysis |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
76 if False: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
77 assert(isinstance(self.engine, fife.Engine)) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
78 assert(isinstance(self.view, GameSceneView)) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
79 assert(isinstance(self.view, GameModel)) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
80 assert(isinstance(self.application, PARPGApplication)) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
81 assert(isinstance(self.event_manager, fife.EventManager)) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
82 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
83 # Last saved mouse coords |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
84 self.action_number = 1 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
85 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
86 self.has_mouse_focus = True |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
87 self.last_mousecoords = None |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
88 self.mouse_callback = None |
4 | 89 self.original_cursor_id = self.engine.getCursor().getId() |
90 self.scroll_data = {"mouse":[], "kb":[], "offset":[0,0]} | |
91 self.scroll_timer = extensions.fife_timer.Timer( | |
92 100, | |
93 lambda: self.view.moveCamera(self.scroll_data["offset"]), | |
94 ) | |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
95 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
96 #this is temporary until we can set the native cursor |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
97 self.resetMouseCursor() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
98 self.paused = False |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
99 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
100 if model.settings.fife.EnableSound: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
101 if not self.view.sounds.music_init: |
2
06145a6ee387
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
102 music_path = 'music' |
06145a6ee387
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
103 music_file = random.choice( |
06145a6ee387
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
104 glob.glob('/'.join([music_path, '*.ogg'])) |
06145a6ee387
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
105 ) |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
106 self.view.sounds.playMusic(music_file) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
107 self.initHud() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
108 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
109 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
110 def initHud(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
111 """Initialize the hud member |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
112 @return: None""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
113 hud_callbacks = { |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
114 'saveGame': self.saveGame, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
115 'loadGame': self.loadGame, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
116 'quitGame': self.quitGame, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
117 } |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
118 self.view.hud = Hud(self, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
119 self.model.settings, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
120 hud_callbacks) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
121 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
122 def keyPressed(self, evt): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
123 """Whenever a key is pressed, fife calls this routine. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
124 @type evt: fife.event |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
125 @param evt: The event that fife caught |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
126 @return: None""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
127 key = evt.getKey() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
128 key_val = key.getValue() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
129 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
130 if(key_val == key.Q): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
131 # we need to quit the game |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
132 self.view.hud.quitGame() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
133 if(key_val == key.T): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
134 self.model.active_map.toggleRenderer('GridRenderer') |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
135 if(key_val == key.F1): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
136 # display the help screen and pause the game |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
137 self.view.hud.displayHelp() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
138 if(key_val == key.F5): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
139 self.model.active_map.toggleRenderer('CoordinateRenderer') |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
140 if(key_val == key.F7): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
141 # F7 saves a screenshot to screenshots directory |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
142 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
143 settings = self.model.settings |
2
06145a6ee387
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
144 # FIXME M. George Hansen 2011-06-06: Not sure that user_path is set |
06145a6ee387
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
145 # correctly atm. |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
146 screenshot_directory = os.path.join(settings.user_path, |
2
06145a6ee387
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
147 'screenshots') |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
148 # try to create the screenshots directory |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
149 try: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
150 os.mkdir(screenshot_directory) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
151 #TODO: distinguish between already existing permissions error |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
152 except OSError: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
153 logger.warning("screenshot directory wasn't created.") |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
154 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
155 screenshot_file = os.path.join(screenshot_directory, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
156 'screen-{0}.png'.format( |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
157 datetime.now().strftime( |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
158 '%Y-%m-%d-%H-%M-%S'))) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
159 self.engine.getRenderBackend().captureScreen(screenshot_file) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
160 logger.info("PARPG: Saved: {0}".format(screenshot_file)) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
161 if(key_val == key.F10): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
162 # F10 shows/hides the console |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
163 self.engine.getGuiManager().getConsole().toggleShowHide() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
164 if(key_val == key.C): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
165 # C opens and closes the character screen. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
166 self.view.hud.toggleCharacterScreen() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
167 if(key_val == key.I): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
168 # I opens and closes the inventory |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
169 self.view.hud.toggleInventory() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
170 if(key_val == key.A): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
171 # A adds a test action to the action box |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
172 # The test actions will follow this format: Action 1, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
173 # Action 2, etc. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
174 self.view.hud.addAction("Action " + str(self.action_number)) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
175 self.action_number += 1 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
176 if(key_val == key.ESCAPE): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
177 # Escape brings up the main menu |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
178 self.view.hud.displayMenu() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
179 # Hide the quit menu |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
180 self.view.hud.quit_window.hide() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
181 if(key_val == key.M): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
182 self.view.sounds.toggleMusic() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
183 if(key_val == key.PAUSE): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
184 # Pause pause/unpause the game |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
185 self.model.togglePause() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
186 self.pause(False) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
187 if(key_val == key.SPACE): |
4 | 188 self.model.active_map.centerCameraOnPlayer() |
189 | |
190 #alter scroll data if a directional key is hit | |
191 if(key_val == key.UP): | |
192 if not "up" in self.scroll_data["kb"]: | |
193 self.scroll_data["kb"].append("up") | |
194 | |
195 if(key_val == key.RIGHT): | |
196 if not "right" in self.scroll_data["kb"]: | |
197 self.scroll_data["kb"].append("right") | |
198 | |
199 if(key_val == key.DOWN): | |
200 if not "down" in self.scroll_data["kb"]: | |
201 self.scroll_data["kb"].append("down") | |
202 | |
203 if(key_val == key.LEFT): | |
204 if not "left" in self.scroll_data["kb"]: | |
205 self.scroll_data["kb"].append("left") | |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
206 |
4 | 207 def keyReleased(self, evt): |
208 """Whenever a key is pressed, fife calls this routine. | |
209 @type evt: fife.event | |
210 @param evt: The event that fife caught | |
211 @return: None""" | |
212 key = evt.getKey() | |
213 key_val = key.getValue() | |
214 | |
215 #alter scroll data if a directional key is released | |
216 if(key_val == key.UP): | |
217 if "up" in self.scroll_data["kb"]: | |
218 self.scroll_data["kb"].remove("up") | |
219 | |
220 if(key_val == key.RIGHT): | |
221 if "right" in self.scroll_data["kb"]: | |
222 self.scroll_data["kb"].remove("right") | |
223 | |
224 if(key_val == key.DOWN): | |
225 if "down" in self.scroll_data["kb"]: | |
226 self.scroll_data["kb"].remove("down") | |
227 | |
228 if(key_val == key.LEFT): | |
229 if "left" in self.scroll_data["kb"]: | |
230 self.scroll_data["kb"].remove("left") | |
231 | |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
232 def mouseReleased(self, evt): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
233 """If a mouse button is released, fife calls this routine. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
234 We want to wait until the button is released, because otherwise |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
235 pychan captures the release if a menu is opened. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
236 @type evt: fife.event |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
237 @param evt: The event that fife caught |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
238 @return: None""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
239 self.view.hud.hideContextMenu() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
240 scr_point = fife.ScreenPoint(evt.getX(), evt.getY()) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
241 if(evt.getButton() == fife.MouseEvent.LEFT): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
242 if(data_drag.dragging): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
243 coord = self.model.getCoords(scr_point)\ |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
244 .getExactLayerCoordinates() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
245 commands = ({"Command": "ResetMouseCursor"}, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
246 {"Command": "StopDragging"}) |
44
98f26f7636d8
Changes to make PARPG "runable" with grease. (With the correct modified assets)
KarstenBock@gmx.net
parents:
39
diff
changeset
|
247 self.model.game_state.getObjectById("PlayerCharacter").fifeagent.approach([coord.x, |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
248 coord.y], |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
249 DropItemAction(self, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
250 data_drag.dragged_item, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
251 commands)) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
252 else: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
253 self.model.movePlayer(self.model.getCoords(scr_point)) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
254 elif(evt.getButton() == fife.MouseEvent.RIGHT): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
255 # is there an object here? |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
256 tmp_active_map = self.model.active_map |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
257 instances = tmp_active_map.cameras[tmp_active_map.my_cam_id].\ |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
258 getMatchingInstances(scr_point, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
259 tmp_active_map.agent_layer) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
260 info = None |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
261 for inst in instances: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
262 # check to see if this is an active item |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
263 if(self.model.objectActive(inst.getId())): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
264 # yes, get the model |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
265 info = self.getItemActions(inst.getId()) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
266 break |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
267 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
268 # take the menu items returned by the engine or show a |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
269 # default menu if no items |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
270 data = info or \ |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
271 [["Walk", "Walk here", self.view.onWalk, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
272 self.model.getCoords(scr_point)]] |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
273 # show the menu |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
274 self.view.hud.showContextMenu(data, (scr_point.x, scr_point.y)) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
275 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
276 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
277 def updateMouse(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
278 """Updates the mouse values""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
279 if self.paused: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
280 return |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
281 cursor = self.engine.getCursor() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
282 #this can be helpful for IDEs code analysis |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
283 if False: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
284 assert(isinstance(cursor, fife.Cursor)) |
4 | 285 self.last_mousecoords = fife.ScreenPoint(cursor.getX(), cursor.getY()) |
286 self.view.highlightFrontObject(self.last_mousecoords) | |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
287 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
288 #set the trigger area in pixles |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
289 pixle_edge = 20 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
290 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
291 mouse_x = self.last_mousecoords.x |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
292 screen_width = self.model.engine.getSettings().getScreenWidth() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
293 mouse_y = self.last_mousecoords.y |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
294 screen_height = self.model.engine.getSettings().getScreenHeight() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
295 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
296 image = None |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
297 settings = self.model.settings |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
298 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
299 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
300 #edge logic |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
301 if self.has_mouse_focus: |
4 | 302 direction = self.scroll_data["mouse"] = [] |
303 | |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
304 #up |
4 | 305 if mouse_y <= pixle_edge: |
306 direction.append("up") | |
2
06145a6ee387
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
307 image = '/'.join(['gui/cursors', settings.parpg.CursorUp]) |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
308 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
309 #right |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
310 if mouse_x >= screen_width - pixle_edge: |
4 | 311 direction.append("right") |
2
06145a6ee387
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
312 image = '/'.join(['gui/cursors', settings.parpg.CursorRight]) |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
313 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
314 #down |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
315 if mouse_y >= screen_height - pixle_edge: |
4 | 316 direction.append("down") |
2
06145a6ee387
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
317 image = '/'.join(['gui/cursors', settings.parpg.CursorDown]) |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
318 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
319 #left |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
320 if mouse_x <= pixle_edge: |
4 | 321 direction.append("left") |
2
06145a6ee387
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
322 image = '/'.join(['gui/cursors', settings.parpg.CursorLeft]) |
4 | 323 |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
324 if image is not None and not data_drag.dragging: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
325 self.setMouseCursor(image, image) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
326 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
327 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
328 def handleCommands(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
329 """Check if a command is to be executed |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
330 """ |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
331 if self.model.map_change: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
332 self.pause(True) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
333 if self.model.active_map: |
88 | 334 self.model.updateObjectDB(self) |
335 player_char = self.model.game_state.\ | |
336 getObjectById("PlayerCharacter").fifeagent | |
337 pc_agent = self.model.agents\ | |
338 [self.model.ALL_AGENTS_KEY]["PlayerCharacter"] | |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
339 pc_agent["Map"] = self.model.target_map_name |
101 | 340 pc_agent["Position"] = (self.model.target_position or |
341 pc_agent["Position"]) | |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
342 player_agent = self.model.active_map.\ |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
343 agent_layer.getInstance("PlayerCharacter") |
101 | 344 self.model.game_state.deleteObject("PlayerCharacter").delete() |
345 deleted = self.model.game_state.deleteObjectsFromMap( | |
88 | 346 self.model.game_state.current_map_name |
347 ) | |
101 | 348 deleted.extend( |
349 self.model.game_state.deleteObjectsFromMap(None) | |
350 ) | |
351 for obj in deleted: | |
352 obj.delete() | |
2
06145a6ee387
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
353 |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
354 self.model.loadMap(self.model.target_map_name) |
2
06145a6ee387
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
355 |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
356 self.model.setActiveMap(self.model.target_map_name) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
357 self.model.readAgentsOfMap(self.model.target_map_name) |
2
06145a6ee387
Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents:
0
diff
changeset
|
358 |
39
3011bc71ab20
Added funcionality to load Entities from file
KarstenBock@gmx.net
parents:
8
diff
changeset
|
359 self.model.placeAgents(self) |
44
98f26f7636d8
Changes to make PARPG "runable" with grease. (With the correct modified assets)
KarstenBock@gmx.net
parents:
39
diff
changeset
|
360 self.model.placePC(self) |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
361 self.model.map_change = False |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
362 # The PlayerCharacter has an inventory, and also some |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
363 # filling of the ready slots in the HUD. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
364 # At this point we sync the contents of the ready slots |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
365 # with the contents of the inventory. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
366 self.view.hud.inventory = None |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
367 self.view.hud.initializeInventory() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
368 self.pause(False) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
369 |
4 | 370 def handleScrolling(self): |
371 """ | |
372 Merge kb and mouse related scroll data, limit the speed and | |
373 move the camera. | |
374 """ | |
375 #this is how many pxls the camera is moved in one time frame | |
376 scroll_offset = self.scroll_data["offset"] = [0,0] | |
377 | |
378 mouse = self.scroll_data["mouse"] | |
379 keyboard = self.scroll_data["kb"] | |
380 speed = self.model.settings.parpg.ScrollSpeed | |
381 | |
382 #adds a value to the offset depending on the contents of each | |
383 # of the controllers: set() removes doubles | |
384 scroll_direction = set(mouse+keyboard) | |
385 for direction in scroll_direction: | |
386 if direction == "up": | |
387 scroll_offset[0] +=1 | |
388 scroll_offset[1] -=1 | |
389 elif direction == "right": | |
390 scroll_offset[0] +=1 | |
391 scroll_offset[1] +=1 | |
392 elif direction == "down": | |
393 scroll_offset[0] -=1 | |
394 scroll_offset[1] +=1 | |
395 elif direction == "left": | |
396 scroll_offset[0] -=1 | |
397 scroll_offset[1] -=1 | |
398 | |
399 #keep the speed within bounds | |
400 if scroll_offset[0] > 0: scroll_offset[0] = speed | |
401 if scroll_offset[0] < 0: scroll_offset[0] = -speed | |
402 | |
403 if scroll_offset[1] > 0: scroll_offset[1] = speed | |
404 if scroll_offset[1] < 0: scroll_offset[1] = -speed | |
405 | |
406 #de/activate scrolling | |
407 if scroll_offset != [0, 0]: | |
408 self.scroll_timer.start() | |
409 else: | |
410 self.scroll_timer.stop() | |
411 if not data_drag.dragging: | |
412 self.resetMouseCursor() | |
413 | |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
414 def nullFunc(self, userdata): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
415 """Sample callback for the context menus.""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
416 logger.info(userdata) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
417 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
418 def initTalk(self, npc_info): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
419 """ Starts the PlayerCharacter talking to an NPC. """ |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
420 # TODO: work more on this when we get NPCData and HeroData straightened |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
421 # out |
51
d3a9caba067b
Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
422 npc = self.model.game_state.getObjectById( |
86
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
82
diff
changeset
|
423 npc_info.general.identifier, |
51
d3a9caba067b
Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
424 self.model.game_state.current_map_name |
d3a9caba067b
Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
425 ) |
d3a9caba067b
Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
426 npc_pos = npc.fifeagent.behaviour.getLocation().getLayerCoordinates() |
d3a9caba067b
Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
427 self.model.game_state.getObjectById("PlayerCharacter").fifeagent.\ |
d3a9caba067b
Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
428 behaviour.approach([npc_pos.x, |
d3a9caba067b
Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
429 npc_pos.y], |
d3a9caba067b
Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
430 TalkAction(self, npc)) |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
431 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
432 def getItemActions(self, obj_id): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
433 """Given the objects ID, return the text strings and callbacks. |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
434 @type obj_id: string |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
435 @param obj_id: ID of object |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
436 @rtype: list |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
437 @return: List of text and callbacks""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
438 actions = [] |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
439 obj = self.model.game_state.\ |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
440 getObjectById(obj_id, |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
441 self.model.game_state.current_map_name) |
57
ba85e5aff370
Removed the pos value from the fifeagent component. getItemActions of Gamescenecontroller gets the position by calling a method of the behaviour.
KarstenBock@gmx.net
parents:
53
diff
changeset
|
442 obj_pos = obj.fifeagent.behaviour.getLocation().getLayerCoordinates() |
51
d3a9caba067b
Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
443 player = self.model.game_state.getObjectById("PlayerCharacter") |
86
a9cc5559ec2a
Move the identifier field from the FifeAgent component to the new General component.
KarstenBock@gmx.net
parents:
82
diff
changeset
|
444 is_player = obj.general.identifier == player.general.identifier |
51
d3a9caba067b
Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
445 |
57
ba85e5aff370
Removed the pos value from the fifeagent component. getItemActions of Gamescenecontroller gets the position by calling a method of the behaviour.
KarstenBock@gmx.net
parents:
53
diff
changeset
|
446 |
51
d3a9caba067b
Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
447 #TODO: Check all actions to be compatible with the grease components |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
448 if obj is not None: |
53
7b9f6e3513d4
Added code that checks if the object is the player so certain actions (talk, attack) will not appear in the menu.
KarstenBock@gmx.net
parents:
51
diff
changeset
|
449 if obj.dialogue and not is_player: |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
450 actions.append(["Talk", "Talk", self.initTalk, obj]) |
53
7b9f6e3513d4
Added code that checks if the object is the player so certain actions (talk, attack) will not appear in the menu.
KarstenBock@gmx.net
parents:
51
diff
changeset
|
451 if obj.characterstats and not is_player: |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
452 actions.append(["Attack", "Attack", self.nullFunc, obj]) |
82
e864b704dd59
The Examine action in the context menu will now only be shown when the Entity actually has a description text.
KarstenBock@gmx.net
parents:
81
diff
changeset
|
453 if obj.description and obj.description.desc: |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
454 actions.append(["Examine", "Examine", |
51
d3a9caba067b
Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
455 player.fifeagent.behaviour.approach, |
57
ba85e5aff370
Removed the pos value from the fifeagent component. getItemActions of Gamescenecontroller gets the position by calling a method of the behaviour.
KarstenBock@gmx.net
parents:
53
diff
changeset
|
456 [obj_pos.x, obj_pos.y], |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
457 ExamineAction(self, |
51
d3a9caba067b
Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
458 obj_id, obj.description.view_name, |
d3a9caba067b
Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
459 obj.description.desc)]) |
81
28561412c7e7
Fixed bug in "getItemActions" when the Entity has a change_map component.
KarstenBock@gmx.net
parents:
57
diff
changeset
|
460 |
51
d3a9caba067b
Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
461 if obj.change_map: |
d3a9caba067b
Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
462 actions.append(["Change Map", "Change Map", |
d3a9caba067b
Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
463 player.fifeagent.behaviour.approach, |
57
ba85e5aff370
Removed the pos value from the fifeagent component. getItemActions of Gamescenecontroller gets the position by calling a method of the behaviour.
KarstenBock@gmx.net
parents:
53
diff
changeset
|
464 [obj_pos.x, obj_pos.y], |
81
28561412c7e7
Fixed bug in "getItemActions" when the Entity has a change_map component.
KarstenBock@gmx.net
parents:
57
diff
changeset
|
465 ChangeMapAction(self, obj.change_map.target_map, |
28561412c7e7
Fixed bug in "getItemActions" when the Entity has a change_map component.
KarstenBock@gmx.net
parents:
57
diff
changeset
|
466 obj.change_map.target_position)]) |
51
d3a9caba067b
Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
467 |
d3a9caba067b
Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
468 if obj.lockable: |
104
c9afad46091b
Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents:
101
diff
changeset
|
469 if obj.lockable.closed: |
c9afad46091b
Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents:
101
diff
changeset
|
470 actions.append(["Open", "Open", |
c9afad46091b
Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents:
101
diff
changeset
|
471 player.fifeagent.behaviour.approach, |
c9afad46091b
Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents:
101
diff
changeset
|
472 [obj_pos.x, obj_pos.y], |
c9afad46091b
Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents:
101
diff
changeset
|
473 OpenAction(self, obj)]) |
c9afad46091b
Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents:
101
diff
changeset
|
474 else: |
c9afad46091b
Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents:
101
diff
changeset
|
475 actions.append(["Close", "Close", |
c9afad46091b
Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents:
101
diff
changeset
|
476 player.fifeagent.behaviour.approach, |
c9afad46091b
Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents:
101
diff
changeset
|
477 [obj_pos.x, obj_pos.y], |
c9afad46091b
Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents:
101
diff
changeset
|
478 CloseAction(self, obj)]) |
c9afad46091b
Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents:
101
diff
changeset
|
479 if obj.lockable.locked: |
c9afad46091b
Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents:
101
diff
changeset
|
480 actions.append(["Unlock", "Unlock", |
c9afad46091b
Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents:
101
diff
changeset
|
481 player.fifeagent.behaviour.approach, |
c9afad46091b
Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents:
101
diff
changeset
|
482 [obj_pos.x, obj_pos.y], |
c9afad46091b
Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents:
101
diff
changeset
|
483 UnlockAction(self, obj)]) |
c9afad46091b
Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents:
101
diff
changeset
|
484 else: |
c9afad46091b
Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents:
101
diff
changeset
|
485 actions.append(["Lock", "Lock", |
c9afad46091b
Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents:
101
diff
changeset
|
486 player.fifeagent.behaviour.approach, |
c9afad46091b
Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents:
101
diff
changeset
|
487 [obj_pos.x, obj_pos.y], |
c9afad46091b
Added actions for lockable components (Open, Close, Lock and Unlock).
KarstenBock@gmx.net
parents:
101
diff
changeset
|
488 LockAction(self, obj)]) |
51
d3a9caba067b
Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
489 if obj.containable: |
d3a9caba067b
Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
490 actions.append(["Pick Up", "Pick Up", |
d3a9caba067b
Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
491 player.fifeagent.behaviour.approach, |
57
ba85e5aff370
Removed the pos value from the fifeagent component. getItemActions of Gamescenecontroller gets the position by calling a method of the behaviour.
KarstenBock@gmx.net
parents:
53
diff
changeset
|
492 [obj_pos.x, obj_pos.y], |
51
d3a9caba067b
Modifications to make talking with npcs possible again. Special actions won't work yet though.
KarstenBock@gmx.net
parents:
44
diff
changeset
|
493 PickUpAction(self, obj)]) |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
494 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
495 return actions |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
496 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
497 def saveGame(self, *args, **kwargs): |
101 | 498 """Saves the game state, delegates call to gamemodel.GameModel |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
499 @return: None""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
500 self.model.pause(False) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
501 self.pause(False) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
502 self.view.hud.enabled = True |
101 | 503 self.model.updateObjectDB(self) |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
504 self.model.save(*args, **kwargs) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
505 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
506 def loadGame(self, *args, **kwargs): |
101 | 507 """Loads the game state, delegates call to gamemodel.GameModel |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
508 @return: None""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
509 # Remove all currently loaded maps so we can start fresh |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
510 self.model.pause(False) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
511 self.pause(False) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
512 self.view.hud.enabled = True |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
513 self.model.deleteMaps() |
101 | 514 for entity in self.entities.copy(): |
515 entity.delete() | |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
516 self.view.hud.inventory = None |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
517 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
518 self.model.load(*args, **kwargs) |
101 | 519 # Load the current map |
520 if self.model.game_state.current_map_name: | |
521 self.model.loadMap(self.model.game_state.current_map_name) | |
522 self.model.placeAgents(self) | |
523 self.model.placePC(self) | |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
524 self.view.hud.initializeInventory() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
525 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
526 def quitGame(self): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
527 """Quits the game |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
528 @return: None""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
529 self.application.listener.quitGame() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
530 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
531 def pause(self, paused): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
532 """Pauses the controller""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
533 super(GameSceneController, self).pause(paused) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
534 self.paused = paused |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
535 if paused: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
536 self.scroll_timer.stop() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
537 self.resetMouseCursor() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
538 |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
539 def onCommand(self, command): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
540 if(command.getCommandType() == fife.CMD_MOUSE_FOCUS_GAINED): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
541 self.has_mouse_focus = True |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
542 elif(command.getCommandType() == fife.CMD_MOUSE_FOCUS_LOST): |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
543 self.has_mouse_focus = False |
4 | 544 |
8
708a6f651c31
Modifications to use the grease manager and modes
KarstenBock@gmx.net
parents:
4
diff
changeset
|
545 def pump(self, dt): |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
546 """Routine called during each frame. Our main loop is in ./run.py""" |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
547 # uncomment to instrument |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
548 # t0 = time.time() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
549 if self.paused: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
550 return |
8
708a6f651c31
Modifications to use the grease manager and modes
KarstenBock@gmx.net
parents:
4
diff
changeset
|
551 ControllerBase.pump(self, dt) |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
552 self.updateMouse() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
553 if self.model.active_map: |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
554 self.view.highlightFrontObject(self.last_mousecoords) |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
555 self.view.refreshTopLayerTransparencies() |
4 | 556 self.handleScrolling() |
0
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
557 self.handleCommands() |
7a89ea5404b1
Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff
changeset
|
558 # print "%05f" % (time.time()-t0,) |