1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 from sounds import SoundEngine
19 from viewbase import ViewBase
20 from fife import fife
21
23 """GameSceneView is responsible for drawing the scene"""
25 """Constructor for GameSceneView
26 @param engine: A fife.Engine instance
27 @type engine: fife.Engine
28 @param model: a script.GameModel instance
29 @type model: script.GameModel
30 """
31 super(GameSceneView, self).__init__(engine, model)
32
33
34 self.sounds = SoundEngine(engine)
35
36 self.hud = None
37
38
39 self.highlight_obj = None
40
41
42 self.faded_objects = set()
43
44 - def displayObjectText(self, obj_id, text, time=1000):
45 """Display on screen the text of the object over the object.
46 @type obj_id: id of fife.instance
47 @param obj: id of object to draw over
48 @type text: String
49 @param text: text to display over object
50 @return: None"""
51 try:
52 if obj_id:
53 obj = self.model.active_map.agent_layer.getInstance(obj_id)
54 else:
55 obj = None
56 except RuntimeError as error:
57 if error.args[0].split(',')[0].strip() == "_[NotFound]_":
58 obj = None
59 else:
60 raise
61 if obj:
62 obj.say(str(text), time)
63
68
70 """Fade or unfade TopLayer instances if the PlayerCharacter
71 is under them."""
72 if not self.model.active_map:
73 return
74
75
76 camera = self.model.active_map.cameras[self.model.active_map.my_cam_id]
77 point = self.model.game_state.player_character.\
78 behaviour.agent.getLocation()
79 scr_coords = camera.toScreenCoordinates(point.getMapCoordinates())
80
81
82 instances = camera.getMatchingInstances(scr_coords,
83 self.model.active_map.top_layer)
84 instance_ids = [ instance.getId() for instance in instances ]
85 faded_objects = self.faded_objects
86
87
88 for instance_id in instance_ids:
89 if instance_id not in faded_objects:
90 faded_objects.add(instance_id)
91 self.model.active_map.top_layer.getInstance(instance_id).\
92 get2dGfxVisual().setTransparency(128)
93
94
95 for instance_id in faded_objects.copy():
96 if instance_id not in instance_ids:
97 faded_objects.remove(instance_id)
98 self.model.active_map.top_layer.getInstance(instance_id).\
99 get2dGfxVisual().setTransparency(0)
100
101
102
103
104
106 """Highlights the object that is at the
107 current mouse coordinates"""
108 if not self.model.active_map:
109 return
110 if mouse_coords:
111 front_obj = self.model.getObjectAtCoords(mouse_coords)
112 if front_obj != None:
113 if self.highlight_obj == None \
114 or front_obj.getId() != \
115 self.highlight_obj:
116 if self.model.game_state.hasObject(front_obj.getId()):
117 self.displayObjectText(self.highlight_obj, "")
118 self.model.active_map.outline_renderer.removeAllOutlines()
119 self.highlight_obj = front_obj.getId()
120 self.model.active_map.outline_renderer.addOutlined(
121 front_obj,
122 0,
123 137, 255, 2)
124
125 item = self.model.objectActive(self.highlight_obj)
126 if item is not None:
127 self.displayObjectText(self.highlight_obj,
128 item.name)
129 else:
130 self.model.active_map.outline_renderer.removeAllOutlines()
131 self.highlight_obj = None
132
133
135 """Move the camera in the given direction.
136 @type direction: list of two integers
137 @param direction: the two integers can be 1, -1, or 0
138 @return: None """
139
140 if 'cameras' in dir(self.model.active_map):
141 cam = self.model.active_map.cameras[self.model.active_map.my_cam_id]
142 location = cam.getLocation()
143 position = location.getMapCoordinates()
144
145
146 move_by = 1
147
148 new_x, new_y = move_by * direction[0], move_by * direction[1]
149
150 position_offset = fife.DoublePoint3D(int(new_x), int(new_y))
151 position += position_offset
152
153
154 location.setMapCoordinates(position)
155
156
157 cam.detach()
158
159 cam.setLocation(location)
160