Files
SVSimServer/SVSim.BattleEngine/Engine/Wizard/FormatChangeUI.cs

154 lines
4.4 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using Cute;
using UnityEngine;
namespace Wizard;
public class FormatChangeUI : MonoBehaviour
{
public enum FormatCategory
{
Invalid,
Rotation,
Unlimited,
PreRotation,
Crossover,
MyRotation,
Other
}
private static readonly Dictionary<FormatCategory, (string ON, string OFF)> ANOTHER_BTN_SPRITES = new Dictionary<FormatCategory, (string, string)>
{
{
FormatCategory.Other,
("btn_gacha_other_on", "btn_gacha_other_off")
},
{
FormatCategory.PreRotation,
("btn_prerotation_on", "btn_prerotation_off")
},
{
FormatCategory.Crossover,
("btn_gacha_crossover_on", "btn_gacha_crossover_off")
},
{
FormatCategory.MyRotation,
("btn_gacha_myrotation_on", "btn_gacha_myrotation_off")
}
};
[SerializeField]
private UIButton _btnRotation;
[SerializeField]
private UIButton _btnUnlimited;
[SerializeField]
private UIButton _btnAnother;
private FormatCategory _currentFormatCategory = FormatCategory.Rotation;
private Action<FormatCategory> _onChangeFormat;
public void ChangeFormat(FormatCategory inFormatCategory)
{
_currentFormatCategory = inFormatCategory;
UpdateFormatBtnSprite(inFormatCategory);
}
public void SetEnableFormatButton(FormatCategory formatCategory, bool isEnable)
{
switch (formatCategory)
{
case FormatCategory.Rotation:
UIManager.SetObjectToGrey(_btnRotation.gameObject, !isEnable);
return;
case FormatCategory.Unlimited:
UIManager.SetObjectToGrey(_btnUnlimited.gameObject, !isEnable);
return;
}
if (ANOTHER_BTN_SPRITES.ContainsKey(formatCategory))
{
UIManager.SetObjectToGrey(_btnAnother.gameObject, !isEnable);
}
}
public void UpdateAnotherFormatButton(FormatCategory anotherFormatCategory)
{
bool flag = anotherFormatCategory != FormatCategory.Invalid;
_btnAnother.gameObject.SetActive(flag);
_btnUnlimited.normalSprite = (flag ? "btn_unlimited_center_off" : "btn_gacha_unlimited_off");
_btnUnlimited.pressedSprite = (flag ? "btn_unlimited_center_on" : "btn_gacha_unlimited_on");
if (flag)
{
_btnAnother.onClick.Add(new EventDelegate(delegate
{
OnClickChangeFormatBtn(anotherFormatCategory);
}));
_btnAnother.normalSprite = ANOTHER_BTN_SPRITES[anotherFormatCategory].OFF;
_btnAnother.pressedSprite = ANOTHER_BTN_SPRITES[anotherFormatCategory].ON;
}
else
{
_btnAnother.onClick.Clear();
}
}
private void OnClickChangeFormatBtn(FormatCategory formatCategory)
{
if (_currentFormatCategory != formatCategory)
{
ChangeFormat(formatCategory);
_onChangeFormat.Call(formatCategory);
StartCoroutine(WaitForCanClickFormatBtns());
}
}
private IEnumerator WaitForCanClickFormatBtns()
{
SetEnableAllBtns(isEnable: false);
yield return new WaitForSeconds(0.4f);
SetEnableAllBtns(isEnable: true);
}
private void SetEnableAllBtns(bool isEnable)
{
_btnRotation.isEnabled = isEnable;
_btnUnlimited.isEnabled = isEnable;
_btnAnother.isEnabled = isEnable;
}
private string RenameSpriteString(string str, bool isEnable)
{
string oldValue = (isEnable ? "_off" : "_on");
string newValue = (isEnable ? "_on" : "_off");
return str.Replace(oldValue, newValue);
}
private void UpdateFormatBtnSprite(FormatCategory inFormatCategory)
{
switch (inFormatCategory)
{
case FormatCategory.Rotation:
_btnRotation.normalSprite = RenameSpriteString(_btnRotation.normalSprite, isEnable: true);
_btnUnlimited.normalSprite = RenameSpriteString(_btnUnlimited.normalSprite, isEnable: false);
_btnAnother.normalSprite = RenameSpriteString(_btnAnother.normalSprite, isEnable: false);
return;
case FormatCategory.Unlimited:
_btnRotation.normalSprite = RenameSpriteString(_btnRotation.normalSprite, isEnable: false);
_btnUnlimited.normalSprite = RenameSpriteString(_btnUnlimited.normalSprite, isEnable: true);
_btnAnother.normalSprite = RenameSpriteString(_btnAnother.normalSprite, isEnable: false);
return;
}
if (ANOTHER_BTN_SPRITES.ContainsKey(inFormatCategory))
{
_btnRotation.normalSprite = RenameSpriteString(_btnRotation.normalSprite, isEnable: false);
_btnUnlimited.normalSprite = RenameSpriteString(_btnUnlimited.normalSprite, isEnable: false);
_btnAnother.normalSprite = RenameSpriteString(_btnAnother.normalSprite, isEnable: true);
}
}
}