feat: harmonize Prop and Stickman editor UI
This commit is contained in:
@@ -76,6 +76,7 @@ const PropFileScript := preload("res://scripts/editors/prop/prop_file.gd")
|
||||
const PropAnchorOverlayScript := preload("res://scripts/props/prop_anchor_overlay.gd")
|
||||
const PropAnchorDataScript := preload("res://scripts/props/prop_anchor_data.gd")
|
||||
const WholeStickmanPreviewScript := preload("res://scripts/editors/stickman/whole_stickman_preview.gd")
|
||||
const EditorContextMenuScript := preload("res://scripts/shared/editor_ui/editor_context_menu.gd")
|
||||
|
||||
const SELECTION_CORE_COLOR := Color.WHITE
|
||||
const SELECTION_HALO_COLOR := Color(0.0, 0.0, 0.0, 0.85)
|
||||
@@ -122,7 +123,7 @@ var _grid_size: int = 15
|
||||
var _snap_enabled: bool = false
|
||||
var _has_clipboard: bool = false
|
||||
var _create_point_armed: bool = false
|
||||
var _context_menu: PopupMenu
|
||||
var _context_menu: EditorContextMenu
|
||||
var _edit_mode: EditMode = EditMode.TRANSFORM
|
||||
var _anchor_overlay: RefCounted
|
||||
var _origin_marker_color: Color = ORIGIN_MARKER_DEFAULT_COLOR
|
||||
@@ -189,7 +190,7 @@ func _ready() -> void:
|
||||
_anchor_overlay = PropAnchorOverlayScript.new()
|
||||
_anchor_overlay.anchors_changed.connect(func(data: Dictionary) -> void: anchors_changed.emit(data); queue_redraw())
|
||||
_anchor_overlay.anchor_selected.connect(func(anchor_id: String) -> void: anchor_selected.emit(anchor_id); queue_redraw())
|
||||
_context_menu = PopupMenu.new()
|
||||
_context_menu = EditorContextMenuScript.new() as EditorContextMenu
|
||||
_context_menu.name = "ContextMenu"
|
||||
add_child(_context_menu)
|
||||
if not _context_menu.id_pressed.is_connected(_on_context_menu_id_pressed):
|
||||
@@ -983,7 +984,12 @@ func set_has_clipboard(state: bool) -> void:
|
||||
## Sets the font size of the right-click context menu (Round 4, theme-driven).
|
||||
func set_context_menu_font_size(size: int) -> void:
|
||||
if _context_menu != null:
|
||||
_context_menu.add_theme_font_size_override("font_size", size)
|
||||
_context_menu.set_font_size(size)
|
||||
|
||||
|
||||
func set_context_menu_visual_theme(visual_theme: EditorVisualTheme, editor: StringName) -> void:
|
||||
if _context_menu != null:
|
||||
_context_menu.configure(visual_theme, editor)
|
||||
|
||||
|
||||
func is_cursor_over_drawing(global_pos: Vector2) -> bool:
|
||||
@@ -1335,8 +1341,8 @@ func _handle_points_right_click(mb: InputEventMouseButton, world_pos: Vector2) -
|
||||
if context_shape >= 0 and context_vertex >= 0:
|
||||
_context_menu.set_meta("context_shape", context_shape)
|
||||
_context_menu.set_meta("context_vertex", context_vertex)
|
||||
_context_menu.add_item("Remove Point", MENU_REMOVE_POINT)
|
||||
_context_menu.popup_on_parent(Rect2(mb.global_position, Vector2.ONE))
|
||||
_context_menu.add_destructive_item("Remove Point", MENU_REMOVE_POINT)
|
||||
_context_menu.popup_at(mb.global_position, _global_point_target_rect(world_pos))
|
||||
return
|
||||
|
||||
# Segment proximity -> Create Point (selects the shape first).
|
||||
@@ -1348,7 +1354,7 @@ func _handle_points_right_click(mb: InputEventMouseButton, world_pos: Vector2) -
|
||||
queue_redraw()
|
||||
shape_selected.emit(seg_shape)
|
||||
_context_menu.add_item("Create Point", MENU_CREATE_POINT)
|
||||
_context_menu.popup_on_parent(Rect2(mb.global_position, Vector2.ONE))
|
||||
_context_menu.popup_at(mb.global_position, _global_shape_target_rect(seg_shape))
|
||||
return
|
||||
|
||||
# Interior body: select only, no menu.
|
||||
@@ -1381,17 +1387,18 @@ func _handle_transform_right_click(mb: InputEventMouseButton, world_pos: Vector2
|
||||
_context_menu.set_meta("click_position", world_pos)
|
||||
queue_redraw()
|
||||
shape_selected.emit(hit_shape)
|
||||
_context_menu.add_item("Copy", MENU_COPY)
|
||||
_context_menu.add_item("Copy Shape", MENU_COPY)
|
||||
if _has_clipboard:
|
||||
_context_menu.add_item("Paste", MENU_PASTE)
|
||||
_context_menu.add_item("Erase", MENU_DELETE)
|
||||
_context_menu.add_item("Paste Shape", MENU_PASTE)
|
||||
_context_menu.add_separator()
|
||||
_context_menu.add_item("Flip Left-Right", MENU_MIRROR_X)
|
||||
_context_menu.add_item("Flip Up-Down", MENU_MIRROR_Y)
|
||||
_context_menu.add_separator()
|
||||
_context_menu.add_item("Bring Forward", MENU_BRING_FORWARD)
|
||||
_context_menu.add_item("Send Back", MENU_SEND_BACK)
|
||||
_context_menu.popup_on_parent(Rect2(mb.global_position, Vector2.ONE))
|
||||
_context_menu.add_separator()
|
||||
_context_menu.add_destructive_item("Erase Shape", MENU_DELETE)
|
||||
_context_menu.popup_at(mb.global_position, _global_shape_target_rect(hit_shape))
|
||||
return
|
||||
|
||||
# Empty canvas -> add primitives.
|
||||
@@ -1403,8 +1410,8 @@ func _handle_transform_right_click(mb: InputEventMouseButton, world_pos: Vector2
|
||||
_context_menu.add_item("Add Circle", MENU_ADD_CIRCLE)
|
||||
if _has_clipboard:
|
||||
_context_menu.add_separator()
|
||||
_context_menu.add_item("Paste", MENU_PASTE)
|
||||
_context_menu.popup_on_parent(Rect2(mb.global_position, Vector2.ONE))
|
||||
_context_menu.add_item("Paste Shape", MENU_PASTE)
|
||||
_context_menu.popup_at(mb.global_position)
|
||||
|
||||
|
||||
func _handle_left_press(world_pos: Vector2) -> void:
|
||||
@@ -1857,6 +1864,19 @@ func _screen_to_world(pos: Vector2) -> Vector2:
|
||||
return (pos - _pan_offset) / _zoom
|
||||
|
||||
|
||||
func _global_point_target_rect(world_pos: Vector2) -> Rect2:
|
||||
var screen_pos := global_position + _pan_offset + world_pos * _zoom
|
||||
return Rect2(screen_pos - Vector2(6.0, 6.0), Vector2(12.0, 12.0))
|
||||
|
||||
|
||||
func _global_shape_target_rect(shape_idx: int) -> Rect2:
|
||||
if shape_idx < 0 or shape_idx >= shapes.size():
|
||||
return Rect2()
|
||||
var world_bounds: Rect2 = _shape_bbox(shapes[shape_idx])
|
||||
var screen_position := global_position + _pan_offset + world_bounds.position * _zoom
|
||||
return Rect2(screen_position, world_bounds.size * _zoom).grow(4.0)
|
||||
|
||||
|
||||
func _snap_to_grid(pos: Vector2) -> Vector2:
|
||||
var gs := float(_grid_size)
|
||||
if gs <= 0.0:
|
||||
|
||||
Reference in New Issue
Block a user