2018-10-28 16:26:37 +01:00
|
|
|
extends HBoxContainer
|
|
|
|
|
|
|
|
var enum_values = [ {name="Foo", value="foo"} ]
|
|
|
|
var enum_current = 0
|
|
|
|
|
2019-12-04 22:26:54 +01:00
|
|
|
const ENUM_ADD = 10000
|
|
|
|
const ENUM_EDIT = 10001
|
|
|
|
const ENUM_REMOVE = 10002
|
|
|
|
const ENUM_UP = 10003
|
|
|
|
const ENUM_DOWN = 10004
|
2018-10-28 16:26:37 +01:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func _ready() -> void:
|
2018-10-28 16:26:37 +01:00
|
|
|
update_enum_list()
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func get_model_data() -> Dictionary:
|
|
|
|
return {
|
|
|
|
values = enum_values,
|
|
|
|
default = enum_current,
|
|
|
|
}
|
2018-10-28 16:26:37 +01:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func set_model_data(data) -> void:
|
2018-10-28 16:26:37 +01:00
|
|
|
enum_values = data.values.duplicate()
|
2019-08-09 08:16:24 +02:00
|
|
|
if data.has("default"):
|
|
|
|
enum_current = data.default
|
|
|
|
else:
|
|
|
|
enum_current = 0
|
2018-10-28 16:26:37 +01:00
|
|
|
update_enum_list()
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func update_enum_list() -> void:
|
2018-10-28 16:26:37 +01:00
|
|
|
var options = $EnumValues
|
|
|
|
options.clear()
|
|
|
|
if !enum_values.empty():
|
|
|
|
for i in range(enum_values.size()):
|
|
|
|
var v = enum_values[i]
|
|
|
|
options.add_item(v.name+" ("+v.value+")", i)
|
|
|
|
options.add_separator()
|
|
|
|
var v = enum_values[enum_current]
|
|
|
|
options.add_item("Edit "+v.value, ENUM_EDIT)
|
|
|
|
options.add_item("Remove "+v.value, ENUM_REMOVE)
|
|
|
|
if enum_current > 0:
|
|
|
|
options.add_item("Move "+v.value+" up", ENUM_UP)
|
|
|
|
if enum_current < enum_values.size() - 1:
|
|
|
|
options.add_item("Move "+v.value+" down", ENUM_DOWN)
|
|
|
|
options.add_separator()
|
|
|
|
options.selected = enum_current
|
|
|
|
options.add_item("Add value", ENUM_ADD)
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func _on_EnumValues_item_selected(id) -> void:
|
2018-10-28 16:26:37 +01:00
|
|
|
id = $EnumValues.get_item_id(id)
|
|
|
|
if id >= 0 and id < enum_values.size():
|
|
|
|
enum_current = id
|
|
|
|
elif id == ENUM_EDIT:
|
2020-01-27 08:17:18 +01:00
|
|
|
var dialog = load("res://material_maker/widgets/node_editor/enum_editor.tscn").instance()
|
2018-10-28 16:26:37 +01:00
|
|
|
var v = enum_values[enum_current]
|
|
|
|
add_child(dialog)
|
|
|
|
dialog.set_value(v.name, v.value)
|
|
|
|
dialog.connect("ok", self, "update_enum_value", [ enum_current ])
|
|
|
|
dialog.popup_centered()
|
|
|
|
elif id == ENUM_ADD:
|
2020-01-27 08:17:18 +01:00
|
|
|
var dialog = load("res://material_maker/widgets/node_editor/enum_editor.tscn").instance()
|
2018-10-28 16:26:37 +01:00
|
|
|
add_child(dialog)
|
|
|
|
dialog.connect("ok", self, "update_enum_value", [ -1 ])
|
|
|
|
dialog.popup_centered()
|
|
|
|
elif id == ENUM_REMOVE:
|
|
|
|
enum_values.remove(enum_current)
|
|
|
|
enum_current = 0
|
|
|
|
elif id == ENUM_UP:
|
|
|
|
var tmp = enum_values[enum_current]
|
|
|
|
enum_values[enum_current] = enum_values[enum_current-1]
|
|
|
|
enum_values[enum_current-1] = tmp
|
|
|
|
enum_current -= 1
|
|
|
|
elif id == ENUM_DOWN:
|
|
|
|
var tmp = enum_values[enum_current]
|
|
|
|
enum_values[enum_current] = enum_values[enum_current+1]
|
|
|
|
enum_values[enum_current+1] = tmp
|
|
|
|
enum_current += 1
|
|
|
|
update_enum_list()
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func update_enum_value(n, v, i) -> void:
|
2018-10-28 16:26:37 +01:00
|
|
|
if i == -1:
|
|
|
|
enum_values.append({ name=n, value=v })
|
|
|
|
enum_current = enum_values.size()-1
|
|
|
|
else:
|
|
|
|
enum_values[i] = { name=n, value=v }
|
|
|
|
enum_current = i
|
|
|
|
update_enum_list()
|