This commit is contained in:
1 parent
ed21bcc52d
commit
293811aecd
13 files changed
+1026
-5
No files matched your search
@@ -20,6 +20,7 @@ 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::terrain_sculpt::{TerrainSculptMode, TerrainSculptState};
|
||||
use crate::viewport::{
|
||||
material_drop::is_surface_asset_selection, snap_translation, viewport_ground_position,
|
||||
EditorViewportMode, MaterialDropState, ViewportDisplayMode, ViewportSettings,
|
||||
@@ -41,6 +42,7 @@ use super::widgets::{
|
||||
pub struct ViewportUiState {
|
||||
pub options_open: bool,
|
||||
pub shortcuts_open: bool,
|
||||
pub toolbar_rect: Option<egui::Rect>,
|
||||
}
|
||||
|
||||
const VIEWPORT_TOOLTIP: &str = "RMB + WASD/QE: fly | MMB: pan | Scroll: dolly\nW/E/R: gizmo | X: world/local | F: focus | G: game view | Ctrl+G: grid\nTab: cycle overlapping picks | Play/Pause/Stop: main toolbar (F5 / F6)";
|
||||
@@ -146,6 +148,7 @@ pub fn viewport_tab_ui(
|
||||
scene_view_overlay_toolbar(world, ui.ctx(), rect);
|
||||
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_render_badge(world, ui.ctx(), rect);
|
||||
scene_view_brush_mode_badge(world, ui.ctx(), rect);
|
||||
scene_view_volume_hud(world, ui.ctx(), rect);
|
||||
@@ -304,6 +307,48 @@ fn scene_view_brush_draw_hints(world: &World, ctx: &egui::Context, scene_rect: e
|
||||
});
|
||||
}
|
||||
|
||||
fn scene_view_terrain_sculpt_hints(world: &World, ctx: &egui::Context, scene_rect: egui::Rect) {
|
||||
let Some(tool) = world.get_resource::<TerrainSculptState>() else {
|
||||
return;
|
||||
};
|
||||
if !tool.active {
|
||||
return;
|
||||
}
|
||||
egui::Area::new(egui::Id::new("scene_view_terrain_sculpt_hints"))
|
||||
.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(
|
||||
egui::RichText::new(format!("Terrain {}", tool.mode.label()))
|
||||
.color(SELECTION)
|
||||
.strong(),
|
||||
);
|
||||
ui.label(
|
||||
egui::RichText::new(format!("R {:.1}m", tool.radius))
|
||||
.color(TEXT_DIM)
|
||||
.monospace()
|
||||
.small(),
|
||||
);
|
||||
ui.label(
|
||||
egui::RichText::new(format!("S {:.2}m", tool.strength))
|
||||
.color(SUCCESS)
|
||||
.monospace()
|
||||
.small(),
|
||||
);
|
||||
});
|
||||
ui.add_space(4.0);
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
key_hint(ui, "LMB Drag", "Sculpt");
|
||||
key_hint(ui, "Esc", "Cancel stroke / close");
|
||||
key_hint(ui, "RMB", "Cancel stroke / close");
|
||||
key_hint(ui, "Ctrl+Z", "Undo stroke");
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn key_hint(ui: &mut egui::Ui, key: &str, label: &str) {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(
|
||||
@@ -492,8 +537,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) {
|
||||
let mut options_open = world.resource::<ViewportUiState>().options_open;
|
||||
let mut shortcuts_open = world.resource::<ViewportUiState>().shortcuts_open;
|
||||
let terrain_selected = world
|
||||
.resource::<crate::selection::SelectedEntity>()
|
||||
.0
|
||||
.filter(|entity| world.get::<shared::TerrainDesc>(*entity).is_some());
|
||||
|
||||
egui::Area::new(egui::Id::new("scene_view_toolbar"))
|
||||
let toolbar_response = egui::Area::new(egui::Id::new("scene_view_toolbar"))
|
||||
.fixed_pos(scene_rect.left_top() + egui::vec2(6.0, 6.0))
|
||||
.interactable(true)
|
||||
.show(ctx, |ui| {
|
||||
@@ -622,6 +671,83 @@ fn scene_view_overlay_toolbar(world: &mut World, ctx: &egui::Context, scene_rect
|
||||
}
|
||||
}
|
||||
|
||||
let sculpt_active = world.resource::<TerrainSculptState>().active;
|
||||
if terrain_selected.is_some() || sculpt_active {
|
||||
ui.separator();
|
||||
let stroking = world.resource::<TerrainSculptState>().is_stroking();
|
||||
let sculpt_button_clicked = tool_button_accent(
|
||||
ui,
|
||||
icons::MOUNTAINS,
|
||||
sculpt_active,
|
||||
if sculpt_active {
|
||||
"Close terrain sculpt tool"
|
||||
} else {
|
||||
"Sculpt selected terrain"
|
||||
},
|
||||
)
|
||||
.clicked();
|
||||
if sculpt_button_clicked {
|
||||
world.resource_mut::<ViewportClick>().0 = None;
|
||||
}
|
||||
if sculpt_button_clicked && !stroking {
|
||||
let state = &mut *world.resource_mut::<TerrainSculptState>();
|
||||
if state.active {
|
||||
state.stop();
|
||||
} else if let Some(entity) = terrain_selected {
|
||||
state.start(entity);
|
||||
}
|
||||
let active = state.active;
|
||||
if active {
|
||||
world.resource_mut::<BrushToolState>().cancel();
|
||||
world
|
||||
.resource_mut::<crate::operators::ActiveOperator>()
|
||||
.status = Some(crate::operators::OperatorStatus {
|
||||
id: "terrain.sculpt".to_string(),
|
||||
label: "Terrain Sculpt".to_string(),
|
||||
phase: crate::operators::OperatorPhase::Preview,
|
||||
hint: "LMB drag sculpts; Esc or RMB cancels".to_string(),
|
||||
warnings: Vec::new(),
|
||||
});
|
||||
}
|
||||
}
|
||||
if sculpt_active {
|
||||
let mut mode = world.resource::<TerrainSculptState>().mode;
|
||||
for candidate in [
|
||||
TerrainSculptMode::Raise,
|
||||
TerrainSculptMode::Lower,
|
||||
TerrainSculptMode::Flatten,
|
||||
TerrainSculptMode::Smooth,
|
||||
TerrainSculptMode::Noise,
|
||||
] {
|
||||
ui.selectable_value(&mut mode, candidate, candidate.label())
|
||||
.on_hover_text(format!("{} terrain", candidate.label()));
|
||||
}
|
||||
let mut radius = world.resource::<TerrainSculptState>().radius;
|
||||
let mut strength = world.resource::<TerrainSculptState>().strength;
|
||||
ui.add(
|
||||
egui::DragValue::new(&mut radius)
|
||||
.range(0.25..=128.0)
|
||||
.speed(0.1)
|
||||
.prefix("R ")
|
||||
.suffix(" m"),
|
||||
)
|
||||
.on_hover_text("Brush radius");
|
||||
ui.add(
|
||||
egui::DragValue::new(&mut strength)
|
||||
.range(0.01..=20.0)
|
||||
.speed(0.05)
|
||||
.prefix("S ")
|
||||
.suffix(" m"),
|
||||
)
|
||||
.on_hover_text("Height strength per dab");
|
||||
let mut state = world.resource_mut::<TerrainSculptState>();
|
||||
state.mode = mode;
|
||||
state.radius = radius;
|
||||
state.strength = strength;
|
||||
state.clamp_settings();
|
||||
}
|
||||
}
|
||||
|
||||
let clean_game_view = world.resource::<ViewportDisplayMode>().clean_game_view;
|
||||
if tool_button(
|
||||
ui,
|
||||
@@ -649,6 +775,13 @@ fn scene_view_overlay_toolbar(world: &mut World, ctx: &egui::Context, scene_rect
|
||||
});
|
||||
});
|
||||
|
||||
let toolbar_clicked = toolbar_response.response.contains_pointer()
|
||||
&& ctx.input(|input| input.pointer.button_clicked(egui::PointerButton::Primary));
|
||||
if toolbar_clicked {
|
||||
world.resource_mut::<ViewportClick>().0 = None;
|
||||
}
|
||||
world.resource_mut::<ViewportUiState>().toolbar_rect = Some(toolbar_response.response.rect);
|
||||
|
||||
if options_open {
|
||||
scene_options_popover(world, ctx, scene_rect, &mut options_open);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user