Show More
Commit Description:
Show a random selection of three stories, rather than one of each.
Commit Description:
Show a random selection of three stories, rather than one of each.
References:
File last commit:
Show/Diff file:
Action:
isometric-park-fna/UI/NewsWindow.cs
141 lines | 6.3 KiB | text/x-csharp | CSharpLexer
141 lines | 6.3 KiB | text/x-csharp | CSharpLexer
r110 | ||||
using ImGuiNET; | ||||
using Num = System.Numerics; | ||||
r115 | using System; | |||
r112 | using System.Linq; | |||
r114 | using System.IO; | |||
using System.Collections.Generic; | ||||
using YamlDotNet.Serialization; | ||||
r110 | ||||
namespace isometricparkfna.UI | ||||
{ | ||||
r111 | public struct NewsItem { | |||
r114 | public string hed; | |||
public string contents; | ||||
r112 | public string source; | |||
r115 | public Dictionary<string, string> variables; | |||
r113 | ||||
public NewsItem Flatten(TraceryNet.Grammar grammar) { | ||||
r115 | ||||
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); | ||||
#if DEBUG | ||||
System.Console.Write(variableString); | ||||
#endif | ||||
r113 | return new NewsItem { | |||
hed = grammar.Flatten(this.hed), | ||||
r115 | contents = grammar.Flatten(contents), | |||
r113 | source = grammar.Flatten(this.source) | |||
}; | ||||
} | ||||
r114 | ||||
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; | ||||
} | ||||
r111 | } | |||
public static class NewsWindow | ||||
r110 | { | |||
r112 | ||||
r114 | public static void Render(ref bool show, ImFontPtr font, Simulation sim, List<NewsItem> content) | |||
r110 | { | |||
if (show) | ||||
{ | ||||
ImGui.PushFont(font); | ||||
ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.None; | ||||
ImGui.PushStyleVar(ImGuiStyleVar.FrameRounding, 0.0f); | ||||
ImGui.PushStyleVar(ImGuiStyleVar.WindowRounding, 0.0f); | ||||
ImGui.PushStyleVar(ImGuiStyleVar.FrameBorderSize, 1.0f); | ||||
ImGui.PushStyleVar(ImGuiStyleVar.TabRounding, 0.0f); | ||||
ImGui.PushStyleColor(ImGuiCol.WindowBg, new Num.Vector4(0.75f, 0.75f, 0.75f, 1f)); | ||||
r112 | ImGui.PushStyleColor(ImGuiCol.Header, new Num.Vector4(0.75f, 0.75f, 0.75f, 1f)); | |||
ImGui.PushStyleColor(ImGuiCol.HeaderHovered, new Num.Vector4(0.75f, 0.75f, 0.75f, 1f)); | ||||
ImGui.PushStyleColor(ImGuiCol.HeaderActive, new Num.Vector4(0.75f, 0.75f, 0.75f, 1f)); | ||||
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, new Num.Vector4(0.75f, 0.75f, 0.75f, 1f)); | ||||
r110 | ||||
var title_bar = new Num.Vector4(0.65f, 0.65f, 0.65f, 1f); | ||||
ImGui.PushStyleColor(ImGuiCol.TitleBg, title_bar); | ||||
ImGui.PushStyleColor(ImGuiCol.TitleBgActive, title_bar); | ||||
ImGui.PushStyleColor(ImGuiCol.TitleBgCollapsed, title_bar); | ||||
ImGui.PushStyleColor(ImGuiCol.Border, new Num.Vector4(0f, 0f, 0f, 1f)); | ||||
ImGui.PushStyleColor(ImGuiCol.BorderShadow, new Num.Vector4(0f, 0f, 0f, 0.5f)); | ||||
ImGui.PushStyleColor(ImGuiCol.Button, new Num.Vector4(0.75f, 0.75f, 0.75f, 1f)); | ||||
ImGui.PushStyleColor(ImGuiCol.Text, new Num.Vector4(0f, 0f, 0f, 1f)); | ||||
r112 | ImGui.Begin("NEWS", ref show, ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoSavedSettings); | |||
r113 | ||||
r110 | ||||
r111 | if (ImGui.BeginTabBar("Sources", 0)) { | |||
r110 | if (ImGui.BeginTabItem("Wire")) { | |||
r127 | foreach (NewsItem story in content.Where( s => (s.source == "Wire" ) ).Take(3)) { | |||
r113 | if (ImGui.TreeNode(story.hed)) { | |||
ImGui.TextWrapped(story.contents); | ||||
ImGui.TreePop(); | ||||
} | ||||
r111 | } | |||
r113 | ImGui.EndTabItem(); | |||
r112 | } | |||
r113 | ImGui.EndTabItem(); | |||
r114 | if (ImGui.BeginTabItem("The Naturalist")) { | |||
r127 | foreach (NewsItem story in content.Where( s => (s.source == "Arborist" ) ).Take(3)) { | |||
r113 | if (ImGui.TreeNode(story.hed)) { | |||
ImGui.TextWrapped(story.contents); | ||||
ImGui.TreePop(); | ||||
} | ||||
r110 | } | |||
r113 | ImGui.EndTabItem(); | |||
r112 | } | |||
if (ImGui.BeginTabItem("All True News")) { | ||||
r127 | foreach (NewsItem story in content.Where( s => (s.source == "True" ) ).Take(3)) { | |||
r113 | if (ImGui.TreeNode(story.hed)) { | |||
ImGui.TextWrapped(story.contents); | ||||
ImGui.TreePop(); | ||||
} | ||||
r112 | } | |||
r113 | ImGui.EndTabItem(); | |||
r110 | } | |||
} | ||||
ImGui.EndTabBar(); | ||||
if (ImGui.Button("Okay")) | ||||
{ | ||||
show = false; | ||||
} | ||||
ImGui.End(); | ||||
ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.Left; | ||||
ImGui.PopStyleVar(4); | ||||
r112 | ImGui.PopStyleColor(12); | |||
r110 | ImGui.PopFont(); | |||
} | ||||
} | ||||
} | ||||
} | ||||