2023-07-09 00:16:37 +02:00
|
|
|
using Godot;
|
|
|
|
|
|
|
|
public class EditorUI : Control
|
|
|
|
{
|
2023-08-12 18:16:45 +02:00
|
|
|
public enum InputMode
|
2023-07-09 00:16:37 +02:00
|
|
|
{
|
|
|
|
None,
|
|
|
|
Grass,
|
|
|
|
Sand,
|
2023-08-12 18:16:45 +02:00
|
|
|
Water,
|
|
|
|
Obstacle,
|
|
|
|
Navigate
|
2023-07-09 00:16:37 +02:00
|
|
|
}
|
2023-11-10 11:11:08 +01:00
|
|
|
|
|
|
|
private CheckBox _gameGeometryCheckBox;
|
|
|
|
private Button _grassButton;
|
|
|
|
private Button _navigateButton;
|
|
|
|
private CheckBox _navigationGeometryCheckBox;
|
|
|
|
private Button _obstacleButton;
|
|
|
|
private CheckBox _physicsGeometryCheckBox;
|
|
|
|
|
|
|
|
// private members
|
|
|
|
private Button _resetButton;
|
|
|
|
private Button _sandButton;
|
|
|
|
private StreamContainer _streamContainer;
|
|
|
|
private ShaderMaterial _tileMaterial;
|
|
|
|
|
|
|
|
private TileWorld _tileWorld;
|
|
|
|
private Button _waterButton;
|
|
|
|
|
2023-08-12 18:16:45 +02:00
|
|
|
public InputMode CurrentInputMode = InputMode.None;
|
2023-11-10 11:11:08 +01:00
|
|
|
// exported members
|
|
|
|
|
|
|
|
// public members
|
|
|
|
public Vector2 currentTileOffset = Vector2.Zero;
|
|
|
|
|
2023-07-09 00:16:37 +02:00
|
|
|
// Called when the node enters the scene tree for the first time.
|
|
|
|
public override void _Ready()
|
|
|
|
{
|
2023-08-12 18:16:45 +02:00
|
|
|
_tileMaterial = GD.Load<ShaderMaterial>("materials/HexTileTextureLookup.tres");
|
2023-11-10 11:11:08 +01:00
|
|
|
|
2023-07-09 00:16:37 +02:00
|
|
|
// signals
|
2023-11-10 11:11:08 +01:00
|
|
|
_resetButton = (Button)FindNode("ResetButton");
|
2023-07-09 00:16:37 +02:00
|
|
|
_resetButton.Connect("pressed", this, nameof(OnResetButton));
|
2023-11-10 11:11:08 +01:00
|
|
|
|
|
|
|
_grassButton = (Button)FindNode("GrassButton");
|
2023-07-09 00:16:37 +02:00
|
|
|
_grassButton.Connect("pressed", this, nameof(OnGrassButton));
|
2023-11-10 11:11:08 +01:00
|
|
|
|
|
|
|
_sandButton = (Button)FindNode("SandButton");
|
2023-07-09 00:16:37 +02:00
|
|
|
_sandButton.Connect("pressed", this, nameof(OnSandButton));
|
2023-11-10 11:11:08 +01:00
|
|
|
|
|
|
|
_waterButton = (Button)FindNode("WaterButton");
|
2023-07-09 00:16:37 +02:00
|
|
|
_waterButton.Connect("pressed", this, nameof(OnWaterButton));
|
2023-07-15 00:39:38 +02:00
|
|
|
|
2023-11-10 11:11:08 +01:00
|
|
|
_obstacleButton = (Button)FindNode("ObstacleButton");
|
2023-08-12 18:16:45 +02:00
|
|
|
_obstacleButton.Connect("pressed", this, nameof(OnObstacleButton));
|
|
|
|
|
2023-11-10 11:11:08 +01:00
|
|
|
_navigateButton = (Button)FindNode("NavigateButton");
|
2023-08-12 18:16:45 +02:00
|
|
|
_navigateButton.Connect("pressed", this, nameof(OnNavigateButton));
|
2023-11-10 11:11:08 +01:00
|
|
|
|
2023-07-15 00:39:38 +02:00
|
|
|
_gameGeometryCheckBox = (CheckBox)FindNode("GameGeometryCheckBox");
|
|
|
|
_gameGeometryCheckBox.Connect("toggled", this, nameof(OnGameGeometryCheckBoxToggled));
|
2023-11-10 11:11:08 +01:00
|
|
|
|
2023-07-15 00:39:38 +02:00
|
|
|
_physicsGeometryCheckBox = (CheckBox)FindNode("PhysicsGeometryCheckBox");
|
|
|
|
_physicsGeometryCheckBox.Connect("toggled", this, nameof(OnPhysicsGeometryCheckBoxToggled));
|
2023-11-10 11:11:08 +01:00
|
|
|
|
2023-08-12 18:16:45 +02:00
|
|
|
_navigationGeometryCheckBox = (CheckBox)FindNode("NavigationGeometryCheckBox");
|
|
|
|
_navigationGeometryCheckBox.Connect("toggled", this, nameof(OnNavigationGeometryCheckBoxToggled));
|
2023-07-09 00:16:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnResetButton()
|
|
|
|
{
|
|
|
|
GD.Print("Resetting Map");
|
|
|
|
_tileWorld.Seed = _tileWorld.Seed + 1;
|
2023-08-12 18:16:45 +02:00
|
|
|
_tileWorld.Generate(24);
|
2023-07-09 00:16:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void OnGrassButton()
|
|
|
|
{
|
2023-08-12 18:16:45 +02:00
|
|
|
CurrentInputMode = InputMode.Grass;
|
2023-07-09 00:16:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void OnSandButton()
|
|
|
|
{
|
2023-08-12 18:16:45 +02:00
|
|
|
CurrentInputMode = InputMode.Sand;
|
2023-07-09 00:16:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void OnWaterButton()
|
|
|
|
{
|
2023-08-12 18:16:45 +02:00
|
|
|
CurrentInputMode = InputMode.Water;
|
|
|
|
}
|
2023-11-10 11:11:08 +01:00
|
|
|
|
2023-08-12 18:16:45 +02:00
|
|
|
public void OnObstacleButton()
|
|
|
|
{
|
|
|
|
CurrentInputMode = InputMode.Obstacle;
|
2023-07-09 00:16:37 +02:00
|
|
|
}
|
|
|
|
|
2023-08-12 18:16:45 +02:00
|
|
|
public void OnNavigateButton()
|
|
|
|
{
|
|
|
|
CurrentInputMode = InputMode.Navigate;
|
|
|
|
}
|
|
|
|
|
2023-07-15 00:39:38 +02:00
|
|
|
public void OnGameGeometryCheckBoxToggled(bool pressed)
|
|
|
|
{
|
2023-11-10 11:11:08 +01:00
|
|
|
var gameGeometries = GetTree().GetNodesInGroup("GameGeometry");
|
2023-07-15 00:39:38 +02:00
|
|
|
foreach (Spatial mesh in gameGeometries)
|
|
|
|
if (mesh != null)
|
|
|
|
mesh.Visible = pressed;
|
|
|
|
}
|
2023-11-10 11:11:08 +01:00
|
|
|
|
|
|
|
|
2023-07-15 00:39:38 +02:00
|
|
|
public void OnPhysicsGeometryCheckBoxToggled(bool pressed)
|
|
|
|
{
|
2023-11-10 11:11:08 +01:00
|
|
|
var physicsGeometries = GetTree().GetNodesInGroup("PhysicsGeometry");
|
2023-07-15 00:39:38 +02:00
|
|
|
foreach (Spatial mesh in physicsGeometries)
|
|
|
|
if (mesh != null)
|
|
|
|
mesh.Visible = pressed;
|
|
|
|
}
|
2023-11-10 11:11:08 +01:00
|
|
|
|
|
|
|
|
2023-08-12 18:16:45 +02:00
|
|
|
public void OnNavigationGeometryCheckBoxToggled(bool pressed)
|
|
|
|
{
|
|
|
|
UpdateTileMaterial();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void UpdateTileMaterial()
|
|
|
|
{
|
|
|
|
if (_navigationGeometryCheckBox.Pressed)
|
|
|
|
{
|
|
|
|
ImageTexture newWorldTexture = new ImageTexture();
|
|
|
|
newWorldTexture.CreateFromImage(_tileWorld.NavigationmapImage,
|
|
|
|
(uint)(Texture.FlagsEnum.Mipmaps | Texture.FlagsEnum.Repeat));
|
|
|
|
_tileMaterial.SetShaderParam("MapAlbedoTexture", newWorldTexture);
|
|
|
|
_tileMaterial.SetShaderParam("TextureSize", (int)_tileWorld.NavigationmapImage.GetSize().x);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ImageTexture newWorldTexture = new ImageTexture();
|
|
|
|
newWorldTexture.CreateFromImage(_tileWorld.ColormapImage,
|
|
|
|
(uint)(Texture.FlagsEnum.Mipmaps | Texture.FlagsEnum.Repeat));
|
|
|
|
_tileMaterial.SetShaderParam("MapAlbedoTexture", newWorldTexture);
|
|
|
|
_tileMaterial.SetShaderParam("TextureSize", (int)_tileWorld.ColormapImage.GetSize().x);
|
|
|
|
}
|
|
|
|
}
|
2023-11-10 11:11:08 +01:00
|
|
|
|
|
|
|
|
2023-07-09 00:16:37 +02:00
|
|
|
public void OnTileClicked(Vector2 offsetCoord)
|
|
|
|
{
|
2023-08-12 18:16:45 +02:00
|
|
|
switch (CurrentInputMode)
|
2023-07-09 00:16:37 +02:00
|
|
|
{
|
2023-11-10 11:11:08 +01:00
|
|
|
case InputMode.Grass:
|
|
|
|
_tileWorld.SetTileColorAtOffset(currentTileOffset, Colors.Green);
|
|
|
|
break;
|
|
|
|
case InputMode.Water:
|
|
|
|
_tileWorld.SetTileColorAtOffset(currentTileOffset, Colors.Blue);
|
|
|
|
break;
|
|
|
|
case InputMode.Sand:
|
|
|
|
_tileWorld.SetTileColorAtOffset(currentTileOffset, Colors.Yellow);
|
|
|
|
break;
|
2023-08-12 18:16:45 +02:00
|
|
|
case InputMode.Obstacle:
|
|
|
|
_tileWorld.MarkCellUnwalkable(HexCell.FromOffsetCoords(offsetCoord));
|
2023-11-10 11:11:08 +01:00
|
|
|
break;
|
2023-07-09 00:16:37 +02:00
|
|
|
}
|
2023-11-10 11:11:08 +01:00
|
|
|
|
2023-08-12 18:16:45 +02:00
|
|
|
UpdateTileMaterial();
|
2023-07-09 00:16:37 +02:00
|
|
|
}
|
2023-11-10 11:11:08 +01:00
|
|
|
}
|