77 lines
2.6 KiB
GDScript
77 lines
2.6 KiB
GDScript
class_name PlayersPanel
|
|
extends Control
|
|
|
|
## Rechte Spalte: die acht Spieler mit Leben, Serie und Klick zum Ansehen.
|
|
|
|
signal scout_requested(p: PlayerState)
|
|
|
|
const PANEL_BG := Color(0.14, 0.15, 0.19)
|
|
|
|
var box: VBoxContainer
|
|
var _w := 0.0
|
|
|
|
|
|
func build(x: float, y: float, w: float, h: float) -> void:
|
|
_w = w
|
|
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)
|
|
box = VBoxContainer.new()
|
|
box.add_theme_constant_override("separation", 4)
|
|
p.add_child(box)
|
|
box.add_child(UiKit.label("Spieler · Klick = ansehen", 15, Color(0.75, 0.8, 0.95)))
|
|
|
|
|
|
func refresh(game: Game, scout: PlayerState) -> void:
|
|
var kids := box.get_children()
|
|
for i in range(1, kids.size()):
|
|
box.remove_child(kids[i])
|
|
kids[i].queue_free()
|
|
var next_opp := game.human_opponent()
|
|
for p in game.ranking():
|
|
var row := VBoxContainer.new()
|
|
row.add_theme_constant_override("separation", 1)
|
|
var top := HBoxContainer.new()
|
|
var col := Color(0.9, 0.9, 0.95) if p.alive else Color(0.5, 0.5, 0.55)
|
|
if p == game.human:
|
|
col = Color(0.6, 0.9, 1.0)
|
|
elif p == next_opp:
|
|
col = Color(1.0, 0.75, 0.6)
|
|
var nm := UiKit.button(p.pname, PANEL_BG if p != scout else Color(0.30, 0.34, 0.48), col)
|
|
nm.custom_minimum_size = Vector2(96, 22)
|
|
nm.alignment = HORIZONTAL_ALIGNMENT_LEFT
|
|
nm.disabled = not p.alive
|
|
nm.pressed.connect(func(): scout_requested.emit(p))
|
|
top.add_child(nm)
|
|
top.add_child(UiKit.label("%d" % p.hp, 14, col))
|
|
if p.streak != 0:
|
|
top.add_child(UiKit.label(" %s%d" % ["+" if p.streak > 0 else "", p.streak], 12,
|
|
Color(0.85, 0.7, 1.0)))
|
|
row.add_child(top)
|
|
var bar := ColorRect.new()
|
|
bar.color = Color(0.12, 0.13, 0.16)
|
|
bar.custom_minimum_size = Vector2(_w - 16, 6)
|
|
var fill := ColorRect.new()
|
|
fill.color = Color(0.35, 0.8, 0.45) if p.alive else Color(0.4, 0.4, 0.45)
|
|
fill.size = Vector2((_w - 16) * (float(p.hp) / float(Data.START_HP)), 6)
|
|
bar.add_child(fill)
|
|
row.add_child(bar)
|
|
box.add_child(row)
|
|
if next_opp != null and game.phase == Game.Phase.PLANNING:
|
|
box.add_child(_note("\nNächster Gegner: %s\nLevel %d, %d Einheiten" %
|
|
[next_opp.pname, next_opp.level, next_opp.board.size()], Color(1.0, 0.75, 0.6)))
|
|
elif next_opp != null:
|
|
box.add_child(_note("\nGegner: " + next_opp.pname, Color(1.0, 0.6, 0.6)))
|
|
if scout != null:
|
|
box.add_child(_note("Oben: Brett von %s" % scout.pname, Color(0.75, 0.85, 1.0)))
|
|
|
|
|
|
func _note(text: String, col: Color) -> Label:
|
|
var l := UiKit.label(text, 13, col)
|
|
l.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
|
l.custom_minimum_size = Vector2(_w - 20, 0)
|
|
return l
|