class_name ElementView extends Control ## Die Vier-Elemente-Regel auf einen Blick: offene Wesen je Element auf dem Tisch. Ab vier ## bekommt das Element +1/+1 und das Element, das es schlägt, -1/-1. var counts := {} 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 func update_from(g: Game) -> void: counts = g.element_counts() queue_redraw() func strong(e: String) -> bool: return int(counts.get(e, 0)) >= Game.ELEMENT_STACK func weak(e: String) -> bool: var predator := Cards.beaten_by(e) return predator != "" and strong(predator) ## 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 weak(e): s += " (-1/-1)" 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 weak(e): draw_style_box(Style.box(Color(Style.RED, 0.12), 6, Style.RED, 1), Rect2(x0 + 2, 0, w - 4, size.y)) Style.text(self, tr(e), 13, Style.TEXT if strong(e) else Style.MUTED, Vector2(x0 + 12, cy), "midleft", strong(e)) 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) if n > Game.ELEMENT_STACK: Style.text(self, "+%d" % (n - Game.ELEMENT_STACK), 11, Style.MUTED, Vector2(px + Game.ELEMENT_STACK * 13 + 2, cy), "midleft") var tag := "" if strong(e): tag = "+1/+1" elif weak(e): tag = "-1/-1" if tag != "": Style.text(self, tag, 13, Style.GREEN if strong(e) else Style.RED, Vector2(x0 + w - 12, cy), "midright", true)