CellGrid.gd 670 B

12345678910111213141516171819202122232425262728
  1. extends GridContainer
  2. #
  3. @export var maxCount : int = 100
  4. var tiles : Array[CellTile] = []
  5. #
  6. func GetTile(idx : int) -> CellTile:
  7. return tiles[idx] if idx < maxCount else null
  8. #
  9. func _on_panel_resized():
  10. if get_child_count() > 0:
  11. var tileSize : int = get_child(0).size.x + get("theme_override_constants/h_separation")
  12. columns = max(1, int(get_parent().get_size().x / tileSize))
  13. else:
  14. columns = 100
  15. func _ready():
  16. tiles.resize(maxCount)
  17. get_parent().resized.connect(_on_panel_resized)
  18. for tileIdx in range(maxCount):
  19. var tile : CellTile = UICommons.CellTilePreset.instantiate()
  20. tile.AssignData(null, 0)
  21. tiles[tileIdx] = tile
  22. add_child(tile)