//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Monday, September 04, 2017
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
using LitJson;
|
using System.Text.RegularExpressions;
|
|
namespace vnxbqy.UI
|
{
|
|
public class LoadingWin : Window
|
{
|
public static int targetMapResId = 0;
|
public static bool isCrossServerOneVsOne = false;
|
|
[SerializeField] RawImage m_ScreenShotCut;
|
[SerializeField] UIAlphaTween m_UIAlphaTween;
|
|
[SerializeField] RectTransform m_ContainerNormal;
|
[SerializeField] Image m_BackGround;
|
[SerializeField] RectTransform m_ContainerFunctions;
|
[SerializeField] LoadingFunctionShow[] m_FunctionShows;
|
[SerializeField] RectTransform m_ContainerProgress;
|
[SerializeField] SmoothSlider m_ProgressSlider;
|
[SerializeField] RectTransform m_ContainerMapName;
|
[SerializeField] Image m_MapName;
|
[SerializeField] RectTransform m_ContainerMapDescription;
|
[SerializeField] Image m_MapDescription;
|
|
[SerializeField] RectTransform m_CrossServerOneVsOne;
|
[SerializeField] Image m_CrossServerOneVsOneBg;
|
[SerializeField] RectTransform m_CrossServerOneVsOneName;
|
[SerializeField] Text m_MyName;
|
[SerializeField] Text m_OpponentName;
|
|
float refProgress = 0f;
|
float overTimer = 0f;
|
|
LoadingType loadingType = LoadingType.Normal;
|
|
#region Built-in
|
protected override void BindController()
|
{
|
}
|
|
protected override void AddListeners()
|
{
|
}
|
|
protected override void OnPreOpen()
|
{
|
if(isCrossServerOneVsOne || ArenaManager.isArenaClient)
|
{
|
loadingType = LoadingType.CrossServerOneOne;
|
}else
|
{
|
loadingType = LoadingType.Normal;
|
}
|
m_ContainerNormal.SetActive(false);
|
m_CrossServerOneVsOne.SetActive(false);
|
ynmbxxjUtil.Instance.SendHideFloatWin();
|
MainPositionTween.resetToDefaultTimer = 0f;
|
}
|
|
protected override void OnAfterOpen()
|
{
|
}
|
|
protected override void OnPreClose()
|
{
|
isCrossServerOneVsOne = false;
|
|
CameraUtility.StopShotCut(m_ScreenShotCut);
|
if (!AssetSource.uiFromEditor)
|
{
|
AssetBundleUtility.Instance.UnloadAssetBundle("ui/sprite/loading", true, false);
|
AssetBundleUtility.Instance.UnloadAssetBundle("ui/sprite/loadingbg", true, false);
|
}
|
}
|
|
protected override void OnAfterClose()
|
{
|
ynmbxxjUtil.Instance.SendShowFloatWin();
|
}
|
|
protected override void OnActived()
|
{
|
base.OnActived();
|
|
CameraUtility.ScreenShotCut(m_ScreenShotCut, null, false, false);
|
m_UIAlphaTween.Play(Display);
|
}
|
|
#endregion
|
|
protected override void LateUpdate()
|
{
|
base.LateUpdate();
|
if (loadingType == LoadingType.Normal)
|
{
|
if (StageLoad.Instance.progress + 0.1f > refProgress)
|
{
|
refProgress = Mathf.Clamp01(StageLoad.Instance.progress + 0.1f);
|
}
|
|
m_ProgressSlider.value = refProgress;
|
}
|
|
overTimer += Time.deltaTime;
|
if (overTimer > 15f)
|
{
|
overTimer -= 5f;
|
|
var loginModel = ModelCenter.Instance.GetModel<LoginModel>();
|
if (!loginModel.busy && !CrossServerLogin.Instance.busy && !StageLoad.Instance.isLoading)
|
{
|
WindowCenter.Instance.Close<LoadingWin>();
|
}
|
}
|
|
}
|
|
private void Display()
|
{
|
overTimer = 0f;
|
refProgress = 0f;
|
var useDefautBackGround = false;
|
if (!AssetSource.uiFromEditor)
|
{
|
var assetVersion = AssetVersionUtility.GetAssetVersion(AssetVersionUtility.EncodeFileName("ui/sprite/loadingbg"));
|
if (assetVersion == null || !assetVersion.localValid)
|
{
|
useDefautBackGround = true;
|
}
|
}
|
|
if (!useDefautBackGround)
|
{
|
var mapResConfig = MapResourcesConfig.Get(targetMapResId);
|
if (mapResConfig == null)
|
{
|
useDefautBackGround = true;
|
}
|
|
if (!useDefautBackGround)
|
{
|
var config = LoadingBackGroundConfig.Get(mapResConfig.DataID, mapResConfig.LineID);
|
if (config == null)
|
{
|
if ((int)Time.time % 2 == 1)
|
{
|
config = LoadingBackGroundConfig.Get(1, 1);
|
}
|
}
|
if (config == null || config.icons.IsNullOrEmpty())
|
{
|
useDefautBackGround = true;
|
}
|
}
|
}
|
|
switch (loadingType)
|
{
|
case LoadingType.Normal:
|
m_ContainerNormal.SetActive(true);
|
m_CrossServerOneVsOne.SetActive(false);
|
|
m_ContainerProgress.SetActive(true);
|
m_ProgressSlider.ResetValue(0f);
|
break;
|
case LoadingType.CrossServerOneOne:
|
m_ContainerNormal.SetActive(false);
|
m_CrossServerOneVsOne.SetActive(true);
|
break;
|
}
|
|
DisplayBackGround(loadingType, useDefautBackGround);
|
DisplayNameAndDescription();
|
}
|
|
private void DisplayBackGround(LoadingType loadingType, bool showDefault)
|
{
|
if (showDefault)
|
{
|
var sprite = BuiltInLoader.LoadSprite("Launch_1");
|
switch (loadingType)
|
{
|
case LoadingType.Arena:
|
m_CrossServerOneVsOneBg.overrideSprite = sprite;
|
m_CrossServerOneVsOneName.SetActive(false);
|
break;
|
case LoadingType.CrossServerOneOne:
|
m_CrossServerOneVsOneBg.overrideSprite = sprite;
|
m_CrossServerOneVsOneName.SetActive(false);
|
break;
|
case LoadingType.Normal:
|
m_BackGround.overrideSprite = sprite;
|
m_ContainerMapName.SetActive(false);
|
m_ContainerMapDescription.SetActive(false);
|
m_ContainerFunctions.SetActive(false);
|
break;
|
}
|
|
return;
|
}
|
|
if (loadingType == LoadingType.CrossServerOneOne)
|
{
|
m_CrossServerOneVsOneBg.SetSprite("CrossServerOneVsOne_LoadingBG");
|
m_CrossServerOneVsOneName.SetActive(true);
|
m_MyName.text = CrossServerLogin.Instance.oneVsOnePlayerData.myName;
|
m_OpponentName.text = CrossServerLogin.Instance.oneVsOnePlayerData.opponentName;
|
if(ArenaManager.isArenaClient)
|
{
|
m_MyName.text = ArenaManager.myName;
|
m_OpponentName.text = ArenaManager.opponentName;
|
}
|
}
|
else
|
{
|
var playerLevel = PlayerDatas.Instance.baseData.LV == 0 ? PlayerDatas.Instance.loginInfo.LV : PlayerDatas.Instance.baseData.LV;
|
var playerJob = PlayerDatas.Instance.baseData.Job == 0 ? PlayerDatas.Instance.loginInfo.Job : PlayerDatas.Instance.baseData.Job;
|
var mapResConfig = MapResourcesConfig.Get(targetMapResId);
|
|
if (mapResConfig != null)
|
{
|
var config = LoadingBackGroundConfig.Get(mapResConfig.DataID, mapResConfig.LineID);
|
if (config == null)
|
config = LoadingBackGroundConfig.Get(1, 1);
|
var iconPool = new List<string>();
|
iconPool.AddRange(config.icons);
|
|
if (playerLevel > GeneralDefine.MasteryLoadingLevelLimit1)
|
{
|
switch (playerJob)
|
{
|
case 1:
|
iconPool.AddRange(config.jobIntroduce1);
|
if (playerLevel >= GeneralDefine.MasteryLoadingLevelLimit2)
|
{
|
iconPool.AddRange(config.jobIntroduce2);
|
}
|
break;
|
case 2:
|
if (playerLevel >= GeneralDefine.MasteryLoadingLevelLimit2)
|
{
|
iconPool.AddRange(config.jobIntroduce1);
|
}
|
iconPool.AddRange(config.jobIntroduce2);
|
break;
|
}
|
}
|
|
if (iconPool.Count > 0)
|
{
|
var icons = new List<string>();
|
var json = JsonMapper.ToObject(config.levelLimit);
|
for (var i = 0; i < iconPool.Count; i++)
|
{
|
var icon = iconPool[i];
|
if (json.Keys.Contains(icon))
|
{
|
var min = 0;
|
var max = int.MaxValue;
|
var levelLimit = json[icon].ToString();
|
var levelsMatch = Regex.Matches(levelLimit, "\\d+");
|
if (levelsMatch.Count > 0)
|
{
|
min = int.Parse(levelsMatch[0].Value);
|
}
|
|
if (levelsMatch.Count > 1)
|
{
|
max = int.Parse(levelsMatch[1].Value);
|
}
|
|
if (playerLevel > min && playerLevel < max)
|
{
|
icons.Add(icon);
|
}
|
}
|
else
|
{
|
icons.Add(icon);
|
}
|
}
|
|
var randomIndex = UnityEngine.Random.Range(0, iconPool.Count > 1 ? icons.Count + 1 : 1);
|
if (randomIndex == icons.Count && GeneralDefine.LoadLV != "")
|
{
|
m_BackGround.SetSprite(GeneralDefine.LoadLV);
|
m_ContainerFunctions.SetActive(true);
|
var functions = GetShowFunctions(playerLevel);
|
for (int i = 0; i < m_FunctionShows.Length; i++)
|
{
|
var show = m_FunctionShows[i];
|
show.Display(functions[i]);
|
}
|
}
|
else
|
{
|
if (randomIndex == icons.Count)
|
{
|
randomIndex--;
|
}
|
m_BackGround.SetSprite(icons[randomIndex]);
|
m_ContainerFunctions.SetActive(false);
|
}
|
|
}
|
}
|
}
|
|
}
|
|
private void DisplayNameAndDescription()
|
{
|
var mapResConfig = MapResourcesConfig.Get(targetMapResId);
|
|
LoadingBackGroundConfig config;
|
if (mapResConfig == null)
|
{
|
config = null;
|
}
|
else
|
{
|
config = LoadingBackGroundConfig.Get(mapResConfig.DataID, mapResConfig.LineID);
|
}
|
|
if (config != null && !string.IsNullOrEmpty(config.name))
|
{
|
m_ContainerMapName.SetActive(true);
|
m_MapName.SetSprite(config.name);
|
}
|
else
|
{
|
m_ContainerMapName.SetActive(false);
|
}
|
|
if (config != null && !string.IsNullOrEmpty(config.description))
|
{
|
m_ContainerMapDescription.SetActive(true);
|
m_MapDescription.SetSprite(config.description);
|
}
|
else
|
{
|
m_ContainerMapDescription.SetActive(false);
|
}
|
}
|
|
private List<int> GetShowFunctions(int _level)
|
{
|
var configs = LoadingFunctionConfig.GetValues();
|
var functions = new List<int>() { configs[0].ID, configs[1].ID, configs[2].ID, configs[3].ID };
|
for (int i = 4; i < configs.Count; i++)
|
{
|
var config = LoadingFunctionConfig.Get(functions[2]);
|
if (_level >= config.Level)
|
{
|
functions.RemoveAt(0);
|
functions.Add(configs[i].ID);
|
}
|
}
|
|
return functions;
|
}
|
|
public enum LoadingType
|
{
|
Normal,
|
CrossServerOneOne,
|
Arena
|
}
|
|
}
|
|
}
|
|
|
|
|