-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
559 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
source/ColorPatches/LanceMechEquipmentListItem_SetTooltipData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
Oops, something went wrong.