Browse Source

fix gui positions when zoom

Bastien Sevajol 7 years ago
parent
commit
f1b3a85c63

+ 6 - 6
sandbox/tile/gui/base.py View File

@@ -137,14 +137,14 @@ class Game(TMXGui):
137 137
 
138 138
     def set_subject_position(self, event: FinishMoveEvent):
139 139
         actor = self.layer_manager.subject_layer.subjects_index[event.subject_id]
140
-        new_world_position = self.layer_manager.grid_manager.get_pixel_position_of_grid_position(event.to_position)
140
+        new_world_position = self.layer_manager.grid_manager.get_world_position_of_grid_position(event.to_position)
141 141
 
142 142
         actor.stop_actions((BaseMoveTo,))
143 143
         actor.set_position(*new_world_position)
144 144
 
145 145
     def start_move_subject(self, event: StartMoveEvent):
146 146
         actor = self.layer_manager.subject_layer.subjects_index[event.subject_id]
147
-        new_world_position = self.layer_manager.grid_manager.get_pixel_position_of_grid_position(event.to_position)
147
+        new_world_position = self.layer_manager.grid_manager.get_world_position_of_grid_position(event.to_position)
148 148
 
149 149
         if event.gui_action == UserAction.ORDER_MOVE:
150 150
             animation = ANIMATION_WALK
@@ -182,12 +182,12 @@ class Game(TMXGui):
182 182
             observed_actor = self.layer_manager.subject_layer.subjects_index[event.observed_subject_id]
183 183
 
