Bladeren bron

Tile: permit to specify gui selection color

Bastien Sevajol 7 jaren geleden
bovenliggende
commit
29cee41ea1

+ 7 - 0
sandbox/tile/const.py Bestand weergeven

1
 # coding: utf-8
1
 # coding: utf-8
2
 
2
 
3
 COLLECTION_ALIVE = 'ALIVE'
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 Bestand weergeven

7
 from synergine2_cocos2d.animation import ANIMATION_CRAWL
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
 class Man(Actor):
18
 class Man(Actor):
11
     animation_image_paths = {
19
     animation_image_paths = {
12
         ANIMATION_WALK: [
20
         ANIMATION_WALK: [
27
         ]
35
         ]
28
     }
36
     }
29
 
37
 
30
-    def __init__(self, subject: Subject) -> None:
38
+    def __init__(
39
+        self,
40
+        subject: Subject,
41
+    ) -> None:
31
         super().__init__(pyglet.resource.image('actors/man.png'), subject=subject)
42
         super().__init__(pyglet.resource.image('actors/man.png'), subject=subject)

+ 23 - 0
sandbox/tile/run.py Bestand weergeven

5
 import logging
5
 import logging
6
 from random import seed
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
 synergine2_path = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../'))
15
 synergine2_path = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../'))
9
 sys.path.append(synergine2_path)
16
 sys.path.append(synergine2_path)
10
 
17
 
36
             config=config,
43
             config=config,
37
             simulation=simulation,
44
             simulation=simulation,
38
             position=position,
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
         subjects.append(man)
63
         subjects.append(man)
41
 
64
 

+ 8 - 0
synergine2/simulation.py Bestand weergeven

40
         self,
40
         self,
41
         config: Config,
41
         config: Config,
42
         simulation: 'Simulation',
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
         super().__init__()
51
         super().__init__()
45
         # FIXME: use shared data to permit dynamic start_collections
52
         # FIXME: use shared data to permit dynamic start_collections
46
         self.collections = self.start_collections[:]
53
         self.collections = self.start_collections[:]
49
         self._id = id(self)  # We store object id because it's lost between process
56
         self._id = id(self)  # We store object id because it's lost between process
50
         self.simulation = simulation
57
         self.simulation = simulation
51
         self.intentions = None
58
         self.intentions = None
59
+        self.properties = properties or {}
52
 
60
 
53
         if self.behaviour_selector_class:
61
         if self.behaviour_selector_class:
54
             self.behaviour_selector = self.behaviour_selector_class()
62
             self.behaviour_selector = self.behaviour_selector_class()

+ 2 - 0
synergine2_cocos2d/actor.py Bestand weergeven

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

+ 4 - 0
synergine2_cocos2d/const.py Bestand weergeven

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 Bestand weergeven

15
 from synergine2.terminals import Terminal
15
 from synergine2.terminals import Terminal
16
 from synergine2.terminals import TerminalPackage
16
 from synergine2.terminals import TerminalPackage
17
 from synergine2_cocos2d.actor import Actor
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
 from synergine2_cocos2d.exception import InteractionNotFound
20
 from synergine2_cocos2d.exception import InteractionNotFound
19
 from synergine2_cocos2d.exception import OuterWorldPosition
21
 from synergine2_cocos2d.exception import OuterWorldPosition
20
 from synergine2_cocos2d.gl import draw_rectangle
22
 from synergine2_cocos2d.gl import draw_rectangle
173
         self.wdrag_start_point = (0, 0)
175
         self.wdrag_start_point = (0, 0)
174
         self.elastic_box = None  # type: MinMaxRect
176
         self.elastic_box = None  # type: MinMaxRect
175
         self.elastic_box_wminmax = 0, 0, 0, 0
177
         self.elastic_box_wminmax = 0, 0, 0, 0
176
-        self.selection = {}
178
+        self.selection = {}  # type: typing.List[Actor]
177
         self.screen_mouse = (0, 0)
179
         self.screen_mouse = (0, 0)
178
         self.world_mouse = (0, 0)
180
         self.world_mouse = (0, 0)
179
         self.sleft = None
181
         self.sleft = None
228
 
230
 
229
             draw_rectangle(
231
             draw_rectangle(
230
                 self.layer_manager.scrolling_manager.world_to_screen_positions(rect_positions),
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
     def draw_interactions(self) -> None:
239
     def draw_interactions(self) -> None: