507 lines
12 KiB
C#
507 lines
12 KiB
C#
// ***********************************************************************
|
|
// Assembly : Game
|
|
// Author : Kimch
|
|
// Created : 2022-01-12
|
|
// Description :
|
|
// Last Modified By :
|
|
// Last Modified On :
|
|
// ***********************************************************************
|
|
// <copyright file= "WheelWindow.View" company="Kunpo"></copyright>
|
|
// <summary></summary>
|
|
// ***********************************************************************
|
|
namespace G.UI
|
|
{
|
|
using System.Collections;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
partial class WheelWindow
|
|
{
|
|
public class Sounds
|
|
{
|
|
public static string Appear = "wheel_appear_01";
|
|
|
|
public static string BigWinLoop;
|
|
|
|
public static string Disappear;
|
|
|
|
public static string NumbersIncrease;
|
|
|
|
public static string SingleTic;
|
|
|
|
public static string WheelSpin = "wheel_spin_01";
|
|
|
|
public static string Start = "wheel_start_01";
|
|
|
|
public static string Win = "wheel_win_01";
|
|
}
|
|
|
|
|
|
public class WheelSlotWidget : KUIWidget
|
|
{
|
|
[KUIFlag]
|
|
Image _imgIcon;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpCount;
|
|
[KUIFlag]
|
|
GameObject _goState;
|
|
|
|
public override void Refresh()
|
|
{
|
|
if (this.data is WheelProxy.SlotInfo slotInfo)
|
|
{
|
|
var rewardProp = slotInfo.reward.propItem;
|
|
IconProxy.Instance.SetSprite(_imgIcon, rewardProp.icon);
|
|
_tmpCount.text = "x" + slotInfo.reward.count.ToString();
|
|
|
|
_goState.SetActive(slotInfo.rewardState != 0);
|
|
}
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
SetViewData();
|
|
}
|
|
}
|
|
|
|
public class LuckRewardWidget : KUIWidget
|
|
{
|
|
[KUIFlag]
|
|
Image _imgIcon;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpCount;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpState;
|
|
|
|
Button _btnState;
|
|
KUIImage _stateImage;
|
|
|
|
public override void Refresh()
|
|
{
|
|
if (this.data is ActivitySubInfo subInfo)
|
|
{
|
|
var rewardInfo = subInfo.rewardInfos[0];
|
|
IconProxy.Instance.SetSprite(_imgIcon, rewardInfo.propItem.icon);
|
|
_tmpCount.text = "x" + rewardInfo.count.ToString();
|
|
_tmpState.text = subInfo.target.ToString();
|
|
_stateImage.ShowSprite(subInfo.status);
|
|
}
|
|
}
|
|
|
|
void OnBtnClick()
|
|
{
|
|
if (this.data is ActivitySubInfo activitySubInfo)
|
|
{
|
|
WheelProxy.Instance.GetRewards(activitySubInfo, (error, message) =>
|
|
{
|
|
if (error == 0)
|
|
{
|
|
Refresh();
|
|
PostNotification(GlobalDefine.EVENT_MONEY_CHANGED);
|
|
ToastBox.ShowText("领取成功");
|
|
}
|
|
else
|
|
{
|
|
OpenWindow<PropListBox>(activitySubInfo.rewardInfos);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
SetViewData();
|
|
_stateImage = GetComponent<KUIImage>();
|
|
_btnState = GetComponent<Button>();
|
|
|
|
_btnState.onClick.AddListener(OnBtnClick);
|
|
}
|
|
}
|
|
|
|
public class RewardItemWidget : KUIWidget
|
|
{
|
|
[KUIFlag]
|
|
Image _imgIcon;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpCount;
|
|
[KUIFlag]
|
|
GameObject _goSignined;
|
|
[KUIFlag]
|
|
GameObject _goComplete;
|
|
[KUIFlag]
|
|
Button _btnProp;
|
|
|
|
public override void Refresh()
|
|
{
|
|
if (this.data is ActivitySubInfo activitySubInfo)
|
|
{
|
|
var reward = activitySubInfo.rewardInfos[0];
|
|
IconProxy.Instance.SetSprite(_imgIcon, reward.propItem.icon);
|
|
_tmpCount.text = "x" + reward.count;
|
|
_goSignined.SetActive(activitySubInfo.status == 2);
|
|
_goComplete.SetActive(activitySubInfo.status == 1);
|
|
}
|
|
else if (this.data is ActivityInfo activityInfo)
|
|
{
|
|
activitySubInfo = activityInfo.subInfos[0];
|
|
var reward = activitySubInfo.rewardInfos[0];
|
|
IconProxy.Instance.SetSprite(_imgIcon, reward.propItem.icon);
|
|
_tmpCount.text = "x" + reward.count;
|
|
_goSignined.SetActive(activitySubInfo.status == 2);
|
|
_goComplete.SetActive(activitySubInfo.status == 1);
|
|
}
|
|
}
|
|
|
|
void OnClick()
|
|
{
|
|
if (this.data is ActivitySubInfo activitySubInfo)
|
|
{
|
|
InviteProxy.Instance.GetRewards(activitySubInfo, (error, message) =>
|
|
{
|
|
if (error == 0)
|
|
{
|
|
Refresh();
|
|
PostNotification(GlobalDefine.EVENT_MONEY_CHANGED);
|
|
ToastBox.ShowText("领取成功");
|
|
}
|
|
else
|
|
{
|
|
ToastBox.ShowText(message);
|
|
}
|
|
});
|
|
}
|
|
else if (this.data is ActivityInfo activityInfo)
|
|
{
|
|
activitySubInfo = activityInfo.subInfos[0];
|
|
|
|
if (activitySubInfo.status == 1 && TimeProxy.Instance.TryTimeKey(502))
|
|
{
|
|
activitySubInfo.status = 2;
|
|
RewardProxy.Instance.GetRewardsWithUI(activitySubInfo.rewardInfos, null);
|
|
Refresh();
|
|
}
|
|
else
|
|
{
|
|
ToastBox.ShowText("请明日再来");
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
SetViewData();
|
|
_btnProp.onClick.AddListener(this.OnClick);
|
|
}
|
|
}
|
|
|
|
#region Auto Generate
|
|
|
|
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|
[KUIFlag]
|
|
Button _btnClose;
|
|
|
|
[KUIFlag]
|
|
Animator __animWheel;
|
|
[KUIFlag]
|
|
Button _btnSpin;
|
|
|
|
[KUIFlag]
|
|
Slider _sliLuck;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpLuck;
|
|
[KUIFlag]
|
|
KUIList __listLuckRewards;
|
|
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpInviteCount;
|
|
[KUIFlag]
|
|
Button _btnInvite;
|
|
[KUIFlag]
|
|
TextMeshProUGUI _tmpInviteMoney;
|
|
[KUIFlag]
|
|
Button _btnSlotRefresh;
|
|
|
|
[KUIFlag]
|
|
Button _btnInviteList;
|
|
[KUIFlag]
|
|
GameObject _goMember;
|
|
[KUIFlag]
|
|
KUIList __listMember;
|
|
|
|
[KUIFlag]
|
|
GameObject __goDaily;
|
|
|
|
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
|
|
|
|
#endregion
|
|
|
|
#region Field
|
|
|
|
private GameObject _innerWheelGO;
|
|
private GameObject _winHighlight;
|
|
|
|
private Transform _goSymbols;
|
|
|
|
private bool _hasSpinStarted;
|
|
|
|
private float _angleToStopWheelOn;
|
|
private int _resultSymbolIndex;
|
|
|
|
private WheelSlotWidget[] _propWidgets;
|
|
|
|
private RewardItemWidget _dailyRewardItemWidget;
|
|
|
|
#endregion
|
|
|
|
#region Method
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void InitView()
|
|
{
|
|
SetViewData();
|
|
_btnClose.onClick.AddListener(this.OnCloseBtnClick);
|
|
_btnSpin.onClick.AddListener(this.OnSpinBtnClick);
|
|
|
|
_winHighlight = __animWheel.transform.Find("WinHighlight").gameObject;
|
|
_innerWheelGO = __animWheel.transform.Find("Wheel").gameObject;
|
|
|
|
_goSymbols = __animWheel.transform.Find("Wheel/Symbols");
|
|
_propWidgets = new WheelSlotWidget[_goSymbols.childCount];
|
|
for (int i = 0; i < _goSymbols.childCount; i++)
|
|
{
|
|
_propWidgets[i] = _goSymbols.GetChild(i).gameObject.AddComponent<WheelSlotWidget>();
|
|
}
|
|
|
|
__listLuckRewards.AddTemplate<LuckRewardWidget>(true);
|
|
__listMember.AddTemplate<ShareWindow.MemberCellWidget>(true);
|
|
|
|
_dailyRewardItemWidget = __goDaily.AddComponent<RewardItemWidget>();
|
|
|
|
_btnInvite.onClick.AddListener(this.OnInviteBtnClick);
|
|
_btnInviteList.onClick.AddListener(this.OnInviteListBtnClick);
|
|
_btnSlotRefresh.onClick.AddListener(this.OnSlotRefreshBtnClick);
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void RefreshView()
|
|
{
|
|
InviteProxy.Instance.GetInviteCount((error, message) =>
|
|
{
|
|
if (error == 0)
|
|
RefreshInviteCount();
|
|
});
|
|
|
|
RefreshLucyAcc();
|
|
RefreshSlot();
|
|
|
|
RefreshDaily();
|
|
|
|
_hasSpinStarted = false;
|
|
_btnSpin.interactable = true;
|
|
_btnSlotRefresh.interactable = true;
|
|
|
|
SoundProxy.PlayFxAsync(Sounds.Appear);
|
|
}
|
|
|
|
void RefreshLucyAcc()
|
|
{
|
|
var activity = WheelProxy.Instance.luckAccActivity;
|
|
var subInfos = activity.subInfos;
|
|
__listLuckRewards.Clear();
|
|
foreach (var subInfo in subInfos)
|
|
{
|
|
__listLuckRewards.GetItem().SetData(subInfo);
|
|
}
|
|
|
|
var maxTarget = subInfos[subInfos.Length - 1].target;
|
|
_tmpLuck.text = WheelProxy.Instance.luckValue.ToString();
|
|
_sliLuck.value = WheelProxy.Instance.luckValue / (float)maxTarget;
|
|
}
|
|
|
|
void RefreshSlot()
|
|
{
|
|
var wheelInfo = WheelProxy.Instance.GetWheelInfo(1);
|
|
var slotInfos = wheelInfo.slotInfos;
|
|
for (int i = 0; i < _propWidgets.Length; i++)
|
|
{
|
|
_propWidgets[i].SetData(slotInfos[i]);
|
|
}
|
|
}
|
|
|
|
void RefreshInviteCount()
|
|
{
|
|
_tmpInviteCount.text = "已邀请人数:x" + InviteProxy.Instance.inviteCount.ToString();
|
|
_tmpInviteMoney.text = "x" + WheelProxy.Instance.wheelMoney.ToString();
|
|
}
|
|
|
|
void RefreshDaily()
|
|
{
|
|
var dailyRewardActivity = ActivityProxy.Instance.GetActivity(800);
|
|
if (dailyRewardActivity != null)
|
|
{
|
|
if (TimeProxy.Instance.GetTimeKey(502))
|
|
{
|
|
dailyRewardActivity.subInfos[0].status = 1;
|
|
}
|
|
else
|
|
{
|
|
dailyRewardActivity.subInfos[0].status = 2;
|
|
}
|
|
_dailyRewardItemWidget.SetData(dailyRewardActivity);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public void UpdateView()
|
|
{
|
|
|
|
}
|
|
|
|
void OnSpinBtnClick()
|
|
{
|
|
WheelProxy.Instance.Spin(1, (error, message, data) =>
|
|
{
|
|
if (error == 0)
|
|
{
|
|
StartCoroutine(SpinSequence(data as WheelProxy.SlotInfo));
|
|
}
|
|
else
|
|
ToastBox.ShowText(message);
|
|
});
|
|
}
|
|
|
|
IEnumerator SpinSequence(WheelProxy.SlotInfo slotInfo)
|
|
{
|
|
//WheelAreaAnimator.Play("UpsaleWheelStop");
|
|
_hasSpinStarted = true;
|
|
_btnSpin.interactable = false;
|
|
_btnSlotRefresh.interactable = false;
|
|
|
|
_resultSymbolIndex = slotInfo.index;
|
|
|
|
int wantedResult = _resultSymbolIndex;
|
|
//wantedResult = Random.Range(0, 10);
|
|
_angleToStopWheelOn = 0f - 36f * wantedResult;
|
|
Debug.Log(wantedResult + " " + _angleToStopWheelOn);
|
|
|
|
__animWheel.Play("UpsaleWheelFullSpin");
|
|
__animWheel.Update(0f);
|
|
SoundProxy.PlayFxAsync(Sounds.WheelSpin);
|
|
|
|
float animationTime = __animWheel.GetCurrentAnimatorClipInfo(0)[0].clip.length;
|
|
yield return new WaitForSeconds(animationTime - 1.5f);
|
|
__animWheel.Play("UpsaleWin");
|
|
SoundProxy.PlayFxAsync(Sounds.Win);
|
|
|
|
yield return new WaitForSeconds(1.1f);
|
|
//float currentResultAmount = _initialAmount;
|
|
//float resultAmount = _totalWinAmount;
|
|
|
|
float countDuration = 3f;
|
|
float countStartTime = Time.time;
|
|
//SoundProxy.PlayFx(Sounds.NumbersIncrease);
|
|
//SoundPoolItem countLoopSound = SoundManager.Instance.PlaySoundFromPool(Sounds.NumbersIncrease, true);
|
|
//while (Time.time <= countStartTime + countDuration && currentResultAmount <= resultAmount)
|
|
//{
|
|
// float lerpFactor = (Time.time - countStartTime) / countDuration;
|
|
// currentResultAmount = Mathf.Lerp(_initialAmount, resultAmount, lerpFactor);
|
|
// //ResultText.text = currentResultAmount.ToNumberFormattingString();
|
|
// yield return new WaitForSeconds(0.02f);
|
|
//}
|
|
//ResultText.text = resultAmount.ToNumberFormattingString();
|
|
|
|
//WheelAreaAnimator.Play("UpsaleWheelIdle");
|
|
|
|
yield return new WaitForSeconds(0.02f);
|
|
//if ((bool)countLoopSound)
|
|
//{
|
|
// countLoopSound.gameObject.SetActive(false);
|
|
//}
|
|
//int minMultiplierToShowFireworks = SettingProxy.GetDefaultInt("upsale_min_multiplier_for_fireworks", 3);
|
|
//if (_winMultiplierValue >= minMultiplierToShowFireworks)
|
|
//{
|
|
// EffectsManager.Instance.ActivateUpsaleFireworksEffect();
|
|
// yield return new WaitForSeconds(1f);
|
|
// _winLoopSound = SoundManager.Instance.PlaySoundFromPool(Sounds.BigWinLoop, true);
|
|
//}
|
|
yield return new WaitForSeconds(1.2f);
|
|
//DisabledSpinButton.SetActive(false);
|
|
//CollectButton.SetActive(true);
|
|
//_canClick = true;
|
|
//WheelAreaAnimator.Play("UpsaleWheelIdle");
|
|
_btnSpin.interactable = true;
|
|
_btnSlotRefresh.interactable = true;
|
|
|
|
_hasSpinStarted = false;
|
|
|
|
WheelProxy.Instance.GetWheelSlotId(1, slotInfo.index, (error, message) =>
|
|
{
|
|
if (error == 0)
|
|
RefreshView();
|
|
else
|
|
ToastBox.ShowText(message);
|
|
});
|
|
}
|
|
|
|
void OnCloseBtnClick()
|
|
{
|
|
CloseWindow(this);
|
|
}
|
|
|
|
void OnInviteBtnClick()
|
|
{
|
|
InviteProxy.Instance.InviteShare((error, message) =>
|
|
{
|
|
if (error == 0)
|
|
ToastBox.ShowText("分享成功");
|
|
else
|
|
ToastBox.ShowText(message);
|
|
});
|
|
}
|
|
|
|
void OnInviteListBtnClick()
|
|
{
|
|
_goMember.SetActive(true);
|
|
__listMember.Clear();
|
|
InviteProxy.Instance.GetInviteList((error, message) =>
|
|
{
|
|
if (error == 0)
|
|
{
|
|
var friendInfos = InviteProxy.Instance.friendInfos;
|
|
foreach (var item in friendInfos)
|
|
{
|
|
__listMember.GetItem().SetData(item);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
void OnSlotRefreshBtnClick()
|
|
{
|
|
WheelProxy.Instance.RefreshSlot((error, message) =>
|
|
{
|
|
if (error == 0)
|
|
RefreshSlot();
|
|
});
|
|
}
|
|
|
|
public static void RotateWheelToSpinResultAngle()
|
|
{
|
|
_Instance._innerWheelGO.transform.localRotation = Quaternion.Euler(0f, 0f, _Instance._angleToStopWheelOn);
|
|
//_Instance._winHighlight.transform.localRotation = Quaternion.Euler(0f, 0f, 0f - _Instance._angleToStopWheelOn);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|