Decompiled source of DashboardOverhaul v1.1.0

DashboardOverhaul.dll

Decompiled 31 minutes ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("DashboardOverhaul")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A series of enhancements for the in-game Dashboard / 为游戏内仪表盘提供一系列优化")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+daef6169a856768b4ce6b07520eb4af0c40d594f")]
[assembly: AssemblyProduct("DashboardOverhaul")]
[assembly: AssemblyTitle("DashboardOverhaul")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace DashboardOverhaul
{
	public static class ChartRename
	{
		private static InputField _input;

		private static UIChart _target;

		public static void Begin(UIChart chart)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)chart == (Object)null)
			{
				return;
			}
			UIDashboard uiDashboard = chart.uiDashboard;
			if ((Object)(object)uiDashboard == (Object)null || (Object)(object)uiDashboard.chartContentRt == (Object)null)
			{
				return;
			}
			StatPlan val = ResolveStatPlan(chart);
			if (val != null)
			{
				InputField obj = EnsureInput(uiDashboard);
				_target = chart;
				RectTransform val2 = (RectTransform)((Component)obj).transform;
				RectTransform obj2 = (((Object)(object)chart.titleText != (Object)null) ? ((Graphic)chart.titleText).rectTransform : chart.rectTrans);
				Transform parent = ((Transform)val2).parent;
				RectTransform val3 = (RectTransform)(object)((parent is RectTransform) ? parent : null);
				Vector3[] array = (Vector3[])(object)new Vector3[4];
				obj2.GetWorldCorners(array);
				float num = 140f;
				float num2 = 22f;
				if ((Object)(object)val3 != (Object)null)
				{
					Vector3 val4 = ((Transform)val3).InverseTransformPoint(array[1]);
					Vector3 val5 = ((Transform)val3).InverseTransformPoint(array[2]);
					Vector3 val6 = ((Transform)val3).InverseTransformPoint(array[0]);
					num = Mathf.Max(140f, Mathf.Abs(val5.x - val4.x));
					num2 = Mathf.Max(20f, Mathf.Abs(val4.y - val6.y));
				}
				Vector2 val7 = default(Vector2);
				((Vector2)(ref val7))..ctor(0f, 1f);
				val2.anchorMax = val7;
				val2.anchorMin = val7;
				val2.pivot = new Vector2(0f, 1f);
				val2.sizeDelta = new Vector2(num, num2);
				((Transform)val2).position = array[1];
				((Component)obj).gameObject.SetActive(true);
				obj.text = val.name ?? string.Empty;
				((Selectable)obj).Select();
				obj.ActivateInputField();
			}
		}

		public static void CancelIfTargeting(UIChart chart)
		{
			if ((Object)(object)_target == (Object)(object)chart)
			{
				Hide();
			}
		}

		public static void Free()
		{
			if ((Object)(object)_input != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_input).gameObject);
			}
			_input = null;
			_target = null;
		}

		private static StatPlan ResolveStatPlan(UIChart chart)
		{
			StatPlanPool val = (((Object)(object)chart != (Object)null && chart.charts != null) ? chart.charts.statPlans : null);
			if (val == null || val.buffer == null || chart.chartData == null)
			{
				return null;
			}
			int statPlanId = chart.chartData.statPlanId;
			if (statPlanId < 0 || statPlanId >= val.buffer.Length)
			{
				return null;
			}
			return val.buffer[statPlanId];
		}

		private static InputField EnsureInput(UIDashboard dash)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_input != (Object)null)
			{
				return _input;
			}
			Font font = (((Object)(object)dash.emptyTip != (Object)null) ? dash.emptyTip.font : null);
			GameObject val = new GameObject("DO_ChartRenameInput", new Type[1] { typeof(RectTransform) });
			RectTransform val2 = (RectTransform)val.transform;
			((Transform)val2).SetParent((Transform)(object)dash.chartContentRt, false);
			val2.sizeDelta = new Vector2(140f, 22f);
			((Graphic)val.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0.85f);
			GameObject val3 = new GameObject("Text", new Type[1] { typeof(RectTransform) });
			RectTransform val4 = (RectTransform)val3.transform;
			((Transform)val4).SetParent((Transform)(object)val2, false);
			val4.anchorMin = Vector2.zero;
			val4.anchorMax = Vector2.one;
			val4.offsetMin = new Vector2(6f, 0f);
			val4.offsetMax = new Vector2(-6f, 0f);
			Text val5 = val3.AddComponent<Text>();
			val5.font = font;
			val5.fontSize = 14;
			val5.alignment = (TextAnchor)3;
			((Graphic)val5).color = Color.white;
			val5.supportRichText = false;
			val5.verticalOverflow = (VerticalWrapMode)1;
			InputField obj = val.AddComponent<InputField>();
			obj.textComponent = val5;
			obj.lineType = (LineType)0;
			obj.characterLimit = 64;
			((UnityEvent<string>)(object)obj.onEndEdit).AddListener((UnityAction<string>)Commit);
			val.SetActive(false);
			_input = obj;
			return obj;
		}

		private static void Commit(string value)
		{
			UIChart target = _target;
			Hide();
			StatPlan val = ResolveStatPlan(target);
			if (val != null)
			{
				string text = (value ?? string.Empty).Trim();
				val.Rename(ref text);
				target.TruncateStatPlanNameText();
				RefreshSidebarName(target.uiDashboard, val);
			}
		}

		private static void RefreshSidebarName(UIDashboard dash, StatPlan statPlan)
		{
			UIStatboard val = (((Object)(object)dash != (Object)null) ? dash.statboard : null);
			if ((Object)(object)val == (Object)null || val.objectEntryPool == null || statPlan == null)
			{
				return;
			}
			List<UIStatPlanEntry> objectEntryPool = val.objectEntryPool;
			for (int i = 0; i < objectEntryPool.Count; i++)
			{
				UIStatPlanEntry val2 = objectEntryPool[i];
				if ((Object)(object)val2 != (Object)null && val2.statPlan != null && val2.statPlan.id == statPlan.id && (Object)(object)val2.nameInput != (Object)null)
				{
					val2.nameInput.text = (string.IsNullOrEmpty(statPlan.name) ? null : statPlan.name);
				}
			}
		}

		private static void Hide()
		{
			_target = null;
			if ((Object)(object)_input != (Object)null)
			{
				((Component)_input).gameObject.SetActive(false);
			}
		}
	}
	public class ChartTitleRenameTrigger : MonoBehaviour, IPointerClickHandler, IEventSystemHandler
	{
		public UIChart Owner;

		public void OnPointerClick(PointerEventData eventData)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)Owner == (Object)null) && (int)eventData.button == 0 && eventData.clickCount >= 2)
			{
				ChartRename.Begin(Owner);
			}
		}
	}
	public static class DashboardLayoutPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(DashboardLayout), "Import")]
		private static void Import_Prefix(DashboardLayout __instance)
		{
			if (__instance.pages != null)
			{
				__instance.pages[1] = null;
			}
		}
	}
	[BepInPlugin("org.fyyy.dashboardoverhaul", "DashboardOverhaul", "1.1.0")]
	public class DashboardOverhaulPlugin : BaseUnityPlugin
	{
		public static readonly ManualLogSource Logger = Logger.CreateLogSource("DashboardOverhaul");

		private Harmony _harmony;

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			_harmony = new Harmony("org.fyyy.dashboardoverhaul");
			_harmony.PatchAll(typeof(UIDashboardPatch));
			_harmony.PatchAll(typeof(UIChartPatch));
			_harmony.PatchAll(typeof(DashboardLayoutPatch));
			Logger.LogInfo((object)"DashboardOverhaul loaded.");
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	public static class Loc
	{
		public static string L(string zh, string en)
		{
			if (!Localization.isZHCN)
			{
				return en;
			}
			return zh;
		}
	}
	public static class PageOps
	{
		public static int ActivePageCount(CustomCharts charts)
		{
			int num = 0;
			DashboardPage[] pages = charts.dashboardLayout.pages;
			for (int i = 1; i < 10; i++)
			{
				if (pages[i] != null)
				{
					num++;
				}
			}
			return num;
		}

		public static int FirstFreeSlot(DashboardLayout layout)
		{
			DashboardPage[] pages = layout.pages;
			for (int i = 1; i < 10; i++)
			{
				if (pages[i] == null)
				{
					return i;
				}
			}
			return -1;
		}

		public static int FirstActiveSlot(DashboardLayout layout)
		{
			DashboardPage[] array = layout?.pages;
			if (array == null)
			{
				return -1;
			}
			for (int i = 1; i < 10; i++)
			{
				if (array[i] != null)
				{
					return i;
				}
			}
			return -1;
		}

		public static bool IsValidViewPage(CustomCharts charts)
		{
			DashboardPage[] array = charts?.dashboardLayout?.pages;
			if (array == null)
			{
				return false;
			}
			int pageIndex = charts.currentView.pageIndex;
			if (pageIndex >= 1 && pageIndex < 10)
			{
				return array[pageIndex] != null;
			}
			return false;
		}

		public static int AddPage(CustomCharts charts)
		{
			DashboardLayout dashboardLayout = charts.dashboardLayout;
			int num = FirstFreeSlot(dashboardLayout);
			if (num < 0)
			{
				return -1;
			}
			dashboardLayout.AddPage(num);
			return num;
		}

		public static bool CanDelete(CustomCharts charts)
		{
			return ActivePageCount(charts) > 1;
		}

		public static int PickPageAfterDelete(DashboardLayout layout, int deletedIndex)
		{
			DashboardPage[] pages = layout.pages;
			for (int num = deletedIndex - 1; num >= 1; num--)
			{
				if (pages[num] != null)
				{
					return num;
				}
			}
			for (int i = deletedIndex + 1; i < 10; i++)
			{
				if (pages[i] != null)
				{
					return i;
				}
			}
			return -1;
		}

		public static bool RemovePage(CustomCharts charts, int index)
		{
			if (index < 1 || index >= 10)
			{
				return false;
			}
			DashboardPage[] pages = charts.dashboardLayout.pages;
			DashboardPage val = pages[index];
			if (val == null)
			{
				return false;
			}
			val.Free();
			pages[index] = null;
			return true;
		}

		public static void RenamePage(DashboardPage page, string newName)
		{
			if (page != null)
			{
				page.name = (newName ?? string.Empty).Trim();
			}
		}
	}
	public class PageTab : MonoBehaviour, IPointerClickHandler, IEventSystemHandler
	{
		public int Slot;

		private PageTabBar _bar;

		public Text Label;

		public Image Background;

		public void Setup(PageTabBar bar, int slot, string label, bool current)
		{
			_bar = bar;
			Slot = slot;
			if ((Object)(object)Label != (Object)null)
			{
				Label.text = label;
			}
			SetCurrent(current);
		}

		public void SetCurrent(bool current)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)Background == (Object)null))
			{
				Color val = ((_bar != null) ? _bar.Dashboard.focusColor : Color.gray);
				((Graphic)Background).color = (Color)(current ? val : new Color(val.r, val.g, val.b, 0.15f));
			}
		}

		public void OnPointerClick(PointerEventData eventData)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			if (_bar != null)
			{
				if ((int)eventData.button == 1)
				{
					_bar.OpenContextMenu(this);
				}
				else if (eventData.clickCount >= 2)
				{
					_bar.BeginRename(this);
				}
				else
				{
					_bar.SwitchTo(Slot);
				}
			}
		}
	}
	public class PageTabBar
	{
		private RectTransform _root;

		private Font _font;

		private readonly List<PageTab> _tabs = new List<PageTab>();

		private InputField _renameInput;

		private int _renamingSlot = -1;

		private const int kTabHeight = 20;

		private const int kTabMinWidth = 64;

		private const float kTabMaxWidth = 160f;

		private const float kTabHPadding = 20f;

		private const float kBaseLeftMargin = 40f;

		private const float kTopOffset = -4f;

		public UIDashboard Dashboard { get; private set; }

		public void Build(UIDashboard dashboard)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			Dashboard = dashboard;
			_font = (((Object)(object)dashboard.emptyTip != (Object)null) ? dashboard.emptyTip.font : null);
			if ((Object)(object)_font == (Object)null)
			{
				DashboardOverhaulPlugin.Logger.LogWarning((object)"[DashboardOverhaul] emptyTip/font is null; tab labels may be invisible.");
			}
			GameObject val = new GameObject("DO_PageTabBar", new Type[1] { typeof(RectTransform) });
			_root = (RectTransform)val.transform;
			((Transform)_root).SetParent((Transform)(object)dashboard.rectTrans, false);
			_root.anchorMin = new Vector2(0f, 1f);
			_root.anchorMax = new Vector2(0f, 1f);
			_root.pivot = new Vector2(0f, 1f);
			_root.anchoredPosition = new Vector2(40f, -4f);
			_root.sizeDelta = new Vector2(0f, 20f);
			HorizontalLayoutGroup obj = val.AddComponent<HorizontalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)obj).spacing = 4f;
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = false;
			((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = true;
			((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true;
			val.AddComponent<ContentSizeFitter>().horizontalFit = (FitMode)2;
		}

		public void Free()
		{
			if ((Object)(object)_root != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_root).gameObject);
			}
			_root = null;
			_renameInput = null;
			_renamingSlot = -1;
			_tabs.Clear();
			Dashboard = null;
		}

		public void UpdateLayout()
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_root == (Object)null) && !((Object)(object)Dashboard == (Object)null))
			{
				float num = 0f;
				RectTransform statboardTestRt = Dashboard.statboardTestRt;
				if ((Object)(object)statboardTestRt != (Object)null)
				{
					Rect rect = statboardTestRt.rect;
					num = Mathf.Max(0f, ((Rect)(ref rect)).width + statboardTestRt.anchoredPosition.x);
				}
				_root.anchoredPosition = new Vector2(40f + num, -4f);
			}
		}

		public void Refresh()
		{
			if ((Object)(object)_root == (Object)null || (Object)(object)Dashboard == (Object)null)
			{
				return;
			}
			for (int num = ((Transform)_root).childCount - 1; num >= 0; num--)
			{
				Object.Destroy((Object)(object)((Component)((Transform)_root).GetChild(num)).gameObject);
			}
			_tabs.Clear();
			CustomCharts charts = Dashboard.charts;
			if (charts == null)
			{
				return;
			}
			DashboardPage[] pages = charts.dashboardLayout.pages;
			int pageIndex = charts.currentView.pageIndex;
			float maxWidth = ComputePerTabMax();
			for (int i = 1; i < 10; i++)
			{
				if (pages[i] != null)
				{
					string label = (string.IsNullOrEmpty(pages[i].name) ? i.ToString() : pages[i].name);
					_tabs.Add(CreateTab(i, label, i == pageIndex, maxWidth));
				}
			}
			CreateAddButton();
		}

		private PageTab CreateTab(int slot, string label, bool current, float maxWidth)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("DO_Tab_" + slot, new Type[1] { typeof(RectTransform) });
			RectTransform val2 = (RectTransform)val.transform;
			((Transform)val2).SetParent((Transform)(object)_root, false);
			Image val3 = val.AddComponent<Image>();
			((Graphic)val3).raycastTarget = true;
			LayoutElement val4 = val.AddComponent<LayoutElement>();
			val4.minWidth = 64f;
			val4.preferredHeight = 20f;
			GameObject val5 = new GameObject("Text", new Type[1] { typeof(RectTransform) });
			RectTransform val6 = (RectTransform)val5.transform;
			((Transform)val6).SetParent((Transform)(object)val2, false);
			val6.anchorMin = Vector2.zero;
			val6.anchorMax = Vector2.one;
			val6.offsetMin = new Vector2(10f, 0f);
			val6.offsetMax = new Vector2(-10f, 0f);
			Text val7 = val5.AddComponent<Text>();
			val7.font = _font;
			val7.fontSize = 14;
			val7.alignment = (TextAnchor)4;
			((Graphic)val7).color = Color.white;
			((Graphic)val7).raycastTarget = false;
			val7.horizontalOverflow = (HorizontalWrapMode)1;
			val7.verticalOverflow = (VerticalWrapMode)1;
			PageTab pageTab = val.AddComponent<PageTab>();
			pageTab.Label = val7;
			pageTab.Background = val3;
			pageTab.Setup(this, slot, label, current);
			FitTabWidth(val7, val4, label, maxWidth);
			return pageTab;
		}

		private static void FitTabWidth(Text text, LayoutElement le, string label, float maxWidth)
		{
			float num = maxWidth - 20f;
			text.text = label;
			if (text.preferredWidth > num)
			{
				string text2 = label;
				while (text2.Length > 1)
				{
					text2 = text2.Substring(0, text2.Length - 1);
					text.text = text2 + "...";
					if (text.preferredWidth <= num)
					{
						break;
					}
				}
			}
			le.preferredWidth = Mathf.Clamp(text.preferredWidth + 20f, 64f, maxWidth);
		}

		private float ComputePerTabMax()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Dashboard == (Object)null || (Object)(object)Dashboard.rectTrans == (Object)null)
			{
				return 160f;
			}
			Rect rect = Dashboard.rectTrans.rect;
			float width = ((Rect)(ref rect)).width;
			if (width <= 1f)
			{
				return 160f;
			}
			float num = 0f;
			RectTransform statboardTestRt = Dashboard.statboardTestRt;
			if ((Object)(object)statboardTestRt != (Object)null)
			{
				rect = statboardTestRt.rect;
				num = Mathf.Max(0f, ((Rect)(ref rect)).width + statboardTestRt.anchoredPosition.x);
			}
			float num2 = (width - num) / 10f;
			return Mathf.Max(64f, num2);
		}

		public void SwitchTo(int slot)
		{
			if (!((Object)(object)Dashboard == (Object)null))
			{
				Dashboard.SetViewPage(slot);
				UpdateHighlights();
			}
		}

		private void UpdateHighlights()
		{
			if ((Object)(object)Dashboard == (Object)null || Dashboard.charts == null)
			{
				return;
			}
			int pageIndex = Dashboard.charts.currentView.pageIndex;
			foreach (PageTab tab in _tabs)
			{
				if ((Object)(object)tab != (Object)null)
				{
					tab.SetCurrent(tab.Slot == pageIndex);
				}
			}
		}

		public void AddNewPage()
		{
			if (!((Object)(object)Dashboard == (Object)null))
			{
				int num = PageOps.AddPage(Dashboard.charts);
				if (num < 0)
				{
					UIRealtimeTip.Popup(Loc.L("已达页面上限", "Page limit reached"), true, 0);
					return;
				}
				Dashboard.SetViewPage(num);
				Refresh();
			}
		}

		private void CreateAddButton()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Expected O, but got Unknown
			GameObject val = new GameObject("DO_AddBtn", new Type[1] { typeof(RectTransform) });
			RectTransform val2 = (RectTransform)val.transform;
			((Transform)val2).SetParent((Transform)(object)_root, false);
			Image val3 = val.AddComponent<Image>();
			Color focusColor = Dashboard.focusColor;
			((Graphic)val3).color = new Color(focusColor.r, focusColor.g, focusColor.b, 0.15f);
			LayoutElement obj = val.AddComponent<LayoutElement>();
			obj.minWidth = 20f;
			obj.preferredHeight = 20f;
			AddPlusBar(val2, 12f, 2f);
			AddPlusBar(val2, 2f, 12f);
			Button obj2 = val.AddComponent<Button>();
			((Selectable)obj2).targetGraphic = (Graphic)(object)val3;
			((UnityEvent)obj2.onClick).AddListener(new UnityAction(AddNewPage));
		}

		private static void AddPlusBar(RectTransform parent, float w, float h)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Bar", new Type[1] { typeof(RectTransform) });
			RectTransform val2 = (RectTransform)val.transform;
			((Transform)val2).SetParent((Transform)(object)parent, false);
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0.5f, 0.5f);
			val2.pivot = val3;
			Vector2 anchorMin = (val2.anchorMax = val3);
			val2.anchorMin = anchorMin;
			val2.anchoredPosition = Vector2.zero;
			val2.sizeDelta = new Vector2(w, h);
			Image obj = val.AddComponent<Image>();
			((Graphic)obj).color = Color.white;
			((Graphic)obj).raycastTarget = false;
		}

		private InputField EnsureRenameInput()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_renameInput != (Object)null)
			{
				return _renameInput;
			}
			GameObject val = new GameObject("DO_RenameInput", new Type[1] { typeof(RectTransform) });
			RectTransform val2 = (RectTransform)val.transform;
			((Transform)val2).SetParent(((Transform)_root).parent, false);
			val2.sizeDelta = new Vector2(120f, 20f);
			((Graphic)val.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0.85f);
			GameObject val3 = new GameObject("Text", new Type[1] { typeof(RectTransform) });
			RectTransform val4 = (RectTransform)val3.transform;
			((Transform)val4).SetParent((Transform)(object)val2, false);
			val4.anchorMin = Vector2.zero;
			val4.anchorMax = Vector2.one;
			val4.offsetMin = new Vector2(6f, 0f);
			val4.offsetMax = new Vector2(-6f, 0f);
			Text val5 = val3.AddComponent<Text>();
			val5.font = _font;
			val5.fontSize = 14;
			val5.alignment = (TextAnchor)3;
			((Graphic)val5).color = Color.white;
			val5.supportRichText = false;
			val5.verticalOverflow = (VerticalWrapMode)1;
			InputField val6 = val.AddComponent<InputField>();
			val6.textComponent = val5;
			val6.lineType = (LineType)0;
			val6.characterLimit = 64;
			((UnityEvent<string>)(object)val6.onEndEdit).AddListener((UnityAction<string>)CommitRename);
			val.SetActive(false);
			_renameInput = val6;
			return val6;
		}

		public void BeginRename(PageTab tab)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_root == (Object)null) && !((Object)(object)Dashboard == (Object)null) && Dashboard.charts != null)
			{
				InputField obj = EnsureRenameInput();
				_renamingSlot = tab.Slot;
				DashboardPage val = Dashboard.charts.dashboardLayout.pages[tab.Slot];
				((Component)obj).gameObject.SetActive(true);
				RectTransform val2 = (RectTransform)((Component)obj).transform;
				RectTransform val3 = (RectTransform)((Component)tab).transform;
				((Transform)val2).position = ((Transform)val3).position;
				Rect rect = val3.rect;
				val2.sizeDelta = new Vector2(Mathf.Max(120f, ((Rect)(ref rect)).width), 20f);
				obj.text = ((val != null) ? (val.name ?? string.Empty) : string.Empty);
				((Selectable)obj).Select();
				obj.ActivateInputField();
			}
		}

		private void CommitRename(string value)
		{
			if (_renamingSlot < 0 || (Object)(object)Dashboard == (Object)null || Dashboard.charts == null)
			{
				_renamingSlot = -1;
				return;
			}
			PageOps.RenamePage(Dashboard.charts.dashboardLayout.pages[_renamingSlot], value);
			_renamingSlot = -1;
			if ((Object)(object)_renameInput != (Object)null)
			{
				((Component)_renameInput).gameObject.SetActive(false);
			}
			Refresh();
		}

		public void OpenContextMenu(PageTab tab)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = (RectTransform)((Component)tab).transform;
			UIPopupMenu obj = Dashboard.OpenChartPopupMenu(new Vector2(0f, -20f), val);
			((Transform)obj.m_RectTrans).SetParent((Transform)(object)Dashboard.chartContentRt);
			UIPopupMenuButton obj2 = obj.AddMenuButton(Loc.L("重命名", "Rename"), -1, false);
			obj2.onMenuButtonClick = (Action<int>)Delegate.Combine(obj2.onMenuButtonClick, (Action<int>)delegate
			{
				Dashboard.CloseChartPopupMenu();
				BeginRename(tab);
			});
			obj2.SetState(true);
			UIPopupMenuButton obj3 = obj.AddMenuButton(Loc.L("删除", "Delete"), -1, false);
			obj3.onMenuButtonClick = (Action<int>)Delegate.Combine(obj3.onMenuButtonClick, (Action<int>)delegate
			{
				Dashboard.CloseChartPopupMenu();
				DeletePage(tab);
			});
			obj3.SetState(true);
			obj.SetState(true);
		}

		public void DeletePage(PageTab tab)
		{
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Expected O, but got Unknown
			CustomCharts charts = Dashboard.charts;
			if (!PageOps.CanDelete(charts))
			{
				UIRealtimeTip.Popup(Loc.L("至少保留一页", "Keep at least one page"), true, 0);
				return;
			}
			int slot = tab.Slot;
			DashboardPage val = charts.dashboardLayout.pages[slot];
			if (val != null && val.chartDatas != null && val.chartDatas.Count > 0)
			{
				UIMessageBox.Show(Loc.L("删除页面", "Delete page"), Loc.L("确认删除该页及其图表?", "Delete this page and its charts?"), Loc.L("取消", "Cancel"), Loc.L("确定", "OK"), 1, (Response)null, (Response)delegate
				{
					DoDeletePage(slot);
				});
			}
			else
			{
				DoDeletePage(slot);
			}
		}

		private void DoDeletePage(int slot)
		{
			if ((Object)(object)Dashboard == (Object)null || Dashboard.charts == null)
			{
				return;
			}
			CustomCharts charts = Dashboard.charts;
			int num = PageOps.PickPageAfterDelete(charts.dashboardLayout, slot);
			bool flag = charts.currentView.pageIndex == slot;
			if (!PageOps.RemovePage(charts, slot))
			{
				return;
			}
			if (_renamingSlot == slot)
			{
				_renamingSlot = -1;
				if ((Object)(object)_renameInput != (Object)null)
				{
					((Component)_renameInput).gameObject.SetActive(false);
				}
			}
			if (flag && num > 0)
			{
				Dashboard.SetViewPage(num);
			}
			Refresh();
		}
	}
	public static class UIChartPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIChart), "SetPopupMenuButtons")]
		private static void SetPopupMenuButtons_Postfix(UIChart __instance, UIPopupMenu popupMenu)
		{
			CustomCharts charts = __instance.charts;
			if (charts == null || __instance.chartData == null)
			{
				return;
			}
			DashboardLayout dashboardLayout = charts.dashboardLayout;
			int pageIndex = charts.currentView.pageIndex;
			List<int> list = new List<int>();
			for (int i = 1; i < 10; i++)
			{
				if (i != pageIndex && dashboardLayout.pages[i] != null)
				{
					list.Add(i);
				}
			}
			if (list.Count > 0)
			{
				UIPopupMenuButton val = popupMenu.AddMenuButton(Loc.L("移动到页面", "Move to page"), -1, true);
				UIPopupMenu val2 = __instance.CreateAndInitChildPopupMenu(val);
				foreach (int item in list)
				{
					DashboardPage val3 = dashboardLayout.pages[item];
					string text = (string.IsNullOrEmpty(val3.name) ? item.ToString() : val3.name);
					UIPopupMenuButton obj = val2.AddMenuButton(text, -1, false);
					obj.data = item;
					obj.onMenuButtonClick = (Action<int>)Delegate.Combine(obj.onMenuButtonClick, (Action<int>)delegate(int s)
					{
						MoveChartToPage(__instance, s);
					});
					obj.SetState(true);
				}
				val.m_ChildMenu = val2;
				val.SetState(true);
			}
			UIPopupMenuButton obj2 = popupMenu.AddMenuButton(Loc.L("重命名", "Rename"), -1, true);
			obj2.onMenuButtonClick = (Action<int>)Delegate.Combine(obj2.onMenuButtonClick, (Action<int>)delegate
			{
				UIDashboard uiDashboard = __instance.uiDashboard;
				if ((Object)(object)uiDashboard != (Object)null)
				{
					uiDashboard.CloseChartPopupMenu();
				}
				ChartRename.Begin(__instance);
			});
			obj2.SetState(true);
			UIPopupMenuButton obj3 = popupMenu.AddMenuButton(Loc.L("删除统计项", "Delete statistic"), -1, false);
			obj3.onMenuButtonClick = (Action<int>)Delegate.Combine(obj3.onMenuButtonClick, (Action<int>)delegate
			{
				ConfirmDelete(__instance);
			});
			obj3.SetState(true);
			popupMenu.SetState(true);
		}

		private static void MoveChartToPage(UIChart chart, int targetSlot)
		{
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			CustomCharts charts = chart.charts;
			if (charts == null)
			{
				return;
			}
			DashboardLayout dashboardLayout = charts.dashboardLayout;
			int pageIndex = charts.currentView.pageIndex;
			DashboardPage val = dashboardLayout.pages[pageIndex];
			DashboardPage val2 = dashboardLayout.pages[targetSlot];
			ChartData chartData = chart.chartData;
			if (val == null || val2 == null || chartData == null || !val.chartDatas.Remove(chartData))
			{
				return;
			}
			int num = int.MinValue;
			for (int i = 0; i < val2.chartDatas.Count; i++)
			{
				if (val2.chartDatas[i].depth > num)
				{
					num = val2.chartDatas[i].depth;
				}
			}
			chartData.depth = ((val2.chartDatas.Count != 0) ? (num + 1) : 0);
			UIDashboard uiDashboard = chart.uiDashboard;
			if ((Object)(object)uiDashboard != (Object)null && Overlaps(val2, chartData.pos, chartData.size))
			{
				Vector2Int boundMax = default(Vector2Int);
				((Vector2Int)(ref boundMax))..ctor(uiDashboard.maxGridCountX * 8, uiDashboard.maxGridCountY * 8);
				chartData.pos = FindFreePosition(val2, chartData.size, boundMax, chartData.pos);
			}
			val2.chartDatas.Add(chartData);
			if ((Object)(object)uiDashboard != (Object)null)
			{
				uiDashboard.CloseChartPopupMenu();
				uiDashboard.DetermineCharts();
			}
		}

		private static bool Overlaps(DashboardPage page, Vector2Int pos, Vector2Int size)
		{
			int num = ((Vector2Int)(ref pos)).x + ((Vector2Int)(ref size)).x;
			int num2 = ((Vector2Int)(ref pos)).y + ((Vector2Int)(ref size)).y;
			List<ChartData> chartDatas = page.chartDatas;
			for (int i = 0; i < chartDatas.Count; i++)
			{
				ChartData val = chartDatas[i];
				int num3 = ((Vector2Int)(ref val.pos)).x + ((Vector2Int)(ref val.size)).x;
				int num4 = ((Vector2Int)(ref val.pos)).y + ((Vector2Int)(ref val.size)).y;
				if (num > ((Vector2Int)(ref val.pos)).x && num3 > ((Vector2Int)(ref pos)).x && num2 > ((Vector2Int)(ref val.pos)).y && num4 > ((Vector2Int)(ref pos)).y)
				{
					return true;
				}
			}
			return false;
		}

		private static Vector2Int FindFreePosition(DashboardPage page, Vector2Int size, Vector2Int boundMax, Vector2Int fallback)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			Vector2Int val = default(Vector2Int);
			for (int i = 0; i + ((Vector2Int)(ref size)).y <= ((Vector2Int)(ref boundMax)).y; i++)
			{
				for (int j = 0; j + ((Vector2Int)(ref size)).x <= ((Vector2Int)(ref boundMax)).x; j++)
				{
					((Vector2Int)(ref val))..ctor(j, i);
					if (!Overlaps(page, val, size))
					{
						return val;
					}
				}
			}
			return fallback;
		}

		private static void ConfirmDelete(UIChart chart)
		{
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Expected O, but got Unknown
			if (!((Object)(object)chart == (Object)null) && chart.chartData != null && chart.charts != null)
			{
				UIDashboard dash = chart.uiDashboard;
				CustomCharts charts = chart.charts;
				int id = chart.chartData.statPlanId;
				if ((Object)(object)dash != (Object)null)
				{
					dash.CloseChartPopupMenu();
				}
				ChartRename.CancelIfTargeting(chart);
				UIMessageBox.Show(Localization.Translate("确认删除统计项标题"), Localization.Translate("确认删除统计项提示"), Localization.Translate("取消"), Localization.Translate("确定"), 1, (Response)null, (Response)delegate
				{
					DoDelete(dash, charts, id);
				});
			}
		}

		private static void DoDelete(UIDashboard dash, CustomCharts charts, int id)
		{
			if (charts == null)
			{
				return;
			}
			charts.RemoveStatPlan(id);
			if ((Object)(object)dash != (Object)null)
			{
				dash.DetermineCharts();
				if ((Object)(object)dash.statboard != (Object)null)
				{
					dash.statboard.DetermineEntryVisible();
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIDashboard), "TakeChartFromPool")]
		private static void TakeChartFromPool_Postfix(UIChart __result)
		{
			if (!((Object)(object)__result == (Object)null) && !((Object)(object)__result.titleText == (Object)null))
			{
				GameObject gameObject = ((Component)__result.titleText).gameObject;
				ChartTitleRenameTrigger chartTitleRenameTrigger = gameObject.GetComponent<ChartTitleRenameTrigger>();
				if ((Object)(object)chartTitleRenameTrigger == (Object)null)
				{
					((Graphic)__result.titleText).raycastTarget = true;
					chartTitleRenameTrigger = gameObject.AddComponent<ChartTitleRenameTrigger>();
				}
				chartTitleRenameTrigger.Owner = __result;
			}
		}
	}
	public static class UIDashboardPatch
	{
		public static PageTabBar Bar;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIDashboard), "_OnCreate")]
		private static void OnCreate_Postfix(UIDashboard __instance)
		{
			Bar = new PageTabBar();
			Bar.Build(__instance);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIDashboard), "_OnOpen")]
		private static void OnOpen_Postfix(UIDashboard __instance)
		{
			if ((Object)(object)__instance != (Object)null && !PageOps.IsValidViewPage(__instance.charts))
			{
				int num = PageOps.FirstActiveSlot(__instance.charts?.dashboardLayout);
				if (num > 0)
				{
					__instance.SetViewPage(num);
				}
			}
			if (Bar != null)
			{
				Bar.Refresh();
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIDashboard), "_OnUpdate")]
		private static void OnUpdate_Postfix()
		{
			if (Bar != null)
			{
				Bar.UpdateLayout();
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIDashboard), "_OnDestroy")]
		private static void OnDestroy_Postfix()
		{
			if (Bar != null)
			{
				Bar.Free();
				Bar = null;
			}
			ChartRename.Free();
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "org.fyyy.dashboardoverhaul";

		public const string PLUGIN_NAME = "DashboardOverhaul";

		public const string PLUGIN_VERSION = "1.1.0";
	}
}