Add regression tests for prop attachment, centering, and editor UX
- Implemented test_phase9a_prop_attach.gd to validate anchor schema, alignment math, and preview isolation. - Implemented test_phase9b_prop_centering.gd to check canonical origin presentation, bounds, centering, and save threshold. - Implemented test_phase9c_prop_editor_ux.gd to assess the user experience in the prop editor, including anchor renaming and UI responsiveness. - Added corresponding .uid files for each test. - Created sync_sources.py script to manage markdown file synchronization with the notebook. - Added .gitignore for virtual environment files.
This commit is contained in:
+420
-32
@@ -16,20 +16,25 @@ const PropBlockScript := preload("res://scripts/prop_block.gd")
|
||||
const PropCanvasScript := preload("res://scripts/prop_canvas.gd")
|
||||
const PropThumbnailScript := preload("res://scripts/thumbnails/prop_thumbnail.gd")
|
||||
const ThumbnailCacheScript := preload("res://scripts/thumbnails/thumbnail_cache.gd")
|
||||
const PropAnchorDataScript := preload("res://scripts/prop_anchor_data.gd")
|
||||
const PropAttachPreviewScene := preload("res://scenes/prop_attach_preview.tscn")
|
||||
|
||||
const PRESET_LABELS: PackedStringArray = ["None", "Wood", "Rubber", "Cardboard", "Metal"]
|
||||
const PRIMITIVE_IDS: PackedStringArray = ["box", "plank", "triangle", "line", "circle"]
|
||||
const PRIMITIVE_LABELS: PackedStringArray = ["Box", "Plank", "Triangle", "Line", "Circle"]
|
||||
const EDITABLE_ROLE_STRINGS: PackedStringArray = ["grip", "emitter", "impact", "mount", "custom"]
|
||||
|
||||
# Kid-facing mode labels/emoji (Round 3); index == PropCanvas.EditMode.
|
||||
const MODE_LABELS: PackedStringArray = ["Arrange", "Reshape"]
|
||||
const MODE_EMOJI: PackedStringArray = ["🖐️", "✏️"]
|
||||
const MODE_LABELS: PackedStringArray = ["Arrange", "Reshape", "Attach"]
|
||||
const MODE_EMOJI: PackedStringArray = ["🖐️", "✏️", "📌"]
|
||||
|
||||
const UNTITLED_NAME: String = "Untitled"
|
||||
const AUTOSAVE_PATH: String = "user://prop_editor_autosave.prop"
|
||||
const AUTOSAVE_DEBOUNCE: float = 1.0
|
||||
const SETTINGS_PATH: String = "user://prop_editor_settings.json"
|
||||
const RECENT_MAX: int = 5
|
||||
const OFF_ORIGIN_WARNING_MIN_DISTANCE: float = 1024.0
|
||||
const OFF_ORIGIN_WARNING_BOUNDS_MULTIPLIER: float = 2.0
|
||||
|
||||
const MENU_NEW := 0
|
||||
const MENU_LOAD := 2
|
||||
@@ -67,6 +72,11 @@ static func update_recent_list(list: Array, path: String, max_count: int = RECEN
|
||||
result.resize(max_count)
|
||||
return result
|
||||
|
||||
static func should_warn_off_origin(has_geometry: bool, bounds: Rect2) -> bool:
|
||||
if not has_geometry: return false
|
||||
var threshold: float = maxf(OFF_ORIGIN_WARNING_MIN_DISTANCE, OFF_ORIGIN_WARNING_BOUNDS_MULTIPLIER * bounds.size.length())
|
||||
return bounds.get_center().length() > threshold
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# On-ready node references
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -76,6 +86,11 @@ static func update_recent_list(list: Array, path: String, max_count: int = RECEN
|
||||
@onready var _prop_name_edit: LineEdit = %PropNameEdit
|
||||
@onready var _canvas: PropCanvas = %PropCanvas
|
||||
@onready var _mode_bar: HBoxContainer = %ModeBar
|
||||
@onready var _attach_tools: FlowContainer = %AttachTools
|
||||
@onready var _canvas_workspace: HSplitContainer = %CanvasWorkspace
|
||||
@onready var _main_layout: HSplitContainer = %MainLayout
|
||||
@onready var _canvas_panel: PanelContainer = %CanvasPanel
|
||||
@onready var _inspector_column: PanelContainer = %InspectorColumn
|
||||
@onready var _inspector_list: VBoxContainer = %InspectorList
|
||||
@onready var _save_dialog: FileDialog = %SaveDialog
|
||||
@onready var _load_dialog: FileDialog = %LoadDialog
|
||||
@@ -92,12 +107,15 @@ var _material_preset: int = PropBlockScript.MaterialPreset.NONE
|
||||
var _current_path: String = ""
|
||||
var _dirty: bool = false
|
||||
var _clipboard: Dictionary = {}
|
||||
var _anchors: Dictionary = PropAnchorDataScript.default_anchors()
|
||||
var _selected_anchor_id: String = ""
|
||||
var _thumb: PropThumbnail
|
||||
var _thumb_cache: ThumbnailCache
|
||||
var _ui_theme: Theme
|
||||
|
||||
# Inspector controls
|
||||
var _preset_option: OptionButton
|
||||
var _material_section: VBoxContainer
|
||||
var _mass_label: Label
|
||||
var _friction_label: Label
|
||||
var _bounce_label: Label
|
||||
@@ -119,19 +137,42 @@ var _updating_inspector: bool = false
|
||||
# Grid settings dialog (removed Round 4 - replaced by top-right controls)
|
||||
var _grid_spin: SpinBox
|
||||
var _snap_check: CheckBox
|
||||
var _center_prop_button: Button
|
||||
|
||||
# Edit-mode toolbar (Round 2/3)
|
||||
var _mode_group: ButtonGroup
|
||||
var _move_button: Button
|
||||
var _points_button: Button
|
||||
var _attach_button: Button
|
||||
|
||||
# Add-shape inspector section (hidden in Reshape mode, Round 3)
|
||||
var _add_section: VBoxContainer
|
||||
var _anchor_section: VBoxContainer
|
||||
var _anchor_list: ItemList
|
||||
var _anchor_role: OptionButton
|
||||
var _anchor_hand: OptionButton
|
||||
var _anchor_x: SpinBox
|
||||
var _anchor_y: SpinBox
|
||||
var _anchor_rotation: SpinBox
|
||||
var _anchor_z: SpinBox
|
||||
var _rename_anchor_button: Button
|
||||
var _delete_anchor_button: Button
|
||||
var _attach_preview: Control
|
||||
var _show_preview_check: CheckBox
|
||||
var _inactive_anchors_check: CheckBox
|
||||
var _rename_anchor_dialog: ConfirmationDialog
|
||||
var _rename_anchor_edit: LineEdit
|
||||
var _rename_anchor_source_id: String = ""
|
||||
var _last_canvas_mode: int = PropCanvasScript.EditMode.TRANSFORM
|
||||
var _inspector_split_initialized: bool = false
|
||||
|
||||
# Exit/new dialog + autosave (Round 3/4)
|
||||
var _exit_dialog: ConfirmationDialog
|
||||
var _off_origin_save_dialog: ConfirmationDialog
|
||||
var _pending_quit: bool = false
|
||||
var _pending_new: bool = false
|
||||
var _pending_save_path: String = ""
|
||||
var _pending_save_with_thumbnail: bool = true
|
||||
var _autosave_remaining: float = 0.0
|
||||
|
||||
# Recent props (Round 5)
|
||||
@@ -156,6 +197,12 @@ func _ready() -> void:
|
||||
_build_mode_toolbar()
|
||||
_build_top_right_controls()
|
||||
_build_inspector()
|
||||
_build_attach_tools()
|
||||
_attach_preview = PropAttachPreviewScene.instantiate() as Control
|
||||
_canvas_workspace.add_child(_attach_preview)
|
||||
_apply_control_theme(_attach_preview)
|
||||
_attach_preview.call("set_ui_hit_target_height", float(_theme.button_min_height()))
|
||||
_attach_preview.visible = false
|
||||
_setup_dialogs()
|
||||
|
||||
_canvas.shape_changed.connect(_on_canvas_shape_changed)
|
||||
@@ -163,10 +210,16 @@ func _ready() -> void:
|
||||
_canvas.shape_copy_requested.connect(_on_canvas_copy_requested)
|
||||
_canvas.paste_from_context_requested.connect(_on_canvas_paste_requested)
|
||||
_canvas.mode_changed.connect(_on_canvas_mode_changed)
|
||||
_canvas.anchors_changed.connect(_on_canvas_anchors_changed)
|
||||
_canvas.anchor_selected.connect(_on_canvas_anchor_selected)
|
||||
_canvas.set_grid_size(_theme.grid_size())
|
||||
_canvas.set_snap_enabled(false)
|
||||
_canvas.set_has_clipboard(false)
|
||||
_canvas.set_context_menu_font_size(_theme.font_context_menu())
|
||||
_canvas.set_anchor_data(_anchors)
|
||||
var origin_marker_color: Color = _theme.text_muted_color()
|
||||
origin_marker_color.a = 0.75
|
||||
_canvas.set_origin_marker_color(origin_marker_color)
|
||||
|
||||
_prop_name_edit.text_changed.connect(_on_name_changed)
|
||||
_prop_name_edit.add_theme_font_size_override("font_size", _theme.font_prop_name())
|
||||
@@ -180,6 +233,9 @@ func _ready() -> void:
|
||||
_sync_mode_controls(_canvas.get_edit_mode())
|
||||
_update_save_status()
|
||||
_update_cursor_coords()
|
||||
_canvas.call_deferred("reset_view")
|
||||
call_deferred("_initialize_inspector_split")
|
||||
_refresh_center_prop_button()
|
||||
_check_autosave_recovery()
|
||||
|
||||
|
||||
@@ -233,10 +289,13 @@ func _build_mode_toolbar() -> void:
|
||||
_mode_group = ButtonGroup.new()
|
||||
_move_button = _make_mode_button(PropCanvasScript.EditMode.TRANSFORM)
|
||||
_points_button = _make_mode_button(PropCanvasScript.EditMode.POINTS)
|
||||
_attach_button = _make_mode_button(PropCanvasScript.EditMode.ATTACH)
|
||||
_move_button.pressed.connect(_on_move_mode_pressed)
|
||||
_points_button.pressed.connect(_on_points_mode_pressed)
|
||||
_attach_button.pressed.connect(_on_attach_mode_pressed)
|
||||
_move_button.theme = _ui_theme
|
||||
_points_button.theme = _ui_theme
|
||||
_attach_button.theme = _ui_theme
|
||||
|
||||
|
||||
func _make_mode_button(mode: int) -> Button:
|
||||
@@ -261,27 +320,62 @@ func _on_move_mode_pressed() -> void:
|
||||
func _on_points_mode_pressed() -> void:
|
||||
_canvas.set_edit_mode(PropCanvasScript.EditMode.POINTS)
|
||||
|
||||
func _on_attach_mode_pressed() -> void:
|
||||
_canvas.set_edit_mode(PropCanvasScript.EditMode.ATTACH)
|
||||
|
||||
|
||||
func _on_canvas_mode_changed(mode: int) -> void:
|
||||
var entering_attach: bool = mode == PropCanvasScript.EditMode.ATTACH and _last_canvas_mode != PropCanvasScript.EditMode.ATTACH
|
||||
if entering_attach and _show_preview_check != null:
|
||||
_show_preview_check.set_pressed_no_signal(true)
|
||||
_last_canvas_mode = mode
|
||||
_sync_mode_buttons(mode)
|
||||
_sync_mode_controls(mode)
|
||||
|
||||
|
||||
func _sync_mode_buttons(mode: int) -> void:
|
||||
if _move_button == null or _points_button == null:
|
||||
if _move_button == null or _points_button == null or _attach_button == null:
|
||||
return
|
||||
_move_button.set_pressed_no_signal(mode == PropCanvasScript.EditMode.TRANSFORM)
|
||||
_points_button.set_pressed_no_signal(mode == PropCanvasScript.EditMode.POINTS)
|
||||
_attach_button.set_pressed_no_signal(mode == PropCanvasScript.EditMode.ATTACH)
|
||||
var accent: Color = _theme.accent_color()
|
||||
_move_button.add_theme_color_override("font_pressed_color", accent)
|
||||
_points_button.add_theme_color_override("font_pressed_color", accent)
|
||||
_attach_button.add_theme_color_override("font_pressed_color", accent)
|
||||
|
||||
|
||||
func _sync_mode_controls(mode: int) -> void:
|
||||
if _attach_tools != null:
|
||||
_attach_tools.visible = mode == PropCanvasScript.EditMode.ATTACH
|
||||
if _add_section != null:
|
||||
_add_section.visible = mode != PropCanvasScript.EditMode.POINTS
|
||||
_add_section.visible = mode == PropCanvasScript.EditMode.TRANSFORM
|
||||
if _delete_button != null:
|
||||
_delete_button.visible = mode != PropCanvasScript.EditMode.POINTS
|
||||
_delete_button.visible = mode == PropCanvasScript.EditMode.TRANSFORM
|
||||
if _shape_section != null:
|
||||
_shape_section.visible = mode != PropCanvasScript.EditMode.ATTACH and _canvas.get_selected_index() >= 0
|
||||
if _material_section != null:
|
||||
_material_section.visible = mode != PropCanvasScript.EditMode.ATTACH
|
||||
if _anchor_section != null:
|
||||
_anchor_section.visible = mode == PropCanvasScript.EditMode.ATTACH
|
||||
if _attach_preview != null:
|
||||
_attach_preview.visible = mode == PropCanvasScript.EditMode.ATTACH and (_show_preview_check == null or _show_preview_check.button_pressed)
|
||||
if _attach_preview.has_method("set_document"):
|
||||
_attach_preview.call("set_document", _canvas.get_shape_data(), _anchors, _selected_anchor_id)
|
||||
|
||||
func _build_attach_tools() -> void:
|
||||
_show_preview_check = CheckBox.new()
|
||||
_show_preview_check.text = "Show Stickman Preview"
|
||||
_show_preview_check.button_pressed = true
|
||||
_show_preview_check.toggled.connect(func(_enabled: bool) -> void: _sync_mode_controls(_canvas.get_edit_mode()))
|
||||
_attach_tools.add_child(_show_preview_check)
|
||||
_inactive_anchors_check = CheckBox.new()
|
||||
_inactive_anchors_check.text = "Show Other Markers"
|
||||
_inactive_anchors_check.button_pressed = true
|
||||
_inactive_anchors_check.toggled.connect(func(enabled: bool) -> void:
|
||||
_canvas.set_show_inactive_anchors(enabled)
|
||||
_canvas.set_show_origin_marker(enabled))
|
||||
_attach_tools.add_child(_inactive_anchors_check)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -322,6 +416,18 @@ func _build_control_theme() -> void:
|
||||
_ui_theme.set_stylebox("hover", "Button", panel_dark)
|
||||
_ui_theme.set_stylebox("pressed", "Button", panel_pressed)
|
||||
_ui_theme.set_stylebox("focus", "Button", panel)
|
||||
var inspector_surface := StyleBoxFlat.new()
|
||||
inspector_surface.bg_color = _theme.inspector_background_color()
|
||||
inspector_surface.border_color = _theme.border_color()
|
||||
inspector_surface.set_border_width_all(1)
|
||||
inspector_surface.content_margin_left = 8
|
||||
inspector_surface.content_margin_right = 8
|
||||
_inspector_column.add_theme_stylebox_override("panel", inspector_surface)
|
||||
var splitter := StyleBoxFlat.new()
|
||||
splitter.bg_color = _theme.border_color().lightened(0.35)
|
||||
splitter.content_margin_left = 3
|
||||
splitter.content_margin_right = 3
|
||||
_canvas_workspace.add_theme_stylebox_override("grabber", splitter)
|
||||
_ui_theme.set_stylebox("normal", "OptionButton", panel)
|
||||
_ui_theme.set_stylebox("hover", "OptionButton", panel_dark)
|
||||
_ui_theme.set_stylebox("pressed", "OptionButton", panel_dark)
|
||||
@@ -457,6 +563,35 @@ func _setup_dialogs() -> void:
|
||||
_save_dialog.file_selected.connect(_on_save_file_selected)
|
||||
_load_dialog.file_selected.connect(_on_load_file_selected)
|
||||
_build_exit_dialog()
|
||||
_rename_anchor_dialog = ConfirmationDialog.new()
|
||||
_rename_anchor_dialog.title = "Rename Anchor"
|
||||
_rename_anchor_dialog.ok_button_text = "Rename"
|
||||
_rename_anchor_dialog.theme = _ui_theme
|
||||
_rename_anchor_edit = LineEdit.new()
|
||||
_rename_anchor_edit.placeholder_text = "Anchor name"
|
||||
_rename_anchor_dialog.add_child(_rename_anchor_edit)
|
||||
add_child(_rename_anchor_dialog)
|
||||
_rename_anchor_edit.text_changed.connect(_update_rename_anchor_confirmation)
|
||||
_rename_anchor_edit.text_submitted.connect(_on_rename_anchor_text_submitted)
|
||||
_rename_anchor_dialog.confirmed.connect(_commit_anchor_rename)
|
||||
_rename_anchor_dialog.canceled.connect(_clear_pending_anchor_rename)
|
||||
|
||||
func _on_rename_anchor_text_submitted(_text: String) -> void:
|
||||
if _rename_anchor_dialog == null or not _rename_anchor_dialog.visible:
|
||||
return
|
||||
var ok_button := _rename_anchor_dialog.get_ok_button()
|
||||
if not ok_button.disabled:
|
||||
ok_button.pressed.emit()
|
||||
|
||||
func _initialize_inspector_split() -> void:
|
||||
if _inspector_split_initialized or _main_layout == null:
|
||||
return
|
||||
var inspector_minimum: float = _inspector_column.get_combined_minimum_size().x
|
||||
if _main_layout.size.x <= inspector_minimum:
|
||||
call_deferred("_initialize_inspector_split")
|
||||
return
|
||||
_main_layout.split_offset = maxi(0, int(_main_layout.size.x - inspector_minimum - _main_layout.get_theme_constant("separation")))
|
||||
_inspector_split_initialized = true
|
||||
|
||||
|
||||
func _build_top_right_controls() -> void:
|
||||
@@ -470,13 +605,22 @@ func _build_top_right_controls() -> void:
|
||||
_grid_spin.max_value = 512
|
||||
_grid_spin.value = _theme.grid_size()
|
||||
_grid_spin.custom_minimum_size.x = 90.0
|
||||
_grid_spin.custom_minimum_size.y = float(_theme.button_min_height())
|
||||
_grid_spin.value_changed.connect(_on_top_grid_changed)
|
||||
_top_right.add_child(_grid_spin)
|
||||
_snap_check = CheckBox.new()
|
||||
_snap_check.text = "Snap"
|
||||
_snap_check.button_pressed = false
|
||||
_snap_check.custom_minimum_size.y = float(_theme.button_min_height())
|
||||
_snap_check.toggled.connect(_on_top_snap_toggled)
|
||||
_top_right.add_child(_snap_check)
|
||||
_center_prop_button = Button.new()
|
||||
_center_prop_button.text = "🎯 Center Prop"
|
||||
_center_prop_button.tooltip_text = "Move the whole prop and its anchors to (0,0)."
|
||||
_center_prop_button.custom_minimum_size.y = float(_theme.button_min_height())
|
||||
_center_prop_button.mouse_filter = Control.MOUSE_FILTER_STOP
|
||||
_center_prop_button.pressed.connect(func() -> void: _center_prop_on_origin())
|
||||
_top_right.add_child(_center_prop_button)
|
||||
|
||||
|
||||
func _on_top_grid_changed(value: float) -> void:
|
||||
@@ -499,6 +643,18 @@ func _build_exit_dialog() -> void:
|
||||
_exit_dialog.confirmed.connect(_on_exit_save)
|
||||
_exit_dialog.custom_action.connect(_on_exit_custom_action)
|
||||
_exit_dialog.canceled.connect(_on_exit_cancel)
|
||||
_off_origin_save_dialog = ConfirmationDialog.new()
|
||||
_off_origin_save_dialog.title = "🎯 Center Prop?"
|
||||
_off_origin_save_dialog.dialog_text = "This prop is far from (0,0). Centering it keeps its shapes and anchors together.\n\nWhat would you like to do?"
|
||||
_off_origin_save_dialog.ok_button_text = "🎯 Center & Save"
|
||||
_off_origin_save_dialog.add_button("💾 Save Anyway", false, "save_anyway")
|
||||
_off_origin_save_dialog.get_cancel_button().text = "❌ Cancel"
|
||||
_off_origin_save_dialog.theme = _ui_theme
|
||||
add_child(_off_origin_save_dialog)
|
||||
_off_origin_save_dialog.confirmed.connect(func() -> void: await _execute_pending_save(true))
|
||||
_off_origin_save_dialog.custom_action.connect(func(action: StringName) -> void:
|
||||
if action == &"save_anyway": await _execute_pending_save(false))
|
||||
_off_origin_save_dialog.canceled.connect(_cancel_pending_save_request)
|
||||
|
||||
|
||||
func _notification(what: int) -> void:
|
||||
@@ -531,19 +687,7 @@ func _on_exit_save() -> void:
|
||||
if _current_path.is_empty():
|
||||
_save_dialog.popup_centered()
|
||||
return
|
||||
await _save_and_finish(_current_path)
|
||||
|
||||
|
||||
func _save_and_finish(path: String) -> void:
|
||||
var ok: bool = await _save_to(path, false)
|
||||
if not ok:
|
||||
return
|
||||
if _pending_quit:
|
||||
_pending_quit = false
|
||||
get_tree().quit()
|
||||
elif _pending_new:
|
||||
_pending_new = false
|
||||
_do_new()
|
||||
_begin_save_request(_current_path, false)
|
||||
|
||||
|
||||
func _on_exit_custom_action(action: StringName) -> void:
|
||||
@@ -561,20 +705,27 @@ func _on_exit_custom_action(action: StringName) -> void:
|
||||
func _on_exit_cancel() -> void:
|
||||
_pending_quit = false
|
||||
_pending_new = false
|
||||
_cancel_pending_save_request()
|
||||
|
||||
|
||||
func _do_new() -> void:
|
||||
_clear_pending_anchor_rename()
|
||||
_prop_name_edit.text = ""
|
||||
_material_preset = PropBlockScript.MaterialPreset.NONE
|
||||
_preset_option.selected = _material_preset
|
||||
_update_physics_labels()
|
||||
_canvas.clear()
|
||||
_anchors = PropAnchorDataScript.default_anchors()
|
||||
_selected_anchor_id = ""
|
||||
_canvas.set_anchor_data(_anchors)
|
||||
_clipboard = {}
|
||||
_canvas.set_has_clipboard(false)
|
||||
_current_path = ""
|
||||
_dirty = false
|
||||
_clear_autosave()
|
||||
_refresh_inspector_from_selection()
|
||||
_refresh_anchor_inspector()
|
||||
_refresh_center_prop_button()
|
||||
_update_save_status()
|
||||
|
||||
|
||||
@@ -588,7 +739,7 @@ func _on_menu_id_pressed(id: int) -> void:
|
||||
if _current_path.is_empty():
|
||||
_save_dialog.popup_centered()
|
||||
else:
|
||||
await _save_to(_current_path)
|
||||
_begin_save_request(_current_path, true)
|
||||
MENU_SAVE_AS:
|
||||
_save_dialog.popup_centered()
|
||||
MENU_RESET_VIEWS:
|
||||
@@ -604,10 +755,13 @@ func _build_inspector() -> void:
|
||||
var row_height: int = _theme.row_min_height()
|
||||
|
||||
# Material preset section
|
||||
_material_section = VBoxContainer.new()
|
||||
_material_section.add_theme_constant_override("separation", 6)
|
||||
_inspector_list.add_child(_material_section)
|
||||
var material_title := Label.new()
|
||||
material_title.text = "Material"
|
||||
material_title.add_theme_font_size_override("font_size", header_size)
|
||||
_inspector_list.add_child(material_title)
|
||||
_material_section.add_child(material_title)
|
||||
|
||||
_preset_option = OptionButton.new()
|
||||
for label: String in PRESET_LABELS:
|
||||
@@ -615,14 +769,14 @@ func _build_inspector() -> void:
|
||||
_preset_option.selected = _material_preset
|
||||
_preset_option.custom_minimum_size.y = float(_theme.button_min_height())
|
||||
_preset_option.item_selected.connect(_on_preset_selected)
|
||||
_inspector_list.add_child(_preset_option)
|
||||
_material_section.add_child(_preset_option)
|
||||
|
||||
_mass_label = Label.new()
|
||||
_friction_label = Label.new()
|
||||
_bounce_label = Label.new()
|
||||
_inspector_list.add_child(_mass_label)
|
||||
_inspector_list.add_child(_friction_label)
|
||||
_inspector_list.add_child(_bounce_label)
|
||||
_material_section.add_child(_mass_label)
|
||||
_material_section.add_child(_friction_label)
|
||||
_material_section.add_child(_bounce_label)
|
||||
_update_physics_labels()
|
||||
|
||||
# Selected-shape section
|
||||
@@ -736,6 +890,160 @@ func _build_inspector() -> void:
|
||||
|
||||
_apply_control_theme(_inspector_list)
|
||||
_rebuild_primitive_params()
|
||||
_build_anchor_inspector()
|
||||
|
||||
func _build_anchor_inspector() -> void:
|
||||
_anchor_section = VBoxContainer.new()
|
||||
_anchor_section.add_theme_constant_override("separation", 6)
|
||||
_inspector_list.add_child(_anchor_section)
|
||||
var title := Label.new(); title.text = "Anchors"; title.add_theme_font_size_override("font_size", _theme.font_header()); _anchor_section.add_child(title)
|
||||
_anchor_list = ItemList.new(); _anchor_list.custom_minimum_size.y = 140.0; _anchor_list.item_selected.connect(func(index: int) -> void: _select_anchor(_anchor_list.get_item_text(index))); _anchor_section.add_child(_anchor_list)
|
||||
var actions := HBoxContainer.new(); _anchor_section.add_child(actions)
|
||||
for label: String in ["Add Anchor", "Rename", "Delete"]:
|
||||
var button := Button.new(); button.text = label; button.custom_minimum_size.y = float(_theme.button_min_height()); actions.add_child(button)
|
||||
if label == "Add Anchor": button.pressed.connect(_on_add_anchor_pressed)
|
||||
elif label == "Rename":
|
||||
_rename_anchor_button = button
|
||||
button.pressed.connect(_on_rename_anchor_pressed)
|
||||
else:
|
||||
_delete_anchor_button = button
|
||||
button.pressed.connect(_on_delete_anchor_pressed)
|
||||
_anchor_role = _anchor_option("Role", EDITABLE_ROLE_STRINGS, _on_anchor_role_selected)
|
||||
_anchor_hand = _anchor_option("Allowed Hands", PropAnchorDataScript.ALLOWED_HAND_STRINGS, _on_anchor_hand_selected)
|
||||
_anchor_x = _anchor_spin("X", -100000.0, 100000.0, _on_anchor_x_changed)
|
||||
_anchor_y = _anchor_spin("Y", -100000.0, 100000.0, _on_anchor_y_changed)
|
||||
_anchor_rotation = _anchor_spin("Rotation", -180.0, 179.0, _on_anchor_rotation_changed)
|
||||
_anchor_z = _anchor_spin("Z Offset", -5.0, 5.0, _on_anchor_z_changed)
|
||||
_anchor_z.step = 1.0
|
||||
var presets := FlowContainer.new(); _anchor_section.add_child(presets)
|
||||
for entry: Dictionary in [{"text":"One-Handed","id":"one_handed"}, {"text":"Two-Handed","id":"two_handed"}, {"text":"Tool / Nozzle","id":"tool_nozzle"}, {"text":"Melee Edge","id":"melee_edge"}]:
|
||||
var button := Button.new(); button.text = str(entry["text"]); button.pressed.connect(func() -> void: _apply_anchor_preset(str(entry["id"]))); presets.add_child(button)
|
||||
_refresh_anchor_inspector()
|
||||
|
||||
func _anchor_option(label_text: String, entries: PackedStringArray, callback: Callable) -> OptionButton:
|
||||
var row := HBoxContainer.new()
|
||||
_anchor_section.add_child(row)
|
||||
var label := Label.new()
|
||||
label.text = label_text + ":"
|
||||
label.custom_minimum_size.x = 84.0
|
||||
label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
row.add_child(label)
|
||||
var option := OptionButton.new()
|
||||
option.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
for entry: String in entries:
|
||||
option.add_item(entry)
|
||||
option.item_selected.connect(callback)
|
||||
row.add_child(option)
|
||||
return option
|
||||
|
||||
func _anchor_spin(label_text: String, minimum: float, maximum: float, callback: Callable) -> SpinBox:
|
||||
var row := HBoxContainer.new()
|
||||
_anchor_section.add_child(row)
|
||||
var label := Label.new()
|
||||
label.text = label_text + ":"
|
||||
label.custom_minimum_size.x = 84.0
|
||||
label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
row.add_child(label)
|
||||
var spin := SpinBox.new()
|
||||
spin.min_value = minimum
|
||||
spin.max_value = maximum
|
||||
spin.step = 1.0
|
||||
spin.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
spin.value_changed.connect(callback)
|
||||
row.add_child(spin)
|
||||
return spin
|
||||
|
||||
func _refresh_anchor_inspector() -> void:
|
||||
if _anchor_list == null: return
|
||||
_updating_inspector = true; _anchor_list.clear()
|
||||
_selected_anchor_id = PropAnchorDataScript.preferred_editable_id(_anchors, _selected_anchor_id)
|
||||
for id: String in PropAnchorDataScript.editable_ids(_anchors): _anchor_list.add_item(id); if id == _selected_anchor_id: _anchor_list.select(_anchor_list.item_count - 1)
|
||||
var anchor: Dictionary = _anchors.get(_selected_anchor_id, {})
|
||||
var editable: bool = not anchor.is_empty()
|
||||
if not anchor.is_empty():
|
||||
var role_index: int = EDITABLE_ROLE_STRINGS.find(str(anchor.get("role", "custom")))
|
||||
_anchor_role.select(role_index if role_index >= 0 else EDITABLE_ROLE_STRINGS.find("custom"))
|
||||
_anchor_hand.select(PropAnchorDataScript.ALLOWED_HAND_STRINGS.find(str(anchor.get("allowed_hands", "both"))))
|
||||
var pos: Vector2 = anchor.get("position", Vector2.ZERO); _anchor_x.value = pos.x; _anchor_y.value = pos.y; _anchor_rotation.value = float(anchor.get("rotation_deg", 0.0)); _anchor_z.value = int(anchor.get("z_index_offset", 0))
|
||||
# OptionButton and Button inherit BaseButton and use `disabled`; SpinBox is a
|
||||
# Range control and gates editing through `editable` in Godot 4.
|
||||
for option: OptionButton in [_anchor_role, _anchor_hand]:
|
||||
option.disabled = not editable
|
||||
option.tooltip_text = "Add or select an anchor." if not editable else ""
|
||||
for spin: SpinBox in [_anchor_x, _anchor_y, _anchor_rotation, _anchor_z]:
|
||||
spin.editable = editable
|
||||
spin.tooltip_text = "Add or select an anchor." if not editable else ""
|
||||
if _rename_anchor_button != null:
|
||||
_rename_anchor_button.disabled = not editable
|
||||
if _delete_anchor_button != null:
|
||||
_delete_anchor_button.disabled = not editable
|
||||
_updating_inspector = false
|
||||
|
||||
func _select_anchor(id: String) -> void:
|
||||
if id != PropAnchorDataScript.ORIGIN_ID and _anchors.has(id): _selected_anchor_id = id; _canvas.select_anchor(id); _refresh_anchor_inspector(); _sync_attach_preview()
|
||||
func _on_add_anchor_pressed() -> void:
|
||||
var id: String = PropAnchorDataScript.normalize_id("anchor", _anchors); var bounds: Rect2 = _canvas.get_shapes_bounds(); _anchors[id] = {"role":"custom", "position": bounds.get_center() if bounds.size != Vector2.ZERO else Vector2.ZERO, "rotation_deg":0.0, "z_index_offset":0, "allowed_hands":"both"}; _selected_anchor_id = id; _anchors = PropAnchorDataScript.normalize_anchors(_anchors); _canvas.set_anchor_data(_anchors); _mark_dirty(); _refresh_anchor_inspector()
|
||||
func _on_rename_anchor_pressed() -> void:
|
||||
if _selected_anchor_id.is_empty() or not _anchors.has(_selected_anchor_id) or _rename_anchor_dialog == null:
|
||||
return
|
||||
_rename_anchor_source_id = _selected_anchor_id
|
||||
_rename_anchor_edit.text = _rename_anchor_source_id
|
||||
_update_rename_anchor_confirmation(_rename_anchor_edit.text)
|
||||
_rename_anchor_dialog.popup_centered(Vector2i(420, 150))
|
||||
_rename_anchor_edit.call_deferred("grab_focus")
|
||||
_rename_anchor_edit.call_deferred("select_all")
|
||||
|
||||
func _update_rename_anchor_confirmation(value: String) -> void:
|
||||
if _rename_anchor_dialog != null:
|
||||
_rename_anchor_dialog.get_ok_button().disabled = value.strip_edges().is_empty()
|
||||
|
||||
func _commit_anchor_rename() -> void:
|
||||
if _rename_anchor_source_id.is_empty() or not _anchors.has(_rename_anchor_source_id):
|
||||
_clear_pending_anchor_rename()
|
||||
return
|
||||
var remaining: Dictionary = _anchors.duplicate(true)
|
||||
var payload: Dictionary = remaining[_rename_anchor_source_id].duplicate(true)
|
||||
remaining.erase(_rename_anchor_source_id)
|
||||
var new_id: String = PropAnchorDataScript.normalize_id(_rename_anchor_edit.text, remaining)
|
||||
var old_id: String = _rename_anchor_source_id
|
||||
_clear_pending_anchor_rename()
|
||||
if new_id == old_id:
|
||||
return
|
||||
remaining[new_id] = payload
|
||||
_anchors = PropAnchorDataScript.normalize_anchors(remaining)
|
||||
_selected_anchor_id = new_id
|
||||
_canvas.set_anchor_data(_anchors)
|
||||
_canvas.select_anchor(new_id)
|
||||
_mark_dirty()
|
||||
_refresh_anchor_inspector()
|
||||
_sync_attach_preview()
|
||||
|
||||
func _clear_pending_anchor_rename() -> void:
|
||||
_rename_anchor_source_id = ""
|
||||
func _on_delete_anchor_pressed() -> void:
|
||||
if _selected_anchor_id.is_empty(): return
|
||||
var ids: Array[String] = PropAnchorDataScript.editable_ids(_anchors)
|
||||
var old_index: int = ids.find(_selected_anchor_id)
|
||||
_anchors.erase(_selected_anchor_id)
|
||||
ids = PropAnchorDataScript.editable_ids(_anchors)
|
||||
_selected_anchor_id = ids[clampi(old_index - 1, 0, ids.size() - 1)] if not ids.is_empty() else ""
|
||||
_canvas.set_anchor_data(_anchors); _canvas.select_anchor(_selected_anchor_id); _mark_dirty(); _refresh_anchor_inspector(); _sync_attach_preview()
|
||||
func _on_anchor_role_selected(index: int) -> void:
|
||||
if index >= 0 and index < EDITABLE_ROLE_STRINGS.size():
|
||||
_set_anchor_field("role", EDITABLE_ROLE_STRINGS[index])
|
||||
func _on_anchor_hand_selected(index: int) -> void: _set_anchor_field("allowed_hands", PropAnchorDataScript.ALLOWED_HAND_STRINGS[index])
|
||||
func _on_anchor_x_changed(value: float) -> void:
|
||||
if not _updating_inspector: _set_anchor_field("position", Vector2(value, _anchor_y.value))
|
||||
func _on_anchor_y_changed(value: float) -> void:
|
||||
if not _updating_inspector: _set_anchor_field("position", Vector2(_anchor_x.value, value))
|
||||
func _on_anchor_rotation_changed(value: float) -> void:
|
||||
if not _updating_inspector: _set_anchor_field("rotation_deg", value)
|
||||
func _on_anchor_z_changed(value: float) -> void:
|
||||
if not _updating_inspector: _set_anchor_field("z_index_offset", int(value))
|
||||
func _set_anchor_field(field: String, value: Variant) -> void:
|
||||
if _updating_inspector or _selected_anchor_id.is_empty(): return
|
||||
var anchor: Dictionary = _anchors[_selected_anchor_id].duplicate(true); anchor[field] = value; _anchors[_selected_anchor_id] = anchor; _anchors = PropAnchorDataScript.normalize_anchors(_anchors); _canvas.set_anchor_data(_anchors); _mark_dirty(); _refresh_anchor_inspector(); _sync_attach_preview()
|
||||
func _apply_anchor_preset(preset: String) -> void: _anchors = PropAnchorDataScript.preset_layout(preset, _canvas.get_shapes_bounds()); _selected_anchor_id = PropAnchorDataScript.preferred_editable_id(_anchors); _canvas.set_anchor_data(_anchors); _canvas.select_anchor(_selected_anchor_id); _mark_dirty(); _refresh_anchor_inspector(); _sync_attach_preview()
|
||||
|
||||
|
||||
func _apply_control_theme(node: Node) -> void:
|
||||
@@ -885,6 +1193,50 @@ func _refresh_inspector_from_selection() -> void:
|
||||
func _on_canvas_shape_changed(_shapes: Array[Dictionary]) -> void:
|
||||
_mark_dirty()
|
||||
_refresh_inspector_from_selection()
|
||||
_refresh_anchor_inspector()
|
||||
_refresh_center_prop_button()
|
||||
_sync_attach_preview()
|
||||
|
||||
func _on_canvas_anchors_changed(anchors: Dictionary) -> void:
|
||||
_anchors = PropAnchorDataScript.normalize_anchors(anchors)
|
||||
_selected_anchor_id = PropAnchorDataScript.preferred_editable_id(_anchors, _canvas.get_selected_anchor_id())
|
||||
_mark_dirty()
|
||||
_refresh_anchor_inspector()
|
||||
_sync_attach_preview()
|
||||
|
||||
func _on_canvas_anchor_selected(anchor_id: String) -> void:
|
||||
_selected_anchor_id = PropAnchorDataScript.preferred_editable_id(_anchors, anchor_id)
|
||||
_refresh_anchor_inspector()
|
||||
_sync_attach_preview()
|
||||
|
||||
func _sync_attach_preview() -> void:
|
||||
if _attach_preview != null and _attach_preview.has_method("set_document"):
|
||||
_attach_preview.call("set_document", _canvas.get_shape_data(), _anchors, _selected_anchor_id)
|
||||
|
||||
func _refresh_center_prop_button() -> void:
|
||||
if _center_prop_button == null: return
|
||||
var bounds: Rect2 = _canvas.get_shapes_bounds()
|
||||
_center_prop_button.disabled = not _canvas.has_shape_geometry() or bounds.get_center().is_zero_approx()
|
||||
|
||||
func _center_prop_on_origin(focus_view: bool = true) -> bool:
|
||||
if not _canvas.has_shape_geometry(): return false
|
||||
var bounds: Rect2 = _canvas.get_shapes_bounds()
|
||||
var delta: Vector2 = -bounds.get_center()
|
||||
if not is_finite(delta.x) or not is_finite(delta.y): return false
|
||||
if delta.is_zero_approx():
|
||||
if focus_view: _canvas.focus_world_point(Vector2.ZERO)
|
||||
return false
|
||||
_anchors = PropAnchorDataScript.translated_non_origin(_anchors, delta)
|
||||
_canvas.set_anchor_data(_anchors)
|
||||
if not _canvas.translate_all_shapes(delta): return false
|
||||
_selected_anchor_id = PropAnchorDataScript.preferred_editable_id(_anchors, _selected_anchor_id)
|
||||
_canvas.select_anchor(_selected_anchor_id)
|
||||
_refresh_inspector_from_selection()
|
||||
_refresh_anchor_inspector()
|
||||
_refresh_center_prop_button()
|
||||
_sync_attach_preview()
|
||||
if focus_view: _canvas.focus_world_point(Vector2.ZERO)
|
||||
return true
|
||||
|
||||
|
||||
func _on_canvas_shape_selected(_idx: int) -> void:
|
||||
@@ -977,10 +1329,11 @@ func _check_autosave_recovery() -> void:
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
func _build_json_data() -> Dictionary:
|
||||
return PropFileScript.to_file_dict(_prop_name_edit.text, _material_preset, _canvas.get_shape_data())
|
||||
return PropFileScript.to_file_dict(_prop_name_edit.text, _material_preset, _canvas.get_shape_data(), _anchors)
|
||||
|
||||
|
||||
func _apply_json_data(json: Variant, is_recovery: bool = false) -> String:
|
||||
_clear_pending_anchor_rename()
|
||||
var model: Dictionary = PropFileScript.from_file_dict(json)
|
||||
if model.is_empty():
|
||||
return "The file could not be read: unsupported version or malformed data."
|
||||
@@ -991,9 +1344,16 @@ func _apply_json_data(json: Variant, is_recovery: bool = false) -> String:
|
||||
_update_physics_labels()
|
||||
var shapes: Array = model.get("shapes", [])
|
||||
_canvas.set_shape_data(shapes)
|
||||
_anchors = PropAnchorDataScript.normalize_anchors(model.get("anchors", {}))
|
||||
_selected_anchor_id = PropAnchorDataScript.preferred_editable_id(_anchors)
|
||||
_canvas.set_anchor_data(_anchors)
|
||||
_canvas.select_anchor(_selected_anchor_id)
|
||||
_dirty = is_recovery
|
||||
_autosave_remaining = 0.0
|
||||
_refresh_inspector_from_selection()
|
||||
_refresh_anchor_inspector()
|
||||
_refresh_center_prop_button()
|
||||
_canvas.call_deferred("reset_view")
|
||||
_update_save_status()
|
||||
return ""
|
||||
|
||||
@@ -1025,16 +1385,44 @@ func _save_prop_thumbnail() -> void:
|
||||
_thumb_cache.save_png(tex, _thumb_cache.prop_file_png(_current_path))
|
||||
|
||||
|
||||
func _begin_save_request(path: String, with_thumbnail: bool) -> void:
|
||||
_pending_save_path = path
|
||||
_pending_save_with_thumbnail = with_thumbnail
|
||||
if should_warn_off_origin(_canvas.has_shape_geometry(), _canvas.get_shapes_bounds()):
|
||||
_off_origin_save_dialog.popup_centered()
|
||||
return
|
||||
await _execute_pending_save(false)
|
||||
|
||||
func _execute_pending_save(center_first: bool) -> void:
|
||||
var path: String = _pending_save_path
|
||||
var with_thumbnail: bool = _pending_save_with_thumbnail
|
||||
if path.is_empty():
|
||||
_cancel_pending_save_request()
|
||||
return
|
||||
if center_first: _center_prop_on_origin(true)
|
||||
var ok: bool = await _save_to(path, with_thumbnail)
|
||||
if not ok:
|
||||
_cancel_pending_save_request()
|
||||
return
|
||||
_pending_save_path = ""
|
||||
_pending_save_with_thumbnail = true
|
||||
if _pending_quit:
|
||||
_pending_quit = false
|
||||
get_tree().quit()
|
||||
elif _pending_new:
|
||||
_pending_new = false
|
||||
_do_new()
|
||||
|
||||
func _cancel_pending_save_request() -> void:
|
||||
_pending_save_path = ""
|
||||
_pending_save_with_thumbnail = true
|
||||
_pending_quit = false
|
||||
_pending_new = false
|
||||
|
||||
func _on_save_file_selected(path: String) -> void:
|
||||
if path.get_extension().to_lower() != "prop":
|
||||
path = path.get_basename() + ".prop"
|
||||
var ok: bool = await _save_to(path, not (_pending_quit or _pending_new))
|
||||
if ok and _pending_quit:
|
||||
_pending_quit = false
|
||||
get_tree().quit()
|
||||
elif ok and _pending_new:
|
||||
_pending_new = false
|
||||
_do_new()
|
||||
_begin_save_request(path, not (_pending_quit or _pending_new))
|
||||
|
||||
|
||||
func _load_from(path: String) -> void:
|
||||
|
||||
Reference in New Issue
Block a user