object layer
This commit is contained in:
+27
-6
@@ -39,13 +39,15 @@ pub(crate) struct EditorState {
|
||||
pub(crate) selected_object: Option<usize>,
|
||||
/// Whether the glyph picker is open for editing the selected object's glyph.
|
||||
pub(crate) object_glyph_picker_open: bool,
|
||||
/// Local copy of the selected object's cell glyph for the picker to edit.
|
||||
/// Local copy of the selected object's glyph for the picker to edit.
|
||||
///
|
||||
/// Kept separate from `board.cells` to avoid a borrow conflict: `glyph_picker::show`
|
||||
/// takes both `&mut Glyph` (edit target) and `&[(Glyph, Archetype)]` (board palette),
|
||||
/// and those can't both alias `board.cells`. This copy is written back to the board
|
||||
/// each frame while an object is selected.
|
||||
/// Kept separate from `board.objects` to avoid a borrow conflict while the
|
||||
/// glyph picker holds `&mut Glyph` and the board is also borrowed. Written
|
||||
/// back to `board.objects[i].glyph` each frame while an object is selected.
|
||||
pub(crate) object_editing_glyph: Glyph,
|
||||
/// When `true`, the next board click in the Objects tab places a new object.
|
||||
/// Set by the "Add Object" button; cleared after placement or on tab switch.
|
||||
pub(crate) placing_object: bool,
|
||||
}
|
||||
|
||||
impl EditorState {
|
||||
@@ -61,6 +63,7 @@ impl EditorState {
|
||||
selected_object: None,
|
||||
object_glyph_picker_open: false,
|
||||
object_editing_glyph: Glyph::player(), // overwritten on first selection
|
||||
placing_object: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -134,9 +137,27 @@ pub(crate) fn show_editor_panel(
|
||||
}
|
||||
|
||||
EditorTab::Objects => {
|
||||
// "Add Object" toggles placement mode; next board click places a new object.
|
||||
let add_label = if editor.placing_object {
|
||||
"Cancel Add"
|
||||
} else {
|
||||
"Add Object"
|
||||
};
|
||||
if ui.button(add_label).clicked() {
|
||||
editor.placing_object = !editor.placing_object;
|
||||
editor.selected_object = None;
|
||||
}
|
||||
if editor.placing_object {
|
||||
ui.label("Click on the board to place.");
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
|
||||
match editor.selected_object {
|
||||
None => {
|
||||
ui.label("Click an object on the board to select it.");
|
||||
if !editor.placing_object {
|
||||
ui.label("Click an object on the board to select it.");
|
||||
}
|
||||
}
|
||||
Some(i) => {
|
||||
// Collect sorted script names before taking a mutable borrow on objects.
|
||||
|
||||
Reference in New Issue
Block a user