source: trunk/game/scripts/gamesceneview.py @ 553

Revision 553, 4.8 KB checked in by beliar, 10 years ago (diff)

Merged changes from code-cleanup-and-refactoring back into the trunk.

  • Property svn:eol-style set to native
RevLine 
[26]1#!/usr/bin/python
2
[30]3#   This file is part of PARPG.
[26]4
[30]5#   PARPG is free software: you can redistribute it and/or modify
6#   it under the terms of the GNU General Public License as published by
7#   the Free Software Foundation, either version 3 of the License, or
8#   (at your option) any later version.
[26]9
[30]10#   PARPG is distributed in the hope that it will be useful,
11#   but WITHOUT ANY WARRANTY; without even the implied warranty of
12#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13#   GNU General Public License for more details.
[26]14
[30]15#   You should have received a copy of the GNU General Public License
[35]16#   along with PARPG.  If not, see <http://www.gnu.org/licenses/>.
[26]17
[550]18from sounds import SoundEngine
[552]19from viewbase import ViewBase
[26]20
[552]21class GameSceneView(ViewBase):
22    """GameSceneView is responsible for drawing the scene"""
23    def __init__(self, engine, model):
[104]24        """Constructor for engine
[552]25           @param engine: A fife.Engine instance
[141]26           @type engine: fife.Engine
[552]27           @param model: a script.GameModel instance
28           @type model: script.GameModel
29           """
30        super(GameSceneView, self).__init__(engine, model)
[361]31
32        self.action_number = 1
33
34        # init the sound
35        self.sounds = SoundEngine(engine)
36
[550]37        self.hud = None       
[361]38
39        # The current highlighted object
40        self.highlight_obj = None
[549]41     
[412]42        # faded objects in top layer
43        self.faded_objects = set()
44
[77]45    def displayObjectText(self, obj, text):
[141]46        """Display on screen the text of the object over the object.
47           @type obj: fife.instance
48           @param obj: object to draw over
[340]49           @type text: String
[141]50           @param text: text to display over object
51           @return: None"""
[120]52        obj.say(str(text), 1000)
[77]53
[150]54    def onWalk(self, click):
[277]55        """Callback sample for the context menu."""
[270]56        self.hud.hideContainer()
[552]57        self.engine.getModel().game_state.PlayerCharacter.run(click)
[115]58
[549]59    def refreshTopLayerTransparencies(self):
[552]60        """Fade or unfade TopLayer instances if the PlayerCharacter
61        is under them."""
62        # get the PlayerCharacter's screen coordinates
63        camera = self.model.active_map.cameras[self.model.active_map.my_cam_id]
64        point = self.model.game_state.PlayerCharacter.\
65                                        behaviour.agent.getLocation()
[412]66        scr_coords = camera.toScreenCoordinates(point.getMapCoordinates())
67
68        # find all instances on TopLayer that fall on those coordinates
69        instances = camera.getMatchingInstances(scr_coords,
[552]70                        self.model.active_map.top_layer)
[412]71        instance_ids = [ instance.getId() for instance in instances ]
72        faded_objects = self.faded_objects
73
74        # fade instances
75        for instance_id in instance_ids:
76            if instance_id not in faded_objects:
77                faded_objects.add(instance_id)
[552]78                self.model.active_map.top_layer.getInstance(instance_id).\
[549]79                        get2dGfxVisual().setTransparency(128)
[412]80
81        # unfade previously faded instances
82        for instance_id in faded_objects.copy():
83            if instance_id not in instance_ids:
84                faded_objects.remove(instance_id)
[552]85                self.model.active_map.top_layer.getInstance(instance_id).\
[412]86                        get2dGfxVisual().setTransparency(0)
87
[338]88
[549]89    def highlightFrontObject(self, mouse_coords):
[552]90        """Highlights the object that is at the
91        current mouse coordinates"""       
[549]92        if mouse_coords:
[552]93            front_obj = self.model.getObjectAtCoords(mouse_coords)
[549]94            if front_obj != None:
95                if self.highlight_obj == None \
96                            or front_obj.getId() != \
97                            self.highlight_obj.getId():
98                    if self.highlight_obj:
99                        self.displayObjectText(self.highlight_obj,"")
[552]100                    self.model.active_map.outline_renderer.removeAllOutlines()
[549]101                    self.highlight_obj = front_obj
[552]102                    self.model.active_map.outline_renderer.addOutlined(
[549]103                                                    self.highlight_obj, 
104                                                    0,
105                                                    137, 255, 2)
106                    # get the text
[552]107                    item = self.model.objectActive(
[549]108                                                    self.highlight_obj.getId())
109                    if item is not None:
110                        self.displayObjectText(self.highlight_obj, 
111                                                    item.name)
112            else:
113                if self.highlight_obj:
114                    self.displayObjectText(self.highlight_obj,"")
[552]115                self.model.active_map.outline_renderer.removeAllOutlines()
[550]116                self.highlight_obj = None 
117           
Note: See TracBrowser for help on using the repository browser.