game: Traglast-Malus, Truhen, Bodenablage und weitere Tränke
This commit is contained in:
parent
01c312d918
commit
3e533e5089
23 changed files with 557 additions and 28 deletions
|
|
@ -311,7 +311,7 @@ func _details(p: Panel, figur: Dictionary) -> void:
|
|||
_aktions_knopf(box, "Benutzen", _benutzen.bind(_sel_id))
|
||||
|
||||
var geben := Button.new()
|
||||
geben.text = "Geben an"
|
||||
geben.text = "Tausch"
|
||||
geben.position = Vector2(450, 96)
|
||||
geben.size = Vector2(250, 52)
|
||||
geben.focus_mode = Control.FOCUS_NONE
|
||||
|
|
@ -422,7 +422,7 @@ func _geben_panel() -> void:
|
|||
_geben_ebene.add_child(p)
|
||||
|
||||
var kopf := Label.new()
|
||||
kopf.text = "GEBEN AN"
|
||||
kopf.text = "TAUSCH"
|
||||
kopf.position = Vector2(30, 24)
|
||||
kopf.add_theme_color_override("font_color", UiTheme.GOLD)
|
||||
p.add_child(kopf)
|
||||
|
|
@ -448,9 +448,18 @@ func _geben_panel() -> void:
|
|||
b.pressed.connect(_geben_an.bind(i))
|
||||
p.add_child(b)
|
||||
|
||||
var fallen := Button.new()
|
||||
fallen.text = "Fallen lassen"
|
||||
fallen.position = Vector2(30, 320)
|
||||
fallen.size = Vector2(350, 56)
|
||||
fallen.focus_mode = Control.FOCUS_NONE
|
||||
fallen.clip_text = true
|
||||
fallen.pressed.connect(_fallen_lassen)
|
||||
p.add_child(fallen)
|
||||
|
||||
var ab := Button.new()
|
||||
ab.text = "Abbrechen"
|
||||
ab.position = Vector2(230, 320)
|
||||
ab.position = Vector2(390, 320)
|
||||
ab.size = Vector2(240, 56)
|
||||
ab.focus_mode = Control.FOCUS_NONE
|
||||
ab.clip_text = true
|
||||
|
|
@ -468,6 +477,16 @@ func _geben_an(index: int) -> void:
|
|||
_bauen()
|
||||
|
||||
|
||||
func _fallen_lassen() -> void:
|
||||
if _sel_id.is_empty() or Game.party.is_empty():
|
||||
return
|
||||
_meldung = Game.fallen_lassen(Game.party[_index], _sel_id)
|
||||
if Game.inventar_hat(Game.party[_index], _sel_id) <= 0:
|
||||
_sel_id = ""
|
||||
_sel_quelle = ""
|
||||
_bauen()
|
||||
|
||||
|
||||
func _geben_schliessen() -> void:
|
||||
if _geben_ebene != null:
|
||||
_geben_ebene.queue_free()
|
||||
|
|
|
|||
128
game/scenes/ui/truhe.gd
Normal file
128
game/scenes/ui/truhe.gd
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
extends Control
|
||||
## Truhe als einmaliger Container (map-JSON: `containers`).
|
||||
##
|
||||
## „Alles nehmen" prüft die Traglast des Parteiführers, legt Gold und Beute
|
||||
## ab und setzt das Flag `truhe_<id>`. Ein zweites Öffnen ist leer.
|
||||
|
||||
signal geschlossen
|
||||
|
||||
const THEME := preload("res://scripts/ui/ui_theme.gd")
|
||||
|
||||
var container: Dictionary = {}
|
||||
var karte := "garana"
|
||||
|
||||
var _wurzel: Control
|
||||
var _meldung := ""
|
||||
|
||||
|
||||
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(560, 260)
|
||||
p.size = Vector2(800, 560)
|
||||
p.add_theme_stylebox_override("panel", THEME.flaeche(Color(1, 1, 1)))
|
||||
_wurzel.add_child(p)
|
||||
|
||||
var titel := Label.new()
|
||||
titel.text = "TRUHE"
|
||||
titel.position = Vector2(40, 24)
|
||||
titel.add_theme_color_override("font_color", UiTheme.GOLD)
|
||||
p.add_child(titel)
|
||||
|
||||
var id := str(container.get("id", ""))
|
||||
if bool(Game.flags.get(id, false)):
|
||||
_label(p, "Leer.", Vector2(40, 120), UiTheme.CREAM_D)
|
||||
_schliessen_knopf(p)
|
||||
return
|
||||
|
||||
var gold := int(container.get("gold", 0))
|
||||
if gold > 0:
|
||||
_label(p, "Gold: %d" % gold, Vector2(40, 84), UiTheme.GOLD)
|
||||
|
||||
var loot: Array = container.get("loot", [])
|
||||
for i in loot.size():
|
||||
var eintrag: Dictionary = loot[i]
|
||||
var item_id := str(eintrag.get("id", ""))
|
||||
var y := 140 + i * 82
|
||||
var pfad := "res://assets/objects/item_%s_64.png" % item_id
|
||||
if ResourceLoader.exists(pfad):
|
||||
var icon := TextureRect.new()
|
||||
icon.texture = load(pfad)
|
||||
icon.position = Vector2(40, y)
|
||||
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
|
||||
p.add_child(icon)
|
||||
_label(p, _item_name(item_id), Vector2(120, y + 12), UiTheme.CREAM)
|
||||
var anzahl := int(eintrag.get("count", 1))
|
||||
if anzahl > 1:
|
||||
_label(p, "x%d" % anzahl, Vector2(660, y + 12), UiTheme.CREAM_D)
|
||||
|
||||
if loot.is_empty() and gold == 0:
|
||||
_label(p, "Leer.", Vector2(40, 120), UiTheme.CREAM_D)
|
||||
|
||||
var nehmen := Button.new()
|
||||
nehmen.text = "Alles nehmen"
|
||||
nehmen.position = Vector2(40, 460)
|
||||
nehmen.size = Vector2(320, 56)
|
||||
nehmen.focus_mode = Control.FOCUS_NONE
|
||||
nehmen.clip_text = true
|
||||
nehmen.pressed.connect(_nehmen)
|
||||
p.add_child(nehmen)
|
||||
|
||||
_schliessen_knopf(p)
|
||||
|
||||
if not _meldung.is_empty():
|
||||
_label(p, _meldung, Vector2(40, 400), Color(0.9, 0.72, 0.45))
|
||||
|
||||
|
||||
func _nehmen() -> void:
|
||||
_meldung = Game.truhe_nehmen(container)
|
||||
_bauen()
|
||||
|
||||
|
||||
func _schliessen_knopf(p: Panel) -> void:
|
||||
var b := Button.new()
|
||||
b.text = "Schließen"
|
||||
b.position = Vector2(400, 460)
|
||||
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 _label(p: Panel, text: String, pos: Vector2, farbe: Color) -> Label:
|
||||
var l := Label.new()
|
||||
l.text = text
|
||||
l.position = pos
|
||||
l.size = Vector2(700, 40)
|
||||
l.clip_text = true
|
||||
l.add_theme_color_override("font_color", farbe)
|
||||
p.add_child(l)
|
||||
return l
|
||||
|
||||
|
||||
func _item_name(id: String) -> String:
|
||||
return str(Content.entry("items", id).get("name", id))
|
||||
|
||||
|
||||
func _leeren(node: Node) -> void:
|
||||
for kind in node.get_children():
|
||||
node.remove_child(kind)
|
||||
kind.queue_free()
|
||||
1
game/scenes/ui/truhe.gd.uid
Normal file
1
game/scenes/ui/truhe.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://beimjkn6igm0r
|
||||
12
game/scenes/ui/truhe.tscn
Normal file
12
game/scenes/ui/truhe.tscn
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/ui/truhe.gd" id="1"]
|
||||
|
||||
[node name="Truhe" 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")
|
||||
|
|
@ -33,6 +33,7 @@ const UEBERGAENGE := {"battle_erde": "erde_nach_gras"}
|
|||
|
||||
## Startfeld der Figur (muss begehbar sein).
|
||||
const START := Vector2i(10, 8)
|
||||
const KARTE_ID := "garana"
|
||||
|
||||
var _karte: Dictionary
|
||||
signal zurueck
|
||||
|
|
@ -56,7 +57,13 @@ var _texturen: Dictionary = {}
|
|||
var _kanten_cache: Dictionary = {}
|
||||
var _welt: Node2D
|
||||
var _leute: Node2D
|
||||
var _boden_items: Node2D
|
||||
var _licht: PointLight2D
|
||||
var _last_label: Label
|
||||
var _fund_label: Label
|
||||
var _truhe: Control
|
||||
var _truhe_ebene: CanvasLayer
|
||||
var _naechster_schritt := 0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
|
|
@ -88,6 +95,10 @@ func _ready() -> void:
|
|||
Game.flags["licht"] = true
|
||||
if arg == "--schnellstart":
|
||||
Game.party_schnellstart()
|
||||
if OS.get_cmdline_user_args().has("--ueberladen"):
|
||||
Game.party_schnellstart()
|
||||
for i in 10:
|
||||
Game.inventar_hinzufuegen(Game.party[0], "platte")
|
||||
if gemalt:
|
||||
_platte = true
|
||||
_figuren_gemalt = gemalt or gedaempft
|
||||
|
|
@ -114,6 +125,12 @@ func _ready() -> void:
|
|||
_ui()
|
||||
_dialog_bauen()
|
||||
_nachbearbeitung()
|
||||
_boden_zeichnen()
|
||||
_last_aktualisieren()
|
||||
if OS.get_cmdline_user_args().has("--truhe"):
|
||||
var truhen: Array = _karte.get("containers", [])
|
||||
if not truhen.is_empty():
|
||||
call_deferred("_truhe_oeffnen", truhen[0])
|
||||
|
||||
|
||||
## Gemaltes Vollbild statt Karte — nur für den Stilvergleich.
|
||||
|
|
@ -361,6 +378,10 @@ func _leute_zeichnen() -> void:
|
|||
_leute = Node2D.new()
|
||||
_leute.name = "Leute"
|
||||
_welt.add_child(_leute)
|
||||
_boden_items = Node2D.new()
|
||||
_boden_items.name = "Boden"
|
||||
_boden_items.z_index = -1
|
||||
_leute.add_child(_boden_items)
|
||||
for eintrag in _karte.get("npcs", []):
|
||||
var nsc: Dictionary = Content.entry("npcs", eintrag["id"])
|
||||
if nsc.is_empty():
|
||||
|
|
@ -386,6 +407,12 @@ func _leute_zeichnen() -> void:
|
|||
|
||||
# ---------------------------------------------------------------- Spieler ----
|
||||
func _spieler_zeichnen() -> void:
|
||||
if str(Game.place.get("id", "")) == KARTE_ID:
|
||||
var gespeichert := Vector2i(int(Game.place.get("x", START.x)),
|
||||
int(Game.place.get("y", START.y)))
|
||||
if _begehbar(gespeichert.x, gespeichert.y):
|
||||
_spieler_kachel = gespeichert
|
||||
Game.place = {"id": KARTE_ID, "x": _spieler_kachel.x, "y": _spieler_kachel.y}
|
||||
_spieler = Sprite2D.new()
|
||||
_spieler.name = "Spieler"
|
||||
_spieler.texture = _textur(_pfad("res://assets/players/", "player_abenteurer_96px"))
|
||||
|
|
@ -494,17 +521,29 @@ func _input(event: InputEvent) -> void:
|
|||
return
|
||||
if richtung == Vector2i.ZERO:
|
||||
return
|
||||
var jetzt := Time.get_ticks_msec()
|
||||
if jetzt < _naechster_schritt:
|
||||
return
|
||||
var malus := 0
|
||||
if not Game.party.is_empty():
|
||||
malus = Game.bewegung_malus(Game.party[0])
|
||||
_naechster_schritt = jetzt + (260 if malus > 0 else 60)
|
||||
var ziel := _spieler_kachel + richtung
|
||||
if not _begehbar(ziel.x, ziel.y):
|
||||
return
|
||||
_blockiert.erase(Vector2i(_spieler_kachel))
|
||||
_spieler_kachel = ziel
|
||||
Game.place = {"id": KARTE_ID, "x": ziel.x, "y": ziel.y}
|
||||
_blockiert[Vector2i(ziel)] = true
|
||||
var fuss := Vector2((ziel.x + 0.5) * KACHEL, (ziel.y + 1) * KACHEL)
|
||||
var ziel_pos := fuss - Vector2(0, _spieler.texture.get_height() * 0.5) \
|
||||
+ Vector2(0, SCHATTEN.fuss_abstand(_spieler.texture))
|
||||
var tween := create_tween()
|
||||
tween.tween_property(_spieler, "position", ziel_pos, 0.10)
|
||||
tween.tween_property(_spieler, "position", ziel_pos,
|
||||
0.22 if malus > 0 else 0.10)
|
||||
_boden_aufnehmen(ziel)
|
||||
_boden_zeichnen()
|
||||
_last_aktualisieren()
|
||||
if _dialog.visible:
|
||||
_dialog.visible = false
|
||||
for ausgang in _karte.get("exits", []):
|
||||
|
|
@ -530,6 +569,79 @@ func _inventar_schliessen() -> void:
|
|||
_inventar = null
|
||||
_inventar_ebene = null
|
||||
_licht_aktualisieren()
|
||||
_boden_zeichnen()
|
||||
|
||||
|
||||
func _last_aktualisieren() -> void:
|
||||
if _last_label == null:
|
||||
return
|
||||
var an := false
|
||||
if not Game.party.is_empty():
|
||||
an = Game.ueberladen(Game.party[0])
|
||||
_last_label.visible = an
|
||||
if an:
|
||||
_last_label.text = "ÜBERLADEN %d/%d" % [
|
||||
Game.gewicht(Game.party[0]), Game.kapazitaet(Game.party[0])]
|
||||
|
||||
|
||||
func _boden_zeichnen() -> void:
|
||||
if _boden_items == null:
|
||||
return
|
||||
for kind in _boden_items.get_children():
|
||||
_boden_items.remove_child(kind)
|
||||
kind.queue_free()
|
||||
for eintrag in Game.boden:
|
||||
if str(eintrag.get("map", "")) != KARTE_ID:
|
||||
continue
|
||||
var id := str(eintrag.get("id", ""))
|
||||
var pfad := "res://assets/objects/item_%s_64.png" % id
|
||||
if not ResourceLoader.exists(pfad):
|
||||
continue
|
||||
var s := Sprite2D.new()
|
||||
s.texture = load(pfad)
|
||||
s.centered = false
|
||||
s.texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST
|
||||
s.position = Vector2(int(eintrag.get("x", 0)) * KACHEL + 16,
|
||||
int(eintrag.get("y", 0)) * KACHEL + 28)
|
||||
_boden_items.add_child(s)
|
||||
|
||||
|
||||
func _boden_aufnehmen(ziel: Vector2i) -> void:
|
||||
if Game.party.is_empty():
|
||||
return
|
||||
var namen := Game.boden_aufnehmen(Game.party[0], KARTE_ID, ziel.x, ziel.y)
|
||||
if not namen.is_empty():
|
||||
_fund("Aufgenommen: " + ", ".join(namen))
|
||||
|
||||
|
||||
func _fund(text: String) -> void:
|
||||
if _fund_label == null:
|
||||
return
|
||||
_fund_label.text = text
|
||||
_fund_label.visible = true
|
||||
await get_tree().create_timer(2.5).timeout
|
||||
if is_instance_valid(_fund_label):
|
||||
_fund_label.visible = false
|
||||
|
||||
|
||||
func _truhe_oeffnen(container: Dictionary) -> void:
|
||||
if _truhe != null:
|
||||
return
|
||||
_truhe_ebene = CanvasLayer.new()
|
||||
_truhe_ebene.layer = 5
|
||||
add_child(_truhe_ebene)
|
||||
_truhe = load("res://scenes/ui/truhe.tscn").instantiate()
|
||||
_truhe.set("container", container)
|
||||
_truhe.set("karte", KARTE_ID)
|
||||
_truhe_ebene.add_child(_truhe)
|
||||
_truhe.geschlossen.connect(_truhe_schliessen)
|
||||
|
||||
|
||||
func _truhe_schliessen() -> void:
|
||||
if _truhe_ebene != null:
|
||||
_truhe_ebene.queue_free()
|
||||
_truhe = null
|
||||
_truhe_ebene = null
|
||||
|
||||
|
||||
## Sprechen mit dem nächsten NSC (ein Feld Abstand, auch diagonal).
|
||||
|
|
@ -537,6 +649,11 @@ func _sprechen() -> void:
|
|||
if _dialog.visible:
|
||||
_dialog.visible = false
|
||||
return
|
||||
for truhe in _karte.get("containers", []):
|
||||
var d := Vector2i(int(truhe["x"]), int(truhe["y"])) - _spieler_kachel
|
||||
if absi(d.x) <= 1 and absi(d.y) <= 1:
|
||||
_truhe_oeffnen(truhe)
|
||||
return
|
||||
for eintrag in _karte.get("npcs", []):
|
||||
var d := Vector2i(int(eintrag["x"]), int(eintrag["y"])) - _spieler_kachel
|
||||
if absi(d.x) <= 1 and absi(d.y) <= 1 and d != Vector2i.ZERO:
|
||||
|
|
@ -611,6 +728,28 @@ func _ui() -> void:
|
|||
inventar_knopf.pressed.connect(_inventar_oeffnen)
|
||||
wurzel.add_child(inventar_knopf)
|
||||
|
||||
_last_label = Label.new()
|
||||
_last_label.text = "ÜBERLADEN"
|
||||
_last_label.position = Vector2(8, 30) * UiTheme.SKALA
|
||||
_last_label.size = Vector2(460, 40)
|
||||
_last_label.clip_text = true
|
||||
_last_label.add_theme_color_override("font_color", Color(0.92, 0.55, 0.42))
|
||||
_last_label.add_theme_color_override("font_outline_color", UiTheme.INK)
|
||||
_last_label.add_theme_constant_override("outline_size", 6)
|
||||
_last_label.visible = false
|
||||
wurzel.add_child(_last_label)
|
||||
|
||||
_fund_label = Label.new()
|
||||
_fund_label.position = Vector2(660, 980)
|
||||
_fund_label.size = Vector2(600, 40)
|
||||
_fund_label.clip_text = true
|
||||
_fund_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
_fund_label.add_theme_color_override("font_color", UiTheme.GOLD)
|
||||
_fund_label.add_theme_color_override("font_outline_color", UiTheme.INK)
|
||||
_fund_label.add_theme_constant_override("outline_size", 6)
|
||||
_fund_label.visible = false
|
||||
wurzel.add_child(_fund_label)
|
||||
|
||||
# Rückwand der Partyspalte: ohne sie steht das HUD auf der Stadtmauer und
|
||||
# wirkt aufgeklebt (Befund aus dem ersten Render).
|
||||
var breite: int = 44 * UiTheme.SKALA
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue