Skip to content

Commit

Permalink
Tag Text, Fixes for customsalvage mod
Browse files Browse the repository at this point in the history
  • Loading branch information
Denadan committed May 18, 2019
1 parent 1578190 commit 19e3ab4
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Reflection;
using BattleTech;
using Harmony;
using HBS.Collections;
using HBS.Extensions;
using HBS.Util;

Expand Down Expand Up @@ -51,6 +52,7 @@ public static void Prefix(object target, Dictionary<string, object> values)
}
}


public static void Postfix(object target, Dictionary<string, object> values)
{
Registry.ProcessCustomFactories(target, values);
Expand All @@ -73,7 +75,13 @@ public static void Postfix(object target, Dictionary<string, object> values)
var trav = new Traverse(def.Description).Property<string>("Details");
trav.Value = def.Description.Details + "\n" + description;
}

TagRestrictionsHandler.Shared.ProcessDescription(def.ComponentTags, def.Description);
}
else if(target is MechDef mdef)
TagRestrictionsHandler.Shared.ProcessDescription(mdef.MechTags, mdef.Description);
else if (target is ChassisDef cdef)
TagRestrictionsHandler.Shared.ProcessDescription(cdef.ChassisTags, cdef.Description);
}
}
}
2 changes: 1 addition & 1 deletion source/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static void Init(string directory, string settingsJSON)
Registry.RegisterSimpleCustomComponents(Assembly.GetExecutingAssembly());
Validator.RegisterMechValidator(CategoryController.Shared.ValidateMech, CategoryController.Shared.ValidateMechCanBeFielded);

Logger.Log("Loaded CustomComponents v0.9.6.0 for bt 1.5.1");
Logger.Log("Loaded CustomComponents v0.9.7.0 for bt 1.5.1");

Validator.RegisterMechValidator(TagRestrictionsHandler.Shared.ValidateMech, TagRestrictionsHandler.Shared.ValidateMechCanBeFielded);
Validator.RegisterDropValidator(pre: TagRestrictionsHandler.Shared.ValidateDrop);
Expand Down
3 changes: 3 additions & 0 deletions source/CustomComponentSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public class CustomComponentSettings
public float SalvageLegWeight = 0.75f;
public float SalvageTorsoWeight = 1f;
public float SalvageHeadWeight = 0.5f;


public bool RunAutofixer = true;
public bool FixDeletedComponents = true;
Expand All @@ -131,6 +132,7 @@ public class CustomComponentSettings
public bool TagRestrictionDropValidateRequiredTags = false;
public bool TagRestrictionDropValidateIncompatibleTags = true;
public bool CheckCriticalComponent = true;
public bool AddTagsToDescription = true;

public bool UseDefaultFixedColor = false;
public UIColor DefaultFlagBackgroundColor = UIColor.UpgradeColor;
Expand All @@ -139,6 +141,7 @@ public class CustomComponentSettings
public CCColor PreinstalledOverlayCColor = new CCColor() { A = 12, R = 255, B = 180, G = 180 };
public CCColor DefaultFlagOverlayCColor = new CCColor() { A = 12, R = 180, B = 180, G = 255 };
public string CategoryDescriptionColor = "#008000";
public string ShortTagsColor = "#008000";

[JsonIgnore] public Color PreinstalledOverlayColor;
[JsonIgnore] public Color DefaultFlagOverlayColor;
Expand Down
3 changes: 2 additions & 1 deletion source/Salvage/Contract_GenerateSalvage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace CustomComponents
[HarmonyPatch(typeof(Contract), "GenerateSalvage")]
public static class Contract_GenerateSalvage
{
private static bool IsDestroyed(MechDef mech)
public static bool IsDestroyed(MechDef mech)
{
if (mech.IsDestroyed)
return true;
Expand All @@ -23,6 +23,7 @@ private static bool IsDestroyed(MechDef mech)
}

[HarmonyPrefix]
[HarmonyPriority(Priority.Low)]
public static bool GenerateSalvage(List<UnitResult> enemyMechs, List<VehicleDef> enemyVehicles,
List<UnitResult> lostUnits, bool logResults,
Contract __instance, ref List<SalvageDef> ___finalPotentialSalvage)
Expand Down
4 changes: 4 additions & 0 deletions source/TagRestrictions/TagRestrictions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ public class TagRestrictions
public string[] RequiredAnyTags;
public string[] IncompatibleTags;

public string ShortText = null;
public string FullText = null;


//public class SearchOptions
//{
// public bool IncludeComponentTags = true;
Expand Down
38 changes: 38 additions & 0 deletions source/TagRestrictions/TagRestrictionsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Linq;
using BattleTech;
using BattleTech.UI;
using Harmony;
using HBS.Collections;
using Localize;

namespace CustomComponents
Expand Down Expand Up @@ -317,5 +319,41 @@ private static string NameForTag(string tag)
return tag;
}

public void ProcessDescription(TagSet tags, DescriptionDef description)
{
string fulltags = "";
string shorttags = "";

foreach (var tag in Restrictions.Values)
{
if (tags.Contains(tag.Tag))
{
if (!string.IsNullOrEmpty(tag.ShortText))
shorttags += tag.ShortText + ", ";
if (!string.IsNullOrEmpty(tag.FullText))
fulltags += "\n" + tag.FullText;
}
}

if (shorttags != "" || fulltags != "")
{
var trav = new Traverse(description).Property<string>("Details");

if (shorttags != "")
{
shorttags = shorttags.Substring(0, shorttags.Length - 2);
shorttags = "\n<b><color=" + Control.Settings.ShortTagsColor + ">[" + shorttags + "]</b></color>";
trav.Value = description.Details + shorttags;
;

}

if (fulltags != "")
{
trav.Value = description.Details + fulltags;
}
}

}
}
}

0 comments on commit 19e3ab4

Please sign in to comment.