diff --git a/scenes/planet.tscn b/scenes/planet.tscn new file mode 100644 index 0000000..372aafb --- /dev/null +++ b/scenes/planet.tscn @@ -0,0 +1,3 @@ +[gd_scene format=3 uid="uid://cynwjsqox5eqx"] + +[node name="Planet" type="Node2D"] diff --git a/scenes/sector.tscn b/scenes/sector.tscn new file mode 100644 index 0000000..c7ac2c7 --- /dev/null +++ b/scenes/sector.tscn @@ -0,0 +1,12 @@ +[gd_scene load_steps=3 format=3 uid="uid://duxpu41p6vik2"] + +[ext_resource type="Script" uid="uid://c6s5mbfosgmc3" path="res://scripts/sector.gd" id="1_c2nvg"] +[ext_resource type="Texture2D" uid="uid://c77e86rim4e14" path="res://assets/background/space1.jpg" id="1_l8itw"] + +[node name="sector" type="Node2D"] +script = ExtResource("1_c2nvg") + +[node name="Sprite2D" type="Sprite2D" parent="."] +position = Vector2(576.00006, 324) +scale = Vector2(0.29999998, 0.3) +texture = ExtResource("1_l8itw") diff --git a/scenes/star.tscn b/scenes/star.tscn new file mode 100644 index 0000000..a4f955e --- /dev/null +++ b/scenes/star.tscn @@ -0,0 +1,3 @@ +[gd_scene format=3 uid="uid://cvc0brcqh2rhu"] + +[node name="Star" type="Node2D"] diff --git a/scripts/GameData.gd b/scripts/GameData.gd index 1bfd62e..34d79e6 100644 --- a/scripts/GameData.gd +++ b/scripts/GameData.gd @@ -2,7 +2,7 @@ extends Node var player_data = [] var sectors: Array = [] - +var selected_sector_data: SectorData = null func new_game(): TranslationServer.set_locale(Settings.language) print("🔹 Tworzenie nowej gry...") diff --git a/scripts/galaxy.gd b/scripts/galaxy.gd index 650c9c2..c1226ef 100644 --- a/scripts/galaxy.gd +++ b/scripts/galaxy.gd @@ -1,30 +1,62 @@ +# Plik: Galaxy.gd extends Node2D func _ready(): - var sectors = GameData.sectors # zakładam że GameData jest autoloadem + var sectors = GameData.sectors _spawn_sectors(sectors) func _spawn_sectors(sectors: Array): for sector in sectors: - var star = Sprite2D.new() - star.texture = sector.texture - star.position = sector.position - star.scale = Vector2(0.02, 0.02) # ewentualnie zmień skalę - add_child(star) # dodajemy bezpośrednio do Galaxy + + var star_button = TextureButton.new() + star_button.set_meta("sector_data", sector) + + star_button.texture_normal = sector.texture + star_button.position = sector.position + + star_button.scale = Vector2(0.02, 0.02) + + if sector.texture: + var size = sector.texture.get_size() + star_button.custom_minimum_size = size + star_button.size = size + + add_child(star_button) + + star_button.pressed.connect(_on_star_clicked.bind(star_button)) - # dodaj nazwę pod gwiazdą var name_label = Label.new() name_label.text = sector.name - name_label.position = star.position + Vector2(-20, 20) + name_label.position = star_button.position + Vector2(-20, 20) add_child(name_label) - # dodaj nazwę pod gwiazdą var name_label2 = Label.new() name_label2.text = sector.planets[0].name - name_label2.position = star.position + Vector2(-20, 40) + name_label2.position = star_button.position + Vector2(-20, 40) add_child(name_label2) +func _on_star_clicked(star_button_node: TextureButton): + var clicked_sector_data = star_button_node.get_meta("sector_data") + + if clicked_sector_data: + open_sector_view(clicked_sector_data) + else: + push_error("Błąd: Nie znaleziono danych sektora w przycisku.") + + +func open_sector_view(data): + + GameData.selected_sector_data = data + + var error = get_tree().change_scene_to_file("res://scenes/sector.tscn") + + if error != OK: + push_error("BŁĄD ZMIANY SCENY: Nie udało się załadować res://scenes/sector.tscn. Sprawdź ścieżkę i plik.") + else: + print("Przeniesiono do widoku sektora:", data.name) + + func _input(event): - if event.is_action_pressed("ui_cancel"): # "ui_cancel" to ESC + if event.is_action_pressed("ui_cancel"): get_tree().change_scene_to_file("res://scenes/Menu.tscn") diff --git a/scripts/sector.gd b/scripts/sector.gd new file mode 100644 index 0000000..8ae80c2 --- /dev/null +++ b/scripts/sector.gd @@ -0,0 +1,25 @@ +# Plik: sector_view_script.gd (Skrypt podłączony do root węzła w sector.tscn) +extends Node2D # lub inny węzeł główny +class_name SectorView # Używamy class_name dla czystości + +var sector_data: SectorData # Lokalna referencja do danych + +func _ready(): + # Pobieramy referencję do danych z Singletonu + sector_data = GameData.selected_sector_data + + if sector_data: + print("Scena sektor załadowana. Dane pobrane dla:", sector_data.name) + # ZWOLNIJ SCHOWEK + GameData.selected_sector_data = null + + # --- TUTAJ ZACZYNASZ INSTANCJONOWAĆ WIZUALIZACJE --- + # Np. rysujesz gwiazdę, planety itd. + + var debug_label = Label.new() + debug_label.text = "Widok Sektora: " + sector_data.name + ", Planety: " + str(sector_data.planets.size()) + debug_label.position = Vector2(100, 100) + add_child(debug_label) + + else: + push_error("Błąd: Scena sektora nie otrzymała danych z GameData!") diff --git a/scripts/sector.gd.uid b/scripts/sector.gd.uid new file mode 100644 index 0000000..faf1329 --- /dev/null +++ b/scripts/sector.gd.uid @@ -0,0 +1 @@ +uid://c6s5mbfosgmc3