game: Inventar und fünf Vollbilder in 1920 — Titel scharf, Startgepäck
This commit is contained in:
parent
5b11e770b8
commit
3fae74b1e8
56 changed files with 795 additions and 84 deletions
237
game/scenes/ui/inventar.gd
Normal file
237
game/scenes/ui/inventar.gd
Normal file
|
|
@ -0,0 +1,237 @@
|
|||
extends Control
|
||||
## Inventar als Modal über der Karte (docs/ui.md §1).
|
||||
##
|
||||
## Zeigt pro Party-Figur die ausgerüsteten Slots und den Rucksack. Ausrüsten
|
||||
## nimmt ein Stück aus dem Rucksack, Ablegen legt es zurück; die RK kommt aus
|
||||
## `Game.rk()` und ändert sich sofort.
|
||||
|
||||
signal geschlossen
|
||||
|
||||
const THEME := preload("res://scripts/ui/ui_theme.gd")
|
||||
|
||||
const SLOTS := [
|
||||
{"key": "weapon", "label": "Waffe"},
|
||||
{"key": "armor", "label": "Rüstung"},
|
||||
{"key": "shield", "label": "Schild"},
|
||||
]
|
||||
|
||||
var _index := 0
|
||||
var _wurzel: Control
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
theme = THEME.baue()
|
||||
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
_wurzel = Control.new()
|
||||
_wurzel.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
add_child(_wurzel)
|
||||
_bauen()
|
||||
|
||||
|
||||
func _bauen() -> void:
|
||||
_leeren(_wurzel)
|
||||
|
||||
var dimm := UiTheme.dimmung()
|
||||
dimm.color = Color(0.04, 0.03, 0.02, 0.72)
|
||||
_wurzel.add_child(dimm)
|
||||
|
||||
var p := Panel.new()
|
||||
p.position = Vector2(260, 160)
|
||||
p.size = Vector2(1400, 760)
|
||||
p.add_theme_stylebox_override("panel", THEME.flaeche(Color(1, 1, 1)))
|
||||
_wurzel.add_child(p)
|
||||
|
||||
var titel := Label.new()
|
||||
titel.text = "INVENTAR"
|
||||
titel.position = Vector2(40, 24)
|
||||
titel.add_theme_color_override("font_color", UiTheme.GOLD)
|
||||
p.add_child(titel)
|
||||
|
||||
# Partei-Reiter
|
||||
var x := 40
|
||||
for i in Game.party.size():
|
||||
var b := Button.new()
|
||||
b.text = str(Game.party[i].get("name", "?"))
|
||||
b.position = Vector2(x, 80)
|
||||
b.size = Vector2(170, 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))
|
||||
p.add_child(b)
|
||||
x += 180
|
||||
|
||||
if Game.party.is_empty():
|
||||
var leer := Label.new()
|
||||
leer.text = "Keine Figur in der Party."
|
||||
leer.position = Vector2(40, 180)
|
||||
p.add_child(leer)
|
||||
_schliessen_knopf(p)
|
||||
return
|
||||
|
||||
var figur: Dictionary = Game.party[_index]
|
||||
_ausgeruestet(p, figur)
|
||||
_rucksack(p, figur)
|
||||
|
||||
var werte := Label.new()
|
||||
werte.text = "RK %d Angriff +%d TP %d/%d" % [
|
||||
Game.rk(figur), Game.angriffsbonus(figur),
|
||||
int(figur["hp"]["current"]), int(figur["hp"]["max"])]
|
||||
werte.position = Vector2(40, 680)
|
||||
werte.size = Vector2(700, 40)
|
||||
werte.clip_text = true
|
||||
p.add_child(werte)
|
||||
|
||||
_schliessen_knopf(p)
|
||||
|
||||
|
||||
func _ausgeruestet(p: Panel, figur: Dictionary) -> void:
|
||||
var kopf := Label.new()
|
||||
kopf.text = "AUSGERÜSTET"
|
||||
kopf.position = Vector2(40, 160)
|
||||
kopf.add_theme_color_override("font_color", UiTheme.GOLD)
|
||||
p.add_child(kopf)
|
||||
|
||||
var equipment: Dictionary = figur.get("equipment", {})
|
||||
for i in SLOTS.size():
|
||||
var slot: Dictionary = SLOTS[i]
|
||||
var y := 210 + i * 84
|
||||
var slot_label := Label.new()
|
||||
slot_label.text = str(slot["label"])
|
||||
slot_label.position = Vector2(40, y)
|
||||
slot_label.size = Vector2(160, 52)
|
||||
slot_label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
slot_label.clip_text = true
|
||||
p.add_child(slot_label)
|
||||
|
||||
var id := ""
|
||||
if str(slot["key"]) == "shield":
|
||||
if bool(equipment.get("shield", false)):
|
||||
id = "schild"
|
||||
else:
|
||||
id = str(equipment.get(slot["key"], ""))
|
||||
|
||||
var wert := Label.new()
|
||||
wert.text = _item_name(id) if not id.is_empty() else "—"
|
||||
wert.position = Vector2(210, y)
|
||||
wert.size = Vector2(260, 52)
|
||||
wert.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
wert.clip_text = true
|
||||
wert.modulate = Color(0.9, 0.84, 0.70)
|
||||
p.add_child(wert)
|
||||
|
||||
if not id.is_empty():
|
||||
var b := Button.new()
|
||||
b.text = "Ablegen"
|
||||
b.position = Vector2(480, y)
|
||||
b.size = Vector2(200, 52)
|
||||
b.focus_mode = Control.FOCUS_NONE
|
||||
b.clip_text = true
|
||||
b.pressed.connect(_ablegen.bind(str(slot["key"])))
|
||||
p.add_child(b)
|
||||
|
||||
|
||||
func _rucksack(p: Panel, figur: Dictionary) -> void:
|
||||
var kopf := Label.new()
|
||||
kopf.text = "RUCKSACK"
|
||||
kopf.position = Vector2(720, 160)
|
||||
kopf.add_theme_color_override("font_color", UiTheme.GOLD)
|
||||
p.add_child(kopf)
|
||||
|
||||
var inventar: Array = figur.get("inventory", [])
|
||||
if inventar.is_empty():
|
||||
var leer := Label.new()
|
||||
leer.text = "leer"
|
||||
leer.position = Vector2(720, 210)
|
||||
leer.modulate = Color(0.75, 0.70, 0.60)
|
||||
p.add_child(leer)
|
||||
return
|
||||
|
||||
for i in inventar.size():
|
||||
var eintrag = inventar[i]
|
||||
var id := ""
|
||||
var anzahl := 1
|
||||
if typeof(eintrag) == TYPE_DICTIONARY:
|
||||
id = str(eintrag.get("id", ""))
|
||||
anzahl = int(eintrag.get("count", 1))
|
||||
else:
|
||||
id = str(eintrag)
|
||||
if id.is_empty():
|
||||
continue
|
||||
var y := 210 + i * 56
|
||||
if y > 700:
|
||||
break
|
||||
|
||||
var item_label := Label.new()
|
||||
item_label.text = _item_name(id)
|
||||
item_label.position = Vector2(720, y)
|
||||
item_label.size = Vector2(340, 44)
|
||||
item_label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
item_label.clip_text = true
|
||||
p.add_child(item_label)
|
||||
|
||||
if anzahl > 1:
|
||||
var zahl := Label.new()
|
||||
zahl.text = "x%d" % anzahl
|
||||
zahl.position = Vector2(1070, y)
|
||||
zahl.size = Vector2(40, 44)
|
||||
zahl.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
p.add_child(zahl)
|
||||
|
||||
if _ist_ausruestbar(id):
|
||||
var b := Button.new()
|
||||
b.text = "Ausrüsten"
|
||||
b.position = Vector2(1120, y)
|
||||
b.size = Vector2(250, 44)
|
||||
b.focus_mode = Control.FOCUS_NONE
|
||||
b.clip_text = true
|
||||
b.pressed.connect(_ausruesten.bind(id))
|
||||
p.add_child(b)
|
||||
|
||||
|
||||
func _schliessen_knopf(p: Panel) -> void:
|
||||
var b := Button.new()
|
||||
b.text = "Schließen"
|
||||
b.position = Vector2(1120, 680)
|
||||
b.size = Vector2(240, 56)
|
||||
b.focus_mode = Control.FOCUS_NONE
|
||||
b.clip_text = true
|
||||
b.pressed.connect(func() -> void: geschlossen.emit())
|
||||
p.add_child(b)
|
||||
|
||||
|
||||
func _waehlen(index: int) -> void:
|
||||
_index = index
|
||||
_bauen()
|
||||
|
||||
|
||||
func _ausruesten(id: String) -> void:
|
||||
if Game.party.is_empty():
|
||||
return
|
||||
Game.ausruesten(Game.party[_index], id)
|
||||
_bauen()
|
||||
|
||||
|
||||
func _ablegen(slot: String) -> void:
|
||||
if Game.party.is_empty():
|
||||
return
|
||||
Game.ablegen(Game.party[_index], slot)
|
||||
_bauen()
|
||||
|
||||
|
||||
func _item_name(id: String) -> String:
|
||||
if id.is_empty():
|
||||
return "—"
|
||||
var item: Dictionary = Content.entry("items", id)
|
||||
return str(item.get("name", id))
|
||||
|
||||
|
||||
func _ist_ausruestbar(id: String) -> bool:
|
||||
var typ := str(Content.entry("items", id).get("type", ""))
|
||||
return typ in ["weapon", "armor", "shield"]
|
||||
|
||||
|
||||
func _leeren(node: Node) -> void:
|
||||
for kind in node.get_children():
|
||||
node.remove_child(kind)
|
||||
kind.queue_free()
|
||||
1
game/scenes/ui/inventar.gd.uid
Normal file
1
game/scenes/ui/inventar.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://diskvqdrx6qkd
|
||||
12
game/scenes/ui/inventar.tscn
Normal file
12
game/scenes/ui/inventar.tscn
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/ui/inventar.gd" id="1"]
|
||||
|
||||
[node name="Inventar" 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")
|
||||
Loading…
Add table
Add a link
Reference in a new issue