Skip to content

Commit

Permalink
colors!
Browse files Browse the repository at this point in the history
  • Loading branch information
Denadan committed Dec 1, 2018
1 parent 9a5b81e commit 46348a8
Show file tree
Hide file tree
Showing 17 changed files with 559 additions and 58 deletions.
8 changes: 5 additions & 3 deletions mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"LogLevel": "Debug",
"Categories": [ ],
"TagRestrictions": [ ],
"ColorTags" : [ ],

"TagRestrictionDropValidateRequiredTags": false,
"TagRestrictionDropValidateIncompatibleTags": true,
"UseDefaultFixedColor": false,
Expand All @@ -20,16 +22,16 @@
"R": 255,
"G": 180,
"B": 180,
"A": 12
"A": 10
},
"DefaultFlagOverlayCColor": {
"R": 180,
"G": 255,
"B": 180,
"A": 12
"A": 10
},

"TestEnableAllTags": true
"TestEnableAllTags": false
},

"Manifest": [ ]
Expand Down
76 changes: 76 additions & 0 deletions source/ColorPatches/ColorExtentions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System.Collections.Generic;
using BattleTech;
using BattleTech.UI;

namespace CustomComponents
{
public static class ColorExtentions
{
public static void SetColor(this UIColorRefTracker color_tracker, MechComponentRef cref)
{
if (cref.Is<IColorComponent>(out var color))
{
color_tracker.SetUIColor(color.UIColor);
if (color.UIColor == UIColor.Custom)
color_tracker.OverrideWithColor(color.RGBColor);
}
else
{
color_tracker.SetUIColor(MechComponentRef.GetUIColor(cref));
}
}

public static void SetColor(this UIColorRefTracker color_tracker, MechComponentDef cdef)
{
if (cdef.Is<IColorComponent>(out var color))
{

color_tracker.SetUIColor(color.UIColor);
if (color.UIColor == UIColor.Custom)
color_tracker.OverrideWithColor(color.RGBColor);
}
else
{
color_tracker.SetUIColor(MechComponentDef.GetUIColor(cdef));
}
}

public static void SetColor(this IEnumerable<UIColorRefTracker> color_trackers, MechComponentRef cref)
{
if (cref.Is<IColorComponent>(out var color))
{
foreach (var color_tracker in color_trackers)
{
color_tracker.SetUIColor(color.UIColor);
if (color.UIColor == UIColor.Custom)
color_tracker.OverrideWithColor(color.RGBColor);

}
}
else
{
foreach (var color_tracker in color_trackers)
color_tracker.SetUIColor(MechComponentRef.GetUIColor(cref));
}
}

public static void SetColor(this IEnumerable<UIColorRefTracker> color_trackers, MechComponentDef cdef)
{
if (cdef.Is<IColorComponent>(out var color))
{
foreach (var color_tracker in color_trackers)
{

color_tracker.SetUIColor(color.UIColor);
if (color.UIColor == UIColor.Custom)
color_tracker.OverrideWithColor(color.RGBColor);
}
}
else
{
foreach (var color_tracker in color_trackers)
color_tracker.SetUIColor(MechComponentDef.GetUIColor(cdef));
}
}
}
}
116 changes: 116 additions & 0 deletions source/ColorPatches/Inventory_RefreshColor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
using System;
using BattleTech;
using BattleTech.UI;
using Harmony;

namespace CustomComponents
{
[HarmonyPatch(typeof(InventoryDataObject_InventoryGear), "RefreshItemColor")]
public class InventoryDataObject_InventoryGear_RefreshItemColor
{
[HarmonyPrefix]
public static bool ChangeColor(InventoryDataObject_InventoryGear __instance, InventoryItemElement theWidget)
{
try
{
theWidget.iconBGColors.SetColor(__instance.componentRef);
}
catch (Exception ex)
{
Control.Logger.LogError(ex);
}
return false;
}
}

[HarmonyPatch(typeof(InventoryDataObject_InventoryWeapon), "RefreshItemColor")]
public class InventoryDataObject_InventoryWeapon_RefreshItemColor
{
[HarmonyPrefix]
public static bool ChangeColor(InventoryDataObject_InventoryWeapon __instance, InventoryItemElement theWidget)
{
try
{
theWidget.iconBGColors.SetColor(__instance.componentRef);
}
catch (Exception ex)
{
Control.Logger.LogError(ex);
}
return false;
}
}

[HarmonyPatch(typeof(InventoryItemElement), "RefreshItemColor")]
public class InventoryItemElement_RefreshItemColor
{
[HarmonyPrefix]
public static bool ChangeColor(InventoryItemElement __instance, MechComponentRef ___componentRef)
{
try
{
__instance.iconBGColors.SetColor(___componentRef);
}
catch (Exception ex)
{
Control.Logger.LogError(ex);
}
return false;
}
}

[HarmonyPatch(typeof(InventoryItemElement_NotListView), "RefreshItemColor")]
public class InventoryItemElement_NotListView_RefreshItemColor
{
[HarmonyPrefix]
public static bool ChangeColor(InventoryItemElement_NotListView __instance, MechComponentRef ___componentRef)
{
try
{
__instance.iconBGColors.SetColor(___componentRef);
}
catch (Exception ex)
{
Control.Logger.LogError(ex);
}
return false;
}
}


[HarmonyPatch(typeof(ListElementController_InventoryGear_NotListView), "RefreshItemColor")]
public class ListElementController_InventoryGear_NotListView_RefreshItemColor
{
[HarmonyPrefix]
public static bool ChangeColor(ListElementController_InventoryGear_NotListView __instance, InventoryItemElement_NotListView theWidget)
{
try
{
theWidget.iconBGColors.SetColor(__instance.componentRef);
}
catch (Exception ex)
{
Control.Logger.LogError(ex);
}
return false;
}
}

[HarmonyPatch(typeof(ListElementController_InventoryWeapon_NotListView), "RefreshItemColor")]
public class ListElementController_InventoryWeapon_NotListViewn_RefreshItemColor
{
[HarmonyPrefix]
public static bool ChangeColor(ListElementController_InventoryWeapon_NotListView __instance, InventoryItemElement_NotListView theWidget)
{
try
{
theWidget.iconBGColors.SetColor(__instance.componentRef);
}
catch (Exception ex)
{
Control.Logger.LogError(ex);
}
return false;
}
}
}
17 changes: 17 additions & 0 deletions source/ColorPatches/LanceMechEquipmentListItem_SetTooltipData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using BattleTech;
using BattleTech.UI;
using Harmony;

