88 lines
2.3 KiB
C#
88 lines
2.3 KiB
C#
|
using Godot;
|
||
|
using System;
|
||
|
|
||
|
public class EditorUI : Control
|
||
|
{
|
||
|
// exported members
|
||
|
[Export] public NodePath World;
|
||
|
[Export] public NodePath StreamContainer;
|
||
|
|
||
|
// public members
|
||
|
public Vector2 currentTileOffset = Vector2.Zero;
|
||
|
|
||
|
// private members
|
||
|
private Button _resetButton;
|
||
|
private Button _grassButton;
|
||
|
private Button _sandButton;
|
||
|
private Button _waterButton;
|
||
|
|
||
|
private TileWorld _tileWorld;
|
||
|
private StreamContainer _streamContainer;
|
||
|
|
||
|
private enum TileType
|
||
|
{
|
||
|
None,
|
||
|
Grass,
|
||
|
Sand,
|
||
|
Water
|
||
|
}
|
||
|
private TileType _currentTileType = TileType.None;
|
||
|
|
||
|
// Called when the node enters the scene tree for the first time.
|
||
|
public override void _Ready()
|
||
|
{
|
||
|
_tileWorld = (TileWorld) GetNode(World);
|
||
|
_streamContainer = (StreamContainer)GetNode(StreamContainer);
|
||
|
|
||
|
// signals
|
||
|
_resetButton = (Button) FindNode("ResetButton");
|
||
|
_resetButton.Connect("pressed", this, nameof(OnResetButton));
|
||
|
|
||
|
_grassButton = (Button) FindNode("GrassButton");
|
||
|
_grassButton.Connect("pressed", this, nameof(OnGrassButton));
|
||
|
|
||
|
_sandButton = (Button) FindNode("SandButton");
|
||
|
_sandButton.Connect("pressed", this, nameof(OnSandButton));
|
||
|
|
||
|
_waterButton = (Button) FindNode("WaterButton");
|
||
|
_waterButton.Connect("pressed", this, nameof(OnWaterButton));
|
||
|
}
|
||
|
|
||
|
|
||
|
public void OnResetButton()
|
||
|
{
|
||
|
GD.Print("Resetting Map");
|
||
|
_tileWorld.Seed = _tileWorld.Seed + 1;
|
||
|
_tileWorld.Generate(12);
|
||
|
}
|
||
|
|
||
|
public void OnGrassButton()
|
||
|
{
|
||
|
_currentTileType = TileType.Grass;
|
||
|
}
|
||
|
|
||
|
public void OnSandButton()
|
||
|
{
|
||
|
_currentTileType = TileType.Sand;
|
||
|
|
||
|
}
|
||
|
|
||
|
public void OnWaterButton()
|
||
|
{
|
||
|
_currentTileType = TileType.Water;
|
||
|
}
|
||
|
|
||
|
public void OnTileClicked(Vector2 offsetCoord)
|
||
|
{
|
||
|
switch (_currentTileType)
|
||
|
{
|
||
|
case TileType.Grass:_tileWorld.SetTileColorAtOffset(currentTileOffset, Colors.Green);
|
||
|
break;
|
||
|
case TileType.Water:_tileWorld.SetTileColorAtOffset(currentTileOffset, Colors.Blue);
|
||
|
break;
|
||
|
case TileType.Sand:_tileWorld.SetTileColorAtOffset(currentTileOffset, Colors.Yellow);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|