summaryrefslogtreecommitdiff
path: root/Thronefall_1_0/GameCode/TFUITextButton.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2024-05-19 16:46:27 +0800
committerchai <215380520@qq.com>2024-05-19 16:46:27 +0800
commit8b1fc7063b387542803c6bc214ccf8acb32870bd (patch)
treed310eb99872c8215f1c1f67731ec21f0915cd778 /Thronefall_1_0/GameCode/TFUITextButton.cs
parent8e13e7e2874adc8982e16d1d2ed2e28d7480b45f (diff)
* rename
Diffstat (limited to 'Thronefall_1_0/GameCode/TFUITextButton.cs')
-rw-r--r--Thronefall_1_0/GameCode/TFUITextButton.cs195
1 files changed, 0 insertions, 195 deletions
diff --git a/Thronefall_1_0/GameCode/TFUITextButton.cs b/Thronefall_1_0/GameCode/TFUITextButton.cs
deleted file mode 100644
index 31205d1..0000000
--- a/Thronefall_1_0/GameCode/TFUITextButton.cs
+++ /dev/null
@@ -1,195 +0,0 @@
-using System;
-using I2.Loc;
-using TMPro;
-using UnityEngine;
-
-[RequireComponent(typeof(TextMeshProUGUI))]
-public class TFUITextButton : ThronefallUIElement
-{
- [Serializable]
- public class Style
- {
- public Color color = Color.white;
-
- public float fontSize = 30f;
-
- public string prefix;
-
- public string suffix;
-
- public TMP_FontAsset font;
-
- public AnimationCurve animationCurve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f);
-
- public float animationDuration = 0.5f;
-
- public Style(Color color, float fontSize, TMP_FontAsset font, AnimationCurve animationCurve, float animationDuration)
- {
- this.color = color;
- this.fontSize = fontSize;
- this.font = font;
- this.animationCurve = animationCurve;
- this.animationDuration = animationDuration;
- }
- }
-
- public class Animation
- {
- public TFUITextButton target;
-
- public Style startStyle;
-
- public Style endStyle;
-
- public float clock;
-
- public Animation(Style startStyle, Style endStyle, TFUITextButton target)
- {
- this.startStyle = startStyle;
- this.endStyle = endStyle;
- this.target = target;
- target.ApplyStyle(startStyle);
- target.targetText.font = endStyle.font;
- target.targetText.text = endStyle.prefix + target.originalString + endStyle.suffix;
- target.currentAnimation = this;
- }
-
- public void Tick()
- {
- clock += Time.unscaledDeltaTime;
- float num = Mathf.InverseLerp(0f, endStyle.animationDuration, clock);
- float t = endStyle.animationCurve.Evaluate(num);
- target.targetText.color = Color.Lerp(startStyle.color, endStyle.color, t);
- target.targetText.fontSize = Mathf.LerpUnclamped(startStyle.fontSize, endStyle.fontSize, t);
- if (num >= 1f)
- {
- target.ApplyStyle(endStyle);
- target.currentAnimation = null;
- }
- }
- }
-
- private Style defaultStyle;
-
- private bool defaultStyleInitialized;
-
- public AnimationCurve defaultAnimationCurve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f);
-
- public float defaultAnimationTime = 0.3f;
-
- public Style focussedStyle;
-
- public Style selectedStyle;
-
- public Style focussedAndSelectedStyle;
-
- public Style overrideStyle;
-
- public bool applyOverrideStyle;
-
- private TextMeshProUGUI targetText;
-
- private string originalString;
-
- private Animation currentAnimation;
-
- private Localize locComponent;
-
- private void Start()
- {
- locComponent = GetComponent<Localize>();
- if (locComponent != null)
- {
- locComponent.LocalizeEvent.AddListener(UpdateOriginalStringLocalized);
- }
- }
-
- private void Update()
- {
- if (currentAnimation != null)
- {
- currentAnimation.Tick();
- }
- }
-
- protected Style GetStyle(SelectionState state)
- {
- if (!defaultStyleInitialized)
- {
- InitializeDefaultStyle();
- }
- return state switch
- {
- SelectionState.Default => defaultStyle,
- SelectionState.Focussed => focussedStyle,
- SelectionState.Selected => selectedStyle,
- SelectionState.FocussedAndSelected => focussedAndSelectedStyle,
- _ => defaultStyle,
- };
- }
-
- protected override void OnApply()
- {
- }
-
- protected override void OnClear()
- {
- new Animation(GetStyle(previousState), applyOverrideStyle ? overrideStyle : defaultStyle, this);
- }
-
- protected override void OnFocus()
- {
- new Animation(GetStyle(previousState), applyOverrideStyle ? overrideStyle : focussedStyle, this);
- }
-
- protected override void OnSelect()
- {
- new Animation(GetStyle(previousState), applyOverrideStyle ? overrideStyle : selectedStyle, this);
- }
-
- protected override void OnFocusAndSelect()
- {
- new Animation(GetStyle(previousState), applyOverrideStyle ? overrideStyle : focussedAndSelectedStyle, this);
- }
-
- protected override void OnHardStateSet(SelectionState selectionState)
- {
- currentAnimation = null;
- ApplyStyle(GetStyle(selectionState));
- }
-
- private void ApplyStyle(Style style)
- {
- targetText.color = style.color;
- targetText.fontSize = style.fontSize;
- targetText.font = style.font;
- targetText.text = style.prefix + originalString + style.suffix;
- }
-
- private void InitializeDefaultStyle()
- {
- if (!defaultStyleInitialized)
- {
- targetText = GetComponent<TextMeshProUGUI>();
- UpdateOriginalStringLocalized();
- defaultStyle = new Style(targetText.color, targetText.fontSize, targetText.font, defaultAnimationCurve, defaultAnimationTime);
- defaultStyleInitialized = true;
- }
- }
-
- private void UpdateOriginalStringLocalized()
- {
- if (locComponent == null)
- {
- locComponent = GetComponent<Localize>();
- }
- if (locComponent == null)
- {
- originalString = targetText.text;
- }
- else
- {
- originalString = LocalizationManager.GetTranslation(locComponent.Term);
- }
- }
-}