namespace CustomComponents
{
[HarmonyPatch(typeof(LanceMechEquipmentListItem), "SetTooltipData")]
public static class LanceMechEquipmentListItem_SetTooltipData
{
[HarmonyPostfix]
public static void SetColor(LanceMechEquipmentListItem __instance,
MechComponentDef MechDef, UIColorRefTracker ___backgroundColor)
{
___backgroundColor.SetColor(MechDef);
}
}
}
37 changes: 37 additions & 0 deletions source/ColorPatches/MechComponentDef_GetUIColor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using BattleTech;
using BattleTech.UI;
using Harmony;
using System;

namespace CustomComponents
{
[HarmonyPatch(typeof(MechComponentDef), "GetUIColor")]
internal static class MechComponentDef_GetUIColor
{

[HarmonyPostfix]
public static void Postfix(MechComponentDef componentDef,
ref UIColor __result)
{
try
{
if (componentDef.Is<Flags>(out var f))
{
if (f.Invalid)
{
__result = UIColor.Red;
}
else if (f.Default)
{
__result = Control.Settings.DefaultFlagBackgroundColor;
}
}
}
catch (Exception e)
{
Control.Logger.LogError(e);
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ public static void Postfix(MechComponentRef __instance,
{
try
{
if (componentRef.Is<ColorComponent>(out var color))
{
__result = color.UIColor;
return;
}


if (componentRef.Is<Flags>(out var f))
{
if (f.Invalid)
Expand All @@ -35,7 +28,7 @@ public static void Postfix(MechComponentRef __instance,
}
}
}
catch(Exception e)
catch (Exception e)
{
Control.Logger.LogError(e);
}
Expand Down
53 changes: 53 additions & 0 deletions source/ColorPatches/MechLabSlotItem_RefreshItemColor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using BattleTech;
using BattleTech.UI;
using Harmony;
using UnityEngine;

namespace CustomComponents
{
[HarmonyPatch(typeof(MechLabItemSlotElement), "RefreshItemColor")]
public static class MechLabSlotItem_RefreshItemColor
{
[HarmonyPrefix]
public static bool ChangeColor(MechLabItemSlotElement __instance, UIColorRefTracker ___backgroundColor,
GameObject ___fixedEquipmentOverlay, IMechLabDropTarget ___dropParent)
{

___backgroundColor.SetColor(__instance.ComponentRef);



if (__instance.ComponentRef != null && __instance.ComponentRef.IsFixed)
{
var preinstalled = false;
if (___dropParent is MechLabLocationWidget widget)
{
var helper = new LocationHelper(widget);
preinstalled = __instance.ComponentRef.IsModuleFixed(helper.mechLab.activeMechDef);
}


if (!Control.Settings.UseDefaultFixedColor)
{
___fixedEquipmentOverlay.SetActive(true);
var color_tracker = ___fixedEquipmentOverlay.GetComponent<UIColorRefTracker>();
color_tracker.colorRef.UIColor = UIColor.Custom;
color_tracker.colorRef.color = preinstalled ? Control.Settings.PreinstalledOverlayColor : Control.Settings.DefaultFlagOverlayColor;
color_tracker.RefreshUIColors();
}
else
___fixedEquipmentOverlay.SetActive(preinstalled);
}
else
{
___fixedEquipmentOverlay.SetActive(false);
}

return false;
}
}
}
Loading

0 comments on commit 46348a8

Please sign in to comment.