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

359 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.P01_Common;
using FGUI.P11_Wheel;
using Spine.Unity;
using UnityEngine;
namespace FlowerPower
{
public class WheelViewUI : BaseUI
{
private WheelViewUICtrl ctrl;
private WheelViewModel model;
private readonly int[] vidieWeight = new int[8];
private TurntableModel turntableData;
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.P11_Wheel.com_wheel ui;
public WheelViewUI(WheelViewUICtrl ctrl) : base(ctrl)
{
uiName = UIConst.WheelViewUI;
this.ctrl = ctrl;
}
protected override void SetUIInfo(UIInfo uiInfo)
{
uiInfo.packageName = "P11_Wheel";
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;
GameDispatcher.Instance.Dispatch(GameMsg.RefreshRedDot);
GameHelper.showGameUI = true;
}
protected override void OnBind()
{
ui = baseUI as FGUI.P11_Wheel.com_wheel;
}
protected override void OnOpenBefore(object args)
{
// ui.t1.Play();
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<TurntableModel>();
normalAnim = FXManager.Instance.SetFx<SkeletonAnimation>(ui.light_parent, Fx_Type.fx_wheel, ref closeCallback);
UpdateTime();
refreshData();
InitView();
if (GameHelper.IsGiftSwitch() && ConfigSystem.GetConfig<CommonModel>().PiggyBankSwitch == 1)
{
(ui.spin.GetChild("img_saveingpot") as GImage).visible = true;
}
}
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
PreferencesMgr.Instance.ThisDayWatchSlyderVideoNum = 0;
// 更新最后检查的日期并保存到PlayerPrefs
_lastCheckDate = currentDate;
SaveLastCheckDate();
}
}
//初始化页面逻辑
private void InitView()
{
normalAnim.state.SetAnimation(0, "daiji", true);
for (var i = 0; i < ItemList.Count; i++)
{
vidieWeight[i] = turntableData.dataList[i].weight;
}
ui.disc.rotation = 0;
ui.spin.SetClick(SpineAnim);
ui.close.SetClick(() =>
{
// ui.t2.Play(() => { });
TimerHelper.mEasy.AddTimer(0.15f, () =>
{
CtrlCloseUI();
});
});
}
private void refreshData()
{
for (int i = 0; i < ItemList.Count; i++)
{
var item = ItemList[i];
var turntable = turntableData.dataList[i];
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 = PreferencesMgr.Instance.ThisDayWatchSlyderVideoNum;
var limits = GameHelper.GetCommonModel().wheelTimes[0];
ui.text_spintimes.SetVar("times", times.ToString()).FlushVars();
ui.text_spintimes.SetVar("limits", limits.ToString()).FlushVars();
}
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() < PreferencesMgr.Instance.NextOpenWheelStampTime) return;
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.spin.touchable = false;
var index = CommonHelper.GetIndexByChanceList(vidieWeight);
var data = turntableData.dataList[index];
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));
}
private void ReceivePlane(Turntable vo, int index)
{
normalAnim.state.SetAnimation(0, "zhongjiang", true);
DOVirtual.DelayedCall(1.5f, () =>
{
isClickSpin = false;
ResultTween = null;
ui.close.touchable = true;
ui.close.grayed = false;
ui.spin.cont_spin.selectedIndex = btn_go.Spin_grey;
ui.spin.cont_state.selectedIndex = btn_go.State_Video;
var id = vo.wheel_item;
var quantity = vo.quantity;
if (!GameHelper.IsGiftSwitch() && id == 102)
{
id = 101;
quantity *= 10;
}
var endPoint = GameHelper.GetUICenterPosition(ui.point);
if (id == 102)
{
endPoint = GameHelper.GetUICenterPosition(ui.point_102);
}
var rewardData = new RewardData();
var rewardSingleData = new RewardSingleData(id, (decimal)quantity, RewardOrigin.LuckyWheel, index)
{
endPosition = new Vector2(endPoint.x - 150, endPoint.y - 136),
};
rewardData.AddReward(rewardSingleData);
rewardData.displayType = RewardDisplayType.RewardFly | RewardDisplayType.Dialog | RewardDisplayType.ValueChange;
rewardData.AddCompleted((isScu) =>
{
normalAnim.state.SetAnimation(0, "daiji", true);
});
GameDispatcher.Instance.Dispatch(GameMsg.GetReward, rewardData);
PreferencesMgr.Instance.NextOpenWheelStampTime =
GameHelper.GetNowTime() + GameHelper.GetCommonModel().wheelTimes[1];
PreferencesMgr.Instance.ThisDayWatchSlyderVideoNum++;
UpdateTime();
refreshData();
});
}
private void UpdateTime()
{
if (PreferencesMgr.Instance.ThisDayWatchSlyderVideoNum >= GameHelper.GetCommonModel().wheelTimes[0])
{
DateTime currentTime = DateTime.Now;
ui.spin.cont_state.selectedIndex = btn_go.State_Limit;
ui.spin.touchable = false;
ui.spin.enabled = false;
ui.spin.cont_spin.selectedIndex = btn_go.Spin_grey;
}
else
{
if (GameHelper.GetNowTime() >= PreferencesMgr.Instance.NextOpenWheelStampTime)
{
ui.spin.touchable = true;
ui.spin.enabled = true;
ui.spin.cont_spin.selectedIndex = btn_go.Spin_none;
ui.spin.cont_state.selectedIndex = btn_go.State_None;
}
else
{
ui.spin.touchable = false;
ui.spin.enabled = false;
ui.spin.cont_spin.selectedIndex = btn_go.Spin_grey;
ui.spin.cont_state.selectedIndex = btn_go.State_Video;
}
ui.spin.text_time.text = model.NextOpenWheelTimeStr;
}
}
}
}