167 lines
4.8 KiB
GDScript
167 lines
4.8 KiB
GDScript
extends Control
|
|
## Zauber vorbereiten (Vancian): je Platz ein Spruch, den die Figur kennt.
|
|
##
|
|
## Erreichbar aus dem Pausenmenü. Kleriker wählen aus der ganzen Liste ihres
|
|
## Grades, Magier nur aus ihrem Buch — beides steht als `known` in der Figur.
|
|
## Änderungen gelten sofort; der Stand wird mit dem Spielstand gespeichert.
|
|
|
|
signal geschlossen
|
|
|
|
const THEME := preload("res://scripts/ui/ui_theme.gd")
|
|
|
|
var _index := 0
|
|
var _panel: Panel
|
|
var _inhalt: Control
|
|
|
|
|
|
func _ready() -> void:
|
|
theme = THEME.baue()
|
|
if Game.party.is_empty() and OS.get_cmdline_user_args().has("--schnellstart"):
|
|
Game.party_schnellstart()
|
|
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
|
|
var dimm := ColorRect.new()
|
|
dimm.color = Color(0.03, 0.02, 0.01, 0.74)
|
|
dimm.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
dimm.mouse_filter = Control.MOUSE_FILTER_STOP
|
|
add_child(dimm)
|
|
|
|
_panel = Panel.new()
|
|
_panel.position = Vector2(340, 120)
|
|
_panel.size = Vector2(1240, 840)
|
|
_panel.add_theme_stylebox_override("panel", THEME.flaeche(Color(1, 1, 1)))
|
|
add_child(_panel)
|
|
|
|
_index = 0
|
|
_bauen()
|
|
|
|
|
|
func _input(event: InputEvent) -> void:
|
|
if event is InputEventKey and event.pressed and not event.echo:
|
|
if event.physical_keycode == KEY_ESCAPE or event.keycode == KEY_ESCAPE:
|
|
geschlossen.emit()
|
|
get_viewport().set_input_as_handled()
|
|
|
|
|
|
func _bauen() -> void:
|
|
if _inhalt != null:
|
|
_inhalt.queue_free()
|
|
_inhalt = Control.new()
|
|
_inhalt.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
_panel.add_child(_inhalt)
|
|
|
|
var titel := Label.new()
|
|
titel.text = "ZAUBER VORBEREITEN"
|
|
titel.position = Vector2(48, 32)
|
|
titel.add_theme_color_override("font_color", THEME.GOLD)
|
|
_inhalt.add_child(titel)
|
|
|
|
# Reiter: eine Schaltfläche je zauberkundiger Figur.
|
|
var x := 48
|
|
for i in Game.party.size():
|
|
if not _hat_zauber(Game.party[i]):
|
|
continue
|
|
var b := Button.new()
|
|
b.text = str(Game.party[i].get("name", "?"))
|
|
b.position = Vector2(x, 88)
|
|
b.size = Vector2(220, 52)
|
|
b.focus_mode = Control.FOCUS_NONE
|
|
b.clip_text = true
|
|
b.modulate = Color(1.45, 1.25, 0.95) if i == _index else Color(1, 1, 1)
|
|
b.pressed.connect(_waehlen.bind(i))
|
|
_inhalt.add_child(b)
|
|
x += 232
|
|
|
|
if _index >= Game.party.size() or not _hat_zauber(Game.party[_index]):
|
|
_index = _erste_zauberin()
|
|
|
|
var figur: Dictionary = Game.party[_index] if _index >= 0 else {}
|
|
var y := 168
|
|
for grad in [1, 2, 3]:
|
|
var plaetze := Game.zauberplatz(figur, grad)
|
|
if plaetze <= 0:
|
|
continue
|
|
var kopf := Label.new()
|
|
kopf.text = "GRAD %d — %d von %d Plätzen belegt" % [grad,
|
|
Game.grad_belegt(figur, grad), plaetze]
|
|
kopf.position = Vector2(48, y)
|
|
kopf.add_theme_color_override("font_color", THEME.GOLD)
|
|
_inhalt.add_child(kopf)
|
|
y += 52
|
|
for id in figur.get("spells", {}).get("known", []):
|
|
var sp := Content.entry("spells", str(id))
|
|
if int(sp.get("level", 1)) != grad:
|
|
continue
|
|
var anzahl := Game.ist_vorbereitet(figur, str(id))
|
|
var name := Label.new()
|
|
name.text = "%s %s" % [str(sp.get("name", id)),
|
|
"x %d" % anzahl if anzahl > 0 else ""]
|
|
name.position = Vector2(48, y)
|
|
name.size = Vector2(620, 44)
|
|
name.clip_text = true
|
|
_inhalt.add_child(name)
|
|
var info := Label.new()
|
|
info.text = "RW %d" % int(sp.get("range", 0))
|
|
info.position = Vector2(700, y)
|
|
info.size = Vector2(120, 44)
|
|
info.modulate = Color(0.8, 0.76, 0.66)
|
|
_inhalt.add_child(info)
|
|
var minus := _klein(Vector2(800, y - 4), "-")
|
|
minus.disabled = anzahl <= 0
|
|
minus.pressed.connect(_abwaehlen.bind(str(id)))
|
|
var plus := _klein(Vector2(900, y - 4), "+")
|
|
plus.disabled = Game.grad_belegt(figur, grad) >= plaetze
|
|
plus.pressed.connect(_vorbereiten.bind(str(id)))
|
|
y += 52
|
|
|
|
var zu := Button.new()
|
|
zu.text = "FERTIG"
|
|
zu.position = Vector2(48, 760)
|
|
zu.size = Vector2(300, 56)
|
|
zu.focus_mode = Control.FOCUS_NONE
|
|
zu.clip_text = true
|
|
zu.pressed.connect(func() -> void:
|
|
Audio.sfx("klick", 0.03, 0.8)
|
|
geschlossen.emit())
|
|
_inhalt.add_child(zu)
|
|
|
|
|
|
func _klein(pos: Vector2, text: String) -> Button:
|
|
var b := Button.new()
|
|
b.text = text
|
|
b.position = pos
|
|
# Breit genug für "+": die Stylebox hat 24 px Innenabstand je Seite.
|
|
b.size = Vector2(84, 52)
|
|
b.focus_mode = Control.FOCUS_NONE
|
|
b.clip_text = true
|
|
# Auch abgeschaltet lesbar: sonst verschwindet das "+" im Braun.
|
|
b.add_theme_color_override("font_disabled_color", Color(0.52, 0.47, 0.40))
|
|
b.pressed.connect(func() -> void: Audio.sfx("klick", 0.03, 0.7))
|
|
_inhalt.add_child(b)
|
|
return b
|
|
|
|
|
|
func _hat_zauber(figur: Dictionary) -> bool:
|
|
return not (figur.get("spells", {}).get("known", []) as Array).is_empty()
|
|
|
|
|
|
func _erste_zauberin() -> int:
|
|
for i in Game.party.size():
|
|
if _hat_zauber(Game.party[i]):
|
|
return i
|
|
return -1
|
|
|
|
|
|
func _waehlen(i: int) -> void:
|
|
_index = i
|
|
_bauen()
|
|
|
|
|
|
func _vorbereiten(id: String) -> void:
|
|
Game.vorbereiten(Game.party[_index], id)
|
|
_bauen()
|
|
|
|
|
|
func _abwaehlen(id: String) -> void:
|
|
Game.abwaehlen(Game.party[_index], id)
|
|
_bauen()
|