63 lines
1.8 KiB
GDScript
63 lines
1.8 KiB
GDScript
extends Node2D
|
|
|
|
|
|
# Declare member variables here. Examples:
|
|
# var a = 2
|
|
# var b = "text"
|
|
|
|
var GridLevel
|
|
|
|
var highlight_hex_coord = Vector2(0,0)
|
|
|
|
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")
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready():
|
|
GridLevel = get_node("GridLevel")
|
|
TileType.add_item("None", 0)
|
|
TileType.add_item("Sand", 1)
|
|
TileType.add_item("Grass", 2)
|
|
update()
|
|
|
|
func _process(_delta):
|
|
var view_size = OS.get_window_safe_area().size
|
|
ui.rect_position = -view_size * 0.5
|
|
update()
|
|
|
|
func _unhandled_input(event):
|
|
if 'position' in event:
|
|
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)
|
|
|
|
if event is InputEventMouseButton:
|
|
if event.button_index == BUTTON_LEFT and event.pressed:
|
|
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
|
|
|
|
update()
|
|
|
|
|
|
func _draw():
|
|
draw_set_transform(highlight_hex_coord, 0, Vector2.ONE)
|
|
draw_polyline(GridLevel.HexPoints, "#ff0000", 4)
|
|
|
|
|
|
|