game: Zauber müssen vorbereitet werden (Vancian) — Vorbereitung im Pausenmenü
This commit is contained in:
parent
145931d133
commit
f80f3831bc
14 changed files with 392 additions and 42 deletions
|
|
@ -21,6 +21,7 @@ var _panel: Panel
|
|||
var _ansicht := ""
|
||||
var _meldung: Label
|
||||
var _einstellungen: Control
|
||||
var _vorbereiten: Control
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
|
|
@ -130,12 +131,20 @@ func _bauen(ansicht: String) -> void:
|
|||
|
||||
|
||||
func _haupt() -> void:
|
||||
var y := 120
|
||||
# Sechs Einträge müssen in 600 px Panelhöhe passen: 76 px Abstand.
|
||||
var y := 112
|
||||
_knopf("WEITERSPIELEN", y, func() -> void: weiter.emit())
|
||||
_knopf("SPEICHERN", y + 84, func() -> void: _bauen("speichern"))
|
||||
_knopf("LADEN", y + 168, func() -> void: _bauen("laden"))
|
||||
_knopf("EINSTELLUNGEN", y + 252, _einstellungen_oeffnen)
|
||||
_knopf("ZUM TITEL", y + 336, func() -> void: zum_titel.emit())
|
||||
y += 76
|
||||
_knopf("SPEICHERN", y, func() -> void: _bauen("speichern"))
|
||||
y += 76
|
||||
_knopf("LADEN", y, func() -> void: _bauen("laden"))
|
||||
y += 76
|
||||
if _hat_zauberin():
|
||||
_knopf("ZAUBER VORBEREITEN", y, _vorbereiten_oeffnen)
|
||||
y += 76
|
||||
_knopf("EINSTELLUNGEN", y, _einstellungen_oeffnen)
|
||||
y += 76
|
||||
_knopf("ZUM TITEL", y, func() -> void: zum_titel.emit())
|
||||
|
||||
|
||||
func _slots(speichern: bool) -> void:
|
||||
|
|
@ -200,6 +209,25 @@ func escape() -> bool:
|
|||
return false
|
||||
|
||||
|
||||
## Vancian: vor dem Kampf die Sprüche in die Plätze legen.
|
||||
func _vorbereiten_oeffnen() -> void:
|
||||
if _vorbereiten != null:
|
||||
return
|
||||
Audio.sfx("klick", 0.03, 0.8)
|
||||
_vorbereiten = load("res://scenes/ui/vorbereiten.tscn").instantiate()
|
||||
add_child(_vorbereiten)
|
||||
_vorbereiten.geschlossen.connect(func() -> void:
|
||||
_vorbereiten.queue_free()
|
||||
_vorbereiten = null)
|
||||
|
||||
|
||||
func _hat_zauberin() -> bool:
|
||||
for figur in Game.party:
|
||||
if not (figur.get("spells", {}).get("known", []) as Array).is_empty():
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func _einstellungen_oeffnen() -> void:
|
||||
if _einstellungen != null:
|
||||
return
|
||||
|
|
|
|||
167
game/scenes/ui/vorbereiten.gd
Normal file
167
game/scenes/ui/vorbereiten.gd
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
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()
|
||||
1
game/scenes/ui/vorbereiten.gd.uid
Normal file
1
game/scenes/ui/vorbereiten.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://d34tv3yqkvcrm
|
||||
12
game/scenes/ui/vorbereiten.tscn
Normal file
12
game/scenes/ui/vorbereiten.tscn
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/ui/vorbereiten.gd" id="1_vor"]
|
||||
|
||||
[node name="Vorbereiten" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_vor")
|
||||
Loading…
Add table
Add a link
Reference in a new issue