Skip to content

Commit 4110b2b

Browse files
authored
Merge pull request #1 from Theadd/develop-pollution-tool
pollution in game overview + toolbar bg fix
2 parents beae74b + 7eb6d1f commit 4110b2b

File tree

6 files changed

+184
-31
lines changed

6 files changed

+184
-31
lines changed

GUITools.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace DevTools.Humankind.GUITools
66
{
7-
[BepInPlugin(PLUGIN_GUID, "GUITools", "1.2.0.0")]
7+
[BepInPlugin(PLUGIN_GUID, "GUITools", "1.2.1.0")]
88
[BepInDependency("Modding.Humankind.DevTools")]
99
[BepInDependency("DevTools.Humankind.SharedAssets")]
1010
public class GUITools : BaseUnityPlugin

MainTools.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public static void Main()
5656

5757
// Maps [ESC] key to: GodMode.Enabled = false
5858
// HumankindDevTools.RegisterAction(new KeyboardShortcut(UnityEngine.KeyCode.Escape), "CancelGodMode", CancelGodMode);
59+
60+
// ToggleGameOverviewWindow();
5961
}
6062

6163
public static void ToggleHideToolbarWindow() => GlobalSettings.HideToolbarWindow.Value = !GlobalSettings.HideToolbarWindow.Value;

UI/MainToolbar.cs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class MainToolbar : FloatingToolWindow
1313
public override bool ShouldRestoreLastWindowPosition => true;
1414
public override string WindowTitle { get; set; } = "TOOLBAR";
1515
public override Rect WindowRect { get; set; } = new Rect (30, 290, 170, 600);
16-
private Color activeBackground = new Color(0.8f, 0.7f, 0.9f, 0.7f);
16+
public static Color ActiveToolBackgroundTint { get; set; } = new Color(0.8f, 0.7f, 0.9f, 0.7f);
1717

1818
#region FloatingToolWindow derived classes
1919

@@ -67,18 +67,29 @@ public void RestoreVisibleWindows()
6767

6868
}
6969

70+
public static Texture2D TintableWhiteTexture { get; set; } =
71+
Utils.CreateSinglePixelTexture2D(new Color(1f, 1f, 1f, 0.8f));
72+
7073
public GUIStyle TintableBackgroundStyle { get; set; } = new GUIStyle(UIController.DefaultSkin.FindStyle("PopupWindow.Row"))
7174
{
7275
padding = new RectOffset(0, 0, 0, 0),
7376
margin = new RectOffset(0, 0, 0, 0),
7477
border = new RectOffset(0, 0, 0, 0),
7578
overflow = new RectOffset(0, 0, 0, 0),
7679
normal = new GUIStyleState() {
77-
background = Utils.CreateSinglePixelTexture2D(new Color(1f, 1f, 1f, 0.8f)),
80+
background = TintableWhiteTexture,
7881
textColor = Color.white
7982
},
8083
hover = new GUIStyleState() {
81-
background =null,
84+
background = TintableWhiteTexture,
85+
textColor = Color.white
86+
},
87+
active = new GUIStyleState() {
88+
background = TintableWhiteTexture,
89+
textColor = Color.white
90+
},
91+
onNormal = new GUIStyleState() {
92+
background = TintableWhiteTexture,
8293
textColor = Color.white
8394
}
8495
};
@@ -88,11 +99,11 @@ public void RestoreVisibleWindows()
8899
margin = new RectOffset(0, 0, 0, 0),
89100
};
90101

91-
private Color bgTintColor = new Color32(205, 196, 174, 244);
102+
public static Color BackgroundTintColor { get; set; } = new Color32(205, 196, 174, 244);
92103

