using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Jotunn;
using Jotunn.Entities;
using Jotunn.Managers;
using UnityEngine;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("SkillBarVisibility")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SkillBarVisibility")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("0.0.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.0")]
namespace SkillBarVisibility;
[BepInPlugin("Lisonna.SkillBarVisibility", "SkillBarVisibility", "0.0.1")]
[BepInProcess("valheim.exe")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
internal class SkillBarVisibility : BaseUnityPlugin
{
public class SkillBarContainer : MonoBehaviour
{
private GameObject m_container = new GameObject("SkillBarContainer", new Type[1] { typeof(RectTransform) });
private Dictionary<SkillType, GameObject> m_skillBars = new Dictionary<SkillType, GameObject>();
private GameObject[] m_activeBars = (GameObject[])(object)new GameObject[30];
public SkillBarContainer()
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
//IL_0074: 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_00a5: 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_0123: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: 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_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_0160: Unknown result type (might be due to invalid IL or missing references)
//IL_0167: Expected O, but got Unknown
//IL_017f: Unknown result type (might be due to invalid IL or missing references)
//IL_019b: Unknown result type (might be due to invalid IL or missing references)
m_container.transform.SetParent(GUIManager.CustomGUIBack.transform, false);
m_container.GetComponent<RectTransform>().anchoredPosition = new Vector2(s_containerXOffset, s_containerYOffset);
foreach (SkillType value2 in Enum.GetValues(typeof(SkillType)))
{
SkillType val = value2;
if (s_iconSpriteNames.TryGetValue(val, out var value))
{
Sprite prefab = Cache.GetPrefab<Sprite>(value);
UIExtensions.ProgressBarConfig config = new UIExtensions.ProgressBarConfig
{
icon = prefab,
name = ((object)(SkillType)(ref val)).ToString(),
height = s_barHeight,
width = s_barWidth,
enableIcon = true,
valueScale = 10f,
bgColor = new Color(0f, 0f, 0f, 0.7f),
bgSprite = s_skillBarBkg,
fgColor = GUIManager.Instance.ValheimBeige,
fgSprite = s_skillBarFrg
};
GameObject val2 = new GameObject("SkillBar " + value);
SkillBar skillBar = val2.AddComponent<SkillBar>();
skillBar.Init(m_container.transform, config, val, this);
val2.SetActive(false);
m_skillBars.Add(val, val2);
}
}
m_container.SetActive(true);
}
public void InitializeSkillBars(Player player)
{
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
Skills skills = ((Character)player).GetSkills();
foreach (GameObject value in m_skillBars.Values)
{
Logger.LogInfo((object)"test1");
SkillBar component = value.GetComponent<SkillBar>();
Logger.LogInfo((object)"test2");
Skill skill = skills.GetSkill(component.m_skillType);
Logger.LogInfo((object)"test3");
if (skill != null)
{
component.UpdateSkill(skill, suppressShow: true);
}
else
{
component.ResetBar();
}
}
}
public void UpdateSkill(SkillType skillType)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
if (m_skillBars.TryGetValue(skillType, out var value))
{
value.GetComponent<SkillBar>().UpdateSkill();
}
}
public GameObject GetSkillBar(SkillType skillType)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
m_skillBars.TryGetValue(skillType, out var value);
return value;
}
public void BarEnabled(GameObject bar)
{
if (m_activeBars.Contains(bar))
{
return;
}
for (int i = 0; i < m_activeBars.Count(); i++)
{
if ((Object)(object)m_activeBars[i] == (Object)null)
{
m_activeBars[i] = bar;
bar.GetComponent<SkillBar>().SetYOffset((s_barHeight + s_barPadding) * (float)i * -1f);
break;
}
}
}
public void BarDisabled(GameObject bar)
{
for (int i = 0; i < m_activeBars.Count(); i++)
{
if ((Object)(object)m_activeBars[i] == (Object)(object)bar)
{
m_activeBars[i] = null;
break;
}
}
}
public void OnDestroy()
{
Logger.LogInfo((object)"skillbarcontainer destroyed?");
s_skillBarContainer = null;
}
}
public class SkillBar : UIExtensions.ProgressBar
{
public SkillType m_skillType;
public Skill m_skill;
private SkillBarContainer m_container;
private float m_level;
private bool m_suppressDisable;
public void Init(Transform parent, UIExtensions.ProgressBarConfig config, SkillType skillType, SkillBarContainer sbc, float startingValue = 0f)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
base.Init(parent, config, startingValue);
m_skillType = skillType;
m_container = sbc;
m_suppressDisable = true;
}
public void Init(Transform parent, UIExtensions.ProgressBarConfig config, SkillType skillType, float startingValue = 0f)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
base.Init(parent, config, startingValue);
m_skillType = skillType;
m_suppressDisable = true;
}
public void UpdateSkill(Skill skill, bool suppressShow = false)
{
m_skill = skill;
UpdateValues(suppressShow);
}
public void UpdateSkill(bool suppressShow = false)
{
UpdateValues(suppressShow);
}
private void UpdateValues(bool suppressShow = false)
{
//IL_00c4: 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_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
float level = m_level;
m_level = m_skill.m_level;
float currentValue = GetCurrentValue();
float num = GetTotalValue() - currentValue;
SetCenterText(((int)m_skill.m_level).ToString());
SetCurrentValue(m_skill.m_accumulator);
SetTotal(m_skill.GetNextLevelRequirement());
if (!suppressShow)
{
EnableSkillBar();
if (s_showGainText && level <= m_level)
{
((Component)this).gameObject.AddComponent<UIExtensions.MovingText>().Init(new UIExtensions.MovingTextConfig
{
duration = 3f,
relativeEndFromStart = new Vector2(125f, 0f),
disableTextOnEnd = true,
deactivateGameObjectAfter = false
}, new UIExtensions.TextObjectConfig
{
text = "+" + FormatValueText((level < m_level) ? num : (m_skill.m_accumulator - currentValue)),
fontSize = 16,
color = Color.green,
xOffset = -75f
});
}
}
}
private void EnableSkillBar()
{
((Component)this).gameObject.SetActive(true);
((Behaviour)this).enabled = true;
SetAlpha(1f);
UIExtensions.UIAnimation.StartFaderAfterTime(((Component)this).gameObject, s_barVisibilityDuration, s_fadeoutDuration);
m_container?.BarEnabled(((Component)this).gameObject);
}
public void ResetBar()
{
SetCurrentValue(0f);
SetTotal(1f);
SetCenterText("1");
}
public void OnDisable()
{
if (!m_suppressDisable)
{
m_container?.BarDisabled(((Component)this).gameObject);
}
else
{
m_suppressDisable = false;
}
}
}
[HarmonyPatch(typeof(Skill), "Raise")]
private class Skill_Patches
{
[HarmonyPostfix]
private static void Postfix(Skill __instance)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
UpdateSkillBar(__instance.m_info.m_skill);
}
}
[HarmonyPatch(typeof(Skills), "LowerAllSkills")]
private class Skills_Patches
{
[HarmonyPostfix]
private static void Postfix(Skills __instance)
{
if ((Object)(object)Player.m_localPlayer == (Object)(object)__instance.m_player)
{
s_skillBarContainer.InitializeSkillBars(__instance.m_player);
}
}
}
[HarmonyPatch(typeof(Player), "Load")]
private class PlayerLoad_Patches
{
[HarmonyPostfix]
private static void Postfix(Player __instance)
{
if ((Object)(object)Player.m_localPlayer == (Object)(object)__instance)
{
int width = Screen.width;
int height = Screen.height;
Logger.LogInfo((object)("Current resolution: " + width + "x" + height));
if ((Object)(object)s_skillBarContainer == (Object)null)
{
s_skillBarContainer = new SkillBarContainer();
s_skillBarContainer.InitializeSkillBars(__instance);
}
}
}
}
public const string PluginGUID = "Lisonna.SkillBarVisibility";
public const string PluginName = "SkillBarVisibility";
public const string PluginVersion = "0.0.1";
public static CustomLocalization Localization = LocalizationManager.Instance.GetLocalization();
private readonly Harmony harmony = new Harmony("Lisonna.SkillBarVisibility");
public static SkillBarContainer s_skillBarContainer;
private static Dictionary<SkillType, string> s_iconSpriteNames = new Dictionary<SkillType, string>
{
{
(SkillType)1,
"SwordIron"
},
{
(SkillType)2,
"knife_flint"
},
{
(SkillType)3,
"club"
},
{
(SkillType)4,
"AtgeirBronze"
},
{
(SkillType)5,
"SpearFlint"
},
{
(SkillType)6,
"shield_banded1"
},
{
(SkillType)7,
"axe_iron"
},
{
(SkillType)8,
"bow"
},
{
(SkillType)9,
"elemental_magic"
},
{
(SkillType)10,
"blood_magic"
},
{
(SkillType)11,
"hands"
},
{
(SkillType)12,
"pickaxe_stone"
},
{
(SkillType)13,
"skill_woodcutting"
},
{
(SkillType)14,
"crossbow_arbalest"
},
{
(SkillType)100,
"skill_jump"
},
{
(SkillType)101,
"skill_sneak"
},
{
(SkillType)102,
"skill_run"
},
{
(SkillType)103,
"skill_swim"
},
{
(SkillType)104,
"fishingrod"
},
{
(SkillType)105,
"meat_cooked"
},
{
(SkillType)106,
"cultivator_bronze"
},
{
(SkillType)107,
"hammer"
},
{
(SkillType)108,
"skill_dodge"
},
{
(SkillType)110,
"SadleLox"
}
};
private static Dictionary<SkillType, Sprite> s_skillSprites = new Dictionary<SkillType, Sprite>();
private static Sprite s_skillBarBkg;
private static Sprite s_skillBarFrg;
public static float s_containerXOffset = -800f;
public static float s_containerYOffset = 0f;
public static float s_barWidth = 250f;
public static float s_barHeight = 20f;
public static float s_barPadding = 4f;
public static float s_barVisibilityDuration = 5f;
public static float s_fadeoutDuration = 2f;
public static bool s_showGainText = true;
private void Awake()
{
PrefabManager.OnVanillaPrefabsAvailable += OnPrefabsAvail;
harmony.PatchAll();
}
private void OnPrefabsAvail()
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
foreach (KeyValuePair<SkillType, string> s_iconSpriteName in s_iconSpriteNames)
{
Sprite prefab = Cache.GetPrefab<Sprite>(s_iconSpriteName.Value);
if ((Object)(object)prefab != (Object)null)
{
s_skillSprites.Add(s_iconSpriteName.Key, prefab);
}
}
s_skillBarBkg = Cache.GetPrefab<Sprite>("skill_bkg");
s_skillBarFrg = Cache.GetPrefab<Sprite>("bar_food_8");
PrefabManager.OnVanillaPrefabsAvailable -= OnPrefabsAvail;
}
private void OnDestroy()
{
harmony.UnpatchSelf();
}
public static void UpdateSkillBar(SkillType skillType)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
s_skillBarContainer.UpdateSkill(skillType);
}
}
public static class RectTransformExtensions
{
public static void SetElementSize(this RectTransform rtf, float width, float height)
{
rtf.SetSizeWithCurrentAnchors((Axis)0, width);
rtf.SetSizeWithCurrentAnchors((Axis)1, height);
}
}
internal class UIExtensions
{
public static class AnchorPoint
{
public static readonly Vector2 TopLeft = new Vector2(0f, 1f);
public static readonly Vector2 Top = new Vector2(0.5f, 1f);
public static readonly Vector2 TopRight = new Vector2(1f, 1f);
public static readonly Vector2 Left = new Vector2(0f, 0.5f);
public static readonly Vector2 Center = new Vector2(0.5f, 0.5f);
public static readonly Vector2 Right = new Vector2(1f, 0.5f);
public static readonly Vector2 BottomLeft = new Vector2(0f, 0f);
public static readonly Vector2 Bottom = new Vector2(0.5f, 0f);
public static readonly Vector2 BottomRight = new Vector2(1f, 0f);
public static Vector2 Reverse(Vector2 vector)
{
//IL_0006: 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_0019: 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_0021: Unknown result type (might be due to invalid IL or missing references)
return new Vector2(1f - vector.x, 1f - vector.y);
}
public static void SetChildPointToParentPoint(RectTransform rtf, Vector2 childPoint, Vector2 parentPoint, float xOffset = 0f, float yOffset = 0f)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: 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_0022: Unknown result type (might be due to invalid IL or missing references)
rtf.anchorMin = parentPoint;
rtf.anchorMax = rtf.anchorMin;
rtf.pivot = childPoint;
rtf.anchoredPosition = new Vector2(xOffset, yOffset);
}
public static void SetChildToFillParent(RectTransform rtf)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: 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_0026: 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)
rtf.anchorMin = BottomLeft;
rtf.anchorMax = TopRight;
rtf.pivot = Center;
rtf.sizeDelta = Vector2.zero;
rtf.anchoredPosition = Vector2.zero;
}
public static GameObject CreateGOAndSetParentPoint(string name, Transform parent, Vector2 childPoint, Vector2 parentPoint, float xOffset = 0f, float yOffset = 0f, params Type[] components)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Expected O, but got Unknown
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject(name, components);
val.transform.SetParent(parent, false);
SetChildPointToParentPoint(ExposedGameObjectExtension.GetOrAddComponent<RectTransform>(val), childPoint, parentPoint, xOffset, yOffset);
return val;
}
public static GameObject CreateGOAndSetChildFillParent(string name, Transform parent, params Type[] components)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
GameObject val = CreateGOAndSetParentPoint(name, parent, Center, Center, 0f, 0f, components);
SetChildToFillParent(val.GetComponent<RectTransform>());
return val;
}
}
public class RectangleConfig
{
}
public class TextObjectConfig
{
public string text = "";
private int _fontSize = 16;
public bool outline = true;
public Color color;
public Font font = GUIManager.Instance.AveriaSerif;
public float xOffset = 0f;
public float yOffset = 0f;
public int fontSize
{
get
{
return _fontSize;
}
set
{
if (value > 0)
{
_fontSize = value;
return;
}
throw new ArgumentOutOfRangeException("value", "Fontsize must be a positive, non-zero value");
}
}
}
public class ProgressBarConfig
{
private float _height = 20f;
private float _width = 200f;
public float xOffset = 0f;
public float yOffset = 0f;
private float _total = 100f;
public Sprite icon;
public bool enableIcon = false;
public bool flipIconPosition = false;
public Color bgColor = Color.black;
public Color fgColor = Color.white;
public Sprite bgSprite;
public Sprite fgSprite;
public Direction direction = (Direction)0;
public bool inverse = false;
public string name = "";
public string centerText = "";
public int fontSize = 16;
public int valueTextDecimals = 0;
public float valueScale = 1f;
public float height
{
get
{
return _height;
}
set
{
if (value > 0f)
{
_height = value;
return;
}
throw new ArgumentOutOfRangeException("value", "Height must be a positive, non-zero value");
}
}
public float width
{
get
{
return _width;
}
set
{
if (value > 0f)
{
_width = value;
return;
}
throw new ArgumentOutOfRangeException("value", "Width must be a positive, non-zero value");
}
}
public float total
{
get
{
return _total;
}
set
{
if (value > 0f)
{
_total = value;
return;
}
throw new ArgumentOutOfRangeException("value", "Total must be a positive, non-zero value");
}
}
}
public class ProgressBar : MonoBehaviour
{
public ProgressBarConfig m_config;
protected GameObject m_barsContainer;
protected GameObject m_backgroundBar;
protected GameObject m_foregroundBar;
protected Slider m_sliderBar;
protected GameObject m_iconContainer;
protected GameObject m_icon;
protected GameObject m_textsContainer;
protected GameObject m_valueText;
protected GameObject m_totalText;
protected GameObject m_centerText;
public virtual void Init(Transform parent, ProgressBarConfig config, float startingValue)
{
m_config = config;
SetupContainer(parent);
SetupIcon();
SetupBars();
SetupSlider(startingValue);
SetupTexts();
((Component)this).gameObject.SetActive(true);
}
private void SetupContainer(Transform parent)
{
//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)
RectTransform orAddComponent = ExposedGameObjectExtension.GetOrAddComponent<RectTransform>(((Component)this).gameObject);
((Component)this).gameObject.transform.SetParent(parent, false);
orAddComponent.SetElementSize(m_config.width, m_config.height);
AnchorPoint.SetChildPointToParentPoint(orAddComponent, AnchorPoint.Center, AnchorPoint.Center, m_config.xOffset, m_config.yOffset);
((Component)this).gameObject.AddComponent<CanvasGroup>();
}
public void SetName(string name)
{
m_config.name = name;
}
public void SetAlpha(float alpha)
{
alpha = Mathf.Clamp01(alpha);
((Component)this).gameObject.GetComponent<CanvasGroup>().alpha = alpha;
}
public void SetXOffset(float x, bool relative = false)
{
//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_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
RectTransform component = ((Component)this).gameObject.GetComponent<RectTransform>();
if (relative)
{
component.anchoredPosition += new Vector2(x, 0f);
}
else
{
component.anchoredPosition = new Vector2(x, component.anchoredPosition.y);
}
m_config.xOffset = component.anchoredPosition.x;
}
public void SetYOffset(float y, bool relative = false)
{
//IL_0036: 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_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
RectTransform component = ((Component)this).gameObject.GetComponent<RectTransform>();
if (relative)
{
component.anchoredPosition += new Vector2(0f, y);
}
else
{
component.anchoredPosition = new Vector2(component.anchoredPosition.x, y);
}
m_config.yOffset = component.anchoredPosition.y;
}
public void SetHeight(float height)
{
m_config.height = height;
((Component)this).gameObject.GetComponent<RectTransform>().SetElementSize(m_config.width, m_config.height);
SetIconSize();
}
public void SetWidth(float width)
{
m_config.width = width;
((Component)this).gameObject.GetComponent<RectTransform>().SetElementSize(m_config.width, m_config.height);
SetIconSize();
}
private void SetupIcon()
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: 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_0055: Unknown result type (might be due to invalid IL or missing references)
m_iconContainer = AnchorPoint.CreateGOAndSetParentPoint("ProgressBarIconContainer", ((Component)this).gameObject.transform, GetIconAnchor(), AnchorPoint.Reverse(GetIconAnchor()), 0f, 0f, typeof(RectTransform));
((Graphic)m_iconContainer.AddComponent<Image>()).color = Color.black;
m_icon = AnchorPoint.CreateGOAndSetChildFillParent("ProgressBarIcon", m_iconContainer.transform, typeof(RectTransform));
m_icon.AddComponent<Image>().sprite = m_config.icon;
SetIconSize();
m_iconContainer.SetActive(m_config.enableIcon);
}
private void SetIconSize()
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
if (GetIconAnchor().y == 0.5f)
{
m_iconContainer.GetComponent<RectTransform>().SetElementSize(m_config.height, m_config.height);
}
else
{
m_iconContainer.GetComponent<RectTransform>().SetElementSize(m_config.width, m_config.width);
}
}
private Vector2 GetIconAnchor()
{
//IL_0017: 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_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
return m_config.flipIconPosition ? AnchorPoint.Reverse(GetFilledEndPoint()) : GetFilledEndPoint();
}
public void SetIcon(Sprite icon)
{
m_config.icon = icon;
m_icon.GetComponent<Image>().sprite = icon;
}
public void EnableIcon()
{
m_config.enableIcon = true;
m_iconContainer.SetActive(true);
}
public void DisableIcon()
{
m_config.enableIcon = false;
m_iconContainer.SetActive(false);
}
public void SetFlipIconPosition(bool flip)
{
m_config.flipIconPosition = flip;
SetIconAnchors();
}
private void SetIconAnchors()
{
//IL_000d: 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_0018: Unknown result type (might be due to invalid IL or missing references)
AnchorPoint.SetChildPointToParentPoint(((Component)this).gameObject.GetComponent<RectTransform>(), GetIconAnchor(), AnchorPoint.Reverse(GetIconAnchor()));
}
private void SetupBars()
{
//IL_006e: 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)
m_barsContainer = AnchorPoint.CreateGOAndSetChildFillParent("ProgressBarBars", ((Component)this).gameObject.transform, typeof(RectTransform));
m_backgroundBar = AnchorPoint.CreateGOAndSetChildFillParent("ProgressBarBgBar", m_barsContainer.transform, typeof(RectTransform));
((Graphic)m_backgroundBar.AddComponent<Image>()).color = m_config.bgColor;
m_backgroundBar.GetComponent<Image>().sprite = m_config.bgSprite;
m_foregroundBar = AnchorPoint.CreateGOAndSetChildFillParent("ProgressBarFgBar", m_barsContainer.transform, typeof(RectTransform));
((Graphic)m_foregroundBar.AddComponent<Image>()).color = m_config.fgColor;
m_foregroundBar.GetComponent<Image>().sprite = m_config.fgSprite;
}
private void SetupSlider(float startingValue)
{
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
m_sliderBar = m_barsContainer.AddComponent<Slider>();
m_sliderBar.fillRect = m_foregroundBar.GetComponent<RectTransform>();
((Selectable)m_sliderBar).targetGraphic = (Graphic)(object)m_foregroundBar.GetComponent<Image>();
((Selectable)m_sliderBar).transition = (Transition)0;
((Selectable)m_sliderBar).interactable = false;
m_sliderBar.minValue = 0f;
m_sliderBar.direction = m_config.direction;
m_sliderBar.maxValue = m_config.total;
m_sliderBar.SetValueWithoutNotify(startingValue);
}
public void SetBackgroundColor(Color color)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
m_config.bgColor = color;
((Graphic)m_backgroundBar.GetComponent<Image>()).color = color;
}
public void SetForegroundColor(Color color)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
m_config.fgColor = color;
((Graphic)m_foregroundBar.GetComponent<Image>()).color = color;
}
public void SetBackgroundSprite(Sprite sprite)
{
m_config.bgSprite = sprite;
m_backgroundBar.GetComponent<Image>().sprite = sprite;
}
public void SetForegroundSprite(Sprite sprite)
{
m_config.fgSprite = sprite;
m_foregroundBar.GetComponent<Image>().sprite = sprite;
}
public void SetDirection(Direction direction)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: 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)
m_config.direction = direction;
m_sliderBar.direction = direction;
SetIconAnchors();
SetIconSize();
}
private Vector2 GetFilledEndPoint()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Expected I4, but got Unknown
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: 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_0036: 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_003f: 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_0054: 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_0051: Unknown result type (might be due to invalid IL or missing references)
Direction direction = m_config.direction;
Direction val = direction;
return (Vector2)((int)val switch
{
0 => AnchorPoint.Right,
1 => AnchorPoint.Left,
2 => AnchorPoint.Top,
3 => AnchorPoint.Bottom,
_ => AnchorPoint.Right,
});
}
public void SetInverse(bool inverse)
{
m_config.inverse = inverse;
SetCurrentValue(GetCurrentValue());
}
private void SetupTexts()
{
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: 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_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_008a: 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_0090: 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_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_00ec: 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)
m_textsContainer = AnchorPoint.CreateGOAndSetChildFillParent("ProgressBarTextContainer", ((Component)this).gameObject.transform, typeof(RectTransform));
Vector2 filledEndPoint = GetFilledEndPoint();
m_totalText = CreateTextObject(m_textsContainer.transform, filledEndPoint, filledEndPoint, new TextObjectConfig
{
color = Color.white,
fontSize = 18,
text = FormatValueText(m_sliderBar.maxValue)
});
m_valueText = CreateTextObject(m_textsContainer.transform, AnchorPoint.Reverse(filledEndPoint), AnchorPoint.Reverse(filledEndPoint), new TextObjectConfig
{
color = Color.white,
fontSize = 18,
text = FormatValueText(m_sliderBar.value)
});
m_centerText = CreateTextObject(m_textsContainer.transform, AnchorPoint.Center, AnchorPoint.Center, new TextObjectConfig
{
color = Color.white,
fontSize = 18,
text = m_config.centerText
});
}
private void UpdateValueText()
{
m_valueText.GetComponent<Text>().text = FormatValueText(m_sliderBar.value);
}
private void UpdateTotalText()
{
m_totalText.GetComponent<Text>().text = FormatValueText(m_sliderBar.maxValue);
}
private void UpdateCenterText()
{
m_centerText.GetComponent<Text>().text = m_config.centerText;
}
protected string FormatValueText(float value)
{
return Math.Round(value * m_config.valueScale, m_config.valueTextDecimals, MidpointRounding.AwayFromZero).ToString();
}
public void SetCenterText(string text)
{
m_config.centerText = text;
UpdateCenterText();
}
public float GetCurrentValue()
{
return m_sliderBar.value;
}
public float GetTotalValue()
{
return m_sliderBar.maxValue;
}
public ProgressBarConfig GetConfig()
{
return m_config;
}
public void SetTotal(float total)
{
m_config.total = total;
m_sliderBar.maxValue = total;
UpdateTotalText();
}
public float SetCurrentValue(float value)
{
float value2 = m_sliderBar.value;
m_sliderBar.SetValueWithoutNotify(m_config.inverse ? (m_config.total - value) : value);
UpdateValueText();
return value2;
}
public void SetValueTextDecimalPlaces(int decimalPlaces)
{
m_config.valueTextDecimals = decimalPlaces;
UpdateValueText();
}
public void SetValueScale(float scale)
{
m_config.valueScale = scale;
UpdateValueText();
UpdateTotalText();
}
}
public class UIAnimationConfig
{
public bool deactivateGameObjectAfter = false;
private float _duration = 1f;
public float duration
{
get
{
return _duration;
}
set
{
if (value >= 0f)
{
_duration = value;
return;
}
throw new ArgumentOutOfRangeException("value", "Duration must not be negative.");
}
}
}
public abstract class UIAnimation : MonoBehaviour
{
public float m_duration;
public float m_startTime;
public bool m_disableGameObjOnEnd = true;
public bool m_isCanceled = false;
public bool m_isPaused = false;
public static void StartFaderAfterTime(GameObject obj, float faderStart, float faderDuration, bool disableGameObjAfterFade = true)
{
obj.GetComponent<UITimedFunctionRun>()?.Cancel();
obj.GetComponent<UIFader>()?.Cancel();
obj.AddComponent<UITimedFunctionRun>().Init(new UITimedFunctionConfig
{
duration = faderStart,
action = startFader
});
void startFader()
{
obj.AddComponent<UIFader>().Init(new UIFaderConfig
{
duration = faderDuration,
deactivateGameObjectAfter = disableGameObjAfterFade
});
}
}
public virtual void Awake()
{
m_startTime = Time.time;
}
protected void Init(UIAnimationConfig config)
{
m_duration = config.duration;
m_disableGameObjOnEnd = config.deactivateGameObjectAfter;
}
public virtual void Pause()
{
m_isPaused = true;
}
public virtual void Resume()
{
m_isPaused = false;
}
public virtual void Cancel()
{
m_isCanceled = true;
((Behaviour)this).enabled = false;
}
public virtual void Update()
{
if (!m_isPaused)
{
UpdateFunction(Time.time - m_startTime);
if (m_duration > 0f && Time.time > m_startTime + m_duration)
{
((Behaviour)this).enabled = false;
}
}
else
{
m_startTime += Time.deltaTime;
}
}
public virtual void UpdateFunction(float t)
{
}
public virtual void OnDisable()
{
if (m_disableGameObjOnEnd && !m_isCanceled)
{
((Component)this).gameObject.SetActive(false);
}
Object.Destroy((Object)(object)this);
}
}
public class UITimedFunctionConfig : UIAnimationConfig
{
public Action action;
}
public class UITimedFunctionRun : UIAnimation
{
public UITimedFunctionConfig m_config;
public void Init(UITimedFunctionConfig config)
{
Init((UIAnimationConfig)config);
if (config.action == null)
{
((Behaviour)this).enabled = false;
Logger.LogWarning((object)"TimedFunction called without a function. Nothing will happen.");
}
m_config = config;
}
public override void OnDisable()
{
m_config.action?.Invoke();
base.OnDisable();
}
}
public class UIFaderConfig : UIAnimationConfig
{
}
public class UIFader : UIAnimation
{
private CanvasGroup m_canvasGroup;
public UIFaderConfig m_config;
public override void Awake()
{
base.Awake();
m_canvasGroup = ExposedGameObjectExtension.GetOrAddComponent<CanvasGroup>(((Component)this).gameObject);
}
public void Init(UIFaderConfig config)
{
Init((UIAnimationConfig)config);
m_config = config;
}
public override void Cancel()
{
m_canvasGroup.alpha = 1f;
base.Cancel();
}
public override void UpdateFunction(float t)
{
m_canvasGroup.alpha = GetAlpha(t);
}
public override void OnDisable()
{
m_canvasGroup.alpha = 1f;
base.OnDisable();
}
private float GetAlpha(float t)
{
return 1f - t / m_duration;
}
}
public class MovingTextConfig : UIAnimationConfig
{
public Vector2 relativeEndFromStart = Vector2.zero;
public bool disableTextOnEnd = true;
}
public class MovingText : UIAnimation
{
public GameObject m_textObject;
private Vector2 m_endPosition;
public MovingTextConfig m_config;
public override void Awake()
{
base.Awake();
}
public GameObject Init(MovingTextConfig config, TextObjectConfig textConfig)
{
//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_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)
Init(config);
m_textObject = CreateTextObject(((Component)this).gameObject.transform, AnchorPoint.Center, AnchorPoint.Center, textConfig);
m_config = config;
m_endPosition = new Vector2(textConfig.xOffset + config.relativeEndFromStart.x, textConfig.yOffset + config.relativeEndFromStart.y);
return m_textObject;
}
public override void UpdateFunction(float t)
{
//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_004e: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)m_textObject != (Object)null && (Object)(object)m_textObject.GetComponent<RectTransform>() != (Object)null)
{
m_textObject.GetComponent<RectTransform>().anchoredPosition = Vector2.Lerp(m_textObject.GetComponent<RectTransform>().anchoredPosition, m_endPosition, Time.deltaTime);
}
}
public override void OnDisable()
{
base.OnDisable();
if (m_config.disableTextOnEnd)
{
m_textObject.SetActive(false);
}
}
}
public static GameObject CreateTextObject(Transform parent, Vector2 childPoint, Vector2 parentPoint, TextObjectConfig config)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
GameObject val = AnchorPoint.CreateGOAndSetParentPoint("ProgressBarText", parent, childPoint, parentPoint, config.xOffset, config.yOffset, typeof(RectTransform), typeof(Text));
val.AddComponent<ContentSizeFitter>().horizontalFit = (FitMode)2;
val.GetComponent<ContentSizeFitter>().verticalFit = (FitMode)2;
Text component = val.GetComponent<Text>();
component.text = config.text;
((Graphic)component).color = config.color;
component.font = config.font;
component.fontSize = config.fontSize;
if (config.outline)
{
Outline val2 = val.AddComponent<Outline>();
((Shadow)val2).effectColor = Color.black;
}
return val;
}
}