Elemente, Kombos, Fallen, KI mit Vorausschau, Kampagne, Hotseat und Netzwerk, Werkstatt, Erfolge, Tagesaufgaben, Tests und Exporte. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QPgKvy5W9WRNFHjkm5QsHx
51 lines
1.5 KiB
GDScript
51 lines
1.5 KiB
GDScript
class_name CardGrid
|
|
extends ScrollContainer
|
|
## Scrollbares Kartenraster mit Beschriftung unter jeder Karte.
|
|
|
|
signal card_clicked(card: Cards.Card)
|
|
signal card_hover(card: Cards.Card, entered: bool)
|
|
|
|
const COLS := 7
|
|
const CW := 100
|
|
const CH := 140
|
|
const GAP := 12
|
|
|
|
var grid: GridContainer
|
|
|
|
|
|
func _init(rect: Rect2) -> void:
|
|
position = rect.position
|
|
size = rect.size
|
|
horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED
|
|
grid = GridContainer.new()
|
|
grid.columns = COLS
|
|
grid.add_theme_constant_override("h_separation", GAP)
|
|
grid.add_theme_constant_override("v_separation", GAP)
|
|
add_child(grid)
|
|
|
|
|
|
## cards: Karten; label_fn(card) -> String; dim_fn(card) -> bool
|
|
func fill(cards: Array, label_fn: Callable, dim_fn: Callable) -> void:
|
|
Style.clear(grid)
|
|
for c in cards:
|
|
var cell := Control.new()
|
|
cell.custom_minimum_size = Vector2(CW, CH + 16)
|
|
cell.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
var v := CardView.new(c, Vector2(CW, CH))
|
|
v.dim = dim_fn.call(c)
|
|
v.clicked.connect(func(_view): card_clicked.emit(c))
|
|
v.hover.connect(func(card, entered): card_hover.emit(card, entered))
|
|
cell.add_child(v)
|
|
var text: String = label_fn.call(c)
|
|
Style.label(cell, text, 12, Style.MUTED if v.dim else Style.TEXT, Rect2(0, CH + 1, CW, 16), "center")
|
|
grid.add_child(cell)
|
|
|
|
|
|
func views() -> Array:
|
|
var out := []
|
|
for cell in grid.get_children():
|
|
for v in cell.get_children():
|
|
if v is CardView:
|
|
out.append(v)
|
|
return out
|