93104
public override void OnDrawUI()
94105
{
95-
GUI.backgroundColor = bgTintColor;
106+
GUI.backgroundColor = BackgroundTintColor;
96107
GUILayout.BeginHorizontal(TintableBackgroundStyle);
97108

98109
GUI.backgroundColor = Color.black;
@@ -121,7 +132,7 @@ private void OnDrawCheatingTools()
121132
GUILayout.Label("<color=#000000AA>C H E A T I N G</color> T O O L S",
122133
"PopupWindow.Sidebar.Heading");
123134

124-
GUI.backgroundColor = activeBackground;
135+
GUI.backgroundColor = ActiveToolBackgroundTint;
125136
if (GlobalSettings.MilitaryTool.Value)
126137
if (DrawItem<MilitaryToolsWindow>(MilitaryTool, "Military"))
127138
Open<MilitaryToolsWindow>(window => MilitaryTool = window);
@@ -153,7 +164,7 @@ private void OnDrawDeveloperTools()
153164
GUILayout.Label("<color=#000000AA>D E V E L O P E R</color> T O O L S",
154165
"PopupWindow.Sidebar.Heading");
155166

156-
GUI.backgroundColor = activeBackground;
167+
GUI.backgroundColor = ActiveToolBackgroundTint;
157168
if (GlobalSettings.AutoTurnTool.Value)
158169
if (DrawItem<AutoTurnToolWindow>(AutoTurnTool, "Auto Turn"))
159170
Open<AutoTurnToolWindow>(window => AutoTurnTool = window);
@@ -189,7 +200,7 @@ private void OnDrawProfilingTools()
189200
GUILayout.Label("<color=#000000AA>P R O F I L I N G</color> T O O L S",
190201
"PopupWindow.Sidebar.Heading");
191202

192-
GUI.backgroundColor = activeBackground;
203+
GUI.backgroundColor = ActiveToolBackgroundTint;
193204
if (GlobalSettings.FramerateTool.Value)
194205
if (DrawItem<FramerateToolWindow>(FramerateTool, "Framerate"))
195206
Open<FramerateToolWindow>(window => FramerateTool = window);
@@ -217,7 +228,7 @@ private void OnDrawExperimentalTools()
217228
{
218229
GUILayout.Label("E X P <color=#000000AA>E R I M E N T A L</color>", "PopupWindow.Sidebar.Heading");
219230

220-
GUI.backgroundColor = activeBackground;
231+
GUI.backgroundColor = ActiveToolBackgroundTint;
221232
if (GlobalSettings.AITool.Value)
222233
if (DrawItem<AIToolWindow>(AITool, "AI Tools"))
223234
Open<AIToolWindow>(window => AITool = window);

UI/Statistics/GameStatisticsGrid.cs

Lines changed: 84 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,62 @@ public class GameStatisticsGrid : DrawableGrid<EmpireSnapshot>
3535
private int CurrentIndex;
3636
private int CurrentEmpireIndex;
3737

38-
public void Draw(GameStatsSnapshot snapshot)
38+
public void SetSnapshot(GameStatsSnapshot snapshot)
3939
{
4040
CurrentSnapshot = snapshot;
4141
if (DisplayOrder == null || DisplayOrder.Length != snapshot.Empires.Length)
4242
DisplayOrder = snapshot.Empires.Select((e, i) => i).ToArray();
43+
}
44+
45+
public void DrawCommonHeader()
46+
{
47+
Row(StaticRowStyle);
48+
RowHeader(" ", CellSpan6);
49+
50+
RowHeader("TURN", CellSpan1);
51+
DrawCell(CurrentSnapshot.Turn.ToString(), CellSpan1);
52+
53+
RowHeader("ATMOSPHERE POLLUTION", CellSpan5);
54+
DrawCell("<size=10>LEVEL " + CurrentSnapshot.AtmospherePollutionLevel + "</size>", CellSpan2);
55+
DrawCell("" +
56+
"<b>" + CurrentSnapshot.AtmospherePollutionStock + "</b>" +
57+
(CurrentSnapshot.AtmospherePollutionNet >= 0 ? " ( +" : " ( ") +
58+
CurrentSnapshot.AtmospherePollutionNet + " " + PerTurn + " )",
59+
CellSpan4);
60+
CellButton("<size=10>-2K</size>", () =>
61+
{
62+
SandboxManager.PostOrder((Order)new EditorOrderAddOrRemoveAtmospherePollution()
63+
{
64+
Delta = -2000
65+
}, (int)Snapshots.GameSnapshot.PresentationData.LocalEmpireInfo.EmpireIndex);
66+
}, CellSpan1);
67+
CellButton("<size=10>-250</size>", () =>
68+
{
69+
SandboxManager.PostOrder((Order)new EditorOrderAddOrRemoveAtmospherePollution()
70+
{
71+
Delta = -250
72+
}, (int)Snapshots.GameSnapshot.PresentationData.LocalEmpireInfo.EmpireIndex);
73+
}, CellSpan1);
74+
CellButton("<size=10>+250</size>", () =>
75+
{
76+
SandboxManager.PostOrder((Order)new EditorOrderAddOrRemoveAtmospherePollution()
77+
{
78+
Delta = 250
79+
}, (int)Snapshots.GameSnapshot.PresentationData.LocalEmpireInfo.EmpireIndex);
80+
}, CellSpan1);
81+
CellButton("<size=10>+2K</size>", () =>
82+
{
83+
SandboxManager.PostOrder((Order)new EditorOrderAddOrRemoveAtmospherePollution()
84+
{
85+
Delta = 2000
86+
}, (int)Snapshots.GameSnapshot.PresentationData.LocalEmpireInfo.EmpireIndex);
87+
}, CellSpan1);
88+
89+
EndRow();
90+
}
4391

92+
public void Draw()
93+
{
4494
DrawRow(" ", StaticRowStyle, (empire, index, empireIndex) =>
4595
{
4696
var headerText = empireIndex == CurrentSnapshot.LocalEmpireIndex ?
@@ -66,6 +116,10 @@ public void Draw(GameStatsSnapshot snapshot)
66116
DrawRow("CITIZENS, EMPIRE POPULATION", empire =>
67117
DrawCell(empire.SettlementsPopulation, CellSpan2)
68118
.DrawCell(empire.EmpirePopulation, CellSpan2));
119+
DrawRow("POLLUTION", empire =>
120+
DrawCell("" + empire.PollutionStock, CellSpan2)
121+
.DrawCell((int.Parse(empire.PollutionNet) >= 0 ? "+" : "") +
122+
empire.PollutionNet + " " + PerTurn, CellSpan2));
69123

70124
DrawSection("<size=12><b>MILITARY STATS</b></size>");
71125
DrawRow("COMBAT STRENGTH", empire => DrawCell(empire.CombatStrength, CellSpan4));
@@ -117,18 +171,41 @@ public void Draw(GameStatsSnapshot snapshot)
117171
GUI.enabled = (empireIndex != CurrentSnapshot.LocalEmpireIndex);
118172
CellButton("<size=10>SWITCH EMPIRE</size>", (e, i, eIndex) =>
119173
{
120-
Services.GetService<INetworkingService>()?.CreateMessageSender().SendLocalMessage(
121-
(LocalMessage) new SandboxControlMessage(
122-
(ISandboxControlInstruction) new ChangeLocalEmpireInstruction(eIndex)
123-
)
124-
);
125-
HumankindGame.Empires.Where(emp => emp.EmpireIndex == eIndex).Settlements().IsCapital().First().CenterToCamera();
174+
try
175+
{
176+
Services.GetService<INetworkingService>()?.CreateMessageSender().SendLocalMessage(
177+
(LocalMessage) new SandboxControlMessage(
178+
(ISandboxControlInstruction) new ChangeLocalEmpireInstruction(eIndex)
179+
)
180+
);
181+
HumankindGame.Empires.Where(emp => emp.EmpireIndex == eIndex).Settlements().IsCapital().First()
182+
.CenterToCamera();
183+
}
184+
catch (Exception)
185+
{
186+
HumankindGame.Empires.Where(emp => emp.EmpireIndex == eIndex).Armies().First().CenterToCamera();
187+
}
126188
}, CellSpan4);
127189
GUI.enabled = true;
128190
});
129191

130192
}
131193

194+
public void CellButton(string text, Action action, params GUILayoutOption[] options)
195+
{
196+
var prevBgTint = GUI.backgroundColor;
197+
// GUI.backgroundColor = CellButtonTintColor;
198+
GUI.backgroundColor = Color.white;
199+
if (GUILayout.Button(text, CellButtonStyle, options))
200+
{
201+
action.Invoke();
202+
HumankindGame.Update();
203+
// CurrentSnapshot.Snapshot();
204+
GameStatsWindow.ResetLoop();
205+
}
206+
GUI.backgroundColor = prevBgTint;
207+
}
208+
132209
public GameStatisticsGrid DrawSection(string title)
133210
{
134211
return (GameStatisticsGrid)this

UI/Statistics/GameStatsSnapshot.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Modding.Humankind.DevTools.DeveloperTools.UI;
88
using UnityEngine;
99
using Amplitude.Mercury;
10+
using Amplitude.Mercury.Interop;
1011

1112
namespace DevTools.Humankind.GUITools.UI
1213
{
@@ -17,6 +18,9 @@ public class GameStatsSnapshot
1718
public int GameSpeedLevel { get; set; }
1819
public EmpireSnapshot[] Empires;
1920
public int LocalEmpireIndex { get; set; }
21+
public int AtmospherePollutionLevel { get; set; }
22+
public int AtmospherePollutionStock { get; set; }
23+
public int AtmospherePollutionNet { get; set; }
2024

2125
public GameStatsSnapshot()
2226
{
@@ -40,7 +44,11 @@ public GameStatsSnapshot Snapshot()
4044
Empires[i].Snapshot(empires[i]);
4145
}
4246
}
43-
47+
48+
var pollutionData = Snapshots.PollutionSnapshot.PresentationData;
49+
AtmospherePollutionLevel = pollutionData.AtmospherePollutionLevel + 1;
50+
AtmospherePollutionStock = (int) pollutionData.AtmospherePollutionStock;
51+
AtmospherePollutionNet = (int) pollutionData.AtmospherePollutionNet;
4452

4553
return this;
4654
}
@@ -148,12 +156,24 @@ private static string GetPlayerIdentifierUserName(HumankindEmpire empire)
148156
public string LuxuryResourcesAccessCount => Values[23];
149157
public string StrategicResourcesAccessCount => Values[24];
150158
public string TradeNodesCount => Values[25];
159+
public string PollutionStock => Values[26];
160+
public string PollutionNet => Values[27];
151161
}
152162

153163
public static class EmpireSnapshotUtils
154164
{
155165
public static string[] MakeEmpireSnapshotValues(HumankindEmpire empire)
156166
{
167+
EmpireInfo empireInfo;
168+
try
169+
{
170+
empireInfo = Snapshots.GameSnapshot.PresentationData.EmpireInfo[empire.EmpireIndex];
171+
}
172+
catch (Exception)
173+
{
174+
empireInfo = new EmpireInfo();
175+
}
176+
157177
return new[] {
158178
$"{empire.EmpireIndex}",
159179
$"{empire.PersonaName}",
@@ -183,6 +203,8 @@ public static string[] MakeEmpireSnapshotValues(HumankindEmpire empire)
183203
$"{empire.LuxuryResourcesAccessCount}",
184204
$"{empire.StrategicResourcesAccessCount}",
185205
$"{empire.TradeNodesCount}",
206+
$"{(int)empireInfo.PollutionStock}",
207+
$"{(int)empireInfo.PollutionNet}",
186208
};
187209
}
188210
}

UI/Statistics/GameStatsWindow.cs

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public class GameStatsWindow : FloatingToolWindow
2323

2424
public static bool IsVisibleFullscreen = false;
2525

26+
public static Vector2 ScrollViewPosition = Vector2.zero;
27+
2628
private static int localEmpireIndex = 0;
2729
// Snapshot currently being displayed
2830
private static GameStatsSnapshot Snapshot;
@@ -45,6 +47,11 @@ public class GameStatsWindow : FloatingToolWindow
4547
private GUIStyle backButtonStyle = new GUIStyle(UIToolManager.DefaultSkin.toggle) {
4648
margin = new RectOffset(1, 1, 1, 1)
4749
};
50+
51+
private GUIStyle CommonHeaderStyle = new GUIStyle(UIToolManager.DefaultSkin.toggle) {
52+
margin = new RectOffset(1, 1, 1, 1),
53+
alignment = TextAnchor.LowerRight
54+
};
4855

4956
private static bool initialized = false;
5057
private static bool isValidSnapshot = false;
@@ -158,32 +165,66 @@ public override void OnDrawUI()
158165
return;
159166
}
160167

