update
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
class_name ElementView
|
||||
extends Control
|
||||
## Elementboni auf einen Blick: offene Wesen je Element auf dem Tisch (ab drei +1/+1) und der
|
||||
## Sondereffekt der eigenen Seite (ab zwei eigenen: Erde Spott, Luft Flink, Wasser Regeneration,
|
||||
## Feuer Doppelschlag), als Symbol in der Elementfarbe.
|
||||
## Elementzähler der eigenen Seite, mittig: je Element zweimal das Symbol seines Sondereffekts in
|
||||
## der Elementfarbe, leuchtend je offenem eigenen Wesen (beide: Effekt aktiv), daneben in der
|
||||
## Elementfarbe das Mana der bisher ausgespielten Karten (je Game.ELEMENT_MANA gibt es +1 Angriff).
|
||||
|
||||
var counts := {} # Tisch
|
||||
var own := {} # eigene Seite
|
||||
const ENTRY_W := 180.0
|
||||
|
||||
var own := {} # offene eigene Wesen je Element
|
||||
var played := {} # ausgespielte Karten je Element
|
||||
|
||||
|
||||
func _init(rect: Rect2) -> void:
|
||||
@@ -13,62 +15,53 @@ func _init(rect: Rect2) -> void:
|
||||
size = rect.size
|
||||
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
for e in Cards.ELEMENTS:
|
||||
counts[e] = 0
|
||||
own[e] = 0
|
||||
played[e] = 0
|
||||
|
||||
|
||||
func update_from(g: Game, me: Game.Player) -> void:
|
||||
counts = g.element_counts()
|
||||
func update_from(_g: Game, me: Game.Player) -> void:
|
||||
for e in Cards.ELEMENTS:
|
||||
own[e] = me.element_count(e) if me != null else 0
|
||||
played[e] = int(me.played.get(e, 0)) if me != null else 0
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func strong(e: String) -> bool:
|
||||
return int(counts.get(e, 0)) >= Game.ELEMENT_STACK
|
||||
|
||||
|
||||
func paired(e: String) -> bool:
|
||||
return int(own.get(e, 0)) >= Game.ELEMENT_PAIR
|
||||
|
||||
|
||||
## Der Inhalt als Text (Tests, Protokoll).
|
||||
func bonus(e: String) -> int:
|
||||
return int(played.get(e, 0)) / Game.ELEMENT_MANA
|
||||
|
||||
|
||||
## Der Inhalt als Text (Tests, Protokoll): Element offen/gespielt, dazu Effekt und Bonus.
|
||||
func text() -> String:
|
||||
var parts: Array[String] = []
|
||||
for e in Cards.ELEMENTS:
|
||||
var s := "%s %d" % [tr(e), int(counts.get(e, 0))]
|
||||
if strong(e):
|
||||
s += " (+1/+1)"
|
||||
var s := "%s %d/%d" % [tr(e), int(own.get(e, 0)), int(played.get(e, 0))]
|
||||
if paired(e):
|
||||
s += " (%s)" % tr(Cards.ELEMENT_KEYWORD[e])
|
||||
if bonus(e) > 0:
|
||||
s += " (+%d)" % bonus(e)
|
||||
parts.append(s)
|
||||
return " · ".join(parts)
|
||||
|
||||
|
||||
func _draw() -> void:
|
||||
var w := size.x / Cards.ELEMENTS.size()
|
||||
var x0 := (size.x - ENTRY_W * Cards.ELEMENTS.size()) / 2
|
||||
var cy := size.y / 2
|
||||
for i in Cards.ELEMENTS.size():
|
||||
var e: String = Cards.ELEMENTS[i]
|
||||
var col: Color = Cards.ELEMENT_COLORS[e]
|
||||
var x0 := i * w
|
||||
var cy := size.y / 2
|
||||
var n := int(counts.get(e, 0))
|
||||
if strong(e):
|
||||
draw_style_box(Style.box(Color(col, 0.35), 6, col, 2), Rect2(x0 + 2, 0, w - 4, size.y))
|
||||
elif paired(e):
|
||||
draw_style_box(Style.box(Color(col, 0.18), 6, Color(col, 0.6), 1), Rect2(x0 + 2, 0, w - 4, size.y))
|
||||
var active := strong(e) or paired(e)
|
||||
Style.text(self, tr(e), 13, Style.TEXT if active else Style.MUTED, Vector2(x0 + 12, cy), "midleft", active)
|
||||
var px := x0 + 12 + Style.FONT_BOLD.get_string_size(tr(e), HORIZONTAL_ALIGNMENT_LEFT, -1, Style.fs(13)).x + 12
|
||||
for k in Game.ELEMENT_STACK:
|
||||
var c := Vector2(px + k * 13, cy)
|
||||
if k < n:
|
||||
draw_circle(c, 4.5, col)
|
||||
else:
|
||||
draw_circle(c, 4.5, Color(0, 0, 0, 0.35))
|
||||
draw_arc(c, 4.5, 0, TAU, 16, Color(col, 0.6), 1.0)
|
||||
px += Game.ELEMENT_STACK * 13 + 2
|
||||
if paired(e):
|
||||
Style.keyword_icon(self, Cards.ELEMENT_KEYWORD[e], Vector2(px + 10, cy), 7, Style.lighter(col, 0.45))
|
||||
if strong(e):
|
||||
Style.text(self, "+1/+1", 13, Style.GREEN, Vector2(x0 + w - 12, cy), "midright", true)
|
||||
var active := paired(e) or bonus(e) > 0
|
||||
var px := x0 + i * ENTRY_W + 10
|
||||
Style.text(self, tr(e), 13, Style.TEXT if active else Style.MUTED, Vector2(px, cy), "midleft", active)
|
||||
px += Style.FONT_BOLD.get_string_size(tr(e), HORIZONTAL_ALIGNMENT_LEFT, -1, Style.fs(13)).x + 10
|
||||
for k in Game.ELEMENT_PAIR:
|
||||
var filled := k < int(own.get(e, 0))
|
||||
Style.keyword_icon(self, Cards.ELEMENT_KEYWORD[e], Vector2(px + k * 24 + 10, cy), 8, Style.lighter(col, 0.45) if filled else Color(col, 0.3))
|
||||
px += Game.ELEMENT_PAIR * 24 + 8
|
||||
Style.text(self, str(int(played.get(e, 0))), 15, Style.lighter(col, 0.45), Vector2(px, cy), "midleft", true)
|
||||
px += 20
|
||||
if bonus(e) > 0:
|
||||
Style.text(self, "+%d" % bonus(e), 12, Style.GREEN, Vector2(px, cy), "midleft", true)
|
||||
|
||||
Reference in New Issue
Block a user