game: Inventar — Tausch, Traglast, Seiten, Laterne, Tränke, Drag & Drop
This commit is contained in:
parent
a78de0ffec
commit
01c312d918
30 changed files with 539 additions and 58 deletions
16
game/scenes/ui/drop_reiter.gd
Normal file
16
game/scenes/ui/drop_reiter.gd
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
class_name DropReiter
|
||||
extends Button
|
||||
## Partei-Reiter als Tauschziel: ein gezogener Gegenstand wechselt die Figur.
|
||||
|
||||
signal figur_bekommen(index: int, id: String)
|
||||
|
||||
var index := 0
|
||||
|
||||
|
||||
func _can_drop_data(_at: Vector2, data: Variant) -> bool:
|
||||
return typeof(data) == TYPE_DICTIONARY and data.get("art") == "inventar" \
|
||||
and not str(data.get("id", "")).is_empty()
|
||||
|
||||
|
||||
func _drop_data(_at: Vector2, data: Variant) -> void:
|
||||
figur_bekommen.emit(index, str(data.get("id", "")))
|
||||
1
game/scenes/ui/drop_reiter.gd.uid
Normal file
1
game/scenes/ui/drop_reiter.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://6tsl7jsq81yf
|
||||
21
game/scenes/ui/drop_slot.gd
Normal file
21
game/scenes/ui/drop_slot.gd
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
class_name DropSlot
|
||||
extends Panel
|
||||
## Ausgerüsteter Slot als Ziel: nur der passende Gegenstandstyp wird genommen.
|
||||
|
||||
signal slot_bekommen(slot: String, id: String)
|
||||
|
||||
var slot := "" ## "weapon", "armor" oder "shield"
|
||||
|
||||
|
||||
func _can_drop_data(_at: Vector2, data: Variant) -> bool:
|
||||
if typeof(data) != TYPE_DICTIONARY or data.get("art") != "inventar":
|
||||
return false
|
||||
var id := str(data.get("id", ""))
|
||||
var typ := str(Content.entry("items", id).get("type", ""))
|
||||
if slot == "shield":
|
||||
return typ == "shield"
|
||||
return typ == slot
|
||||
|
||||
|
||||
func _drop_data(_at: Vector2, data: Variant) -> void:
|
||||
slot_bekommen.emit(slot, str(data.get("id", "")))
|
||||
1
game/scenes/ui/drop_slot.gd.uid
Normal file
1
game/scenes/ui/drop_slot.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://c1rgq40opn47a
|
||||
|
|
@ -25,6 +25,8 @@ var _wurzel: Control
|
|||
var _sel_id := ""
|
||||
var _sel_quelle := "" ## "inventar" oder "slot"
|
||||
var _meldung := ""
|
||||
var _seite := 0
|
||||
var _geben_ebene: Control
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
|
|
@ -38,6 +40,7 @@ func _ready() -> void:
|
|||
|
||||
func _bauen() -> void:
|
||||
_leeren(_wurzel)
|
||||
_geben_ebene = null
|
||||
|
||||
var dimm := UiTheme.dimmung()
|
||||
dimm.color = Color(0.04, 0.03, 0.02, 0.72)
|
||||
|
|
@ -67,6 +70,8 @@ func _bauen() -> void:
|
|||
Game.rk(figur), Game.angriffsbonus(figur),
|
||||
int(figur["hp"]["current"]), int(figur["hp"]["max"])],
|
||||
Vector2(40, 680), Vector2(700, 40))
|
||||
_label(p, "Last %d / %d" % [Game.gewicht(figur), Game.kapazitaet(figur)],
|
||||
Vector2(40, 640), Vector2(400, 36), UiTheme.CREAM_D)
|
||||
_schliessen_knopf(p)
|
||||
|
||||
|
||||
|
|
@ -92,14 +97,16 @@ func _gold(p: Panel) -> void:
|
|||
func _reiter(p: Panel) -> void:
|
||||
var x := 40
|
||||
for i in Game.party.size():
|
||||
var b := Button.new()
|
||||
var b := DropReiter.new()
|
||||
b.text = str(Game.party[i].get("name", "?"))
|
||||
b.index = i
|
||||
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_figur.bind(i))
|
||||
b.figur_bekommen.connect(_geben_drop)
|
||||
p.add_child(b)
|
||||
x += 180
|
||||
|
||||
|
|
@ -121,8 +128,19 @@ func _ausgeruestet(p: Panel, figur: Dictionary) -> void:
|
|||
else:
|
||||
id = str(equipment.get(slot["key"], ""))
|
||||
|
||||
var ziel := DropSlot.new()
|
||||
ziel.slot = str(slot["key"])
|
||||
ziel.position = Vector2(40, y)
|
||||
ziel.size = Vector2(64, 64)
|
||||
var rahmen := StyleBoxFlat.new()
|
||||
rahmen.bg_color = Color(0, 0, 0, 0)
|
||||
rahmen.border_color = Color(UiTheme.LINE, 0.7)
|
||||
rahmen.set_border_width_all(2)
|
||||
ziel.add_theme_stylebox_override("panel", rahmen)
|
||||
ziel.slot_bekommen.connect(_auf_slot)
|
||||
p.add_child(ziel)
|
||||
if not id.is_empty():
|
||||
_icon(p, id, Vector2(40, y))
|
||||
_icon(ziel, id, Vector2.ZERO)
|
||||
_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 "—",
|
||||
|
|
@ -142,15 +160,39 @@ func _ausgeruestet(p: Panel, figur: Dictionary) -> void:
|
|||
# ---------------------------------------------------------------- Rucksack --
|
||||
|
||||
func _rucksack(p: Panel, figur: Dictionary) -> void:
|
||||
_label(p, "RUCKSACK", RASTER + Vector2(0, -40),
|
||||
Vector2(300, 40), UiTheme.GOLD)
|
||||
|
||||
var inventar: Array = figur.get("inventory", [])
|
||||
var seiten := maxi(1, ceili(float(inventar.size()) / float(SPALTEN * ZEILEN)))
|
||||
_seite = clampi(_seite, 0, seiten - 1)
|
||||
|
||||
_label(p, "RUCKSACK %d/%d" % [_seite + 1, seiten],
|
||||
RASTER + Vector2(0, -40), Vector2(340, 40), UiTheme.GOLD)
|
||||
|
||||
if seiten > 1:
|
||||
var zurueck := Button.new()
|
||||
zurueck.text = "<"
|
||||
zurueck.position = Vector2(980, 144)
|
||||
zurueck.size = Vector2(72, 56)
|
||||
zurueck.focus_mode = Control.FOCUS_NONE
|
||||
zurueck.clip_text = true
|
||||
zurueck.disabled = _seite == 0
|
||||
zurueck.pressed.connect(_seite_wechseln.bind(-1))
|
||||
p.add_child(zurueck)
|
||||
var vor := Button.new()
|
||||
vor.text = ">"
|
||||
vor.position = Vector2(1060, 144)
|
||||
vor.size = Vector2(72, 56)
|
||||
vor.focus_mode = Control.FOCUS_NONE
|
||||
vor.clip_text = true
|
||||
vor.disabled = _seite >= seiten - 1
|
||||
vor.pressed.connect(_seite_wechseln.bind(1))
|
||||
p.add_child(vor)
|
||||
|
||||
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 index := _seite * SPALTEN * ZEILEN + i
|
||||
if index < inventar.size():
|
||||
var eintrag = inventar[index]
|
||||
var id := ""
|
||||
var anzahl := 1
|
||||
if typeof(eintrag) == TYPE_DICTIONARY:
|
||||
|
|
@ -164,7 +206,8 @@ func _rucksack(p: Panel, figur: Dictionary) -> void:
|
|||
|
||||
|
||||
func _slot_knopf(p: Panel, id: String, anzahl: int, pos: Vector2) -> void:
|
||||
var b := Button.new()
|
||||
var b := ItemSlot.new()
|
||||
b.item_id = id
|
||||
b.position = pos
|
||||
b.size = Vector2(KACHEL, KACHEL)
|
||||
b.focus_mode = Control.FOCUS_NONE
|
||||
|
|
@ -228,7 +271,7 @@ func _slot_style(b: Button, gewaehlt: bool) -> void:
|
|||
func _details(p: Panel, figur: Dictionary) -> void:
|
||||
var box := Panel.new()
|
||||
box.position = Vector2(640, 510)
|
||||
box.size = Vector2(720, 150)
|
||||
box.size = Vector2(720, 160)
|
||||
box.add_theme_stylebox_override("panel", THEME.flaeche(Color(1, 1, 1)))
|
||||
p.add_child(box)
|
||||
|
||||
|
|
@ -267,8 +310,17 @@ func _details(p: Panel, figur: Dictionary) -> void:
|
|||
else:
|
||||
_aktions_knopf(box, "Benutzen", _benutzen.bind(_sel_id))
|
||||
|
||||
var geben := Button.new()
|
||||
geben.text = "Geben an"
|
||||
geben.position = Vector2(450, 96)
|
||||
geben.size = Vector2(250, 52)
|
||||
geben.focus_mode = Control.FOCUS_NONE
|
||||
geben.clip_text = true
|
||||
geben.pressed.connect(_geben_panel)
|
||||
box.add_child(geben)
|
||||
|
||||
if not _meldung.is_empty():
|
||||
_label(box, _meldung, Vector2(20, 104), Vector2(660, 36),
|
||||
_label(box, _meldung, Vector2(20, 110), Vector2(420, 36),
|
||||
Color(0.88, 0.78, 0.55))
|
||||
|
||||
|
||||
|
|
@ -287,6 +339,7 @@ func _aktions_knopf(box: Panel, text: String, cb: Callable) -> void:
|
|||
|
||||
func _waehlen_figur(index: int) -> void:
|
||||
_index = index
|
||||
_seite = 0
|
||||
_sel_id = ""
|
||||
_sel_quelle = ""
|
||||
_meldung = ""
|
||||
|
|
@ -340,6 +393,109 @@ func _benutzen(id: String) -> void:
|
|||
_bauen()
|
||||
|
||||
|
||||
func _seite_wechseln(delta: int) -> void:
|
||||
_seite += delta
|
||||
_bauen()
|
||||
|
||||
|
||||
func _geben_drop(index: int, id: String) -> void:
|
||||
_sel_id = id
|
||||
_sel_quelle = "inventar"
|
||||
_geben_an(index)
|
||||
|
||||
|
||||
func _geben_panel() -> void:
|
||||
if _sel_id.is_empty() or _geben_ebene != null:
|
||||
return
|
||||
_geben_ebene = Control.new()
|
||||
_geben_ebene.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
_wurzel.add_child(_geben_ebene)
|
||||
|
||||
var dimm := UiTheme.dimmung()
|
||||
dimm.color = Color(0.03, 0.02, 0.01, 0.78)
|
||||
_geben_ebene.add_child(dimm)
|
||||
|
||||
var p := Panel.new()
|
||||
p.position = Vector2(610, 340)
|
||||
p.size = Vector2(700, 400)
|
||||
p.add_theme_stylebox_override("panel", THEME.flaeche(Color(1, 1, 1)))
|
||||
_geben_ebene.add_child(p)
|
||||
|
||||
var kopf := Label.new()
|
||||
kopf.text = "GEBEN AN"
|
||||
kopf.position = Vector2(30, 24)
|
||||
kopf.add_theme_color_override("font_color", UiTheme.GOLD)
|
||||
p.add_child(kopf)
|
||||
|
||||
var gegen := Label.new()
|
||||
gegen.text = _item_name(_sel_id)
|
||||
gegen.position = Vector2(30, 64)
|
||||
gegen.size = Vector2(620, 40)
|
||||
gegen.clip_text = true
|
||||
p.add_child(gegen)
|
||||
|
||||
for i in Game.party.size():
|
||||
var b := Button.new()
|
||||
var ziel: Dictionary = Game.party[i]
|
||||
b.text = str(ziel.get("name", "?"))
|
||||
b.position = Vector2(30 + (i % 2) * 320, 120 + (i / 2) * 72)
|
||||
b.size = Vector2(300, 56)
|
||||
b.focus_mode = Control.FOCUS_NONE
|
||||
b.clip_text = true
|
||||
b.disabled = i == _index
|
||||
b.tooltip_text = "Last %d / %d" % [
|
||||
Game.gewicht(ziel), Game.kapazitaet(ziel)]
|
||||
b.pressed.connect(_geben_an.bind(i))
|
||||
p.add_child(b)
|
||||
|
||||
var ab := Button.new()
|
||||
ab.text = "Abbrechen"
|
||||
ab.position = Vector2(230, 320)
|
||||
ab.size = Vector2(240, 56)
|
||||
ab.focus_mode = Control.FOCUS_NONE
|
||||
ab.clip_text = true
|
||||
ab.pressed.connect(_geben_schliessen)
|
||||
p.add_child(ab)
|
||||
|
||||
|
||||
func _geben_an(index: int) -> void:
|
||||
if index == _index or _sel_id.is_empty() or Game.party.is_empty():
|
||||
return
|
||||
_meldung = Game.geben(Game.party[_index], 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()
|
||||
_geben_ebene = null
|
||||
|
||||
|
||||
func _auf_slot(slot: String, id: String) -> void:
|
||||
if Game.party.is_empty():
|
||||
return
|
||||
var typ := _item_typ(id)
|
||||
var passt: bool
|
||||
if slot == "shield":
|
||||
passt = typ == "shield"
|
||||
else:
|
||||
passt = typ == slot
|
||||
if not passt:
|
||||
_meldung = "Passt nicht in den Slot."
|
||||
else:
|
||||
var figur: Dictionary = Game.party[_index]
|
||||
if Game.ausruesten(figur, id):
|
||||
_meldung = "%s ausgerüstet." % _item_name(id)
|
||||
_sel_id = ""
|
||||
_sel_quelle = ""
|
||||
else:
|
||||
_meldung = "Diese Klasse darf das nicht tragen."
|
||||
_bauen()
|
||||
|
||||
|
||||
func _schliessen_knopf(p: Panel) -> void:
|
||||
var b := Button.new()
|
||||
b.text = "Schließen"
|
||||
|
|
|
|||
20
game/scenes/ui/item_slot.gd
Normal file
20
game/scenes/ui/item_slot.gd
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
class_name ItemSlot
|
||||
extends Button
|
||||
## Rucksack-Slot: klickbar (Auswahl) und ziehbar (Tausch/Ausrüsten).
|
||||
|
||||
var item_id := ""
|
||||
|
||||
|
||||
func _get_drag_data(_at: Vector2) -> Variant:
|
||||
if item_id.is_empty():
|
||||
return null
|
||||
var pfad := "res://assets/objects/item_%s_64.png" % item_id
|
||||
if ResourceLoader.exists(pfad):
|
||||
var bild := TextureRect.new()
|
||||
bild.texture = load(pfad)
|
||||
bild.size = Vector2(64, 64)
|
||||
bild.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
|
||||
bild.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
|
||||
bild.texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST
|
||||
set_drag_preview(bild)
|
||||
return {"art": "inventar", "id": item_id}
|
||||
1
game/scenes/ui/item_slot.gd.uid
Normal file
1
game/scenes/ui/item_slot.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://1bb8fk8pafj8
|
||||
Loading…
Add table
Add a link
Reference in a new issue