Browse Source

Tile: permit to specify gui selection color

Bastien Sevajol 6 years ago
parent
commit
29cee41ea1

+ 7 - 0
sandbox/tile/const.py View File

@@ -1,3 +1,10 @@
1 1
 # coding: utf-8
2 2
 
3 3
 COLLECTION_ALIVE = 'ALIVE'
4
+
5
+FLAG = 'FLAG'
6
+FLAG_DE = 'DE'
7
+FLAG_URSS = 'URSS'
8
+
9
+DE_COLOR = (0, 81, 211)
10
+URSS_COLOR = (204, 0, 0)

+ 12 - 1
sandbox/tile/gui/actor.py View File

@@ -7,6 +7,14 @@ from synergine2_cocos2d.animation import ANIMATION_WALK
7 7
 from synergine2_cocos2d.animation import ANIMATION_CRAWL
8 8
 
9 9
 
10
+FLAG_DE = 'DE'
11
+FLAG_URSS = 'URSS'
12
+
13
+FLAG_COLORS = {
14
+    FLAG_DE
15
+}
16
+
17
+
10 18
 class Man(Actor):
11 19
     animation_image_paths = {
12 20
         ANIMATION_WALK: [
@@ -27,5 +35,8 @@ class Man(Actor):
27 35
         ]
28 36
     }
29 37
 
30
-    def __init__(self, subject: Subject) -> None:
38
+    def __init__(
39
+        self,
40
+        subject: Subject,
41
+    ) -> None:
31 42
         super().__init__(pyglet.resource.image('actors/man.png'), subject=subject)

+ 23 - 0
sandbox/tile/run.py View File

@@ -5,6 +5,13 @@ import sys
5 5
 import logging
6 6
 from random import seed
7 7
 
8
+from sandbox.tile.const import FLAG
9
+from sandbox.tile.const import FLAG_DE
10
+from sandbox.tile.const import DE_COLOR
11
+from sandbox.tile.const import URSS_COLOR
12
+from sandbox.tile.const import FLAG_URSS
13
+from synergine2_cocos2d.const import SELECTION_COLOR_RGB
14
+
8 15
 synergine2_path = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../'))
9 16
 sys.path.append(synergine2_path)
10 17
 
@@ -36,6 +43,22 @@ def main(map_dir_path: str, seed_value: int=42):
36 43
             config=config,
37 44
             simulation=simulation,
38 45
             position=position,
46
+            properties={
47
+                SELECTION_COLOR_RGB: DE_COLOR,
48
+                FLAG: FLAG_DE,
49
+            }
50
+        )
51
+        subjects.append(man)
52
+
53
+    for position in ((20, 10),):
54
+        man = Man(
55
+            config=config,
56
+            simulation=simulation,
57
+            position=position,
58
+            properties={
59
+                SELECTION_COLOR_RGB: URSS_COLOR,
60
+                FLAG: FLAG_URSS,
61
+            }
39 62
         )
40 63
         subjects.append(man)
41 64
 

+ 8 - 0
synergine2/simulation.py View File

@@ -40,7 +40,14 @@ class Subject(IdentifiedObject):
40 40
         self,
41 41
         config: Config,
42 42
         simulation: 'Simulation',
43
+        properties: dict=None,
43 44
     ):
45
+        """
46
+
47
+        :param config: config object
48
+        :param simulation: simulation object
49
+        :param properties: additional data (will not change during simulation)
50
+        """
44 51
         super().__init__()
45 52
         # FIXME: use shared data to permit dynamic start_collections
46 53
         self.collections = self.start_collections[:]
@@ -49,6 +56,7 @@ class Subject(IdentifiedObject):
49 56
         self._id = id(self)  # We store object id because it's lost between process
50 57
         self.simulation = simulation
51 58
         self.intentions = None
59
+        self.properties = properties or {}
52 60
 
53 61
         if self.behaviour_selector_class:
54 62
             self.behaviour_selector = self.behaviour_selector_class()

+ 2 - 0
synergine2_cocos2d/actor.py View File

@@ -24,6 +24,7 @@ class Actor(AnimatedInterface, cocos.sprite.Sprite):
24 24
         opacity=255,
25 25
         color=(255, 255, 255),
26 26
         anchor=None,
27
+        properties: dict=None,
27 28
         **kwargs
28 29
     ):
29 30
         super().__init__(
@@ -42,6 +43,7 @@ class Actor(AnimatedInterface, cocos.sprite.Sprite):
42 43
         self.build_animation_images()
43 44
         self.current_image = image
44 45
         self.need_update_cshape = False
46
+        self.properties = properties or {}
45 47
 
46 48
     def stop_actions(self, action_types: typing.Tuple[typing.Type[cocos.actions.Action], ...]) -> None:
47 49
         for action in self.actions:

+ 4 - 0
synergine2_cocos2d/const.py View File

@@ -0,0 +1,4 @@
1
+# coding: utf-8
2
+
3
+DEFAULT_SELECTION_COLOR_RGB = 'DEFAULT_SELECTION_COLOR_RGB'
4
+SELECTION_COLOR_RGB = 'SELECTION_COLOR_RGB'

+ 7 - 2
synergine2_cocos2d/gui.py View File

@@ -15,6 +15,8 @@ from synergine2.log import SynergineLogger
15 15
 from synergine2.terminals import Terminal
16 16
 from synergine2.terminals import TerminalPackage
17 17
 from synergine2_cocos2d.actor import Actor
18
+from synergine2_cocos2d.const import SELECTION_COLOR_RGB
19
+from synergine2_cocos2d.const import DEFAULT_SELECTION_COLOR_RGB
18 20
 from synergine2_cocos2d.exception import InteractionNotFound
19 21
 from synergine2_cocos2d.exception import OuterWorldPosition
20 22
 from synergine2_cocos2d.gl import draw_rectangle
@@ -173,7 +175,7 @@ class EditLayer(cocos.layer.Layer):
173 175
         self.wdrag_start_point = (0, 0)
174 176
         self.elastic_box = None  # type: MinMaxRect
175 177
         self.elastic_box_wminmax = 0, 0, 0, 0
176
-        self.selection = {}
178
+        self.selection = {}  # type: typing.List[Actor]
177 179
         self.screen_mouse = (0, 0)
178 180
         self.world_mouse = (0, 0)
179 181
         self.sleft = None
@@ -228,7 +230,10 @@ class EditLayer(cocos.layer.Layer):
228 230
 
229 231
             draw_rectangle(
230 232
                 self.layer_manager.scrolling_manager.world_to_screen_positions(rect_positions),
231
-                (0, 81, 211),
233
+                actor.subject.properties.get(
234
+                    SELECTION_COLOR_RGB,
235
+                    self.config.get(DEFAULT_SELECTION_COLOR_RGB, (0, 81, 211))
236
+                ),
232 237
             )
233 238
 
234 239
     def draw_interactions(self) -> None: