@@ -5,8 +5,8 @@ use pyri_state::extra::entity_scope::StateScope;
5
5
use pyri_state:: prelude:: * ;
6
6
7
7
use crate :: core:: pause:: Pause ;
8
- use crate :: core:: UpdateSet ;
9
8
use crate :: game:: actor:: player:: IsPlayer ;
9
+ use crate :: game:: combat:: death:: OnDeath ;
10
10
use crate :: screen:: fade_out;
11
11
use crate :: screen:: playing:: PlayingAssets ;
12
12
use crate :: screen:: playing:: PlayingMenu ;
@@ -15,29 +15,32 @@ use crate::ui::prelude::*;
15
15
use crate :: util:: prelude:: * ;
16
16
17
17
pub ( super ) fn plugin ( app : & mut App ) {
18
+ app. observe ( detect_defeat) ;
19
+
18
20
app. add_systems (
19
21
StateFlush ,
20
22
PlayingMenu :: Defeat . on_edge ( Pause :: disable, ( Pause :: enable_default, open_defeat_menu) ) ,
21
23
) ;
24
+ }
22
25
23
- app. add_systems (
24
- Update ,
25
- PlayingMenu :: Defeat
26
- . enter ( )
27
- . in_set ( UpdateSet :: SyncLate )
28
- . run_if ( detect_defeat) ,
29
- ) ;
26
+ fn detect_defeat (
27
+ trigger : Trigger < OnDeath > ,
28
+ player_query : Query < ( ) , With < IsPlayer > > ,
29
+ mut playing_menu : NextMut < PlayingMenu > ,
30
+ ) {
31
+ let entity = r ! ( trigger. get_entity( ) ) ;
32
+ if !player_query. contains ( entity) {
33
+ return ;
34
+ }
35
+
36
+ playing_menu. enter ( PlayingMenu :: Defeat ) ;
30
37
}
31
38
32
39
fn open_defeat_menu ( mut commands : Commands , ui_root : Res < UiRoot > ) {
33
40
commands. spawn_with ( defeat_overlay) . set_parent ( ui_root. body ) ;
34
41
commands. spawn_with ( defeat_menu) . set_parent ( ui_root. body ) ;
35
42
}
36
43
37
- pub fn detect_defeat ( player_query : Query < Entity , With < IsPlayer > > ) -> bool {
38
- player_query. is_empty ( )
39
- }
40
-
41
44
fn defeat_overlay ( mut entity : EntityWorldMut ) {
42
45
entity. add ( widget:: blocking_overlay) . insert ( (
43
46
Name :: new ( "DefeatOverlay" ) ,
@@ -126,7 +129,9 @@ fn restart_button(mut entity: EntityWorldMut) {
126
129
127
130
fn quit_to_title_button ( mut entity : EntityWorldMut ) {
128
131
entity. add ( widget:: menu_button ( "Quit to title" ) ) . insert ( (
129
- On :: < Pointer < Click > > :: run ( Screen :: Title . enter ( ) ) ,
132
+ On :: < Pointer < Click > > :: run ( |mut commands : Commands | {
133
+ commands. spawn_with ( fade_out ( Screen :: Title ) ) ;
134
+ } ) ,
130
135
Style {
131
136
height : Vw ( 9.0 ) ,
132
137
width : Vw ( 38.0 ) ,
0 commit comments