93 lines
2.2 KiB
GDScript
93 lines
2.2 KiB
GDScript
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")
|
|
onready var IslandIndex = get_node("UI/Editor/IslandIndex")
|
|
|
|
# World objects
|
|
onready var world = get_node("../World")
|
|
onready var world_camera = get_node("../World/Camera")
|
|
var last_index = -1
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
pass # Replace with function body.
|
|
|
|
|
|
func handle_editor_event(event):
|
|
var island = world.current_island
|
|
|
|
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
|
|
|
|
var hex_coord = Globals.HexGrid.get_hex_center(Globals.ScreenToHex(event.position,world.WorldCamera))
|
|
island.set_tile(hex_coord, tile_type)
|
|
|
|
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()
|
|
|
|
|
|
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)
|
|
|
|
|
|
func _on_SaveWorldButton_pressed():
|
|
var island = world.current_island
|
|
island.save_island(get_island_filename())
|
|
|
|
|
|
func _on_ClearWorldButton_pressed():
|
|
var island = world.current_island
|
|
island.clear_island()
|
|
|
|
|
|
func _on_LoadWorldButton_pressed():
|
|
var island = world.current_island
|
|
island.load_island(get_island_filename())
|
|
last_index = IslandIndex.value
|
|
|
|
|
|
func _on_EditIslandButton_toggled(button_pressed):
|
|
EditorUI.visible = button_pressed
|
|
print (button_pressed)
|
|
|
|
|
|
func _on_IslandIndex_value_changed(value):
|
|
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())
|
|
|