enter and exit build mode ui #5

This commit is contained in:
Cat Flynn 2022-12-08 20:53:49 +00:00
parent e988d9b38e
commit 511ed61eda
7 changed files with 141 additions and 25 deletions

View File

@ -1,10 +1,11 @@
[gd_scene load_steps=6 format=2]
[gd_scene load_steps=7 format=2]
[ext_resource path="res://nodes/grid.tscn" type="PackedScene" id=1]
[ext_resource path="res://nodes/grid_cursor.tscn" type="PackedScene" id=2]
[ext_resource path="res://nodes/debug_ui.tscn" type="PackedScene" id=3]
[ext_resource path="res://nodes/ui/debug_ui.tscn" type="PackedScene" id=3]
[ext_resource path="res://nodes/clock.tscn" type="PackedScene" id=4]
[ext_resource path="res://nodes/interaction_mode.tscn" type="PackedScene" id=5]
[ext_resource path="res://nodes/ui/build_mode_ui.tscn" type="PackedScene" id=6]
[node name="Root" type="Node"]
@ -14,14 +15,22 @@ DiffusionCoefficient = 0.1
[node name="Cursor" parent="." instance=ExtResource( 2 )]
Grid = NodePath("../Grid")
[node name="Debug UI" parent="." instance=ExtResource( 3 )]
[node name="Clock" parent="." instance=ExtResource( 4 )]
_autoTick = true
[node name="Interaction Mode" parent="." instance=ExtResource( 5 )]
[connection signal="OnPauseChanged" from="Clock" to="Debug UI" method="_on_Clock_OnPauseChanged"]
[node name="UI" type="Control" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
[node name="Debug" parent="UI" instance=ExtResource( 3 )]
[node name="Build Mode" parent="UI" instance=ExtResource( 6 )]
[connection signal="OnPauseChanged" from="Clock" to="UI/Debug" method="_on_Clock_OnPauseChanged"]
[connection signal="OnTick" from="Clock" to="Grid" method="_on_Clock_OnTick"]
[connection signal="OnTick" from="Clock" to="Debug UI" method="_on_Clock_OnTick"]
[connection signal="OnInteractionModeChanged" from="Interaction Mode" to="Debug UI" method="_on_Interaction_Mode_OnInteractionModeChanged"]
[connection signal="OnTick" from="Clock" to="UI/Debug" method="_on_Clock_OnTick"]
[connection signal="OnInteractionModeChanged" from="Interaction Mode" to="UI/Debug" method="_on_Interaction_Mode_OnInteractionModeChanged"]
[connection signal="OnInteractionModeChanged" from="Interaction Mode" to="UI/Build Mode" method="_on_Interaction_Mode_OnInteractionModeChanged"]
[connection signal="OnExit" from="UI/Build Mode" to="Interaction Mode" method="Reset"]

View File

@ -0,0 +1,45 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://scripts/ui/BuildModeUI.cs" type="Script" id=1]
[node name="Build Mode" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 1 )
[node name="ColorRect" type="ColorRect" parent="."]
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
margin_top = -40.0
grow_horizontal = 0
grow_vertical = 0
[node name="Exit" type="Button" parent="ColorRect"]
margin_left = 2.0
margin_top = 2.0
margin_right = 38.0
margin_bottom = 38.0
[node name="Label" type="Label" parent="ColorRect/Exit"]
anchor_right = 1.0
anchor_bottom = 1.0
text = "exit"
align = 1
valign = 1
[node name="Exit2" type="Button" parent="ColorRect"]
margin_left = 54.0
margin_top = 2.0
margin_right = 90.0
margin_bottom = 38.0
[node name="Label" type="Label" parent="ColorRect/Exit2"]
anchor_right = 1.0
anchor_bottom = 1.0
text = "developed"
align = 1
valign = 1
autowrap = true
[connection signal="pressed" from="ColorRect/Exit" to="." method="_on_Exit_pressed"]

View File

@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://scripts/DebugUI.cs" type="Script" id=1]
[ext_resource path="res://scripts/ui/DebugUI.cs" type="Script" id=1]
[node name="Debug UI" type="Control"]
anchor_right = 1.0
@ -12,41 +12,36 @@ InteractionModeLabelPath = NodePath("Interaction Mode")
[node name="Interaction Mode" type="Label" parent="."]
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = -94.0
margin_top = -64.0
margin_right = -10.0
margin_bottom = -50.0
margin_left = -102.0
margin_top = 15.0
margin_right = -14.0
margin_bottom = 29.0
grow_horizontal = 0
grow_vertical = 0
text = "mode: SELECT"
align = 2
valign = 2
[node name="Ticks" type="Label" parent="."]
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
margin_right = -10.0
margin_bottom = -30.0
margin_left = -60.0
margin_top = 35.0
margin_right = -14.0
margin_bottom = 49.0
grow_horizontal = 0
grow_vertical = 0
text = "ticks: 0"
align = 2
valign = 2
[node name="Paused" type="Label" parent="."]
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
margin_right = -10.0
margin_bottom = -10.0
margin_left = -90.0
margin_top = 55.0
margin_right = -14.0
margin_bottom = 69.0
grow_horizontal = 0
grow_vertical = 0
text = "pause: false"
align = 2
valign = 2

View File

@ -15,6 +15,11 @@ public class InteractionMode : Node
BUILD = 1
}
public void Reset()
{
Current = Mode.SELECT;
}
public Mode Current
{
get => _current;

View File

@ -54,6 +54,9 @@ public class WorldGrid : Node2D
public void SetTileValue(int x, int y, float value)
{
if (!IsInBounds(x, y))
return;
_tiles[x, y].value = value;
}

View File

@ -0,0 +1,59 @@
using Godot;
using System;
public class BuildModeUI : Control
{
[Signal]
delegate void OnExit();
// Declare member variables here. Examples:
// private int a = 2;
// private string b = "text";
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
Visible = false;
}
public void _on_Exit_pressed()
{
Exit();
}
public void _on_Interaction_Mode_OnInteractionModeChanged(InteractionMode.Mode oldMode, InteractionMode.Mode newMode)
{
if (oldMode == InteractionMode.Mode.BUILD)
{
Visible = false;
return;
}
if (newMode == InteractionMode.Mode.BUILD)
{
Visible = true;
return;
}
}
private void Exit()
{
EmitSignal(nameof(OnExit));
}
public override void _Input(InputEvent @event)
{
if (!Visible)
return;
if (!(@event is InputEventKey keyEvent))
return;
if (keyEvent.Pressed)
return;
if ((KeyList)keyEvent.Scancode == KeyList.Escape)
{
Exit();
}
}
}