//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Tuesday, September 12, 2017
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
using UnityEngine.UI;
|
namespace vnxbqy.UI
|
{
|
|
public class FairyRequestWin : Window, SecondWindowInterface
|
{
|
private Button allAgreeBtn;
|
private Button allRefuseBtn;
|
private ScrollerController m_RequestCtrl;
|
private List<PlayerFairyData.FairyApply> applyList = new List<PlayerFairyData.FairyApply>();
|
|
public Button close { get; set; }
|
|
#region Built-in
|
protected override void BindController()
|
{
|
if (this is SecondWindowInterface)
|
{
|
var frame = this.GetComponentInChildren<SecondFrameLoader>();
|
frame.Create();
|
close = frame.GetComponentInChildren<Button>();
|
}
|
|
allAgreeBtn = transform.Find("AllAgreeBtn").GetComponent<Button>();
|
allRefuseBtn = transform.Find("AllRefuseBtn").GetComponent<Button>();
|
m_RequestCtrl = transform.Find("RequestListBGM/Controller").GetComponent<ScrollerController>();
|
}
|
|
protected override void AddListeners()
|
{
|
close.onClick.AddListener(OnRequestClose);
|
allAgreeBtn.onClick.AddListener(OnAllAgree);
|
allRefuseBtn.onClick.AddListener(OnAllRefuse);
|
m_RequestCtrl.OnRefreshCell += OnRefreshRequesCell;
|
}
|
|
protected override void OnPreOpen()
|
{
|
PlayerDatas.Instance.fairyData.OnRefreshApplyList += OnRefreshApplyList;
|
PlayerDatas.Instance.fairyData.OnRefreshFairyMine += OnRefreshFairyMine;
|
OnRefreshApplyList();
|
|
if (applyList.Count > 0)
|
{
|
CA402_tagCGViewFamilyRequestInfo pak = new CA402_tagCGViewFamilyRequestInfo();
|
GameNetSystem.Instance.SendInfo(pak);
|
}
|
}
|
|
protected override void OnAfterOpen()
|
{
|
}
|
|
protected override void OnPreClose()
|
{
|
}
|
|
protected override void OnAfterClose()
|
{
|
PlayerDatas.Instance.fairyData.OnRefreshApplyList -= OnRefreshApplyList;
|
PlayerDatas.Instance.fairyData.OnRefreshFairyMine -= OnRefreshFairyMine;
|
}
|
|
#endregion
|
|
private void OnRefreshFairyMine()
|
{
|
if (!PlayerDatas.Instance.fairyData.HasFairy
|
|| !PlayerDatas.Instance.fairyData.IsCanFunc(PlayerFairyData.LimitFunc.CanCall))
|
{
|
CloseImmediately();
|
}
|
}
|
private void OnRefreshFairyInfo()
|
{
|
PlayerFairyData.FairyData fairy = PlayerDatas.Instance.fairyData.fairy;
|
if (fairy == null) return;
|
if (PlayerDatas.Instance.fairyData.mine.FamilyLV < 2)
|
{
|
Close();
|
}
|
}
|
private void OnGenerateRequest()
|
{
|
m_RequestCtrl.Refresh();
|
for (int i = 0; i < applyList.Count; i++)
|
{
|
m_RequestCtrl.AddCell(ScrollerDataType.Normal, i);
|
}
|
m_RequestCtrl.Restart();
|
}
|
|
private void OnRefreshApplyList()
|
{
|
applyList.Clear();
|
List<PlayerFairyData.FairyApply> list = PlayerDatas.Instance.fairyData.GetApplyList();
|
if (list != null)
|
{
|
applyList.AddRange(list);
|
}
|
OnGenerateRequest();
|
}
|
|
private void OnRequestClose()
|
{
|
Close();
|
}
|
|
private void OnAllRefuse()
|
{
|
if (applyList.Count < 1) return;
|
HandleApply(0, false);
|
applyList.Clear();
|
OnGenerateRequest();
|
}
|
|
private void OnAllAgree()
|
{
|
if (applyList.Count < 1) return;
|
bool isOnline = false;
|
for (int i = 0; i < applyList.Count; i++)
|
{
|
if (applyList[i].IsOnLine == 1)
|
{
|
isOnline = true;
|
break;
|
}
|
}
|
if (!isOnline)
|
{
|
ServerTipDetails.DisplayNormalTip(Language.Get("L1097"));
|
return;
|
}
|
HandleApply(0, true);
|
}
|
|
private void OnRefreshRequesCell(ScrollerDataType type, CellView cell)
|
{
|
int index = cell.index;
|
if (index < applyList.Count)
|
{
|
PlayerFairyData.FairyApply apply = applyList[index];
|
Text text = cell.transform.Find("NameText").GetComponent<Text>();
|
text.text = apply.Name;
|
text = cell.transform.Find("LevelText").GetComponent<Text>();
|
text.text = apply.PlayerLV.ToString();
|
Button btn = cell.transform.Find("RefuseBtn").GetComponent<Button>();
|
btn.onClick.RemoveAllListeners();
|
btn.onClick.AddListener(() =>
|
{
|
OnRefuse(apply);
|
});
|
btn = cell.transform.Find("AgreeBtn").GetComponent<Button>();
|
btn.onClick.RemoveAllListeners();
|
btn.onClick.AddListener(() =>
|
{
|
OnAgree(apply);
|
});
|
}
|
}
|
|
private void OnRefuse(PlayerFairyData.FairyApply apply)
|
{
|
HandleApply(apply.PlayerID, false);
|
int index = applyList.IndexOf(apply);
|
if (index < applyList.Count && index >= 0)
|
{
|
applyList.RemoveAt(index);
|
OnGenerateRequest();
|
}
|
}
|
|
private void OnAgree(PlayerFairyData.FairyApply apply)
|
{
|
if (apply.IsOnLine == 0)
|
{
|
ServerTipDetails.DisplayNormalTip(Language.Get("L1096"));
|
return;
|
}
|
HandleApply(apply.PlayerID, true);
|
}
|
|
private void HandleApply(uint playerid, bool isOk)
|
{
|
PlayerFairyData.FairyData fairy = PlayerDatas.Instance.fairyData.fairy;
|
if (fairy == null) return;
|
FamilyConfig cfg = FamilyConfig.Get(fairy.FamilyLV);
|
if (cfg == null) return;
|
if (playerid == 0 && isOk)
|
{
|
if (applyList.Count > cfg.memberCnt - fairy.MemberCount)
|
{
|
ServerTipDetails.DisplayNormalTip(Language.Get("L1027"));
|
return;
|
}
|
}
|
else if (isOk)
|
{
|
if (cfg.memberCnt - fairy.MemberCount < 1)
|
{
|
ServerTipDetails.DisplayNormalTip(Language.Get("L1028"));
|
return;
|
}
|
}
|
CA403_tagCGJoinFamilyReply joinPack = new CA403_tagCGJoinFamilyReply();
|
joinPack.IsOK = isOk ? (byte)1 : (byte)0;
|
joinPack.TagPlayerID = playerid;
|
GameNetSystem.Instance.SendInfo(joinPack);
|
}
|
}
|
}
|