pir-serious-game-ethics/addons/dialogic/Editor/Events/Common/DefinitionPicker.gd

37 lines
840 B
GDScript3
Raw Normal View History

tool
extends MenuButton
var default_text = '[ Select a definition ]'
func _ready():
get_popup().connect("index_pressed", self, '_on_entry_selected')
get_popup().clear()
connect("about_to_show", self, "_on_MenuButton_about_to_show")
func _on_MenuButton_about_to_show():
get_popup().clear()
var index = 0
2021-03-25 22:52:07 +01:00
for d in DialogicUtil.get_sorted_default_definitions_list():
if d['type'] == 0:
get_popup().add_item(d['name'])
get_popup().set_item_metadata(index, {
'id': d['id'],
})
index += 1
func _on_entry_selected(index):
var _text = get_popup().get_item_text(index)
var metadata = get_popup().get_item_metadata(index)
text = _text
2021-03-25 22:46:46 +01:00
func load_definition(id):
if id != '':
for d in DialogicResources.get_default_definitions()['variables']:
if d['id'] == id:
text = d['name']
else:
text = default_text