2021-06-27 12:26:44 +02:00
|
|
|
extends Node2D
|
|
|
|
|
|
|
|
|
|
|
|
# Declare member variables here. Examples:
|
|
|
|
# var a = 2
|
|
|
|
# var b = "text"
|
|
|
|
|
|
|
|
# UI elements
|
|
|
|
onready var EditorUI = get_node("UI/Editor")
|
|
|
|
onready var TileTypes = get_node("UI/TileTypes")
|
|
|
|
onready var NoneButton = get_node("UI/Editor/NoneButton")
|
2021-06-28 22:34:48 +02:00
|
|
|
onready var IslandIndex = get_node("UI/Editor/IslandIndex")
|
2021-06-27 12:26:44 +02:00
|
|
|
|
|
|
|
# World objects
|
|
|
|
onready var world = get_node("../World")
|
|
|
|
onready var world_camera = get_node("../World/Camera")
|
2021-06-28 22:34:48 +02:00
|
|
|
var last_index = -1
|
2021-06-27 12:26:44 +02:00
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready():
|
|
|
|
pass # Replace with function body.
|
|
|
|
|
|
|
|
|
|
|
|
func handle_editor_event(event):
|
2021-06-28 22:34:48 +02:00
|
|
|
var island = world.current_island
|
|
|
|
|
2021-06-27 12:26:44 +02:00
|
|
|
if (Input.get_mouse_button_mask() & BUTTON_LEFT) == BUTTON_LEFT:
|
|
|
|
# if event.pressed and event.button_index == BUTTON_LEFT:
|
|
|
|
var pressed_button = NoneButton.group.get_pressed_button()
|
|
|
|
var tile_type = "None"
|
|
|
|
if pressed_button:
|
|
|
|
tile_type = pressed_button.text
|
|
|
|
|
2021-06-28 21:51:09 +02:00
|
|
|
var hex_coord = Globals.HexGrid.get_hex_center(Globals.ScreenToHex(event.position,world.WorldCamera))
|
2021-06-28 22:34:48 +02:00
|
|
|
island.set_tile(hex_coord, tile_type)
|
2021-06-27 12:26:44 +02:00
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
|
|
|
|
func _unhandled_input(event):
|
|
|
|
if not EditorUI.visible:
|
|
|
|
return
|
|
|
|
|
|
|
|
if event is InputEventMouseButton:
|
|
|
|
if handle_editor_event (event):
|
|
|
|
return
|
|
|
|
|
|
|
|
if 'position' in event:
|
|
|
|
if handle_editor_event (event):
|
|
|
|
return
|
|
|
|
|
|
|
|
update()
|
|
|
|
|
|
|
|
|
2021-06-28 22:34:48 +02:00
|
|
|
func get_island_filename_for_index(index):
|
|
|
|
return "user://pirate_game_island_" + str(index) + ".island"
|
|
|
|
|
|
|
|
|
|
|
|
func get_island_filename():
|
|
|
|
return get_island_filename_for_index(IslandIndex.value)
|
|
|
|
|
|
|
|
|
2021-06-27 12:26:44 +02:00
|
|
|
func _on_SaveWorldButton_pressed():
|
2021-06-28 22:34:48 +02:00
|
|
|
var island = world.current_island
|
|
|
|
island.save_island(get_island_filename())
|
2021-06-27 12:26:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
func _on_ClearWorldButton_pressed():
|
2021-06-28 22:34:48 +02:00
|
|
|
var island = world.current_island
|
|
|
|
island.clear_island()
|
2021-06-27 12:26:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
func _on_LoadWorldButton_pressed():
|
2021-06-28 22:34:48 +02:00
|
|
|
var island = world.current_island
|
|
|
|
island.load_island(get_island_filename())
|
|
|
|
last_index = IslandIndex.value
|
2021-06-27 12:26:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
func _on_EditIslandButton_toggled(button_pressed):
|
|
|
|
EditorUI.visible = button_pressed
|
|
|
|
print (button_pressed)
|
2021-06-28 22:34:48 +02:00
|
|
|
|
|
|
|
|
2021-07-07 22:22:07 +02:00
|
|
|
func _on_IslandIndex_value_changed(_value):
|
2021-06-28 22:34:48 +02:00
|
|
|
var island = world.current_island
|
|
|
|
if last_index >= 0:
|
|
|
|
island.save_island(get_island_filename_for_index(last_index))
|
|
|
|
island.clear_island()
|
|
|
|
island.load_island(get_island_filename())
|
|
|
|
|