update
This commit is contained in:
113
scripts/ui/ShopPanel.gd
Normal file
113
scripts/ui/ShopPanel.gd
Normal file
@@ -0,0 +1,113 @@
|
||||
class_name ShopPanel
|
||||
extends Control
|
||||
|
||||
## Unten: Shop, Würfeln, Einfrieren, Futter und Hinweise.
|
||||
|
||||
signal buy_requested(index: int, quick: bool)
|
||||
signal reroll_pressed
|
||||
signal lock_pressed
|
||||
|
||||
const PANEL_BG := Color(0.14, 0.15, 0.19)
|
||||
const SLOT_BG := Color(0.20, 0.21, 0.26)
|
||||
|
||||
var row: HBoxContainer
|
||||
var btn_reroll: Button
|
||||
var btn_lock: Button
|
||||
var lbl_fodder: Label
|
||||
var lbl_hint: Label
|
||||
|
||||
|
||||
func build(x: float, y: float, w: float, h: float) -> void:
|
||||
position = Vector2(x, y)
|
||||
size = Vector2(w, h)
|
||||
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
var p := UiKit.panel(PANEL_BG)
|
||||
p.size = size
|
||||
add_child(p)
|
||||
var v := VBoxContainer.new()
|
||||
v.add_theme_constant_override("separation", 6)
|
||||
p.add_child(v)
|
||||
|
||||
var head := HBoxContainer.new()
|
||||
head.add_theme_constant_override("separation", 14)
|
||||
v.add_child(head)
|
||||
head.add_child(UiKit.label("Shop", 13, Color(0.7, 0.72, 0.8)))
|
||||
btn_reroll = UiKit.button("Neu würfeln %d Gold [D]" % Data.REROLL_COST, Color(0.30, 0.32, 0.44))
|
||||
btn_reroll.custom_minimum_size = Vector2(200, 26)
|
||||
btn_reroll.pressed.connect(func(): reroll_pressed.emit())
|
||||
head.add_child(btn_reroll)
|
||||
btn_lock = UiKit.button("Einfrieren [F]", Color(0.30, 0.38, 0.50))
|
||||
btn_lock.custom_minimum_size = Vector2(150, 26)
|
||||
btn_lock.pressed.connect(func(): lock_pressed.emit())
|
||||
head.add_child(btn_lock)
|
||||
lbl_fodder = UiKit.label("", 13, Color(0.7, 0.72, 0.8))
|
||||
head.add_child(lbl_fodder)
|
||||
lbl_hint = UiKit.label("", 13, Color(0.95, 0.85, 0.45))
|
||||
head.add_child(lbl_hint)
|
||||
var spacer := Control.new()
|
||||
spacer.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
head.add_child(spacer)
|
||||
head.add_child(UiKit.label(
|
||||
"Ziehen: Bank ↔ Feld · Rechtsklick: verkaufen / zurück · Rechtsklick auf Neutral: wie zuletzt",
|
||||
13, Color(0.6, 0.62, 0.7)))
|
||||
|
||||
row = HBoxContainer.new()
|
||||
row.add_theme_constant_override("separation", 8)
|
||||
v.add_child(row)
|
||||
|
||||
|
||||
func refresh(game: Game) -> void:
|
||||
var p := game.human
|
||||
for c in row.get_children():
|
||||
row.remove_child(c)
|
||||
c.queue_free()
|
||||
for i in p.shop.size():
|
||||
var e: ShopEntry = p.shop[i]
|
||||
var b: Button
|
||||
if e.sold:
|
||||
b = UiKit.button("verkauft", SLOT_BG.darkened(0.3))
|
||||
b.disabled = true
|
||||
else:
|
||||
var col := e.color()
|
||||
var note: String
|
||||
if e.element < 0:
|
||||
note = "Element wählen"
|
||||
if p.last_element >= 0:
|
||||
note += "\nRechtsklick: %s" % Data.ELEMENT_NAMES[p.last_element]
|
||||
else:
|
||||
note = "noch %d im Vorrat" % game.pool.element_left[e.element]
|
||||
b = UiKit.button("%s\n%d Gold\n%s" % [e.label(), e.price(), note], col, UiKit.ink(col))
|
||||
b.disabled = p.gold < e.price() or game.phase != Game.Phase.PLANNING
|
||||
b.gui_input.connect(_on_card_input.bind(i))
|
||||
b.custom_minimum_size = Vector2(196, 88)
|
||||
row.add_child(b)
|
||||
var mine := []
|
||||
for el in p.shop_elements(game.pool):
|
||||
mine.append("%s %d" % [Data.ELEMENT_NAMES[el], game.pool.element_left[el]])
|
||||
row.add_child(UiKit.label(" Dein Shop zeigt Neutral\n und deine Elemente:\n %s"
|
||||
% [", ".join(mine) if mine else "noch keine aufgestellt"], 12, Color(0.7, 0.72, 0.8)))
|
||||
|
||||
var fodder := p.fodder_counts()
|
||||
var parts := []
|
||||
for e in fodder:
|
||||
parts.append("%dx %s" % [fodder[e], Data.ELEMENT_NAMES[e]])
|
||||
lbl_fodder.text = "Futter: " + (", ".join(parts) if parts else "-")
|
||||
btn_lock.text = "Eingefroren [F]" if p.shop_locked else "Einfrieren [F]"
|
||||
btn_lock.add_theme_stylebox_override("normal",
|
||||
UiKit.flat(Color(0.35, 0.55, 0.75) if p.shop_locked else Color(0.30, 0.38, 0.50)))
|
||||
btn_reroll.disabled = game.phase != Game.Phase.PLANNING or p.gold < Data.REROLL_COST
|
||||
|
||||
|
||||
func _on_card_input(event: InputEvent, index: int) -> void:
|
||||
if event is InputEventMouseButton and event.pressed:
|
||||
if event.button_index == MOUSE_BUTTON_LEFT:
|
||||
buy_requested.emit(index, false)
|
||||
elif event.button_index == MOUSE_BUTTON_RIGHT:
|
||||
buy_requested.emit(index, true)
|
||||
|
||||
|
||||
func hint(text: String) -> void:
|
||||
lbl_hint.text = text
|
||||
get_tree().create_timer(2.5).timeout.connect(func():
|
||||
if is_instance_valid(lbl_hint) and lbl_hint.text == text:
|
||||
lbl_hint.text = "")
|
||||
Reference in New Issue
Block a user