tile-types #15
|
@ -51,6 +51,7 @@ _buildModePath = NodePath("../../Interaction Modes/Build Mode")
|
||||||
[connection signal="OnModeEntered" from="Interaction Modes/Build Mode" to="Interaction Modes" method="_on_Build_Mode_OnModeEntered"]
|
[connection signal="OnModeEntered" from="Interaction Modes/Build Mode" to="Interaction Modes" method="_on_Build_Mode_OnModeEntered"]
|
||||||
[connection signal="OnModeEntered" from="Interaction Modes/Build Mode" to="UI/Mode Selection" method="EnableBuildMode"]
|
[connection signal="OnModeEntered" from="Interaction Modes/Build Mode" to="UI/Mode Selection" method="EnableBuildMode"]
|
||||||
[connection signal="OnModeExited" from="Interaction Modes/Build Mode" to="Interaction Modes" method="_on_Build_Mode_OnModeExited"]
|
[connection signal="OnModeExited" from="Interaction Modes/Build Mode" to="Interaction Modes" method="_on_Build_Mode_OnModeExited"]
|
||||||
|
[connection signal="SelectedTileTypeChanged" from="Interaction Modes/Build Mode" to="UI/Build Mode" method="UpdateButtonToggleState"]
|
||||||
[connection signal="OnExit" from="UI/Build Mode" to="Interaction Modes" method="Reset"]
|
[connection signal="OnExit" from="UI/Build Mode" to="Interaction Modes" method="Reset"]
|
||||||
[connection signal="OnExit" from="UI/Build Mode" to="UI/Mode Selection" method="Enable"]
|
[connection signal="OnExit" from="UI/Build Mode" to="UI/Mode Selection" method="Enable"]
|
||||||
[connection signal="BuildModeEnabled" from="UI/Mode Selection" to="Interaction Modes/Build Mode" method="Enable"]
|
[connection signal="BuildModeEnabled" from="UI/Mode Selection" to="Interaction Modes/Build Mode" method="Enable"]
|
||||||
|
|
|
@ -5,5 +5,6 @@
|
||||||
[resource]
|
[resource]
|
||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
Name = "Developed"
|
Name = "Developed"
|
||||||
|
BuildLabel = "[D]eveloped"
|
||||||
Key = 68
|
Key = 68
|
||||||
Color = Color( 0.372549, 0.372549, 0.372549, 1 )
|
Color = Color( 0.372549, 0.372549, 0.372549, 1 )
|
||||||
|
|
|
@ -46,24 +46,6 @@ public class GridCursor : Sprite
|
||||||
this.Position = position;
|
this.Position = position;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (@event is InputEventMouseButton mouseButtonEvent)
|
|
||||||
//{
|
|
||||||
// var button = (ButtonList)mouseButtonEvent.ButtonIndex;
|
|
||||||
// if (button != ButtonList.Left)
|
|
||||||
// return;
|
|
||||||
|
|
||||||
// if (!mouseButtonEvent.Pressed)
|
|
||||||
// {
|
|
||||||
// _material.SetShaderParam(T, 0f);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// var pos = mouseButtonEvent.Position;
|
|
||||||
// _grid.GetGridPos(pos, out var x, out var y);
|
|
||||||
// _grid.SetTileValue(x, y, 1.0f);
|
|
||||||
// _material.SetShaderParam(T, 1f);
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _Process(float delta)
|
public override void _Process(float delta)
|
||||||
|
|
|
@ -5,6 +5,9 @@ public class TileType : Resource
|
||||||
[Export]
|
[Export]
|
||||||
public string Name { get; private set; }
|
public string Name { get; private set; }
|
||||||
|
|
||||||
|
[Export]
|
||||||
|
public string BuildLabel { get; private set; }
|
||||||
|
|
||||||
[Export]
|
[Export]
|
||||||
public KeyList Key { get; private set; }
|
public KeyList Key { get; private set; }
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,9 @@ using System;
|
||||||
|
|
||||||
public class BuildMode : Mode
|
public class BuildMode : Mode
|
||||||
{
|
{
|
||||||
|
[Signal]
|
||||||
|
delegate void SelectedTileTypeChanged();
|
||||||
|
|
||||||
[Export]
|
[Export]
|
||||||
private NodePath _gridPath;
|
private NodePath _gridPath;
|
||||||
private WorldGrid _grid;
|
private WorldGrid _grid;
|
||||||
|
@ -33,6 +36,7 @@ public class BuildMode : Mode
|
||||||
}
|
}
|
||||||
|
|
||||||
_selectedTileType = value;
|
_selectedTileType = value;
|
||||||
|
EmitSignal(nameof(SelectedTileTypeChanged), _selectedTileType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private TileType _selectedTileType = null;
|
private TileType _selectedTileType = null;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using Godot;
|
using Godot;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
public class BuildModeUI : Control
|
public class BuildModeUI : Control
|
||||||
{
|
{
|
||||||
|
@ -10,6 +11,9 @@ public class BuildModeUI : Control
|
||||||
private NodePath _buildModePath;
|
private NodePath _buildModePath;
|
||||||
private BuildMode _buildMode;
|
private BuildMode _buildMode;
|
||||||
|
|
||||||
|
private readonly Dictionary<TileType, Button> _typeButtons
|
||||||
|
= new Dictionary<TileType, Button>();
|
||||||
|
|
||||||
// Called when the node enters the scene tree for the first time.
|
// Called when the node enters the scene tree for the first time.
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
|
@ -22,6 +26,15 @@ public class BuildModeUI : Control
|
||||||
SpawnButton(tileType, buttonHeight, ref x);
|
SpawnButton(tileType, buttonHeight, ref x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateButtonToggleState(TileType tileType)
|
||||||
|
{
|
||||||
|
foreach (var kvp in _typeButtons)
|
||||||
|
{
|
||||||
|
var button = _typeButtons[kvp.Key];
|
||||||
|
button.SetPressedNoSignal(kvp.Key == tileType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void SpawnButton(TileType tileType, int buttonHeight, ref int x)
|
private void SpawnButton(TileType tileType, int buttonHeight, ref int x)
|
||||||
{
|
{
|
||||||
const int MARGIN = 5;
|
const int MARGIN = 5;
|
||||||
|
@ -29,8 +42,8 @@ public class BuildModeUI : Control
|
||||||
var button = new Button();
|
var button = new Button();
|
||||||
this.AddChild(button);
|
this.AddChild(button);
|
||||||
|
|
||||||
button.Text = tileType.Name;
|
button.Text = tileType.BuildLabel;
|
||||||
var parameters = new Godot.Collections.Array(tileType);
|
var parameters = new Godot.Collections.Array(button, tileType);
|
||||||
button.Connect("pressed", this, nameof(SelectTileType), parameters);
|
button.Connect("pressed", this, nameof(SelectTileType), parameters);
|
||||||
|
|
||||||
button.SetAnchorsPreset(LayoutPreset.BottomLeft);
|
button.SetAnchorsPreset(LayoutPreset.BottomLeft);
|
||||||
|
@ -39,13 +52,19 @@ public class BuildModeUI : Control
|
||||||
var size = button.RectSize;
|
var size = button.RectSize;
|
||||||
button.RectSize = new Vector2(size.x, buttonHeight);
|
button.RectSize = new Vector2(size.x, buttonHeight);
|
||||||
|
|
||||||
|
button.ToggleMode = true;
|
||||||
|
|
||||||
button.SetPosition(new Vector2(x, -buttonHeight));
|
button.SetPosition(new Vector2(x, -buttonHeight));
|
||||||
x += Mathf.RoundToInt(size.x) + MARGIN;
|
x += Mathf.RoundToInt(size.x) + MARGIN;
|
||||||
|
|
||||||
|
_typeButtons[tileType] = button;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SelectTileType(TileType tileType)
|
private void SelectTileType(Button button, TileType tileType)
|
||||||
{
|
{
|
||||||
_buildMode.SelectedTileType = tileType;
|
_buildMode.SelectedTileType = button.Pressed
|
||||||
|
? tileType
|
||||||
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Exit()
|
public void Exit()
|
||||||
|
|
Loading…
Reference in New Issue