@@ -6,7 +6,7 @@ use bevy::{
66use bevy_aseprite_ultra:: prelude:: * ;
77
88use crate :: {
9- gameplay:: { FactorySystems , structure:: assets:: StructureDef } ,
9+ gameplay:: { FactorySystems , structure:: assets:: StructureDef , world :: tilemap :: TileClicked } ,
1010 screens:: Screen ,
1111} ;
1212
@@ -43,6 +43,11 @@ pub fn plugin(app: &mut App) {
4343 highlight_selected_slot. in_set ( FactorySystems :: UI ) ,
4444 ) ,
4545 ) ;
46+
47+ app. add_systems (
48+ PostUpdate ,
49+ deselect_on_use. run_if ( on_message :: < TileClicked > ) ,
50+ ) ;
4651}
4752
4853#[ derive( SystemParam ) ]
@@ -121,6 +126,10 @@ pub enum HotbarActionKind {
121126#[ reflect( Component ) ]
122127struct HotbarShortcut ( KeyCode ) ;
123128
129+ #[ derive( Component , Reflect , Debug ) ]
130+ #[ reflect( Component ) ]
131+ struct HotbarPersistAfterUse ;
132+
124133fn spawn_hotbar ( mut commands : Commands ) {
125134 commands. spawn ( (
126135 Name :: new ( "Hotbar" ) ,
@@ -200,6 +209,7 @@ fn assign_hotbar_paths(
200209 ChildOf ( hotbar_slot) ,
201210 HotbarActionOf ( hotbar_slot) ,
202211 HotbarActionKind :: PlacePath ,
212+ HotbarPersistAfterUse ,
203213 Pickable :: IGNORE ,
204214 Node :: default ( ) ,
205215 children ! [ (
@@ -252,3 +262,23 @@ fn select_on_keyboard_shortcuts(
252262 }
253263 }
254264}
265+
266+ fn deselect_on_use (
267+ mut selector : HotbarSelector ,
268+ hotbar_actions : Query < & HotbarAction > ,
269+ persisted_actions : Query < Entity , With < HotbarPersistAfterUse > > ,
270+ ) {
271+ let Some ( selected) = selector. selection . 0 else {
272+ return ;
273+ } ;
274+
275+ let Ok ( HotbarAction ( action) ) = hotbar_actions. get ( selected) else {
276+ return ;
277+ } ;
278+
279+ if persisted_actions. contains ( * action) {
280+ return ;
281+ }
282+
283+ selector. select ( None ) ;
284+ }
0 commit comments