diff --git a/isometric-park-fna/Components/AreaComponent.cs b/isometric-park-fna/Components/AreaComponent.cs --- a/isometric-park-fna/Components/AreaComponent.cs +++ b/isometric-park-fna/Components/AreaComponent.cs @@ -1,4 +1,3 @@ - using Microsoft.Xna.Framework; using Encompass; diff --git a/isometric-park-fna/Components/PointComponent.cs b/isometric-park-fna/Components/PointComponent.cs new file mode 100644 --- /dev/null +++ b/isometric-park-fna/Components/PointComponent.cs @@ -0,0 +1,11 @@ +using Microsoft.Xna.Framework; + +using Encompass; + +namespace isometricparkfna.Components { + + public struct PointComponent : IComponent { + public Vector2 Square; + public Tool Tool; + } +} diff --git a/isometric-park-fna/Components/StructureComponent.cs b/isometric-park-fna/Components/StructureComponent.cs new file mode 100644 --- /dev/null +++ b/isometric-park-fna/Components/StructureComponent.cs @@ -0,0 +1,17 @@ + +using Encompass; + +using isometricparkfna.Messages; + +namespace isometricparkfna.Components { + public enum Structure + { + None, + Tower + } + + public struct StructureComponent : IComponent { + public Structure Structure; + // public DateTime Placed; + } +} diff --git a/isometric-park-fna/Engines/BuildToolEngine.cs b/isometric-park-fna/Engines/BuildToolEngine.cs --- a/isometric-park-fna/Engines/BuildToolEngine.cs +++ b/isometric-park-fna/Engines/BuildToolEngine.cs @@ -17,13 +17,15 @@ typeof(AdjustSelection))] [Writes(typeof(AreaComponent), // typeof(SelectedComponent), + typeof(PointComponent), typeof(PreserveComponent))] [Reads(typeof(SelectedComponent), typeof(ContractStatusComponent), typeof(AreaComponent), typeof(PreserveComponent), typeof(SelectedComponent), - typeof(ToolComponent))] + typeof(ToolComponent), + typeof(PointComponent))] [Sends(typeof(ChangeContractStatusMessage))] public class BuildToolEngine : Engine { @@ -204,6 +206,52 @@ } } } + else if (statuses.ContainsKey(Tool.Tower) && statuses[Tool.Tower]) { + foreach (ref readonly var message in ReadMessages()) + { + if (message.Start.X >= 0 && message.Start.X < this.Map.MapWidth + && message.Start.Y >= 0 && message.Start.Y < this.Map.MapHeight) { + var entity = CreateEntity(); + + AddComponent(entity, new PointComponent {Square = message.Start, + Tool=Tool.Tower}); + AddComponent(entity, new SelectedComponent { selected = true, Type= SelectionType.Area}); + } + } + + foreach (ref readonly var message in ReadMessages()) { + foreach (ref readonly var entity in ReadEntities()) { + var selection = GetComponent(entity); + + if (selection.Type == SelectionType.Area + && selection.selected) { + if(message.Type == AdjustmentType.Clear) { + Destroy(entity); + } + else if(message.Type == AdjustmentType.Complete) { + var point = GetComponent(entity); + var structure_entity = CreateEntity(); + + AddComponent(structure_entity, new PointComponent {Square = point.Square, + Tool = point.Tool} ); + AddComponent(structure_entity, + new StructureComponent { Structure = Structure.Tower}); + Destroy(entity); + Logging.Success("Placed Tower!"); + + } + else { + var point = GetComponent(entity); + SetComponent(entity, new PointComponent {Square = message.End, + Tool = point.Tool}); + } + } + + } + + } + + } } } } diff --git a/isometric-park-fna/FNAGame.cs b/isometric-park-fna/FNAGame.cs --- a/isometric-park-fna/FNAGame.cs +++ b/isometric-park-fna/FNAGame.cs @@ -318,6 +318,7 @@ WorldBuilder.AddGeneralRenderer(new AreaRenderer(this.tileBatch, this.monoFont), 1); WorldBuilder.AddGeneralRenderer(new ImGuiWindowRenderer(this, this.simulation, this.imGuiWindowBridgeEngine, this.gdm), 2); WorldBuilder.AddGeneralRenderer(new CursorRenderer(this.tileBatch, this.monoFont), 3); + WorldBuilder.AddGeneralRenderer(new StructureRenderer(this.tileBatch, this.monoFont), 4); var contractWindow = WorldBuilder.CreateEntity(); WorldBuilder.SetComponent(contractWindow, new VisibilityComponent { visible = false }); WorldBuilder.SetComponent(contractWindow, new WindowTypeComponent { type = isometricparkfna.Messages.Window.Contracts }); diff --git a/isometric-park-fna/Renderers/StructureRenderer.cs b/isometric-park-fna/Renderers/StructureRenderer.cs new file mode 100644 --- /dev/null +++ b/isometric-park-fna/Renderers/StructureRenderer.cs @@ -0,0 +1,40 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +using isometricparkfna.UI; +using isometricparkfna.Components; + +using Encompass; +using SpriteFontPlus; + +namespace isometricparkfna.Renderers +{ + public class StructureRenderer : GeneralRenderer + { + private SpriteBatch batch; + private SpriteFont font; + + public StructureRenderer(SpriteBatch batch, SpriteFont font) + { + this.batch = batch; + this.font = font; + } + + public override void Render() + { + + + foreach (ref readonly var entity in ReadEntities()) + { + var point = GetComponent(entity); + Tile.drawTileAt(this.batch, (int)point.Square.X, (int)point.Square.Y, + 300, 2, 0.79f, Color.White); + } + + + + } + } + + +} diff --git a/isometric-park-fna/UI/StyleSets.cs b/isometric-park-fna/UI/StyleSets.cs --- a/isometric-park-fna/UI/StyleSets.cs +++ b/isometric-park-fna/UI/StyleSets.cs @@ -34,8 +34,8 @@ {ImGuiCol.FrameBg, grey}, {ImGuiCol.FrameBgHovered, grey}, {ImGuiCol.Header, darkgrey}, - {ImGuiCol.HeaderHovered, grey}, - {ImGuiCol.HeaderActive, grey}, + {ImGuiCol.HeaderHovered, darkgrey}, + {ImGuiCol.HeaderActive, darkgrey}, {ImGuiCol.ButtonHovered, grey}, {ImGuiCol.ButtonActive, darkgrey}, {ImGuiCol.SliderGrab, darkgrey},