|
|
using System;
|
|
|
using System.Linq;
|
|
|
using System.Collections.Generic;
|
|
|
using ImGuiNET;
|
|
|
using isometricparkfna.Utils;
|
|
|
using TraceryNet;
|
|
|
using Num = System.Numerics;
|
|
|
using Encompass;
|
|
|
|
|
|
using isometricparkfna.Engines;
|
|
|
using isometricparkfna.Components;
|
|
|
using isometricparkfna.Messages;
|
|
|
|
|
|
#nullable enable
|
|
|
|
|
|
namespace isometricparkfna.UI
|
|
|
{
|
|
|
|
|
|
|
|
|
//#nullable enable
|
|
|
public struct DialogOption
|
|
|
{
|
|
|
public String? choice;
|
|
|
public String response;
|
|
|
public String speaker;
|
|
|
}
|
|
|
|
|
|
|
|
|
public static class DialogTrees
|
|
|
{
|
|
|
|
|
|
public static Node<DialogOption> introTree = new Node<DialogOption>(
|
|
|
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. B opens the budget and F lets you adjust Forest Policy.",
|
|
|
speaker = "The Governor"
|
|
|
},
|
|
|
new Node<DialogOption>(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!",
|
|
|
speaker = "The Governor"
|
|
|
},
|
|
|
new Node<DialogOption>[]{
|
|
|
new Node<DialogOption>(new DialogOption {choice="And I need to keep the forest healthy, too, right?", response="Uhh yeah.", speaker = "The Governor" },
|
|
|
new Node<DialogOption>(new DialogOption {choice="...", speaker = "The Governor"})),
|
|
|
new Node<DialogOption>(new DialogOption {choice="Sounds good!", response="I'll check in soon.", speaker = "The Governor" })
|
|
|
|
|
|
})
|
|
|
);
|
|
|
|
|
|
public static Node<DialogOption> testTree = new Node<DialogOption>(
|
|
|
new DialogOption
|
|
|
{
|
|
|
response = "#addressGreetingFormal#",
|
|
|
speaker = "#assistantName#"
|
|
|
},
|
|
|
new Node<DialogOption>[]{
|
|
|
new Node<DialogOption>(new DialogOption {choice="Call me #playerCasual#", response="Sure",
|
|
|
speaker = "#assistantName#" }),
|
|
|
new Node<DialogOption>(new DialogOption {choice="Hi.", response="Bye!",
|
|
|
speaker = "#assistantName#" }),
|
|
|
new Node<DialogOption>(new DialogOption {choice="How are you?", response="#howdoing#",
|
|
|
speaker = "#assistantName#" })
|
|
|
|
|
|
}
|
|
|
);
|
|
|
|
|
|
public static Node<DialogOption> testTree2 = new Node<DialogOption>(
|
|
|
new DialogOption
|
|
|
{
|
|
|
response = "#whatever#",
|
|
|
speaker = "#assistantName#"
|
|
|
},
|
|
|
|
|
|
new Node<DialogOption>[]{
|
|
|
new Node<DialogOption>(new DialogOption {choice="Hi.", response="Bye!",
|
|
|
speaker = "#assistantName#" }),
|
|
|
new Node<DialogOption>(new DialogOption {choice="How are you?", response="#howdoing#",
|
|
|
speaker = "#assistantName#" })
|
|
|
|
|
|
}
|
|
|
);
|
|
|
|
|
|
|
|
|
public static Node<DialogOption> flatten (Node<DialogOption> node, Grammar grammar) {
|
|
|
|
|
|
DialogOption new_data = new DialogOption
|
|
|
{
|
|
|
choice = node.data.choice != null ? grammar.Flatten(node.data.choice) : node.data.choice,
|
|
|
response = grammar.Flatten(node.data.response),
|
|
|
speaker = grammar.Flatten(node.data.speaker)
|
|
|
};
|
|
|
|
|
|
|
|
|
if (node.children != null) {
|
|
|
List<Node<DialogOption>> new_children = new List<Node<DialogOption>>();
|
|
|
foreach (Node<DialogOption> child in node.children)
|
|
|
{
|
|
|
new_children.Add(flatten(child, grammar));
|
|
|
}
|
|
|
|
|
|
return new Node<DialogOption>(new_data, new_children.ToArray());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return new Node<DialogOption>(new_data);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public static class DialogInterface
|
|
|
{
|
|
|
|
|
|
public static bool hadFocus = false;
|
|
|
public static void RenderDialog(Entity entity,
|
|
|
ImGuiWindowBridgeEngine bridgeEngine, ref bool show, ref bool paused, ImFontPtr font, DialogComponent dialogComponent)
|
|
|
{
|
|
|
if (show)
|
|
|
{
|
|
|
ImGui.PushFont(font);
|
|
|
ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.None;
|
|
|
|
|
|
StyleSets.defaultSet.push();
|
|
|
|
|
|
ImGui.SetNextWindowSize(new Num.Vector2(400, 200));
|
|
|
if(DialogInterface.hadFocus)
|
|
|
{
|
|
|
ImGui.PushStyleColor(ImGuiCol.Text, StyleSets.white);
|
|
|
}
|
|
|
|
|
|
ImGui.Begin(dialogComponent.CurrentSpeaker, ref show, ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoSavedSettings);
|
|
|
if (DialogInterface.hadFocus)
|
|
|
{
|
|
|
ImGui.PopStyleColor();
|
|
|
}
|
|
|
DialogInterface.hadFocus = ImGui.IsWindowFocused();
|
|
|
|
|
|
|
|
|
if (dialogComponent.CurrentDialog != null)
|
|
|
{
|
|
|
string messageText = dialogComponent.CurrentDialog;
|
|
|
ImGui.TextWrapped(messageText);
|
|
|
}
|
|
|
|
|
|
if ((dialogComponent.Options != null) && dialogComponent.Options.Count > 0)
|
|
|
{
|
|
|
for(int i = 0; i < dialogComponent.Options.Count; i++)
|
|
|
{
|
|
|
string buttonText = dialogComponent.Options[i];
|
|
|
if (ImGui.Button(buttonText))
|
|
|
{
|
|
|
bridgeEngine.dialogChoiceMessages.Add(new DialogChoiceMessage {
|
|
|
|
|
|
Entity = entity,
|
|
|
Choice = i });
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (ImGui.Button("Okay"))
|
|
|
{
|
|
|
show = false;
|
|
|
paused = false;
|
|
|
bridgeEngine.dialogChoiceMessages.Add(new DialogChoiceMessage {
|
|
|
|
|
|
Entity = entity,
|
|
|
Choice = -1 });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (dialogComponent.CurrentDialog == null)
|
|
|
{
|
|
|
show = false;
|
|
|
paused = false;
|
|
|
|
|
|
}
|
|
|
ImGui.End();
|
|
|
ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.Left;
|
|
|
StyleSets.defaultSet.pop();
|
|
|
ImGui.PopFont();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|