annotate src/parpg/gamescenecontroller.py @ 192:191f89a22303

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