# HG changeset patch # User alys # Date 2021-01-04 21:32:13 # Node ID 9c98448d319bee5d2fe636fc10ec7c8d8f518b26 # Parent 7a42e052acb80b5090acf2eb45f58d314c1d9011 Add proper marker for highlighting squares. diff --git a/isometric-park-fna/Dialog.cs b/isometric-park-fna/Dialog.cs --- a/isometric-park-fna/Dialog.cs +++ b/isometric-park-fna/Dialog.cs @@ -105,6 +105,7 @@ { public static Node RenderDialog(ref bool show, ref bool paused, ImFontPtr font, Node currentNode) { + Node new_child = currentNode; if (show) { ImGui.PushFont(font); @@ -142,7 +143,7 @@ string buttonText = child.data.choice; if (ImGui.Button(buttonText)) { - return child; + new_child = child; } } } @@ -166,7 +167,7 @@ ImGui.PopStyleColor(8); ImGui.PopFont(); } - return currentNode; + return new_child; } } 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 @@ -174,8 +174,6 @@ } ); - - this.debugWindow = new DebugWindow(this._imGuiRenderer, GraphicsDevice); var json2 = new FileInfo(@"Content/grammar.json"); @@ -188,8 +186,7 @@ this.remainingDialog = new Queue>(); this.remainingDialog.Enqueue(DialogTrees.flatten(DialogTrees.testTree, this.grammar)); - - + //font = fontBakeResult.CreateSpriteFont(GraphicsDevice); monoFont = bakedMono.CreateSpriteFont(GraphicsDevice); @@ -498,23 +495,23 @@ } protected override void Draw(GameTime gameTime) - { - // Render stuff in here. Do NOT run game logic in here! + { + // Render stuff in here. Do NOT run game logic in here! - frameCounter++; + frameCounter++; - string fps = string.Format("fps: {0}", frameRate); + string fps = string.Format("fps: {0}", frameRate); - Stopwatch stopWatch = new Stopwatch(); - stopWatch.Start(); - GraphicsDevice.Clear(Color.CornflowerBlue); - batch.Begin(SpriteSortMode.BackToFront, - BlendState.AlphaBlend, - null, - null, - null, - null, - camera.get_transformation(GraphicsDevice)); + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + GraphicsDevice.Clear(Color.CornflowerBlue); + batch.Begin(SpriteSortMode.BackToFront, + BlendState.AlphaBlend, + null, + null, + null, + null, + camera.get_transformation(GraphicsDevice)); //New tile stuff /* @@ -558,70 +555,71 @@ //reset this.tilesDrawn = 0; - for (int y = 0; y < this.squaresDown; y++) - { + for (int y = 0; y < this.squaresDown; y++) + { - for (int x = 0; x < this.squaresAcross; x++) - { + for (int x = 0; x < this.squaresAcross; x++) + { - int screenx = (x - y) * Tile.TileSpriteWidth/2; + int screenx = (x - y) * Tile.TileSpriteWidth / 2; - int screeny = (x + y) * Tile.TileSpriteHeight / 2; + int screeny = (x + y) * Tile.TileSpriteHeight / 2; - if (this.cull(x, y)) { - batch.Draw( - Tile.TileSetTexture, - new Rectangle( - screenx, - screeny, - Tile.TileWidth, Tile.TileHeight), - Tile.GetSourceRectangle(1), - Color.White, - 0.0f, - Vector2.Zero, - SpriteEffects.None, - 0.9f); + if (this.cull(x, y)) + { + batch.Draw( + Tile.TileSetTexture, + new Rectangle( + screenx, + screeny, + Tile.TileWidth, Tile.TileHeight), + Tile.GetSourceRectangle(1), + Color.White, + 0.0f, + Vector2.Zero, + SpriteEffects.None, + 0.9f); - this.tilesDrawn++; - } + this.tilesDrawn++; + } + - - } + } - } + } #endregion draw_tiles #region draw_gridlines if (this.showGrid) - { - //need to go one extra so gridlines include the far side of the final tile: - for (int y = 0; y < (this.squaresDown + 1); y++) - { + { + //need to go one extra so gridlines include the far side of the final tile: + for (int y = 0; y < (this.squaresDown + 1); y++) + { - Vector2 adjust = new Vector2(Tile.TileSpriteWidth / 2, Tile.TileSpriteHeight); //TODO figure out why this second value shouldn't be halved + Vector2 adjust = new Vector2(Tile.TileSpriteWidth / 2, Tile.TileSpriteHeight); //TODO figure out why this second value shouldn't be halved - Line.drawLine(batch, - new Vector2(((0 - y) * Tile.TileSpriteWidth / 2), (0 + y) * Tile.TileSpriteHeight / 2) + adjust, - //new Vector2(this.squaresAcross * Tile.TileSpriteWidth, (y+1) * Tile.TileSpriteHeight), - new Vector2((this.squaresAcross - (y)) * Tile.TileSpriteWidth / 2, (this.squaresAcross + (y)) * Tile.TileSpriteHeight / 2) + adjust, - Color.White, 0.8f); + Line.drawLine(batch, + new Vector2(((0 - y) * Tile.TileSpriteWidth / 2), (0 + y) * Tile.TileSpriteHeight / 2) + adjust, + //new Vector2(this.squaresAcross * Tile.TileSpriteWidth, (y+1) * Tile.TileSpriteHeight), + new Vector2((this.squaresAcross - (y)) * Tile.TileSpriteWidth / 2, (this.squaresAcross + (y)) * Tile.TileSpriteHeight / 2) + adjust, + Color.White, 0.8f); - } + } - for (int x = 0; x < (this.squaresAcross + 1); x++) - { + for (int x = 0; x < (this.squaresAcross + 1); x++) + { - Vector2 adjust = new Vector2(Tile.TileSpriteWidth / 2, Tile.TileSpriteHeight); //TODO figure out why this second value shouldn't be halved + Vector2 adjust = new Vector2(Tile.TileSpriteWidth / 2, Tile.TileSpriteHeight); //TODO figure out why this second value shouldn't be halved - Line.drawLine(batch, - new Vector2(((x - 0) * Tile.TileSpriteWidth / 2), (x + 0) * Tile.TileSpriteHeight / 2) + adjust, - //new Vector2(this.squaresAcross * Tile.TileSpriteWidth, (y+1) * Tile.TileSpriteHeight), - new Vector2((x - this.squaresDown) * Tile.TileSpriteWidth / 2, (x + this.squaresDown) * Tile.TileSpriteHeight / 2) + adjust, - Color.White, 0.8f); + Line.drawLine(batch, + new Vector2(((x - 0) * Tile.TileSpriteWidth / 2), (x + 0) * Tile.TileSpriteHeight / 2) + adjust, + //new Vector2(this.squaresAcross * Tile.TileSpriteWidth, (y+1) * Tile.TileSpriteHeight), + new Vector2((x - this.squaresDown) * Tile.TileSpriteWidth / 2, (x + this.squaresDown) * Tile.TileSpriteHeight / 2) + adjust, + Color.White, 0.8f); - } - } + } + } #endregion draw_gridlines @@ -665,12 +663,21 @@ */ drawTileAt(4, 4, 140, 3); - drawTileAt(6, 4, 141, 3); - drawTileAt(8, 4, 142, 2); - drawTileAt(10, 4, 142, 3); + drawTileAt(6, 4, 141, 3); + drawTileAt(8, 4, 142, 2); + drawTileAt(10, 4, 142, 3); #region draw_cursor - drawTileAt((int)this.mouseGrid.X, (int)this.mouseGrid.Y, 2, 1, 0.85f); //between tiles and gridlines + //drawTileAt((int)this.mouseGrid.X, (int)this.mouseGrid.Y, 2, 1, 0.85f); //between tiles and gridlines + + //TODO figure out why it has to be -1 + if (MathUtils.Between(this.mouseGrid.X, -1, this.simulation.map.MapWidth) + && MathUtils.Between(this.mouseGrid.Y, -1, this.simulation.map.MapHeight)) + { + OutlineSquare(this.mouseGrid.X, this.mouseGrid.Y, Color.Yellow); + } + + #endregion draw_cursor /* @@ -695,120 +702,150 @@ #region draw_trees for (int i = 0; i < this.simulation.map.MapHeight; i++) - { - for (int j = 0; j < this.simulation.map.MapWidth; j += 1) - { + { + for (int j = 0; j < this.simulation.map.MapWidth; j += 1) + { - if (this.simulation.map.cells[i][j].hasTree) - { //until we actually simulate: - if((i+j)%8 == 0) + if (this.simulation.map.cells[i][j].hasTree) + { //until we actually simulate: + if ((i + j) % 8 == 0) { - drawTileAt(i, j, 141, 2); - } - else + drawTileAt(i, j, 141, 2); + } + else { - drawTileAt(i, j, 142, 2); - } - } - } - } + drawTileAt(i, j, 142, 2); + } + } + } + } #endregion draw_trees drawTileAt(2, 2, 140, 2); - drawTileAt(1, 1, 140, 2); - drawTileAt(3, 2, 140, 2); + drawTileAt(1, 1, 140, 2); + drawTileAt(3, 2, 140, 2); - batch.End(); + batch.End(); #region draw_header batch.Begin(SpriteSortMode.BackToFront, - BlendState.AlphaBlend, - null, - null, - null, - null); + BlendState.AlphaBlend, + null, + null, + null, + null); - bool has_tree = false; - if (MathUtils.Between(this.mouseGrid.X, 0, this.squaresAcross) && MathUtils.Between(this.mouseGrid.Y, 0, this.squaresAcross)) + bool has_tree = false; + if (MathUtils.Between(this.mouseGrid.X, 0, this.squaresAcross) && MathUtils.Between(this.mouseGrid.Y, 0, this.squaresAcross)) { - has_tree = this.simulation.map.cells[(int)this.mouseGrid.X][(int)this.mouseGrid.Y].hasTree; - //batch.DrawString(font, has_tree.ToString(), new Vector2(500, 33), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f); - //batch.DrawString(font, has_tree.ToString(), new Vector2(499, 32), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.49f); - } - //*/ - - - String header_left = String.Format("${0:}|{1:} trees⚘𐂷🌳", this.simulation.money, this.simulation.map.tree_count); - String header_middle = String.Format("{0:MMMMM yyyy} ({1:})", this.simulation.DateTime, this.simulation.Season); - - this.Window.Title = String.Format("Isometric Park [{0:}]",header_middle); - Vector2 dimensions = monoFont.MeasureString(header_middle); - - float middle_start = (FNAGame.width / 2) - (dimensions.X / 2); - - FilledRectangle.drawFilledRectangle(batch, new Rectangle(0, 0, width, (int)dimensions.Y), Color.White, 0.51f); + has_tree = this.simulation.map.cells[(int)this.mouseGrid.X][(int)this.mouseGrid.Y].hasTree; + //batch.DrawString(font, has_tree.ToString(), new Vector2(500, 33), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f); + //batch.DrawString(font, has_tree.ToString(), new Vector2(499, 32), Color.White, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.49f); + } + //*/ - batch.DrawString(monoFont, header_left, new Vector2(1, 1), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f); - batch.DrawString(monoFont, header_middle, new Vector2(middle_start, 1), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f); + String header_left = String.Format("${0:}|{1:} trees⚘𐂷🌳", this.simulation.money, this.simulation.map.tree_count); + String header_middle = String.Format("{0:MMMMM yyyy} ({1:})", this.simulation.DateTime, this.simulation.Season); + + this.Window.Title = String.Format("Isometric Park [{0:}]", header_middle); + Vector2 dimensions = monoFont.MeasureString(header_middle); + + float middle_start = (FNAGame.width / 2) - (dimensions.X / 2); + + FilledRectangle.drawFilledRectangle(batch, new Rectangle(0, 0, width, (int)dimensions.Y), Color.White, 0.51f); + + + batch.DrawString(monoFont, header_left, new Vector2(1, 1), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f); + batch.DrawString(monoFont, header_middle, new Vector2(middle_start, 1), Color.Black, 0.0f, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f); #endregion draw_header batch.End(); - #region debug_window - //Calcs for debug window: - if ((this.frameCounter % 15) == 0) { - past_fps.Enqueue(this.frameRate); + #region debug_window + //Calcs for debug window: + if ((this.frameCounter % 15) == 0) + { + past_fps.Enqueue(this.frameRate); - } + } - DebugInfo debugInfo = new DebugInfo - { - fps = this.frameRate, - pastFps = past_fps.ToArray(), - cameraPosition = camera.position, - drawTime = this.drawTime, - treeCount = this.simulation.map.tree_count, - mouseGrid = this.mouseGrid, - hasTree = has_tree, - tilesDrawn = this.tilesDrawn - }; - - //Finally, draw the debug window - _imGuiRenderer.BeforeLayout(gameTime); + DebugInfo debugInfo = new DebugInfo + { + fps = this.frameRate, + pastFps = past_fps.ToArray(), + cameraPosition = camera.position, + drawTime = this.drawTime, + treeCount = this.simulation.map.tree_count, + mouseGrid = this.mouseGrid, + hasTree = has_tree, + tilesDrawn = this.tilesDrawn + }; - var additionalInfo = new Dictionary(); + //Finally, draw the debug window + _imGuiRenderer.BeforeLayout(gameTime); - additionalInfo.Add("Tracery Test", this.output); - debugWindow.Layout(debugInfo, additionalInfo,ref show_another_window); + var additionalInfo = new Dictionary(); - //String[] messages = { "Message1", "Message2" }; + additionalInfo.Add("Tracery Test", this.output); + debugWindow.Layout(debugInfo, additionalInfo, ref show_another_window); - //DialogOption[] dialog = { new DialogOption{ response="Welcome to your new park, director! You can use the mouse or arrow keys to move around, and the plus and minus keys to zoom in and out.", choice="Okay" }, - // new DialogOption{ response="Make sure that you keep visitors happy and the budget in the black! You're currently getting an annual grant out of my budget—it'd sure be nice if you park were self-sufficient so we could drop that expense!", choice="And I need to keep the forest healthy, too, right?" }, - // new DialogOption{ response="Oh yeah, of course.", choice="..." }}; + //String[] messages = { "Message1", "Message2" }; + + //DialogOption[] dialog = { new DialogOption{ response="Welcome to your new park, director! You can use the mouse or arrow keys to move around, and the plus and minus keys to zoom in and out.", choice="Okay" }, + // new DialogOption{ response="Make sure that you keep visitors happy and the budget in the black! You're currently getting an annual grant out of my budget—it'd sure be nice if you park were self-sufficient so we could drop that expense!", choice="And I need to keep the forest healthy, too, right?" }, + // new DialogOption{ response="Oh yeah, of course.", choice="..." }}; - if (this.currentNode != null) + if (this.currentNode != null) { - this.currentNode = DialogInterface.RenderDialog(ref this.showInitial, - ref this.simulation.paused, debugWindow.monoFont, this.currentNode); - } - + this.currentNode = DialogInterface.RenderDialog(ref this.showInitial, + ref this.simulation.paused, debugWindow.monoFont, this.currentNode); + } - - _imGuiRenderer.AfterLayout(); + _imGuiRenderer.AfterLayout(); #endregion debug_window stopWatch.Stop(); - this.drawTime = stopWatch.Elapsed; + this.drawTime = stopWatch.Elapsed; + + base.Draw(gameTime); + } + + private void OutlineSquare(float x, float y, Color color) + { + Vector2 adjust2 = new Vector2(Tile.TileSpriteWidth / 2, Tile.TileSpriteHeight); //TODO figure out why this second value shouldn't be halved + + //Upper right + //float x = this.mouseGrid.X; + //float y = this.mouseGrid.Y; + Line.drawLine(batch, + new Vector2(((x - y) * Tile.TileSpriteWidth / 2), (x + y) * Tile.TileSpriteHeight / 2) + adjust2, + //new Vector2(this.squaresAcross * Tile.TileSpriteWidth, (y+1) * Tile.TileSpriteHeight), + new Vector2(((x - y + 1) * Tile.TileSpriteWidth / 2), (x + y + 1) * Tile.TileSpriteHeight / 2) + adjust2, + color, 0.79f); - base.Draw(gameTime); - } - - + //Bottom right + Line.drawLine(batch, + new Vector2(((x + 1 - y) * Tile.TileSpriteWidth / 2), (x + 1 + y) * Tile.TileSpriteHeight / 2) + adjust2, + //new Vector2(this.squaresAcross * Tile.TileSpriteWidth, (y+1) * Tile.TileSpriteHeight), + new Vector2(((x + 1 - (y + 1)) * Tile.TileSpriteWidth / 2), (x + 1 + (y + 1)) * Tile.TileSpriteHeight / 2) + adjust2, + color, 0.79f); + //Bottom left + Line.drawLine(batch, + new Vector2(((x - (y + 1)) * Tile.TileSpriteWidth / 2), (x + y + 1) * Tile.TileSpriteHeight / 2) + adjust2, + //new Vector2(this.squaresAcross * Tile.TileSpriteWidth, (y+1) * Tile.TileSpriteHeight), + new Vector2(((x + 1 - (y + 1)) * Tile.TileSpriteWidth / 2), (x + 1 + (y + 1)) * Tile.TileSpriteHeight / 2) + adjust2, + color, 0.79f); + //Upper left + Line.drawLine(batch, + new Vector2(((x - y) * Tile.TileSpriteWidth / 2), (x + y) * Tile.TileSpriteHeight / 2) + adjust2, + //new Vector2(this.squaresAcross * Tile.TileSpriteWidth, (y+1) * Tile.TileSpriteHeight), + new Vector2(((x - (y + 1)) * Tile.TileSpriteWidth / 2), (x + (y + 1)) * Tile.TileSpriteHeight / 2) + adjust2, + color, 0.79f); + } }