Skip to content

Commit

Permalink
Allow for specifying a response template (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanhoad authored Oct 21, 2023
1 parent e58746d commit 9a84be9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
6 changes: 3 additions & 3 deletions addons/dialogue_manager/dialogue_label.gd
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ func type_out() -> void:
if get_total_character_count() == 0:
self.is_typing = false
elif seconds_per_step == 0:
_mutation_remaining_mutations()
_mutate_remaining_mutations()
visible_characters = get_total_character_count()
self.is_typing = false


## Stop typing out the text and jump right to the end
func skip_typing() -> void:
_mutation_remaining_mutations()
_mutate_remaining_mutations()
visible_characters = get_total_character_count()
self.is_typing = false
skipped_typing.emit()
Expand Down Expand Up @@ -147,7 +147,7 @@ func _get_speed(at_index: int) -> float:


# Run any inline mutations that haven't been run yet
func _mutation_remaining_mutations() -> void:
func _mutate_remaining_mutations() -> void:
for i in range(visible_characters, get_total_character_count() + 1):
_mutate_inline_mutations(i)

Expand Down
12 changes: 11 additions & 1 deletion addons/dialogue_manager/dialogue_reponses_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class_name DialogueResponsesMenu extends VBoxContainer
signal response_selected(response: DialogueResponse)


## Optionally specify a control to duplicate for each response
@export var response_template: Control

# The list of dialogue responses.
var _responses: Array = []

Expand All @@ -18,6 +21,9 @@ func _ready() -> void:
get_menu_items()[0].grab_focus()
)

if is_instance_valid(response_template):
response_template.get_parent().remove_child(response_template)


## Set the list of responses to show.
func set_responses(next_responses: Array) -> void:
Expand All @@ -31,7 +37,11 @@ func set_responses(next_responses: Array) -> void:
# Add new items
if _responses.size() > 0:
for response in _responses:
var item: Button = Button.new()
var item: Control
if is_instance_valid(response_template):
item = response_template.duplicate()
else:
item = Button.new()
item.name = "Response%d" % get_child_count()
if not response.is_allowed:
item.name = String(item.name) + "Disallowed"
Expand Down
3 changes: 2 additions & 1 deletion addons/dialogue_manager/example_balloon/example_balloon.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,13 @@ offset_bottom = -0.552
grow_horizontal = 2
grow_vertical = 2

[node name="ResponsesMenu" type="VBoxContainer" parent="Balloon/Responses"]
[node name="ResponsesMenu" type="VBoxContainer" parent="Balloon/Responses" node_paths=PackedStringArray("response_template")]
unique_name_in_owner = true
layout_mode = 2
size_flags_vertical = 8
theme_override_constants/separation = 2
script = ExtResource("3_72ixx")
response_template = NodePath("ResponseExample")

[node name="ResponseExample" type="Button" parent="Balloon/Responses/ResponsesMenu"]
layout_mode = 2
Expand Down

0 comments on commit 9a84be9

Please sign in to comment.