-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathUI_Changes.cs
261 lines (231 loc) · 10.7 KB
/
UI_Changes.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
using System;
using System.Reflection;
using BattleTech;
using Harmony;
using BattleTech.UI;
using Newtonsoft.Json;
using System.IO;
using UnityEngine;
using System.Collections.Generic;
using System.Linq;
using BattleTech.UI.Tooltips;
using HBS.Collections;
namespace Pilot_Quirks
{
class UI_Changes
{
public static Pilot PilotHolder;
[HarmonyPatch(typeof(SG_HiringHall_DetailPanel), "DisplayPilot")]
public static class SG_HiringHall_DetailPanel_DisplayPilot_Patch
{
public static void Prefix(Pilot p)
{
if (!p.pilotDef.PilotTags.Contains("PQ_Tagged"))
{
p.pilotDef.PilotTags.Add("PQ_Tagged");
if (p.pilotDef.Description.Id.StartsWith("pilot_ronin") || p.pilotDef.Description.Id.StartsWith("pilot_backer"))
p.Description.Details += "\n\n";
var sim = UnityGameInstance.BattleTechGame.Simulation;
foreach (var tag in p.pilotDef.PilotTags)
{
if (p.pilotDef.Description.Id.StartsWith("pilot_ronin") || p.pilotDef.Description.Id.StartsWith("pilot_backer"))
{
if (Pre_Control.settings.TagIDToDescription.Keys.Contains(tag))
{
p.Description.Details += "<b>" + Pre_Control.settings.TagIDToNames[tag] + ": </b>" +
Pre_Control.settings.TagIDToDescription[tag] + "\n\n";
}
}
else
{
if (Pre_Control.settings.TagIDToDescription.Keys.Contains(tag))
p.Description.Details += Pre_Control.settings.TagIDToNames[tag] + "\n\n"
+ Pre_Control.settings.TagIDToDescription[tag] + "\n\n";
}
}
}
}
}
[HarmonyPatch(typeof(SGBarracksRosterSlot), "Refresh")]
public static class SGBarracksRosterSlot_Refresh_Patch
{
public static void Postfix(SGBarracksRosterSlot __instance)
{
if (__instance.Pilot == null)
return;
var tooltip = __instance.gameObject.GetComponent<HBSTooltip>()
?? __instance.gameObject.AddComponent<HBSTooltip>();
var p = __instance.Pilot;
string TagDesc = "";
if (p.pilotDef.PilotTags.Contains("pilot_fatigued"))
{
TagDesc += "<b>***PILOT FATIGUED***</b>\nPilot will suffer from Low Spirits if used in combat. The lance will also experience reduced Resolve per turn during combat.\n\n";
}
else if (p.pilotDef.PilotTags.Contains("pilot_lightinjury"))
TagDesc += "<b>***PILOT LIGHT INJURY***</b>\nPilot cannot drop into combat. This pilot requires rest after dropping too frequently while fatigued.\n\n";
foreach (var tag in p.pilotDef.PilotTags)
{
if (Pre_Control.settings.TagIDToDescription.Keys.Contains(tag))
{
TagDesc += "<b>" + Pre_Control.settings.TagIDToNames[tag] + ": </b>" +
Pre_Control.settings.TagIDToDescription[tag] + "\n\n";
}
else if (tag == "PQ_Mech_Mastery")
{
TagDesc = MechMasterTagDescription(__instance.pilot, TagDesc);
}
}
var descriptionDef = new BaseDescriptionDef("Tags", p.Callsign, TagDesc, null);
tooltip.SetDefaultStateData(TooltipUtilities.GetStateDataFromObject(descriptionDef));
}
}
[HarmonyPatch(typeof(TagDataStructFetcher), "GetItem")]
public static class TagDataStructFetcher_GetItem_Patch
{
public static void Postfix(string id, TagDataStruct __result)
{
if (id == "HACK_GENCON_UNIT")
__result.DescriptionTag += MechMasterTagDescription(UI_Changes.PilotHolder, __result.DescriptionTag);
if (!Pre_Control.settings.TagIDToDescription.ContainsKey(id))
return;
__result.DescriptionTag += "\n\n" + Pre_Control.settings.TagIDToDescription[id];
}
}
[HarmonyPatch(typeof(HBSTagView), "Initialize")]
public static class HBSTagView_Initialize_Patch
{
public static void Postfix(HBSTagView __instance, TagSet tagSet, GameContext context)
{
if (!Pre_Control.settings.MechBonding)
return;
if (tagSet.Contains("PQ_Mech_Mastery"))
{
bool HasTattoo = PilotHolder.pilotDef.PilotTags.Any(x => x.StartsWith("PQ_Pilot_GUID"));
if (!HasTattoo)
return;
string PilotTattoo = PilotHolder.pilotDef.PilotTags.First(x => x.StartsWith("PQ_Pilot_GUID"));
if (!MechBonding.PilotsAndMechs.Keys.Contains(PilotTattoo) || MechBonding.PilotsAndMechs[PilotTattoo].Count() == 0)
return;
var MechExperience = MechBonding.PilotsAndMechs[PilotTattoo];
var BondedMech = MechExperience.Aggregate((l, r) => l.Value > r.Value ? l : r).Key;
string MasteryTier = "";
if (MechExperience[BondedMech] >= Pre_Control.settings.Tier4)
MasteryTier = "Elite ";
else if (MechExperience[BondedMech] >= Pre_Control.settings.Tier3)
MasteryTier = "Veteran ";
else if (MechExperience[BondedMech] >= Pre_Control.settings.Tier2)
MasteryTier = "Regular ";
else if (MechExperience[BondedMech] >= Pre_Control.settings.Tier1)
MasteryTier = "Green ";
string DescriptionName = MasteryTier + " 'Mech Pilot";
var item = new TagDataStruct("HACK_GENCON_UNIT", true, true, "name", DescriptionName , "description");
string contextItem = string.Format("{0}[{1}]", "TDSF", item.Tag);
string friendlyName = item.FriendlyName;
var itemTT = TooltipUtilities.GetGameContextTooltipString(contextItem, friendlyName);
__instance.AddTag(itemTT, item.FriendlyName);
}
}
}
public static string MechMasterTagDescription(Pilot pilot, string TagDesc)
{
if (!Pre_Control.settings.MechBonding)
return "";
bool HasTattoo = pilot.pilotDef.PilotTags.Any(x => x.StartsWith("PQ_Pilot_GUID"));
if (!HasTattoo)
return "<b>No 'Mech mastery.</b>";
string PilotTattoo = pilot.pilotDef.PilotTags.First(x => x.StartsWith("PQ_Pilot_GUID"));
if (!MechBonding.PilotsAndMechs.Keys.Contains(PilotTattoo) || MechBonding.PilotsAndMechs[PilotTattoo].Count() == 0)
return "<b>No 'Mech mastery.</b>";
var MechExperience = MechBonding.PilotsAndMechs[PilotTattoo];
string TierOneString = "\n• Reduced Fatigue\n\t(";
string TierTwoString = "\n• +1 Piloting Skill\n\t(";
string TierThreeString = "\n• Increased Sensor and Spotting Range\n\t(";
string TierFourString = "\n• +1 Gunnery Skill\n\t(";
bool TierOne = false;
bool TierTwo = false;
bool TierThree = false;
bool TierFour = false;
int h = 0;
foreach (var BondedMech in MechExperience.OrderByDescending(x => x.Value))
{
if (MechExperience[BondedMech.Key] >= Pre_Control.settings.Tier1)
{
TierOneString += BondedMech.Key + ", ";
TierOne = true;
}
if (MechExperience[BondedMech.Key] >= Pre_Control.settings.Tier2)
{
TierTwoString += BondedMech.Key + ", ";
TierTwo = true;
}
if (MechExperience[BondedMech.Key] >= Pre_Control.settings.Tier3)
{
TierThreeString += BondedMech.Key + ", ";
TierThree = true;
}
if (MechExperience[BondedMech.Key] >= Pre_Control.settings.Tier4)
{
TierFourString += BondedMech.Key + ", ";
TierFour = true;
}
h++;
if (h == 3)
break;
}
char[] charsToTrim = { ' ', ',' };
if (TierOne)
{
TagDesc += "<b>'Mech Mastery:</b> Bonuses when piloting 'Mechs.";
TierOneString = TierOneString.TrimEnd(charsToTrim) + ")";
TagDesc += TierOneString;
}
else
{
TagDesc += "<b>No 'Mech mastery.</b>";
}
if (TierTwo)
{
TierTwoString = TierTwoString.TrimEnd(charsToTrim) + ")";
TagDesc += TierTwoString;
}
if (TierThree)
{
TierThreeString = TierThreeString.TrimEnd(charsToTrim) + ")";
TagDesc += TierThreeString;
}
if (TierFour)
{
TierFourString = TierFourString.TrimEnd(charsToTrim) + ")";
TagDesc += TierFourString;
}
TagDesc += "\n\nMech Experience - ";
int i = 0;
foreach (var MechXP in MechExperience.OrderByDescending(x => x.Value))
{
TagDesc += MechXP.Key + ": " + MechXP.Value + ", ";
i++;
if (i == 3) break;
}
TagDesc = TagDesc.TrimEnd(charsToTrim);
TagDesc = TagDesc + "\n\n";
return TagDesc;
}
}
//Hold Pilot for tag generation.
[HarmonyPatch(typeof(SGBarracksServicePanel), "SetPilot")]
public static class SGBarracksServicePanel_SetPilot_Patch
{
public static void Prefix(Pilot p)
{
UI_Changes.PilotHolder = p;
}
}
[HarmonyPatch(typeof(SGMemorialWallAdditionalDetailsPanel), "DisplayPilot")]
public static class SGMemorialWallAdditionalDetailsPanel_DisplayPilot_Patch
{
public static void Prefix(Pilot pilot)
{
UI_Changes.PilotHolder = pilot;
}
}
}