game: Inventar-Raster mit Icons, Klassenregeln, Gold und Verbrauch
This commit is contained in:
parent
3fae74b1e8
commit
a78de0ffec
61 changed files with 1047 additions and 148 deletions
|
|
@ -1,9 +1,9 @@
|
|||
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.
|
||||
## 5×3-Raster mit Item-Icons, ausgerüstete Slots links, Details und Aktionen
|
||||
## rechts. Ausrüsten prüft die Klassenbeschränkung aus `classes.json`;
|
||||
## Verbrauchsgüter laufen über `Game.benutzen()`.
|
||||
|
||||
signal geschlossen
|
||||
|
||||
|
|
@ -14,9 +14,17 @@ const SLOTS := [
|
|||
{"key": "armor", "label": "Rüstung"},
|
||||
{"key": "shield", "label": "Schild"},
|
||||
]
|
||||
const SPALTEN := 5
|
||||
const ZEILEN := 3
|
||||
const KACHEL := 88
|
||||
const ABSTAND := 8
|
||||
const RASTER := Vector2(640, 200)
|
||||
|
||||
var _index := 0
|
||||
var _wurzel: Control
|
||||
var _sel_id := ""
|
||||
var _sel_quelle := "" ## "inventar" oder "slot"
|
||||
var _meldung := ""
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
|
|
@ -41,13 +49,47 @@ func _bauen() -> void:
|
|||
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)
|
||||
_titel(p)
|
||||
_reiter(p)
|
||||
_gold(p)
|
||||
|
||||
# Partei-Reiter
|
||||
if Game.party.is_empty():
|
||||
_label(p, "Keine Figur in der Party.", Vector2(40, 200))
|
||||
_schliessen_knopf(p)
|
||||
return
|
||||
|
||||
var figur: Dictionary = Game.party[_index]
|
||||
_ausgeruestet(p, figur)
|
||||
_rucksack(p, figur)
|
||||
_details(p, figur)
|
||||
|
||||
_label(p, "RK %d Angriff +%d TP %d/%d" % [
|
||||
Game.rk(figur), Game.angriffsbonus(figur),
|
||||
int(figur["hp"]["current"]), int(figur["hp"]["max"])],
|
||||
Vector2(40, 680), Vector2(700, 40))
|
||||
_schliessen_knopf(p)
|
||||
|
||||
|
||||
func _titel(p: Panel) -> void:
|
||||
var l := Label.new()
|
||||
l.text = "INVENTAR"
|
||||
l.position = Vector2(40, 24)
|
||||
l.add_theme_color_override("font_color", UiTheme.GOLD)
|
||||
p.add_child(l)
|
||||
|
||||
|
||||
func _gold(p: Panel) -> void:
|
||||
var l := Label.new()
|
||||
l.text = "Gold: %d" % Game.gold
|
||||
l.position = Vector2(1080, 24)
|
||||
l.size = Vector2(280, 40)
|
||||
l.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT
|
||||
l.clip_text = true
|
||||
l.add_theme_color_override("font_color", UiTheme.GOLD)
|
||||
p.add_child(l)
|
||||
|
||||
|
||||
func _reiter(p: Panel) -> void:
|
||||
var x := 40
|
||||
for i in Game.party.size():
|
||||
var b := Button.new()
|
||||
|
|
@ -57,53 +99,21 @@ func _bauen() -> void:
|
|||
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))
|
||||
b.pressed.connect(_waehlen_figur.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)
|
||||
|
||||
# ------------------------------------------------------------- ausgerüstet --
|
||||
|
||||
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)
|
||||
_label(p, "AUSGERÜSTET", Vector2(40, 160),
|
||||
Vector2(300, 40), UiTheme.GOLD)
|
||||
|
||||
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 y := 210 + i * 100
|
||||
var id := ""
|
||||
if str(slot["key"]) == "shield":
|
||||
if bool(equipment.get("shield", false)):
|
||||
|
|
@ -111,19 +121,17 @@ func _ausgeruestet(p: Panel, figur: Dictionary) -> void:
|
|||
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():
|
||||
_icon(p, id, Vector2(40, y))
|
||||
_label(p, str(slot["label"]), Vector2(120, y + 12),
|
||||
Vector2(260, 40), UiTheme.CREAM_D)
|
||||
_label(p, _item_name(id) if not id.is_empty() else "—",
|
||||
Vector2(120, y + 44), Vector2(260, 40))
|
||||
|
||||
if not id.is_empty():
|
||||
var b := Button.new()
|
||||
b.text = "Ablegen"
|
||||
b.position = Vector2(480, y)
|
||||
b.position = Vector2(400, y + 6)
|
||||
b.size = Vector2(200, 52)
|
||||
b.focus_mode = Control.FOCUS_NONE
|
||||
b.clip_text = true
|
||||
|
|
@ -131,62 +139,205 @@ func _ausgeruestet(p: Panel, figur: Dictionary) -> void:
|
|||
p.add_child(b)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- Rucksack --
|
||||
|
||||
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)
|
||||
_label(p, "RUCKSACK", RASTER + Vector2(0, -40),
|
||||
Vector2(300, 40), UiTheme.GOLD)
|
||||
|
||||
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)
|
||||
for i in SPALTEN * ZEILEN:
|
||||
var x := RASTER.x + (i % SPALTEN) * (KACHEL + ABSTAND)
|
||||
var y := RASTER.y + (i / SPALTEN) * (KACHEL + ABSTAND)
|
||||
if i < 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)
|
||||
_slot_knopf(p, id, anzahl, Vector2(x, y))
|
||||
else:
|
||||
_leerer_slot(p, Vector2(x, y))
|
||||
|
||||
|
||||
func _slot_knopf(p: Panel, id: String, anzahl: int, pos: Vector2) -> void:
|
||||
var b := Button.new()
|
||||
b.position = pos
|
||||
b.size = Vector2(KACHEL, KACHEL)
|
||||
b.focus_mode = Control.FOCUS_NONE
|
||||
b.tooltip_text = _item_name(id)
|
||||
_slot_style(b, _sel_id == id and _sel_quelle == "inventar")
|
||||
b.pressed.connect(_waehlen_item.bind(id))
|
||||
p.add_child(b)
|
||||
|
||||
var t := _item_textur(id)
|
||||
if t != null:
|
||||
var icon := TextureRect.new()
|
||||
icon.texture = t
|
||||
icon.position = Vector2(12, 6)
|
||||
icon.size = Vector2(64, 64)
|
||||
icon.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
|
||||
icon.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
|
||||
icon.texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST
|
||||
icon.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
b.add_child(icon)
|
||||
|
||||
if anzahl > 1:
|
||||
var zahl := Label.new()
|
||||
zahl.text = str(anzahl)
|
||||
zahl.position = Vector2(44, 54)
|
||||
zahl.size = Vector2(40, 30)
|
||||
zahl.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT
|
||||
zahl.add_theme_color_override("font_outline_color", UiTheme.INK)
|
||||
zahl.add_theme_constant_override("outline_size", 6)
|
||||
zahl.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
b.add_child(zahl)
|
||||
|
||||
|
||||
func _leerer_slot(p: Panel, pos: Vector2) -> void:
|
||||
var panel := Panel.new()
|
||||
panel.position = pos
|
||||
panel.size = Vector2(KACHEL, KACHEL)
|
||||
var sb := StyleBoxFlat.new()
|
||||
sb.bg_color = Color(UiTheme.PANEL_LO, 0.7)
|
||||
sb.border_color = Color(UiTheme.LINE, 0.45)
|
||||
sb.set_border_width_all(2)
|
||||
panel.add_theme_stylebox_override("panel", sb)
|
||||
p.add_child(panel)
|
||||
|
||||
|
||||
func _slot_style(b: Button, gewaehlt: bool) -> void:
|
||||
var normal := StyleBoxFlat.new()
|
||||
normal.bg_color = UiTheme.PANEL_LO
|
||||
normal.border_color = UiTheme.GOLD if gewaehlt else UiTheme.LINE
|
||||
normal.set_border_width_all(2)
|
||||
var heiss := normal.duplicate() as StyleBoxFlat
|
||||
heiss.bg_color = UiTheme.PANEL_HI
|
||||
heiss.border_color = UiTheme.GOLD
|
||||
b.add_theme_stylebox_override("normal", normal)
|
||||
b.add_theme_stylebox_override("hover", heiss)
|
||||
b.add_theme_stylebox_override("pressed", heiss)
|
||||
b.add_theme_stylebox_override("focus", normal)
|
||||
|
||||
|
||||
# ----------------------------------------------------------------- Details --
|
||||
|
||||
func _details(p: Panel, figur: Dictionary) -> void:
|
||||
var box := Panel.new()
|
||||
box.position = Vector2(640, 510)
|
||||
box.size = Vector2(720, 150)
|
||||
box.add_theme_stylebox_override("panel", THEME.flaeche(Color(1, 1, 1)))
|
||||
p.add_child(box)
|
||||
|
||||
if _sel_id.is_empty():
|
||||
_label(box, "Wähle einen Gegenstand.", Vector2(20, 20),
|
||||
Vector2(680, 40), UiTheme.CREAM_D)
|
||||
if not _meldung.is_empty():
|
||||
_label(box, _meldung, Vector2(20, 80), Vector2(680, 36),
|
||||
Color(0.88, 0.78, 0.55))
|
||||
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))
|
||||
_label(box, _item_name(_sel_id), Vector2(20, 16),
|
||||
Vector2(420, 40), UiTheme.GOLD)
|
||||
|
||||
var typ := _item_typ(_sel_id)
|
||||
var item: Dictionary = Content.entry("items", _sel_id)
|
||||
var beschreibung := "Sonstiges"
|
||||
match typ:
|
||||
"weapon":
|
||||
beschreibung = "Waffe - %s" % str(item.get("damage", "?"))
|
||||
"armor":
|
||||
beschreibung = "Rüstung - RK +%d" % int(item.get("ac_bonus", 0))
|
||||
"shield":
|
||||
beschreibung = "Schild - RK +%d" % int(item.get("ac_bonus", 0))
|
||||
_label(box, beschreibung, Vector2(20, 58), Vector2(420, 36), UiTheme.CREAM_D)
|
||||
|
||||
if _sel_quelle == "slot":
|
||||
_aktions_knopf(box, "Ablegen", _ablegen.bind(_sel_id))
|
||||
elif typ in ["weapon", "armor", "shield"]:
|
||||
var erlaubt: bool = Game.ausruesten_erlaubt(figur, _sel_id)
|
||||
if erlaubt:
|
||||
_aktions_knopf(box, "Ausrüsten", _ausruesten.bind(_sel_id))
|
||||
else:
|
||||
id = str(eintrag)
|
||||
if id.is_empty():
|
||||
continue
|
||||
var y := 210 + i * 56
|
||||
if y > 700:
|
||||
break
|
||||
_label(box, "Diese Klasse darf das nicht tragen.",
|
||||
Vector2(20, 104), Vector2(560, 36), Color(0.85, 0.55, 0.42))
|
||||
else:
|
||||
_aktions_knopf(box, "Benutzen", _benutzen.bind(_sel_id))
|
||||
|
||||
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 not _meldung.is_empty():
|
||||
_label(box, _meldung, Vector2(20, 104), Vector2(660, 36),
|
||||
Color(0.88, 0.78, 0.55))
|
||||
|
||||
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 _aktions_knopf(box: Panel, text: String, cb: Callable) -> void:
|
||||
var b := Button.new()
|
||||
b.text = text
|
||||
b.position = Vector2(450, 30)
|
||||
b.size = Vector2(250, 56)
|
||||
b.focus_mode = Control.FOCUS_NONE
|
||||
b.clip_text = true
|
||||
b.pressed.connect(cb)
|
||||
box.add_child(b)
|
||||
|
||||
|
||||
# -------------------------------------------------------------- Aktionen ----
|
||||
|
||||
func _waehlen_figur(index: int) -> void:
|
||||
_index = index
|
||||
_sel_id = ""
|
||||
_sel_quelle = ""
|
||||
_meldung = ""
|
||||
_bauen()
|
||||
|
||||
|
||||
func _waehlen_item(id: String) -> void:
|
||||
_sel_id = id
|
||||
_sel_quelle = "inventar"
|
||||
_meldung = ""
|
||||
_bauen()
|
||||
|
||||
|
||||
func _ausruesten(id: String) -> void:
|
||||
if Game.party.is_empty():
|
||||
return
|
||||
if Game.ausruesten(Game.party[_index], id):
|
||||
_meldung = "%s ausgerüstet." % _item_name(id)
|
||||
_sel_id = ""
|
||||
_sel_quelle = ""
|
||||
else:
|
||||
_meldung = "Nicht erlaubt oder nicht im Rucksack."
|
||||
_bauen()
|
||||
|
||||
|
||||
func _ablegen(slot: String) -> void:
|
||||
if Game.party.is_empty():
|
||||
return
|
||||
var figur: Dictionary = Game.party[_index]
|
||||
var id := ""
|
||||
if slot == "shield":
|
||||
id = "schild"
|
||||
else:
|
||||
id = str(figur.get("equipment", {}).get(slot, ""))
|
||||
if Game.ablegen(figur, slot):
|
||||
_meldung = "%s abgelegt." % _item_name(id)
|
||||
_sel_id = ""
|
||||
_sel_quelle = ""
|
||||
else:
|
||||
_meldung = "Slot ist leer."
|
||||
_bauen()
|
||||
|
||||
|
||||
func _benutzen(id: String) -> void:
|
||||
if Game.party.is_empty():
|
||||
return
|
||||
_meldung = Game.benutzen(Game.party[_index], id)
|
||||
if Game.inventar_hat(Game.party[_index], id) <= 0:
|
||||
_sel_id = ""
|
||||
_sel_quelle = ""
|
||||
_bauen()
|
||||
|
||||
|
||||
func _schliessen_knopf(p: Panel) -> void:
|
||||
|
|
@ -200,23 +351,41 @@ func _schliessen_knopf(p: Panel) -> void:
|
|||
p.add_child(b)
|
||||
|
||||
|
||||
func _waehlen(index: int) -> void:
|
||||
_index = index
|
||||
_bauen()
|
||||
# --------------------------------------------------------------- Bausteine --
|
||||
|
||||
func _label(eltern: Node, text: String, pos: Vector2,
|
||||
groesse: Vector2 = Vector2(300, 40), farbe: Color = UiTheme.CREAM) -> Label:
|
||||
var l := Label.new()
|
||||
l.text = text
|
||||
l.position = pos
|
||||
l.size = groesse
|
||||
l.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
l.clip_text = true
|
||||
l.add_theme_color_override("font_color", farbe)
|
||||
eltern.add_child(l)
|
||||
return l
|
||||
|
||||
|
||||
func _ausruesten(id: String) -> void:
|
||||
if Game.party.is_empty():
|
||||
func _icon(eltern: Node, id: String, pos: Vector2) -> void:
|
||||
var t := _item_textur(id)
|
||||
if t == null:
|
||||
return
|
||||
Game.ausruesten(Game.party[_index], id)
|
||||
_bauen()
|
||||
var icon := TextureRect.new()
|
||||
icon.texture = t
|
||||
icon.position = pos
|
||||
icon.size = Vector2(64, 64)
|
||||
icon.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
|
||||
icon.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
|
||||
icon.texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST
|
||||
icon.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
eltern.add_child(icon)
|
||||
|
||||
|
||||
func _ablegen(slot: String) -> void:
|
||||
if Game.party.is_empty():
|
||||
return
|
||||
Game.ablegen(Game.party[_index], slot)
|
||||
_bauen()
|
||||
func _item_textur(id: String) -> Texture2D:
|
||||
var pfad := "res://assets/objects/item_%s_64.png" % id
|
||||
if not ResourceLoader.exists(pfad):
|
||||
return null
|
||||
return load(pfad)
|
||||
|
||||
|
||||
func _item_name(id: String) -> String:
|
||||
|
|
@ -226,9 +395,8 @@ func _item_name(id: String) -> String:
|
|||
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 _item_typ(id: String) -> String:
|
||||
return str(Content.entry("items", id).get("type", ""))
|
||||
|
||||
|
||||
func _leeren(node: Node) -> void:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue