Browse Source

set position when drag + drag only in placement mode

Bastien Sevajol 5 years ago
parent
commit
b11131cd3a

+ 35 - 4
opencombat/gui/base.py View File

21
 from opencombat.gui.animation import ANIMATION_WALK
21
 from opencombat.gui.animation import ANIMATION_WALK
22
 from opencombat.gui.animation import ANIMATION_CRAWL
22
 from opencombat.gui.animation import ANIMATION_CRAWL
23
 from opencombat.gui.fire import GuiFiringEvent
23
 from opencombat.gui.fire import GuiFiringEvent
24
+from opencombat.gui.placement import SetSubjectPositionsInteraction
24
 from opencombat.gui.state import SaveStateInteraction
25
 from opencombat.gui.state import SaveStateInteraction
25
 from opencombat.simulation.interior import InteriorManager
26
 from opencombat.simulation.interior import InteriorManager
26
 from opencombat.simulation.tmx import TileMap
27
 from opencombat.simulation.tmx import TileMap
74
             )
75
             )
75
         interaction.execute()
76
         interaction.execute()
76
 
77
 
78
+    def can_move(self, selected) -> bool:
79
+        return self.config.resolve('_runtime.placement_mode', False)
80
+
81
+    def end_drag_move(self, wx, wy):
82
+        # set position
83
+        super().end_drag_move(wx, wy)
84
+
85
+        interaction = self.layer_manager \
86
+            .interaction_manager \
87
+            .get_for_user_action(
88
+                UserAction.SET_SUBJECTS_POSITION,
89
+            )
90
+        interaction.execute()
91
+
77
 
92
 
78
 class BackgroundLayer(cocos.layer.Layer):
93
 class BackgroundLayer(cocos.layer.Layer):
79
     def __init__(
94
     def __init__(
280
         from opencombat.gui.move import MoveCrawlActorInteraction
295
         from opencombat.gui.move import MoveCrawlActorInteraction
281
         from opencombat.gui.fire import FireActorInteraction
296
         from opencombat.gui.fire import FireActorInteraction
282
 
297
 
283
-        self.layer_manager.interaction_manager.register(MoveActorInteraction, self.layer_manager)
284
-        self.layer_manager.interaction_manager.register(MoveFastActorInteraction, self.layer_manager)
285
-        self.layer_manager.interaction_manager.register(MoveCrawlActorInteraction, self.layer_manager)
286
-        self.layer_manager.interaction_manager.register(FireActorInteraction, self.layer_manager)
298
+        self.layer_manager.interaction_manager.register(
299
+            MoveActorInteraction,
300
+            self.layer_manager,
301
+        )
302
+        self.layer_manager.interaction_manager.register(
303
+            MoveFastActorInteraction,
304
+            self.layer_manager,
305
+        )
306
+        self.layer_manager.interaction_manager.register(
307
+            MoveCrawlActorInteraction,
308
+            self.layer_manager,
309
+        )
310
+        self.layer_manager.interaction_manager.register(
311
+            FireActorInteraction,
312
+            self.layer_manager,
313
+        )
287
         self.layer_manager.interaction_manager.register(
314
         self.layer_manager.interaction_manager.register(
288
             SaveStateInteraction,
315
             SaveStateInteraction,
289
             self.layer_manager,
316
             self.layer_manager,
290
         )
317
         )
318
+        self.layer_manager.interaction_manager.register(
319
+            SetSubjectPositionsInteraction,
320
+            self.layer_manager,
321
+        )
291
 
322
 
292
     def set_subject_position(
323
     def set_subject_position(
293
         self,
324
         self,

+ 26 - 0
opencombat/gui/placement.py View File

1
+# coding: utf-8
2
+from synergine2.terminals import TerminalPackage
3
+from synergine2_cocos2d.interaction import Interaction
4
+
5
+from opencombat.simulation.placement import SetSubjectPositionsSimulationBehaviour  # nopep8
6
+from opencombat.user_action import UserAction
7
+
8
+
9
+class SetSubjectPositionsInteraction(Interaction):
10
+    gui_action = UserAction.SET_SUBJECTS_POSITION
11
+
12
+    def get_package_for_terminal(self) -> TerminalPackage:
13
+        data = []  # type: typing.List[typing.Tuple[int, typing.Tuple[int, int]]]  # nopep8
14
+        for moved_subject in self.layer_manager.edit_layer.selection.keys():
15
+            grid_position = self.layer_manager.grid_manager.get_grid_position(
16
+                moved_subject.position,
17
+            )
18
+            data.append(
19
+                (moved_subject.subject.id, grid_position),
20
+            )
21
+
22
+        return TerminalPackage(
23
+            simulation_actions=[
24
+                (SetSubjectPositionsSimulationBehaviour, data),
25
+            ]
26
+        )

+ 21 - 0
opencombat/simulation/placement.py View File

1
+# coding: utf-8
2
+import typing
3
+
4
+from synergine2.simulation import SimulationBehaviour
5
+from synergine2.simulation import Event
6
+
7
+
8
+class SetSubjectPositionsSimulationBehaviour(SimulationBehaviour):
9
+    def action(self, data) -> typing.List[Event]:
10
+        for subject_id, new_position in data:
11
+            subject = self.simulation.subjects.index[subject_id]
12
+            subject.position = new_position
13
+
14
+        return []
15
+
16
+    @classmethod
17
+    def merge_data(cls, new_data, start_data=None):
18
+        pass
19
+
20
+    def run(self, data):
21
+        pass

+ 1 - 1
opencombat/state.xsd View File

38
     </xs:simpleType>
38
     </xs:simpleType>
39
 
39
 
40
     <xs:simpleType name="directiontype">
40
     <xs:simpleType name="directiontype">
41
-        <xs:restriction base="xs:positiveInteger"/>
41
+        <xs:restriction base="xs:float"/>
42
     </xs:simpleType>
42
     </xs:simpleType>
43
 
43
 
44
     <xs:complexType name="statetype">
44
     <xs:complexType name="statetype">

+ 1 - 0
opencombat/user_action.py View File

8
     ORDER_MOVE_FAST = 'ORDER_MOVE_FAST'
8
     ORDER_MOVE_FAST = 'ORDER_MOVE_FAST'
9
     ORDER_MOVE_CRAWL = 'ORDER_MOVE_CRAWL'
9
     ORDER_MOVE_CRAWL = 'ORDER_MOVE_CRAWL'
10
     ORDER_FIRE = 'ORDER_FIRE'
10
     ORDER_FIRE = 'ORDER_FIRE'
11
+    SET_SUBJECTS_POSITION = 'SET_SUBJECTS_POSITION'