Files
JJBB/Assets/Project/Script/LuaScripts/UI/SuperBenefitFirstRechargeTip.cs

448 lines
13 KiB
C#
Raw Normal View History

2024-08-23 15:49:34 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using GCGame.Table;
using Module.Log;
// 原为超值首冲活动提示
// 现为一种活动的mini提示工具需要活动提示的信息会成为队列信息依次显示。
// 直到所有信息显示完毕,界面关闭;新的活动类型信息传入时,重新显示
// 一旦一个活动的信息显示过,后续不再显示该类型。
// 若存在多个信息存于队列中,点击关闭按钮会显示后一个,而不是全部关闭。
public class SuperBenefitFirstRechargeTip : MonoBehaviour {
public Button closeBtn; // 关闭按钮
public Button rechargeBtn; // 充值按钮,点击跳转充值界面
public Button bgBtn; // 背景作为按钮,点击跳转到超值首冲活动界面
public UICameraTexture model; // 模型
// 在该活动中resImg和协议的iconPath的安排如下
// 0背景
// 1标题
// 2关闭按钮
// 3描述
// 4充值/跳转到活动描述
public Image[] resImg = new Image[5]; // 资源素材
private Queue<MarketingNewPayTip> tipQueues; // 消息队列
private int curActId; // 当前活动id
private int curEntranceId; // 活动入口ID
private static List<int> actList = new List<int>();
public static bool IsActTipsExist(int actID)
{
if(actList.Contains(actID))
{
return true;
}
else
{
actList.Add(actID);
return false;
}
}
public RectTransform animStartAnchor; // 该组件是动画的上一层节点,用于控制动画的初始位置
private Vector3 oriPos; // 记录原始位置,如果找不到目标位置,则使用这个。
private enum Side
{
left,
right
}
private Side leftOrRightAnim = Side.right; // 使用左侧还是右侧动画,-1 左侧1 右侧
///// <summary>
///// 判断该活动的提示信息是否能被显示
///// </summary>
///// <param name="actID">活动入口ID</param>
///// <returns></returns>
//public static bool IsTipCanShow(int actID)
//{
// // 不合法活动ID 或 已显示过的不再显示
// if(actID < 0 || finishTips.Contains(actID))
// {
// return false;
// }
// return true;
//}
private static SuperBenefitFirstRechargeTip instance;
public static SuperBenefitFirstRechargeTip Instance
{ get { return instance; } }
public void Awake()
{
if(instance == null)
{
instance = this;
oriPos = animStartAnchor.position;
rechargeBtn.onClick.AddListener(OnRechargeBtnClick);
closeBtn.onClick.AddListener(Close);
bgBtn.onClick.AddListener(OnBgBtnClick);
tipQueues = new Queue<MarketingNewPayTip>();
curActId = -1;
curEntranceId = -100;
}
}
private void OnDestroy()
{
instance = null;
}
private void Close()
{
FinishOne();
}
private void OnEnable()
{
}
#region
public void ShowInfo(object packet)
{
MarketingNewPayTip data = packet as MarketingNewPayTip;
if(data != null)
{
if (tipQueues.Count <= 0)
{
tipQueues.Enqueue(data);
StartCoroutine("ShowHeadTips");
}
else
{
tipQueues.Enqueue(data);
}
}
}
private void FinishOne()
{
if (curActId != -1)
{
//if (!finishTips.Contains(curActId))
//{
// finishTips.Add(curActId);
//}
tipQueues.Dequeue();
actList.Remove(curActId);
curActId = -1;
}
// 动画内已由CanvasGroup控制整体Tip的交互功能所以可以取消SetActive(false)
PlayHideTipsAnim();
StartCoroutine("ShowHeadTips");
}
private IEnumerator ShowHeadTips()
{
// 2.0 秒时间内判断,当前是否已经播放完动画。
for(int i = 0; i < 4; ++i)
{
AnimatorStateInfo animatorInfo = _ShowTipAnim.GetCurrentAnimatorStateInfo(0);
if(animatorInfo.IsName("None"))
{
if (tipQueues.Count > 0)
{
ShowTip();
}
else
{
model.gameObject.SetActive(false);
}
yield break;
}
else if((animatorInfo.IsName("RightHide") || animatorInfo.IsName("LeftHide")) && animatorInfo.normalizedTime >= 0.99f)
{
if (tipQueues.Count > 0)
{
ShowTip();
}
else
{
model.gameObject.SetActive(false);
}
yield break;
}
yield return new WaitForSeconds(0.5f);
}
LogModule.ErrorLog("Can't show tip.");
}
private void ShowTip()
{
MarketingNewPayTip curData = tipQueues.Peek();
curActId = curData.actID;
curEntranceId = curData.entrance;
if (curData.iconPath.Count != resImg.Length)
{
Close();
LogModule.ErrorLog("SuperBenefitFirstRechargeTip: iconPath.count is wrong !");
return;
}
InitPos(curEntranceId, curActId);
PlayShowTipsAnim();
// 将iconPath和Image一一对应
for (int i = 0; i < resImg.Length; ++i)
{
if (!string.IsNullOrEmpty(curData.iconPath[i]))
{
resImg[i].gameObject.SetActive(true);
LoadAssetBundle.Instance.SetImageSprite(resImg[i], curData.iconPath[i],
(bool isSucess, GameObject obj)=>
{
if(isSucess)
{
for(int j = 0; j < resImg.Length; ++j)
{
resImg[j].SetNativeSize();
}
}
});
}
else
{
resImg[i].gameObject.SetActive(false);
}
}
// 显示模型
Tab_CharModel tab_W = TableManager.GetCharModelByID(curData.ModelId, 0);
if (tab_W != null)
{
model.gameObject.SetActive(true);
model.InitModelPath(tab_W.ResPath, tab_W);
}
else
{
model.gameObject.SetActive(false);
}
}
#endregion
private void OnRechargeBtnClick()
{
if (curEntranceId < -1)
{
Close();
return;
}
switch (curEntranceId)
{
// vip跳转
case -1:
YuanBaoShopLogic.OpenVipPage();
break;
// 充值商店
case 0:
YuanBaoShopLogic.OpenChargePage();
break;
default:
if (MarketingActsRoot.Instance() != null)
{
if (isJustEntranceId(curEntranceId, curActId) == true)
{
MarketingActsRoot.Instance().ShowActById(curEntranceId);
}
else
{
// Todo
}
}
break;
}
FinishOne();
}
// 背景按钮点击,跳转活动界面
private void OnBgBtnClick()
{
if (curActId == -1)
{
Close();
return;
}
ItemGetPathPopRoot.GotoOperationalAct(curEntranceId, curActId);
//switch(curEntranceId)
//{
// // vip跳转
// case -1:
// YuanBaoShopLogic.OpenVipPage();
// break;
// // 福利大厅
// case 0:
// UIManager.ShowUI(UIInfo.WelfareRoot,
// (bool bSuccess, object param) =>
// {
// if (bSuccess)
// {
// WelfareRootCtr.Instance.OpenWith((int)param);
// }
// }, curActId);
// break;
// default:
// if (MarketingActsRoot.Instance() != null)
// {
// if(isJustEntranceId(curEntranceId, curActId) == true)
// {
// MarketingActsRoot.Instance().ShowActById(curEntranceId);
// }
// else
// {
// // Todo
// }
// }
// break;
//}
FinishOne();
}
/// <summary>
/// 判断入口ID和活动ID是否用同一个预制体是的话不用二级打开
/// </summary>
/// <param name="enhanceID">入口 ID</param>
/// <param name="actID">活动 ID</param>
/// <returns></returns>
private bool isJustEntranceId(int enhanceID, int actID)
{
Tab_ActInfoClient tab_En = TableManager.GetActInfoClientByID(enhanceID, 0);
Tab_ActInfoClient tab_Act = TableManager.GetActInfoClientByID(actID, 0);
if (tab_En != null && tab_Act != null)
{
if (tab_En.UIPath == tab_Act.UIPath)
{
return true;
}
}
return false;
}
#region
// 跟随左侧所有按钮的位移动画
// FunctionBaseShowPanel
public Animator _ShowAnim;
public void ShowBtns()
{
_ShowAnim.Play("Show", 0, 0);
}
public void HideBtns()
{
_ShowAnim.Play("Hide", 0, 0);
}
// 单纯该提示的动画
public Animator _ShowTipAnim;
public void PlayShowTipsAnim()
{
if (leftOrRightAnim == Side.left)
{
_ShowTipAnim.Play("LeftShow");
}
else
{
_ShowTipAnim.Play("RightShow");
}
}
public void PlayHideTipsAnim()
{
if (leftOrRightAnim == Side.left)
{
_ShowTipAnim.Play("LeftHide");
}
else
{
_ShowTipAnim.Play("RightHide");
}
}
// 初始化显示位置
public void InitPos(int enhanceID, int actID)
{
Vector3 targetPos = oriPos;
switch (enhanceID)
{
// vip 需要左上角人物框下的Vip位置
// ButtonMarket
case -1:
if(PlayerFrameLogic.Instance() != null && PlayerFrameLogic.Instance().gameObject.activeInHierarchy == true)
{
Transform target = PlayerFrameLogic.Instance().m_VipLevel.transform;
if(target != null)
{
targetPos = target.position;
}
}
leftOrRightAnim = Side.left ;
break;
// 福利大厅
case 0:
if (FunctionButtonLogic.Instance() != null && FunctionButtonLogic.Instance().gameObject.activeInHierarchy == true)
{
LogModule.DebugLog(FunctionButtonLogic.Instance().gameObject.name);
Transform target = FunctionButtonLogic.Instance().gameObject.transform.Find("Anchor-RightTop/FunctionWindow/FunctionButtonOffset/TopBtns/TopBtns/ButtonLingJiang");
if (target != null)
{
targetPos = target.position;
}
}
leftOrRightAnim = Side.right;
break;
// 其他运营活动
default:
leftOrRightAnim = Side.right;
// 找到活动入口的位置
if (MarketingActsRoot.Instance() != null && MarketingActsRoot.Instance().gameObject.activeInHierarchy)
{
MarketingMainMenu actIconCS = null;
actIconCS = MarketingActsRoot.Instance().GetContainItem(enhanceID);
if (actIconCS != null)
{
targetPos = actIconCS.transform.position;
// 运营活动中 左是0右是1
if(actIconCS.MyActState.leftOrRight == 0)
{
leftOrRightAnim = Side.left;
}
}
}
break;
}
// 如果没找到初始位置,使用默认位置,也用左边的动画
animStartAnchor.localPosition = animStartAnchor.parent.InverseTransformVector(targetPos);
}
#endregion
}