Files
7d2dXG/Mods/zzz_REBIRTH__Utils/Scripts/XUIC/XUiC_ItemInfoWindowRebirth.cs
Nathaniel Cosford 062dfab2cd Patched
2025-05-30 01:04:40 +09:30

492 lines
23 KiB
C#

using System.Collections.Generic;
using UnityEngine.Scripting;
[Preserve]
public class XUiC_ItemInfoWindowRebirth : XUiC_InfoWindow
{
private ItemStack itemStack = ItemStack.Empty.Clone();
private ItemClass itemClass;
private XUiC_RepairableVehicleStack selectedItemStack;
private XUiController itemPreview;
private XUiC_ItemActionList mainActionItemList;
private XUiC_ItemActionList traderActionItemList;
private XUiC_PartList partList;
public XUiC_Counter BuySellCounter;
private XUiController statButton;
private XUiController descriptionButton;
private XUiC_InfoWindow emptyInfoWindow;
private bool isBuying;
private bool useCustomMarkup;
public bool SetMaxCountOnDirty;
private ItemDisplayEntry itemDisplayEntry;
private XUiC_SelectableEntry hoverEntry;
private ItemStack compareStack = ItemStack.Empty;
private bool showStats = true;
private readonly CachedStringFormatterInt itemcostFormatter = new CachedStringFormatterInt();
private readonly CachedStringFormatter<int> markupFormatter = new CachedStringFormatter<int>((Func<int, string>)(_i =>
{
if (_i > 0)
return string.Format(" (+{0}%)", (object)_i);
return _i >= 0 ? "" : string.Format(" ({0}%)", (object)_i);
}));
private readonly CachedStringFormatterXuiRgbaColor itemicontintcolorFormatter = new CachedStringFormatterXuiRgbaColor();
private readonly CachedStringFormatterXuiRgbaColor durabilitycolorFormatter = new CachedStringFormatterXuiRgbaColor();
private readonly CachedStringFormatterFloat durabilityfillFormatter = new CachedStringFormatterFloat();
private readonly CachedStringFormatterInt durabilitytextFormatter = new CachedStringFormatterInt();
private readonly CachedStringFormatterXuiRgbaColor altitemtypeiconcolorFormatter = new CachedStringFormatterXuiRgbaColor();
private static readonly Dictionary<string, string> itemGroupToIcon;
private static readonly string defaultItemGroupIcon;
private bool isOpenAsTrader => this.xui.Trader != null && this.xui.Trader.Trader != null;
public XUiC_SelectableEntry HoverEntry
{
get => this.hoverEntry;
set
{
if (this.hoverEntry == value)
return;
this.hoverEntry = value;
if (this.hoverEntry != null && !this.hoverEntry.Selected && !this.itemStack.IsEmpty())
{
ItemStack controllerItemStack = this.GetHoverControllerItemStack();
if (!controllerItemStack.IsEmpty() && XUiM_ItemStack.CanCompare(controllerItemStack.itemValue.ItemClass, this.itemClass))
this.CompareStack = controllerItemStack;
else
this.CompareStack = ItemStack.Empty;
}
else
this.CompareStack = ItemStack.Empty;
}
}
public ItemStack CompareStack
{
get => this.compareStack;
set
{
if (this.compareStack == value)
return;
this.compareStack = value;
this.RefreshBindings();
}
}
private ItemStack GetHoverControllerItemStack()
{
//Log.Out("XUiC_ItemInfoWindowRebirth-GetHoverControllerItemStack START");
if (this.hoverEntry is XUiC_RepairableVehicleStack hoverEntry1)
{
//Log.Out("XUiC_ItemInfoWindowRebirth-GetHoverControllerItemStack 1");
return hoverEntry1.ItemStack;
}
return this.hoverEntry is XUiC_QuestTurnInEntry hoverEntry5 ? hoverEntry5.Item : (ItemStack)null;
}
public override void Init()
{
//Log.Out("XUiC_ItemInfoWindowRebirth-Init START");
base.Init();
this.itemPreview = this.GetChildById("itemPreview");
this.mainActionItemList = (XUiC_ItemActionList)this.GetChildById("itemActions");
this.traderActionItemList = (XUiC_ItemActionList)this.GetChildById("vendorItemActions");
this.partList = (XUiC_PartList)this.GetChildById("parts");
this.BuySellCounter = this.GetChildByType<XUiC_Counter>();
if (this.BuySellCounter != null)
{
//Log.Out("XUiC_ItemInfoWindowRebirth-Init 1");
this.BuySellCounter.OnCountChanged += new XUiEvent_OnCountChanged(this.Counter_OnCountChanged);
this.BuySellCounter.Count = 1;
}
this.statButton = this.GetChildById("statButton");
this.statButton.OnPress += new XUiEvent_OnPressEventHandler(this.StatButton_OnPress);
this.descriptionButton = this.GetChildById("descriptionButton");
this.descriptionButton.OnPress += new XUiEvent_OnPressEventHandler(this.DescriptionButton_OnPress);
}
private void DescriptionButton_OnPress(XUiController _sender, int _mouseButton)
{
//Log.Out("XUiC_ItemInfoWindowRebirth-DescriptionButton_OnPress START");
((XUiV_Button)this.statButton.ViewComponent).Selected = false;
((XUiV_Button)this.descriptionButton.ViewComponent).Selected = true;
this.showStats = false;
this.IsDirty = true;
}
private void StatButton_OnPress(XUiController _sender, int _mouseButton)
{
//Log.Out("XUiC_ItemInfoWindowRebirth-StatButton_OnPress START");
((XUiV_Button)this.statButton.ViewComponent).Selected = true;
((XUiV_Button)this.descriptionButton.ViewComponent).Selected = false;
this.showStats = true;
this.IsDirty = true;
}
private void Counter_OnCountChanged(XUiController _sender, OnCountChangedEventArgs _e)
{
//Log.Out("XUiC_ItemInfoWindowRebirth-Counter_OnCountChanged START");
this.RefreshBindings();
this.traderActionItemList.RefreshActionList();
}
public override void Deselect()
{
}
public override void Update(float _dt)
{
base.Update(_dt);
if (!this.IsDirty || !this.ViewComponent.IsVisible)
return;
if (this.emptyInfoWindow == null)
this.emptyInfoWindow = (XUiC_InfoWindow)this.xui.FindWindowGroupByName("backpack").GetChildById("emptyInfoPanel");
if (this.selectedItemStack != null)
this.SetItemStack(this.selectedItemStack);
this.IsDirty = false;
}
public override bool GetBindingValue(ref string value, string bindingName)
{
switch (bindingName)
{
case "durabilitycolor":
Color32 _v1_1 = (Color32)Color.white;
if (!this.itemStack.IsEmpty())
_v1_1 = (Color32)QualityInfo.GetTierColor(this.itemStack.itemValue.Quality);
value = this.durabilitycolorFormatter.Format(_v1_1);
return true;
case "durabilityfill":
value = !this.itemStack.IsEmpty() ? (this.itemStack.itemValue.MaxUseTimes == 0 ? "1" : this.durabilityfillFormatter.Format(((float)this.itemStack.itemValue.MaxUseTimes - this.itemStack.itemValue.UseTimes) / (float)this.itemStack.itemValue.MaxUseTimes)) : "";
return true;
case "durabilityjustify":
value = "center";
if (!this.itemStack.IsEmpty() && !this.itemClass.ShowQualityBar)
value = "right";
return true;
case "durabilitytext":
value = "";
if (!this.itemStack.IsEmpty())
value = !this.itemClass.ShowQualityBar ? (this.itemClass.Stacknumber == 1 ? "" : this.durabilitytextFormatter.Format(this.itemStack.count)) : (this.itemStack.itemValue.Quality > 0 ? this.durabilitytextFormatter.Format(this.itemStack.itemValue.Quality) : "-");
return true;
case "hasdurability":
value = (!this.itemStack.IsEmpty() && this.itemClass.ShowQualityBar).ToString();
return true;
case "hasitemtypeicon":
value = !this.itemStack.IsEmpty() ? (!this.itemStack.itemValue.ItemClass.IsBlock() ? (this.itemStack.itemValue.ItemClass.ItemTypeIcon != "").ToString() : (Block.list[this.itemStack.itemValue.type].ItemTypeIcon != "").ToString()) : "false";
return true;
case "iscomparing":
value = (!this.CompareStack.IsEmpty()).ToString();
return true;
case "isnotcomparing":
value = this.CompareStack.IsEmpty().ToString();
return true;
case "itemammoname":
value = "";
if (this.itemClass != null)
{
if (this.itemClass.Actions[0] is ItemActionRanged action2)
{
if (action2.MagazineItemNames.Length > 1)
{
ItemClass itemClass = ItemClass.GetItemClass(action2.MagazineItemNames[(int)this.itemStack.itemValue.SelectedAmmoTypeIndex]);
value = itemClass.GetLocalizedItemName();
}
}
else if (this.itemClass.Actions[0] is ItemActionLauncher action1 && action1.MagazineItemNames.Length > 1)
{
ItemClass itemClass = ItemClass.GetItemClass(action1.MagazineItemNames[(int)this.itemStack.itemValue.SelectedAmmoTypeIndex]);
value = itemClass.GetLocalizedItemName();
}
}
return true;
case "itemdescription":
value = "";
if (this.itemClass != null)
{
if (this.itemClass.IsBlock())
{
string descriptionKey = Block.list[this.itemClass.Id].DescriptionKey;
if (Localization.Exists(descriptionKey))
value = Localization.Get(descriptionKey);
}
else
{
string descriptionKey = this.itemClass.DescriptionKey;
if (Localization.Exists(descriptionKey))
value = Localization.Get(descriptionKey);
if (this.itemClass.Unlocks != "")
{
ItemClass itemClass = ItemClass.GetItemClass(this.itemClass.Unlocks);
if (itemClass != null)
value = value + "\n\n" + Localization.Get(itemClass.DescriptionKey);
}
}
}
return true;
case "itemgroupicon":
value = "";
if (this.itemClass != null && this.itemClass.Groups.Length != 0)
{
string group = this.itemClass.Groups[0];
if (!XUiC_ItemInfoWindowRebirth.itemGroupToIcon.TryGetValue(group, out value))
value = XUiC_ItemInfoWindowRebirth.defaultItemGroupIcon;
}
return true;
case "itemicon":
value = this.itemStack == null ? "" : this.itemStack.itemValue.GetPropertyOverride("CustomIcon", this.itemStack.itemValue.ItemClass != null ? this.itemStack.itemValue.ItemClass.GetIconName() : "");
return true;
case "itemicontint":
Color32 _v1_2 = (Color32)Color.white;
if (this.itemClass != null)
_v1_2 = (Color32)this.itemStack.itemValue.ItemClass.GetIconTint(this.itemStack.itemValue);
value = this.itemicontintcolorFormatter.Format(_v1_2);
return true;
case "itemname":
value = this.itemClass != null ? this.itemClass.GetLocalizedItemName() : "";
return true;
case "itemstattitle1":
value = this.itemClass != null ? this.GetStatTitle(0) : "";
return true;
case "itemstattitle2":
value = this.itemClass != null ? this.GetStatTitle(1) : "";
return true;
case "itemstattitle3":
value = this.itemClass != null ? this.GetStatTitle(2) : "";
return true;
case "itemstattitle4":
value = this.itemClass != null ? this.GetStatTitle(3) : "";
return true;
case "itemstattitle5":
value = this.itemClass != null ? this.GetStatTitle(4) : "";
return true;
case "itemstattitle6":
value = this.itemClass != null ? this.GetStatTitle(5) : "";
return true;
case "itemstattitle7":
value = this.itemClass != null ? this.GetStatTitle(6) : "";
return true;
case "itemtypeicon":
if (this.itemStack.IsEmpty())
value = "";
else if (this.itemStack.itemValue.ItemClass.IsBlock())
{
value = Block.list[this.itemStack.itemValue.type].ItemTypeIcon;
}
else
{
if (this.itemStack.itemValue.ItemClass.AltItemTypeIcon != null && this.itemStack.itemValue.ItemClass.Unlocks != "" && XUiM_ItemStack.CheckKnown(this.xui.playerUI.entityPlayer, this.itemStack.itemValue.ItemClass, this.itemStack.itemValue))
{
value = this.itemStack.itemValue.ItemClass.AltItemTypeIcon;
return true;
}
value = this.itemStack.itemValue.ItemClass.ItemTypeIcon;
}
return true;
case "itemtypeicontint":
value = "255,255,255,255";
if (!this.itemStack.IsEmpty() && this.itemStack.itemValue.ItemClass.Unlocks != "" && XUiM_ItemStack.CheckKnown(this.xui.playerUI.entityPlayer, this.itemStack.itemValue.ItemClass, this.itemStack.itemValue))
value = this.altitemtypeiconcolorFormatter.Format((Color32)this.itemStack.itemValue.ItemClass.AltItemTypeIconColor);
return true;
case "pricelabel":
value = "";
if (this.itemClass != null && (!this.itemClass.IsBlock() ? this.itemClass.SellableToTrader : Block.list[this.itemStack.itemValue.type].SellableToTrader))
{
int count = this.itemStack.count;
if (this.isOpenAsTrader)
count = this.BuySellCounter.Count;
value = !this.isBuying ? (XUiM_Trader.GetSellPrice(this.xui, this.itemStack.itemValue, count, this.itemClass) > 0 ? Localization.Get("xuiSellPrice") : "") : (XUiM_Trader.GetBuyPrice(this.xui, this.itemStack.itemValue, count, this.itemClass) > 0 ? Localization.Get("xuiBuyPrice") : "");
}
return true;
case "showdescription":
value = (!this.showStats).ToString();
return true;
case "shownormaloptions":
value = (!this.isOpenAsTrader).ToString();
return true;
case "showonlydescription":
value = (!XUiM_ItemStack.HasItemStats(this.itemStack)).ToString();
return true;
case "showstatanddescription":
value = XUiM_ItemStack.HasItemStats(this.itemStack).ToString();
return true;
case "showstatoptions":
value = "false";
return true;
case "showstats":
value = this.showStats.ToString();
return true;
case "showtraderoptions":
value = this.isOpenAsTrader.ToString();
return true;
default:
return false;
}
}
private string GetStatTitle(int index)
{
//Log.Out("XUiC_ItemInfoWindowRebirth-GetStatTitle START");
if (this.itemDisplayEntry == null || this.itemDisplayEntry.DisplayStats.Count <= index)
return "";
return this.itemDisplayEntry.DisplayStats[index].TitleOverride != null ? this.itemDisplayEntry.DisplayStats[index].TitleOverride : UIDisplayInfoManager.Current.GetLocalizedName(this.itemDisplayEntry.DisplayStats[index].StatType);
}
private void makeVisible(bool _makeVisible)
{
//Log.Out("XUiC_ItemInfoWindowRebirth-makeVisible START");
if (!_makeVisible || !this.windowGroup.isShowing)
{
//Log.Out("XUiC_ItemInfoWindowRebirth-makeVisible 1");
return;
}
this.ViewComponent.IsVisible = true;
((XUiV_Window)this.viewComponent).ForceVisible(1f);
}
public void SetItemStack(XUiC_RepairableVehicleStack stack, bool _makeVisible = false)
{
//Log.Out("XUiC_ItemInfoWindowRebirth-SetItemStack START");
if (stack == null || stack.ItemStack.IsEmpty())
{
//Log.Out("XUiC_ItemInfoWindowRebirth-SetItemStack 1");
this.ShowEmptyInfo();
}
else
{
//Log.Out("XUiC_ItemInfoWindowRebirth-SetItemStack 2");
this.makeVisible(_makeVisible);
this.selectedItemStack = stack;
this.SetInfo(stack.ItemStack, (XUiController)stack, XUiC_ItemActionList.ItemActionListTypes.Item);
}
}
private void ShowEmptyInfo()
{
//Log.Out("XUiC_ItemInfoWindowRebirth-ShowEmptyInfo START");
if (this.emptyInfoWindow == null)
{
//Log.Out("XUiC_ItemInfoWindowRebirth-ShowEmptyInfo 1");
this.emptyInfoWindow = (XUiC_InfoWindow)this.xui.FindWindowGroupByName("backpack").GetChildById("emptyInfoPanel");
}
this.emptyInfoWindow.ViewComponent.IsVisible = true;
}
private void SetInfo(
ItemStack stack,
XUiController controller,
XUiC_ItemActionList.ItemActionListTypes actionListType)
{
//Log.Out("XUiC_ItemInfoWindowRebirth-SetInfo START");
bool flag1 = stack.itemValue.type == this.itemStack.itemValue.type && stack.count == this.itemStack.count;
this.itemStack = stack.Clone();
bool flag2 = this.itemStack != null && !this.itemStack.IsEmpty();
if (this.itemPreview == null)
{
//Log.Out("XUiC_ItemInfoWindowRebirth-SetInfo 1");
return;
}
if (!flag1 || !stack.itemValue.Equals(this.itemStack.itemValue))
{
//Log.Out("XUiC_ItemInfoWindowRebirth-SetInfo 2");
this.compareStack = ItemStack.Empty.Clone();
}
this.itemClass = (ItemClass)null;
int num = 1;
if (flag2)
{
//Log.Out("XUiC_ItemInfoWindowRebirth-SetInfo 3");
this.itemClass = this.itemStack.itemValue.ItemClass;
if (this.itemClass is ItemClassQuest)
{
//Log.Out("XUiC_ItemInfoWindowRebirth-SetInfo 4");
this.itemClass = (ItemClass)ItemClassQuest.GetItemQuestById(this.itemStack.itemValue.Seed);
}
num = this.itemClass.IsBlock() ? Block.list[this.itemStack.itemValue.type].EconomicBundleSize : this.itemClass.EconomicBundleSize;
}
if (flag2)
{
//Log.Out("XUiC_ItemInfoWindowRebirth-SetInfo 5");
this.itemDisplayEntry = UIDisplayInfoManager.Current.GetDisplayStatsForTag(this.itemClass.IsBlock() ? Block.list[this.itemStack.itemValue.type].DisplayType : this.itemClass.DisplayType);
}
if (this.isOpenAsTrader)
{
//Log.Out("XUiC_ItemInfoWindowRebirth-SetInfo 6");
this.isBuying = actionListType == XUiC_ItemActionList.ItemActionListTypes.Trader;
this.traderActionItemList.SetCraftingActionList(actionListType, controller);
int count = this.BuySellCounter.Count;
if (!flag1)
{
//Log.Out("XUiC_ItemInfoWindowRebirth-SetInfo 7");
this.BuySellCounter.Count = this.itemStack.count < num ? 0 : num;
}
else if (count > this.itemStack.count)
{
//Log.Out("XUiC_ItemInfoWindowRebirth-SetInfo 8");
this.BuySellCounter.Count = this.itemStack.count < num ? 0 : this.itemStack.count;
}
this.BuySellCounter.MaxCount = this.itemStack.count < num ? 0 : this.itemStack.count / num * num;
this.BuySellCounter.Step = num;
if (this.BuySellCounter.Count == 0 && this.itemStack.count >= num)
{
//Log.Out("XUiC_ItemInfoWindowRebirth-SetInfo 9");
this.BuySellCounter.Count = num;
}
if (this.SetMaxCountOnDirty)
{
//Log.Out("XUiC_ItemInfoWindowRebirth-SetInfo 10");
this.BuySellCounter.Count = this.BuySellCounter.MaxCount;
this.SetMaxCountOnDirty = false;
}
this.BuySellCounter.ForceTextRefresh();
}
else
{
//Log.Out("XUiC_ItemInfoWindowRebirth-SetInfo 11");
this.mainActionItemList.SetCraftingActionList(actionListType, controller);
this.isBuying = false;
this.useCustomMarkup = false;
}
if (flag2 && this.itemStack.itemValue.Modifications != null)
{
//Log.Out("XUiC_ItemInfoWindowRebirth-SetInfo 12");
if (this.itemStack.itemValue.CosmeticMods != null && this.itemStack.itemValue.CosmeticMods.Length != 0 && this.itemStack.itemValue.CosmeticMods[0] != null && !this.itemStack.itemValue.CosmeticMods[0].IsEmpty())
{
//Log.Out("XUiC_ItemInfoWindowRebirth-SetInfo 13");
this.partList.SetSlot(this.itemStack.itemValue.CosmeticMods[0], 0);
this.partList.SetSlots(this.itemStack.itemValue.Modifications, 1);
}
else
{
//Log.Out("XUiC_ItemInfoWindowRebirth-SetInfo 14");
this.partList.SetSlots(this.itemStack.itemValue.Modifications);
}
this.partList.ViewComponent.IsVisible = true;
}
else
{
//Log.Out("XUiC_ItemInfoWindowRebirth-SetInfo 15");
this.partList.ViewComponent.IsVisible = false;
}
this.RefreshBindings();
}
static XUiC_ItemInfoWindowRebirth()
{
CaseInsensitiveStringDictionary<string> stringDictionary = new CaseInsensitiveStringDictionary<string>();
stringDictionary.Add("basics", "ui_game_symbol_campfire");
stringDictionary.Add("building", "ui_game_symbol_map_house");
stringDictionary.Add("resources", "ui_game_symbol_resource");
stringDictionary.Add("ammo/weapons", "ui_game_symbol_knife");
stringDictionary.Add("tools/traps", "ui_game_symbol_tool");
stringDictionary.Add("food/cooking", "ui_game_symbol_fork");
stringDictionary.Add("medicine", "ui_game_symbol_medical");
stringDictionary.Add("clothing", "ui_game_symbol_shirt");
stringDictionary.Add("decor/miscellaneous", "ui_game_symbol_chair");
stringDictionary.Add("books", "ui_game_symbol_book");
stringDictionary.Add("chemicals", "ui_game_symbol_water");
stringDictionary.Add("mods", "ui_game_symbol_assemble");
XUiC_ItemInfoWindowRebirth.itemGroupToIcon = (Dictionary<string, string>)stringDictionary;
XUiC_ItemInfoWindowRebirth.defaultItemGroupIcon = "ui_game_symbol_campfire";
}
}