Punkt wyjscia
This commit is contained in:
parent
edd30ea0f4
commit
e9172db507
3
scenes/planet.tscn
Normal file
3
scenes/planet.tscn
Normal file
@ -0,0 +1,3 @@
|
||||
[gd_scene format=3 uid="uid://cynwjsqox5eqx"]
|
||||
|
||||
[node name="Planet" type="Node2D"]
|
||||
12
scenes/sector.tscn
Normal file
12
scenes/sector.tscn
Normal file
@ -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")
|
||||
3
scenes/star.tscn
Normal file
3
scenes/star.tscn
Normal file
@ -0,0 +1,3 @@
|
||||
[gd_scene format=3 uid="uid://cvc0brcqh2rhu"]
|
||||
|
||||
[node name="Star" type="Node2D"]
|
||||
@ -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...")
|
||||
|
||||
@ -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
|
||||
|
||||
# dodaj nazwę pod gwiazdą
|
||||
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))
|
||||
|
||||
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")
|
||||
|
||||
25
scripts/sector.gd
Normal file
25
scripts/sector.gd
Normal file
@ -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!")
|
||||
1
scripts/sector.gd.uid
Normal file
1
scripts/sector.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://c6s5mbfosgmc3
|
||||
Loading…
x
Reference in New Issue
Block a user