Browse Source

add gui methods and behaviour decorators

Bastien Sevajol 6 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
         """
399
         """
400
         raise NotImplementedError()
400
         raise NotImplementedError()
401
 
401
 
402
-    def action(self, data) -> [Event]:
402
+    def action(self, data) -> typing.List[Event]:
403
         """
403
         """
404
         Method called in main process
404
         Method called in main process
405
         Return events will be give to terminals
405
         Return events will be give to terminals
470
     def action(self, data):
470
     def action(self, data):
471
         step = self.get_step(data)
471
         step = self.get_step(data)
472
         return step.get_events()
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
 
5
 
6
 import pyglet
6
 import pyglet
7
 import time
7
 import time
8
+
9
+from cocos.collision_model import AARectShape
8
 from pyglet.window import mouse
10
 from pyglet.window import mouse
9
 
11
 
10
 import cocos
12
 import cocos
235
         self.wdrag_start_point = (0, 0)
237
         self.wdrag_start_point = (0, 0)
236
         self.elastic_box = None  # type: MinMaxRect
238
         self.elastic_box = None  # type: MinMaxRect
237
         self.elastic_box_wminmax = 0, 0, 0, 0
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
         self.screen_mouse = (0, 0)
241
         self.screen_mouse = (0, 0)
240
         self.world_mouse = (0, 0)
242
         self.world_mouse = (0, 0)
241
         self.sleft = None
243
         self.sleft = None
615
             print("begin drag selection: drag_selecting, drag_moving",
617
             print("begin drag selection: drag_selecting, drag_moving",
616
                   self.drag_selecting, self.drag_moving)
618
                   self.drag_selecting, self.drag_moving)
617
 
619
 
618
-        else:
620
+        elif self.can_move(under_mouse_unique):
619
             # want drag move
621
             # want drag move
620
             if under_mouse_unique in self.selection:
622
             if under_mouse_unique in self.selection:
621
                 # want to move current selection
623
                 # want to move current selection
625
                 self.selection.clear()
627
                 self.selection.clear()
626
                 self.selection_add(under_mouse_unique)
628
                 self.selection_add(under_mouse_unique)
627
             self.begin_drag_move()
629
             self.begin_drag_move()
630
+    
631
+    def can_move(self, selected) -> bool:
632
+        return True
628
 
633
 
629
     def begin_drag_move(self):
634
     def begin_drag_move(self):
630
         # begin drag move
635
         # begin drag move