475 lines
15 KiB
C#
475 lines
15 KiB
C#
// using FGUI.A000_common;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using DG.Tweening;
|
|
using FairyGUI;
|
|
using FGUI.Common_01;
|
|
using FGUI.Turntable_11;
|
|
using IgnoreOPS;
|
|
using Spine.Unity;
|
|
using UnityEngine;
|
|
|
|
namespace ChillConnect
|
|
{
|
|
public class WheelViewUI : BaseUI
|
|
{
|
|
private WheelViewUICtrl ctrl;
|
|
private WheelViewModel model;
|
|
private readonly int[] vidieWeight = new int[12];
|
|
private TurntableModel turntableData;
|
|
|
|
private List<com_coin> ItemList = new();
|
|
private bool isClickSpin;
|
|
private bool isClickAbleWatchAD = true;
|
|
|
|
// private SkeletonAnimation turnAnim;
|
|
private SkeletonAnimation awardAnim;
|
|
private Action closeCallback;
|
|
|
|
|
|
private FGUI.Turntable_11.com_wheel ui;
|
|
|
|
public WheelViewUI(WheelViewUICtrl ctrl) : base(ctrl)
|
|
{
|
|
uiName = UIConst.WheelViewUI;
|
|
this.ctrl = ctrl;
|
|
}
|
|
|
|
protected override void SetUIInfo(UIInfo uiInfo)
|
|
{
|
|
uiInfo.packageName = "Turntable_11";
|
|
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;
|
|
|
|
GameHelper.showGameUI = true;
|
|
}
|
|
|
|
protected override void OnBind()
|
|
{
|
|
ui = baseUI as FGUI.Turntable_11.com_wheel;
|
|
}
|
|
|
|
protected override void OnOpenBefore(object args)
|
|
{
|
|
// if (Screen.safeArea.y != 0)
|
|
// {
|
|
// // ui..y += Screen.safeArea.y;
|
|
// }
|
|
|
|
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);
|
|
ItemList.Add(disc.award9);
|
|
ItemList.Add(disc.award10);
|
|
ItemList.Add(disc.award11);
|
|
ItemList.Add(disc.award12);
|
|
|
|
HallManager.Instance.UpdateSecondEvent += UpdateTime;
|
|
|
|
turntableData = ConfigSystem.GetConfig<TurntableModel>();
|
|
|
|
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;
|
|
|
|
// 更新最后检查的日期并保存到PlayerPrefs
|
|
_lastCheckDate = currentDate;
|
|
|
|
SaveLastCheckDate();
|
|
}
|
|
}
|
|
|
|
//初始化页面逻辑
|
|
private void InitView()
|
|
{
|
|
for (var i = 0; i < ItemList.Count; i++)
|
|
{
|
|
vidieWeight[i] = turntableData.DataList[i].weight;
|
|
}
|
|
ui.disc.rotation = 0;
|
|
ui.btn_spin.SetClick(SpineAnim);
|
|
|
|
ui.btn_close.SetClick(() =>
|
|
{
|
|
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;
|
|
|
|
item.text_num.text = "x" + (id == 0 ? GameHelper.Get101Str((decimal)quantity) : quantity.ToString());
|
|
|
|
setItemUrl(item.item_icon, id, (int)quantity);
|
|
}
|
|
|
|
|
|
var times = DataMgr.ThisDayWatchSlyderVideoNum.Value;
|
|
var limits = GameHelper.GetCommonModel().wheelTimes[0];
|
|
ui.text_spin.SetVar("times", times.ToString()).FlushVars();
|
|
ui.text_spin.SetVar("limits", limits.ToString()).FlushVars();
|
|
|
|
}
|
|
|
|
public string GetIndex(int quantity)
|
|
{
|
|
// 验证输入是否为有效数值
|
|
if (quantity < 0)
|
|
{
|
|
throw new ArgumentException("Quantity must be a non-negative integer.");
|
|
}
|
|
|
|
// 使用 switch 表达式明确处理边界条件
|
|
return quantity switch
|
|
{
|
|
<= 80 => "1",
|
|
> 80 and <= 150 => "2",
|
|
> 150 => "3",
|
|
};
|
|
}
|
|
|
|
void setItemUrl(GLoader loader, int urltype, int quantity)
|
|
{
|
|
if (urltype == 0)
|
|
{
|
|
string idx = GetIndex(quantity);
|
|
|
|
loader.url = $"ui://Turntable_11/spin_gold{idx}";
|
|
}
|
|
else if (urltype == 1) loader.url = "ui://Common_01/spin_remove";
|
|
else if (urltype == 2) loader.url = "ui://Common_01/spin_undo";
|
|
else if (urltype == 3) loader.url = "ui://Common_01/spin_refresh";
|
|
// if(urltype > 0) loader.SetScale(0.7f, 0.7f);
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
if (isClickAbleWatchAD)
|
|
{
|
|
isClickAbleWatchAD = false;
|
|
|
|
GameHelper.ShowVideoAd("reward_luckySpin", isSuccess =>
|
|
{
|
|
if (isSuccess)
|
|
{
|
|
Spin();
|
|
}
|
|
|
|
isClickAbleWatchAD = true;
|
|
});
|
|
}
|
|
}
|
|
|
|
void hideAllLight()
|
|
{
|
|
for (int i = 0; i < ItemList.Count; i++)
|
|
{
|
|
ItemList[i].light.visible = false;
|
|
ItemList[i].light1.visible = false;
|
|
ItemList[i].light_anim.visible = false;
|
|
}
|
|
}
|
|
|
|
private void Spin()
|
|
{
|
|
// normalAnim.SetActive(false);
|
|
|
|
if (awardAnim != null)
|
|
{
|
|
// 停止之前的动画并释放资源
|
|
awardAnim.state.ClearTracks();
|
|
awardAnim = null;
|
|
}
|
|
|
|
hideAllLight();
|
|
|
|
isClickSpin = true;
|
|
ui.btn_close.touchable = false;
|
|
ui.btn_close.grayed = false;
|
|
|
|
ui.btn_spin.touchable = false;
|
|
|
|
var index = CommonHelper.GetIndexByChanceList(vidieWeight);
|
|
AudioManager.Instance.PlayDynamicEffect(AudioConst.wheel_spin);
|
|
var data = turntableData.DataList[index];
|
|
Debug.Log("spin index=== : " + index);
|
|
int allNum = ItemList.Count * 6 + index;
|
|
int itemCount = ItemList.Count;
|
|
float[] timess = (float[])ReceivePlanes(allNum);
|
|
|
|
float totalTimes = timess.Last();
|
|
for (int i = 0; i < allNum; i++)
|
|
{
|
|
int currentIndex = i % itemCount;
|
|
float time = timess[i];
|
|
|
|
DOVirtual.DelayedCall(time, () =>
|
|
{
|
|
int selectI = currentIndex + 1;
|
|
if (currentIndex + 1 > itemCount - 1)
|
|
{
|
|
selectI = 0;
|
|
}
|
|
ItemList[selectI].light.visible = true;
|
|
ItemList[selectI].light1.visible = true;
|
|
|
|
ItemList[currentIndex].light.visible = false;
|
|
ItemList[currentIndex].light1.visible = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
ResultTween = DOVirtual.DelayedCall(totalTimes, () => ReceivePlane(data, index));
|
|
|
|
}
|
|
|
|
private Array ReceivePlanes(int nums)
|
|
{
|
|
float start = 0.25f;
|
|
float end = 0.06f;
|
|
float delta = 0.02f;
|
|
float lastDelta = 0.1f;
|
|
|
|
float delay = start;
|
|
float[] sum = new float[nums];
|
|
for (int i = 0; i < nums; i++)
|
|
{
|
|
if (i == 0)
|
|
{
|
|
sum[i] = delay;
|
|
}
|
|
else
|
|
{
|
|
sum[i] = sum[i - 1] + delay;
|
|
}
|
|
|
|
if (delay > end)
|
|
{
|
|
delay -= delta;
|
|
}
|
|
else
|
|
{
|
|
delay = end;
|
|
}
|
|
|
|
//后8个间隔变慢
|
|
if (i >= nums - 8)
|
|
{
|
|
sum[i] += lastDelta;
|
|
}
|
|
}
|
|
|
|
return sum;
|
|
}
|
|
|
|
private void ReceivePlane(Turntable vo, int index)
|
|
{
|
|
ItemList[index].light1.visible = false;
|
|
|
|
ItemList[index].light_anim.visible = true;
|
|
awardAnim = FXManager.Instance.SetFx<SkeletonAnimation>(ItemList[index].light_anim, Fx_Type.fx_wheel, ref closeCallback);
|
|
awardAnim.state.SetAnimation(0, "animation", true);
|
|
|
|
DOVirtual.DelayedCall(1.5f, () =>
|
|
{
|
|
isClickSpin = false;
|
|
ResultTween = null;
|
|
ui.btn_close.touchable = true;
|
|
ui.btn_close.grayed = false;
|
|
|
|
ui.btn_spin.cont_spin.selectedIndex = btn_go1.Spin_grey;
|
|
|
|
ui.btn_spin.cont_state.selectedIndex = btn_go1.State_Video;
|
|
|
|
var id = vo.wheel_item;
|
|
var quantity = vo.quantity;
|
|
Debug.Log($"barry ReceivePlane===: {id} {quantity}");
|
|
if (id == 0)
|
|
{
|
|
var startPoint = GameHelper.GetUICenterPosition(ItemList[index]);
|
|
var endPoint = GameHelper.GetUICenterPosition(ui.point);
|
|
|
|
var rewardData = new RewardData();
|
|
var rewardSingleData = new RewardSingleData(101, (decimal)quantity, RewardOrigin.LuckyWheel, index)
|
|
{
|
|
startPosition = startPoint,
|
|
endPosition = new Vector2(endPoint.x - 150, endPoint.y - 136),
|
|
};
|
|
rewardData.AddReward(rewardSingleData);
|
|
rewardData.displayType = RewardDisplayType.RewardFly | RewardDisplayType.Dialog |
|
|
RewardDisplayType.ValueChange;
|
|
rewardData.AddCompleted((isScu) =>
|
|
{
|
|
|
|
});
|
|
GameDispatcher.Instance.Dispatch(GameMsg.GetReward, rewardData);
|
|
}
|
|
else
|
|
{
|
|
GameHelper.AddItemNumber(id - 1, (int)quantity);
|
|
GameHelper.ShowTips("Successfully received");
|
|
}
|
|
|
|
DataMgr.NextOpenWheelStampTime.Value =
|
|
GameHelper.GetNowTime() + GameHelper.GetCommonModel().wheelTimes[1];
|
|
DataMgr.ThisDayWatchSlyderVideoNum.Value++;
|
|
|
|
UpdateTime();
|
|
refreshData();
|
|
});
|
|
}
|
|
|
|
private void UpdateTime()
|
|
{
|
|
if (DataMgr.ThisDayWatchSlyderVideoNum.Value >= GameHelper.GetCommonModel().wheelTimes[0])
|
|
{
|
|
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;
|
|
ui.btn_spin.img_saveingpot.visible = false;
|
|
}
|
|
else
|
|
{
|
|
if (GameHelper.GetNowTime() >= DataMgr.NextOpenWheelStampTime.Value)
|
|
{
|
|
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;
|
|
if (GameHelper.IsGiftSwitch() && ConfigSystem.GetConfig<CommonModel>().PiggyBankSwitch == 1)
|
|
{
|
|
ui.btn_spin.img_saveingpot.visible = true;
|
|
}
|
|
else
|
|
{
|
|
ui.btn_spin.img_saveingpot.visible = false;
|
|
}
|
|
}
|
|
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;
|
|
ui.btn_spin.img_saveingpot.visible = false;
|
|
}
|
|
|
|
ui.btn_spin.text_time.text = model.NextOpenWheelTimeStr;
|
|
}
|
|
}
|
|
|
|
}
|
|
} |