Files
BingoGrassland/Assets/BingoBrain/ModuleUI/BingoStart/BingoStartUI.cs
T
2026-04-20 13:49:36 +08:00

736 lines
26 KiB
C#

using System;
using FairyGUI;
using UnityEngine;
using BingoBrain.Core;
using DG.Tweening;
using BingoBrain.HotFix;
using FGUI.JBingoPlay;
using System.Collections.Generic;
using Random = UnityEngine.Random;
using FGUI.ACommon;
using Spine.Unity;
namespace BingoBrain
{
public class BingoStartUI : BaseUI
{
private BingoStartUICtrl ctrl;
private BingoStartModel model;
public com_play ui;
private com_AddBall com_Add;
private Action CloseCb;
private GTweener ballonTweenr;
private List<com_Num> poolComNum = new();
private List<com_Num> showComNum = new();
private List<Vector2> showComNumPot = new();
private bool isInited;
private Tween energyTween;
private float moveTime = 3;
private bool isLeft = true;
private Tween waitTween;
private bool isMoveFinish = true;
private GameObject ballIdle;
private GameObject ballEnter;
private int click_number = -1;
private bool IsBallonCD => GameHelper.GetNowTime() < PreferencesMgr.Instance.BallonCdTime;
public BingoStartUI(BingoStartUICtrl ctrl) : base(ctrl)
{
uiName = UIConst.BingoStartUI;
this.ctrl = ctrl;
}
protected override void SetUIInfo(UIInfo uiInfo)
{
uiInfo.packageName = "JBingoPlay";
uiInfo.assetName = "com_play";
uiInfo.layerType = UILayerType.Normal;
uiInfo.isNeedOpenAnim = false;
uiInfo.isNeedCloseAnim = false;
}
#region
protected override void OnInit()
{
model = ModuleBoardk.GetModel(ModelConst.BingoStartModel) as BingoStartModel;
}
protected override void OnClose()
{
}
protected override void OnBind()
{
ui = baseUI as com_play;
}
private bool is_safearea = false;
protected override void OnOpenBefore(object args)
{
if (Screen.safeArea.y != 0 && !is_safearea)
{//刘海屏
ui.group_.y += Screen.safeArea.y;
is_safearea = true;
}
Audio.Instance.StopBGM();
click_number = 0;
ui.btn_star.icon_image.fillAmount = 0;
ui.btn_star.progress_text.text = "0/3";
ui.btn_star.progress.width = 0;
if (isInited)
{
return;
}
InitData();
InitView();
}
private void InitData()
{
isInited = true;
Hall.Instance.SetGaming(true);
model.show101 = PreferencesMgr.Instance.Currency101;
model.show102 = PreferencesMgr.Instance.Currency102;
poolComNum.Clear();
showComNum.Clear();
poolComNum.Add(ui.com_CallNum.com_Num1);
poolComNum.Add(ui.com_CallNum.com_Num2);
poolComNum.Add(ui.com_CallNum.com_Num3);
poolComNum.Add(ui.com_CallNum.com_Num4);
poolComNum.Add(ui.com_CallNum.com_Num5);
showComNumPot.Add(ui.com_CallNum.com_Num5.position);
showComNumPot.Add(ui.com_CallNum.com_Num4.position);
showComNumPot.Add(ui.com_CallNum.com_Num3.position);
showComNumPot.Add(ui.com_CallNum.com_Num2.position);
showComNumPot.Add(ui.com_CallNum.com_Num1.position);
Vector3 localPos = ui.com_prop.size / 2;
localPos += ui.com_prop.position;
BingoCell.propOriginPos = GRoot.inst.LocalToGlobal(localPos);
BingoCell.propOriginPos = CameraBoardk.Instance.FGUIPosToWorldPos(BingoCell.propOriginPos);
isShowGameOver = false;
BingoCell.GetCoinSum = 0;
BingoCell.GetCashSum = 0;
}
private void InitView()
{
Set101();
Set102();
if (GameHelper.IsGiftSwitch())
{
(ui.btn_cash as com_102).gift.selectedIndex = 1;
(ui.btn_ballon as btn_balloon).gift.selectedIndex = 1;
}
else
{
ui.btn_star.visible = false;
}
GameHelper.SetGObject("btn_prop", ui.com_prop);
FX.Instance.SetFx<ParticleSystem>(ui.com_AddBall.gp_fx, Fx_Type.fx_ball_enter, ps => { }, CloseCb);
MoveToOtherSide();
Hall.Instance.UpdateSecondEvent += UpdateSecond;
ui.touchable = false;
ui.com_prop.visible = !BingoCell.isFirstGame;
// ui.btn_close.visible = !BingoData.isFirstGame;
ui.btn_close.SetClick(OnBtnCloseClick);
ui.com_carddi.cont_card.selectedIndex = com_carddi.Card_keySum_0;
ui.com_AddBall.visible = false;
ui.fairyBatching = false;
ui.btn_ballon.visible = !IsBallonCD;
ui.btn_ballon.SetClick(OnClickBalloon);
if (ballEnter == null)
{
var effect = Battle.Instance.ShungTik.Get("Effect.spark.ballEffect", "ballEffect");
ballEnter = effect.transform.Find("fx_qiu_enter").gameObject;
ballIdle = effect.transform.Find("fx_qiu_idle").gameObject;
effect.transform.localScale = 100 * Vector3.one;
var wrapper = new GoWrapper();
wrapper.SetWrapTarget(effect, true);
ui.com_prop.gh_effect.SetNativeObject(wrapper);
}
SetIdleEffect();
ui.com_CallNum.btn_Speed.text = "X" + BingoCell.CallSpeed;
ui.com_CallNum.btn_Speed.SetClick(OnClickCallSpeed);
SetEnergy();
InitStartGameEvent();
RefreshUI();
}
private void OnClickCallSpeed()
{
Audio.Instance.PlayDynamicEffect("button");
BingoCell.CallSpeed = BingoCell.CallSpeed switch
{
1 => 2,
2 => 3,
_ => 1
};
}
private void InitStartGameEvent()
{
Sequence sequence = DOTween.Sequence();
sequence.Append(DOVirtual.DelayedCall(0.5f, () =>
{
Audio.Instance.StopBGM();
ui.fx_readygo.SetHook("Ready", () => { Audio.Instance.PlayDynamicEffect("ready_Ready"); });
ui.fx_readygo.SetHook("Go", () => { Audio.Instance.PlayDynamicEffect("ready_Go"); });
ui.fx_readygo.Play();
}).SetAutoKill());
sequence.Append(DOVirtual.DelayedCall(ui.fx_readygo.totalDuration, () =>
{
Audio.Instance.PlayBGM("bgm_play");
if (BingoCell.isFirstGame)
{
var pos = NNfds.WorldToUIPos(BingoCell.cardBoardList[0].cardList[0].Game
.gameObject);
GameHelper.SetGuidePos("third", pos);
}
else
{
GameHelper.SetGuidePos("fifth", ui.com_prop);
}
ui.touchable = true;
}).SetAutoKill());
sequence.Append(DOVirtual.DelayedCall(Time.deltaTime, () =>
{
// 开始叫号
gameDispatcher.Dispatch(BingoInfo.StartCallNum);
}).SetAutoKill());
}
#region
private void OnClickBalloon()
{
if (BingoCell.isProcedure || BingoCell.IsGuiding || BingoCell.isPropRewarding)
{
return;
}
Audio.Instance.PlayDynamicEffect("button");
GameHelper.GetVideo("reward_flyballoon", isSuccess =>
{
if (isSuccess)
{
ui.btn_ballon.touchable = false;
var rewardType = GameHelper.GetCommonModel().ballonRewardType[0];
double rewardCount = 0;
if (rewardType == 102)
{
rewardCount =
GameHelper.GetDynamicReward(rewardType, GameHelper.GetCommonModel().ballonReward102);
}
ui.btn_ballon.visible = false;
PreferencesMgr.Instance.BallonCdTime =
(int)(GameHelper.GetNowTime() + GameHelper.GetCommonModel().ballonCD);
GameHelper.GetRewardOnly(rewardType, (decimal)rewardCount, RewardOrigin.PlayBallon,
isSuccess => { ui.btn_ballon.touchable = true; }, ui.btn_ballon);
}
});
}
void MoveToOtherSide()
{
if (!ui.btn_ballon.visible)
{
return;
}
if (!isMoveFinish)
{
return;
}
float offset = 300;
isMoveFinish = false;
var btnBalloon = ui.btn_ballon.displayObject.gameObject.transform;
var sequence = DOTween.Sequence();
var pos1 = new Vector3(ui.left_top.x, ui.left_top.y - RandomKit.RandomRange(30, 100));
var posLocal1 = GameHelper.FguiToUnityLocalPot(pos1);
ui.btn_ballon.position = pos1;
var pos2 = new Vector3(ui.left_bottom.x, BingoCell.CenterUIPos.y + offset + RandomKit.RandomRange(200, 300));
var posLocal2 = GameHelper.FguiToUnityLocalPot(pos2);
var tw1 = btnBalloon.DOLocalMove(posLocal2, 3).SetEase(Ease.Linear);
sequence.Append(tw1);
var pos3 = new Vector3(ui.right_top.x, ui.right_top.y - RandomKit.RandomRange(30, 100));
var posLocal3 = GameHelper.FguiToUnityLocalPot(pos3);
var tw2 = btnBalloon.DOLocalMove(posLocal3, 3);
tw2.SetDelay(Random.Range(5, 7)).SetEase(Ease.Linear);
sequence.Append(tw2);
var pos4 = new Vector3(ui.right_bottom.x,
BingoCell.CenterUIPos.y + offset + RandomKit.RandomRange(200, 300));
var posLocal4 = GameHelper.FguiToUnityLocalPot(pos4);
var tw3 = btnBalloon.DOLocalMove(posLocal4, 3);
tw3.SetDelay(Random.Range(3, 5)).SetEase(Ease.Linear);
sequence.Append(tw3);
var tw4 = btnBalloon.DOLocalMove(posLocal1, 3);
tw4.SetDelay(Random.Range(5, 11)).SetEase(Ease.Linear);
sequence.Append(tw4);
var tw5 = DOVirtual.DelayedCall(Random.Range(5, 11), () => { });
sequence.Append(tw5);
sequence.OnComplete(() =>
{
isMoveFinish = true;
ui.btn_ballon.InvalidateBatchingState();
MoveToOtherSide();
});
}
private void UpdateSecond()
{
if (ui.btn_ballon.visible != !IsBallonCD)
{
ui.btn_ballon.visible = !IsBallonCD;
// 开始移动
if (ui.btn_ballon.visible)
{
MoveToOtherSide();
}
}
}
#endregion
void SetIdleEffect(bool isIdle = true)
{
ballIdle.SetActive(isIdle);
ballEnter.SetActive(!isIdle);
}
protected override void OnOpen(object args)
{
ui?.FadeIn();
}
private void OnBtnCloseClick()
{
if (BingoCell.isProcedure)
{
return;
}
if (!BingoCell.IsInGame)
{
return;
}
Audio.Instance.PlayDynamicEffect("button");
uiCtrlDispatcher.Dispatch(SkinInfo.LeaveBingoUI_Open);
}
void SetEnergy()
{
if (BingoCell.isPropRewarding)
{
return;
}
var originFillAmount = ui.com_prop.img_prg.fillAmount;
if (energyTween != null && energyTween.active)
{
energyTween?.Kill();
}
energyTween = DOVirtual.Float(originFillAmount, BingoCell.EnergyPrg, 0.5f,
prg => { ui.com_prop.img_prg.fillAmount = prg; });
}
private void CallNum(object obj)
{
RefreshUI();
var sum = (int)obj;
var item = GetComNum();
item.visible = true;
item.scale = Vector2.one;
item.alpha = 1;
// item.position = new Vector2(5, -140);
item.displayObject.gameObject.transform.localPosition = new Vector3(5, -140);
var localPos = GameHelper.FguiToUnityLocalPot(showComNumPot[4]);
item.displayObject.gameObject.transform.DOLocalMoveX(localPos.x, aniTime).SetEase(Ease.Linear);
item.displayObject.gameObject.transform.DOLocalMoveY(localPos.y, aniTime).SetEase(Ease.Linear);
// item.TweenMove(showComNumPot[4], aniTime);
item.text_num.text = GameHelper.GetNoDecimalUnitStr(sum);
item.cont_state.selectedIndex = (sum - 1) / 15;
for (var i = 0; i < showComNum.Count; i++)
{
var _Num = showComNum[i];
var index = i + (4 - showComNum.Count);
// _Num.TweenMove(showComNumPot[index], aniTime);
_Num.displayObject.gameObject.transform.DOLocalMoveX(showComNumPot[index].x, aniTime)
.SetEase(Ease.Linear);
if (i == 0 && showComNum.Count >= 4)
{
DOVirtual.Float(1, 0.6f, aniTime, e => { _Num.alpha = e; }).SetAutoKill();
}
if (index == 3)
{
DOVirtual.Float(1, 0.8f, aniTime, e => { _Num.scale = Vector2.one * e; }).SetAutoKill();
}
}
showComNum.Add(item);
}
private com_Num GetComNum()
{
com_Num item;
if (poolComNum.Count <= 0)
{
item = showComNum[0];
showComNum.RemoveAt(0);
}
else
{
item = poolComNum[0];
poolComNum.RemoveAt(0);
}
return item;
}
protected override void OnHide()
{
isInited = false;
ui?.FadeOut();
foreach (var comNum in showComNum)
{
comNum.visible = false;
poolComNum.Add(comNum);
}
Hall.Instance.SetGaming(false);
OnClearTween();
showComNum.Clear();
CloseCb?.Invoke();
Hall.Instance.UpdateSecondEvent -= UpdateSecond;
}
protected override void OnDisplay(object args)
{
OnOpenBefore(args);
OnOpen(args);
}
private void RefreshUI(object o = null)
{
ui.com_CallNum.btn_Speed.text_Speed.text = BingoCell.CallSpeed + "X";
ui.com_ballleft.text_numLeft.text =
GameHelper.GetNoDecimalUnitStr(BingoCell.MaxCallSum - BingoCell.calledList.Count);
var num = Math.Min(3, BingoCell.KeyCardSum);
ui.com_carddi.cont_card.selectedIndex = num;
}
#endregion
#region
protected override void AddListener()
{
uiCtrlDispatcher.AddListener(SkinInfo.CallEndUI_Close, RefreshUI);
gameDispatcher.AddListener(BingoInfo.CallNum, CallNum);
gameDispatcher.AddListener(BingoInfo.CallSpeedChange, RefreshUI);
gameDispatcher.AddListener(BingoInfo.StartBingoGame, OnStartBingoGame);
gameDispatcher.AddListener(BingoInfo.SelectOneNum, OnSelectOneCard);//点击
gameDispatcher.AddListener(BingoInfo.AddPropRewardFinish, OnAddPropRewardFinish);
gameDispatcher.AddListener(BingoInfo.StartFullEnergy, OnStartFullEnergy);
gameDispatcher.AddListener(BingoInfo.ShowGameOver, OnEndBingoGame);
gameDispatcher.AddListener(BingoInfo.KeyCardSumChane, RefreshUI);
gameDispatcher.AddListener(BingoInfo.AddBallSum, AddBallSum);
}
private void OnStartBingoGame(object obj)
{
// RefreshUI();
}
private bool isShowGameOver = false;
private void OnEndBingoGame(object obj)
{
if (isShowGameOver)
{
return;
}
isShowGameOver = true;
ui.fx_gameover.Stop();
Audio.Instance.PlayDynamicEffect("gameover");
ui.fx_gameover.Play(() =>
{
UICtrlDispatcher.Instance.Dispatch(SkinInfo.BingoEndUI_Open);
isShowGameOver = false;
CtrlCloseUI();
});
}
private void OnStartFullEnergy(object obj)
{
var type = (int)obj;
ui.com_prop.cont_prop.selectedIndex = type + 1;
SetIdleEffect(false);
}
private void OnAddPropRewardFinish(object obj)
{
ui.com_prop.cont_prop.selectedIndex = ui.com_prop._Prop_normal;
DOVirtual.Float(1, 0, 0.2f, prg => { ui.com_prop.img_prg.fillAmount = prg; }).OnComplete(() =>
{
SetIdleEffect();
SetEnergy();
}).SetAutoKill();
}
private SkeletonAnimation cardSpine;
private void OnSelectOneCard(object obj)//点击事件
{
click_number++;
Debug.Log(click_number);
if (GameHelper.IsGiftSwitch() && click_number >= 3)
{
Audio.Instance.PlayDynamicEffect("star");
click_number = 0;
//uiCtrlDispatcher.Dispatch(SkinInfo.StarRewardUI_Open);
if (cardSpine == null)
{
FX.Instance.SetFx<SkeletonAnimation>(ui.spine_parent, Fx_Type.spine_starreward, sk =>
{
cardSpine = sk;
NAAVsa.PlayAnim(cardSpine, "b", false);
// NAAVsa.AddCompleteEvent(cardSpine,(sk)=>{
// });
GTweener tweener1 = ui.spine_parent.TweenMove(GameHelper.GetUICenterPosition(ui), 0.75f).OnComplete(() =>
{
uiCtrlDispatcher.Dispatch(SkinInfo.StarRewardUI_Open);
ui.spine_parent.x = ui.btn_star.x;
ui.spine_parent.y = ui.btn_star.y;
}); // 位置从当前值渐变到新的坐标
tweener1.SetEase(EaseType.QuadOut);
// NAAVsa.AddCompleteEvent(cardSpine, OnChangeCardFinish);
// OnChangeCardFinish(null);
}, CloseCb);
}
else
{
NAAVsa.PlayAnim(cardSpine, "b", false);
// NAAVsa.AddCompleteEvent(cardSpine,(sk)=>{
// });
GTweener tweener1 = ui.spine_parent.TweenMove(GameHelper.GetUICenterPosition(ui), 0.75f).OnComplete(() =>
{
uiCtrlDispatcher.Dispatch(SkinInfo.StarRewardUI_Open);
ui.spine_parent.x = ui.btn_star.x;
ui.spine_parent.y = ui.btn_star.y;
}); // 位置从当前值渐变到新的坐标
tweener1.SetEase(EaseType.QuadOut);
}
}
ui.btn_star.icon_image.fillAmount = (float)click_number / 3;
ui.btn_star.progress_text.text = click_number + "/3";
ui.btn_star.progress.width = ((float)click_number / 3) * 138;
SetEnergy();
}
private float aniTime = 0.3f;
private void AddBallSum(object o)
{
var sum = (int)o;
// 第一段出现时间
var showTime = 0.4f;
// 等待时间
var IdleTime = 0.5f;
// 第二段飞行时间
var moveTime = 0.3f;
// 球飞行间隔
var dleFloat = 0.1f;
ui.com_AddBall.visible = true;
var sys = ui.LocalToGlobal(ui.com_ballleft.position + (Vector3)ui.com_ballleft.size / 2);
var tar = ui.com_AddBall.GlobalToLocal(sys);
GameDispatcher.Instance.Dispatch(BingoInfo.AddPause, 1);
Audio.Instance.PlayDynamicEffect("extraBall_show");
for (var i = 0; i < 5; i++)
{
var item = ui.com_AddBall.GetChildAt(i + 1);
item.visible = false;
item.alpha = 1;
var index = i;
if (sum > index)
{
item.visible = true;
Vector2 startPot = item.position;
item.position = ui.com_AddBall.size / 2;
item.scale = Vector2.zero;
DOVirtual.DelayedCall(index * dleFloat, () =>
{
item.TweenMove(startPot, showTime);
DOVirtual.Float(0.3f, 1, showTime, e => { item.scale = Vector2.one * e; }).OnComplete(() =>
{
DOVirtual.DelayedCall(IdleTime, () =>
{
DOVirtual.Float(1, 0.6f, moveTime, e =>
{
item.scale = Vector2.one * e;
item.alpha = e;
}).SetAutoKill();
DOVirtual.Float(1, 0.3f, moveTime / 2, e => { item.scale = Vector2.one * e; })
.SetAutoKill();
item.TweenMove(tar, moveTime).OnComplete(() =>
{
BingoCell.MaxCallSum += 1;
if (index == 0)
{
GameDispatcher.Instance.Dispatch(BingoInfo.AddPause, -1);
}
RefreshUI();
item.position = startPot;
item.visible = false;
if (sum == index + 1)
{
ui.com_AddBall.visible = false;
}
});
}).SetAutoKill();
}).SetAutoKill();
});
/*DOVirtual.DelayedCall(index * dleFloat, () =>
{
item.TweenMove(startPot, showTime);
DOVirtual.Float(0.3f, 1, showTime, e => { item.scale = Vector2.one * e; }).OnComplete(() =>
{
DOVirtual.DelayedCall(IdleTime, () =>
{
DOVirtual.Float(1, 0.6f, moveTime, e =>
{
item.scale = Vector2.one * e;
item.alpha = e;
}).SetAutoKill();
DOVirtual.Float(1, 0.3f, moveTime / 2, e => { item.scale = Vector2.one * e; })
.SetAutoKill();
item.TweenMove(tar, moveTime).OnComplete(() =>
{
BingoData.MaxCallSum += 1;
RefreshUI();
item.position = startPot;
item.visible = false;
if (index == 0)
{
GameDispatcher.Instance.Dispatch(GameMsg.AddPause, -1);
}
if (sum == index + 1)
{
ui.com_AddBall.visible = false;
}
});
}).SetAutoKill();
}).SetAutoKill();
}).SetAutoKill();*/
}
}
}
protected override void RemoveListener()
{
uiCtrlDispatcher.RemoveListener(SkinInfo.CallEndUI_Close, RefreshUI);
gameDispatcher.RemoveListener(BingoInfo.CallNum, CallNum);
gameDispatcher.RemoveListener(BingoInfo.CallSpeedChange, RefreshUI);
gameDispatcher.RemoveListener(BingoInfo.SelectOneNum, OnSelectOneCard);
gameDispatcher.RemoveListener(BingoInfo.AddPropRewardFinish, OnAddPropRewardFinish);
gameDispatcher.RemoveListener(BingoInfo.StartFullEnergy, OnStartFullEnergy);
gameDispatcher.RemoveListener(BingoInfo.ShowGameOver, OnEndBingoGame);
gameDispatcher.RemoveListener(BingoInfo.KeyCardSumChane, RefreshUI);
gameDispatcher.RemoveListener(BingoInfo.AddBallSum, AddBallSum);
}
#endregion
public void Set101(string coinStr = null)
{
if (coinStr == null)
{
coinStr = PreferencesMgr.Instance.Currency101 == -1
? GameHelper.GetCommonModel().Init101Num.ToString("N0")
: PreferencesMgr.Instance.Currency101.ToString("N0");
}
// 房间券余额 数值
ui.btn_coin.GetChild("title").text = coinStr;
}
public void Set102(string cashStr = null)
{
if (cashStr == null)
{
cashStr = PreferencesMgr.Instance.Currency102 == -1
? GameHelper.GetCommonModel().Init102Num.ToString("N")
: PreferencesMgr.Instance.Currency102.ToString("N");
}
// 房间券余额 数值
ui.btn_cash.GetChild("title").text = cashStr;
(ui.btn_ballon as btn_balloon).cash_text.text = GameHelper.GetDynamicReward(102, GameHelper.GetCommonModel().ballonReward102).ToString("0.00");
}
private void OnClearTween()
{
ballonTweenr?.Kill();
ballonTweenr = null;
}
}
}