|
|
|
|
|
using ImGuiNET;
|
|
|
|
|
|
using Num = System.Numerics;
|
|
|
using System;
|
|
|
using System.Linq;
|
|
|
using System.IO;
|
|
|
using System.Collections.Generic;
|
|
|
using YamlDotNet.Serialization;
|
|
|
using Encompass;
|
|
|
|
|
|
using isometricparkfna.Messages;
|
|
|
using isometricparkfna.Engines;
|
|
|
|
|
|
namespace isometricparkfna.UI
|
|
|
{
|
|
|
|
|
|
public struct NewsItem {
|
|
|
public string hed;
|
|
|
public string contents;
|
|
|
public string source;
|
|
|
public Dictionary<string, string> variables;
|
|
|
|
|
|
public NewsItem Flatten(TraceryNet.Grammar grammar) {
|
|
|
|
|
|
var variableString = "#";
|
|
|
|
|
|
if (this.variables != null) {
|
|
|
foreach (var variable in this.variables) {
|
|
|
variableString += String.Format("[{0}:{1}]", variable.Key, variable.Value);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
variableString += "vars# ";
|
|
|
var result = grammar.Flatten(variableString);
|
|
|
// Logging.Trace(String.Format("{0}: {1}", variableString, result));
|
|
|
|
|
|
return new NewsItem {
|
|
|
hed = grammar.Flatten(this.hed),
|
|
|
contents = grammar.Flatten(contents),
|
|
|
source = grammar.Flatten(this.source)
|
|
|
};
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static List<NewsItem> FromYaml(string yamlString) {
|
|
|
var input = new StringReader(yamlString);
|
|
|
|
|
|
var deserializer = new DeserializerBuilder()
|
|
|
.Build();
|
|
|
|
|
|
//Dictionary<string, string>
|
|
|
var items = deserializer.Deserialize<List<NewsItem>>(input);
|
|
|
|
|
|
return items;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public static class NewsWindow
|
|
|
{
|
|
|
|
|
|
public static bool had_focus = false;
|
|
|
|
|
|
public static void Render(bool show, ImFontPtr font, Simulation sim, ImGuiWindowBridgeEngine engine)
|
|
|
{
|
|
|
bool newShow = show;
|
|
|
if (show)
|
|
|
{
|
|
|
ImGui.PushFont(font);
|
|
|
|
|
|
ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.None;
|
|
|
|
|
|
StyleSet.pushStyleVarSet(StyleSet.defaultWindowVars);
|
|
|
StyleSet.pushColorSet(StyleSet.defaultWindowColors);
|
|
|
|
|
|
|
|
|
ImGui.SetNextWindowSize(new Num.Vector2(400, 400));
|
|
|
|
|
|
if(NewsWindow.had_focus)
|
|
|
{
|
|
|
ImGui.PushStyleColor(ImGuiCol.Text, StyleSet.white);
|
|
|
}
|
|
|
ImGui.Begin("NEWS", ref newShow, ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoSavedSettings);
|
|
|
|
|
|
if (NewsWindow.had_focus)
|
|
|
{
|
|
|
ImGui.PopStyleColor();
|
|
|
}
|
|
|
NewsWindow.had_focus = ImGui.IsWindowFocused();
|
|
|
|
|
|
var content = sim.latestNewsItems;
|
|
|
|
|
|
|
|
|
if (ImGui.BeginTabBar("Sources", 0)) {
|
|
|
|
|
|
|
|
|
if (ImGui.BeginTabItem("Wire")) {
|
|
|
|
|
|
foreach (NewsItem story in content.Where( s => (s.source == "Wire" ) ).Take(3)) {
|
|
|
if (ImGui.TreeNode(story.hed)) {
|
|
|
ImGui.TextWrapped(story.contents);
|
|
|
ImGui.TreePop();
|
|
|
}
|
|
|
}
|
|
|
ImGui.EndTabItem();
|
|
|
}
|
|
|
ImGui.EndTabItem();
|
|
|
if (ImGui.BeginTabItem("The Naturalist")) {
|
|
|
foreach (NewsItem story in content.Where( s => (s.source == "Arborist" ) ).Take(3)) {
|
|
|
if (ImGui.TreeNode(story.hed)) {
|
|
|
ImGui.TextWrapped(story.contents);
|
|
|
ImGui.TreePop();
|
|
|
}
|
|
|
}
|
|
|
ImGui.EndTabItem();
|
|
|
}
|
|
|
if (ImGui.BeginTabItem("All True News")) {
|
|
|
foreach (NewsItem story in content.Where( s => (s.source == "True" ) ).Take(3)) {
|
|
|
if (ImGui.TreeNode(story.hed)) {
|
|
|
ImGui.TextWrapped(story.contents);
|
|
|
ImGui.TreePop();
|
|
|
}
|
|
|
}
|
|
|
ImGui.EndTabItem();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
ImGui.EndTabBar();
|
|
|
|
|
|
|
|
|
if (ImGui.Button("Okay"))
|
|
|
{
|
|
|
show = false;
|
|
|
}
|
|
|
|
|
|
ImGui.End();
|
|
|
ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.Left;
|
|
|
|
|
|
StyleSet.popStyleVarSet(StyleSet.defaultWindowVars);
|
|
|
StyleSet.popColorSet(StyleSet.defaultWindowColors);
|
|
|
ImGui.PopFont();
|
|
|
}
|
|
|
|
|
|
if (show != newShow)
|
|
|
{
|
|
|
engine.typeMessages.Add(new ToggleWindowTypeMessage {Window = Window.News });
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|