public static void Postfix(InventoryItemElement_NotListView __instance) { try { //Logger.Debug("[InventoryItemElement_NotListView_SetData_POSTFIX] Expanding bonusText fields"); __instance.gearBonusText.enableAutoSizing = false; __instance.gearBonusText.enableWordWrapping = false; __instance.gearBonusText.overflowMode = TextOverflowModes.Overflow; __instance.gearBonusTextB.enableAutoSizing = false; __instance.gearBonusTextB.enableWordWrapping = false; __instance.gearBonusTextB.overflowMode = TextOverflowModes.Overflow; __instance.bonusStat1.enableAutoSizing = false; __instance.bonusStat1.enableWordWrapping = false; __instance.bonusStat1.overflowMode = TextOverflowModes.Overflow; __instance.bonusStat2.enableAutoSizing = false; __instance.bonusStat2.enableWordWrapping = false; __instance.bonusStat2.overflowMode = TextOverflowModes.Overflow; } catch (Exception e) { Logger.Error(e); } }
public static void prefix(InventoryItemElement_NotListView a, InventoryItemElement_NotListView b) { try { var i = Control.Instance; i.LogDebug(DInfo.Sort, "SORT:"); i.LogDebug(DInfo.Sort, "- a: {0}", a == null); i.LogDebug(DInfo.Sort, "-- a.controler:{0} a.salvageDef:{1}", a.controller == null, a.controller?.salvageDef); i.LogDebug(DInfo.Sort, "-- a.GetId:{0}", a.controller.GetId()); i.LogDebug(DInfo.Sort, "-- a.GetName:{0}", a.controller.GetName()); i.LogDebug(DInfo.Sort, "- b: {0}", a == null); i.LogDebug(DInfo.Sort, "-- b.controler:{0} b.salvageDef:{1}", b.controller == null, b.controller?.salvageDef); i.LogDebug(DInfo.Sort, "-- b.GetId:{0}", b.controller.GetId()); i.LogDebug(DInfo.Sort, "-- b.GetName:{0}", b.controller.GetName()); } catch (Exception e) { Console.WriteLine(e); throw; } }
//[Conditional("COLORICON")] internal static void ResetTextIconColor(InventoryItemElement_NotListView theWidget) { var color_text = theWidget.itemName.GetComponent <UIColorRefTracker>(); var color_icon = theWidget.icon.GetComponent <UIColorRefTracker>(); if (color_icon != null) { color_icon.SetUIColor(UIColor.White); } color_text.SetUIColor(UIColor.White); }
public static void ChangeBackColor(MechComponentDef cdef, InventoryItemElement_NotListView theWidget) { try { theWidget.iconBGColors.SetColor(cdef); } catch (Exception ex) { Control.LogError(ex); } }
public static bool ChangeColor(InventoryItemElement_NotListView __instance, MechComponentRef ___componentRef) { try { __instance.iconBGColors.SetColor(___componentRef); } catch (Exception ex) { Control.LogError(ex); } return(false); }
public static void ChangeColor(ListElementController_SalvageMechPart_NotListView __instance, InventoryItemElement_NotListView theWidget) { try { TColorExtentions.ResetTextIconColor(theWidget); } catch (Exception e) { Control.LogError(e); } }
public static bool ChangeColor(InventoryItemElement_NotListView __instance, MechComponentRef ___componentRef) { try { ColorExtentions.ChangeBackColor(___componentRef.Def, __instance); TColorExtentions.ChangeTextIconColor(___componentRef.Def, __instance); } catch { return(true); } return(false); }
public static void Postfix(InventoryItemElement_NotListView __instance, MechComponentRef ___componentRef) { try { if (HasOverrideColor(___componentRef.Def, out Color overrideColor)) { UIColorRefTracker[] array = __instance.iconBGColors; for (int i = 0; i < array.Length; i++) { array[i].OverrideWithColor(overrideColor); } } } catch (Exception e) { Logger.Error(e); } }
public static bool ChangeColor(ListElementController_SalvageWeapon_NotListView __instance, InventoryItemElement_NotListView theWidget) { try { if (__instance.componentDef == null) { return(true); } theWidget.iconBGColors.SetColor(__instance.componentDef); return(false); } catch (Exception e) { Control.LogError(e); return(true); } }
public static bool ChangeColor(ListElementController_SalvageWeapon_NotListView __instance, InventoryItemElement_NotListView theWidget) { try { if (__instance.componentDef == null) { return(true); } ColorExtentions.ChangeBackColor(__instance.weaponDef ?? __instance.componentDef, theWidget); TColorExtentions.ChangeTextIconColor(__instance.weaponDef ?? __instance.componentDef, theWidget); return(false); } catch (Exception e) { Control.LogError(e); return(true); } }
//[Conditional("COLORICON")] internal static void ChangeTextIconColor(MechComponentDef cdef, InventoryItemElement_NotListView theWidget) { var color_text = theWidget.itemName.GetComponent <UIColorRefTracker>(); var color_icon = theWidget.icon.GetComponent <UIColorRefTracker>(); if (color_icon == null) { color_icon = theWidget.icon.gameObject.AddComponent <UIColorRefTracker>(); } if (cdef.Is <ITColorComponent>(out var color)) { if (color.SkipText) { color_text.SetCustomColor(UIColor.White, Color.white); } else { color_text.SetCustomColor(color.UIColor, color.RGBColor); } if (color_icon != null) { if (color.SkipIcon) { color_icon.SetUIColor(UIColor.White); } else { color_icon.SetCustomColor(color.UIColor, color.RGBColor); } } } else { color_text.SetUIColor(UIColor.White); color_icon.SetUIColor(UIColor.White); } }
public static void RemoveItem(this MechLabInventoryWidget inventoryWidget, InventoryItemElement_NotListView item) { if (item.controller != null) { //Logger.Debug("[Extensions.MechLabInventoryWidget.RemoveItem] item.controller != null"); if (item.controller.quantity > 1) { item.controller.ModifyQuantity(-1); //Logger.Debug("[Extensions.MechLabInventoryWidget.RemoveItem] item.controller.quantity: " + item.controller.quantity); } else { //Logger.Debug("[Extensions.MechLabInventoryWidget.RemoveItem] item.controller.quantity <= 1: " + item.controller.quantity); inventoryWidget.localInventory.Remove(item); item.SetRadioParent(null); item.controller.Pool(); ReflectionHelper.InvokePrivateMethode(inventoryWidget, "EndOfFrameScrollBarMovement", null); } } else if (item.Quantity > 1) { item.ModifyQuantity(-1); } else { inventoryWidget.localInventory.Remove(item); item.SetRadioParent(null); ReflectionHelper.InvokePrivateMethode(inventoryWidget, "EndOfFrameScrollBarMovement", null); } if (!inventoryWidget.localInventory.Contains(item)) { //Logger.Debug("[Extensions.MechLabInventoryWidget.RemoveItem] !inventoryWidget.localInventory.Contains(item): HIDING item"); item.ElementVisible = false; } inventoryWidget.ApplySorting(true); }
public static void Postfix(ListElementController_SalvageMechPart_NotListView __instance, InventoryItemElement_NotListView theWidget, SimGameState ___simState) { if (Main.Settings.DependsOnArgoUpgrade && !___simState.PurchasedArgoUpgrades.Contains(Main.Settings.ArgoUpgrade)) { return; } var defaultMechPartMax = ___simState.Constants.Story.DefaultMechPartMax; Main.ExcludedVariantHolder = __instance.mechDef; var thisMechPieces = Main.GetMechParts(___simState, __instance.mechDef); var allMechPieces = Main.GetAllVariantMechParts(___simState, __instance.mechDef); if (!Main.Settings.VariantExceptions.Contains(__instance.mechDef.Description.Id)) { theWidget.mechPartsNumbersText.SetText($"{thisMechPieces} ({allMechPieces}) / {defaultMechPartMax}"); } else { theWidget.mechPartsNumbersText.SetText($"{thisMechPieces} (R) / {defaultMechPartMax}"); } }
static bool Prefix(ListElementController_InventoryWeapon_NotListView __instance, InventoryItemElement_NotListView theWidget) { try { if (__instance.quantity == -2147483648) { theWidget.qtyElement.SetActive(false); return(false); } theWidget.qtyElement.SetActive(true); theWidget.quantityValue.SetText("{0}", __instance.quantity); theWidget.quantityValueColor.SetUIColor((__instance.quantity > 0 || __instance.quantity == int.MinValue) ? UIColor.White : UIColor.Red); return(false); } catch (Exception e) { Log("*****Exception thrown with ListElementController_InventoryWeapon_NotListView"); Log($"theWidget null: {theWidget == null}"); Log($"theWidget.qtyElement null: {theWidget.qtyElement == null}"); Log($"theWidget.quantityValue null: {theWidget.quantityValue == null}"); Log($"theWidget.quantityValueColor null: {theWidget.quantityValueColor == null}"); if (theWidget.itemName != null) { Log("theWidget.itemName"); Log(theWidget.itemName.ToString()); } if (__instance.GetName() != null) { Log("__instance.GetName"); Log(__instance.GetName()); } Error(e); return(false); } }
public static void Postfix(ListElementController_SalvageMechPart_NotListView __instance, InventoryItemElement_NotListView theWidget, MechDef ___mechDef, SalvageDef ___salvageDef) { Mod.Log.Debug?.Write($"LEC_SMP_NLV:RIOW - entered"); if (___salvageDef != null && ___salvageDef.RewardID != null && ___salvageDef.RewardID.Contains("_qty")) { int qtyIdx = ___salvageDef.RewardID.IndexOf("_qty"); string countS = ___salvageDef.RewardID.Substring(qtyIdx + 4); int count = int.Parse(countS); Mod.Log.Debug?.Write($"LEC_SMP_NLV:RIOW - found quantity {count}, changing mechdef"); DescriptionDef currentDesc = ___mechDef.Chassis.Description; string displayName = !String.IsNullOrEmpty(currentDesc.UIName) ? currentDesc.UIName : currentDesc.Name; string newUIName = $"{displayName} <lowercase>[QTY:{count}]</lowercase>"; Text newPartName = new Text(newUIName, new object[] { }); theWidget.mechPartName.SetText(newPartName); } }
public static void Postfix(ListElementController_InventoryGear_NotListView __instance, InventoryItemElement_NotListView theWidget) { try { if (HasOverrideColor(__instance.componentRef.Def, out Color overrideColor)) { UIColorRefTracker[] array = theWidget.iconBGColors; for (int i = 0; i < array.Length; i++) { array[i].OverrideWithColor(overrideColor); } } } catch (Exception e) { Logger.Error(e); } }
public static int Compare_NotListView(InventoryItemElement_NotListView a, InventoryItemElement_NotListView b) { return(BetterSorting.Compare(ListElementControllerCompare.Wrap(b.controller), ListElementControllerCompare.Wrap(a.controller))); }
public static void Postfix(InventoryItemElement_NotListView __instance) { // have to be holding shift if (!(Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))) { return; } // Nothing to do, return if (__instance.controller == null || __instance.controller.salvageDef == null) { return; } // skip processing any non-parts or when the UI isn't up if (__instance.controller.salvageDef.Type == SalvageDef.SalvageType.MECH_PART) { return; } if (ModState.SimGameState == null || ModState.AAR_SalvageScreen == null) { Mod.Log.Warn?.Write("Expected state variables were null when performing quick sell - skipping!"); return; } // Ensure we can access the necessary UI elements before adding money if (__instance.DropParent is AAR_SalvageChosen salvageChosen) { Mod.Log.Debug?.Write("Checking contract salvage against controller item"); List <SalvageDef> salvageResults = ModState.Contract.SalvageResults; SalvageDef matchingItem = salvageResults.FirstOrDefault(x => x == __instance.controller.salvageDef); if (matchingItem != null) { // We have a matching salvageDef. Calculate the cost, and remove it from the list. var cost = __instance.controller.salvageDef.Description.Cost; var sellCost = Mathf.FloorToInt(cost * ModState.SimGameState.Constants.Finances.ShopSellModifier); Mod.Log.Info?.Write($"Selling {matchingItem?.Description.Name} worth {matchingItem?.Description.Cost}" + $" x {ModState.SimGameState.Constants.Finances.ShopSellModifier} shopSellModifier = {matchingItem?.Description.Cost * ModState.SimGameState.Constants.Finances.ShopSellModifier}"); ModState.SimGameState.AddFunds(sellCost, "LootMagnet", false, true); ModState.SGCurrencyDisplay.UpdateMoney(); // Create the new floatie text for the sell amount var floatie = new GameObject(ModConsts.LootMagnetFloatieGOName); floatie.transform.SetParent(ModState.HBSPopupRoot.transform); floatie.transform.position = __instance.gameObject.transform.position; var text = floatie.AddComponent <TextMeshProUGUI>(); text.font = ModState.FloatieFont; text.SetText($"¢{sellCost:N0}"); floatie.AddComponent <FloatieBehaviour>(); floatie.AddComponent <FadeText>(); // Finally, remove it from salvage - which has already been fixed ModState.Contract.SalvageResults.Remove(__instance.controller.salvageDef); // Remove it from the inventory widgets salvageChosen.LeftoverInventory.Remove(__instance); if (__instance.DropParent != null) { __instance.RemoveFromParent(); } __instance.gameObject.SetActive(false); } Mod.Log.Info?.Write("All items sold"); } }
public static bool ChangeColor(ListElementController_InventoryGear_NotListView __instance, InventoryItemElement_NotListView theWidget) { try { theWidget.iconBGColors.SetColor(__instance.componentRef); } catch (Exception ex) { Control.LogError(ex); } return(false); }
public static void Postfix(ListElementController_SalvageMechPart_NotListView __instance, InventoryItemElement_NotListView theWidget, MechDef ___mechDef, SalvageDef ___salvageDef) { if (UnityGameInstance.BattleTechGame.Simulation != null && UnityGameInstance.BattleTechGame.Simulation.Constants.Story.MaximumDebt == 42) { Mod.Log.Debug($"LEC_SMP_NLV:RIOW - entered"); if (___salvageDef.RewardID != null && ___salvageDef.RewardID.Contains("_qty")) { int qtyIdx = ___salvageDef.RewardID.IndexOf("_qty"); string countS = ___salvageDef.RewardID.Substring(qtyIdx + 4); int count = int.Parse(countS); Mod.Log.Debug($"LEC_SMP_NLV:RIOW - found quantity {count}, changing mechdef"); DescriptionDef currentDesc = ___mechDef.Chassis.Description; string newUIName = $"{currentDesc.UIName} <lowercase>[QTY:{count}]</lowercase>"; Text newPartName = new Text(newUIName, new object[] { }); theWidget.mechPartName.SetText(newPartName); } } }
public PatchMechlabLimitItems(MechLabPanel instance) { try { var sw = new Stopwatch(); sw.Start(); this.instance = instance; this.inventoryWidget = new Traverse(instance).Field("inventoryWidget") .GetValue <MechLabInventoryWidget>() .LogIfNull("inventoryWidget is null"); LogDebug($"StorageInventory contains {instance.storageInventory.Count}"); if (instance.IsSimGame) { new Traverse(instance).Field("originalStorageInventory").SetValue(instance.storageInventory.LogIfNull("storageInventory is null")); } LogDebug($"Mechbay Patch initialized :simGame? {instance.IsSimGame}"); List <ListElementController_BASE_NotListView> BuildRawInventory() => instance.storageInventory.Select <MechComponentRef, ListElementController_BASE_NotListView>(componentRef => { componentRef.LogIfNull("componentRef is null"); componentRef.DataManager = instance.dataManager.LogIfNull("(MechLabPanel instance).dataManager is null"); componentRef.RefreshComponentDef(); componentRef.Def.LogIfNull("componentRef.Def is null"); var count = (!instance.IsSimGame ? int.MinValue : instance.sim.GetItemCount(componentRef.Def.Description, componentRef.Def.GetType(), instance.sim.GetItemCountDamageType(componentRef))); if (componentRef.ComponentDefType == ComponentType.Weapon) { ListElementController_InventoryWeapon_NotListView controller = new ListElementController_InventoryWeapon_NotListView(); controller.InitAndFillInSpecificWidget(componentRef, null, instance.dataManager, null, count, false); return(controller); } else { ListElementController_InventoryGear_NotListView controller = new ListElementController_InventoryGear_NotListView(); controller.InitAndFillInSpecificWidget(componentRef, null, instance.dataManager, null, count, false); return(controller); } }).ToList(); /* Build a list of data only for all components. */ rawInventory = Sort(BuildRawInventory()); InventoryItemElement_NotListView mkiie(bool nonexistant) { var nlv = instance.dataManager.PooledInstantiate(ListElementController_BASE_NotListView.INVENTORY_ELEMENT_PREFAB_NotListView , BattleTechResourceType.UIModulePrefabs, null, null, null) .LogIfNull("Unable to instantiate INVENTORY_ELEMENT_PREFAB_NotListView") .GetComponent <InventoryItemElement_NotListView>() .LogIfNull("Inventory_Element_prefab does not contain a NLV"); nlv.gameObject.IsDestroyedError("NLV gameObject has been destroyed"); nlv.gameObject.LogIfNull("NLV gameObject has been destroyed"); if (!nonexistant) { nlv.SetRadioParent(new Traverse(inventoryWidget).Field("inventoryRadioSet").GetValue <HBSRadioSet>().LogIfNull("inventoryRadioSet is null")); nlv.gameObject.transform.SetParent(new Traverse(inventoryWidget).Field("listParent").GetValue <UnityEngine.Transform>().LogIfNull("listParent is null"), false); nlv.gameObject.transform.localScale = UnityEngine.Vector3.one; } return(nlv); }; iieTmp = mkiie(true); /* Allocate very few visual elements, as this is extremely slow for both allocation and deallocation. * It's the difference between a couple of milliseconds and several seconds for many unique items in inventory * This is the core of the fix, the rest is just to make it work within HBS's existing code. */ List <InventoryItemElement_NotListView> make_ielCache() => Enumerable.Repeat <Func <InventoryItemElement_NotListView> >(() => mkiie(false), itemLimit) .Select(thunk => thunk()) .ToList(); ielCache = make_ielCache(); var li = new Traverse(inventoryWidget).Field("localInventory").GetValue <List <InventoryItemElement_NotListView> >(); ielCache.ForEach(iw => li.Add(iw)); // End var lp = new Traverse(inventoryWidget).Field("listParent").GetValue <UnityEngine.Transform>(); // DummyStart&End are blank rects stored at the beginning and end of the list so that unity knows how big the scrollrect should be // "placeholders" if (DummyStart == null) { DummyStart = new UnityEngine.GameObject().AddComponent <UnityEngine.RectTransform>(); } if (DummyEnd == null) { DummyEnd = new UnityEngine.GameObject().AddComponent <UnityEngine.RectTransform>(); } DummyStart.SetParent(lp, false); DummyEnd.SetParent(lp, false); LogDebug(string.Format("[LimitItems] inventory cached in {0} ms", sw.Elapsed.TotalMilliseconds)); FilterChanged(); } catch (Exception e) { LogException(e); } }
public static bool MechCanEquipItem_Pre(InventoryItemElement_NotListView item) { return(item.ComponentRef == null ? false : true); }
public static bool ChangeColor(ListElementController_InventoryGear_NotListView __instance, InventoryItemElement_NotListView theWidget) { try { ColorExtentions.ChangeBackColor(__instance.componentRef.Def, theWidget); TColorExtentions.ChangeTextIconColor(__instance.componentRef.Def, theWidget); } catch { return(true); } return(false); }
public static void Postfix(ListElementController_SalvageMechPart_NotListView __instance, InventoryItemElement_NotListView theWidget, SimGameState ___simState) { int pieces = ___simState.GetItemCount(__instance.mechDef.Description.Id, "MECHPART", SimGameState.ItemCountType.UNDAMAGED_ONLY); int needed = ___simState.Constants.Story.DefaultMechPartMax; int varpieces = SimpleMechAssembly_Main.GetNumPartsForAssembly(___simState, __instance.mechDef); int owned = SimpleMechAssembly_Main.GetNumberOfMechsOwnedOfType(___simState, __instance.mechDef); theWidget.mechPartsNumbersText.SetText(string.Format("{0}({1})/{3}({2})", pieces, varpieces, owned, needed)); }
public static void Postfix(ListElementController_SalvageMechPart_NotListView __instance, InventoryItemElement_NotListView theWidget, SimGameState ___simState) { theWidget.mechPartsNumbersText.SetText(SimpleMechAssembly_Main.GetMechCountDescrString(___simState, __instance.mechDef)); }