2021-06-13 15:03:10 +02:00
|
|
|
extends Node2D
|
|
|
|
|
|
|
|
|
|
|
|
# Declare member variables here. Examples:
|
|
|
|
# var a = 2
|
|
|
|
# var b = "text"
|
|
|
|
|
|
|
|
var GridLevel
|
|
|
|
|
|
|
|
var highlight_hex_coord = Vector2(0,0)
|
|
|
|
|
2021-06-13 20:40:05 +02:00
|
|
|
onready var camera = get_node("Camera2D")
|
|
|
|
onready var ui = get_node("Camera2D/UI")
|
|
|
|
onready var ScreenCoords = get_node("Camera2D/UI/ScreenCoords")
|
|
|
|
onready var HexCoords = get_node("Camera2D/UI/HexCoords")
|
|
|
|
onready var WorldCoords = get_node("Camera2D/UI/WorldCoords")
|
|
|
|
onready var TileType = get_node("Camera2D/UI/TileType")
|
|
|
|
|
2021-06-13 15:03:10 +02:00
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready():
|
|
|
|
GridLevel = get_node("GridLevel")
|
2021-06-13 20:40:05 +02:00
|
|
|
TileType.add_item("None", 0)
|
|
|
|
TileType.add_item("Sand", 1)
|
|
|
|
TileType.add_item("Grass", 2)
|
2021-06-13 15:03:10 +02:00
|
|
|
update()
|
|
|
|
|
2021-06-13 20:40:05 +02:00
|
|
|
func _process(_delta):
|
|
|
|
var view_size = OS.get_window_safe_area().size
|
|
|
|
ui.rect_position = -view_size * 0.5
|
|
|
|
update()
|
2021-06-13 15:03:10 +02:00
|
|
|
|
2021-06-13 20:40:05 +02:00
|
|
|
func _unhandled_input(event):
|
2021-06-13 15:03:10 +02:00
|
|
|
if 'position' in event:
|
2021-06-13 20:40:05 +02:00
|
|
|
ScreenCoords.text = str(event.position)
|
|
|
|
var world_coords = camera.ScreenToWorld(event.position)
|
|
|
|
WorldCoords.text = str(world_coords)
|
|
|
|
var hex_coords = GridLevel.WorldToTileCoords(world_coords)
|
|
|
|
|
|
|
|
HexCoords.text = str(hex_coords)
|
|
|
|
highlight_hex_coord = GridLevel.GetHexCenter(hex_coords)
|
2021-06-13 15:03:10 +02:00
|
|
|
|
|
|
|
if event is InputEventMouseButton:
|
|
|
|
if event.button_index == BUTTON_LEFT and event.pressed:
|
2021-06-13 20:40:05 +02:00
|
|
|
GridLevel.SetTile (hex_coords.x, hex_coords.y, TileType.selected)
|
|
|
|
if event.button_index == BUTTON_WHEEL_DOWN and event.pressed:
|
|
|
|
camera.zoom = camera.zoom * 1.0 / 0.8
|
|
|
|
if event.button_index == BUTTON_WHEEL_UP and event.pressed:
|
|
|
|
camera.zoom = camera.zoom * 0.8
|
|
|
|
|
|
|
|
if event is InputEventMouseButton and Input.is_mouse_button_pressed(BUTTON_MIDDLE):
|
|
|
|
camera.transform.origin = world_coords
|
2021-06-13 15:03:10 +02:00
|
|
|
|
|
|
|
update()
|
|
|
|
|
|
|
|
|
|
|
|
func _draw():
|
|
|
|
draw_set_transform(highlight_hex_coord, 0, Vector2.ONE)
|
|
|
|
draw_polyline(GridLevel.HexPoints, "#ff0000", 4)
|
|
|
|
|
|
|
|
|
|
|
|
|