155 lines
5.2 KiB
C#
155 lines
5.2 KiB
C#
using Godot;
|
|
using Godot.Collections;
|
|
|
|
public class EditorUI : Control {
|
|
public enum InputMode {
|
|
None,
|
|
Grass,
|
|
Sand,
|
|
Water,
|
|
Obstacle,
|
|
Navigate
|
|
}
|
|
|
|
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;
|
|
|
|
public InputMode CurrentInputMode = InputMode.None;
|
|
// exported members
|
|
|
|
// public members
|
|
public Vector2 currentTileOffset = Vector2.Zero;
|
|
|
|
// Called when the node enters the scene tree for the first time.
|
|
public override void _Ready() {
|
|
_tileMaterial = GD.Load<ShaderMaterial>("materials/HexTileTextureLookup.tres");
|
|
|
|
// 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));
|
|
|
|
_obstacleButton = (Button)FindNode("ObstacleButton");
|
|
_obstacleButton.Connect("pressed", this, nameof(OnObstacleButton));
|
|
|
|
_navigateButton = (Button)FindNode("NavigateButton");
|
|
_navigateButton.Connect("pressed", this, nameof(OnNavigateButton));
|
|
|
|
_gameGeometryCheckBox = (CheckBox)FindNode("GameGeometryCheckBox");
|
|
_gameGeometryCheckBox.Connect("toggled", this, nameof(OnGameGeometryCheckBoxToggled));
|
|
|
|
_physicsGeometryCheckBox = (CheckBox)FindNode("PhysicsGeometryCheckBox");
|
|
_physicsGeometryCheckBox.Connect("toggled", this, nameof(OnPhysicsGeometryCheckBoxToggled));
|
|
|
|
_navigationGeometryCheckBox = (CheckBox)FindNode("NavigationGeometryCheckBox");
|
|
_navigationGeometryCheckBox.Connect("toggled", this, nameof(OnNavigationGeometryCheckBoxToggled));
|
|
}
|
|
|
|
|
|
public void OnResetButton() {
|
|
GD.Print("Resetting Map");
|
|
_tileWorld.Seed = _tileWorld.Seed + 1;
|
|
_tileWorld.Generate(24);
|
|
}
|
|
|
|
public void OnGrassButton() {
|
|
CurrentInputMode = InputMode.Grass;
|
|
}
|
|
|
|
public void OnSandButton() {
|
|
CurrentInputMode = InputMode.Sand;
|
|
}
|
|
|
|
public void OnWaterButton() {
|
|
CurrentInputMode = InputMode.Water;
|
|
}
|
|
|
|
public void OnObstacleButton() {
|
|
CurrentInputMode = InputMode.Obstacle;
|
|
}
|
|
|
|
public void OnNavigateButton() {
|
|
CurrentInputMode = InputMode.Navigate;
|
|
}
|
|
|
|
public void OnGameGeometryCheckBoxToggled(bool pressed) {
|
|
Array gameGeometries = GetTree().GetNodesInGroup("GameGeometry");
|
|
foreach (Spatial mesh in gameGeometries) {
|
|
if (mesh != null) {
|
|
mesh.Visible = pressed;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public void OnPhysicsGeometryCheckBoxToggled(bool pressed) {
|
|
Array physicsGeometries = GetTree().GetNodesInGroup("PhysicsGeometry");
|
|
foreach (Spatial mesh in physicsGeometries) {
|
|
if (mesh != null) {
|
|
mesh.Visible = pressed;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public void OnNavigationGeometryCheckBoxToggled(bool pressed) {
|
|
UpdateTileMaterial();
|
|
}
|
|
|
|
public void UpdateTileMaterial() {
|
|
if (_navigationGeometryCheckBox.Pressed) {
|
|
ImageTexture newWorldTexture = new();
|
|
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();
|
|
newWorldTexture.CreateFromImage(_tileWorld.ColormapImage,
|
|
(uint)(Texture.FlagsEnum.Mipmaps | Texture.FlagsEnum.Repeat));
|
|
_tileMaterial.SetShaderParam("MapAlbedoTexture", newWorldTexture);
|
|
_tileMaterial.SetShaderParam("TextureSize", (int)_tileWorld.ColormapImage.GetSize().x);
|
|
}
|
|
}
|
|
|
|
|
|
public void OnTileClicked(Vector2 offsetCoord) {
|
|
switch (CurrentInputMode) {
|
|
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;
|
|
case InputMode.Obstacle:
|
|
_tileWorld.MarkCellUnwalkable(HexCell.FromOffsetCoords(offsetCoord));
|
|
break;
|
|
}
|
|
|
|
UpdateTileMaterial();
|
|
}
|
|
} |