184 184
             observer_pixel_position = self.layer_manager.scrolling_manager.world_to_screen(
185
-                *self.layer_manager.grid_manager.get_pixel_position_of_grid_position(
185
+                *self.layer_manager.grid_manager.get_world_position_of_grid_position(
186 186
                     observer_actor.subject.position,
187 187
                 )
188 188
             )
189 189
             observed_pixel_position = self.layer_manager.scrolling_manager.world_to_screen(
190
-                *self.layer_manager.grid_manager.get_pixel_position_of_grid_position(
190
+                *self.layer_manager.grid_manager.get_world_position_of_grid_position(
191 191
                     observed_actor.subject.position,
192 192
                 )
193 193
             )
@@ -206,12 +206,12 @@ class Game(TMXGui):
206 206
         # TODO: Not in edit layer !
207 207
         shooter_actor = self.layer_manager.subject_layer.subjects_index[event.shooter_subject_id]
208 208
         shooter_pixel_position = self.layer_manager.scrolling_manager.world_to_screen(
209
-            *self.layer_manager.grid_manager.get_pixel_position_of_grid_position(
209
+            *self.layer_manager.grid_manager.get_world_position_of_grid_position(
210 210
                 shooter_actor.subject.position,
211 211
             )
212 212
         )
213 213
         fire_to_pixel_position = self.layer_manager.scrolling_manager.world_to_screen(
214
-            *self.layer_manager.grid_manager.get_pixel_position_of_grid_position(
214
+            *self.layer_manager.grid_manager.get_world_position_of_grid_position(
215 215
                 event.target_position,
216 216
             )
217 217
         )

+ 10 - 10
sandbox/tile/gui/fire.py View File

@@ -18,7 +18,7 @@ class BaseFireActorInteraction(BaseActorInteraction):
18 18
     def draw_pending(self) -> None:
19 19
         for actor in self.layer_manager.edit_layer.selection:
20 20
             actor_grid_position = self.layer_manager.grid_manager.get_grid_position(actor.position)
21
-            actor_pixel_position = self.layer_manager.grid_manager.get_pixel_position_of_grid_position(
21
+            actor_pixel_position = self.layer_manager.grid_manager.get_world_position_of_grid_position(
22 22
                 actor_grid_position,
23 23
             )
24 24
             mouse_grid_position = self.layer_manager.grid_manager.get_grid_position(
@@ -28,7 +28,7 @@ class BaseFireActorInteraction(BaseActorInteraction):
28 28
             )
29 29
             draw_to_pixel = self.layer_manager.edit_layer.screen_mouse
30 30
 
31
-            obstacle_grid_position = self.layer_manager.edit_layer.physics.get_visibility_obstacle(
31
+            obstacle_grid_position = self.layer_manager.gui.physics.get_visibility_obstacle(
32 32
                 subject=actor.subject,
33 33
                 to_position=mouse_grid_position,
34 34
                 matrix_name='visibility',
@@ -37,34 +37,34 @@ class BaseFireActorInteraction(BaseActorInteraction):
37 37
 
38 38
             # DEBUG
39 39
             if self.layer_manager.debug:
40
-                grid_paths = self.layer_manager.edit_layer.physics.matrixes.get_path_positions(
40
+                grid_paths = self.layer_manager.gui.physics.matrixes.get_path_positions(
41 41
                     from_=actor_grid_position,
42 42
                     to=mouse_grid_position,
43 43
                 )
44 44
                 previous_grid_path = None
45 45
                 for grid_path in grid_paths:
46 46
                     if previous_grid_path:
47
-                        previous_grid_path_pixel = self.layer_manager.grid_manager.get_pixel_position_of_grid_position(
47
+                        previous_grid_path_pixel = self.layer_manager.grid_manager.get_world_position_of_grid_position(
48 48
                             previous_grid_path,
49 49
                         )
50
-                        current_grid_pixel = self.layer_manager.grid_manager.get_pixel_position_of_grid_position(
50
+                        current_grid_pixel = self.layer_manager.grid_manager.get_world_position_of_grid_position(
51 51
                             grid_path,
52 52
                         )
53 53
                         draw_line(
54
-                            previous_grid_path_pixel,
55
-                            current_grid_pixel,
54
+                            self.layer_manager.scrolling_manager.world_to_screen(*previous_grid_path_pixel),
55
+                            self.layer_manager.scrolling_manager.world_to_screen(*current_grid_pixel),
56 56
                             (25, 125, 25),
57 57
                         )
58 58
                     previous_grid_path = grid_path
59 59
 
60 60
             if obstacle_grid_position:
61
-                obstacle_pixel = self.layer_manager.grid_manager.get_pixel_position_of_grid_position(
61
+                obstacle_pixel = self.layer_manager.grid_manager.get_world_position_of_grid_position(
62 62
                     obstacle_grid_position,
63 63
                 )
64
-                draw_to_pixel = obstacle_pixel
64
+                draw_to_pixel = self.layer_manager.scrolling_manager.world_to_screen(*obstacle_pixel)
65 65
 
66 66
                 draw_line(
67
-                    obstacle_pixel,
67
+                    self.layer_manager.scrolling_manager.world_to_screen(*obstacle_pixel),
68 68
                     self.layer_manager.edit_layer.screen_mouse,
69 69
                     self.not_visible_color,
70 70
                 )

+ 1 - 1
sandbox/tile/gui/move.py View File

@@ -17,7 +17,7 @@ class BaseMoveActorInteraction(BaseActorInteraction):
17 17
     def draw_pending(self) -> None:
18 18
         for actor in self.layer_manager.edit_layer.selection:
19 19
             grid_position = self.layer_manager.grid_manager.get_grid_position(actor.position)
20
-            pixel_position = self.layer_manager.grid_manager.get_pixel_position_of_grid_position(grid_position)
20
+            pixel_position = self.layer_manager.grid_manager.get_world_position_of_grid_position(grid_position)
21 21
 
22 22
             draw_line(
23 23
                 self.layer_manager.scrolling_manager.world_to_screen(*pixel_position),

+ 8 - 4
synergine2_cocos2d/gui.py View File

@@ -60,7 +60,7 @@ class GridManager(object):
60 60
 
61 61
         return cell_x, cell_y
62 62
 
63
-    def get_pixel_position_of_grid_position(self, grid_position: typing.Tuple[int, int]) -> typing.Tuple[int, int]:
63
+    def get_world_position_of_grid_position(self, grid_position: typing.Tuple[int, int]) -> typing.Tuple[int, int]:
64 64
         return grid_position[0] * self.cell_width + (self.cell_width // 2),\
65 65
                grid_position[1] * self.cell_height + (self.cell_height // 2)
66 66
 
@@ -355,7 +355,7 @@ class EditLayer(cocos.layer.Layer):
355 355
 
356 356
                 try:
357 357
                     grid_pos = self.grid_manager.get_grid_position(new_pos)
358
-                    grid_pixel_pos = self.grid_manager.get_pixel_position_of_grid_position(grid_pos)
358
+                    grid_pixel_pos = self.grid_manager.get_world_position_of_grid_position(grid_pos)
359 359
                     actor.update_position(grid_pixel_pos)
360 360
                 except OuterWorldPosition:
361 361
                     # don't update position
@@ -689,7 +689,7 @@ class SubjectMapper(object):
689 689
         layer_manager: LayerManager,
690 690
     ) -> None:
691 691
         actor = self.actor_class(subject)
692
-        pixel_position = layer_manager.grid_manager.get_pixel_position_of_grid_position(
692
+        pixel_position = layer_manager.grid_manager.get_world_position_of_grid_position(
693 693
             (subject.position[0], subject.position[1]),
694 694
         )
695 695
         actor.update_position(euclid.Vector2(*pixel_position))
@@ -724,10 +724,12 @@ class Gui(object):
724 724
             config: Config,
725 725
             logger: SynergineLogger,
726 726
             terminal: Terminal,
727
+            physics: Physics,
727 728
             read_queue_interval: float= 1/60.0,
728 729
     ):
729 730
         self.config = config
730 731
         self.logger = logger
732
+        self.physics = physics
731 733
         self._read_queue_interval = read_queue_interval
732 734
         self.terminal = terminal
733 735
         self.cycle_duration = self.config.resolve('core.cycle_duration')
@@ -750,6 +752,7 @@ class Gui(object):
750 752
             self.logger,
751 753
             middleware=self.get_layer_middleware(),
752 754
             interaction_manager=self.interaction_manager,
755
+            gui=self,
753 756
         )
754 757
         self.layer_manager.init()
755 758
         self.layer_manager.center()
@@ -804,7 +807,8 @@ class TMXGui(Gui):
804 807
             config,
805 808
             logger,
806 809
             terminal,
807
-            read_queue_interval,
810
+            physics=physics,
811
+            read_queue_interval=read_queue_interval,
808 812
         )
809 813
         self.physics = physics
810 814
 

+ 1 - 1
synergine2_cocos2d/interaction.py View File

@@ -77,7 +77,7 @@ class BaseActorInteraction(Interaction):
77 77
     def draw_pending(self) -> None:
78 78
         for actor in self.layer_manager.edit_layer.selection:
79 79
             grid_position = self.layer_manager.grid_manager.get_grid_position(actor.position)
80
-            pixel_position = self.layer_manager.grid_manager.get_pixel_position_of_grid_position(grid_position)
80
+            pixel_position = self.layer_manager.grid_manager.get_world_position_of_grid_position(grid_position)
81 81
 
82 82
             draw_line(
83 83
                 self.layer_manager.scrolling_manager.world_to_screen(*pixel_position),

+ 3 - 0
synergine2_cocos2d/layer.py View File

@@ -12,6 +12,7 @@ from synergine2_cocos2d.middleware import MapMiddleware
12 12
 if False:
13 13
     from synergine2_cocos2d.actor import Actor
14 14
     from synergine2_cocos2d.gui import GridManager
15
+    from synergine2_cocos2d.gui import Gui
15 16
     from synergine2_cocos2d.interaction import InteractionManager
16 17
 
17 18
 
@@ -66,11 +67,13 @@ class LayerManager(object):
66 67
         logger: SynergineLogger,
67 68
         middleware: MapMiddleware,
68 69
         interaction_manager: 'InteractionManager',
70
+        gui: 'Gui',
69 71
     ) -> None:
70 72
         self.config = config
71 73
         self.logger = logger
72 74
         self.middleware = middleware
73 75
         self.interaction_manager = interaction_manager
76
+        self.gui = gui
74 77
 
75 78
         self.grid_manager = None  # type: GridManager
76 79
         self.scrolling_manager = None  # type: ScrollingManager