change to build mode with keyboard shortcuts #5
This commit is contained in:
parent
4650a5b7f3
commit
e988d9b38e
13
gdd.md
13
gdd.md
|
@ -8,6 +8,19 @@
|
||||||
* Education
|
* Education
|
||||||
* Supply chains
|
* Supply chains
|
||||||
|
|
||||||
|
## Interaction Modes
|
||||||
|
|
||||||
|
Interaction modes can be changed via keyboard shortcut.
|
||||||
|
|
||||||
|
### Selection Mode
|
||||||
|
|
||||||
|
This is the default interaction mode.
|
||||||
|
It can be accessed at any time by pressing the `esc` key.
|
||||||
|
|
||||||
|
### Build Mode
|
||||||
|
|
||||||
|
Build mode can be entered by pressing the `b` key.
|
||||||
|
|
||||||
## Critical Path
|
## Critical Path
|
||||||
|
|
||||||
### Grid
|
### Grid
|
||||||
|
|
|
@ -8,6 +8,22 @@ anchor_bottom = 1.0
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
TicksLabelPath = NodePath("Ticks")
|
TicksLabelPath = NodePath("Ticks")
|
||||||
PauseLabelPath = NodePath("Paused")
|
PauseLabelPath = NodePath("Paused")
|
||||||
|
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
|
||||||
|
grow_horizontal = 0
|
||||||
|
grow_vertical = 0
|
||||||
|
text = "mode: SELECT"
|
||||||
|
align = 2
|
||||||
|
valign = 2
|
||||||
|
|
||||||
[node name="Ticks" type="Label" parent="."]
|
[node name="Ticks" type="Label" parent="."]
|
||||||
anchor_left = 1.0
|
anchor_left = 1.0
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
[gd_scene load_steps=5 format=2]
|
[gd_scene load_steps=6 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://nodes/grid.tscn" type="PackedScene" id=1]
|
[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/grid_cursor.tscn" type="PackedScene" id=2]
|
||||||
[ext_resource path="res://nodes/debug_ui.tscn" type="PackedScene" id=3]
|
[ext_resource path="res://nodes/debug_ui.tscn" type="PackedScene" id=3]
|
||||||
[ext_resource path="res://nodes/clock.tscn" type="PackedScene" id=4]
|
[ext_resource path="res://nodes/clock.tscn" type="PackedScene" id=4]
|
||||||
|
[ext_resource path="res://nodes/interaction_mode.tscn" type="PackedScene" id=5]
|
||||||
|
|
||||||
[node name="Root" type="Node"]
|
[node name="Root" type="Node"]
|
||||||
|
|
||||||
|
@ -18,6 +19,9 @@ Grid = NodePath("../Grid")
|
||||||
[node name="Clock" parent="." instance=ExtResource( 4 )]
|
[node name="Clock" parent="." instance=ExtResource( 4 )]
|
||||||
_autoTick = true
|
_autoTick = true
|
||||||
|
|
||||||
|
[node name="Interaction Mode" parent="." instance=ExtResource( 5 )]
|
||||||
|
|
||||||
[connection signal="OnPauseChanged" from="Clock" to="Debug UI" method="_on_Clock_OnPauseChanged"]
|
[connection signal="OnPauseChanged" from="Clock" to="Debug UI" method="_on_Clock_OnPauseChanged"]
|
||||||
[connection signal="OnTick" from="Clock" to="Grid" method="_on_Clock_OnTick"]
|
[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="OnTick" from="Clock" to="Debug UI" method="_on_Clock_OnTick"]
|
||||||
|
[connection signal="OnInteractionModeChanged" from="Interaction Mode" to="Debug UI" method="_on_Interaction_Mode_OnInteractionModeChanged"]
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
[gd_scene load_steps=2 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://scripts/InteractionMode.cs" type="Script" id=1]
|
||||||
|
|
||||||
|
[node name="Interaction Mode" type="Node"]
|
||||||
|
script = ExtResource( 1 )
|
||||||
|
_buildMode = 66
|
|
@ -11,27 +11,29 @@ public class DebugUI : Control
|
||||||
public NodePath PauseLabelPath { private get; set; }
|
public NodePath PauseLabelPath { private get; set; }
|
||||||
private Label _pauseLabel;
|
private Label _pauseLabel;
|
||||||
|
|
||||||
|
[Export]
|
||||||
|
public NodePath InteractionModeLabelPath { private get; set; }
|
||||||
|
private Label _interactionModeLabel;
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_ticksLabel = GetNode<Label>(TicksLabelPath);
|
_ticksLabel = GetNode<Label>(TicksLabelPath);
|
||||||
_pauseLabel = GetNode<Label>(PauseLabelPath);
|
_pauseLabel = GetNode<Label>(PauseLabelPath);
|
||||||
|
_interactionModeLabel = GetNode<Label>(InteractionModeLabelPath);
|
||||||
SetTicksText(0);
|
|
||||||
SetPauseText(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Signals
|
#region Signals
|
||||||
public void _on_Clock_OnPauseChanged(bool paused) => SetPauseText(paused);
|
public void _on_Clock_OnPauseChanged(bool paused) =>
|
||||||
public void _on_Clock_OnTick(int ticks) => SetTicksText(ticks);
|
SetLabelText(_pauseLabel, "pause", paused);
|
||||||
|
|
||||||
|
public void _on_Clock_OnTick(int ticks) =>
|
||||||
|
SetLabelText(_ticksLabel, "ticks", ticks);
|
||||||
|
|
||||||
|
public void _on_Interaction_Mode_OnInteractionModeChanged(InteractionMode.Mode oldMode, InteractionMode.Mode newMode) =>
|
||||||
|
SetLabelText(_interactionModeLabel, "mode", newMode);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private void SetTicksText(int ticks)
|
private void SetLabelText(Label label, string key, object value)
|
||||||
{
|
{
|
||||||
_ticksLabel.Text = $"ticks: {ticks}";
|
label.Text = $"{key}: {value}";
|
||||||
}
|
|
||||||
|
|
||||||
private void SetPauseText(bool paused)
|
|
||||||
{
|
|
||||||
_pauseLabel.Text = $"pause: {paused}";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
using Godot;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
public class InteractionMode : Node
|
||||||
|
{
|
||||||
|
[Export]
|
||||||
|
private KeyList _buildMode;
|
||||||
|
|
||||||
|
[Signal]
|
||||||
|
delegate void OnInteractionModeChanged(Mode oldMode, Mode newMode);
|
||||||
|
|
||||||
|
public enum Mode
|
||||||
|
{
|
||||||
|
SELECT = 0,
|
||||||
|
BUILD = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
public Mode Current
|
||||||
|
{
|
||||||
|
get => _current;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (_current == value)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var old = _current;
|
||||||
|
_current = value;
|
||||||
|
|
||||||
|
EmitSignal(nameof(OnInteractionModeChanged), old, _current);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private Mode _current = Mode.SELECT;
|
||||||
|
|
||||||
|
public override void _Input(InputEvent @event)
|
||||||
|
{
|
||||||
|
base._Input(@event);
|
||||||
|
|
||||||
|
if (!(@event is InputEventKey keyEvent))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!keyEvent.Pressed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var key = (KeyList)keyEvent.Scancode;
|
||||||
|
|
||||||
|
// TODO: this should be developed into a UI stack
|
||||||
|
if (key == KeyList.Escape)
|
||||||
|
{
|
||||||
|
Current = Mode.SELECT;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key == _buildMode)
|
||||||
|
{
|
||||||
|
Current = Mode.BUILD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue