# HG changeset patch # User Alys Brooks # Date 2022-02-13 06:37:40 # Node ID 8290bd03f9ac129da15b5733af743f7ce88b73ca # Parent e3be69aada5b611d8fe1a3fe1e3641a5793e5154 Extend ranges properly. diff --git a/isometric-park-fna/Components/SelectedComponent.cs b/isometric-park-fna/Components/SelectedComponent.cs --- a/isometric-park-fna/Components/SelectedComponent.cs +++ b/isometric-park-fna/Components/SelectedComponent.cs @@ -3,7 +3,14 @@ namespace isometricparkfna.Components { + public enum SelectionType { + None, + Window, //Selected in a window + ActiveTool + } + public struct SelectedComponent : IComponent { public bool selected; + public SelectionType Type; } -} \ No newline at end of file +} 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 @@ -1,4 +1,6 @@ using System; +using System.Linq; +using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; @@ -13,7 +15,25 @@ [Receives(typeof(SpawnSelection), typeof(AdjustSelection))] [Writes(typeof(AreaComponent))] + [Reads(typeof(SelectedComponent), + typeof(AreaComponent))] public class BuildToolEngine : Engine { + + private System.Collections.Generic.IEnumerable step_until(float start, float stop) { + if (stop >= start) { + for(float i = start; i <= stop; i++) + { + yield return i; + } + } + else { + for(float i = start; i >= stop; i--) + { + yield return i; + } + } + } + public override void Update(double dt) { foreach (ref readonly var message in ReadMessages()) @@ -21,9 +41,54 @@ var entity = CreateEntity(); AddComponent(entity, new AreaComponent { squares = new[] {message.Start} }); - AddComponent(entity, new SelectedComponent { selected = false}); + AddComponent(entity, new SelectedComponent { selected = true, Type= SelectionType.ActiveTool}); } - } - } -} + + foreach (ref readonly var message in ReadMessages()) + { + foreach (ref readonly var entity in ReadEntities()) + { + var selection = GetComponent(entity); + if(selection.Type == SelectionType.ActiveTool) { + if(message.Clear) { + Destroy(entity); + } + else { + var area = GetComponent(entity); + + var newSquares = new List(); + + newSquares.Add(area.squares[0]); + + // + // for (float i = area.squares[0].X; i >= message.End.X; i--) { + // for (float j = area.squares[0].Y; j >= message.End.Y; j--) { + // newSquares.Add(new Vector2(i, j)); + // } + // } + // + // for (float i = area.squares[0].X; i <= message.End.X; i++) { + // for (float j = area.squares[0].Y; j <= message.End.Y; j++) { + // newSquares.Add(new Vector2(i, j)); + // } + // } + + foreach (var i in step_until(area.squares[0].X, message.End.X)) { + foreach (var j in step_until(area.squares[0].Y, message.End.Y)) { + newSquares.Add(new Vector2(i, j)); + } + } + + newSquares.Add(message.End); + + SetComponent(entity, new AreaComponent { squares = newSquares.ToArray() /*( new[]{ area.squares[0], message.End}*/}); + } + } + } + + } + } + } + } + diff --git a/isometric-park-fna/Engines/InputEngine.cs b/isometric-park-fna/Engines/InputEngine.cs --- a/isometric-park-fna/Engines/InputEngine.cs +++ b/isometric-park-fna/Engines/InputEngine.cs @@ -246,6 +246,16 @@ SendMessage(new SpawnSelection {Start = CellMap.calculateMousegrid(original_point)}); } + if ( mouseCur.LeftButton == ButtonState.Released && mousePrev.LeftButton == ButtonState.Pressed ) + { + SendMessage(new AdjustSelection {Clear = true }); + } + + if (mouseCur.LeftButton == ButtonState.Pressed && mousePrev.LeftButton == ButtonState.Pressed) + { + SendMessage(new AdjustSelection { End = CellMap.calculateMousegrid(original_point)}); + } + #endregion this.keyboardPrev = keyboardCur; this.mousePrev = mouseCur; diff --git a/isometric-park-fna/Engines/Spawners/ContractSpawner.cs b/isometric-park-fna/Engines/Spawners/ContractSpawner.cs --- a/isometric-park-fna/Engines/Spawners/ContractSpawner.cs +++ b/isometric-park-fna/Engines/Spawners/ContractSpawner.cs @@ -206,7 +206,7 @@ AddComponent(contract, new AreaComponent { squares = squares }); var nameAndDescription = new NameAndDescriptionComponent { DisplayName = this.grammar.Flatten(message.name) }; AddComponent(contract, nameAndDescription); - AddComponent(contract, new SelectedComponent { selected = false }); + AddComponent(contract, new SelectedComponent { selected = false, Type = SelectionType.Window }); AddComponent(contract, new ContractStatusComponent { status = ContractStatus.Proposed, date = this.simulation.DateTime }); AddComponent(contract, new TreeDeltaComponent { deltaTrees = new Fact(deltaTrees) }); AddComponent(contract, new BudgetLineComponent diff --git a/isometric-park-fna/Engines/UIEngine.cs b/isometric-park-fna/Engines/UIEngine.cs --- a/isometric-park-fna/Engines/UIEngine.cs +++ b/isometric-park-fna/Engines/UIEngine.cs @@ -40,7 +40,10 @@ { foreach (var entity in ReadEntities()) { - SetComponent(entity, new SelectedComponent { selected = false }); + var selected = GetComponent(entity); + if (selected.Type == SelectionType.Window) { + SetComponent(entity, new SelectedComponent { selected = false }); + } } foreach (ref readonly var windowMessage in ReadMessages()) diff --git a/isometric-park-fna/Messages/AdjustSelection.cs b/isometric-park-fna/Messages/AdjustSelection.cs --- a/isometric-park-fna/Messages/AdjustSelection.cs +++ b/isometric-park-fna/Messages/AdjustSelection.cs @@ -5,5 +5,6 @@ namespace isometricparkfna.Messages { public struct AdjustSelection : IMessage { public Vector2 End; + public bool Clear; } } diff --git a/isometric-park-fna/Renderers/AreaRenderer.cs b/isometric-park-fna/Renderers/AreaRenderer.cs --- a/isometric-park-fna/Renderers/AreaRenderer.cs +++ b/isometric-park-fna/Renderers/AreaRenderer.cs @@ -34,12 +34,12 @@ // var SelectedComponent = GetComponent(entity); var selected = GetComponent(entity).selected; - if (!HasComponent(entity) - || GetComponent(entity).status == ContractStatus.Accepted - ) + if ((!HasComponent(entity) + || GetComponent(entity).status == ContractStatus.Accepted) + && !selected) { Tile.DrawOutlinedSquares(batch, areaComponent.squares, Color.Teal); - Quad.FillSquares(batch, areaComponent.squares, Color.Teal, 0.5f, 0.79f); + Quad.FillSquares(batch, areaComponent.squares, Color.Teal, 0.5f, 0.78f); } else if (HasComponent(entity) @@ -48,11 +48,11 @@ ) { Tile.DrawOutlinedSquares(batch, areaComponent.squares, Color.Teal); - Quad.FillSquares(batch, areaComponent.squares, Color.Gray, 0.5f, 0.80f); + Quad.FillSquares(batch, areaComponent.squares, Color.Gray, 0.5f, 0.78f); } else if (!HasComponent(entity) ) { - Quad.FillSquares(batch, areaComponent.squares, Color.Red, 0.5f, 0.80f); + Quad.FillSquares(batch, areaComponent.squares, Color.Red, 0.5f, 0.79f); Tile.DrawOutlinedSquares(batch, areaComponent.squares, Color.Red); } } diff --git a/isometric-park-fna/Renderers/ImGuiWindowRenderer.cs b/isometric-park-fna/Renderers/ImGuiWindowRenderer.cs --- a/isometric-park-fna/Renderers/ImGuiWindowRenderer.cs +++ b/isometric-park-fna/Renderers/ImGuiWindowRenderer.cs @@ -116,7 +116,9 @@ foreach (var e in contracts) { - contract_data.Add(getContractDetails(e)); + if(HasComponent(e)) { + contract_data.Add(getContractDetails(e)); + } } ContractsWindow.Render(this.BridgeEngine.font, this.BridgeEngine, contract_data);