11use std:: time:: Duration ;
22
3- use avian3d:: prelude:: { RigidBody , RigidBodyDisabled } ;
3+ use avian3d:: prelude:: { RigidBody } ;
44use bevy:: asset:: uuid:: Uuid ;
55use bevy:: ecs:: lifecycle:: HookContext ;
66use bevy:: ecs:: world:: DeferredWorld ;
@@ -11,7 +11,7 @@ use bevy::color::palettes::css::{BLUE, GRAY};
1111use bevy_ingame_clock:: InGameClock ;
1212use bevy_old_tv_shader:: OldTvPlugin ;
1313
14- use crate :: { CameraInterpolation , CameraInterpolation2 , CameraState , CameraTarget , Interactable , InteractionEvent , Player , PlayerCamera , PlayerState } ;
14+ use crate :: { CameraInterpolation2 , CameraTarget , Interactable , InteractionEvent , Player , PlayerCamera , PlayerState } ;
1515
1616mod computer_input;
1717mod computer_display;
@@ -62,6 +62,26 @@ fn on_crt_tv_add(
6262 . observe ( computer_interaction_observer) ;
6363}
6464
65+ #[ derive( Component ) ]
66+ #[ require(
67+ Node {
68+ position_type: PositionType :: Absolute ,
69+ width: Val :: Percent ( 11. ) ,
70+ height: Val :: Percent ( 15. ) ,
71+ align_items: AlignItems :: Center ,
72+ border_radius: BorderRadius :: all( Val :: Px ( 10. ) ) ,
73+ left: Val :: Px ( 20. ) ,
74+ top: Val :: Px ( 400. ) ,
75+ flex_direction: FlexDirection :: Column ,
76+ overflow: Overflow { x: OverflowAxis :: Hidden , y: OverflowAxis :: Hidden } ,
77+ ..default ( )
78+ } ,
79+ BackgroundColor ( BLUE . into( ) ) ,
80+ IconClickTimer ( Timer :: from_seconds( 1.0 , TimerMode :: Once ) ) ,
81+ ) ]
82+ #[ component( on_add = on_computer_rover_icon_add) ]
83+ pub struct ComputerRoverIcon ;
84+
6585#[ derive( Component ) ]
6686#[ require(
6787 Node {
@@ -79,13 +99,47 @@ fn on_crt_tv_add(
7999 BackgroundColor ( BLUE . into( ) ) ,
80100 IconClickTimer ( Timer :: from_seconds( 1.0 , TimerMode :: Once ) ) ,
81101) ]
82- #[ component( on_add = on_computer_icon_add ) ]
83- pub struct ComputerIcon ;
102+ #[ component( on_add = on_computer_cctv_icon_add ) ]
103+ pub struct ComputerCctvIcon ;
84104
85105#[ derive( Component ) ]
86106pub struct IconClickTimer ( pub Timer ) ;
87107
88- fn on_computer_icon_add (
108+ fn on_computer_rover_icon_add (
109+ mut world : DeferredWorld ,
110+ context : HookContext ,
111+ ) {
112+ let icon: Handle < Image > = world. resource :: < AssetServer > ( ) . load ( "icons/geometrica/save-block.png" ) ;
113+
114+ let icon_node = world. commands ( ) . spawn ( (
115+ Node {
116+ width : Val :: Auto ,
117+ height : Val :: Percent ( 75. ) ,
118+ ..default ( )
119+ } ,
120+ ImageNode :: new ( icon) ,
121+ ) ) . id ( ) ;
122+
123+ let text_node = world. commands ( ) . spawn ( (
124+ Node {
125+ width : Val :: Auto ,
126+ height : Val :: Percent ( 25. ) ,
127+ ..default ( )
128+ } ,
129+ Text :: new ( "ROVER" ) ,
130+ ) ) . id ( ) ;
131+
132+ world. commands ( )
133+ . entity ( context. entity )
134+ . observe ( icon_drag_observer)
135+ . observe ( icon_over)
136+ . observe ( icon_out)
137+ . observe ( rover_icon_double_click_observer)
138+ . add_child ( icon_node)
139+ . add_child ( text_node) ;
140+ }
141+
142+ fn on_computer_cctv_icon_add (
89143 mut world : DeferredWorld ,
90144 context : HookContext ,
91145) {
@@ -97,8 +151,6 @@ fn on_computer_icon_add(
97151 height : Val :: Percent ( 75. ) ,
98152 ..default ( )
99153 } ,
100- //BackgroundColor(GREEN.into()),
101- //Text::new("TEST"),
102154 ImageNode :: new ( icon) ,
103155 ) ) . id ( ) ;
104156
@@ -108,7 +160,6 @@ fn on_computer_icon_add(
108160 height : Val :: Percent ( 25. ) ,
109161 ..default ( )
110162 } ,
111- //BackgroundColor(GOLDENROD.into()),
112163 Text :: new ( "TEST" ) ,
113164 ) ) . id ( ) ;
114165
@@ -117,7 +168,7 @@ fn on_computer_icon_add(
117168 . observe ( icon_drag_observer)
118169 . observe ( icon_over)
119170 . observe ( icon_out)
120- . observe ( icon_double_click_observer )
171+ . observe ( cctv_icon_double_click_observer )
121172 . add_child ( icon_node)
122173 . add_child ( text_node) ;
123174}
@@ -228,7 +279,7 @@ fn on_computer_ui_node_add(
228279 . with_children ( |parent| {
229280 parent
230281 . spawn ( (
231- ComputerIcon ,
282+ ComputerRoverIcon ,
232283 ) ) ;
233284 parent
234285 . spawn ( (
@@ -261,24 +312,21 @@ fn display_time(
261312 mut clock_text_query : Query < & mut Text , With < ComputerClock > > ,
262313) {
263314 if let Ok ( mut clock_text) = clock_text_query. single_mut ( ) {
264- clock_text. 0 = format ! (
265- "{}" ,
266- clock. format_datetime( None )
267- ) ;
315+ clock_text. 0 = clock. format_datetime ( None ) . to_string ( ) ;
268316 }
269317}
270318
271319fn computer_interaction_observer (
272320 _trigger : On < InteractionEvent > ,
273321 mut commands : Commands ,
274- mut player_query : Query < ( & mut PlayerState , Entity ) , With < Player > > ,
322+ mut player_query : Query < & mut PlayerState , With < Player > > ,
275323 transform_query : Query < & GlobalTransform , Without < Player > > ,
276324 camera_query : Query < ( Entity , & Transform ) , With < PlayerCamera > > ,
277325 camera_target_query : Query < Entity , With < CameraTarget > > ,
278326 time : Res < Time > ,
279327) {
280328 trace ! ( "OBSERVER: computer_interaction_observer" ) ;
281- if let Ok ( ( mut player_state, player_entity ) ) = player_query. single_mut ( )
329+ if let Ok ( mut player_state) = player_query. single_mut ( )
282330 && let Ok ( target_entity) = camera_target_query. single ( )
283331 && let Ok ( target_transform) = transform_query. get ( target_entity)
284332 && let Ok ( ( camera_entity, camera_transform) ) = camera_query. single ( ) {
0 commit comments