1
- use bevy:: { color:: palettes:: css, prelude:: * } ;
1
+ use std:: ops:: Deref ;
2
+
3
+ use bevy:: { color:: palettes:: css, prelude:: * , transform:: commands} ;
2
4
use bevy_egui:: { egui, EguiContexts , EguiPlugin } ;
3
5
use bevy_ogle:: { prelude:: * , OglePlugin } ;
4
6
use rand:: random;
@@ -11,42 +13,40 @@ fn main() {
11
13
. add_plugins ( DefaultPlugins )
12
14
. add_plugins ( EguiPlugin )
13
15
. add_plugins ( OglePlugin )
14
- . add_systems ( Startup , setup_background )
16
+ . add_systems ( Startup , setup_scene )
15
17
. add_systems ( Startup , |mut commands : Commands | {
16
18
commands. spawn ( Camera2dBundle :: default ( ) ) ;
17
- // Create target, begin following it.
18
- let entity = commands
19
- . spawn ( ( ThingToFollow , SpatialBundle :: default ( ) ) )
20
- . id ( ) ;
21
- commands. ogle_change_mode ( OgleMode :: Frozen ) ;
22
- commands. ogle_target_entity ( entity) ;
23
19
} )
24
20
. add_systems ( Update , move_target)
25
21
. add_systems ( Update , control_camera_ui)
26
22
. run ( ) ;
27
23
}
28
24
29
- fn setup_background ( mut commands : Commands ) {
30
- let n = 20 ;
31
- let spacing = 50. ;
32
- let offset = spacing * n as f32 / 2. ;
33
- let custom_size = Some ( Vec2 :: new ( spacing, spacing) ) ;
34
- for x in 0 ..n {
35
- for y in 0 ..n {
36
- let x = x as f32 * spacing - offset;
37
- let y = y as f32 * spacing - offset;
38
- let color = Color :: hsl ( 240. , random :: < f32 > ( ) * 0.3 , random :: < f32 > ( ) * 0.3 ) ;
39
- commands. spawn ( SpriteBundle {
40
- sprite : Sprite {
41
- color,
42
- custom_size,
43
- ..default ( )
44
- } ,
45
- transform : Transform :: from_xyz ( x, y, 0. ) ,
25
+ fn setup_scene ( mut commands : Commands ) {
26
+ // Background
27
+ commands. spawn ( SpriteBundle {
28
+ sprite : Sprite {
29
+ color : css:: LIME . into ( ) ,
30
+ custom_size : Some ( Vec2 :: new ( 500.0 , 500.0 ) ) ,
31
+ ..default ( )
32
+ } ,
33
+ transform : Transform :: from_xyz ( 0.0 , 0.0 , 0. ) ,
34
+ ..default ( )
35
+ } ) ;
36
+
37
+ // Moving thing for the camera to follow
38
+ commands. spawn ( (
39
+ ThingToFollow ,
40
+ SpriteBundle {
41
+ sprite : Sprite {
42
+ color : css:: RED . into ( ) ,
43
+ custom_size : Some ( Vec2 :: new ( 5.0 , 5.0 ) ) ,
46
44
..default ( )
47
- } ) ;
48
- }
49
- }
45
+ } ,
46
+ transform : Transform :: from_xyz ( 0.0 , 0.0 , 0. ) ,
47
+ ..default ( )
48
+ } ,
49
+ ) ) ;
50
50
}
51
51
52
52
fn move_target (
@@ -61,8 +61,10 @@ fn move_target(
61
61
}
62
62
63
63
fn control_camera_ui (
64
+ mut commands : Commands ,
64
65
mut contexts : EguiContexts ,
65
66
query_thing : Query < Entity , With < ThingToFollow > > ,
67
+ target : Res < OgleTarget > ,
66
68
mode : Res < State < OgleMode > > ,
67
69
mut next_mode : ResMut < NextState < OgleMode > > ,
68
70
) {
@@ -71,6 +73,7 @@ fn control_camera_ui(
71
73
. resizable ( false )
72
74
. title_bar ( true ) ;
73
75
window. show ( contexts. ctx_mut ( ) , |ui| {
76
+ ui. heading ( "Mode" ) ;
74
77
let mut set_mode = mode. clone ( ) ;
75
78
if ui
76
79
. radio_value ( & mut set_mode, OgleMode :: Frozen , "Frozen" )
@@ -87,5 +90,18 @@ fn control_camera_ui(
87
90
{
88
91
next_mode. set ( set_mode) ;
89
92
}
93
+
94
+ ui. separator ( ) ;
95
+ ui. heading ( "Mode" ) ;
96
+ let target_entity = query_thing. single ( ) ;
97
+ if ui. radio ( * target == OgleTarget :: None , "None" ) . clicked ( ) {
98
+ commands. ogle_clear_target ( ) ;
99
+ }
100
+ if ui
101
+ . radio ( * target == OgleTarget :: Entity ( target_entity) , "Entity" )
102
+ . clicked ( )
103
+ {
104
+ commands. ogle_target_entity ( target_entity) ;
105
+ }
90
106
} ) ;
91
107
}
0 commit comments