extends Control ## Anzeige einer einzelnen Spielkarte (CR 17). ## ## Zeigt die PNG aus assets/ui/cards/, sobald der Autor sie geliefert hat ## (Pfad kommt aus data/minigames/cards.json). Fehlt die Datei, zeichnet ## diese Ansicht eine **Platzhalter-Karte**: weißes Rechteck mit Wert und ## Farbzeichen, rot oder schwarz. Beide Zustände sind gleich groß und ## gleich bedienbar — das Spiel wartet nicht auf die Grafiken. ## ## Verdeckte Karten (show_back) zeigen den Rücken; auch dafür gibt es ## einen Platzhalter, damit die Gegnerhand vor dem Showdown zu ist. const CARD_SIZE := Vector2(64, 92) const CORNER_RADIUS := 5 var _card: Dictionary = {} var _is_face_up := true ## Baut die Kinder-Knoten einmalig auf. func _ready() -> void: custom_minimum_size = CARD_SIZE size = CARD_SIZE ## Zeigt eine Karte offen an. func show_card(card: Dictionary, deck: CardDeck) -> void: _card = card _is_face_up = true _rebuild(deck) ## Zeigt die Rückseite (Gegnerhand vor dem Showdown). func show_back(deck: CardDeck) -> void: _card = {} _is_face_up = false _rebuild(deck) ## Die aktuell gezeigte Karte (für Sonden). func get_card() -> Dictionary: return _card ## Liegt die Karte offen? (für Sonden) func is_face_up() -> bool: return _is_face_up ## Baut die Anzeige neu: Textur, wenn vorhanden, sonst Platzhalter. func _rebuild(deck: CardDeck) -> void: for child in get_children(): child.queue_free() var path := "" if _is_face_up and deck != null: path = deck.texture_path(_card) elif deck != null and not deck.texture_dir.is_empty(): path = deck.texture_dir + "ruecken.png" if not path.is_empty() and ResourceLoader.exists(path): var texture_rect := TextureRect.new() texture_rect.texture = load(path) texture_rect.expand_mode = TextureRect.EXPAND_IGNORE_SIZE texture_rect.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED texture_rect.set_anchors_preset(Control.PRESET_FULL_RECT) add_child(texture_rect) return _build_placeholder() ## Zeichnet die Platzhalter-Karte aus Rechteck und Text. func _build_placeholder() -> void: var panel := PanelContainer.new() panel.set_anchors_preset(Control.PRESET_FULL_RECT) var style := StyleBoxFlat.new() style.corner_radius_top_left = CORNER_RADIUS style.corner_radius_top_right = CORNER_RADIUS style.corner_radius_bottom_left = CORNER_RADIUS style.corner_radius_bottom_right = CORNER_RADIUS style.border_width_left = 2 style.border_width_top = 2 style.border_width_right = 2 style.border_width_bottom = 2 if not _is_face_up: style.bg_color = Color(0.22, 0.26, 0.38) style.border_color = Color(0.42, 0.46, 0.58) else: style.bg_color = Color(0.96, 0.95, 0.91) style.border_color = Color(0.35, 0.33, 0.3) panel.add_theme_stylebox_override("panel", style) add_child(panel) if not _is_face_up: return var label := Label.new() label.set_anchors_preset(Control.PRESET_FULL_RECT) label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER label.text = "%s\n%s" % [str(_card.get("label", "?")), str(_card.get("symbol", "?"))] label.add_theme_font_size_override("font_size", 22) var is_red: bool = bool(_card.get("is_red", false)) label.add_theme_color_override("font_color", Color(0.72, 0.16, 0.16) if is_red else Color(0.12, 0.12, 0.14)) add_child(label)