Show More
Commit Description:
Fix rendering of selected areas.
Commit Description:
Fix rendering of selected areas.
File last commit:
Show/Diff file:
Action:
isometric-park-fna/UI/ContractsWindow.cs
192 lines | 8.1 KiB | text/x-csharp | CSharpLexer
using System.Collections.Generic;
using System.Linq;
using ImGuiNET;
using isometricparkfna.Components;
using isometricparkfna.Engines;
using isometricparkfna.Messages;
using Num = System.Numerics;
using Encompass;
namespace isometricparkfna.UI
{
public static class ContractsWindow
{
public static bool show_all;
private static (Entity entity, string name, ContractStatus status, decimal amount, string delta_trees) selected;
public static void Render(ImFontPtr font, ImGuiWindowBridgeEngine engine,
List<(Entity entity, string name, ContractStatus status, decimal amount, string delta_trees)> contracts)
{
bool newShow = true;
// Entity newSelected;
var grey = new Num.Vector4(0.75f, 0.75f, 0.75f, 1f);
var darkgrey = new Num.Vector4(0.45f, 0.45f, 0.45f, 1f);
var black = new Num.Vector4(0f, 0f, 0f, 1f);
var title_bar = new Num.Vector4(0.65f, 0.65f, 0.65f, 1f);
if (newShow)
{
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, grey);
ImGui.PushStyleColor(ImGuiCol.FrameBg, grey);
ImGui.PushStyleColor(ImGuiCol.FrameBgHovered, grey);
ImGui.PushStyleColor(ImGuiCol.Header, darkgrey);
ImGui.PushStyleColor(ImGuiCol.HeaderHovered, darkgrey);
ImGui.PushStyleColor(ImGuiCol.HeaderActive, darkgrey);
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, grey);
ImGui.PushStyleColor(ImGuiCol.CheckMark, black);
ImGui.PushStyleColor(ImGuiCol.TitleBg, title_bar);
ImGui.PushStyleColor(ImGuiCol.TitleBgActive, title_bar);
ImGui.PushStyleColor(ImGuiCol.TitleBgCollapsed, title_bar);
ImGui.PushStyleColor(ImGuiCol.Border, black);
ImGui.PushStyleColor(ImGuiCol.BorderShadow, black);
ImGui.PushStyleColor(ImGuiCol.Button, grey);
ImGui.PushStyleColor(ImGuiCol.Text, black);
ImGui.SetNextWindowSize(new Num.Vector2(320, 340));
ImGui.Begin("Contracts", ref newShow, ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoSavedSettings);
ImGui.ListBoxHeader("##Contracts:", new Num.Vector2(300, 150));
foreach (var contract in contracts.Where((contract) => ((!(new[] {ContractStatus.Expired, ContractStatus.Broken, ContractStatus.Rejected}.Contains(contract.status))
|| ContractsWindow.show_all ))))
{
if (ImGui.Selectable(contract.name, ContractsWindow.selected.entity== contract.entity))
{
ContractsWindow.selected.entity= contract.entity;
// newSelected = contract.entity;
}
if (ContractsWindow.selected.entity== contract.entity)
{
ContractsWindow.selected = contract;
}
ImGui.SameLine();
switch (contract.status)
{
case ContractStatus.Proposed:
ImGui.TextColored(new Num.Vector4(0.25f, 0.25f, 0.95f, 1f), contract.status.ToString());
break;
case ContractStatus.Active:
case ContractStatus.Accepted:
ImGui.TextColored(new Num.Vector4(0.25f, 0.95f, 0.25f, 1f), contract.status.ToString());
break;
case ContractStatus.Rejected:
case ContractStatus.Broken:
case ContractStatus.Expired:
// if (ContractsWindow.show_all)
// {
// ImGui.TextColored(new Num.Vector4(0.95f, 0.25f, 0.25f, 1f), contract.status.ToString());
// }
ImGui.TextColored(new Num.Vector4(0.95f, 0.25f, 0.25f, 1f), contract.status.ToString());
break;
case ContractStatus.Completed:
ImGui.TextColored(new Num.Vector4(0.25f, 0.25f, 0.25f, 1f), contract.status.ToString());
break;
default:
break;
}
}
ImGui.ListBoxFooter();
ImGui.Checkbox("Show All", ref show_all);
ImGui.Separator();
ImGui.Text(string.Format("Amount: ${0}/mo.", ContractsWindow.selected.amount));
if (ContractsWindow.selected.delta_trees != null)
{
ImGui.Text("Sustainability: ");
ImGui.SameLine();
var color = new Num.Vector4(1f, 1f, 1f, 1f);
switch (ContractsWindow.selected.delta_trees)
{
case "Unsustainable":
color = new Num.Vector4(0.95f, 0.25f, 0.25f, 1f);
break;
case "Restoration":
color = new Num.Vector4(0.25f, 0.95f, 0.25f, 1f);
break;
case "Moderately unsustainable":
case "Somewhat unsustainable":
color = new Num.Vector4(0.95f, 0.65f, 0.25f, 1f);
break;
}
ImGui.TextColored(color, ContractsWindow.selected.delta_trees);
}
if (selected.status == ContractStatus.Proposed)
{
if (ImGui.Button("Accept"))
{
System.Console.Write(string.Format("{0} selected", ContractsWindow.selected.entity));
engine.contractStatusMessages.Add(new ChangeContractStatusMessage { Entity = ContractsWindow.selected.entity, newStatus = ContractStatus.Accepted });
}
ImGui.SameLine();
if (ImGui.Button("Reject"))
{
System.Console.Write(string.Format("{0} rejected", ContractsWindow.selected.entity));
engine.contractStatusMessages.Add(new ChangeContractStatusMessage { Entity = ContractsWindow.selected.entity, newStatus = ContractStatus.Rejected });
}
}
else if (selected.status == ContractStatus.Accepted)
{
if (ImGui.Button("Cancel"))
{
System.Console.Write(string.Format("{0} canceled", ContractsWindow.selected.entity));
engine.contractStatusMessages.Add(new ChangeContractStatusMessage { Entity = ContractsWindow.selected.entity, newStatus = ContractStatus.Broken });
}
}
ImGui.Separator();
if (ImGui.Button("Okay"))
{
newShow = false;
}
ImGui.End();
ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.Left;
ImGui.PopStyleVar(4);
ImGui.PopStyleColor(16);
ImGui.PopFont();
}
if (!newShow)
{
engine.messages.Add(new ToggleWindowMessage { Window = Window.Contracts });
}
engine.selectedMessages.Add(new SelectMessage { Entity = selected.entity });
}
}
}