using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
public class HazyRegionIncidentPanel : MonoBehaviour
|
{
|
[SerializeField] HazyRegionCyclicScroll m_CyclicScroll;
|
[SerializeField] Transform m_ContainerPoint;
|
[SerializeField] Slider m_Slider;
|
[SerializeField] Text m_Point;
|
[SerializeField] Button m_Back;
|
[SerializeField] Button m_Goto;
|
[SerializeField] Text m_GotoLabel;
|
|
List<int> incidents = new List<int>();
|
|
HazyRegionModel model { get { return ModelCenter.Instance.GetModel<HazyRegionModel>(); } }
|
DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
|
PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
FindPreciousModel findPreciousModel { get { return ModelCenter.Instance.GetModel<FindPreciousModel>(); } }
|
DailyQuestModel dailyQuestModel { get { return ModelCenter.Instance.GetModel<DailyQuestModel>(); } }
|
|
DateTime requestTime = DateTime.Now;
|
int requestCount = 0;
|
float timer = 0f;
|
Dictionary<int, List<byte>> requestLines = new Dictionary<int, List<byte>>();
|
|
private void Awake()
|
{
|
m_Back.AddListener(OnBack);
|
m_Goto.AddListener(Goto);
|
}
|
|
public void Display()
|
{
|
DisplayPoint();
|
DisplayIncidents();
|
DisplayBackButton();
|
DisplayGotoState();
|
|
requestCount = 0;
|
model.incidentDirty = false;
|
SendRequestPlayerCount();
|
|
m_ContainerPoint.gameObject.SetActive(false);
|
|
DailyQuestActionTimer.Instance.RefreshDailyQuestState -= RefreshDailyQuestState;
|
DailyQuestActionTimer.Instance.RefreshDailyQuestState += RefreshDailyQuestState;
|
|
m_CyclicScroll.animationComplete -= AnimationComplete;
|
m_CyclicScroll.animationComplete += AnimationComplete;
|
}
|
|
void DisplayIncidents()
|
{
|
incidents.Clear();
|
incidents.AddRange(model.GetAllIncidents());
|
incidents.Sort(Compare);
|
|
if (incidents.Count > 0)
|
{
|
var _ids = new List<int>(incidents);
|
_ids.Sort((x, y) =>
|
{
|
HazyRegionModel.Incident lhs_incident;
|
HazyRegionModel.Incident rhs_incident;
|
if (model.TryGetIncident(x, out lhs_incident)
|
&& model.TryGetIncident(y, out rhs_incident))
|
{
|
var lhs_index = model.incidentSelectSort.IndexOf(lhs_incident.state);
|
var rhs_index = model.incidentSelectSort.IndexOf(rhs_incident.state);
|
if (lhs_index != rhs_index)
|
{
|
return lhs_index.CompareTo(rhs_index);
|
}
|
lhs_index = incidents.IndexOf(x);
|
rhs_index = incidents.IndexOf(y);
|
if (lhs_index != rhs_index)
|
{
|
return lhs_index.CompareTo(rhs_index);
|
}
|
}
|
return 0;
|
});
|
|
model.selectIncident = _ids[0];
|
}
|
|
m_CyclicScroll.Init(incidents);
|
|
if (!model.requireIncidentAnimation && model.selectIncident != incidents[0])
|
{
|
m_CyclicScroll.MoveToCenter(incidents.IndexOf(model.selectIncident));
|
}
|
|
if (model.requireIncidentAnimation)
|
{
|
m_CyclicScroll.DisplayAnimation();
|
model.requireIncidentAnimation = false;
|
}
|
}
|
|
void DisplayPoint()
|
{
|
var point = Mathf.Min(model.point, model.limitPoint);
|
m_Point.text = StringUtility.Contact(point, "/", model.limitPoint);
|
m_Slider.value = Mathf.Clamp01((float)point / model.limitPoint);
|
}
|
|
void DisplayBackButton()
|
{
|
m_Back.gameObject.SetActive(false);
|
}
|
|
int Compare(int lhs, int rhs)
|
{
|
var lhs_config = HazyRegionConfig.Get(lhs);
|
var rhs_config = HazyRegionConfig.Get(rhs);
|
var lhs_index = model.incidentTypesSort.IndexOf((HazyRegionIncidentType)lhs_config.incidentType);
|
var rhs_index = model.incidentTypesSort.IndexOf((HazyRegionIncidentType)rhs_config.incidentType);
|
if (lhs_index != rhs_index)
|
{
|
return lhs_index.CompareTo(rhs_index);
|
}
|
if (lhs_config.incidentType == rhs_config.incidentType)
|
{
|
if ((HazyRegionIncidentType)lhs_config.incidentType == HazyRegionIncidentType.DemonKing)
|
{
|
if (lhs_config.lineId != rhs_config.lineId)
|
{
|
return -lhs_config.lineId.CompareTo(rhs_config.lineId);
|
}
|
}
|
}
|
return 0;
|
}
|
|
private void OnBack()
|
{
|
if (model.IsIncidentDungeon())
|
{
|
|
return;
|
}
|
|
var state = 0;
|
|
bool allComplete = true;
|
int minpoint = int.MaxValue;
|
|
foreach (var id in incidents)
|
{
|
HazyRegionModel.Incident incident;
|
if (model.TryGetIncident(id, out incident))
|
{
|
if (incident.state == HazyRegionModel.IncidentState.Processing)
|
{
|
state = 2;
|
allComplete = false;
|
break;
|
}
|
if(incident.state != HazyRegionModel.IncidentState.Complete)
|
{
|
allComplete = false;
|
}
|
var config = HazyRegionConfig.Get(id);
|
if (minpoint > config.point)
|
{
|
minpoint = config.point;
|
}
|
}
|
}
|
|
if (state == 0 && !allComplete && model.point >= minpoint)
|
{
|
state = 1;
|
}
|
|
switch (state)
|
{
|
case 1:
|
ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("HazyRegionBackRemind_1"), (bool isOk) =>
|
{
|
if (isOk)
|
{
|
model.SendBackHazyRegion();
|
}
|
});
|
break;
|
case 2:
|
ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("HazyRegionBackRemind_2"), (bool isOk) =>
|
{
|
if (isOk)
|
{
|
model.SendBackHazyRegion();
|
}
|
});
|
break;
|
default:
|
model.SendBackHazyRegion();
|
break;
|
}
|
}
|
|
private void DisplayGotoState()
|
{
|
var questState = dailyQuestModel.GetQuestState((int)DailyQuestType.HazyRegion);
|
m_Goto.SetColorful(m_GotoLabel, questState != DailyQuestModel.DailyQuestState.OutTime);
|
}
|
|
private void Goto()
|
{
|
var error = 0;
|
if (!model.TryGotoIncident(model.selectIncident, true, out error))
|
{
|
model.DisplayErrorRemind(error);
|
}
|
else
|
{
|
var config = HazyRegionConfig.Get(model.selectIncident);
|
if (config.incidentType == (int)HazyRegionIncidentType.FairyGrass)
|
{
|
HazyRegionModel.Incident incident;
|
if (model.TryGetIncident(model.selectIncident, out incident))
|
{
|
if (incident.state == HazyRegionModel.IncidentState.UnStart)
|
{
|
var item = dungeonModel.GetTicketCost(config.dungeonId, config.lineId);
|
if (item.id != 0)
|
{
|
var itemConfig = ItemConfig.Get(item.id);
|
ConfirmCancel.ShowItemConfirm(Language.Get("HazyRegionFairyGrassTicket",
|
item.count, itemConfig.ItemName), item.id,
|
item.count, () =>
|
{
|
var count = packModel.GetItemCountByID(PackType.Item, item.id);
|
if (count >= item.count)
|
{
|
model.SendGotoIncident(model.selectIncident);
|
}
|
else
|
{
|
ItemTipUtility.Show(item.id);
|
}
|
});
|
return;
|
}
|
}
|
}
|
}
|
model.SendGotoIncident(model.selectIncident);
|
}
|
}
|
|
private void LateUpdate()
|
{
|
timer += Time.deltaTime;
|
if (timer >= 0.5f)
|
{
|
if (model.incidentDirty)
|
{
|
model.incidentDirty = false;
|
requestCount = 0;
|
requestTime = DateTime.Now;
|
SendRequestPlayerCount();
|
return;
|
}
|
timer = 0f;
|
if ((DateTime.Now - requestTime).TotalSeconds > 5
|
&& requestCount < 10)
|
{
|
SendRequestPlayerCount();
|
}
|
}
|
}
|
|
void SendRequestPlayerCount()
|
{
|
requestLines.Clear();
|
for (int i = 0; i < incidents.Count; i++)
|
{
|
var config = HazyRegionConfig.Get(incidents[i]);
|
if (config.incidentType != (int)HazyRegionIncidentType.DemonKing
|
|| config.dungeonType == 0)
|
{
|
continue;
|
}
|
if (findPreciousModel.IsBossAlive(config.npcId))
|
{
|
if (!requestLines.ContainsKey(config.dungeonId))
|
{
|
requestLines.Add(config.dungeonId, new List<byte>());
|
}
|
if (!requestLines[config.dungeonId].Contains((byte)config.lineId))
|
{
|
requestLines[config.dungeonId].Add((byte)config.lineId);
|
}
|
}
|
}
|
|
if (requestLines.Count > 0)
|
{
|
foreach (var mapId in requestLines.Keys)
|
{
|
var pak = new CA004_tagCGGetFBLinePlayerCnt();
|
pak.MapID = (uint)mapId;
|
pak.LineCount = (byte)requestLines[mapId].Count;
|
pak.LineIDList = requestLines[mapId].ToArray();
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
requestCount++;
|
requestTime = DateTime.Now;
|
}
|
}
|
|
private void RefreshDailyQuestState()
|
{
|
DisplayGotoState();
|
}
|
|
private void AnimationComplete()
|
{
|
//if (!NewBieCenter.Instance.IsGuideCompleted(58))
|
//{
|
// NewBieCenter.Instance.StartNewBieGuide(58);
|
//}
|
}
|
|
public void Dispose()
|
{
|
m_CyclicScroll.Dispose();
|
DailyQuestActionTimer.Instance.RefreshDailyQuestState -= RefreshDailyQuestState;
|
m_CyclicScroll.animationComplete -= AnimationComplete;
|
}
|
|
#if UNITY_EDITOR
|
void OnGUI()
|
{
|
if (GUILayout.Button("Back"))
|
{
|
OnBack();
|
}
|
}
|
#endif
|
}
|
}
|
|