@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using DG.Tweening;
|
||||
using I2.Loc;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
@@ -15,17 +16,17 @@ namespace Ichni.UI
|
||||
public int intStep;
|
||||
public int intMin;
|
||||
public int intMax;
|
||||
|
||||
|
||||
public ModifyValueButton increaseButton;
|
||||
public ModifyValueButton decreaseButton;
|
||||
public TMP_Text valueText;
|
||||
|
||||
public Image barImage;
|
||||
|
||||
|
||||
public string prefix;
|
||||
public string suffix;
|
||||
public bool showPositiveMark;
|
||||
|
||||
|
||||
public void SetUp(int initialValue, int step, string title = "")
|
||||
{
|
||||
intStep = step;
|
||||
@@ -33,19 +34,21 @@ namespace Ichni.UI
|
||||
intMax = int.MaxValue;
|
||||
|
||||
base.SetUp(title);
|
||||
|
||||
|
||||
increaseButton.SetUpButton(IncreaseValue, IncreaseValue);
|
||||
decreaseButton.SetUpButton(DecreaseValue, DecreaseValue);
|
||||
SetValue(initialValue);
|
||||
UpdateValueText();
|
||||
}
|
||||
|
||||
|
||||
public void SetMinMax(int min, int max)
|
||||
{
|
||||
intMin = Convert.ToInt32(min);
|
||||
intMax = Convert.ToInt32(max);
|
||||
UpdateValueText();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void SetPrefixAndSuffix(string prefix, string suffix, bool showPositiveMark)
|
||||
{
|
||||
this.showPositiveMark = showPositiveMark;
|
||||
@@ -62,42 +65,50 @@ namespace Ichni.UI
|
||||
int valueRange = intMax - intMin;
|
||||
int stepCount = Mathf.RoundToInt(percentage * valueRange / intStep);
|
||||
int nearestValue = intMin + stepCount * intStep;
|
||||
|
||||
|
||||
return nearestValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public partial class ValueModifier
|
||||
{
|
||||
public void SetValue(int value)
|
||||
public void SetValue(int value, bool usingAnimation = false)
|
||||
{
|
||||
intValue = Convert.ToInt32(value);
|
||||
intValue = Mathf.Clamp(intValue, intMin, intMax);
|
||||
|
||||
UpdateValueText();
|
||||
|
||||
if (usingAnimation) UpdateValueTextTween(); else UpdateValueText();
|
||||
}
|
||||
|
||||
|
||||
public void IncreaseValue()
|
||||
{
|
||||
intValue += intStep;
|
||||
intValue = Mathf.Clamp(intValue, intMin, intMax);
|
||||
|
||||
UpdateValueText();
|
||||
SetValue(intValue + 1, true);
|
||||
}
|
||||
|
||||
|
||||
public void DecreaseValue()
|
||||
{
|
||||
intValue -= intStep;
|
||||
intValue = Mathf.Clamp(intValue, intMin, intMax);
|
||||
|
||||
UpdateValueText();
|
||||
SetValue(intValue - 1, true);
|
||||
}
|
||||
|
||||
|
||||
public void UpdateValueText()
|
||||
{
|
||||
|
||||
valueText.text = prefix + (showPositiveMark && intValue > 0 ? "+" : "") + intValue.ToString() + suffix;
|
||||
barImage.rectTransform.sizeDelta = new Vector2((float)(intValue - intMin) / (intMax - intMin) * 660, 20);
|
||||
|
||||
var target = new Vector2((float)(intValue - intMin) / (intMax - intMin) * 660, 20);
|
||||
barImage.rectTransform.sizeDelta = target;
|
||||
updateValueAction?.Invoke();
|
||||
}
|
||||
|
||||
private Tween tween;
|
||||
private int LastValue = -1;
|
||||
public void UpdateValueTextTween()
|
||||
{
|
||||
if (LastValue == intValue) return;
|
||||
tween?.Complete();
|
||||
valueText.text = prefix + (showPositiveMark && intValue > 0 ? "+" : "") + intValue.ToString() + suffix;
|
||||
var target = new Vector2((float)(intValue - intMin) / (intMax - intMin) * 660, 20);
|
||||
tween = barImage.rectTransform.DOSizeDelta(target, 0.2f).SetEase(Ease.OutExpo).Play();
|
||||
LastValue = intValue;
|
||||
updateValueAction?.Invoke();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user