# HG changeset patch # User alys # Date 2020-12-31 02:58:17 # Node ID 11e74a08597df489929be95e3ec1b78db092f27a # Parent ce8b160270cfb048afde67e86f9e022b08d5de58 Add dialogue, yeah! diff --git a/isometric-park-fna/Dialog.cs b/isometric-park-fna/Dialog.cs new file mode 100644 --- /dev/null +++ b/isometric-park-fna/Dialog.cs @@ -0,0 +1,25 @@ +using System; +using System.Text.Json; +using isometricparkfna.Utils; + +namespace isometricparkfna +{ + + + //#nullable enable + public struct DialogOption + { + public String? choice; + public String response; + } + + public static class Dialog + { + + public static Node Parse(JsonDocument document) + { + + } + } + +} 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 @@ -5,12 +5,15 @@ using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Media; + + using System; using System.IO; using SpriteFontPlus; using isometricparkfna; using System.Diagnostics; using static isometricparkfna.TileMap; +using isometricparkfna.Utils; using ImGuiNET.SampleProgram.XNA; @@ -65,6 +68,9 @@ //buggy private static bool enableCulling = false; + private Node tree; + private Node currentNode; + private bool showGrid = true; private static void Main(string[] args) @@ -121,6 +127,21 @@ Content.RootDirectory = "Content"; + tree = new Node(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.", + }, + new Node(new DialogOption { choice = "Okay", 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!" }, + new Node[]{ + new Node(new DialogOption {choice="And I need to keep the forest healthy, too, right?", response="Uhh yeah." }, + new Node(new DialogOption {choice="..." })), + new Node(new DialogOption {choice="Sounds good!", response="I'll check in soon." }) + + }) + ); + + currentNode = tree; + } protected override void Initialize() @@ -471,9 +492,10 @@ } + + - protected override void Draw(GameTime gameTime) { @@ -754,16 +776,44 @@ _imGuiRenderer.BeforeLayout(gameTime); debugWindow.Layout(debugInfo, new Dictionary(),ref show_another_window); - String[] messages = { "Message1", "Message2" }; + //String[] messages = { "Message1", "Message2" }; - if (showInitial && (messageIndex < messages.Length)) + //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 (showInitial) { - ImGui.Begin("Welcome", ref showInitial); + ImGui.Begin("The Governor", ref showInitial); ImGui.PushFont(debugWindow.monoFont); - ImGui.Text(messages[messageIndex]); - if(ImGui.Button("Okay")) + ImGui.TextWrapped(currentNode.data.response); + + + if ((currentNode.children != null) && currentNode.children.Length > 0) { - messageIndex++; + foreach (Node child in currentNode.children) + { + if (ImGui.Button(child.data.choice)) + { + currentNode = child; + } + + } + + } + else + { + if (ImGui.Button("Okay")) { + this.showInitial = false; + + } + + } + + if (currentNode.data.response == null) + { + this.showInitial = false; } ImGui.PopFont(); diff --git a/isometric-park-fna/Utils/MathUtils.cs b/isometric-park-fna/Utils/MathUtils.cs new file mode 100644 --- /dev/null +++ b/isometric-park-fna/Utils/MathUtils.cs @@ -0,0 +1,47 @@ +using System; +namespace isometricparkfna +{ + public class MathUtils + { + public MathUtils() + { + } + + public static bool Between(float val, float x, float y) + { + return ((x < val && val < y) || (y < val && val < x)); + + } + + public static bool Between(int val, int x, int y) + { + return ((x < val && val < y) || (y < val && val < x)); + + } + + protected float Decrement(float value, float delta) + { + float magnitude = Math.Abs(value); + + //If distance from zero is less than our delta, + //go to zero to prevent overshooting: + if (magnitude < delta) + { + return 0.0f; + } + else if (value > 0) + { + return value - delta; + } + else if (value < 0) + { + return value + delta; + } + else + { + return 0.0f; + } + } + + } +} diff --git a/isometric-park-fna/Utils/Node.cs b/isometric-park-fna/Utils/Node.cs new file mode 100644 --- /dev/null +++ b/isometric-park-fna/Utils/Node.cs @@ -0,0 +1,32 @@ +using System; +namespace isometricparkfna.Utils +{ + public class Node + { + public Node[] children; //TODO RECONSIDER?? + + public T data; + + + public Node() + { + } + + public Node(T data) + { + this.data = data; + } + + public Node(T data, Node[] children) + { + this.data = data; + this.children = children; + } + + public Node(T data, Node child) + { + this.data = data; + this.children = new Node[] { child }; + } + } +} diff --git a/isometric-park-fna/isometric-park-fna.csproj b/isometric-park-fna/isometric-park-fna.csproj --- a/isometric-park-fna/isometric-park-fna.csproj +++ b/isometric-park-fna/isometric-park-fna.csproj @@ -36,12 +36,14 @@ - + + + @@ -132,6 +134,9 @@ ..\packages\System.Runtime.CompilerServices.Unsafe.4.4.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll + + +