windgeschworen/scripts/ui/dialogue_box.gd
danny 3cdf5f6ac5 Phase 3: Charakter-Anlage + Viadukt-Set-Piece mit Wren-Moment
- Charakter-Anlage (character_creation.tscn): Namenseingabe mit Default
  Tyrveil, Enter/confirm bestaetigt, cancel zurueck; Controller nutzt den
  Tastatur-Fallback mit bestaetigbarem Default (virtuelle Tastatur bewusst
  ausgelassen, nur Mobile/Web nativ); Name in GameState.player_name,
  erscheint in der Dialog-Box
- Neues Spiel: Hauptmenue -> Charakter-Anlage -> Viadukt -> (Platzhalter-
  Uebergang) Reiterquadrant; Fortsetzen unveraendert
- Viadukt (scenes/viaduct): vier kurze Segmente - schmaler Steg mit
  Sprung-Luecke und Gelaender-Stuecken, Kletter-Engstelle (Mechanik aus
  Phase 1b), Wren-Moment, Endplattform mit Uebergang; cineastischer
  Kamera-Schwenk beim Betreten (player.play_camera_pan, SPEC 2)
- Wren-Moment: nicht abbrechbarer Entscheidungspunkt ueber das bestehende
  Dialog-System (can_abort:false sperrt cancel UND dialogue_abort);
  beide Optionen retten Wren (fixer Ausgang laut STORY.md), Klinge/Herz
  -10/+10, Beziehung +1/+3, Wahl als Story-Flag viaduct_wren_rescue
  (neues gespeichertes story_flags-Muster im GameState)
- Permadeath: KillZone unter dem Steg - AN: Game Over ins Hauptmenue,
  AUS: Respawn am zuletzt erreichten Segment-Checkpoint
- DialogueSystem: story_flag-Options-Tag, is_abort_allowed,
  Spielername aus GameState in der Box
- .idea/ in .gitignore aufgenommen
- Headless verifiziert (23 Checks): Namensfluss, Pan-Sperre, Respawn,
  Abbruch-Sperre im Wren-Moment, beide Pfade inkl. Flags, Endübergang,
  Game Over bei Permadeath AN

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-05 12:15:32 +02:00

111 lines
3.6 KiB
GDScript

extends CanvasLayer
## Dialog-Box am unteren Bildrand im Stil von Baldur's Gate 3
## (Change Request, siehe docs/CHANGEREQUESTS_DONE.md).
##
## Zeigt jede Dialog-Zeile gut lesbar mit Sprechernamen an und beherbergt
## die fokus-navigierbare Antwortauswahl; die Sprechblasen über den Köpfen
## bleiben als Ambiente bestehen. Navigation über Pfeiltasten/D-Pad/linken
## Stick, Aktivierung über confirm (Enter/Ⓐ/✕) nach dem Muster des
## Hauptmenü-Fixes: Events, die auch Godots ui_accept matchen, verarbeitet
## der fokussierte Button selbst, nur die übrigen (Controller) lösen
## manuell aus. choose() liefert den Index der gewählten Option als
## Coroutine.
signal option_chosen(index: int)
const ABORT_INDEX := -1
@onready var _speaker_label: Label = $Root/Panel/Margin/Content/SpeakerLabel
@onready var _line_label: Label = $Root/Panel/Margin/Content/LineLabel
@onready var _options_box: VBoxContainer = $Root/Panel/Margin/Content/OptionsBox
## Startet unsichtbar; sichtbar wird die Box über show_line().
func _ready() -> void:
visible = false
## Zeigt eine Dialog-Zeile mit Sprechernamen; eine noch offene
## Antwortauswahl wird dabei geleert.
func show_line(speaker_name: String, text: String) -> void:
_speaker_label.text = speaker_name
_line_label.text = text
_clear_options()
visible = true
## Zeigt die Antwortoptionen unterhalb der aktuellen Zeile an und liefert
## den Index der gewählten Option, sobald der Spieler bestätigt hat.
func choose(option_texts: Array) -> int:
_show_options(option_texts)
var index: int = await option_chosen
return index
## Blendet die Box am Dialogende aus.
func hide_box() -> void:
_clear_options()
visible = false
## Meldet, ob gerade eine Antwortauswahl offen ist (auch für Test-Sonden).
func has_open_options() -> bool:
return visible and _options_box.visible
## Aktiviert mit confirm den fokussierten Options-Button und meldet mit
## cancel den Dialog-Abbruch als ABORT_INDEX (nur solange eine Auswahl
## offen ist); Fokus-Verlust wird auf die erste Option repariert.
func _unhandled_input(event: InputEvent) -> void:
if not has_open_options():
return
if event.is_action_pressed("cancel") or event.is_action_pressed("dialogue_abort"):
if not DialogueSystem.is_abort_allowed:
return
_clear_options()
option_chosen.emit(ABORT_INDEX)
return
if not event.is_action_pressed("confirm"):
return
var focused := get_viewport().gui_get_focus_owner()
if focused == null or focused.get_parent() != _options_box:
if _options_box.get_child_count() > 0:
(_options_box.get_child(0) as Button).grab_focus()
return
if event.is_action("ui_accept"):
return
var button := focused as BaseButton
if button != null and not button.disabled:
button.pressed.emit()
## Baut die Options-Buttons neu auf und setzt den Fokus auf die erste
## Option.
func _show_options(option_texts: Array) -> void:
_clear_options()
var first_button: Button = null
for i in option_texts.size():
var button := Button.new()
button.text = str(option_texts[i])
button.custom_minimum_size = Vector2(0, 40)
button.pressed.connect(_on_option_pressed.bind(i))
_options_box.add_child(button)
if first_button == null:
first_button = button
_options_box.visible = true
if first_button != null:
first_button.grab_focus.call_deferred()
## Entfernt alle Options-Buttons und blendet die Options-Leiste aus.
func _clear_options() -> void:
for child in _options_box.get_children():
_options_box.remove_child(child)
child.queue_free()
_options_box.visible = false
## Schließt die Auswahl und meldet den gewählten Index.
func _on_option_pressed(index: int) -> void:
_clear_options()
option_chosen.emit(index)