diff --git a/Game.tscn b/Game.tscn index 66bcf59..c2256e1 100644 --- a/Game.tscn +++ b/Game.tscn @@ -22,4 +22,5 @@ script = ExtResource("3_7olyu") camera = NodePath("../Camera2D") [connection signal="scanner_selected" from="Interface/Gui" to="Map" method="_on_gui_scanner_selected"] +[connection signal="mouse_motion" from="Camera2D" to="Interface/Gui" method="_on_camera_2d_mouse_motion"] [connection signal="seed_list_updated" from="Planter" to="Interface/Gui" method="_on_planter_seed_list_updated"] diff --git a/objects/gui/Scanner_modes.tscn b/objects/gui/Scanner_modes.tscn index 75ecaa8..06daa1c 100644 --- a/objects/gui/Scanner_modes.tscn +++ b/objects/gui/Scanner_modes.tscn @@ -1,7 +1,10 @@ -[gd_scene load_steps=3 format=3 uid="uid://0so4tpnkk8t2"] +[gd_scene load_steps=6 format=3 uid="uid://0so4tpnkk8t2"] [ext_resource type="Script" path="res://scripts/gui/scanner_modes.gd" id="1_synac"] [ext_resource type="Theme" uid="uid://dnebunkx13tbr" path="res://assets/gui/Text.tres" id="2_3kvh5"] +[ext_resource type="Texture2D" uid="uid://dpfe11wn04ntd" path="res://assets/gui/icons/watering-soil.svg" id="3_7lrcm"] +[ext_resource type="Texture2D" uid="uid://dgo81cisfryi1" path="res://assets/gui/icons/soil-alt.svg" id="4_ld01f"] +[ext_resource type="Texture2D" uid="uid://bdg3ep75da6xd" path="res://assets/gui/icons/tree.svg" id="5_fjsbw"] [node name="ScannerModes" type="Control"] layout_mode = 3 @@ -24,10 +27,13 @@ selected = 0 item_count = 4 popup/item_0/text = "No Scanner" popup/item_1/text = "Water" +popup/item_1/icon = ExtResource("3_7lrcm") popup/item_1/id = 1 popup/item_2/text = "Fertility" +popup/item_2/icon = ExtResource("4_ld01f") popup/item_2/id = 2 popup/item_3/text = "Population" +popup/item_3/icon = ExtResource("5_fjsbw") popup/item_3/id = 3 [connection signal="item_selected" from="Scanner Select" to="." method="_on_scanner_select_item_selected"] diff --git a/objects/gui/Seed_card.tscn b/objects/gui/Seed_card.tscn index 20e6e07..811e40c 100644 --- a/objects/gui/Seed_card.tscn +++ b/objects/gui/Seed_card.tscn @@ -4,7 +4,7 @@ [ext_resource type="Theme" uid="uid://dnebunkx13tbr" path="res://assets/gui/Text.tres" id="2_n5opx"] [ext_resource type="Texture2D" uid="uid://dpfe11wn04ntd" path="res://assets/gui/icons/watering-soil.svg" id="3_4sryb"] [ext_resource type="Texture2D" uid="uid://be2uusaqcpcpd" path="res://assets/gradients/Fertility.tres" id="4_5omu3"] -[ext_resource type="PackedScene" path="res://objects/gui/Stats_area.tscn" id="4_wwqbk"] +[ext_resource type="PackedScene" uid="uid://qjwtbyq2c87m" path="res://objects/gui/Stats_area.tscn" id="4_wwqbk"] [ext_resource type="Texture2D" uid="uid://cwowpvsoo3dey" path="res://assets/gradients/Water.tres" id="5_hwfmn"] [ext_resource type="Texture2D" uid="uid://dgo81cisfryi1" path="res://assets/gui/icons/soil-alt.svg" id="6_4k6c3"] [ext_resource type="Texture2D" uid="uid://bdg3ep75da6xd" path="res://assets/gui/icons/tree.svg" id="8_i3l01"] diff --git a/objects/gui/Stats_area.tscn b/objects/gui/Stats_area.tscn index ed8cfd3..85860bd 100644 --- a/objects/gui/Stats_area.tscn +++ b/objects/gui/Stats_area.tscn @@ -1,16 +1,24 @@ -[gd_scene load_steps=5 format=3 uid="uid://qjwtbyq2c87m"] +[gd_scene load_steps=7 format=3 uid="uid://qjwtbyq2c87m"] [ext_resource type="Script" path="res://scripts/gui/stats_area.gd" id="1_il8so"] [ext_resource type="Texture2D" uid="uid://be2uusaqcpcpd" path="res://assets/gradients/Fertility.tres" id="1_qy7fg"] [sub_resource type="Gradient" id="Gradient_8q55d"] interpolation_mode = 1 -offsets = PackedFloat32Array(0, 0.319527, 0.718935) +offsets = PackedFloat32Array(0, 0.319527, 0.689349) colors = PackedColorArray(0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1) -[sub_resource type="GradientTexture1D" id="GradientTexture1D_tb5qg"] +[sub_resource type="GradientTexture1D" id="GradientTexture1D_58i1n"] gradient = SubResource("Gradient_8q55d") +[sub_resource type="Gradient" id="Gradient_o25mg"] +interpolation_mode = 1 +offsets = PackedFloat32Array(0, 0.319527, 0.37574) +colors = PackedColorArray(1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0) + +[sub_resource type="GradientTexture1D" id="GradientTexture1D_tb5qg"] +gradient = SubResource("Gradient_o25mg") + [node name="StatsArea" type="CenterContainer"] script = ExtResource("1_il8so") @@ -23,5 +31,11 @@ expand_mode = 2 [node name="Zone" type="TextureRect" parent="."] custom_minimum_size = Vector2(100, 10) layout_mode = 2 +texture = SubResource("GradientTexture1D_58i1n") +expand_mode = 2 + +[node name="Cursor" type="TextureRect" parent="."] +custom_minimum_size = Vector2(100, 10) +layout_mode = 2 texture = SubResource("GradientTexture1D_tb5qg") expand_mode = 2 diff --git a/scenes/Map.tscn b/scenes/Map.tscn index 1593f19..0d8c295 100644 --- a/scenes/Map.tscn +++ b/scenes/Map.tscn @@ -22,7 +22,6 @@ shader_parameter/texture_medium = ExtResource("7_iuq0o") shader_parameter/texture_high = ExtResource("5_6sl35") [sub_resource type="CompressedTexture2D" id="CompressedTexture2D_rhtup"] -load_path = "res://.godot/imported/normal.png-c44c610586e914477a8ee139158bfa7e.ctex" [sub_resource type="Gradient" id="Gradient_u5wcm"] offsets = PackedFloat32Array(1) diff --git a/scripts/camera.gd b/scripts/camera.gd index cf3c416..f3a4d1b 100644 --- a/scripts/camera.gd +++ b/scripts/camera.gd @@ -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()) diff --git a/scripts/gui.gd b/scripts/gui.gd index bfe93ef..dcd3669 100644 --- a/scripts/gui.gd +++ b/scripts/gui.gd @@ -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) diff --git a/scripts/gui/seed_card.gd b/scripts/gui/seed_card.gd index 21cb044..eb81e28 100644 --- a/scripts/gui/seed_card.gd +++ b/scripts/gui/seed_card.gd @@ -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) diff --git a/scripts/gui/stats_area.gd b/scripts/gui/stats_area.gd index f490238..7595fdf 100644 --- a/scripts/gui/stats_area.gd +++ b/scripts/gui/stats_area.gd @@ -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 diff --git a/scripts/terrain.gd b/scripts/terrain.gd index 278b558..dd269e1 100644 --- a/scripts/terrain.gd +++ b/scripts/terrain.gd @@ -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()