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;
|
|
List<int> incidents = new List<int>();
|
|
HazyRegionModel model { get { return ModelCenter.Instance.GetModel<HazyRegionModel>(); } }
|
|
private void Awake()
|
{
|
m_Back.AddListener(OnBack);
|
m_Goto.AddListener(Goto);
|
}
|
|
public void Display()
|
{
|
DisplayPoint();
|
DisplayIncidents();
|
DisplayBackButton();
|
}
|
|
void DisplayIncidents()
|
{
|
incidents.Clear();
|
incidents.AddRange(model.GetAllIncidents());
|
incidents.Sort(Compare);
|
|
if (incidents.Count > 0)
|
{
|
model.selectIncident = incidents[0];
|
}
|
|
m_CyclicScroll.Init(incidents);
|
|
if (model.requireIncidentAnimation)
|
{
|
m_CyclicScroll.DisplayAnimation();
|
model.requireIncidentAnimation = false;
|
}
|
}
|
|
void DisplayPoint()
|
{
|
m_ContainerPoint.gameObject.SetActive(!model.InFakeHazyRegion);
|
|
if (!model.InFakeHazyRegion)
|
{
|
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(!model.InFakeHazyRegion);
|
}
|
|
int Compare(int lhs, int rhs)
|
{
|
var lhs_config = HazyRegionConfig.Get(lhs);
|
var rhs_config = HazyRegionConfig.Get(rhs);
|
if (lhs_config.incidentType != rhs_config.incidentType)
|
{
|
return lhs_config.incidentType.CompareTo(rhs_config.incidentType);
|
}
|
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 Goto()
|
{
|
var error = 0;
|
if (!model.TryGotoIncident(model.selectIncident, out error))
|
{
|
model.DisplayErrorRemind(error);
|
}
|
else
|
{
|
model.SendGotoIncident(model.selectIncident);
|
}
|
}
|
|
public void Dispose()
|
{
|
m_CyclicScroll.Dispose();
|
}
|
|
#if UNITY_EDITOR
|
void OnGUI()
|
{
|
if (GUILayout.Button("Back"))
|
{
|
OnBack();
|
}
|
}
|
#endif
|
}
|
}
|