Skip to content

Commit d0bbe25

Browse files
committed
Improved remote paramters rearrangement
Support dropping parameters in-between rows
1 parent dae9bb0 commit d0bbe25

2 files changed

Lines changed: 14 additions & 20 deletions

File tree

addons/material_maker/engine/nodes/gen_remote.gd

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,12 @@ func link_parameter(widget_name : String, generator : MMGenBase, param : String)
260260
parameters[widget_name] = 0
261261
emit_signal("parameter_changed", "__update_all__", null)
262262

263-
func move_parameter(widget_name : String, offset : int) -> void:
264-
for i in range(widgets.size()):
265-
if widgets[i].name == widget_name:
266-
var widget = widgets[i]
267-
var widget2 = widgets[i+offset]
268-
widgets[i] = widget2
269-
widgets[i+offset] = widget
270-
break
263+
func rearrange_parameter(from : int, to : int, is_after : bool) -> void:
264+
var arrange_widget = widgets[from]
265+
widgets.remove_at(from)
266+
if from < to:
267+
to -= 1
268+
widgets.insert(to + int(is_after), arrange_widget)
271269
emit_signal("parameter_changed", "__update_all__", null)
272270

273271
func remove_parameter(widget_name : String) -> void:
@@ -306,7 +304,6 @@ func remove_configuration(widget_name : String, config_name : String) -> void:
306304
widget.configurations.erase(config_name)
307305
emit_signal("parameter_changed", "__update_all__", null)
308306

309-
310307
func _serialize(data: Dictionary) -> Dictionary:
311308
data.type = "remote"
312309
data.widgets = widgets

material_maker/nodes/remote/remote.gd

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ func undo_redo_register_change(action_name : String, previous_state : Dictionary
140140
if new_state.hash() == previous_state.hash():
141141
return
142142
get_parent().undoredo_create_step(action_name, generator.get_hier_name(), previous_state, new_state)
143-
144-
func move_parameter(widget_name : String, offset : int) -> void:
143+
144+
func rearrange_parameter(from : int, to : int, is_after : bool) -> void:
145145
old_state = generator.serialize().duplicate(true)
146-
generator.move_parameter(widget_name, offset)
147-
undo_redo_register_change("Move parameter", old_state)
146+
generator.rearrange_parameter(from, to, is_after)
147+
undo_redo_register_change("Rearrange parameter", old_state)
148148

149149
func remove_parameter(widget_name : String) -> void:
150150
old_state = generator.serialize().duplicate(true)
@@ -269,12 +269,10 @@ func on_exit_widget(widget) -> void:
269269
l.queue_free()
270270
links.erase(widget)
271271

272-
273272
func modulate_row_controls(row_index: int, color: Color):
274273
for i in range(grid.columns * row_index, grid.columns * row_index + grid.columns):
275274
grid.get_child(i).modulate = color
276275

277-
278276
func row_get_data(_at_pos: Vector2, index: int, widget_name: String) -> Dictionary:
279277
var preview_root := Control.new()
280278

@@ -315,13 +313,13 @@ func row_get_data(_at_pos: Vector2, index: int, widget_name: String) -> Dictiona
315313

316314
return { "row_index": row_index, "widget_name": widget_name, "node_name": name }
317315

318-
319316
func row_can_drop(_at_pos: Vector2, data: Dictionary, index: int) -> bool:
320317
return data.row_index != floor(index / grid.columns) and data.node_name == name
321318

322-
323-
func row_drop_data(_at_pos: Vector2, data: Dictionary, index: int) -> void:
324-
move_parameter(data.widget_name, floor(index / grid.columns) - data.row_index)
319+
func row_drop_data(at_pos: Vector2, data: Dictionary, index: int) -> void:
320+
var row_index := int(index / grid.columns)
321+
var drop_pos_y : float = at_pos.y / grid.get_child(row_index).size.y
322+
rearrange_parameter(data.row_index, row_index, drop_pos_y > 0.5)
325323

326324
# workaround FloatEdits' focused state when dropping rows
327325
await get_tree().process_frame
@@ -332,7 +330,6 @@ func row_drop_data(_at_pos: Vector2, data: Dictionary, index: int) -> void:
332330
float_edit.get_child(0).add_theme_stylebox_override(
333331
"background", get_theme_stylebox("normal","MM_NodeFloatEdit"))
334332

335-
336333
func _notification(what: int) -> void:
337334
match what:
338335
NOTIFICATION_DRAG_END:

0 commit comments

Comments
 (0)