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. var counts := {} # Tisch var own := {} # eigene Seite func _init(rect: Rect2) -> void: position = rect.position size = rect.size mouse_filter = Control.MOUSE_FILTER_IGNORE for e in Cards.ELEMENTS: counts[e] = 0 own[e] = 0 func update_from(g: Game, me: Game.Player) -> void: counts = g.element_counts() for e in Cards.ELEMENTS: own[e] = me.element_count(e) 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 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)" if paired(e): s += " (%s)" % tr(Cards.ELEMENT_KEYWORD[e]) parts.append(s) return " ยท ".join(parts) func _draw() -> void: var w := size.x / Cards.ELEMENTS.size() 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)