annotate gamescenecontroller.py @ 14:a9019d0ac5f8

Added system for containers
author KarstenBock@gmx.net
date Sun, 31 Jul 2011 23:47:28 +0200
parents 708a6f651c31
children 3011bc71ab20
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
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
23
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
24 from fife import fife
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
25 from fife import extensions
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
26
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
27 from controllerbase import ControllerBase
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
28 from parpg.gui.hud import Hud
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
29 from parpg.gui import drag_drop_data as data_drag
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
30 from objects.action import ChangeMapAction, ExamineAction, OpenBoxAction, \
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
31 UnlockBoxAction, LockBoxAction, TalkAction, \
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
32 PickUpAction, DropItemAction
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
33
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
34 #For debugging/code analysis
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
35 if False:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
36 from gamesceneview import GameSceneView
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
37 from gamemodel import GameModel
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
38 from parpg import PARPGApplication
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
39
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
40 import logging
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
41
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
42 logger = logging.getLogger('gamescenecontroller')
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 class GameSceneController(ControllerBase):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
45 '''
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
46 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
47 "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
48 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
49 '''
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
50
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
51
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
52 def __init__(self, engine, view, model, application):
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 Constructor
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
55 @param engine: Instance of the active fife engine
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
56 @type engine: fife.Engine
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
57 @param view: Instance of a GameSceneView
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
58 @param type: parpg.GameSceneView
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
59 @param model: The model that has the current gamestate
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
60 @type model: parpg.GameModel
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
61 @param application: The application that created this controller
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
62 @type application: parpg.PARPGApplication
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
63 @param settings: The current settings of the application
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
64 @type settings: fife.extensions.fife_settings.Setting
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
65 '''
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
66 ControllerBase.__init__(self,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
67 engine,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
68 view,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
69 model,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
70 application)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
71 #this can be helpful for IDEs code analysis
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
72 if False:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
73 assert(isinstance(self.engine, fife.Engine))
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
74 assert(isinstance(self.view, GameSceneView))
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
75 assert(isinstance(self.view, GameModel))
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
76 assert(isinstance(self.application, PARPGApplication))
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
77 assert(isinstance(self.event_manager, fife.EventManager))
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
78
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
79 # Last saved mouse coords
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
80 self.action_number = 1
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
81
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
82 self.has_mouse_focus = True
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
83 self.last_mousecoords = None
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
84 self.mouse_callback = None
4
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
85 self.original_cursor_id = self.engine.getCursor().getId()
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
86 self.scroll_data = {"mouse":[], "kb":[], "offset":[0,0]}
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
87 self.scroll_timer = extensions.fife_timer.Timer(
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
88 100,
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
89 lambda: self.view.moveCamera(self.scroll_data["offset"]),
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
90 )
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
91
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
92 #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
93 self.resetMouseCursor()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
94 self.paused = False
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 if model.settings.fife.EnableSound:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
97 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
98 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
99 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
100 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
101 )
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
102 self.view.sounds.playMusic(music_file)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
103 self.initHud()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
104
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
105
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
106 def initHud(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
107 """Initialize the hud member
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
108 @return: None"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
109 hud_callbacks = {
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
110 'saveGame': self.saveGame,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
111 'loadGame': self.loadGame,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
112 'quitGame': self.quitGame,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
113 }
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
114 self.view.hud = Hud(self,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
115 self.model.settings,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
116 hud_callbacks)
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 def keyPressed(self, evt):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
119 """Whenever a key is pressed, fife calls this routine.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
120 @type evt: fife.event
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
121 @param evt: The event that fife caught
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
122 @return: None"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
123 key = evt.getKey()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
124 key_val = key.getValue()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
125
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
126 if(key_val == key.Q):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
127 # we need to quit the game
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
128 self.view.hud.quitGame()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
129 if(key_val == key.T):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
130 self.model.active_map.toggleRenderer('GridRenderer')
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
131 if(key_val == key.F1):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
132 # display the help screen and pause the game
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
133 self.view.hud.displayHelp()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
134 if(key_val == key.F5):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
135 self.model.active_map.toggleRenderer('CoordinateRenderer')
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
136 if(key_val == key.F7):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
137 # F7 saves a screenshot to screenshots directory
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
138
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
139 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
140 # 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
141 # correctly atm.
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
142 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
143 'screenshots')
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
144 # try to create the screenshots directory
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
145 try:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
146 os.mkdir(screenshot_directory)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
147 #TODO: distinguish between already existing permissions error
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
148 except OSError:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
149 logger.warning("screenshot directory wasn't created.")
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
150
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
151 screenshot_file = os.path.join(screenshot_directory,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
152 'screen-{0}.png'.format(
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
153 datetime.now().strftime(
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
154 '%Y-%m-%d-%H-%M-%S')))
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
155 self.engine.getRenderBackend().captureScreen(screenshot_file)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
156 logger.info("PARPG: Saved: {0}".format(screenshot_file))
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
157 if(key_val == key.F10):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
158 # F10 shows/hides the console
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
159 self.engine.getGuiManager().getConsole().toggleShowHide()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
160 if(key_val == key.C):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
161 # C opens and closes the character screen.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
162 self.view.hud.toggleCharacterScreen()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
163 if(key_val == key.I):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
164 # I opens and closes the inventory
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
165 self.view.hud.toggleInventory()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
166 if(key_val == key.A):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
167 # A adds a test action to the action box
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
168 # The test actions will follow this format: Action 1,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
169 # Action 2, etc.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
170 self.view.hud.addAction("Action " + str(self.action_number))
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
171 self.action_number += 1
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
172 if(key_val == key.ESCAPE):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
173 # Escape brings up the main menu
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
174 self.view.hud.displayMenu()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
175 # Hide the quit menu
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
176 self.view.hud.quit_window.hide()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
177 if(key_val == key.M):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
178 self.view.sounds.toggleMusic()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
179 if(key_val == key.PAUSE):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
180 # Pause pause/unpause the game
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
181 self.model.togglePause()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
182 self.pause(False)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
183 if(key_val == key.SPACE):
4
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
184 self.model.active_map.centerCameraOnPlayer()
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
185
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
186 #alter scroll data if a directional key is hit
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
187 if(key_val == key.UP):
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
188 if not "up" in self.scroll_data["kb"]:
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
189 self.scroll_data["kb"].append("up")
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
190
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
191 if(key_val == key.RIGHT):
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
192 if not "right" in self.scroll_data["kb"]:
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
193 self.scroll_data["kb"].append("right")
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
194
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
195 if(key_val == key.DOWN):
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
196 if not "down" in self.scroll_data["kb"]:
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
197 self.scroll_data["kb"].append("down")
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
198
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
199 if(key_val == key.LEFT):
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
200 if not "left" in self.scroll_data["kb"]:
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
201 self.scroll_data["kb"].append("left")
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
202
4
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
203 def keyReleased(self, evt):
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
204 """Whenever a key is pressed, fife calls this routine.
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
205 @type evt: fife.event
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
206 @param evt: The event that fife caught
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
207 @return: None"""
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
208 key = evt.getKey()
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
209 key_val = key.getValue()
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
210
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
211 #alter scroll data if a directional key is released
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
212 if(key_val == key.UP):
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
213 if "up" in self.scroll_data["kb"]:
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
214 self.scroll_data["kb"].remove("up")
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
215
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
216 if(key_val == key.RIGHT):
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
217 if "right" in self.scroll_data["kb"]:
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
218 self.scroll_data["kb"].remove("right")
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
219
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
220 if(key_val == key.DOWN):
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
221 if "down" in self.scroll_data["kb"]:
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
222 self.scroll_data["kb"].remove("down")
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
223
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
224 if(key_val == key.LEFT):
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
225 if "left" in self.scroll_data["kb"]:
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
226 self.scroll_data["kb"].remove("left")
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
227
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
228 def mouseReleased(self, evt):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
229 """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
230 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
231 pychan captures the release if a menu is opened.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
232 @type evt: fife.event
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
233 @param evt: The event that fife caught
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
234 @return: None"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
235 self.view.hud.hideContextMenu()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
236 scr_point = fife.ScreenPoint(evt.getX(), evt.getY())
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
237 if(evt.getButton() == fife.MouseEvent.LEFT):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
238 if(data_drag.dragging):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
239 coord = self.model.getCoords(scr_point)\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
240 .getExactLayerCoordinates()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
241 commands = ({"Command": "ResetMouseCursor"},
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
242 {"Command": "StopDragging"})
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
243 self.model.game_state.player_character.approach([coord.x,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
244 coord.y],
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
245 DropItemAction(self,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
246 data_drag.dragged_item,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
247 commands))
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
248 else:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
249 self.model.movePlayer(self.model.getCoords(scr_point))
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
250 elif(evt.getButton() == fife.MouseEvent.RIGHT):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
251 # is there an object here?
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
252 tmp_active_map = self.model.active_map
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
253 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
254 getMatchingInstances(scr_point,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
255 tmp_active_map.agent_layer)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
256 info = None
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
257 for inst in instances:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
258 # check to see if this is an active item
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
259 if(self.model.objectActive(inst.getId())):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
260 # yes, get the model
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
261 info = self.getItemActions(inst.getId())
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
262 break
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
263
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
264 # 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
265 # default menu if no items
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
266 data = info or \
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
267 [["Walk", "Walk here", self.view.onWalk,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
268 self.model.getCoords(scr_point)]]
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
269 # show the menu
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
270 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
271
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
272
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
273 def updateMouse(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
274 """Updates the mouse values"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
275 if self.paused:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
276 return
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
277 cursor = self.engine.getCursor()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
278 #this can be helpful for IDEs code analysis
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
279 if False:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
280 assert(isinstance(cursor, fife.Cursor))
4
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
281 self.last_mousecoords = fife.ScreenPoint(cursor.getX(), cursor.getY())
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
282 self.view.highlightFrontObject(self.last_mousecoords)
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
283
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
284 #set the trigger area in pixles
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
285 pixle_edge = 20
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
286
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
287 mouse_x = self.last_mousecoords.x
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
288 screen_width = self.model.engine.getSettings().getScreenWidth()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
289 mouse_y = self.last_mousecoords.y
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
290 screen_height = self.model.engine.getSettings().getScreenHeight()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
291
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
292 image = None
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
293 settings = self.model.settings
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
294
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 #edge logic
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
297 if self.has_mouse_focus:
4
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
298 direction = self.scroll_data["mouse"] = []
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
299
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
300 #up
4
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
301 if mouse_y <= pixle_edge:
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
302 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
303 image = '/'.join(['gui/cursors', settings.parpg.CursorUp])
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
304
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
305 #right
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
306 if mouse_x >= screen_width - pixle_edge:
4
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
307 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
308 image = '/'.join(['gui/cursors', settings.parpg.CursorRight])
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
309
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
310 #down
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
311 if mouse_y >= screen_height - pixle_edge:
4
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
312 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
313 image = '/'.join(['gui/cursors', settings.parpg.CursorDown])
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
314
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
315 #left
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
316 if mouse_x <= pixle_edge:
4
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
317 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
318 image = '/'.join(['gui/cursors', settings.parpg.CursorLeft])
4
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
319
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
320 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
321 self.setMouseCursor(image, image)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
322
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
323
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
324 def handleCommands(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
325 """Check if a command is to be executed
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 if self.model.map_change:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
328 self.pause(True)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
329 if self.model.active_map:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
330 player_char = self.model.game_state.player_character
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
331 self.model.game_state.player_character = None
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
332 pc_agent = self.model.agents[self.model.ALL_AGENTS_KEY]\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
333 ["PlayerCharacter"]
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
334 pc_agent.update(player_char.getStateForSaving())
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
335 pc_agent["Map"] = self.model.target_map_name
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
336 pc_agent["Position"] = self.model.target_position
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
337 pc_agent["Inventory"] = \
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
338 player_char.inventory.serializeInventory()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
339 player_agent = self.model.active_map.\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
340 agent_layer.getInstance("PlayerCharacter")
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
341 self.model.active_map.agent_layer.deleteInstance(player_agent)
2
06145a6ee387 Fixed resource path dependencies issue that caused PARPG to crash on start.
M. George Hansen <technopolitica@gmail.com>
parents: 0
diff changeset
342
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
343 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
344
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
345 self.model.setActiveMap(self.model.target_map_name)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
346 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
347
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
348 self.model.placeAgents()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
349 self.model.placePC()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
350 self.model.map_change = False
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
351 # The PlayerCharacter has an inventory, and also some
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
352 # filling of the ready slots in the HUD.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
353 # 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
354 # with the contents of the inventory.
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
355 self.view.hud.inventory = None
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
356 self.view.hud.initializeInventory()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
357 self.pause(False)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
358
4
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
359 def handleScrolling(self):
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
360 """
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
361 Merge kb and mouse related scroll data, limit the speed and
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
362 move the camera.
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
363 """
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
364 #this is how many pxls the camera is moved in one time frame
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
365 scroll_offset = self.scroll_data["offset"] = [0,0]
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
366
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
367 mouse = self.scroll_data["mouse"]
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
368 keyboard = self.scroll_data["kb"]
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
369 speed = self.model.settings.parpg.ScrollSpeed
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
370
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
371 #adds a value to the offset depending on the contents of each
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
372 # of the controllers: set() removes doubles
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
373 scroll_direction = set(mouse+keyboard)
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
374 for direction in scroll_direction:
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
375 if direction == "up":
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
376 scroll_offset[0] +=1
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
377 scroll_offset[1] -=1
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
378 elif direction == "right":
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
379 scroll_offset[0] +=1
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
380 scroll_offset[1] +=1
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
381 elif direction == "down":
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
382 scroll_offset[0] -=1
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
383 scroll_offset[1] +=1
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
384 elif direction == "left":
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
385 scroll_offset[0] -=1
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
386 scroll_offset[1] -=1
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
387
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
388 #keep the speed within bounds
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
389 if scroll_offset[0] > 0: scroll_offset[0] = speed
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
390 if scroll_offset[0] < 0: scroll_offset[0] = -speed
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
391
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
392 if scroll_offset[1] > 0: scroll_offset[1] = speed
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
393 if scroll_offset[1] < 0: scroll_offset[1] = -speed
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
394
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
395 #de/activate scrolling
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
396 if scroll_offset != [0, 0]:
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
397 self.scroll_timer.start()
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
398 else:
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
399 self.scroll_timer.stop()
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
400 if not data_drag.dragging:
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
401 self.resetMouseCursor()
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
402
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
403 def nullFunc(self, userdata):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
404 """Sample callback for the context menus."""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
405 logger.info(userdata)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
406
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
407 def initTalk(self, npc_info):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
408 """ Starts the PlayerCharacter talking to an NPC. """
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
409 # 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
410 # out
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
411 npc = self.model.game_state.getObjectById(npc_info.ID,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
412 self.model.game_state.\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
413 current_map_name)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
414 self.model.game_state.player_character.approach([npc.getLocation().\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
415 getLayerCoordinates().x,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
416 npc.getLocation().\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
417 getLayerCoordinates().y],
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
418 TalkAction(self, npc))
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
419
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
420 def getItemActions(self, obj_id):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
421 """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
422 @type obj_id: string
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
423 @param obj_id: ID of object
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
424 @rtype: list
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
425 @return: List of text and callbacks"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
426 actions = []
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
427 # note: ALWAYS check NPC's first!
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
428 obj = self.model.game_state.\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
429 getObjectById(obj_id,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
430 self.model.game_state.current_map_name)
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 if obj is not None:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
433 if obj.trueAttr("NPC"):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
434 # keep it simple for now, None to be replaced by callbacks
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
435 actions.append(["Talk", "Talk", self.initTalk, obj])
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
436 actions.append(["Attack", "Attack", self.nullFunc, obj])
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
437 else:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
438 actions.append(["Examine", "Examine",
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
439 self.model.game_state.\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
440 player_character.approach,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
441 [obj.X, obj.Y],
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
442 ExamineAction(self,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
443 obj_id, obj.name,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
444 obj.text)])
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
445 # is it a Door?
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
446 if obj.trueAttr("door"):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
447 actions.append(["Change Map", "Change Map",
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
448 self.model.game_state.player_character.approach,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
449 [obj.X, obj.Y],
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
450 ChangeMapAction(self, obj.target_map_name,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
451 obj.target_pos)])
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
452 # is it a container?
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
453 if obj.trueAttr("container"):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
454 actions.append(["Open", "Open",
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
455 self.model.game_state.\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
456 player_character.approach,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
457 [obj.X, obj.Y],
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
458 OpenBoxAction(self, obj)])
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
459 actions.append(["Unlock", "Unlock",
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
460 self.model.game_state.\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
461 player_character.approach,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
462 [obj.X, obj.Y],
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
463 UnlockBoxAction(self, obj)])
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
464 actions.append(["Lock", "Lock",
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
465 self.model.game_state.\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
466 player_character.approach,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
467 [obj.X, obj.Y],
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
468 LockBoxAction(self, obj)])
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
469 # can you pick it up?
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
470 if obj.trueAttr("carryable"):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
471 actions.append(["Pick Up", "Pick Up",
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
472 self.model.game_state.\
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
473 player_character.approach,
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
474 [obj.X, obj.Y],
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
475 PickUpAction(self, obj)])
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
476
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
477 return actions
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
478
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
479 def saveGame(self, *args, **kwargs):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
480 """Saves the game state, delegates call to engine.Engine
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
481 @return: None"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
482 self.model.pause(False)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
483 self.pause(False)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
484 self.view.hud.enabled = True
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
485 self.model.save(*args, **kwargs)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
486
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
487 def loadGame(self, *args, **kwargs):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
488 """Loads the game state, delegates call to engine.Engine
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
489 @return: None"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
490 # 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
491 self.model.pause(False)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
492 self.pause(False)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
493 self.view.hud.enabled = True
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
494 self.model.deleteMaps()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
495 self.view.hud.inventory = None
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 self.model.load(*args, **kwargs)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
498 self.view.hud.initializeInventory()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
499
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
500 def quitGame(self):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
501 """Quits the game
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
502 @return: None"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
503 self.application.listener.quitGame()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
504
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
505 def pause(self, paused):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
506 """Pauses the controller"""
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
507 super(GameSceneController, self).pause(paused)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
508 self.paused = paused
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
509 if paused:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
510 self.scroll_timer.stop()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
511 self.resetMouseCursor()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
512
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
513 def onCommand(self, command):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
514 if(command.getCommandType() == fife.CMD_MOUSE_FOCUS_GAINED):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
515 self.has_mouse_focus = True
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
516 elif(command.getCommandType() == fife.CMD_MOUSE_FOCUS_LOST):
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
517 self.has_mouse_focus = False
4
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
518
8
708a6f651c31 Modifications to use the grease manager and modes
KarstenBock@gmx.net
parents: 4
diff changeset
519 def pump(self, dt):
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
520 """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
521 # uncomment to instrument
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
522 # t0 = time.time()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
523 if self.paused:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
524 return
8
708a6f651c31 Modifications to use the grease manager and modes
KarstenBock@gmx.net
parents: 4
diff changeset
525 ControllerBase.pump(self, dt)
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
526 self.updateMouse()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
527 if self.model.active_map:
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
528 self.view.highlightFrontObject(self.last_mousecoords)
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
529 self.view.refreshTopLayerTransparencies()
4
bf1dd9c24a7e Scrolling by keyboard is now possible.
DomtronVox
parents: 2
diff changeset
530 self.handleScrolling()
0
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
531 self.handleCommands()
7a89ea5404b1 Initial commit of parpg-core.
M. George Hansen <technopolitica@gmail.com>
parents:
diff changeset
532 # print "%05f" % (time.time()-t0,)