This commit is contained in:
1 parent
d1a56f77cc
commit
0e7aed40f1
21 files changed
+1253
-19
No files matched your search
@@ -20,6 +20,10 @@ use crate::state::PlayPossession;
|
||||
use crate::viewport::actor_icons::ActorIconSettings;
|
||||
use crate::viewport::brush_edit::{BrushEditMode, BrushElementSelection};
|
||||
use crate::viewport::brush_tool::{BrushToolPhase, BrushToolState};
|
||||
use crate::viewport::physics_placement::{
|
||||
begin_physics_placement, request_physics_placement, PhysicsPlacementPhase,
|
||||
PhysicsPlacementRequest, PhysicsPlacementState,
|
||||
};
|
||||
use crate::viewport::terrain_paint::{TerrainPaintMode, TerrainPaintState};
|
||||
use crate::viewport::terrain_sculpt::{TerrainSculptMode, TerrainSculptState};
|
||||
use crate::viewport::{
|
||||
@@ -146,11 +150,12 @@ pub fn viewport_tab_ui(
|
||||
return;
|
||||
}
|
||||
|
||||
scene_view_overlay_toolbar(world, ui.ctx(), rect);
|
||||
scene_view_overlay_toolbar(world, ui.ctx(), rect, selected_entities);
|
||||
scene_view_selection_hud(world, ui.ctx(), rect, selected_entities);
|
||||
scene_view_brush_draw_hints(world, ui.ctx(), rect);
|
||||
scene_view_terrain_sculpt_hints(world, ui.ctx(), rect);
|
||||
scene_view_terrain_paint_hints(world, ui.ctx(), rect);
|
||||
scene_view_physics_placement_hud(world, ui.ctx(), rect);
|
||||
scene_view_render_badge(world, ui.ctx(), rect);
|
||||
scene_view_brush_mode_badge(world, ui.ctx(), rect);
|
||||
scene_view_volume_hud(world, ui.ctx(), rect);
|
||||
@@ -582,7 +587,12 @@ fn scene_view_volume_hud(world: &World, ctx: &egui::Context, scene_rect: egui::R
|
||||
});
|
||||
}
|
||||
|
||||
fn scene_view_overlay_toolbar(world: &mut World, ctx: &egui::Context, scene_rect: egui::Rect) {
|
||||
fn scene_view_overlay_toolbar(
|
||||
world: &mut World,
|
||||
ctx: &egui::Context,
|
||||
scene_rect: egui::Rect,
|
||||
selected_entities: &SelectedEntities,
|
||||
) {
|
||||
let mut options_open = world.resource::<ViewportUiState>().options_open;
|
||||
let mut shortcuts_open = world.resource::<ViewportUiState>().shortcuts_open;
|
||||
let terrain_selected = world
|
||||
@@ -737,6 +747,56 @@ fn scene_view_overlay_toolbar(world: &mut World, ctx: &egui::Context, scene_rect
|
||||
}
|
||||
}
|
||||
|
||||
let placement_active = world.resource::<PhysicsPlacementState>().active();
|
||||
ui.separator();
|
||||
if placement_active {
|
||||
let phase = world.resource::<PhysicsPlacementState>().phase;
|
||||
ui.label(
|
||||
egui::RichText::new(phase.label())
|
||||
.color(match phase {
|
||||
PhysicsPlacementPhase::Settled => SUCCESS,
|
||||
PhysicsPlacementPhase::TimedOut => WARNING,
|
||||
_ => SELECTION,
|
||||
})
|
||||
.strong()
|
||||
.small(),
|
||||
);
|
||||
if icon_button_small(
|
||||
ui,
|
||||
icons::CHECK,
|
||||
"Commit physics placement (Enter when settled)",
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
request_physics_placement(world, PhysicsPlacementRequest::Commit);
|
||||
}
|
||||
if icon_button_small(ui, icons::X, "Cancel physics placement (Esc)")
|
||||
.clicked()
|
||||
{
|
||||
request_physics_placement(world, PhysicsPlacementRequest::Cancel);
|
||||
}
|
||||
} else {
|
||||
let selected = selected_entities.iter().collect::<Vec<_>>();
|
||||
let can_start = !selected.is_empty();
|
||||
let clicked = ui
|
||||
.add_enabled(
|
||||
can_start,
|
||||
egui::Button::new(phosphor_icon(icons::HAND_ARROW_DOWN, 16.0)),
|
||||
)
|
||||
.on_hover_text(if can_start {
|
||||
"Release selected props into physics"
|
||||
} else {
|
||||
"Select one or more props to place with physics"
|
||||
})
|
||||
.clicked();
|
||||
if clicked && begin_physics_placement(world, selected).is_ok() {
|
||||
world.resource_mut::<TerrainSculptState>().stop();
|
||||
world.resource_mut::<TerrainPaintState>().stop();
|
||||
world.resource_mut::<BrushToolState>().cancel();
|
||||
world.resource_mut::<ViewportClick>().0 = None;
|
||||
}
|
||||
}
|
||||
|
||||
let sculpt_active = world.resource::<TerrainSculptState>().active;
|
||||
let paint_active = world.resource::<TerrainPaintState>().active;
|
||||
if terrain_selected.is_some() || sculpt_active || paint_active {
|
||||
@@ -950,6 +1010,66 @@ fn scene_view_overlay_toolbar(world: &mut World, ctx: &egui::Context, scene_rect
|
||||
world.resource_mut::<ViewportUiState>().shortcuts_open = shortcuts_open;
|
||||
}
|
||||
|
||||
fn scene_view_physics_placement_hud(world: &World, ctx: &egui::Context, scene_rect: egui::Rect) {
|
||||
let state = world.resource::<PhysicsPlacementState>();
|
||||
if !state.active() {
|
||||
let Some(error) = state.last_error.as_deref() else {
|
||||
return;
|
||||
};
|
||||
egui::Area::new(egui::Id::new("scene_view_physics_placement_error"))
|
||||
.fixed_pos(scene_rect.left_top() + egui::vec2(8.0, 52.0))
|
||||
.interactable(false)
|
||||
.show(ctx, |ui| {
|
||||
overlay_chip_frame().show(ui, |ui| {
|
||||
ui.label(
|
||||
egui::RichText::new("Physics placement unavailable")
|
||||
.color(ERROR)
|
||||
.strong(),
|
||||
);
|
||||
for line in error.lines().take(4) {
|
||||
ui.label(egui::RichText::new(line).color(TEXT_DIM).small());
|
||||
}
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
egui::Area::new(egui::Id::new("scene_view_physics_placement_hud"))
|
||||
.fixed_pos(scene_rect.left_top() + egui::vec2(8.0, 52.0))
|
||||
.interactable(false)
|
||||
.show(ctx, |ui| {
|
||||
overlay_chip_frame().show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(phosphor_icon(icons::HAND_ARROW_DOWN, 16.0).color(SELECTION));
|
||||
ui.label(
|
||||
egui::RichText::new(format!("Physics Placement / {}", state.phase.label()))
|
||||
.color(match state.phase {
|
||||
PhysicsPlacementPhase::Settled => SUCCESS,
|
||||
PhysicsPlacementPhase::TimedOut => WARNING,
|
||||
_ => SELECTION,
|
||||
})
|
||||
.strong(),
|
||||
);
|
||||
ui.label(
|
||||
egui::RichText::new(format!(
|
||||
"{} props / {:.1}s",
|
||||
state.selected_count,
|
||||
state.simulated_seconds()
|
||||
))
|
||||
.color(TEXT_DIM)
|
||||
.monospace()
|
||||
.small(),
|
||||
);
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
key_hint(ui, "Esc", "Cancel");
|
||||
key_hint(ui, "Enter", "Commit when settled");
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn scene_options_popover(
|
||||
world: &mut World,
|
||||
ctx: &egui::Context,
|
||||
|
||||
Reference in new issue
Block a user