Mercurial > parpg-source
view gamesceneview.py @ 1:4912a6f97c52
Various improvements to the build process including support for self-contained builds.
* Note that despite all of these changes PARPG still does not run because asset paths are not standardized,
* Modified the SCons script so that by default running `scons` with no arguments creates a self-contained "build" under a build subdirectory to make in-source testing easier. To install PARPG, use `scons install` instead.
* Got rid of the binary launcher and replaced it with a shell script for unix and a batch script for Windows (batch script is untested). The binary turned out to be too much trouble to maintain.
* Modified the parpg.settings module and parpg.main entry script so that PARPG searches through several default search paths for configuration file(s). PARPG thus no longer crashes if it can't find a configuration file in any particular search path, but will crash it if can't find any configuration files.
* Paths supplied to parpg.main are now appended as search paths for the configuration file(s).
* Changed the default configuration file name to "parpg.cfg" to simplify searches.
* Created the site_scons directory tree where SCons extensions and tools should be placed.
* Created a new SCons builder, CopyRecurse, which can copy only certain files and folders from a directory tree using filters (files and folders that start with a leading dot "." e.g. ".svn" are ignored by default).
* Added the CPython SCons tool (stands for Compile-Python - I didn't name it!), which provides the InstallPython builder for pre-compiling python sources before they are installed. However, it is currently broken and only installs the python sources.
author | M. George Hansen <technopolitica@gmail.com> |
---|---|
date | Tue, 31 May 2011 02:46:20 -0700 |
parents | 7a89ea5404b1 |
children | 98f26f7636d8 |
line wrap: on
line source
# This file is part of PARPG. # PARPG is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # PARPG is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with PARPG. If not, see <http://www.gnu.org/licenses/>. from sounds import SoundEngine from viewbase import ViewBase from fife import fife class GameSceneView(ViewBase): """GameSceneView is responsible for drawing the scene""" def __init__(self, engine, model): """Constructor for GameSceneView @param engine: A fife.Engine instance @type engine: fife.Engine @param model: a script.GameModel instance @type model: script.GameModel """ super(GameSceneView, self).__init__(engine, model) # init the sound self.sounds = SoundEngine(engine) self.hud = None # The current highlighted object self.highlight_obj = None # faded objects in top layer self.faded_objects = set() def displayObjectText(self, obj_id, text, time=1000): """Display on screen the text of the object over the object. @type obj_id: id of fife.instance @param obj: id of object to draw over @type text: String @param text: text to display over object @return: None""" try: if obj_id: obj = self.model.active_map.agent_layer.getInstance(obj_id) else: obj = None except RuntimeError as error: if error.args[0].split(',')[0].strip() == "_[NotFound]_": obj = None else: raise if obj: obj.say(str(text), time) def onWalk(self, click): """Callback sample for the context menu.""" self.hud.hideContainer() self.model.game_state.player_character.run(click) def refreshTopLayerTransparencies(self): """Fade or unfade TopLayer instances if the PlayerCharacter is under them.""" if not self.model.active_map: return # get the PlayerCharacter's screen coordinates camera = self.model.active_map.cameras[self.model.active_map.my_cam_id] point = self.model.game_state.player_character.\ behaviour.agent.getLocation() scr_coords = camera.toScreenCoordinates(point.getMapCoordinates()) # find all instances on TopLayer that fall on those coordinates instances = camera.getMatchingInstances(scr_coords, self.model.active_map.top_layer) instance_ids = [ instance.getId() for instance in instances ] faded_objects = self.faded_objects # fade instances for instance_id in instance_ids: if instance_id not in faded_objects: faded_objects.add(instance_id) self.model.active_map.top_layer.getInstance(instance_id).\ get2dGfxVisual().setTransparency(128) # unfade previously faded instances for instance_id in faded_objects.copy(): if instance_id not in instance_ids: faded_objects.remove(instance_id) self.model.active_map.top_layer.getInstance(instance_id).\ get2dGfxVisual().setTransparency(0) #def removeHighlight(self): def highlightFrontObject(self, mouse_coords): """Highlights the object that is at the current mouse coordinates""" if not self.model.active_map: return if mouse_coords: front_obj = self.model.getObjectAtCoords(mouse_coords) if front_obj != None: if self.highlight_obj == None \ or front_obj.getId() != \ self.highlight_obj: if self.model.game_state.hasObject(front_obj.getId()): self.displayObjectText(self.highlight_obj, "") self.model.active_map.outline_renderer.removeAllOutlines() self.highlight_obj = front_obj.getId() self.model.active_map.outline_renderer.addOutlined( front_obj, 0, 137, 255, 2) # get the text item = self.model.objectActive(self.highlight_obj) if item is not None: self.displayObjectText(self.highlight_obj, item.name) else: self.model.active_map.outline_renderer.removeAllOutlines() self.highlight_obj = None def moveCamera(self, direction): """Move the camera in the given direction. @type direction: list of two integers @param direction: the two integers can be 1, -1, or 0 @return: None """ if 'cameras' in dir(self.model.active_map): cam = self.model.active_map.cameras[self.model.active_map.my_cam_id] location = cam.getLocation() position = location.getMapCoordinates() #how many pixls to move by each call move_by = 1 #create a new DoublePoint3D and add it to position DoublePoint3D new_x, new_y = move_by * direction[0], move_by * direction[1] position_offset = fife.DoublePoint3D(int(new_x), int(new_y)) position += position_offset #give location the new position location.setMapCoordinates(position) #detach the camera from any objects cam.detach() #move the camera to the new location cam.setLocation(location)