528 lines
17 KiB
C#
528 lines
17 KiB
C#
using UnityEngine;
|
||
using System.Collections;
|
||
using UnityEngine.UI;
|
||
using System.Collections.Generic;
|
||
using GCGame.Table;
|
||
using Module.Log;
|
||
using System;
|
||
|
||
// 开服活动
|
||
// 主要控制菜单列表
|
||
public class OpenServiceRootCS : MarketingUIBaseCS
|
||
{
|
||
#region Single
|
||
private static OpenServiceRootCS _instance;
|
||
public static OpenServiceRootCS Instance
|
||
{
|
||
get
|
||
{
|
||
if (_instance != null)
|
||
{
|
||
return _instance;
|
||
}
|
||
|
||
//LogModule.ErrorLog("Can't get instances");
|
||
return null;
|
||
}
|
||
}
|
||
|
||
private void Awake()
|
||
{
|
||
if (_instance == null)
|
||
{
|
||
_instance = this;
|
||
}
|
||
|
||
closeBtn.onClick.AddListener(Close);
|
||
|
||
// 排行榜
|
||
close.onClick.AddListener(OnCloseRankBtnClick);
|
||
bgMask._BackClick.AddListener(OnCloseRankBtnClick);
|
||
}
|
||
#endregion
|
||
|
||
// 用于设置活动接收菜单数据后显示的活动
|
||
// 无论存在此活动与否,都要在第一次显示过后,设回 -1
|
||
// -1 不跳转
|
||
private static int openWithAct = -1;
|
||
public static int OpenWithAct
|
||
{
|
||
get { return openWithAct; }
|
||
set { openWithAct = value; }
|
||
}
|
||
|
||
// 记录需要打开活动的具体某一项,配合OpenWithAct使用。现仅用于 开服累充
|
||
private static int openWithTagIndex = -1;
|
||
public static int OpenWithTagIndex
|
||
{
|
||
get { return openWithTagIndex; }
|
||
set { openWithTagIndex = value; }
|
||
}
|
||
|
||
public Text title; // 标题
|
||
public UIContainerSelect menuContainer; // 列表容器
|
||
public GameObject pageContainer; // 页面内容父物体
|
||
public List<MarketingActState> actPageInfo; // 菜单信息
|
||
public Button closeBtn; // 关闭按钮
|
||
public float showTipsInterval; // 显示提示的间隔
|
||
|
||
private int curPageID; // 当前显示页面ID
|
||
private int targetPageID;
|
||
private Queue<MarketingActAwardItem> tipsQueue; // 等待显示的获取信息队列
|
||
|
||
private void OnEnable()
|
||
{
|
||
OnCloseRankBtnClick();
|
||
Init();
|
||
}
|
||
|
||
private void OnDisable()
|
||
{
|
||
if (MarketingActsRoot.Instance() != null)
|
||
{
|
||
//if(curPageID != -1)
|
||
//{
|
||
// if(MarketingActsRoot.Instance()._ShowingWin[curPageID] != null)
|
||
// {
|
||
// MarketingActsRoot.Instance()._ShowingWin[curPageID].SetActive(false);
|
||
// }
|
||
// else
|
||
// {
|
||
// LogModule.ErrorLog("Try to get an activity in Openservice. But is Null, please check _ActId = " + curPageID);
|
||
// }
|
||
|
||
// MarketingActsRoot.Instance().ClearShowingWin(_ActID);
|
||
//}
|
||
|
||
MarketingActsRoot.Instance().ClearShowingWin(_ActID);
|
||
}
|
||
}
|
||
|
||
public void Close()
|
||
{
|
||
gameObject.SetActive(false);
|
||
}
|
||
|
||
private void Init()
|
||
{
|
||
tipsQueue = new Queue<MarketingActAwardItem>();
|
||
AskForInfo();
|
||
}
|
||
public void ShowMarketUi(int arcId)
|
||
{
|
||
openWithAct = arcId;
|
||
SetMenu(actPageInfo);
|
||
}
|
||
|
||
private void SetMenu(List<MarketingActState> menuInfos)
|
||
{
|
||
if (menuInfos.Count > 0)
|
||
{
|
||
List<MarketingActState> selectMenus = new List<MarketingActState>();
|
||
|
||
// 查看是否有需要打开的活动ID
|
||
int index = menuInfos.FindIndex((MarketingActState m) => { return m.actID == openWithAct; });
|
||
if (index != -1)
|
||
{
|
||
selectMenus.Add(menuInfos[index]);
|
||
}
|
||
else
|
||
{
|
||
selectMenus.Add(menuInfos[0]);
|
||
if (openWithAct != -1)
|
||
{
|
||
GUIData.AddNotifyData(StrDictionary.GetClientDictionaryString("#{6741}"));
|
||
}
|
||
}
|
||
|
||
menuContainer.InitSelectContent(menuInfos, selectMenus, OnMenuSelect);
|
||
}
|
||
|
||
openWithAct = -1;
|
||
}
|
||
|
||
// 加载页面
|
||
private void OnMenuSelect(object info)
|
||
{
|
||
LogModule.DebugLog("Openservice: MenuClick");
|
||
MarketingActState selectMenu = info as MarketingActState;
|
||
if (selectMenu != null)
|
||
{
|
||
Tab_ActInfoClient tab = TableManager.GetActInfoClientByID(selectMenu.actID, 0);
|
||
Hashtable parm = new Hashtable();
|
||
parm.Add("ActState", selectMenu);
|
||
targetPageID = selectMenu.actID;
|
||
|
||
LuaUIManager.Instance.ShowLuaUIAsChild(tab.UIPath, pageContainer, LoadUICallBack, parm, true);
|
||
}
|
||
else
|
||
{
|
||
LogModule.ErrorLog("No this page.");
|
||
}
|
||
}
|
||
|
||
private void LoadUICallBack(bool sucess, object param, GameObject uiObj)
|
||
{
|
||
MarketingActState info = ((Hashtable)param)["ActState"] as MarketingActState;
|
||
if (info == null)
|
||
{
|
||
LogModule.DebugLog("Openservice UI callBack param error:" + curPageID);
|
||
return;
|
||
}
|
||
|
||
if (info.actID != targetPageID)
|
||
{
|
||
Tab_ActInfoClient tab = TableManager.GetActInfoClientByID(info.actID, 0);
|
||
LuaUIManager.Instance.CancelLoadUICallBack(tab.UIPath);
|
||
}
|
||
else
|
||
{
|
||
if (MarketingActsRoot.Instance()._ShowingWin.ContainsKey(curPageID))
|
||
{
|
||
if (MarketingActsRoot.Instance()._ShowingWin[curPageID] != null)
|
||
{
|
||
MarketingActsRoot.Instance()._ShowingWin[curPageID].SetActive(false);
|
||
}
|
||
else
|
||
{
|
||
LogModule.DebugLog("Try to get an activity in Openservice. But is Null, please check _ActId = " + curPageID);
|
||
}
|
||
|
||
MarketingActsRoot.Instance()._ShowingWin.Remove(curPageID);
|
||
}
|
||
|
||
///////////// 临时修复Bug:会出现没及时删除旧页面的情况
|
||
if (MarketingActsRoot.Instance()._ShowingWin.ContainsKey(info.actID))
|
||
{
|
||
if (MarketingActsRoot.Instance()._ShowingWin[info.actID] != null)
|
||
{
|
||
MarketingActsRoot.Instance()._ShowingWin[info.actID].SetActive(false);
|
||
}
|
||
else
|
||
{
|
||
LogModule.DebugLog("Try to get an activity in Openservice. But is Null, please check _ActId = " + curPageID);
|
||
}
|
||
|
||
MarketingActsRoot.Instance()._ShowingWin.Remove(info.actID);
|
||
}
|
||
|
||
curPageID = targetPageID;
|
||
MarketingActsRoot.Instance().LoadUICallBack(sucess, param, uiObj);
|
||
}
|
||
}
|
||
|
||
// 显示获得的信息
|
||
public void ShowGetTips(List<MarketingActAwardItem> awardList)
|
||
{
|
||
if (tipsQueue.Count > 0)
|
||
{
|
||
for (int i = 0; i < awardList.Count; i++)
|
||
{
|
||
tipsQueue.Enqueue(awardList[i]);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
for (int i = 0; i < awardList.Count; i++)
|
||
{
|
||
tipsQueue.Enqueue(awardList[i]);
|
||
}
|
||
StartCoroutine("ShowTips");
|
||
}
|
||
}
|
||
|
||
private IEnumerator ShowTips()
|
||
{
|
||
// 安全计数,防止死循环
|
||
int count = 0;
|
||
while (tipsQueue.Count > 0)
|
||
{
|
||
MarketingActAwardItem item = tipsQueue.Dequeue();
|
||
Tab_CommonItem tab = TableManager.GetCommonItemByID(item.awardType, item.awardSubType);
|
||
string tip = tab.Name + " X " + item.awardNum;
|
||
LogModule.DebugLog("Get item : " + tip);
|
||
|
||
for (float i = 0.0f; i < showTipsInterval; i++)
|
||
{
|
||
yield return null;
|
||
}
|
||
|
||
count++;
|
||
if (count > 50)
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
#region 发送请求以及接收处理
|
||
|
||
// 请求
|
||
private void AskForInfo()
|
||
{
|
||
MarketingActsReq request = new MarketingActsReq();
|
||
request.actType = _ActID;
|
||
|
||
request.SendMsg();
|
||
}
|
||
|
||
// 接收
|
||
protected override void MarketingActRetInner(MarketingActsRet marketActsRet)
|
||
{
|
||
LogModule.DebugLog(this.gameObject.name + " : Recieve message.");
|
||
base.MarketingActRetInner(marketActsRet);
|
||
|
||
if (!string.IsNullOrEmpty(marketActsRet.SkipPath))
|
||
{
|
||
string skipPath = marketActsRet.SkipPath.Trim();
|
||
if (!string.IsNullOrEmpty(skipPath))
|
||
{
|
||
string[] skipParam = skipPath.Split('|');
|
||
int actID = Convert.ToInt32(skipParam[0]);
|
||
int tagIndex = Convert.ToInt32(skipParam[1]);
|
||
|
||
OpenWithAct = actID;
|
||
OpenWithTagIndex = tagIndex;
|
||
}
|
||
}
|
||
actPageInfo = marketActsRet.actIDState;
|
||
SetMenu(marketActsRet.actIDState);
|
||
}
|
||
|
||
#endregion
|
||
|
||
// 排行榜相关
|
||
public GameObject advanceRankPanel;
|
||
public UICameraTexture model;
|
||
public UIContainerSelect rankList;
|
||
public Button close;
|
||
public UIBackRayBehind bgMask;
|
||
public Text advancePanelTitle;
|
||
public GameObject noModelTips;
|
||
|
||
// 自身排行
|
||
public Text myRankNum;
|
||
|
||
public Sprite[] specialSprites = new Sprite[3];
|
||
|
||
public Text myRankInfo;
|
||
|
||
public void OnCloseRankBtnClick()
|
||
{
|
||
noModelTips.SetActive(false);
|
||
advanceRankPanel.SetActive(false);
|
||
}
|
||
|
||
public void OnRecieveRankInfo(GC_RET_RANK_LIST packet)
|
||
{
|
||
advanceRankPanel.SetActive(true);
|
||
advancePanelTitle.text = StrDictionary.GetClientDictionaryString("#{" + (packet.Ranktype - 71 + 62928) + "}");
|
||
|
||
List<AdvanceRankItem.AdvanceRankItemData> rankDatas = new List<AdvanceRankItem.AdvanceRankItemData>();
|
||
|
||
for (int i = 0; i < packet.ranklistCount; i++)
|
||
{
|
||
if (i >= 100)
|
||
break;
|
||
|
||
// 54 玩家的进阶阶级 数字
|
||
// 55 玩家的进阶星数 仅坐骑 数字
|
||
// 2 玩家名 字符串
|
||
// UserAdvanceCombat = 61, //玩家的进阶战斗力
|
||
AdvanceRankItem.AdvanceRankItemData newData = new AdvanceRankItem.AdvanceRankItemData();
|
||
newData.advanceType = packet.Ranktype - 71;
|
||
newData.rank = i + 1;
|
||
newData.star = (int)GetProValueInt(54, packet.ranklistList[i]);
|
||
newData.level = (int)GetProValueInt(55, packet.ranklistList[i]);
|
||
newData.name = GetProValueStr(2, packet.ranklistList[i]);
|
||
newData.combat = (int)GetProValueInt(61, packet.ranklistList[i]);
|
||
|
||
if (rankDatas.Count < 20)
|
||
{
|
||
rankDatas.Add(newData);
|
||
}
|
||
else
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
|
||
AdvanceRankItem.AdvanceRankItemData myRankData = new AdvanceRankItem.AdvanceRankItemData();
|
||
|
||
// 49 - 玩家在榜单中的排名0~N
|
||
myRankData.advanceType = packet.Ranktype - 71;
|
||
myRankData.rank = (int)GetProValueInt(49, packet.Myrankinfo) + 1;
|
||
myRankData.star = (int)GetProValueInt(54, packet.Myrankinfo);
|
||
myRankData.level = (int)GetProValueInt(55, packet.Myrankinfo);
|
||
myRankData.combat = (int)GetProValueInt(61, packet.Myrankinfo);
|
||
|
||
if (rankDatas.Count > 0)
|
||
{
|
||
// 当没有排行榜数据时,显示点击的排名模型
|
||
List<AdvanceRankItem.AdvanceRankItemData> selectItems = new List<AdvanceRankItem.AdvanceRankItemData>() { rankDatas[0] };
|
||
rankList.InitSelectContent(rankDatas, selectItems, ShowModel);
|
||
}
|
||
else
|
||
{
|
||
// 当没有 排行榜数据时,显示自己的
|
||
rankList.InitSelectContent(rankDatas, null, ShowModel);
|
||
ShowModel(myRankData);
|
||
}
|
||
|
||
SetMyRankInfo(myRankData);
|
||
|
||
// 模型
|
||
if (!AdvanceCanadvanceCtr.Instance.IsAdvanceFuncOpen(myRankData.advanceType) && rankDatas.Count <= 0)
|
||
{
|
||
noModelTips.gameObject.SetActive(true);
|
||
model.gameObject.SetActive(false);
|
||
}
|
||
else
|
||
{
|
||
noModelTips.gameObject.SetActive(false);
|
||
model.gameObject.SetActive(true);
|
||
}
|
||
}
|
||
|
||
private void ShowModel(object obj)
|
||
{
|
||
AdvanceRankItem.AdvanceRankItemData selectedObj = obj as AdvanceRankItem.AdvanceRankItemData;
|
||
|
||
if (selectedObj == null)
|
||
{
|
||
model.gameObject.SetActive(false);
|
||
return;
|
||
}
|
||
|
||
int advanceBaseID = -1;
|
||
Tab_AdvanceBase advanceBase = null;
|
||
|
||
// 坐骑、翅膀、其他分三种情况初始化模型,因为读表流程不一样
|
||
switch (selectedObj.advanceType)
|
||
{
|
||
case (int)AdvanceBase.AdvanceType.Ride:
|
||
advanceBaseID = (selectedObj.advanceType + 1) * 1000 + 5 * (selectedObj.star - 1) + 1;
|
||
advanceBase = TableManager.GetAdvanceBaseByID(advanceBaseID, 0);
|
||
if (advanceBase == null)
|
||
{
|
||
model.gameObject.SetActive(false);
|
||
return;
|
||
}
|
||
|
||
Tab_MountBase mountBase = TableManager.GetMountBaseByID(advanceBase.ShowModelId, 0);
|
||
if (mountBase == null)
|
||
{
|
||
model.gameObject.SetActive(false);
|
||
return;
|
||
}
|
||
|
||
// 坐骑模型资源数据
|
||
Tab_CharMount charMount = TableManager.GetCharMountByID(mountBase.ModelID, 0);
|
||
if (charMount == null)
|
||
{
|
||
model.gameObject.SetActive(false);
|
||
return;
|
||
}
|
||
|
||
model.InitMountModelPath(charMount, delegate ()
|
||
{
|
||
model.gameObject.SetActive(true);
|
||
});
|
||
|
||
break;
|
||
case (int)AdvanceBase.AdvanceType.Wing:
|
||
advanceBaseID = (selectedObj.advanceType + 1) * 1000 + selectedObj.star;
|
||
advanceBase = TableManager.GetAdvanceBaseByID(advanceBaseID, 0);
|
||
|
||
if (advanceBase == null)
|
||
{
|
||
model.gameObject.SetActive(false);
|
||
return;
|
||
}
|
||
|
||
model.InitWingModelPath(advanceBase, null, delegate ()
|
||
{
|
||
model._CameraPrefab.GetComponent<Camera>().orthographicSize = 1.3f;
|
||
model.gameObject.SetActive(true);
|
||
});
|
||
|
||
break;
|
||
case (int)AdvanceBase.AdvanceType.Piano:
|
||
case (int)AdvanceBase.AdvanceType.Qilinbi:
|
||
case (int)AdvanceBase.AdvanceType.Mask:
|
||
case (int)AdvanceBase.AdvanceType.Soul:
|
||
case (int)AdvanceBase.AdvanceType.Huopao:
|
||
advanceBaseID = (selectedObj.advanceType + 1) * 1000 + selectedObj.star;
|
||
advanceBase = TableManager.GetAdvanceBaseByID(advanceBaseID, 0);
|
||
if (advanceBase == null)
|
||
{
|
||
model.gameObject.SetActive(false);
|
||
return;
|
||
}
|
||
|
||
Tab_CharModel charModel = TableManager.GetCharModelByID(advanceBase.ShowModelId, 0);
|
||
if (charModel != null)
|
||
{
|
||
model.InitModelPath(charModel.ResPath, charModel, LoadAssetBundle.BUNDLE_PATH_MODEL, true, delegate ()
|
||
{
|
||
model._CameraPrefab.GetComponent<Camera>().orthographicSize = 1.3f;
|
||
model.gameObject.SetActive(true);
|
||
});
|
||
}
|
||
|
||
break;
|
||
default:
|
||
model.gameObject.SetActive(false);
|
||
return;
|
||
}
|
||
}
|
||
|
||
private void SetMyRankInfo(AdvanceRankItem.AdvanceRankItemData data)
|
||
{
|
||
if (data.rank <= 0)
|
||
{
|
||
myRankNum.text = StrDictionary.GetClientDictionaryString("#{62937}");
|
||
}
|
||
else
|
||
{
|
||
myRankNum.text = data.rank.ToString();
|
||
}
|
||
|
||
myRankInfo.gameObject.SetActive(true);
|
||
if (AdvanceCanadvanceCtr.Instance.IsAdvanceFuncOpen(data.advanceType) == true)
|
||
{
|
||
myRankInfo.text = StrDictionary.GetClientDictionaryString("#{" + (data.advanceType + 62921).ToString() + "}", data.combat.ToString());
|
||
}
|
||
else
|
||
{
|
||
myRankInfo.text = StrDictionary.GetClientDictionaryString("#{" + (data.advanceType + 62921).ToString() + "}", StrDictionary.GetClientDictionaryString("#{62936}"));
|
||
}
|
||
}
|
||
|
||
long GetProValueInt(int proID, RankElemStruct ranklist)
|
||
{
|
||
if (ranklist == null)
|
||
return -1;
|
||
for (int i = 0; i < ranklist.numberfieldsCount; i++)
|
||
{
|
||
RankFieldNumberStruct numberInfo = ranklist.GetNumberfields(i);
|
||
if (proID == numberInfo.Propid)
|
||
return numberInfo.Propvalue;
|
||
}
|
||
return -1;
|
||
}
|
||
|
||
string GetProValueStr(int proID, RankElemStruct ranklist)
|
||
{
|
||
if (ranklist == null)
|
||
return "";
|
||
for (int i = 0; i < ranklist.stringfieldsCount; i++)
|
||
{
|
||
RankFieldStringStruct stringInfo = ranklist.GetStringfields(i);
|
||
if (proID == stringInfo.Propid)
|
||
return stringInfo.Propvalue;
|
||
}
|
||
return "";
|
||
}
|
||
}
|