Browse Source

add gui methods and behaviour decorators

Bastien Sevajol 5 years ago
parent
commit
87dba5b1ad
2 changed files with 29 additions and 3 deletions
  1. 22 1
      synergine2/simulation.py
  2. 7 2
      synergine2_cocos2d/gui.py

+ 22 - 1
synergine2/simulation.py View File

@@ -399,7 +399,7 @@ class SimulationBehaviour(Behaviour):
399 399
         """
400 400
         raise NotImplementedError()
401 401
 
402
-    def action(self, data) -> [Event]:
402
+    def action(self, data) -> typing.List[Event]:
403 403
         """
404 404
         Method called in main process
405 405
         Return events will be give to terminals
@@ -470,3 +470,24 @@ class SubjectComposedBehaviour(SubjectBehaviour):
470 470
     def action(self, data):
471 471
         step = self.get_step(data)
472 472
         return step.get_events()
473
+
474
+
475
+def disable_when(
476
+    predicate: typing.Callable[[Config, Simulation], bool],
477
+):
478
+    def decorator(func) -> typing.Any:
479
+        def wrapper(self, *args, **kwargs):
480
+            if predicate(self.config, self.simulation):
481
+                return False
482
+            return func(self, *args, **kwargs)
483
+        return wrapper
484
+    return decorator
485
+
486
+
487
+def config_value(parameter_to_resolve: str):
488
+    def predicate(
489
+        config: Config,
490
+        simulation: Simulation,
491
+    ):
492
+        return bool(config.resolve(parameter_to_resolve, False))
493
+    return predicate

+ 7 - 2
synergine2_cocos2d/gui.py View File

@@ -5,6 +5,8 @@ from math import floor
5 5
 
6 6
 import pyglet
7 7
 import time
8
+
9
+from cocos.collision_model import AARectShape
8 10
 from pyglet.window import mouse
9 11
 
10 12
 import cocos
@@ -235,7 +237,7 @@ class EditLayer(cocos.layer.Layer):
235 237
         self.wdrag_start_point = (0, 0)
236 238
         self.elastic_box = None  # type: MinMaxRect
237 239
         self.elastic_box_wminmax = 0, 0, 0, 0
238
-        self.selection = {}  # type: typing.List[Actor]
240
+        self.selection = {}  # type: typing.Dict[Actor, AARectShape]
239 241
         self.screen_mouse = (0, 0)
240 242
         self.world_mouse = (0, 0)
241 243
         self.sleft = None
@@ -615,7 +617,7 @@ class EditLayer(cocos.layer.Layer):
615 617
             print("begin drag selection: drag_selecting, drag_moving",
616 618
                   self.drag_selecting, self.drag_moving)
617 619
 
618
-        else:
620
+        elif self.can_move(under_mouse_unique):
619 621
             # want drag move
620 622
             if under_mouse_unique in self.selection:
621 623
                 # want to move current selection
@@ -625,6 +627,9 @@ class EditLayer(cocos.layer.Layer):
625 627
                 self.selection.clear()
626 628
                 self.selection_add(under_mouse_unique)
627 629
             self.begin_drag_move()
630
+    
631
+    def can_move(self, selected) -> bool:
632
+        return True
628 633
 
629 634
     def begin_drag_move(self):
630 635
         # begin drag move