2022-08-31 16:43:15 +02:00
|
|
|
extends Spatial
|
2022-09-15 14:15:23 +02:00
|
|
|
class_name HexTile3D
|
2022-08-25 15:33:44 +02:00
|
|
|
|
|
|
|
onready var is_mouse_over = false
|
2022-08-31 16:43:15 +02:00
|
|
|
onready var mesh = $Mesh
|
2022-10-08 14:14:20 +02:00
|
|
|
onready var old_material_override = preload("res://materials/SandTile.tres")
|
|
|
|
onready var game_tile = preload("res://utils/GameTile.gd").new()
|
2022-08-25 15:33:44 +02:00
|
|
|
|
2022-08-25 17:06:26 +02:00
|
|
|
signal tile_selected
|
2022-08-25 23:40:19 +02:00
|
|
|
signal tile_mouse_entered
|
|
|
|
|
2022-09-21 14:09:31 +02:00
|
|
|
#var cube_coords = Vector3(0, 0, 0) setget set_cube_coords, get_cube_coords
|
|
|
|
|
|
|
|
func set_tiletype(type):
|
2022-10-07 16:14:05 +02:00
|
|
|
var GameTile = load("res://utils/GameTile.gd").new()
|
2022-09-21 14:09:31 +02:00
|
|
|
|
2022-10-08 14:14:20 +02:00
|
|
|
game_tile.type = type
|
2022-09-21 14:09:31 +02:00
|
|
|
|
2022-10-08 14:14:20 +02:00
|
|
|
var _mesh = $Mesh
|
|
|
|
|
|
|
|
if type == GameTile.TileType.Sand or type== GameTile.TileType.Water:
|
|
|
|
_mesh.set_surface_material(0, preload("res://materials/SandTile.tres"))
|
2022-10-07 16:14:05 +02:00
|
|
|
elif type == GameTile.TileType.Grass:
|
2022-10-08 14:14:20 +02:00
|
|
|
_mesh.set_surface_material(0, preload("res://materials/GrassTile.tres"))
|
2022-09-21 14:09:31 +02:00
|
|
|
else:
|
2022-10-08 14:14:20 +02:00
|
|
|
_mesh.set_surface_material(0, preload("res://materials/DeepGrassTile.tres"))
|
2022-09-15 14:15:23 +02:00
|
|
|
|
2022-08-25 17:06:26 +02:00
|
|
|
|
2022-08-25 15:33:44 +02:00
|
|
|
func _on_Area_mouse_entered():
|
|
|
|
is_mouse_over = true
|
2022-08-31 16:43:15 +02:00
|
|
|
old_material_override = mesh.material_override
|
2022-08-25 15:33:44 +02:00
|
|
|
|
2022-08-31 16:43:15 +02:00
|
|
|
var material = mesh.get_surface_material(0)
|
2022-08-25 15:33:44 +02:00
|
|
|
var cloned_material = material.duplicate()
|
|
|
|
cloned_material.albedo_color = Color (1, 0, 0)
|
2022-08-31 16:43:15 +02:00
|
|
|
mesh.material_override = cloned_material
|
2022-08-25 23:40:19 +02:00
|
|
|
emit_signal("tile_mouse_entered", self)
|
2022-08-25 15:33:44 +02:00
|
|
|
|
2022-08-25 17:06:26 +02:00
|
|
|
|
2022-08-25 15:33:44 +02:00
|
|
|
func _on_Area_mouse_exited():
|
|
|
|
is_mouse_over = false
|
2022-08-31 16:43:15 +02:00
|
|
|
mesh.material_override = old_material_override
|
2022-08-25 17:06:26 +02:00
|
|
|
|
|
|
|
|
2022-10-08 14:14:20 +02:00
|
|
|
func _on_Area_input_event(_camera, event, position, _normal, _shape_idx):
|
2022-08-25 17:06:26 +02:00
|
|
|
if is_mouse_over and event is InputEventMouseButton:
|
|
|
|
if event.button_index == 1 and event.pressed:
|
|
|
|
emit_signal("tile_selected", self)
|