Skip to content

Commit 46079b4

Browse files
committed
progress with ecs native window refactor
1 parent 2ec1902 commit 46079b4

18 files changed

Lines changed: 251 additions & 156 deletions

crates/bevy_animation_graph_editor/src/ui/actions/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use bevy::{
2222
},
2323
log::error,
2424
};
25-
use egui_dock::DockState;
2625
use event_tracks::{EventTrackAction, handle_event_track_action};
2726
use fsm::{FsmAction, handle_fsm_action};
2827
use graph::{GraphAction, handle_graph_action};
@@ -123,7 +122,7 @@ fn handle_view_action(
123122
}
124123
ViewAction::New(name) => {
125124
commands.queue(|world: &mut World| {
126-
let view_state = EditorViewUiState::init(world, name, DockState::new(vec![]));
125+
let view_state = EditorViewUiState::empty(world, name);
127126
let mut ui_state = world.resource_mut::<UiState>();
128127
ui_state.new_native_view(view_state);
129128
});

crates/bevy_animation_graph_editor/src/ui/actions/saving.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::{
44
UiState,
55
core::EguiWindow,
66
editor_windows::saving::{SaveWindow, SaveWindowAssetMeta},
7+
global_state::{ClearGlobalState, active_fsm::ActiveFsm, active_graph::ActiveGraph},
78
},
89
};
910
use bevy::{asset::UntypedAssetId, platform::collections::HashMap, prelude::*};
@@ -96,9 +97,9 @@ pub fn handle_save_graph(
9697
In(save_graph): In<SaveGraph>,
9798
asset_server: Res<AssetServer>,
9899
graph_assets: Res<Assets<AnimationGraph>>,
99-
mut ui_state: ResMut<UiState>,
100100
cli: Res<Cli>,
101101
registry: Res<AppTypeRegistry>,
102+
mut commands: Commands,
102103
) {
103104
let type_registry = registry.0.read();
104105
let graph = graph_assets.get(save_graph.asset_id).unwrap();
@@ -121,16 +122,16 @@ pub fn handle_save_graph(
121122
// editor selection.
122123
// Also delete the temporary asset
123124
if asset_server.get_path(save_graph.asset_id).is_none() {
124-
ui_state.global_state.graph_editor = None;
125+
commands.trigger(ClearGlobalState::<ActiveGraph>::default());
125126
}
126127
}
127128

128129
pub fn handle_save_fsm(
129130
In(save_fsm): In<SaveFsm>,
130131
asset_server: Res<AssetServer>,
131132
graph_assets: Res<Assets<StateMachine>>,
132-
mut ui_state: ResMut<UiState>,
133133
cli: Res<Cli>,
134+
mut commands: Commands,
134135
) {
135136
let fsm = graph_assets.get(save_fsm.asset_id).unwrap();
136137
let graph_serial = StateMachineSerial::from(fsm);
@@ -152,15 +153,13 @@ pub fn handle_save_fsm(
152153
// editor selection.
153154
// Also delete the temporary asset
154155
if asset_server.get_path(save_fsm.asset_id).is_none() {
155-
ui_state.global_state.fsm_editor = None;
156+
commands.trigger(ClearGlobalState::<ActiveFsm>::default());
156157
}
157158
}
158159

159160
pub fn handle_save_animation_clip(
160161
In(save_fsm): In<SaveClip>,
161-
asset_server: Res<AssetServer>,
162162
clip_assets: Res<Assets<GraphClip>>,
163-
mut ui_state: ResMut<UiState>,
164163
cli: Res<Cli>,
165164
) {
166165
let clip = clip_assets.get(save_fsm.asset_id).unwrap();
@@ -181,13 +180,6 @@ pub fn handle_save_animation_clip(
181180
ron::ser::PrettyConfig::default(),
182181
)
183182
.unwrap();
184-
185-
// If we just saved a newly created graph, unload the in-memory asset from the
186-
// editor selection.
187-
// Also delete the temporary asset
188-
if asset_server.get_path(save_fsm.asset_id).is_none() {
189-
ui_state.global_state.fsm_editor = None;
190-
}
191183
}
192184

193185
pub fn handle_save_colliders(

crates/bevy_animation_graph_editor/src/ui/global_state/active_fsm.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ use bevy::{
55
use bevy_animation_graph::core::state_machine::high_level::StateMachine;
66

77
use crate::ui::global_state::{
8-
RegisterGlobalState, SetOrInsertEvent, observe_clear_global_state, observe_set_or_insert_event,
8+
RegisterStateComponent, SetOrInsertEvent, observe_clear_global_state,
9+
observe_set_or_insert_event,
910
};
1011

1112
#[derive(Debug, Component, Default, Clone)]
1213
pub struct ActiveFsm {
1314
pub handle: Handle<StateMachine>,
1415
}
1516

16-
impl RegisterGlobalState for ActiveFsm {
17+
impl RegisterStateComponent for ActiveFsm {
1718
fn register(world: &mut World, _global_state_entity: Entity) {
1819
world.add_observer(observe_set_or_insert_event::<ActiveFsm, SetActiveFsm>);
1920
world.add_observer(observe_clear_global_state::<Self>);

crates/bevy_animation_graph_editor/src/ui/global_state/active_fsm_state.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ use bevy::{
44
};
55
use bevy_animation_graph::core::state_machine::high_level::{StateId, StateMachine};
66

7-
use crate::ui::global_state::{RegisterGlobalState, SetOrInsertEvent, observe_set_or_insert_event};
7+
use crate::ui::global_state::{
8+
RegisterStateComponent, SetOrInsertEvent, observe_set_or_insert_event,
9+
};
810

911
#[derive(Debug, Component, Default, Clone)]
1012
pub struct ActiveFsmState {
1113
pub handle: Handle<StateMachine>,
1214
pub state: StateId,
1315
}
1416

15-
impl RegisterGlobalState for ActiveFsmState {
17+
impl RegisterStateComponent for ActiveFsmState {
1618
fn register(world: &mut World, _global_state_entity: Entity) {
1719
world.add_observer(observe_set_or_insert_event::<ActiveFsmState, SetActiveFsmState>);
1820
}

crates/bevy_animation_graph_editor/src/ui/global_state/active_fsm_transition.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ use bevy::{
44
};
55
use bevy_animation_graph::core::state_machine::high_level::{StateMachine, TransitionId};
66

7-
use crate::ui::global_state::{RegisterGlobalState, SetOrInsertEvent, observe_set_or_insert_event};
7+
use crate::ui::global_state::{
8+
RegisterStateComponent, SetOrInsertEvent, observe_set_or_insert_event,
9+
};
810

911
#[derive(Debug, Component, Default, Clone)]
1012
pub struct ActiveFsmTransition {
1113
pub handle: Handle<StateMachine>,
1214
pub transition: TransitionId,
1315
}
1416

15-
impl RegisterGlobalState for ActiveFsmTransition {
17+
impl RegisterStateComponent for ActiveFsmTransition {
1618
fn register(world: &mut World, _global_state_entity: Entity) {
1719
world.add_observer(
1820
observe_set_or_insert_event::<ActiveFsmTransition, SetActiveFsmTransition>,

crates/bevy_animation_graph_editor/src/ui/global_state/active_graph.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ use bevy::{
44
};
55
use bevy_animation_graph::prelude::AnimationGraph;
66

7-
use crate::ui::global_state::{RegisterGlobalState, SetOrInsertEvent, observe_set_or_insert_event};
7+
use crate::ui::global_state::{
8+
RegisterStateComponent, SetOrInsertEvent, observe_set_or_insert_event,
9+
};
810

911
#[derive(Debug, Component, Default, Clone)]
1012
pub struct ActiveGraph {
1113
pub handle: Handle<AnimationGraph>,
1214
}
1315

14-
impl RegisterGlobalState for ActiveGraph {
16+
impl RegisterStateComponent for ActiveGraph {
1517
fn register(world: &mut World, _global_state_entity: Entity) {
1618
world.add_observer(observe_set_or_insert_event::<ActiveGraph, SetActiveGraph>);
1719
}

crates/bevy_animation_graph_editor/src/ui/global_state/active_graph_context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ use bevy::{
88
};
99
use bevy_animation_graph::prelude::GraphContextId;
1010

11-
use crate::ui::global_state::{GlobalState, RegisterGlobalState};
11+
use crate::ui::global_state::{GlobalState, RegisterStateComponent};
1212

1313
#[derive(Debug, Component, Clone, Default)]
1414
pub struct ActiveContexts {
1515
pub by_asset: HashMap<UntypedAssetId, (Entity, GraphContextId)>,
1616
}
1717

18-
impl RegisterGlobalState for ActiveContexts {
18+
impl RegisterStateComponent for ActiveContexts {
1919
fn register(world: &mut World, global_state_entity: Entity) {
2020
world
2121
.entity_mut(global_state_entity)

crates/bevy_animation_graph_editor/src/ui/global_state/active_graph_node.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use bevy_animation_graph::{
77
prelude::AnimationGraph,
88
};
99

10-
use crate::ui::global_state::{RegisterGlobalState, SetOrInsertEvent, observe_set_or_insert_event};
10+
use crate::ui::global_state::{
11+
RegisterStateComponent, SetOrInsertEvent, observe_set_or_insert_event,
12+
};
1113

1214
#[derive(Debug, Component, Default, Clone)]
1315
pub struct ActiveGraphNode {
@@ -16,7 +18,7 @@ pub struct ActiveGraphNode {
1618
pub selected_pin: Option<PinId>,
1719
}
1820

19-
impl RegisterGlobalState for ActiveGraphNode {
21+
impl RegisterStateComponent for ActiveGraphNode {
2022
fn register(world: &mut World, _global_state_entity: Entity) {
2123
world.add_observer(observe_set_or_insert_event::<ActiveGraphNode, SetActiveGraphNode>);
2224
}

crates/bevy_animation_graph_editor/src/ui/global_state/active_scene.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ use bevy::{
55
use bevy_animation_graph::prelude::AnimatedScene;
66

77
use crate::ui::global_state::{
8-
RegisterGlobalState, SetOrInsertEvent, observe_clear_global_state, observe_set_or_insert_event,
8+
RegisterStateComponent, SetOrInsertEvent, observe_clear_global_state,
9+
observe_set_or_insert_event,
910
};
1011

1112
#[derive(Debug, Component, Default, Clone)]
1213
pub struct ActiveScene {
1314
pub handle: Handle<AnimatedScene>,
1415
}
1516

16-
impl RegisterGlobalState for ActiveScene {
17+
impl RegisterStateComponent for ActiveScene {
1718
fn register(world: &mut World, _global_state_entity: Entity) {
1819
world.add_observer(observe_set_or_insert_event::<ActiveScene, SetActiveScene>);
1920
world.add_observer(observe_clear_global_state::<Self>);

crates/bevy_animation_graph_editor/src/ui/global_state/inspector_selection.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use bevy::ecs::{component::Component, entity::Entity, event::Event, world::World};
22

3-
use crate::ui::global_state::{RegisterGlobalState, SetOrInsertEvent, observe_set_or_insert_event};
3+
use crate::ui::global_state::{
4+
RegisterStateComponent, SetOrInsertEvent, observe_set_or_insert_event,
5+
};
46

57
#[derive(Debug, Component, Default, Clone, Hash)]
68
pub enum InspectorSelection {
@@ -17,7 +19,7 @@ pub enum InspectorSelection {
1719
Nothing,
1820
}
1921

20-
impl RegisterGlobalState for InspectorSelection {
22+
impl RegisterStateComponent for InspectorSelection {
2123
fn register(world: &mut World, global_state_entity: Entity) {
2224
world
2325
.entity_mut(global_state_entity)

0 commit comments

Comments
 (0)