@@ -414,6 +414,66 @@ class PortraitsDisplayer extends EditorProperty:
414414 emit_changed (get_edited_property (), portraits .duplicate ())
415415
416416
417+ class EditorPropertyPortraits extends EditorProperty :
418+ var options :OptionButton
419+
420+ func _option_selected (option :int ) -> void :
421+ pass
422+
423+
424+ func _set_read_only (value :bool ) -> void :
425+ options .disabled = value
426+ pass
427+
428+
429+ func update_property () -> void :
430+ var chara = get_edited_object ().get ("character" )
431+ if chara != null :
432+ for portrait_idx in chara .portraits .size ():
433+ var portrait = chara .portraits [portrait_idx ]
434+ for item in options .get_item_count ():
435+ if portrait_idx == options .get_item_metadata (item ):
436+ var texture = ImageTexture .new ()
437+ texture .create_from_image (portrait .icon .get_data ())
438+ texture .set_size_override (Vector2 (32 ,32 ))
439+
440+ options .set_item_icon (item , texture )
441+
442+ var current_selected = get_edited_object ()[get_edited_property ()]
443+
444+ for item in options .get_item_count ():
445+ if current_selected == options .get_item_metadata (item ):
446+ options .select (item )
447+
448+
449+ func setup (p_options :PoolStringArray ) -> void :
450+ options .clear ()
451+ var current_value :int = 0
452+ for option_idx in p_options .size ():
453+ var text_split :Array = p_options [option_idx ].split (":" )
454+ if text_split .size () != 1 :
455+ current_value = int (text_split [1 ])
456+
457+ options .add_item (text_split [0 ])
458+ options .set_item_metadata (option_idx , current_value )
459+ current_value += 1
460+
461+
462+ func set_option_button_clip (enable :bool ) -> void :
463+ pass
464+
465+
466+ func _init () -> void :
467+ options = OptionButton .new ()
468+ options .flat = true
469+ options .clip_text = true
470+ options .expand_icon = true
471+ var _options_popup :PopupMenu = options .get_popup ()
472+ _options_popup .allow_search = true
473+ add_child (options )
474+ add_focusable (options )
475+
476+
417477const InspectorTools = preload ("res://addons/textalog/core/inspector_tools.gd" )
418478
419479var plugin_script :EditorPlugin
@@ -424,6 +484,7 @@ var TextClass = load("res://addons/textalog/events/dialog/text.gd")
424484var ChoiceClass = load ("res://addons/textalog/events/dialog/choice.gd" )
425485var _JoinEvent = load ("res://addons/textalog/events/character/join.gd" )
426486var _CharacterClass = load ("res://addons/textalog/resources/character_class/character_class.gd" )
487+ var _CharEventClass = load ("res://addons/textalog/events/character/char_event.gd" )
427488
428489func can_handle (object : Object ) -> bool :
429490
@@ -438,7 +499,10 @@ func can_handle(object: Object) -> bool:
438499
439500 if object is _CharacterClass :
440501 return true
441-
502+
503+ if object is _CharEventClass :
504+ return true
505+
442506 return false
443507
444508
@@ -507,11 +571,21 @@ func parse_property(object: Object, type: int, path: String, hint: int, hint_tex
507571
508572 return true
509573
574+
510575 if object is _CharacterClass :
511576 if path == "portraits" :
512577 var property_node = PortraitsDisplayer .new ()
513578 add_property_editor (path , property_node )
514579 return true
515580
581+
582+ if object is _CharEventClass :
583+ if path == "selected_portrait" :
584+ var property_node = EditorPropertyPortraits .new ()
585+ var options = hint_text .split ("," )
586+ property_node .setup (options )
587+ add_property_editor (path , property_node )
588+ return true
589+
516590 return false
517591
0 commit comments