Files
RedHotRoast-ios/Assets/Scripts/ModuleUI/WheelView/WheelViewUI.cs
T

347 lines
11 KiB
C#
Raw Normal View History

2026-04-22 09:52:55 +08:00
// using FGUI.A000_common;
using System;
using System.Collections.Generic;
using DG.Tweening;
using FairyGUI;
using FGUI.ZM_Common_01;
using FGUI.ZM_Turntable_11;
2026-04-22 09:52:55 +08:00
using Spine.Unity;
using UnityEngine;
namespace RedHotRoast
2026-04-22 09:52:55 +08:00
{
public class WheelViewUI : BaseUI
{
private WheelViewUICtrl ctrl;
private WheelViewModel model;
private readonly int[] vidieWeight = new int[8];
private List<Turntable> turntableData;
2026-04-22 09:52:55 +08:00
private List<com_coin> ItemList = new();
private bool isClickSpin;
private bool isClickAbleWatchAD = true;
private SkeletonAnimation normalAnim;
// private SkeletonAnimation turnAnim;
// private SkeletonAnimation awardAnim;
private Action closeCallback;
private FGUI.ZM_Turntable_11.com_wheel ui;
2026-04-22 09:52:55 +08:00
public WheelViewUI(WheelViewUICtrl ctrl) : base(ctrl)
{
uiName = UIConst.WheelViewUI;
this.ctrl = ctrl;
}
protected override void SetUIInfo(UIInfo uiInfo)
{
uiInfo.packageName = "ZM_Turntable_11";
2026-04-22 09:52:55 +08:00
uiInfo.assetName = "com_wheel";
uiInfo.layerType = UILayerType.Popup;
uiInfo.isNeedOpenAnim = true;
uiInfo.isNeedCloseAnim = true;
uiInfo.isNeedUIMask = true;
}
#region
protected override void OnInit()
{
model = moduleManager.GetModel(ModelConst.WheelViewModel) as WheelViewModel;
}
protected override void OnClose()
{
HallManager.Instance.UpdateSecondEvent -= UpdateTime;
2026-04-22 09:52:55 +08:00
GameHelper.showGameUI = true;
}
protected override void OnBind()
{
ui = baseUI as FGUI.ZM_Turntable_11.com_wheel;
2026-04-22 09:52:55 +08:00
}
protected override void OnOpenBefore(object args)
{
LoadLastCheckDate();
CheckNewDay();
var disc = ui.disc;
ItemList.Add(disc.award1);
ItemList.Add(disc.award2);
ItemList.Add(disc.award3);
ItemList.Add(disc.award4);
ItemList.Add(disc.award5);
ItemList.Add(disc.award6);
ItemList.Add(disc.award7);
ItemList.Add(disc.award8);
HallManager.Instance.UpdateSecondEvent += UpdateTime;
turntableData = ConfigSystem.GetConfig<Turntable>();
2026-04-22 09:52:55 +08:00
normalAnim = FXManager.Instance.SetFx<SkeletonAnimation>(ui.light_parent, Fx_Type.fx_wheel, ref closeCallback);
UpdateTime();
refreshData();
InitView();
}
private DateTime _lastCheckDate;
private const string PlayerPrefsKeyLastCheckDate = "Wheel_new_days";
private void LoadLastCheckDate()
{
string lastCheckDateString = PlayerPrefs.GetString(PlayerPrefsKeyLastCheckDate, "");
if (!string.IsNullOrEmpty(lastCheckDateString))
{
_lastCheckDate = DateTime.ParseExact(lastCheckDateString, "yyyy-MM-dd", null);
}
else
{
// 如果没有找到日期,初始化为今天的日期
_lastCheckDate = DateTime.Today;
SaveLastCheckDate();
}
}
private void SaveLastCheckDate()
{
// 将日期转换为字符串并存储到PlayerPrefs
PlayerPrefs.SetString(PlayerPrefsKeyLastCheckDate, _lastCheckDate.ToString("yyyy-MM-dd"));
PlayerPrefs.Save();
}
private void CheckNewDay()
{
DateTime currentDate = DateTime.Today;
// 如果当前日期与上次检查的日期不同,说明是新的一天
if (_lastCheckDate != currentDate)
{
// 重置 ThisDayWatchSlyderVideoNum
DataMgr.ThisDayWatchSlyderVideoNum.Value = 0;
2026-04-22 09:52:55 +08:00
// 更新最后检查的日期并保存到PlayerPrefs
_lastCheckDate = currentDate;
SaveLastCheckDate();
}
}
//初始化页面逻辑
private void InitView()
{
normalAnim.state.SetAnimation(0, "daiji", true);
for (var i = 0; i < ItemList.Count; i++)
{
vidieWeight[i] = turntableData[i].weight;
2026-04-22 09:52:55 +08:00
}
ui.disc.rotation = 0;
ui.btn_spin.SetClick(SpineAnim);
2026-04-22 09:52:55 +08:00
ui.close.SetClick(() =>
{
CtrlCloseUI();
2026-04-22 09:52:55 +08:00
});
}
private void refreshData()
{
for (int i = 0; i < ItemList.Count; i++)
{
var item = ItemList[i];
var turntable = turntableData[i];
2026-04-22 09:52:55 +08:00
var id = turntable.wheel_item;
var quantity = turntable.quantity;
if (!GameHelper.IsGiftSwitch() && id == 102)
{
id = 101;
quantity *= 10;
}
item.text_num.text = id == 102 ? GameHelper.Get102Str((decimal)quantity) : GameHelper.Get101Str((decimal)quantity);
item.status.selectedIndex = id == 102 ? com_coin.Status_b : com_coin.Status_a;
}
var times = DataMgr.ThisDayWatchSlyderVideoNum.Value;
2026-04-22 09:52:55 +08:00
var limits = GameHelper.GetCommonModel().wheelTimes[0];
ui.limit.SetVar("times", times.ToString()).FlushVars();
ui.limit.SetVar("limit", limits.ToString()).FlushVars();
2026-04-22 09:52:55 +08:00
}
protected override void OnOpen(object args)
{
}
protected override void OnHide()
{
}
protected override void OnDisplay(object args)
{
}
#endregion
#region
protected override void AddListener()
{
}
protected override void RemoveListener()
{
}
#endregion
private Tween ResultTween;
private float turnTime = 7.0f;
private void SpineAnim()
{
if (isClickSpin)
return;
if (GameHelper.GetNowTime() < DataMgr.NextOpenWheelStampTime.Value) return;
2026-04-22 09:52:55 +08:00
if (isClickAbleWatchAD)
{
isClickAbleWatchAD = false;
GameHelper.ShowVideoAd("reward_luckySpin", isSuccess =>
{
if (isSuccess)
{
Spin();
}
isClickAbleWatchAD = true;
});
}
}
private void Spin()
{
// normalAnim.SetActive(false);
ui.disc.rotation = 0;
normalAnim.state.SetAnimation(0, "xuanzhuan", true);
isClickSpin = true;
ui.close.touchable = false;
ui.close.grayed = false;
ui.btn_spin.touchable = false;
2026-04-22 09:52:55 +08:00
var index = CommonHelper.GetIndexByChanceList(vidieWeight);
var data = turntableData[index];
2026-04-22 09:52:55 +08:00
var angle = 3600 - (data.Seq - 1) * 45;
AudioManager.Instance.PlayDynamicEffect(AudioConst.wheel_spin);
DOTween.To(() => ui.disc.rotation, e => ui.disc.rotation = e, angle, turnTime)
.SetEase(Ease.OutQuad);
ResultTween = DOVirtual.DelayedCall(turnTime, () => ReceivePlane(data,index));
2026-04-22 09:52:55 +08:00
}
private void ReceivePlane(Turntable vo,int index)
2026-04-22 09:52:55 +08:00
{
normalAnim.state.SetAnimation(0, "zhongjiang", true);
DOVirtual.DelayedCall(1.5f, () =>
{
isClickSpin = false;
ResultTween = null;
ui.close.touchable = true;
ui.close.grayed = false;
ui.btn_spin.cont_spin.selectedIndex = btn_go1.Spin_grey;
2026-04-22 09:52:55 +08:00
ui.btn_spin.cont_state.selectedIndex = btn_go1.State_Video;
2026-04-22 09:52:55 +08:00
var id = vo.wheel_item;
var quantity = vo.quantity;
if (!GameHelper.IsGiftSwitch() && id == 102)
{
id = 101;
quantity *= 10;
}
var endPoint = GameHelper.GetUICenterPosition(ui.point);
var rewardData = new RewardData();
var rewardSingleData = new RewardSingleData(id, (decimal)quantity, RewardOrigin.LuckyWheel,index)
2026-04-22 09:52:55 +08:00
{
endPosition = new Vector2(endPoint.x - 150, endPoint.y - 136),
};
rewardData.AddReward(rewardSingleData);
rewardData.displayType = RewardDisplayType.RewardFly | RewardDisplayType.Dialog |
RewardDisplayType.ValueChange;
2026-04-22 09:52:55 +08:00
rewardData.AddCompleted((isScu) =>
{
normalAnim.state.SetAnimation(0, "daiji", true);
});
GameDispatcher.Instance.Dispatch(GameMsg.GetReward, rewardData);
DataMgr.NextOpenWheelStampTime.Value =
2026-04-22 09:52:55 +08:00
GameHelper.GetNowTime() + GameHelper.GetCommonModel().wheelTimes[1];
DataMgr.ThisDayWatchSlyderVideoNum.Value++;
2026-04-22 09:52:55 +08:00
UpdateTime();
refreshData();
});
}
private void UpdateTime()
{
if (DataMgr.ThisDayWatchSlyderVideoNum.Value >= GameHelper.GetCommonModel().wheelTimes[0])
2026-04-22 09:52:55 +08:00
{
DateTime currentTime = DateTime.Now;
ui.btn_spin.cont_state.selectedIndex = btn_go1.State_Limit;
ui.btn_spin.touchable = false;
ui.btn_spin.enabled = false;
ui.btn_spin.cont_spin.selectedIndex = btn_go1.Spin_grey;
2026-04-22 09:52:55 +08:00
}
else
{
if (GameHelper.GetNowTime() >= DataMgr.NextOpenWheelStampTime.Value)
2026-04-22 09:52:55 +08:00
{
ui.btn_spin.touchable = true;
ui.btn_spin.enabled = true;
ui.btn_spin.cont_spin.selectedIndex = btn_go1.Spin_none;
ui.btn_spin.cont_state.selectedIndex = btn_go1.State_None;
2026-04-22 09:52:55 +08:00
}
else
{
ui.btn_spin.touchable = false;
ui.btn_spin.enabled = false;
ui.btn_spin.cont_spin.selectedIndex = btn_go1.Spin_grey;
ui.btn_spin.cont_state.selectedIndex = btn_go1.State_Video;
2026-04-22 09:52:55 +08:00
}
ui.btn_spin.text_time.text = model.NextOpenWheelTimeStr;
2026-04-22 09:52:55 +08:00
}
}
}
}