Add dialogue progress controls

This commit is contained in:
2026-06-18 12:57:17 +09:00
parent 0be75ac1c9
commit 68342c1b0b
5 changed files with 48 additions and 8 deletions

View File

@@ -117,6 +117,8 @@ var dialogue_portrait_label: Label
var dialogue_column: VBoxContainer
var dialogue_speaker_label: Label
var dialogue_text_label: Label
var dialogue_progress_label: Label
var dialogue_previous_button: Button
var dialogue_continue_button: Button
var result_panel: PanelContainer
var result_label: Label
@@ -175,7 +177,9 @@ func _unhandled_input(event: InputEvent) -> void:
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
_advance_dialogue()
elif event is InputEventKey and event.pressed and not event.echo:
if event.keycode == KEY_ENTER or event.keycode == KEY_SPACE or event.keycode == KEY_ESCAPE:
if event.keycode == KEY_LEFT or event.keycode == KEY_BACKSPACE:
_retreat_dialogue()
elif event.keycode == KEY_ENTER or event.keycode == KEY_SPACE or event.keycode == KEY_ESCAPE or event.keycode == KEY_RIGHT:
_advance_dialogue()
return
@@ -604,12 +608,28 @@ func _create_hud() -> void:
dialogue_text_label.add_theme_font_size_override("font_size", 17)
dialogue_column.add_child(dialogue_text_label)
var dialogue_control_row := HBoxContainer.new()
dialogue_control_row.add_theme_constant_override("separation", 8)
dialogue_column.add_child(dialogue_control_row)
dialogue_progress_label = Label.new()
dialogue_progress_label.custom_minimum_size = Vector2(520, 32)
dialogue_progress_label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
dialogue_progress_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT
dialogue_control_row.add_child(dialogue_progress_label)
dialogue_previous_button = Button.new()
dialogue_previous_button.text = "Prev"
dialogue_previous_button.disabled = true
dialogue_previous_button.custom_minimum_size = Vector2(88, 32)
dialogue_previous_button.pressed.connect(_retreat_dialogue)
dialogue_control_row.add_child(dialogue_previous_button)
dialogue_continue_button = Button.new()
dialogue_continue_button.text = "Next"
dialogue_continue_button.custom_minimum_size = Vector2(120, 32)
dialogue_continue_button.size_flags_horizontal = Control.SIZE_SHRINK_END
dialogue_continue_button.pressed.connect(_advance_dialogue)
dialogue_column.add_child(dialogue_continue_button)
dialogue_control_row.add_child(dialogue_continue_button)
result_panel = PanelContainer.new()
result_panel.visible = false
@@ -1986,12 +2006,20 @@ func _render_dialogue_line() -> void:
dialogue_speaker_label.visible = not speaker.is_empty()
dialogue_text_label.text = str(line.get("text", ""))
_update_dialogue_portrait(speaker, str(line.get("portrait", "")))
dialogue_continue_button.text = "Close" if active_dialogue_index >= active_dialogue_lines.size() - 1 else "Next"
_update_dialogue_controls()
dialogue_panel.visible = true
_update_hud()
queue_redraw()
func _update_dialogue_controls() -> void:
if dialogue_progress_label != null:
dialogue_progress_label.text = "%d / %d" % [active_dialogue_index + 1, active_dialogue_lines.size()]
if dialogue_previous_button != null:
dialogue_previous_button.disabled = active_dialogue_index <= 0
dialogue_continue_button.text = "Close" if active_dialogue_index >= active_dialogue_lines.size() - 1 else "Next"
func _apply_dialogue_side(side: String) -> void:
if dialogue_row == null or dialogue_portrait_panel == null or dialogue_column == null:
return
@@ -2070,11 +2098,23 @@ func _advance_dialogue() -> void:
queue_redraw()
func _retreat_dialogue() -> void:
if not _is_dialogue_visible() or active_dialogue_index <= 0:
return
_play_ui_click()
active_dialogue_index -= 1
_render_dialogue_line()
func _hide_dialogue_panel() -> void:
if dialogue_panel != null:
dialogue_panel.visible = false
active_dialogue_lines.clear()
active_dialogue_index = 0
if dialogue_progress_label != null:
dialogue_progress_label.text = ""
if dialogue_previous_button != null:
dialogue_previous_button.disabled = true
func _clear_dialogue() -> void: