123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- public class SpinBoxButton : MonoBehaviour
- {
- public void Init(SpinBoxParam spinBoxParam, UILabel lBox, UILabel lPoint)
- {
- this.m_lBox = lBox;
- this.m_lPoint = lPoint;
- this.maxSpinBoxNumber = spinBoxParam.m_maxNumber;
- this.minSpinBoxNumber = spinBoxParam.m_minNumber;
- this.amountPerPoint = spinBoxParam.amountPerPoint;
- if (BaseMgr<ProfileMgr>.Instance.m_maidStatus != null)
- {
- this.maxMaidPoint = SceneEdit.Instance.maidPoint;
- }
- this.m_myUiButton = base.gameObject.GetComponent<UIButton>();
- this.activeColor = new Color(this.m_myUiButton.defaultColor.r, this.m_myUiButton.defaultColor.g, this.m_myUiButton.defaultColor.b, 1f);
- this.inActiveColor = this.m_myUiButton.defaultColor;
- this.InitDownButton();
- }
- private void InitDownButton()
- {
- string name = base.gameObject.transform.name;
- if (name == "Down")
- {
- this.m_myUiButton.enabled = false;
- }
- }
- private void Update()
- {
- if (this.m_isPressed && this.m_updateTime < Time.realtimeSinceStartup)
- {
- this.OnUpDownButtonClick(base.transform.name);
- this.m_updateTime = Time.realtimeSinceStartup + this.m_updateInterval;
- }
- if (this.GetDividedPoint() > 0)
- {
- this.SetDownButtonActive(true);
- }
- else
- {
- this.SetDownButtonActive(false);
- }
- if (this.GetMaidPoint() > 0 && int.Parse(this.m_lBox.text) < this.maxSpinBoxNumber)
- {
- this.SetUpButtonActive(true);
- }
- else
- {
- this.SetUpButtonActive(false);
- }
- }
- private void OnPress(bool isDown)
- {
- if (isDown)
- {
- this.m_isPressed = true;
- this.m_updateTime = Time.realtimeSinceStartup + this.m_updateInterval;
- this.OnUpDownButtonClick(base.transform.name);
- }
- else
- {
- this.m_isPressed = false;
- }
- }
- public void OnUpDownButtonClick()
- {
- this.OnUpDownButtonClick(UIButton.current.name);
- }
- public void OnUpDownButtonClick(string clickBtnName)
- {
- SpinBoxButton.SpinBoxButtonType spinBoxButtonType = SpinBoxButton.SpinBoxButtonType.None;
- if (clickBtnName == SpinBoxButton.SpinBoxButtonType.Up.ToString())
- {
- spinBoxButtonType = SpinBoxButton.SpinBoxButtonType.Up;
- }
- else if (clickBtnName == SpinBoxButton.SpinBoxButtonType.Down.ToString())
- {
- spinBoxButtonType = SpinBoxButton.SpinBoxButtonType.Down;
- }
- else
- {
- Debug.LogError(string.Format("不適切なボタンが押されました。ボタン名:{0}", clickBtnName));
- }
- if (this.CanUpDownSpineBox(spinBoxButtonType))
- {
- this.UpdataPoint(spinBoxButtonType);
- }
- }
- private bool CanUpDownSpineBox(SpinBoxButton.SpinBoxButtonType spinBoxButtonType)
- {
- int num;
- if (!int.TryParse(this.m_lBox.text, out num))
- {
- return false;
- }
- if (spinBoxButtonType != SpinBoxButton.SpinBoxButtonType.Up)
- {
- return spinBoxButtonType == SpinBoxButton.SpinBoxButtonType.Down && (SceneEdit.Instance.maidPoint < this.maxMaidPoint && num > 0) && this.GetDividedPoint() > 0;
- }
- return SceneEdit.Instance.maidPoint > 0 && num < this.maxSpinBoxNumber;
- }
- private void UpdataPoint(SpinBoxButton.SpinBoxButtonType spinBoxButtonType)
- {
- int spinBoxPointToUse = this.GetSpinBoxPointToUse(spinBoxButtonType);
- int num = Math.Min(this.diffMaidPoint * this.amountPerPoint, spinBoxPointToUse);
- int num2 = 0;
- if (spinBoxButtonType != SpinBoxButton.SpinBoxButtonType.Up)
- {
- if (spinBoxButtonType == SpinBoxButton.SpinBoxButtonType.Down)
- {
- this.SetStatusDispPoint(-num);
- num2 = this.diffMaidPoint;
- this.SetDividedPoint(-num2);
- }
- }
- else
- {
- this.SetStatusDispPoint(num);
- num2 = -this.diffMaidPoint;
- this.SetDividedPoint(this.diffMaidPoint);
- }
- this.SetMaidPoint(num2);
- BaseMgr<ProfileMgr>.Instance.CloseSubWindowIfOpen();
- BaseMgr<ProfileMgr>.Instance.LoadMaidParamData();
- }
- private void SetStatusDispPoint(int spinBoxDispPoint)
- {
- if (this.GetSpinBoxName() == "Lovely")
- {
- BaseMgr<ProfileMgr>.Instance.m_maidStatus.baseLovely += spinBoxDispPoint;
- }
- else if (this.GetSpinBoxName() == "Elegance")
- {
- BaseMgr<ProfileMgr>.Instance.m_maidStatus.baseElegance += spinBoxDispPoint;
- }
- else if (this.GetSpinBoxName() == "Charm")
- {
- BaseMgr<ProfileMgr>.Instance.m_maidStatus.baseCharm += spinBoxDispPoint;
- }
- else if (this.GetSpinBoxName() == "Hentai")
- {
- BaseMgr<ProfileMgr>.Instance.m_maidStatus.baseHentai += spinBoxDispPoint;
- }
- else if (this.GetSpinBoxName() == "MValue")
- {
- BaseMgr<ProfileMgr>.Instance.m_maidStatus.baseMvalue += spinBoxDispPoint;
- }
- else if (this.GetSpinBoxName() == "Inran")
- {
- BaseMgr<ProfileMgr>.Instance.m_maidStatus.baseInyoku += spinBoxDispPoint;
- }
- else if (this.GetSpinBoxName() == "Housi")
- {
- BaseMgr<ProfileMgr>.Instance.m_maidStatus.baseHousi += spinBoxDispPoint;
- }
- else if (this.GetSpinBoxName() == "Cooking")
- {
- BaseMgr<ProfileMgr>.Instance.m_maidStatus.baseCooking += spinBoxDispPoint;
- }
- else if (this.GetSpinBoxName() == "Dance")
- {
- BaseMgr<ProfileMgr>.Instance.m_maidStatus.baseDance += spinBoxDispPoint;
- }
- else if (this.GetSpinBoxName() == "Vocal")
- {
- BaseMgr<ProfileMgr>.Instance.m_maidStatus.baseVocal += spinBoxDispPoint;
- }
- }
- private int GetSpinBoxPointToUse(SpinBoxButton.SpinBoxButtonType spinBoxButtonType)
- {
- if (spinBoxButtonType == SpinBoxButton.SpinBoxButtonType.Up)
- {
- return this.maxSpinBoxNumber - int.Parse(this.m_lBox.text);
- }
- if (spinBoxButtonType != SpinBoxButton.SpinBoxButtonType.Down)
- {
- return 0;
- }
- return int.Parse(this.m_lBox.text);
- }
- private void SetMaidPoint(int number)
- {
- SceneEdit.Instance.maidPoint += number;
- }
- private int GetMaidPoint()
- {
- return SceneEdit.Instance.maidPoint;
- }
- private int GetDividedPoint()
- {
- GameObject gameObject = base.transform.parent.gameObject;
- int result = 0;
- if (BaseMgr<ProfileMgr>.Instance.m_dicDividedPoint.TryGetValue(gameObject.name, out result))
- {
- return result;
- }
- Debug.LogError("不適切なスピンボックスボタンが押下されました。");
- return result;
- }
- private void SetDividedPoint(int point)
- {
- string spinBoxName = this.GetSpinBoxName();
- if (BaseMgr<ProfileMgr>.Instance.m_dicDividedPoint.ContainsKey(spinBoxName))
- {
- Dictionary<string, int> dicDividedPoint;
- string key;
- (dicDividedPoint = BaseMgr<ProfileMgr>.Instance.m_dicDividedPoint)[key = spinBoxName] = dicDividedPoint[key] + point;
- }
- else
- {
- Debug.LogError("不適切なスピンボックスボタンが押下されました。");
- }
- }
- private string GetSpinBoxName()
- {
- return base.transform.parent.gameObject.name;
- }
- private void SetUpButtonActive(bool active)
- {
- string name = base.gameObject.transform.name;
- if (name == "Up")
- {
- if (active)
- {
- if (active != this.m_currentUpActive)
- {
- this.m_myUiButton.defaultColor = this.activeColor;
- this.m_myUiButton.enabled = active;
- this.m_currentUpActive = active;
- }
- }
- else if (active != this.m_currentUpActive)
- {
- this.m_myUiButton.defaultColor = this.inActiveColor;
- this.m_myUiButton.enabled = active;
- this.m_currentUpActive = active;
- }
- }
- }
- private void SetDownButtonActive(bool active)
- {
- string name = base.gameObject.transform.name;
- if (name == "Down")
- {
- if (active)
- {
- if (active != this.m_currentDownActive)
- {
- this.m_myUiButton.defaultColor = this.activeColor;
- this.m_myUiButton.enabled = active;
- this.m_currentDownActive = active;
- }
- }
- else if (active != this.m_currentDownActive)
- {
- this.m_myUiButton.defaultColor = this.inActiveColor;
- this.m_myUiButton.enabled = active;
- this.m_currentDownActive = active;
- }
- }
- }
- private UILabel m_lBox;
- private UILabel m_lPoint;
- private UIButton m_myUiButton;
- private bool m_isPressed;
- private bool m_currentDownActive;
- private bool m_currentUpActive;
- private int maxSpinBoxNumber = 9999;
- private int minSpinBoxNumber;
- private int maxMaidPoint;
- private int amountPerPoint;
- private int diffMaidPoint = 1;
- [SerializeField]
- private float m_updateInterval;
- private float m_updateTime;
- private Color activeColor;
- private Color inActiveColor;
- private enum SpinBoxButtonType
- {
- None = -1,
- Up,
- Down
- }
- }
|