CellGrid.gd 806 B

12345678910111213141516171819202122232425262728293031
  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. var firstTile : CellTile = GetTile(0)
  11. var tileSize : int = firstTile.size.x + get("theme_override_constants/h_separation") if firstTile else 0
  12. if tileSize > 0:
  13. columns = max(1, int(size.x / tileSize))
  14. else:
  15. columns = maxCount
  16. func _ready():
  17. tiles.resize(maxCount)
  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.call_deferred(tile)
  23. func _on_gui_input(event : InputEvent):
  24. Launcher.Action.TryConsume(event, "gp_zoom_in")
  25. Launcher.Action.TryConsume(event, "gp_zoom_out")