From 5f8052f0a346555b2ec5870d367856d3f7a379ca Mon Sep 17 00:00:00 2001 From: Zacharie Guet Date: Sat, 31 Aug 2024 17:13:07 +0200 Subject: [PATCH] Setup basic GUI and scanner selection --- .gitignore | 1 + Game.tscn | 17 ++++---- assets/gradients/Fertility.tres | 8 ++++ objects/gui/Scanner_modes.tscn | 29 +++++++++++++ objects/gui/Seed_card.tscn | 69 +++++++++++++++++++++++++++++++ objects/gui/Seed_queue.tscn | 72 +++++++++++++++++++++++++++++++++ scenes/Gui.tscn | 38 +++++++++++++++++ {objects => scenes}/Map.tscn | 0 scenes/Scanners.tscn | 34 ++++++++++------ scripts/gui.gd | 7 ++++ scripts/gui/scanner_modes.gd | 14 +++++++ scripts/map.gd | 4 ++ scripts/scanners.gd | 23 +++++++---- 13 files changed, 288 insertions(+), 28 deletions(-) create mode 100644 assets/gradients/Fertility.tres create mode 100644 objects/gui/Scanner_modes.tscn create mode 100644 objects/gui/Seed_card.tscn create mode 100644 objects/gui/Seed_queue.tscn create mode 100644 scenes/Gui.tscn rename {objects => scenes}/Map.tscn (100%) create mode 100644 scripts/gui.gd create mode 100644 scripts/gui/scanner_modes.gd diff --git a/.gitignore b/.gitignore index 0af181c..3a8346a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ # Godot 4+ specific ignores .godot/ /android/ +addons/ \ No newline at end of file diff --git a/Game.tscn b/Game.tscn index 16c8cbc..c410b87 100644 --- a/Game.tscn +++ b/Game.tscn @@ -1,15 +1,14 @@ [gd_scene load_steps=3 format=3 uid="uid://d3srnfkpx01we"] -[sub_resource type="Gradient" id="Gradient_vr3vq"] -colors = PackedColorArray(1, 1, 1, 1, 1, 1, 1, 1) - -[sub_resource type="GradientTexture1D" id="GradientTexture1D_8n51p"] -gradient = SubResource("Gradient_vr3vq") +[ext_resource type="PackedScene" uid="uid://d3hul8b7hlmj7" path="res://scenes/Map.tscn" id="1_nnb57"] +[ext_resource type="PackedScene" uid="uid://dha8pa1les53a" path="res://scenes/Gui.tscn" id="2_d5c8m"] [node name="Game" type="Node2D"] -[node name="Souris" type="Node2D" parent="."] +[node name="Map" parent="." instance=ExtResource("1_nnb57")] -[node name="Sprite2D" type="Sprite2D" parent="Souris"] -scale = Vector2(0.0859375, 23) -texture = SubResource("GradientTexture1D_8n51p") +[node name="Interface" type="CanvasLayer" parent="."] + +[node name="Gui" parent="Interface" instance=ExtResource("2_d5c8m")] + +[connection signal="scanner_selected" from="Interface/Gui" to="Map" method="_on_gui_scanner_selected"] diff --git a/assets/gradients/Fertility.tres b/assets/gradients/Fertility.tres new file mode 100644 index 0000000..dba5fca --- /dev/null +++ b/assets/gradients/Fertility.tres @@ -0,0 +1,8 @@ +[gd_resource type="GradientTexture1D" load_steps=2 format=3 uid="uid://be2uusaqcpcpd"] + +[sub_resource type="Gradient" id="Gradient_pafyk"] +offsets = PackedFloat32Array(0, 0.22549, 0.51634, 0.813725, 1) +colors = PackedColorArray(0.66677, 0.166288, 0, 1, 0.41, 0.328, 0, 1, 0.0321677, 2.76752e-07, 0.262162, 1, 0, 0.592306, 0, 1, 0, 0.964706, 0.580392, 1) + +[resource] +gradient = SubResource("Gradient_pafyk") diff --git a/objects/gui/Scanner_modes.tscn b/objects/gui/Scanner_modes.tscn new file mode 100644 index 0000000..efde36b --- /dev/null +++ b/objects/gui/Scanner_modes.tscn @@ -0,0 +1,29 @@ +[gd_scene load_steps=2 format=3 uid="uid://0so4tpnkk8t2"] + +[ext_resource type="Script" path="res://scripts/gui/scanner_modes.gd" id="1_synac"] + +[node name="ScannerModes" type="Control"] +layout_mode = 3 +anchors_preset = 0 +size_flags_horizontal = 4 +size_flags_vertical = 0 +script = ExtResource("1_synac") + +[node name="Scanner Select" type="OptionButton" parent="."] +layout_mode = 1 +anchors_preset = 5 +anchor_left = 0.5 +anchor_right = 0.5 +offset_left = -60.5 +offset_right = 60.5 +offset_bottom = 40.0 +grow_horizontal = 2 +selected = 0 +item_count = 3 +popup/item_0/text = "No Scanner" +popup/item_1/text = "Water" +popup/item_1/id = 1 +popup/item_2/text = "Fertility" +popup/item_2/id = 2 + +[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 new file mode 100644 index 0000000..ddaf302 --- /dev/null +++ b/objects/gui/Seed_card.tscn @@ -0,0 +1,69 @@ +[gd_scene load_steps=4 format=3 uid="uid://iaf4md4cbwqh"] + +[sub_resource type="Gradient" id="Gradient_lissx"] +offsets = PackedFloat32Array(1) +colors = PackedColorArray(0.125911, 0.125911, 0.125911, 1) + +[sub_resource type="GradientTexture1D" id="GradientTexture1D_aglhv"] +gradient = SubResource("Gradient_lissx") + +[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_kiud1"] + +[node name="SeedCard" type="Control"] +layout_mode = 3 +anchors_preset = 0 +size_flags_horizontal = 8 +size_flags_vertical = 8 + +[node name="Card" type="PanelContainer" parent="."] +layout_mode = 1 +anchors_preset = 3 +anchor_left = 1.0 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = -100.0 +offset_top = -181.0 +grow_horizontal = 0 +grow_vertical = 0 + +[node name="TextureRect" type="TextureRect" parent="Card"] +layout_mode = 2 +texture = SubResource("GradientTexture1D_aglhv") +expand_mode = 1 + +[node name="MarginContainer" type="MarginContainer" parent="Card"] +layout_mode = 2 +theme_override_constants/margin_left = 10 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_right = 10 +theme_override_constants/margin_bottom = 10 + +[node name="VBoxContainer" type="VBoxContainer" parent="Card/MarginContainer"] +layout_mode = 2 + +[node name="Nom" type="Label" parent="Card/MarginContainer/VBoxContainer"] +layout_mode = 2 +text = "Chène" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="Image" type="TextureRect" parent="Card/MarginContainer/VBoxContainer"] +custom_minimum_size = Vector2(0, 80) +layout_mode = 2 +texture = SubResource("NoiseTexture2D_kiud1") +expand_mode = 3 +stretch_mode = 5 + +[node name="Besoins" type="Label" parent="Card/MarginContainer/VBoxContainer"] +layout_mode = 2 +text = "Besoins" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="Apports" type="Label" parent="Card/MarginContainer/VBoxContainer"] +layout_mode = 2 +text = "Apports +" +horizontal_alignment = 1 +vertical_alignment = 1 diff --git a/objects/gui/Seed_queue.tscn b/objects/gui/Seed_queue.tscn new file mode 100644 index 0000000..7673912 --- /dev/null +++ b/objects/gui/Seed_queue.tscn @@ -0,0 +1,72 @@ +[gd_scene load_steps=2 format=3 uid="uid://bm8nlb7kmaa6k"] + +[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_reedq"] + +[node name="SeedQueue" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="HBoxContainer" type="HBoxContainer" parent="."] +layout_mode = 1 +anchors_preset = 12 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 0 +theme_override_constants/separation = 10 + +[node name="NextSeed" type="TextureRect" parent="HBoxContainer"] +custom_minimum_size = Vector2(80, 80) +layout_mode = 2 +texture = SubResource("NoiseTexture2D_reedq") +expand_mode = 2 + +[node name="Queue" type="HBoxContainer" parent="HBoxContainer"] +layout_mode = 2 +theme_override_constants/separation = 10 +alignment = 2 + +[node name="Seed1" type="TextureRect" parent="HBoxContainer/Queue"] +custom_minimum_size = Vector2(40, 40) +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 8 +texture = SubResource("NoiseTexture2D_reedq") +expand_mode = 2 + +[node name="Seed2" type="TextureRect" parent="HBoxContainer/Queue"] +custom_minimum_size = Vector2(40, 40) +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 8 +texture = SubResource("NoiseTexture2D_reedq") +expand_mode = 2 + +[node name="Seed3" type="TextureRect" parent="HBoxContainer/Queue"] +custom_minimum_size = Vector2(40, 40) +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 8 +texture = SubResource("NoiseTexture2D_reedq") +expand_mode = 2 + +[node name="Seed4" type="TextureRect" parent="HBoxContainer/Queue"] +custom_minimum_size = Vector2(40, 40) +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 8 +texture = SubResource("NoiseTexture2D_reedq") +expand_mode = 2 + +[node name="Seed5" type="TextureRect" parent="HBoxContainer/Queue"] +custom_minimum_size = Vector2(40, 40) +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 8 +texture = SubResource("NoiseTexture2D_reedq") +expand_mode = 2 diff --git a/scenes/Gui.tscn b/scenes/Gui.tscn new file mode 100644 index 0000000..23c6e81 --- /dev/null +++ b/scenes/Gui.tscn @@ -0,0 +1,38 @@ +[gd_scene load_steps=5 format=3 uid="uid://dha8pa1les53a"] + +[ext_resource type="Script" path="res://scripts/gui.gd" id="1_6gq27"] +[ext_resource type="PackedScene" uid="uid://bm8nlb7kmaa6k" path="res://objects/gui/Seed_queue.tscn" id="1_lh8u1"] +[ext_resource type="PackedScene" uid="uid://iaf4md4cbwqh" path="res://objects/gui/Seed_card.tscn" id="2_bt3vo"] +[ext_resource type="PackedScene" uid="uid://0so4tpnkk8t2" path="res://objects/gui/Scanner_modes.tscn" id="3_bsm7r"] + +[node name="Gui" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_6gq27") + +[node name="MarginContainer" type="MarginContainer" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_constants/margin_left = 20 +theme_override_constants/margin_top = 20 +theme_override_constants/margin_right = 20 +theme_override_constants/margin_bottom = 20 + +[node name="SeedQueue" parent="MarginContainer" instance=ExtResource("1_lh8u1")] +layout_mode = 2 + +[node name="SeedCard" parent="MarginContainer" instance=ExtResource("2_bt3vo")] +layout_mode = 2 + +[node name="ScannerModes" parent="MarginContainer" instance=ExtResource("3_bsm7r")] +layout_mode = 2 + +[connection signal="scanner_selected" from="MarginContainer/ScannerModes" to="." method="_on_scanner_modes_scanner_selected"] diff --git a/objects/Map.tscn b/scenes/Map.tscn similarity index 100% rename from objects/Map.tscn rename to scenes/Map.tscn diff --git a/scenes/Scanners.tscn b/scenes/Scanners.tscn index 05966a5..b356ee4 100644 --- a/scenes/Scanners.tscn +++ b/scenes/Scanners.tscn @@ -1,19 +1,18 @@ -[gd_scene load_steps=8 format=3 uid="uid://6ferubyu2uy1"] +[gd_scene load_steps=9 format=3 uid="uid://6ferubyu2uy1"] [ext_resource type="Script" path="res://scripts/scanners.gd" id="1_orxwo"] [ext_resource type="Shader" path="res://scripts/shaders/Scanner.gdshader" id="2_8t6wf"] +[ext_resource type="Texture2D" uid="uid://be2uusaqcpcpd" path="res://assets/gradients/Fertility.tres" id="3_bt6q7"] -[sub_resource type="Gradient" id="Gradient_pafyk"] -offsets = PackedFloat32Array(0, 0.22549, 0.51634, 0.813725, 1) -colors = PackedColorArray(0.66677, 0.166288, 0, 1, 0.41, 0.328, 0, 1, 0, 0, 0, 1, 0, 0.592306, 0, 1, 0, 0.964706, 0.580392, 1) - -[sub_resource type="GradientTexture1D" id="GradientTexture1D_mpkd3"] -gradient = SubResource("Gradient_pafyk") - -[sub_resource type="ShaderMaterial" id="ShaderMaterial_yl6st"] +[sub_resource type="ShaderMaterial" id="ShaderMaterial_05bn7"] shader = ExtResource("2_8t6wf") shader_parameter/dimension = 1 -shader_parameter/gradient = SubResource("GradientTexture1D_mpkd3") +shader_parameter/gradient = ExtResource("3_bt6q7") + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_lpu5x"] +shader = ExtResource("2_8t6wf") +shader_parameter/dimension = 0 +shader_parameter/gradient = ExtResource("3_bt6q7") [sub_resource type="Gradient" id="Gradient_sc8ss"] interpolation_mode = 1 @@ -25,6 +24,11 @@ gradient = SubResource("Gradient_sc8ss") fill_from = Vector2(0, 1) fill_to = Vector2(1, 1) +[sub_resource type="ShaderMaterial" id="ShaderMaterial_0lkln"] +shader = ExtResource("2_8t6wf") +shader_parameter/dimension = 2 +shader_parameter/gradient = ExtResource("3_bt6q7") + [node name="Scanners" type="Node2D"] script = ExtResource("1_orxwo") @@ -34,11 +38,17 @@ centered = false [node name="Fertility" type="Sprite2D" parent="."] visible = false -material = SubResource("ShaderMaterial_yl6st") +material = SubResource("ShaderMaterial_05bn7") centered = false [node name="Water" type="Sprite2D" parent="."] visible = false -material = SubResource("ShaderMaterial_yl6st") +material = SubResource("ShaderMaterial_lpu5x") +texture = SubResource("GradientTexture2D_a7oi7") +centered = false + +[node name="Presence" type="Sprite2D" parent="."] +visible = false +material = SubResource("ShaderMaterial_0lkln") texture = SubResource("GradientTexture2D_a7oi7") centered = false diff --git a/scripts/gui.gd b/scripts/gui.gd new file mode 100644 index 0000000..756cf9f --- /dev/null +++ b/scripts/gui.gd @@ -0,0 +1,7 @@ +class_name Gui +extends Control + +signal scanner_selected + +func _on_scanner_modes_scanner_selected(type : Scanners.Type): + emit_signal("scanner_selected", type) diff --git a/scripts/gui/scanner_modes.gd b/scripts/gui/scanner_modes.gd new file mode 100644 index 0000000..fb5fdb2 --- /dev/null +++ b/scripts/gui/scanner_modes.gd @@ -0,0 +1,14 @@ +extends Control + +signal scanner_selected + +func _on_scanner_select_item_selected(index): + var scannerType : Scanners.Type + + match index: + 0: scannerType = Scanners.Type.NoScanner + 1: scannerType = Scanners.Type.Water + 2: scannerType = Scanners.Type.Fertility + 3: scannerType = Scanners.Type.Presence + + emit_signal("scanner_selected", scannerType) diff --git a/scripts/map.gd b/scripts/map.gd index 3fbebfb..1ac992b 100644 --- a/scripts/map.gd +++ b/scripts/map.gd @@ -1,2 +1,6 @@ class_name Map extends Node2D + + +func _on_gui_scanner_selected(type : Scanners.Type): + $Scanners.select_scanner(type) diff --git a/scripts/scanners.gd b/scripts/scanners.gd index 8a8bbf9..6e696ee 100644 --- a/scripts/scanners.gd +++ b/scripts/scanners.gd @@ -1,11 +1,20 @@ class_name Scanners extends Node2D -func _ready(): - for sprite in [$Water, $Fertility, $Data]: - sprite.texture = GameTerrain.get_texture() - sprite.scale = Vector2(GameTerrain.MAP_RATIO,GameTerrain.MAP_RATIO,) +enum Type {NoScanner, Water, Fertility, Presence, Combined} -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _process(delta): - pass +func _ready(): + for sprite in [$Water, $Fertility, $Presence, $Data]: + sprite.texture = GameTerrain.get_texture() + sprite.scale = Vector2(GameTerrain.MAP_RATIO,GameTerrain.MAP_RATIO) + sprite.visible = false + +func select_scanner(type: Type): + for sprite in [$Water, $Fertility, $Presence, $Data]: + sprite.visible = false + + match type: + Type.Water: $Water.visible = true + Type.Fertility: $Fertility.visible = true + Type.Presence: $Presence.visible = true + Type.Combined: $Data.visible = true -- 2.45.2