Decompiled source of DashboardOverhaul v1.3.0

DashboardOverhaul.dll

Decompiled 6 days 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.3.0.0")]
[assembly: AssemblyInformationalVersion("1.3.0+20b23a3e82c6ae281679e494b735ddfc5060d761")]
[assembly: AssemblyProduct("DashboardOverhaul")]
[assembly: AssemblyTitle("DashboardOverhaul")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.3.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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: 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_00c2: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: 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)
			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)
			{
				UIDashboardPatch.Bar?.FinishRename();
				Cancel();
				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();
				((Component)obj).transform.SetAsLastSibling();
				UIRealtimeTip.Popup(string.Format(Loc.L("重命名统计项,将影响 {0} 个图表", "Renaming this statistic affects {0} charts"), PageOps.ChartCount(chart.charts, val.id)), true, 0);
			}
		}

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

		public static void Free()
		{
			Cancel();
			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;
			bool num = (Object)(object)_input != (Object)null && _input.wasCanceled;
			Hide();
			if (!num)
			{
				StatPlan val = ResolveStatPlan(target);
				if (val != null)
				{
					string text = (value ?? string.Empty).Trim();
					val.Rename(ref text);
				}
			}
		}

		public static void Finish()
		{
			if ((Object)(object)_target != (Object)null)
			{
				_input.DeactivateInputField(true);
			}
		}

		public static void Cancel()
		{
			Hide();
		}

		private static void Hide()
		{
			_target = null;
			DashboardUi.HideInput(_input);
		}
	}
	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;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(DashboardLayout), "AddPage")]
		private static void AddPage_Postfix(DashboardLayout __instance, int index)
		{
			if (__instance.pages != null && index >= 0 && index < 10 && __instance.pages[index] != null)
			{
				__instance.pages[index].name = "";
			}
		}
	}
	[BepInPlugin("org.fyyy.dashboardoverhaul", "DashboardOverhaul", "1.3.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();
			}
		}
	}
	internal static class DashboardUi
	{
		public static Text Text(Transform parent, Font font, string value, TextAnchor alignment = (TextAnchor)4)
		{
			//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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Text", new Type[1] { typeof(RectTransform) });
			RectTransform val2 = (RectTransform)val.transform;
			((Transform)val2).SetParent(parent, false);
			val2.anchorMin = Vector2.zero;
			val2.anchorMax = Vector2.one;
			val2.offsetMin = new Vector2(8f, 0f);
			val2.offsetMax = new Vector2(-8f, 0f);
			Text obj = val.AddComponent<Text>();
			obj.font = font;
			obj.fontSize = 14;
			((Graphic)obj).color = Color.white;
			obj.alignment = alignment;
			obj.supportRichText = false;
			((Graphic)obj).raycastTarget = false;
			obj.text = value;
			return obj;
		}

		public static void StyleButton(Button button, Color color)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			ColorBlock colors = ((Selectable)button).colors;
			((ColorBlock)(ref colors)).normalColor = color;
			((ColorBlock)(ref colors)).highlightedColor = Color.Lerp(color, Color.white, 0.3f);
			((ColorBlock)(ref colors)).selectedColor = ((ColorBlock)(ref colors)).highlightedColor;
			((ColorBlock)(ref colors)).pressedColor = Color.Lerp(color, Color.white, 0.5f);
			((ColorBlock)(ref colors)).disabledColor = new Color(color.r, color.g, color.b, 0.08f);
			((ColorBlock)(ref colors)).fadeDuration = 0.08f;
			((Selectable)button).colors = colors;
		}

		public static void Tip(GameObject go, string title, string description)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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)
			UIDashboardTip obj = go.GetComponent<UIDashboardTip>() ?? go.AddComponent<UIDashboardTip>();
			obj.settings = new Settings
			{
				tipType = (TipType)2,
				tipTitle = title,
				tipText = description,
				delay = 0.4f,
				corner = 3,
				width = 300
			};
			obj.RefreshSimpleGeneralTipText();
		}

		public static void HideInput(InputField input)
		{
			if (!((Object)(object)input == (Object)null))
			{
				if ((Object)(object)EventSystem.current != (Object)null && (Object)(object)EventSystem.current.currentSelectedGameObject == (Object)(object)((Component)input).gameObject)
				{
					EventSystem.current.SetSelectedGameObject((GameObject)null);
				}
				((Component)input).gameObject.SetActive(false);
			}
		}
	}
	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 string PageName(DashboardPage page, int slot)
		{
			if (!string.IsNullOrEmpty(page.name))
			{
				return page.name;
			}
			return slot.ToString();
		}

		public static void EnsureViewPage(CustomCharts charts)
		{
			if (!IsValidViewPage(charts))
			{
				int num = FirstActiveSlot(charts.dashboardLayout);
				if (num < 0)
				{
					num = 1;
					charts.dashboardLayout.AddPage(num);
				}
				charts.currentView.pageIndex = num;
			}
		}

		public static int AddPage(CustomCharts charts)
		{
			DashboardLayout dashboardLayout = charts.dashboardLayout;
			int num = FirstFreeSlot(dashboardLayout);
			if (num < 0)
			{
				return -1;
			}
			List<DashboardPage> list = new List<DashboardPage>();
			for (int i = 1; i < 10; i++)
			{
				if (dashboardLayout.pages[i] != null)
				{
					list.Add(dashboardLayout.pages[i]);
				}
			}
			dashboardLayout.AddPage(num);
			list.Add(dashboardLayout.pages[num]);
			ReorderPages(charts, list);
			return list.Count;
		}

		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 (!CanDelete(charts))
			{
				return false;
			}
			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 bool ReorderPages(CustomCharts charts, IReadOnlyList<DashboardPage> newOrder)
		{
			DashboardPage[] array = charts?.dashboardLayout?.pages;
			if (array == null || newOrder == null)
			{
				return false;
			}
			int num = ActivePageCount(charts);
			if (num == 0)
			{
				return false;
			}
			if (newOrder.Count != num)
			{
				return false;
			}
			HashSet<DashboardPage> hashSet = new HashSet<DashboardPage>();
			foreach (DashboardPage item in newOrder)
			{
				if (item == null)
				{
					return false;
				}
				hashSet.Add(item);
			}
			if (hashSet.Count != num)
			{
				return false;
			}
			for (int i = 1; i < 10; i++)
			{
				if (array[i] != null && !hashSet.Contains(array[i]))
				{
					return false;
				}
			}
			int pageIndex = charts.currentView.pageIndex;
			DashboardPage val = ((pageIndex >= 1 && pageIndex < 10) ? array[pageIndex] : null);
			for (int j = 0; j < newOrder.Count; j++)
			{
				array[j + 1] = newOrder[j];
			}
			for (int k = newOrder.Count + 1; k < 10; k++)
			{
				array[k] = null;
			}
			int pageIndex2 = 1;
			if (val != null)
			{
				for (int l = 1; l < 10; l++)
				{
					if (array[l] == val)
					{
						pageIndex2 = l;
						break;
					}
				}
			}
			charts.currentView.pageIndex = pageIndex2;
			return true;
		}

		public static void RenamePage(DashboardPage page, string newName)
		{
			if (page != null)
			{
				page.name = (newName ?? string.Empty).Trim();
			}
		}

		public static int ChartCount(CustomCharts charts, int statPlanId)
		{
			int num = 0;
			DashboardPage[] pages = charts.dashboardLayout.pages;
			foreach (DashboardPage val in pages)
			{
				if (val == null)
				{
					continue;
				}
				foreach (ChartData chartData in val.chartDatas)
				{
					if (chartData.statPlanId == statPlanId)
					{
						num++;
					}
				}
			}
			if (charts.watchLayout?.chartDatas != null)
			{
				foreach (ChartData chartData2 in charts.watchLayout.chartDatas)
				{
					if (chartData2.statPlanId == statPlanId)
					{
						num++;
					}
				}
			}
			return num;
		}

		public static bool TryMoveChart(DashboardPage source, DashboardPage target, ChartData chart, Vector2Int bounds)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			if (source == target || !source.chartDatas.Contains(chart))
			{
				return false;
			}
			Vector2Int pos = chart.pos;
			if (!Fits(target, pos, chart.size, bounds))
			{
				bool flag = false;
				for (int i = 0; i + ((Vector2Int)(ref chart.size)).y <= ((Vector2Int)(ref bounds)).y; i++)
				{
					if (flag)
					{
						break;
					}
					for (int j = 0; j + ((Vector2Int)(ref chart.size)).x <= ((Vector2Int)(ref bounds)).x; j++)
					{
						if (Fits(target, new Vector2Int(j, i), chart.size, bounds))
						{
							((Vector2Int)(ref pos))..ctor(j, i);
							flag = true;
							break;
						}
					}
				}
				if (!flag)
				{
					return false;
				}
			}
			int num = -1;
			foreach (ChartData chartData in target.chartDatas)
			{
				num = Math.Max(num, chartData.depth);
			}
			source.chartDatas.Remove(chart);
			chart.pos = pos;
			chart.depth = num + 1;
			target.chartDatas.Add(chart);
			return true;
		}

		private static bool Fits(DashboardPage page, Vector2Int pos, Vector2Int size, Vector2Int bounds)
		{
			if (((Vector2Int)(ref pos)).x < 0 || ((Vector2Int)(ref pos)).y < 0 || ((Vector2Int)(ref pos)).x + ((Vector2Int)(ref size)).x > ((Vector2Int)(ref bounds)).x || ((Vector2Int)(ref pos)).y + ((Vector2Int)(ref size)).y > ((Vector2Int)(ref bounds)).y)
			{
				return false;
			}
			foreach (ChartData chartData in page.chartDatas)
			{
				if (((Vector2Int)(ref pos)).x + ((Vector2Int)(ref size)).x > ((Vector2Int)(ref chartData.pos)).x && ((Vector2Int)(ref chartData.pos)).x + ((Vector2Int)(ref chartData.size)).x > ((Vector2Int)(ref pos)).x && ((Vector2Int)(ref pos)).y + ((Vector2Int)(ref size)).y > ((Vector2Int)(ref chartData.pos)).y && ((Vector2Int)(ref chartData.pos)).y + ((Vector2Int)(ref chartData.size)).y > ((Vector2Int)(ref pos)).y)
				{
					return false;
				}
			}
			return true;
		}

		public static bool CopyIntoEmptyPage(DashboardPage source, DashboardPage target)
		{
			//IL_003f: 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_0046: 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_0050: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: 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_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Expected O, but got Unknown
			if (source == target || target.chartDatas.Count != 0 || source.chartDatas.Count == 0)
			{
				return false;
			}
			foreach (ChartData chartData in source.chartDatas)
			{
				target.chartDatas.Add(new ChartData
				{
					pos = chartData.pos,
					size = chartData.size,
					depth = chartData.depth,
					statPlanId = chartData.statPlanId,
					presetIndex = chartData.presetIndex,
					genericStyleIndex = chartData.genericStyleIndex,
					backgroundStyleIndex = chartData.backgroundStyleIndex,
					borderStyleIndex = chartData.borderStyleIndex,
					displayTypeParams = (int[])chartData.displayTypeParams.Clone()
				});
			}
			return true;
		}
	}
	public class PageTab : Button, IBeginDragHandler, IEventSystemHandler, IDragHandler, IEndDragHandler
	{
		public int Slot;

		private PageTabBar _bar;

		public Text Label;

		public Image Background;

		public string FullName;

		public void Setup(PageTabBar bar, int slot, string label, bool current)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			_bar = bar;
			Slot = slot;
			FullName = label;
			((Selectable)this).targetGraphic = (Graphic)(object)Background;
			((UnityEvent)((Button)this).onClick).AddListener((UnityAction)delegate
			{
				_bar.SwitchTo(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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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)
			if (!((Object)(object)Background == (Object)null))
			{
				Color val = ((_bar != null) ? _bar.Dashboard.focusColor : Color.gray);
				DashboardUi.StyleButton((Button)(object)this, (Color)(current ? val : new Color(val.r, val.g, val.b, 0.25f)));
			}
		}

		public override 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
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if (_bar != null)
			{
				if ((int)eventData.button == 1)
				{
					_bar.OpenContextMenu(this);
				}
				else if ((int)eventData.button == 0 && eventData.clickCount >= 2)
				{
					_bar.BeginRename(this);
				}
				else
				{
					((Button)this).OnPointerClick(eventData);
				}
			}
		}

		public void OnBeginDrag(PointerEventData eventData)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			if ((int)eventData.button == 0 && _bar != null)
			{
				_bar.BeginDrag(this, eventData);
			}
		}

		public void OnDrag(PointerEventData eventData)
		{
			if (_bar != null)
			{
				_bar.Drag(this, eventData);
			}
		}

		public void OnEndDrag(PointerEventData eventData)
		{
			if (_bar != null)
			{
				_bar.EndDrag(this, eventData);
			}
		}
	}
	public class PageTabBar
	{
		private RectTransform _content;

		private RectTransform _header;

		private RectTransform _root;

		private Vector2 _statboardTopOffset;

		private Font _font;

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

		private InputField _renameInput;

		private DashboardPage _renamingPage;

		private RectTransform _addButton;

		private PageTab _draggingTab;

		private RectTransform _placeholder;

		private float _dragFixedY;

		private float _dragZ;

		private int _dragInsertIndex = -1;

		private HorizontalLayoutGroup _layout;

		private readonly Vector3[] _dragCorners = (Vector3[])(object)new Vector3[4];

		private readonly List<Transform> _reflowOrdered = new List<Transform>();

		private float _tabWidth = -1f;

		private RectTransform _emptyPanel;

		private Text _emptyText;

		private Button _emptyAdd;

		private Button _emptyCopy;

		private int _emptyState = -1;

		private RectTransform _notice;

		private Text _noticeText;

		private DashboardPage _movedPage;

		private ChartData _movedChart;

		private float _noticeUntil;

		private const int kTabHeight = 28;

		private const int kTabMinWidth = 64;

		private const float kTabMaxWidth = 160f;

		private const float kDragChipMaxWidth = 120f;

		private const float kTabHPadding = 20f;

		private const float kHeaderHeight = 44f;

		private const float kChartLeftMargin = 32f;

		private const float kBaseLeftMargin = 4f;

		private const float kTopOffset = -4f;

		public UIDashboard Dashboard { get; private set; }

		public void Build(UIDashboard dashboard)
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Expected O, but got Unknown
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: 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_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Expected O, but got Unknown
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Expected O, but got Unknown
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0312: Expected O, but got Unknown
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Expected O, but got Unknown
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_0393: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ad: 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.");
			}
			if ((Object)(object)dashboard.emptyTip != (Object)null)
			{
				((Behaviour)dashboard.emptyTip).enabled = false;
			}
			_content = (RectTransform)new GameObject("DO_Content", new Type[1] { typeof(RectTransform) }).transform;
			((Transform)_content).SetParent((Transform)(object)dashboard.rectTrans, false);
			((Transform)_content).SetAsFirstSibling();
			_content.anchorMin = Vector2.zero;
			_content.anchorMax = Vector2.one;
			_content.offsetMin = new Vector2(32f, 0f);
			_content.offsetMax = new Vector2(0f, -44f);
			Color color = default(Color);
			((Color)(ref color))..ctor(0.04f, 0.12f, 0.19f, 1f);
			RectTransform val = (RectTransform)new GameObject("DO_SidebarGutter", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			}).transform;
			((Transform)val).SetParent((Transform)(object)_content, false);
			val.anchorMin = Vector2.zero;
			val.anchorMax = new Vector2(0f, 1f);
			val.pivot = new Vector2(1f, 0.5f);
			val.anchoredPosition = Vector2.zero;
			val.sizeDelta = new Vector2(32f, 0f);
			((Graphic)((Component)val).GetComponent<Image>()).color = color;
			Reparent(((Graphic)dashboard.gridRawImage).rectTransform, _content);
			Reparent(dashboard.chartContentRt, _content);
			RectTransform val2 = (RectTransform)((Component)dashboard.statboard).transform;
			_statboardTopOffset = val2.offsetMax;
			val2.offsetMax = _statboardTopOffset - new Vector2(0f, 44f);
			_header = (RectTransform)new GameObject("DO_Header", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			}).transform;
			((Transform)_header).SetParent((Transform)(object)dashboard.rectTrans, false);
			_header.anchorMin = new Vector2(0f, 1f);
			_header.anchorMax = Vector2.one;
			_header.pivot = new Vector2(0f, 1f);
			_header.sizeDelta = new Vector2(0f, 44f);
			_header.anchoredPosition = Vector2.zero;
			((Graphic)((Component)_header).GetComponent<Image>()).color = color;
			((Transform)dashboard.tipsParent).SetAsLastSibling();
			GameObject val3 = new GameObject("DO_PageTabBar", new Type[1] { typeof(RectTransform) });
			_root = (RectTransform)val3.transform;
			((Transform)_root).SetParent((Transform)(object)_header, false);
			_root.anchorMin = new Vector2(0f, 1f);
			_root.anchorMax = new Vector2(0f, 1f);
			_root.pivot = new Vector2(0f, 1f);
			_root.anchoredPosition = new Vector2(4f, -4f);
			_root.sizeDelta = new Vector2(0f, 28f);
			HorizontalLayoutGroup val4 = (_layout = val3.AddComponent<HorizontalLayoutGroup>());
			((HorizontalOrVerticalLayoutGroup)val4).spacing = 4f;
			((HorizontalOrVerticalLayoutGroup)val4).childForceExpandWidth = false;
			((HorizontalOrVerticalLayoutGroup)val4).childForceExpandHeight = true;
			((HorizontalOrVerticalLayoutGroup)val4).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)val4).childControlHeight = true;
			val3.AddComponent<ContentSizeFitter>().horizontalFit = (FitMode)2;
			BuildEmptyPanel();
		}

		private static void Reparent(RectTransform child, RectTransform parent)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			Vector2 anchoredPosition = child.anchoredPosition;
			((Transform)child).SetParent((Transform)(object)parent, false);
			child.anchoredPosition = anchoredPosition;
		}

		public void Free()
		{
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			CancelRename();
			if ((Object)(object)_renameInput != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_renameInput).gameObject);
			}
			if ((Object)(object)_emptyPanel != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_emptyPanel).gameObject);
			}
			if ((Object)(object)_notice != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_notice).gameObject);
			}
			if ((Object)(object)_header != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_header).gameObject);
			}
			if ((Object)(object)_content != (Object)null)
			{
				Reparent(((Graphic)Dashboard.gridRawImage).rectTransform, Dashboard.rectTrans);
				Reparent(Dashboard.chartContentRt, Dashboard.rectTrans);
				Object.Destroy((Object)(object)((Component)_content).gameObject);
			}
			((RectTransform)((Component)Dashboard.statboard).transform).offsetMax = _statboardTopOffset;
			_content = null;
			_header = null;
			_root = null;
			_renameInput = null;
			_addButton = null;
			_placeholder = null;
			_draggingTab = null;
			_layout = null;
			_tabs.Clear();
			Dashboard = null;
		}

		public void UpdateLayout()
		{
			if ((Object)(object)_root == (Object)null || (Object)(object)Dashboard == (Object)null)
			{
				return;
			}
			float num = ComputePerTabMax();
			if ((Object)(object)_draggingTab == (Object)null && !Mathf.Approximately(num, _tabWidth))
			{
				ResizeTabs(num);
			}
			if (_renamingPage != null)
			{
				PositionRenameInput();
			}
			UpdateEmptyPanel();
			if ((Object)(object)_notice != (Object)null && ((Component)_notice).gameObject.activeSelf)
			{
				int num2 = Array.IndexOf(Dashboard.charts.dashboardLayout.pages, _movedPage);
				if (Time.unscaledTime >= _noticeUntil || num2 < 1 || !_movedPage.chartDatas.Contains(_movedChart))
				{
					((Component)_notice).gameObject.SetActive(false);
				}
				else
				{
					_noticeText.text = Loc.L("已移动到:", "Moved to: ") + PageOps.PageName(_movedPage, num2);
				}
			}
		}

		public void Refresh()
		{
			if ((Object)(object)_root == (Object)null || (Object)(object)Dashboard == (Object)null)
			{
				return;
			}
			CleanupDrag();
			for (int num = ((Transform)_root).childCount - 1; num >= 0; num--)
			{
				Transform child = ((Transform)_root).GetChild(num);
				((Component)child).gameObject.SetActive(false);
				child.SetParent((Transform)null, false);
				Object.Destroy((Object)(object)((Component)child).gameObject);
			}
			_tabs.Clear();
			CustomCharts charts = Dashboard.charts;
			if (charts == null)
			{
				return;
			}
			DashboardPage[] pages = charts.dashboardLayout.pages;
			int pageIndex = charts.currentView.pageIndex;
			float num2 = ComputePerTabMax();
			for (int i = 1; i < 10; i++)
			{
				if (pages[i] != null)
				{
					string label = PageOps.PageName(pages[i], i);
					_tabs.Add(CreateTab(i, label, i == pageIndex, num2));
				}
			}
			CreateAddButton();
			ResizeTabs(num2);
			UpdateLayout();
		}

		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 = 28f;
			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.supportRichText = 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);
			DashboardUi.Tip(val, label, Loc.L("单击切换 · 双击重命名 · 右键管理 · 拖动排序", "Click to switch · Double-click to rename · Right-click to manage · Drag to reorder"));
			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.minWidth = Mathf.Min(64f, maxWidth);
			le.preferredWidth = Mathf.Clamp(text.preferredWidth + 20f, le.minWidth, maxWidth);
		}

		private float ComputePerTabMax()
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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;
			}
			int count = ((Dashboard.charts == null) ? 1 : Mathf.Max(1, PageOps.ActivePageCount(Dashboard.charts)));
			Rect rect = Dashboard.rectTrans.rect;
			return ComputePerTabMax(((Rect)(ref rect)).width, count);
		}

		private static float ComputePerTabMax(float dashW, int count)
		{
			if (dashW <= 1f)
			{
				return 160f;
			}
			return Mathf.Clamp((dashW - 4f - 16f - 28f - (float)count * 4f) / (float)count, 32f, 240f);
		}

		private void ResizeTabs(float width)
		{
			_tabWidth = width;
			foreach (PageTab tab in _tabs)
			{
				tab.FullName = PageOps.PageName(Dashboard.charts.dashboardLayout.pages[tab.Slot], tab.Slot);
				FitTabWidth(tab.Label, ((Component)tab).GetComponent<LayoutElement>(), tab.FullName, width);
				DashboardUi.Tip(((Component)tab).gameObject, tab.FullName, Loc.L("单击切换 · 双击重命名 · 右键管理 · 拖动排序", "Click to switch · Double-click to rename · Right-click to manage · Drag to reorder"));
			}
		}

		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))
			{
				FinishRename();
				Dashboard.CloseChartPopupMenu();
				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_003d: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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_00bd: 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_0128: Expected O, but got Unknown
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: 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);
			_addButton = val2;
			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 = 28f;
			obj.preferredHeight = 28f;
			AddPlusBar(val2, 12f, 2f);
			AddPlusBar(val2, 2f, 12f);
			Button val4 = val.AddComponent<Button>();
			((Selectable)val4).targetGraphic = (Graphic)(object)val3;
			DashboardUi.StyleButton(val4, ((Graphic)val3).color);
			((Graphic)val3).color = Color.white;
			((Selectable)val4).interactable = PageOps.ActivePageCount(Dashboard.charts) < 9;
			DashboardUi.Tip(val, Loc.L("新建页面", "New page"), ((Selectable)val4).interactable ? Loc.L("在末尾添加一个空白页面", "Append an empty page") : Loc.L("已达 9 页上限", "Maximum of 9 pages reached"));
			((UnityEvent)val4.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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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_0083: 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)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: 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_00be: 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_00c9: 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_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: 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);
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0f, 1f);
			val2.pivot = val3;
			Vector2 anchorMin = (val2.anchorMax = val3);
			val2.anchorMin = anchorMin;
			((Graphic)val.AddComponent<Image>()).color = Color.black;
			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(6f, 0f);
			val6.offsetMax = new Vector2(-6f, 0f);
			Text val7 = val5.AddComponent<Text>();
			val7.font = _font;
			val7.fontSize = 14;
			val7.alignment = (TextAnchor)3;
			((Graphic)val7).color = Color.white;
			val7.supportRichText = false;
			val7.verticalOverflow = (VerticalWrapMode)1;
			InputField val8 = val.AddComponent<InputField>();
			val8.textComponent = val7;
			val8.lineType = (LineType)0;
			val8.characterLimit = 64;
			((UnityEvent<string>)(object)val8.onEndEdit).AddListener((UnityAction<string>)CommitRename);
			val.SetActive(false);
			_renameInput = val8;
			return val8;
		}

		public void BeginRename(PageTab tab)
		{
			if (!((Object)(object)_root == (Object)null) && !((Object)(object)Dashboard == (Object)null) && Dashboard.charts != null)
			{
				FinishRename();
				ChartRename.Cancel();
				InputField obj = EnsureRenameInput();
				DashboardPage val = (_renamingPage = Dashboard.charts.dashboardLayout.pages[tab.Slot]);
				((Component)obj).gameObject.SetActive(true);
				PositionRenameInput();
				obj.text = ((val != null) ? (val.name ?? string.Empty) : string.Empty);
				((Selectable)obj).Select();
				obj.ActivateInputField();
				((Component)obj).transform.SetAsLastSibling();
			}
		}

		private static Rect RenameInputRect(Rect tab, Rect header)
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Min(Mathf.Max(120f, ((Rect)(ref tab)).width), ((Rect)(ref header)).width - 8f);
			float num2 = Mathf.Clamp(((Rect)(ref tab)).xMin, ((Rect)(ref header)).xMin + 4f, ((Rect)(ref header)).xMax - num - 4f);
			float num3 = Mathf.Clamp(((Rect)(ref tab)).yMax - 28f, ((Rect)(ref header)).yMin + 4f, ((Rect)(ref header)).yMax - 28f - 4f);
			return new Rect(num2, num3, num, 28f);
		}

		private void PositionRenameInput()
		{
			//IL_004b: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: 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_00b8: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: 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_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			foreach (PageTab tab in _tabs)
			{
				if (Dashboard.charts.dashboardLayout.pages[tab.Slot] == _renamingPage)
				{
					RectTransform val = (RectTransform)((Component)_renameInput).transform;
					((RectTransform)((Component)tab).transform).GetWorldCorners(_dragCorners);
					Vector2 val2 = Vector2.op_Implicit(((Transform)_header).InverseTransformPoint(_dragCorners[0]));
					Vector2 val3 = Vector2.op_Implicit(((Transform)_header).InverseTransformPoint(_dragCorners[2]));
					Rect val4 = RenameInputRect(Rect.MinMaxRect(val2.x, val2.y, val3.x, val3.y), _header.rect);
					val.sizeDelta = ((Rect)(ref val4)).size;
					float xMin = ((Rect)(ref val4)).xMin;
					Rect rect = _header.rect;
					float num = xMin - ((Rect)(ref rect)).xMin;
					float yMax = ((Rect)(ref val4)).yMax;
					rect = _header.rect;
					val.anchoredPosition = new Vector2(num, yMax - ((Rect)(ref rect)).yMax);
					break;
				}
			}
		}

		private void CommitRename(string value)
		{
			DashboardPage renamingPage = _renamingPage;
			bool flag = (Object)(object)_renameInput != (Object)null && _renameInput.wasCanceled;
			CancelRename();
			if (!(renamingPage == null || flag) && Dashboard?.charts != null && Array.IndexOf(Dashboard.charts.dashboardLayout.pages, renamingPage) >= 1)
			{
				PageOps.RenamePage(renamingPage, value);
				ResizeTabs(ComputePerTabMax());
			}
		}

		public void FinishRename()
		{
			if (_renamingPage != null)
			{
				_renameInput.DeactivateInputField(true);
			}
		}

		public void CancelRename()
		{
			_renamingPage = null;
			DashboardUi.HideInput(_renameInput);
		}

		public void Close()
		{
			CancelRename();
			ChartRename.Cancel();
			if ((Object)(object)_notice != (Object)null)
			{
				((Component)_notice).gameObject.SetActive(false);
			}
			_movedPage = null;
			_movedChart = null;
		}

		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, -28f), val);
			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);
			bool flag = PageOps.CanDelete(Dashboard.charts);
			UIPopupMenuButton obj3 = obj.AddMenuButton(flag ? Loc.L("删除页面", "Delete page") : Loc.L("删除页面(至少保留一页)", "Delete page (keep at least one)"), -1, false);
			obj3.onMenuButtonClick = (Action<int>)Delegate.Combine(obj3.onMenuButtonClick, (Action<int>)delegate
			{
				Dashboard.CloseChartPopupMenu();
				DeletePage(tab);
			});
			obj3.SetState(true);
			((Selectable)obj3.m_Button).interactable = flag;
			obj.SetState(true);
			Dashboard.input_lock = true;
		}

		public void DeletePage(PageTab tab)
		{
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: 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 page = charts.dashboardLayout.pages[slot];
			if (page != null && page.chartDatas != null && page.chartDatas.Count > 0)
			{
				UIMessageBox.Show(Loc.L("删除页面", "Delete page"), string.Format(Loc.L("删除页面“{0}”及其中 {1} 个图表?统计项仍保留在侧栏。", "Delete page “{0}” and its {1} charts? Statistics remain in the sidebar."), PageOps.PageName(page, slot), page.chartDatas.Count), Loc.L("取消", "Cancel"), Loc.L("确定", "OK"), 1, (Response)null, (Response)delegate
				{
					DoDeletePage(charts, page);
				});
			}
			else
			{
				DoDeletePage(charts, page);
			}
		}

		private void DoDeletePage(CustomCharts charts, DashboardPage page)
		{
			if ((Object)(object)Dashboard == (Object)null || Dashboard.charts != charts)
			{
				return;
			}
			int num = Array.IndexOf(charts.dashboardLayout.pages, page);
			if (page != null && num >= 1 && PageOps.CanDelete(charts))
			{
				CancelRename();
				ChartRename.Cancel();
				int num2 = PageOps.PickPageAfterDelete(charts.dashboardLayout, num);
				if (charts.currentView.pageIndex == num && num2 > 0)
				{
					Dashboard.SetViewPage(num2);
				}
				if (PageOps.RemovePage(charts, num))
				{
					Refresh();
				}
			}
		}

		public void BeginDrag(PageTab tab, PointerEventData eventData)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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_0098: 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)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_root == (Object)null) && !((Object)(object)Dashboard == (Object)null) && !((Object)(object)tab == (Object)null) && !((Object)(object)_draggingTab != (Object)null) && _tabs.Count >= 2)
			{
				CancelRename();
				_draggingTab = tab;
				_dragInsertIndex = -1;
				RectTransform val = (RectTransform)((Component)tab).transform;
				LayoutElement component = ((Component)tab).GetComponent<LayoutElement>();
				Vector3[] array = (Vector3[])(object)new Vector3[4];
				val.GetWorldCorners(array);
				Vector3 val2 = (array[0] + array[2]) * 0.5f;
				_dragFixedY = val2.y;
				_dragZ = ((Transform)val).position.z;
				float num;
				if ((Object)(object)tab.Label != (Object)null && (Object)(object)component != (Object)null)
				{
					FitTabWidth(tab.Label, component, tab.FullName, Mathf.Min(_tabWidth, 120f));
					num = component.preferredWidth;
				}
				else
				{
					Rect rect = val.rect;
					num = ((Rect)(ref rect)).width;
				}
				_placeholder = CreatePlaceholder(num);
				((Transform)_placeholder).SetSiblingIndex(((Transform)val).GetSiblingIndex());
				if ((Object)(object)component != (Object)null)
				{
					component.ignoreLayout = true;
				}
				if ((Object)(object)tab.Background != (Object)null)
				{
					((Graphic)tab.Background).raycastTarget = false;
				}
				val.pivot = new Vector2(0.5f, 0.5f);
				val.SetSizeWithCurrentAnchors((Axis)0, num);
				((Transform)val).position = val2;
				((Transform)val).SetAsLastSibling();
			}
		}

		public void Drag(PageTab tab, PointerEventData eventData)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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)
			Vector3 val = default(Vector3);
			if (!((Object)(object)_draggingTab != (Object)(object)tab) && !((Object)(object)_root == (Object)null) && RectTransformUtility.ScreenPointToWorldPointInRectangle(_root, eventData.position, eventData.pressEventCamera, ref val))
			{
				RectTransform val2 = (RectTransform)((Component)tab).transform;
				_root.GetWorldCorners(_dragCorners);
				Rect rect = val2.rect;
				float num = ((Rect)(ref rect)).width * ((Transform)_root).lossyScale.x * 0.5f;
				float num2 = Mathf.Clamp(val.x, _dragCorners[0].x + num, _dragCorners[2].x - num);
				((Transform)val2).position = new Vector3(num2, _dragFixedY, _dragZ);
				ReflowPlaceholder(num2);
			}
		}

		public void EndDrag(PageTab tab, PointerEventData eventData)
		{
			if ((Object)(object)_draggingTab != (Object)(object)tab)
			{
				return;
			}
			if ((Object)(object)Dashboard == (Object)null || Dashboard.charts == null)
			{
				CleanupDrag();
				Refresh();
				return;
			}
			DashboardLayout dashboardLayout = Dashboard.charts.dashboardLayout;
			List<DashboardPage> list = new List<DashboardPage>();
			for (int i = 0; i < ((Transform)_root).childCount; i++)
			{
				Transform child = ((Transform)_root).GetChild(i);
				if ((Object)(object)child == (Object)(object)_placeholder)
				{
					DashboardPage val = dashboardLayout.pages[_draggingTab.Slot];
					if (val != null)
					{
						list.Add(val);
					}
					continue;
				}
				PageTab component = ((Component)child).GetComponent<PageTab>();
				if (!((Object)(object)component == (Object)null) && !((Object)(object)component == (Object)(object)_draggingTab))
				{
					DashboardPage val2 = dashboardLayout.pages[component.Slot];
					if (val2 != null)
					{
						list.Add(val2);
					}
				}
			}
			if (!PageOps.ReorderPages(Dashboard.charts, list))
			{
				DashboardOverhaulPlugin.Logger.LogWarning((object)"[DashboardOverhaul] Reorder rejected: built order was not a permutation of the current pages; drag discarded.");
			}
			CleanupDrag();
			Refresh();
		}

		private RectTransform CreatePlaceholder(float width)
		{
			//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
			GameObject val = new GameObject("DO_DragPlaceholder", new Type[1] { typeof(RectTransform) });
			RectTransform val2 = (RectTransform)val.transform;
			((Transform)val2).SetParent((Transform)(object)_root, false);
			LayoutElement obj = val.AddComponent<LayoutElement>();
			obj.preferredWidth = width;
			obj.minWidth = width;
			obj.preferredHeight = 28f;
			return val2;
		}

		private void ReflowPlaceholder(float cursorWorldX)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_placeholder == (Object)null || (Object)(object)_root == (Object)null)
			{
				return;
			}
			float x = ((Transform)_root).lossyScale.x;
			float num = (((Object)(object)_layout != (Object)null) ? ((HorizontalOrVerticalLayoutGroup)_layout).spacing : 0f);
			float num2 = (((Object)(object)_layout != (Object)null) ? ((float)((LayoutGroup)_layout).padding.left) : 0f);
			_root.GetWorldCorners(_dragCorners);
			float x2 = _dragCorners[0].x;
			_reflowOrdered.Clear();
			int num3 = 0;
			float num4 = x2 + num2 * x;
			for (int i = 0; i < ((Transform)_root).childCount; i++)
			{
				Transform child = ((Transform)_root).GetChild(i);
				PageTab component = ((Component)child).GetComponent<PageTab>();
				if (!((Object)(object)component == (Object)null) && !((Object)(object)component == (Object)(object)_draggingTab))
				{
					_reflowOrdered.Add(child);
					((RectTransform)child).GetWorldCorners(_dragCorners);
					float num5 = _dragCorners[2].x - _dragCorners[0].x;
					if (num4 + num5 * 0.5f < cursorWorldX)
					{
						num3++;
					}
					num4 += num5 + num * x;
				}
			}
			if (num3 > _reflowOrdered.Count)
			{
				num3 = _reflowOrdered.Count;
			}
			if (num3 != _dragInsertIndex)
			{
				_dragInsertIndex = num3;
				_reflowOrdered.Insert(num3, (Transform)(object)_placeholder);
				if ((Object)(object)_addButton != (Object)null)
				{
					_reflowOrdered.Add((Transform)(object)_addButton);
				}
				_reflowOrdered.Add(((Component)_draggingTab).transform);
				for (int j = 0; j < _reflowOrdered.Count; j++)
				{
					_reflowOrdered[j].SetSiblingIndex(j);
				}
			}
		}

		private void CleanupDrag()
		{
			_placeholder = null;
			_draggingTab = null;
			_dragInsertIndex = -1;
		}

		private Button CreateAction(Transform parent, string label, float x, float width, UnityAction action)
		{
			//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_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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("DO_Action", new Type[1] { typeof(RectTransform) });
			RectTransform val2 = (RectTransform)val.transform;
			((Transform)val2).SetParent(parent, false);
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0.5f, 0f);
			val2.anchorMax = val3;
			val2.anchorMin = val3;
			val2.pivot = new Vector2(0.5f, 0f);
			val2.anchoredPosition = new Vector2(x, 0f);
			val2.sizeDelta = new Vector2(width, 30f);
			Image targetGraphic = val.AddComponent<Image>();
			Button obj = val.AddComponent<Button>();
			((Selectable)obj).targetGraphic = (Graphic)(object)targetGraphic;
			DashboardUi.StyleButton(obj, new Color(0.13f, 0.3f, 0.4f, 0.95f));
			DashboardUi.Text((Transform)(object)val2, _font, label, (TextAnchor)4);
			((UnityEvent)obj.onClick).AddListener(action);
			return obj;
		}

		private void BuildEmptyPanel()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_0056: 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)
			//IL_00af: Expected O, but got Unknown
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Expected O, but got Unknown
			GameObject val = new GameObject("DO_EmptyPage", new Type[1] { typeof(RectTransform) });
			_emptyPanel = (RectTransform)val.transform;
			((Transform)_emptyPanel).SetParent((Transform)(object)Dashboard.chartContentRt, false);
			_emptyPanel.sizeDelta = new Vector2(460f, 112f);
			_emptyText = DashboardUi.Text((Transform)(object)_emptyPanel, _font, "", (TextAnchor)1);
			_emptyAdd = CreateAction((Transform)(object)_emptyPanel, Loc.L("添加图表", "Add charts"), -100f, 184f, (UnityAction)delegate
			{
				if (Dashboard.charts.statPlans.count == 0)
				{
					UIRoot.instance.uiGame.OpenProductionWindow();
					UIRealtimeTip.Popup(Loc.L("在统计窗口中选择需要监控的统计项", "Choose a statistic to monitor in the statistics window"), true, 0);
				}
				else if (!Dashboard.showSidebar)
				{
					Dashboard.OnSidebarBtnClick(0);
				}
			});
			_emptyCopy = CreateAction((Transform)(object)_emptyPanel, Loc.L("复制其他页面", "Copy another page"), 100f, 184f, new UnityAction(OpenCopyMenu));
			val.SetActive(false);
		}

		private void UpdateEmptyPanel()
		{
			if ((Object)(object)_emptyPanel == (Object)null || !PageOps.IsValidViewPage(Dashboard.charts))
			{
				return;
			}
			CustomCharts charts = Dashboard.charts;
			DashboardPage val = charts.dashboardLayout.pages[charts.currentView.pageIndex];
			bool flag = val.chartDatas.Count == 0;
			if (((Component)_emptyPanel).gameObject.activeSelf != flag)
			{
				((Component)_emptyPanel).gameObject.SetActive(flag);
			}
			if (!flag)
			{
				return;
			}
			bool flag2 = charts.statPlans.count > 0;
			bool flag3 = false;
			DashboardPage[] pages = charts.dashboardLayout.pages;
			foreach (DashboardPage val2 in pages)
			{
				if (val2 != null && val2 != val && val2.chartDatas.Count > 0)
				{
					flag3 = true;
					break;
				}
			}
			int num = (int)((flag2 ? 1u : 0u) | (uint)(flag3 ? 2 : 0)) | (Localization.isZHCN ? 4 : 0);
			if (num != _emptyState)
			{
				_emptyState = num;
				_emptyText.text = Loc.L("当前页暂无图表\n", "This page has no charts\n") + (flag2 ? Loc.L("打开侧栏,点击统计项旁的添加按钮。", "Open the sidebar and use a statistic's add button.") : Loc.L("先在统计窗口中添加需要监控的统计项。", "Start by adding a statistic from the statistics window."));
				((Component)_emptyAdd).GetComponentInChildren<Text>().text = (flag2 ? Loc.L("添加图表", "Add charts") : Loc.L("打开统计窗口", "Open statistics"));
				((Selectable)_emptyCopy).interactable = flag3;
				DashboardUi.Tip(((Component)_emptyCopy).gameObject, Loc.L("复制其他页面", "Copy another page"), flag3 ? Loc.L("复制布局和显示设置;统计项与原页面共享,重命名会同步生效。", "Copy layout and display settings. Statistics are shared; renaming affects both pages.") : Loc.L("没有其他包含图表的页面", "No other page contains charts"));
			}
		}

		private void OpenCopyMenu()
		{
			//IL_0055: 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_006f: Expected O, but got Unknown
			CustomCharts charts = Dashboard.charts;
			DashboardPage target = charts.dashboardLayout.pages[charts.currentView.pageIndex];
			UIPopupMenu val = Dashboard.OpenChartPopupMenu(new Vector2(0f, 30f), (RectTransform)((Component)_emptyCopy).transform);
			((Transform)val.m_RectTrans).SetParent((Transform)(object)Dashboard.chartContentRt, true);
			for (int i = 1; i < 10; i++)
			{
				DashboardPage source = charts.dashboardLayout.pages[i];
				if (source == null || source == target || source.chartDatas.Count == 0)
				{
					continue;
				}
				UIPopupMenuButton obj = val.AddMenuButton($"{PageOps.PageName(source, i)} ({source.chartDatas.Count})", -1, false);
				obj.onMenuButtonClick = (Action<int>)Delegate.Combine(obj.onMenuButtonClick, (Action<int>)delegate
				{
					if (!((Object)(object)Dashboard == (Object)null) && Dashboard.charts == charts && Array.IndexOf(charts.dashboardLayout.pages, target) >= 1)
					{
						Dashboard.CloseChartPopupMenu();
						if (PageOps.CopyIntoEmptyPage(source, target))
						{
							Dashboard.DetermineCharts();
							UpdateEmptyPanel();
							UIRealtimeTip.Popup(Loc.L("已复制图表,统计项与原页共享。", "Charts copied. Statistics are shared with the source page."), true, 0);
						}
					}
				});
				obj.SetState(true);
			}
			val.SetState(true);
			Dashboard.input_lock = true;
		}

		public void ShowMoved(DashboardPage page, ChartData chart)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Expected O, but got Unknown
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Expected O, but got Unknown
			if ((Object)(object)_notice == (Object)null)
			{
				GameObject val = new GameObject("DO_MoveNotice", new Type[1] { typeof(RectTransform) });
				_notice = (RectTransform)val.transform;
				((Transform)_notice).SetParent((Transform)(object)Dashboard.rectTrans, false);
				RectTransform notice = _notice;
				RectTransform notice2 = _notice;
				Vector2 val2 = default(Vector2);
				((Vector2)(ref val2))..ctor(0.5f, 0f);
				notice2.anchorMax = val2;
				notice.anchorMin = val2;
				_notice.pivot = new Vector2(0.5f, 0f);
				_notice.anchoredPosition = new Vector2(0f, 36f);
				_notice.sizeDelta = new Vector2(440f, 96f);
				((Graphic)val.AddComponent<Image>()).color = new Color(0.02f, 0.08f, 0.14f, 0.96f);
				_noticeText = DashboardUi.Text((Transform)(object)_notice, _font, "", (TextAnchor)1);
				((Graphic)_noticeText).rectTransform.offsetMin = new Vector2(8f, 36f);
				((Graphic)_noticeText).rectTransform.offsetMax = new Vector2(-8f, -8f);
				CreateAction((Transform)(object)_notice, Loc.L("前往", "Go to page"), -50f, 90f, (UnityAction)delegate
				{
					int num = Array.IndexOf(Dashboard.charts.dashboardLayout.pages, _movedPage);
					if (num > 0)
					{
						SwitchTo(num);
						Dashboard.HighlightChart(_movedChart);
					}
					((Component)_notice).gameObject.SetActive(false);
				});
				CreateAction((Transform)(object)_notice, Loc.L("关闭", "Dismiss"), 50f, 90f, (UnityAction)delegate
				{
					((Component)_notice).gameObject.SetActive(false);
				});
			}
			_movedPage = page;
			_movedChart = chart;
			_noticeUntil = Time.unscaledTime + 10f;
			((Component)_notice).gameObject.SetActive(true);
			((Transform)_notice).SetAsLastSibling();
			UpdateLayout();
		}
	}
	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;
			foreach (UIPopupMenuButton childButton in popupMenu.childButtons)
			{
				if (childButton.onMenuButtonClick == new Action<int>(__instance.CloseAndRemoveChart))
				{
					childButton.ButtonText = Loc.L("移除此图表", "Remove this chart");
					childButton.SetState(true);
				}
			}
			if (PageOps.ActivePageCount(charts) > 1)
			{
				UIPopupMenuButton val = popupMenu.AddMenuButton(Loc.L("移动到页面", "Move to page"), -1, true);
				UIPopupMenu val2 = __instance.CreateAndInitChildPopupMenu(val);
				for (int i = 1; i < 10; i++)
				{
					DashboardPage val3 = dashboardLayout.pages[i];
					if (i != pageIndex && val3 != null)
					{
						UIPopupMenuButton obj = val2.AddMenuButton(PageOps.PageName(val3, i), -1, false);
						obj.data = i;
						obj.onMenuButtonClick = (Action<int>)Delegate.Combine(obj.onMenuButtonClick, (Action<int>)delegate(int slot)
						{
							MoveChartToPage(__instance, slot);
						});
						obj.SetState(true);
					}
				}
				val.m_ChildMenu = val2;
				val.SetState(true);
			}
			int num = PageOps.ChartCount(charts, __instance.chartData.statPlanId);
			UIPopupMenuButton obj2 = popupMenu.AddMenuButton(string.Format(Loc.L("重命名统计项(影响 {0} 个图表)", "Rename statistic (affects {0} charts)"), num), -1, true);
			obj2.onMenuButtonClick = (Action<int>)Delegate.Combine(obj2.onMenuButtonClick, (Action<int>)delegate
			{
				__instance.uiDashboard.CloseChartPopupMenu();
				ChartRename.Begin(__instance);
			});
			obj2.SetState(true);
			UIPopupMenuButton obj3 = popupMenu.AddMenuButton(Loc.L("删除统计项及其全部图表", "Delete statistic and all its charts"), -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_005f: Unknown result type (might be due to invalid IL or missing references)
			CustomCharts charts = chart.charts;
			UIDashboard uiDashboard = chart.uiDashboard;
			if (charts == null || (Object)(object)uiDashboard == (Object)null || chart.chartData == null)
			{
				return;
			}
			DashboardPage[] pages = charts.dashboardLayout.pages;
			DashboardPage val = pages[charts.currentView.pageIndex];
			DashboardPage val2 = pages[targetSlot];
			ChartData chartData = chart.chartData;
			uiDashboard.CloseChartPopupMenu();
			if (val != null && val2 != null)
			{
				ChartRename.CancelIfTargeting(chart);
				if (!PageOps.TryMoveChart(val, val2, chartData, uiDashboard.CalculateMaxMiniGridCount()))
				{
					UIRealtimeTip.Popup(Loc.L("目标页面没有足够空位,图表保留在原页。", "No room on the destination page. The chart stays on its original page."), true, 0);
					return;
				}
				uiDashboard.DetermineCharts();
				UIDashboardPatch.Bar?.ShowMoved(val2, chartData);
			}
		}

		private static void ConfirmDelete(UIChart chart)
		{
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			if (chart.chartData == null || chart.charts == null)
			{
				return;
			}
			UIDashboard dash = chart.uiDashboard;
			CustomCharts charts = chart.charts;
			int id = chart.chartData.statPlanId;
			StatPlan stat = charts.statPlans[id];
			dash.CloseChartPopupMenu();
			ChartRename.CancelIfTargeting(chart);
			UIMessageBox.Show(Loc.L("删除统计项", "Delete statistic"), string.Format(Loc.L("删除统计项“{0}”?\n将移除其全部 {1} 个图表(包括其他页面和监控视图),以及侧栏中的统计项。", "Delete statistic “{0}”?\nThis removes all {1} associated charts, including other pages and watch views, and the sidebar statistic."), stat.displayName, PageOps.ChartCount(charts, id)), Localization.Translate("取消"), Localization.Translate("确定"), 1, (Response)null, (Response)delegate
			{
				if (!((Object)(object)dash == (Object)null) && dash.charts == charts && charts.statPlans?.buffer != null && id < charts.statPlans.buffer.Length && charts.statPlans[id] == stat)
				{
					ChartRename.Cancel();
					dash.ResetChartPool();
					charts.RemoveStatPlan(id);
					dash.DetermineCharts();
					dash.statboard.DetermineEntryVisible();
				}
			});
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(UIDashboard), "PutChartIntoPool")]
		private static void PutChartIntoPool_Prefix(UIChart chart)
		{
			ChartRename.CancelIfTargeting(chart);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StatPlan), "Rename")]
		private static void Rename_Postfix(StatPlan __instance)
		{
			UIDashboard val = UIDashboardPatch.Bar?.Dashboard;
			if ((Object)(object)val == (Object)null || val.charts != __instance.charts)
			{
				return;
			}
			foreach (UIChart item in val.chartPool)
			{
				if (((ManualBehaviour)item).inited && item.chartData.statPlanId == __instance.id)
				{
					item.SetTipFormatString();
					UIDashboardTip titleTip = item.titleTip;
					if (titleTip != null)
					{
						titleTip.RefreshSimpleGeneralTipText();
					}
				}
			}
			foreach (UIStatPlanEntry item2 in val.statboard.objectEntryPool)
			{
				if (item2.statPlan == __instance)
				{
					item2.nameInput.SetTextWithoutNotify(__instance.name ?? "");
				}
			}
		}

		[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 obj = gameObject.GetComponent<ChartTitleRenameTrigger>() ?? gameObject.AddComponent<ChartTitleRenameTrigger>();
				((Graphic)__result.titleText).raycastTarget = true;
				obj.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);
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(UIDashboard), "_OnOpen")]
		private static void OnOpen_Prefix(UIDashboard __instance)
		{
			PageOps.EnsureViewPage(__instance.charts);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIDashboard), "_OnOpen")]
		private static void OnOpen_Postfix()
		{
			Bar?.Refresh();
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(UIDashboard), "SetViewPage")]
		private static void SetViewPage_Prefix(UIDashboard __instance)
		{
			Bar?.FinishRename();
			ChartRename.Finish();
			__instance.CloseChartPopupMenu();
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(UIDashboard), "_OnClose")]
		private static void OnClose_Prefix()
		{
			Bar?.Close();
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(UIDashboard), "_OnFree")]
		private static void OnFree_Prefix()
		{
			Bar?.Close();
		}

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

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIDashboard), "_OnDestroy")]
		private static void OnDestroy_Postfix()
		{
			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.3.0";
	}
}