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="UI/Mode Selection" method="EnableBuildMode"]
|
||||
[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="UI/Mode Selection" method="Enable"]
|
||||
[connection signal="BuildModeEnabled" from="UI/Mode Selection" to="Interaction Modes/Build Mode" method="Enable"]
|
||||
|
|
|
@ -5,5 +5,6 @@
|
|||
[resource]
|
||||
script = ExtResource( 1 )
|
||||
Name = "Developed"
|
||||
BuildLabel = "[D]eveloped"
|
||||
Key = 68
|
||||
Color = Color( 0.372549, 0.372549, 0.372549, 1 )
|
||||
|
|
|
@ -46,24 +46,6 @@ public class GridCursor : Sprite
|
|||
this.Position = position;
|
||||
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)
|
||||
|
|
|
@ -5,6 +5,9 @@ public class TileType : Resource
|
|||
[Export]
|
||||
public string Name { get; private set; }
|
||||
|
||||
[Export]
|
||||
public string BuildLabel { get; private set; }
|
||||
|
||||
[Export]
|
||||
public KeyList Key { get; private set; }
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@ using System;
|
|||
|
||||
public class BuildMode : Mode
|
||||
{
|
||||
[Signal]
|
||||
delegate void SelectedTileTypeChanged();
|
||||
|
||||
[Export]
|
||||
private NodePath _gridPath;
|
||||
private WorldGrid _grid;
|
||||
|
@ -33,6 +36,7 @@ public class BuildMode : Mode
|
|||
}
|
||||
|
||||
_selectedTileType = value;
|
||||
EmitSignal(nameof(SelectedTileTypeChanged), _selectedTileType);
|
||||
}
|
||||
}
|
||||
private TileType _selectedTileType = null;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class BuildModeUI : Control
|
||||
{
|
||||
|
@ -10,6 +11,9 @@ public class BuildModeUI : Control
|
|||
private NodePath _buildModePath;
|
||||
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.
|
||||
public override void _Ready()
|
||||
{
|
||||
|
@ -22,6 +26,15 @@ public class BuildModeUI : Control
|
|||
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)
|
||||
{
|
||||
const int MARGIN = 5;
|
||||
|
@ -29,8 +42,8 @@ public class BuildModeUI : Control
|
|||
var button = new Button();
|
||||
this.AddChild(button);
|
||||
|
||||
button.Text = tileType.Name;
|
||||
var parameters = new Godot.Collections.Array(tileType);
|
||||
button.Text = tileType.BuildLabel;
|
||||
var parameters = new Godot.Collections.Array(button, tileType);
|
||||
button.Connect("pressed", this, nameof(SelectTileType), parameters);
|
||||
|
||||
button.SetAnchorsPreset(LayoutPreset.BottomLeft);
|
||||
|
@ -39,13 +52,19 @@ public class BuildModeUI : Control
|
|||
var size = button.RectSize;
|
||||
button.RectSize = new Vector2(size.x, buttonHeight);
|
||||
|
||||
button.ToggleMode = true;
|
||||
|
||||
button.SetPosition(new Vector2(x, -buttonHeight));
|
||||
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()
|
||||
|
|
Loading…
Reference in New Issue