Skip to content

Commit

Permalink
Improve/fix textbubble style (dialogic-godot#2336)
Browse files Browse the repository at this point in the history
- Adds the ability to LayoutBase to remember information
   - Uses this ability on the textbubble to remember registered characters

- Fixes/Renames the choices_shown signal and thus the badly placed choice buttons in the textbubble
  • Loading branch information
Jowan-Spooner authored Jul 10, 2024
1 parent 3fe2920 commit f7976ee
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 12 deletions.
8 changes: 3 additions & 5 deletions addons/dialogic/Modules/Choice/subsystem_choices.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extends DialogicSubsystem
signal choice_selected(info:Dictionary)
## Emitted when a set of choices is reached and shown.
## Info includes the keys 'choices' (an array of dictionaries with infos on all the choices).
signal choices_shown(info:Dictionary)
signal question_shown(info:Dictionary)

## Contains information on the latest question.
var last_question_info := {}
Expand Down Expand Up @@ -68,10 +68,6 @@ func hide_all_choices() -> void:
node.disconnect('button_up', _on_choice_selected)



func show_choices() -> void:
hide_all_choices()

## Collects information on all the choices of the current question.
## The result is a dictionary like this:
## {'choices':
Expand Down Expand Up @@ -182,7 +178,9 @@ func show_current_question(instant:=true) -> void:
if node.pressed.is_connected(_on_choice_selected):
node.pressed.disconnect(_on_choice_selected)
node.pressed.connect(_on_choice_selected.bind(choice))

_choice_blocker.start(block_delay)
question_shown.emit(question_info)

if missing_button:
printerr("[Dialogic] The layout you are using doesn't have enough Choice Buttons for the choices you are trying to display.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,32 @@ func _ready() -> void:
add_bubble()


func register_character(character:DialogicCharacter, node:Node):
func register_character(character:Variant, node:Node):
if typeof(character) == TYPE_STRING:
var character_string: String = character
if character.begins_with("res://"):
character = load(character)
else:
character = DialogicResourceUtil.get_character_resource(character)
if not character:
printerr("[Dialogic] Textbubble: Tried registering character from invalid string '", character_string, "'.")

registered_characters[character] = node
if len(registered_characters) > len(bubbles) and len(bubbles) < bubble_count:
add_bubble()


func _get_persistent_info() -> Dictionary:
return {"textbubble_registers": registered_characters}


func _load_persistent_info(info: Dictionary) -> void:
var register_info: Dictionary = info.get("textbubble_registers", {})
for character in register_info:
if is_instance_valid(register_info[character]):
register_character(character, register_info[character])


func add_bubble() -> void:
if not has_node('TextBubbleLayer'):
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var bg_padding := 30

func _ready() -> void:
reset()
DialogicUtil.autoload().Choices.choices_shown.connect(_on_choices_shown)
DialogicUtil.autoload().Choices.question_shown.connect(_on_question_shown)


func reset() -> void:
Expand Down Expand Up @@ -133,7 +133,7 @@ func _resize_bubble(content_size:Vector2, popup:=false) -> void:
name_label_holder.size.x = text.size.x


func _on_choices_shown(info:Dictionary) -> void:
func _on_question_shown(info:Dictionary) -> void:
if !is_visible_in_tree():
return

Expand Down
40 changes: 36 additions & 4 deletions addons/dialogic/Resources/dialogic_layout_base.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ extends Node
## Base class that should be extended by custom layouts.


## Method that adds a node as a layer
func add_layer(layer:DialogicLayoutLayer) -> Node:
add_child(layer)
return layer


## Method that returns the given child
func get_layer(index:int) -> Node:
return get_child(index)


## Method to return all the layers
func get_layers() -> Array:
var layers := []
for child in get_children():
Expand All @@ -22,17 +25,18 @@ func get_layers() -> Array:
return layers


## Method that is called to load the export overrides.
## This happens when the style is first introduced,
## but also when switching to a different style using the same scene!
func apply_export_overrides() -> void:
_apply_export_overrides()
for child in get_children():
if child.has_method('_apply_export_overrides'):
child._apply_export_overrides()


func _apply_export_overrides() -> void:
pass


## Returns a setting on this base.
## This is useful so that layers can share settings like base_color, etc.
func get_global_setting(setting:StringName, default:Variant) -> Variant:
if setting in self:
return get(setting)
Expand All @@ -44,3 +48,31 @@ func get_global_setting(setting:StringName, default:Variant) -> Variant:
return get('global_'+str(setting))

return default


## To be overwritten. Apply the settings to your scene here.
func _apply_export_overrides() -> void:
pass


#region HANDLE PERSISTENT DATA
################################################################################

func _enter_tree() -> void:
_load_persistent_info(Engine.get_meta("dialogic_persistent_style_info", {}))


func _exit_tree() -> void:
Engine.set_meta("dialogic_persistent_style_info", _get_persistent_info())


## To be overwritten. Return any info that a later used style might want to know.
func _get_persistent_info() -> Dictionary:
return {}


## To be overwritten. Apply any info that a previous style might have stored and this style should use.
func _load_persistent_info(info: Dictionary) -> void:
pass

#endregion

0 comments on commit f7976ee

Please sign in to comment.