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

Revision 583, 4.9 KB checked in by beliar, 9 years ago (diff)

Patch by Beliar.

  • Made the shebang the same in all files
  • Added ContainerGuiBase?, a base class for guis that show container contents
  • Moved ContainerGui? from scripts.gui.popups to a new file
  • ContainerGui? and InventoryGui? now have ContainerGuiBase? as base class
  • If an item is taken out of an inventory the item will now be deleted from item_lookup instead of being set to None. That fixes an bug where items taken out of the inventory could not be moved back in.
  • Property svn:eol-style set to native
Line 
1#!/usr/bin/env python # pylint: disable-msg=C0111
2
3#   This file is part of PARPG.
4
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.
9
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.
14
15#   You should have received a copy of the GNU General Public License
16#   along with PARPG.  If not, see <http://www.gnu.org/licenses/>.
17
18from sounds import SoundEngine
19from viewbase import ViewBase
20
21class GameSceneView(ViewBase):
22    """GameSceneView is responsible for drawing the scene"""
23    def __init__(self, engine, model):
24        """Constructor for engine
25           @param engine: A fife.Engine instance
26           @type engine: fife.Engine
27           @param model: a script.GameModel instance
28           @type model: script.GameModel
29           """
30        super(GameSceneView, self).__init__(engine, model)
31
32        self.action_number = 1
33
34        # init the sound
35        self.sounds = SoundEngine(engine)
36
37        self.hud = None       
38
39        # The current highlighted object
40        self.highlight_obj = None
41     
42        # faded objects in top layer
43        self.faded_objects = set()
44
45    def displayObjectText(self, obj, text):
46        """Display on screen the text of the object over the object.
47           @type obj: fife.instance
48           @param obj: object to draw over
49           @type text: String
50           @param text: text to display over object
51           @return: None"""
52        obj.say(str(text), 1000)
53
54    def onWalk(self, click):
55        """Callback sample for the context menu."""
56        self.hud.hideContainer()
57        self.model.game_state.player_character.run(click)
58
59    def refreshTopLayerTransparencies(self):
60        """Fade or unfade TopLayer instances if the PlayerCharacter
61        is under them."""
62        if not self.model.active_map:
63            return
64
65        # get the PlayerCharacter's screen coordinates
66        camera = self.model.active_map.cameras[self.model.active_map.my_cam_id]
67        point = self.model.game_state.player_character.\
68                                        behaviour.agent.getLocation()
69        scr_coords = camera.toScreenCoordinates(point.getMapCoordinates())
70
71        # find all instances on TopLayer that fall on those coordinates
72        instances = camera.getMatchingInstances(scr_coords,
73                        self.model.active_map.top_layer)
74        instance_ids = [ instance.getId() for instance in instances ]
75        faded_objects = self.faded_objects
76
77        # fade instances
78        for instance_id in instance_ids:
79            if instance_id not in faded_objects:
80                faded_objects.add(instance_id)
81                self.model.active_map.top_layer.getInstance(instance_id).\
82                        get2dGfxVisual().setTransparency(128)
83
84        # unfade previously faded instances
85        for instance_id in faded_objects.copy():
86            if instance_id not in instance_ids:
87                faded_objects.remove(instance_id)
88                self.model.active_map.top_layer.getInstance(instance_id).\
89                        get2dGfxVisual().setTransparency(0)
90
91
92    def highlightFrontObject(self, mouse_coords):
93        """Highlights the object that is at the
94        current mouse coordinates"""       
95        if not self.model.active_map:
96            return
97        if mouse_coords:
98            front_obj = self.model.getObjectAtCoords(mouse_coords)
99            if front_obj != None:
100                if self.highlight_obj == None \
101                            or front_obj.getId() != \
102                            self.highlight_obj.getId():
103                    if self.highlight_obj:
104                        self.displayObjectText(self.highlight_obj,"")
105                    self.model.active_map.outline_renderer.removeAllOutlines()
106                    self.highlight_obj = front_obj
107                    self.model.active_map.outline_renderer.addOutlined(
108                                                    self.highlight_obj, 
109                                                    0,
110                                                    137, 255, 2)
111                    # get the text
112                    item = self.model.objectActive(
113                                                    self.highlight_obj.getId())
114                    if item is not None:
115                        self.displayObjectText(self.highlight_obj, 
116                                                    item.name)
117            else:
118                if self.highlight_obj:
119                    self.displayObjectText(self.highlight_obj,"")
120                self.model.active_map.outline_renderer.removeAllOutlines()
121                self.highlight_obj = None 
122           
Note: See TracBrowser for help on using the repository browser.