161-
GUILayout.BeginVertical(bgStyle, GUILayout.Width(Screen.width), GUILayout.Height(Screen.height));
162-
DrawBackButton();
163-
164-
GUILayout.FlexibleSpace();
165-
166-
GUILayout.BeginHorizontal();
167-
168-
GUILayout.FlexibleSpace();
168+
grid.SetSnapshot(Snapshot);
169+
170+
BeginBackgroundScrollView();
171+
{
172+
GUILayout.BeginHorizontal(GUILayout.Width(Screen.width), GUILayout.Height(Screen.height));
173+
{
174+
GUILayout.FlexibleSpace();
169175

170-
DrawWindowContent();
176+
GUILayout.BeginVertical();
177+
{
178+
GUILayout.Space(24f);
179+
DrawCommonContent();
180+
181+
GUILayout.Space(72f);
182+
GUILayout.FlexibleSpace();
183+
184+
DrawWindowContent();
185+
// GUILayout.Space(16f);
186+
// DrawWindowContent();
187+
188+
GUILayout.FlexibleSpace();
189+
GUILayout.Space(72f);
171190

172-
GUILayout.FlexibleSpace();
191+
}
192+
GUILayout.EndVertical();
173193

194+
GUILayout.FlexibleSpace();
195+
}
174196
GUILayout.EndHorizontal();
197+
}
198+
GUILayout.EndScrollView();
199+
DrawBackButton();
200+
}
175201

176-
GUILayout.FlexibleSpace();
202+
private void BeginBackgroundScrollView()
203+
{
204+
ScrollViewPosition = GUILayout.BeginScrollView(
205+
ScrollViewPosition,
206+
false,
207+
false,
208+
"horizontalscrollbar",
209+
"verticalscrollbar",
210+
bgStyle,
211+
// "scrollview",
212+
GUILayout.Height(Screen.height));
213+
}
177214

178-
GUILayout.EndVertical();
215+
private void DrawCommonContent()
216+
{
217+
GUILayout.BeginHorizontal();
218+
grid.DrawCommonHeader();
219+
GUILayout.EndHorizontal();
179220
}
180221

181222
private void DrawWindowContent()
182223
{
183224
GUILayout.BeginVertical();
184225
GUILayout.Space(4f);
185226

186-
grid.Draw(Snapshot);
227+
grid.Draw();
187228

188229
GUILayout.Space(4f);
189230
GUILayout.EndVertical();

0 commit comments

Comments
 (0)