Adding cursors

This commit is contained in:
2024-09-01 17:10:10 +02:00
parent 67d7812205
commit ebf0952dec
10 changed files with 74 additions and 8 deletions

View File

@@ -9,6 +9,8 @@ const SCREEN_BORDER_THRESHOLD = 40
var grabbing = false
var mouse_last_global_position = Vector2()
signal mouse_motion
func _process(delta):
var direction = Vector2()
var zoom_change = 0
@@ -71,4 +73,8 @@ func move_camera_on_map(movement):
0
)
)
position = lerp(position, new_position, 0.7)
position = lerp(position, new_position, 0.8)
func _input(event):
if event is InputEventMouseMotion:
emit_signal("mouse_motion", get_global_mouse_position())

View File

@@ -20,3 +20,7 @@ func _on_scanner_modes_scanner_selected(type : Scanners.Type):
func _on_planter_seed_list_updated() -> void:
seed_queue.update_queue()
seed_card.update_card()
func _on_camera_2d_mouse_motion(mouse_position):
seed_card.update_mouse_position(mouse_position)

View File

@@ -29,3 +29,14 @@ func update_card():
waterSupply.text = str(next_seed_param.water_prod)
fertilitySupply.text = str(next_seed_param.fertility_prod)
populationSupply.text = str(next_seed_param.presence_prod)
func update_mouse_position(mouse_position):
if (
mouse_position.x > 0
and mouse_position.y > 0
and mouse_position.x < GameTerrain.TERRAIN_SIZE.x * GameTerrain.MAP_RATIO
and mouse_position.y < GameTerrain.TERRAIN_SIZE.y * GameTerrain.MAP_RATIO
):
waterNeeds.set_cursor(GameTerrain.get_color(mouse_position).r)
fertilityNeeds.set_cursor(GameTerrain.get_color(mouse_position).g)
populationNeeds.set_cursor(GameTerrain.get_color(mouse_position).b)

View File

@@ -3,6 +3,8 @@ extends CenterContainer
@export var gradient : GradientTexture1D
const CURSOR_WIDTH = 0.08
# Called when the node enters the scene tree for the first time.
func _ready():
$Gradient.texture = gradient
@@ -26,3 +28,20 @@ func set_area(need : Array):
texture.gradient = zone_grad
$Zone.texture = texture
func set_cursor(color_value):
var zone_grad := Gradient.new()
zone_grad.interpolation_mode = Gradient.GRADIENT_INTERPOLATE_CONSTANT
zone_grad.set_color(0, Color(1,1,1,0))
zone_grad.set_color(1, Color(1,1,1,0))
zone_grad.add_point(max(color_value - CURSOR_WIDTH/2, 0.0), Color(1,1,1,1))
zone_grad.add_point(min(color_value + CURSOR_WIDTH/2, 1.0), Color(1,1,1,0))
var texture := GradientTexture1D.new()
texture.gradient = zone_grad
$Cursor.texture = texture

View File

@@ -132,6 +132,12 @@ func modify_rect(
)
update_texture()
func get_color(
pos: Vector2
) -> Color:
var pixel_pos = map_to_pixel(pos)
return image.get_pixelv(pixel_pos)
func get_stat(
pos: Vector2,
stat : Stats
@@ -161,7 +167,7 @@ func setup_texture(
Vector3i(
color_value_to_level(water_noise.get_noise_2d(x, y)),
color_value_to_level(fertility_noise.get_noise_2d(x, y)/2),
-5
-LEVELS_NUMBER/2
)
)
update_texture()