1
1
use bevy:: prelude:: * ;
2
+ use crate :: chart:: event:: LineEvent ;
3
+ use crate :: chart:: note:: Note ;
2
4
3
5
use crate :: project:: project_loaded;
4
6
@@ -10,7 +12,7 @@ pub struct Selected;
10
12
11
13
/// Select a [Entity] in the world
12
14
#[ derive( Event ) ]
13
- pub struct SelectEvent ( pub Entity ) ;
15
+ pub struct SelectEvent ( pub Entity , pub bool ) ;
14
16
15
17
pub struct SelectionPlugin ;
16
18
@@ -21,8 +23,39 @@ impl Plugin for SelectionPlugin {
21
23
}
22
24
}
23
25
24
- pub fn handle_select_event ( mut commands : Commands , mut select_events : EventReader < SelectEvent > ) {
26
+ pub fn handle_select_event (
27
+ mut commands : Commands ,
28
+ mut select_events : EventReader < SelectEvent > ,
29
+ note_query : Query < & Note > ,
30
+ event_query : Query < & LineEvent > ,
31
+
32
+ selected_notes_query : Query < Entity , ( With < Selected > , With < Note > , Without < LineEvent > ) > ,
33
+ selected_events_query : Query < Entity , ( With < Selected > , With < LineEvent > , Without < Note > ) > ,
34
+
35
+ selected_notes_and_events_query : Query < Entity , ( With < Selected > , Or < ( With < Note > , With < LineEvent > ) > ) > ,
36
+ ) {
25
37
for event in select_events. read ( ) {
38
+ if event. 1 {
39
+ // unselect all notes and events
40
+ for entity in & selected_notes_and_events_query {
41
+ commands. entity ( entity) . remove :: < Selected > ( ) ;
42
+ }
43
+ } else {
44
+ // selecting both notes and events is not allowed
45
+ if note_query. get ( event. 0 ) . is_ok ( ) {
46
+ // target is note, unselect all events
47
+ for entity in & selected_events_query {
48
+ commands. entity ( entity) . remove :: < Selected > ( ) ;
49
+ }
50
+ }
51
+ if event_query. get ( event. 0 ) . is_ok ( ) {
52
+ // target is event, unselect all notes
53
+ for entity in & selected_notes_query {
54
+ commands. entity ( entity) . remove :: < Selected > ( ) ;
55
+ }
56
+ }
57
+ }
58
+
26
59
commands. entity ( event. 0 ) . insert ( Selected ) ;
27
60
}
28
61
}
0 commit comments