Skip to content

Commit 0fe9935

Browse files
authored
Improved remote parameters rearrangement (contributed by williamchange)
Improve remote paramters rearrangement
2 parents 3384dba + d0bbe25 commit 0fe9935

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
@@ -265,14 +265,12 @@ func link_parameter(widget_name : String, generator : MMGenBase, param : String)
265265
parameters[widget_name] = 0
266266
emit_signal("parameter_changed", "__update_all__", null)
267267

268-
func move_parameter(widget_name : String, offset : int) -> void:
269-
for i in range(widgets.size()):
270-
if widgets[i].name == widget_name:
271-
var widget = widgets[i]
272-
var widget2 = widgets[i+offset]
273-
widgets[i] = widget2
274-
widgets[i+offset] = widget
275-
break
268+
func rearrange_parameter(from : int, to : int, is_after : bool) -> void:
269+
var arrange_widget = widgets[from]
270+
widgets.remove_at(from)
271+
if from < to:
272+
to -= 1
273+
widgets.insert(to + int(is_after), arrange_widget)
276274
emit_signal("parameter_changed", "__update_all__", null)
277275

278276
func remove_parameter(widget_name : String) -> void:
@@ -311,7 +309,6 @@ func remove_configuration(widget_name : String, config_name : String) -> void:
311309
widget.configurations.erase(config_name)
312310
emit_signal("parameter_changed", "__update_all__", null)
313311

314-
315312
func _serialize(data: Dictionary) -> Dictionary:
316313
data.type = "remote"
317314
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)