|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
|
|
|
using ImGuiNET;
|
|
|
using ImGuiNET.SampleProgram.XNA;
|
|
|
|
|
|
using isometricparkfna.Components;
|
|
|
using isometricparkfna.Engines;
|
|
|
using isometricparkfna.Messages;
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
|
using Num = System.Numerics;
|
|
|
|
|
|
using Encompass;
|
|
|
|
|
|
namespace isometricparkfna.UI
|
|
|
{
|
|
|
public static class ContractWindow
|
|
|
{
|
|
|
|
|
|
private static ImageMap map;
|
|
|
private static IntPtr _imGuiTexture;
|
|
|
|
|
|
private static bool show = false;
|
|
|
|
|
|
private static Dictionary<string, bool> hadFocus = new Dictionary<string, bool>();
|
|
|
|
|
|
public static void LoadContent(ImGuiRenderer _imGuiRenderer, ImageMap map)
|
|
|
{
|
|
|
ContractWindow.map = map;
|
|
|
|
|
|
var _xnaTexture = ImageMap.ImageMapTexture;
|
|
|
ContractWindow._imGuiTexture = _imGuiRenderer.BindTexture(_xnaTexture);
|
|
|
}
|
|
|
|
|
|
public static void Render(ImFontPtr font, ImFontPtr italicFont, ImGuiWindowBridgeEngine engine, Entity entity, string name, string description, ContractStatus status, decimal amount, string delta_trees, int area_size, int imageIndex, Vector2 square)
|
|
|
|
|
|
{
|
|
|
bool newShow = true;
|
|
|
|
|
|
if (newShow)
|
|
|
{
|
|
|
ImGui.PushFont(font);
|
|
|
|
|
|
ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.None;
|
|
|
StyleSet.pushStyleVarSet(StyleSet.defaultWindowVars);
|
|
|
StyleSet.pushColorSet(StyleSet.defaultWindowColors);
|
|
|
ImGui.SetNextWindowSize(new Num.Vector2(320, 420));
|
|
|
|
|
|
var title = string.Format("Contract {0} ## {1}", name, entity.ID);
|
|
|
|
|
|
if (ContractWindow.hadFocus.ContainsKey(title) &&
|
|
|
ContractWindow.hadFocus[title])
|
|
|
{
|
|
|
ImGui.PushStyleColor(ImGuiCol.Text, StyleSet.white);
|
|
|
}
|
|
|
|
|
|
ImGui.Begin(name, ref newShow,
|
|
|
ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoSavedSettings);
|
|
|
|
|
|
if (ContractWindow.hadFocus.ContainsKey(title) &&
|
|
|
ContractWindow.hadFocus[title])
|
|
|
{
|
|
|
ImGui.PopStyleColor();
|
|
|
}
|
|
|
if(ContractWindow.hadFocus.ContainsKey(title))
|
|
|
{
|
|
|
ContractWindow.hadFocus[title] = ImGui.IsWindowFocused();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ContractWindow.hadFocus.Add(title, ImGui.IsWindowFocused());
|
|
|
}
|
|
|
|
|
|
ImGui.Image(_imGuiTexture, new Num.Vector2(250, 200), map.GetSourceUVStart(imageIndex), map.GetSourceUVEnd(imageIndex), Num.Vector4.One, Num.Vector4.Zero); // Here, the previously loaded texture is used
|
|
|
|
|
|
ImGui.PushFont(italicFont);
|
|
|
ImGui.TextWrapped(description);
|
|
|
ImGui.PopFont();
|
|
|
|
|
|
ImGui.Separator();
|
|
|
switch (status)
|
|
|
{
|
|
|
case ContractStatus.Proposed:
|
|
|
ImGui.TextColored(new Num.Vector4(0.25f, 0.25f, 0.95f, 1f), status.ToString());
|
|
|
break;
|
|
|
case ContractStatus.Active:
|
|
|
case ContractStatus.Accepted:
|
|
|
ImGui.TextColored(new Num.Vector4(0.25f, 0.95f, 0.25f, 1f), 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), status.ToString());
|
|
|
break;
|
|
|
case ContractStatus.Completed:
|
|
|
ImGui.TextColored(new Num.Vector4(0.25f, 0.25f, 0.25f, 1f), status.ToString());
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
ImGui.Text(string.Format("Amount: ${0}/mo.", amount));
|
|
|
ImGui.Text(string.Format("Size: {0} acres", area_size));
|
|
|
|
|
|
if (delta_trees != null)
|
|
|
{
|
|
|
ImGui.Text("Sustainability: ");
|
|
|
ImGui.SameLine();
|
|
|
ImGui.TextDisabled("(?)");
|
|
|
if (ImGui.IsItemHovered())
|
|
|
{
|
|
|
var rect = ImGui.GetItemRectMax();
|
|
|
ImGui.SetNextWindowPos(rect + new Num.Vector2(15, 0));
|
|
|
ImGui.BeginTooltip();
|
|
|
ImGui.Text("Are logged trees replaced?");
|
|
|
ImGui.EndTooltip();
|
|
|
}
|
|
|
|
|
|
|
|
|
ImGui.SameLine();
|
|
|
var color = new Num.Vector4(1f, 1f, 1f, 1f);
|
|
|
switch (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, delta_trees);
|
|
|
}
|
|
|
|
|
|
ContractStatusButtons(engine, entity, status);
|
|
|
|
|
|
ImGui.Separator();
|
|
|
|
|
|
if (ImGui.Button("Okay"))
|
|
|
{
|
|
|
newShow = false;
|
|
|
}
|
|
|
ImGui.SameLine();
|
|
|
if (ImGui.Button("Jump To"))
|
|
|
{
|
|
|
int adjustedx = (int)square.X;
|
|
|
int adjustedy = (int)square.Y;
|
|
|
|
|
|
int screenx = (adjustedx - adjustedy) * Tile.TileSpriteWidth / 2;
|
|
|
int screeny = (adjustedx + adjustedy) * Tile.TileSpriteHeight / 2;
|
|
|
|
|
|
engine.jumpCameraMessages.Add(new JumpCameraMessage {Movement = new Vector2(screenx, screeny)});
|
|
|
}
|
|
|
// Logging.Trace("Almost done.");
|
|
|
|
|
|
ImGui.End();
|
|
|
ImGui.GetStyle().WindowMenuButtonPosition = ImGuiDir.Left;
|
|
|
StyleSet.popStyleVarSet(StyleSet.defaultWindowVars);
|
|
|
StyleSet.popColorSet(StyleSet.defaultWindowColors);
|
|
|
ImGui.PopFont();
|
|
|
|
|
|
// Logging.Trace("Finished.");
|
|
|
}
|
|
|
|
|
|
if (!newShow)
|
|
|
{
|
|
|
engine.messages.Add(new ToggleWindowMessage {Window = Window.Contract, Entity = entity });
|
|
|
}
|
|
|
|
|
|
engine.selectedMessages.Add(new SelectMessage { Entity = entity });
|
|
|
|
|
|
}
|
|
|
|
|
|
public static void ContractStatusButtons(ImGuiWindowBridgeEngine engine, Entity entity, ContractStatus status)
|
|
|
{
|
|
|
if (status == ContractStatus.Proposed)
|
|
|
{
|
|
|
if (ImGui.Button("Accept"))
|
|
|
{
|
|
|
System.Console.Write(string.Format("{0} selected", entity));
|
|
|
|
|
|
engine.contractStatusMessages.Add(new ChangeContractStatusMessage { Entity = entity, newStatus = ContractStatus.Accepted });
|
|
|
|
|
|
}
|
|
|
ImGui.SameLine();
|
|
|
if (ImGui.Button("Reject"))
|
|
|
{
|
|
|
System.Console.Write(string.Format("{0} rejected", entity));
|
|
|
|
|
|
engine.contractStatusMessages.Add(new ChangeContractStatusMessage { Entity = entity, newStatus = ContractStatus.Rejected });
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
else if (status == ContractStatus.Accepted)
|
|
|
{
|
|
|
if (ImGui.Button("Cancel"))
|
|
|
{
|
|
|
System.Console.Write(string.Format("{0} canceled", entity));
|
|
|
|
|
|
engine.contractStatusMessages.Add(new ChangeContractStatusMessage { Entity = entity, newStatus = ContractStatus.Broken });
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|