Skip to content

Commit

Permalink
Rework how point geometry is handled
Browse files Browse the repository at this point in the history
- Single points setter, single property, no setter overridding
- Copy-pasted shapes are sharing geometry by default now (in line with
the editor conventions)
- Implement Make Unique toggle with undo support (workaround for godotengine/godot#74918)
- SS2D_Point_Array.clone()
- A confirmation dialog for "Make Unique" action to avoid accidental
misclicks
- Fix: Unable to clear SS2D_Point_Array resource in inspector
- Fix: Opening a scene with a shape generates change in the scene file
even if shape wasn't touched
  • Loading branch information
limbonaut committed Mar 15, 2023
1 parent 9a995a4 commit 90b4d7a
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 107 deletions.
8 changes: 8 additions & 0 deletions addons/rmsmartshape/plugin-functionality.gd
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,11 @@ static func action_invert_orientation(
undo.commit_action()
return true
return false


static func action_make_shape_unique(s: SS2D_Shape_Base, undo: EditorUndoRedoManager) -> bool:
undo.create_action("Make Unique")
undo.add_do_method(s, "set_point_array", s.get_point_array().clone(true))
undo.add_undo_method(s, "set_point_array", s.get_point_array())
undo.commit_action()
return true
22 changes: 22 additions & 0 deletions addons/rmsmartshape/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ var tb_snap: MenuButton = null
# The PopupMenu that belongs to tb_snap
var tb_snap_popup: PopupMenu = null

var make_unique_dialog: AcceptDialog

# Edge Stuff
var on_edge: bool = false
var edge_point: Vector2
Expand Down Expand Up @@ -349,6 +351,14 @@ func _ready() -> void:
add_child(gui_snap_settings)
gui_snap_settings.hide()

make_unique_dialog = AcceptDialog.new()
make_unique_dialog.title = "Make Shape Unique"
make_unique_dialog.get_label().text = "Make shape point geometry unique (not materials). Proceed?"
make_unique_dialog.get_ok_button().text = "Proceed"
make_unique_dialog.add_cancel_button("Cancel")
make_unique_dialog.connect("confirmed", self._shape_make_unique)
add_child(make_unique_dialog)

connect("main_screen_changed", self._on_main_screen_changed)


Expand Down Expand Up @@ -524,11 +534,15 @@ static func snap_position(
func disconnect_shape(s) -> void:
if s.is_connected("points_modified", self._on_shape_point_modified):
s.disconnect("points_modified", self._on_shape_point_modified)
if s.is_connected("make_unique_pressed", self._on_shape_make_unique):
s.disconnect("make_unique_pressed", self._on_shape_make_unique)


func connect_shape(s) -> void:
if not s.is_connected("points_modified", self._on_shape_point_modified):
s.connect("points_modified", self._on_shape_point_modified)
if not s.is_connected("make_unique_pressed", self._on_shape_make_unique):
s.connect("make_unique_pressed", self._on_shape_make_unique)


static func get_material_override_from_indicies(
Expand Down Expand Up @@ -606,6 +620,14 @@ func _on_shape_point_modified() -> void:
FUNC.action_invert_orientation(self, "update_overlays", get_undo_redo(), shape)


func _on_shape_make_unique(_shape: SS2D_Shape_Base) -> void:
make_unique_dialog.popup_centered()


func _shape_make_unique() -> void:
FUNC.action_make_shape_unique(shape, get_undo_redo())


func get_et() -> Transform2D:
return get_editor_interface().get_edited_scene_root().get_viewport().global_canvas_transform

Expand Down
25 changes: 25 additions & 0 deletions addons/rmsmartshape/shapes/point_array.gd
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,31 @@ func _init() -> void:
_material_overrides = {}


func clone(deep: bool = false) -> SS2D_Point_Array:
var copy := SS2D_Point_Array.new()
copy._next_key = _next_key
if deep:
var new_point_dict := {}
for k in _points:
new_point_dict[k] = _points[k].duplicate(true)
copy._points = new_point_dict
copy._point_order = _point_order.duplicate(true)

copy._constraints = {}
for tuple in _constraints:
copy._constraints[tuple] = _constraints[tuple]

copy._material_overrides = {}
for tuple in _material_overrides:
copy._material_overrides[tuple] = _material_overrides[tuple]
else:
copy._points = _points
copy._point_order = _point_order
copy._constraints = _constraints
copy._material_overrides = _material_overrides
return copy


func set_points(ps: Dictionary) -> void:
# Called by Godot when loading from a saved scene
for k in ps:
Expand Down
Loading

0 comments on commit 90b4d7a

Please sign in to comment.