123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- public class ClanInfoView : View {
- public Text nameText;
- public Text descText;
- public Button actionBtn;
- public Text actionBtnLabel;
- public Button editBtn;
- public Text editBtnLabel;
- public Text rankLabel;
- public Text rankText;
- public Text idLabe;
- public Text idText;
- public Text menberLabel;
- public Text menberText;
- public Text requireLabel;
- public Text requireText;
- public Text typeLabel;
- public Text typeText;
- public Transform menberContainer;
- public ClanMenberItem menberItemPrefab;
- private ClanData clanData;
- void Awake()
- {
- nameText.text = "";
- descText.text = "";
- rankLabel.text = Language.GetStr ("ClanPanel", "rankLabel");
- idLabe.text = Language.GetStr ("ClanPanel", "idLabel");
- menberLabel.text = Language.GetStr ("ClanPanel", "menberLabel");
- requireLabel.text = Language.GetStr ("ClanPanel", "requireLabel");
- typeLabel.text = Language.GetStr ("ClanPanel", "typeLabel");
- editBtnLabel.text = Language.GetStr ("ClanPanel", "edit");
- rankText.text = idText.text = menberText.text = requireText.text = typeText.text = "";
- menberItemPrefab.gameObject.SetActive (false);
- actionBtn.gameObject.SetActive (false);
- menberItemPrefab.clanInfoView = this;
- }
- protected override void OnInitCompleted ()
- {
- this.data = data;
- }
- public override object data {
- get {
- return base.data;
- }
- set {
- base.data = value;
- if (value != null && value is int) {
- SetClanId ((int)value);
- }
- }
- }
- private void SetClanId(int clanId)
- {
- if (initialized && clanId > 0) {
- actionBtn.gameObject.SetActive (false);
- editBtn.gameObject.SetActive (false);
- ProgressPanel.Show ();
- ClanManager.GetInstance ().GetClan (clanId, OnGetClan);
- }
- }
- private void OnGetClan(ClanData data)
- {
- ProgressPanel.Hide ();
- this.clanData = data;
- int myClanId = Session.GetInstance ().myUserData.clanId;
- if (myClanId == 0) {
- actionBtnLabel.text = Language.GetStr ("ClanPanel", "join");
- actionBtn.gameObject.SetActive (true);
- } else if (data.id == myClanId) {
- actionBtnLabel.text = Language.GetStr ("ClanPanel", "leave");
- actionBtn.gameObject.SetActive (true);
- } else {
- actionBtn.gameObject.SetActive (false);
- }
- editBtn.gameObject.SetActive (clanData.founder == Session.myUserId);
- nameText.text = data.name;
- descText.text = data.description;
- rankText.text = data.rank.ToString ();
- idText.text = data.id.ToString ();
- menberText.text = "" + data.amount + "/" + data.maxAmount;
- //requireText.text = data.
- typeText.text = data.GetLimitStr();
- int index = 0;
- if(data.userList != null)
- {
- for(int i=0; i<data.userList.Count; i++)
- {
- ClanMenberItem item = null;
- if (i >= menberContainer.childCount) {
- item = Instantiate<GameObject> (menberItemPrefab.gameObject).GetComponent<ClanMenberItem> ();
- PopUpManager.AddToMainCanvas (item.gameObject, menberContainer);
- } else {
- item = menberContainer.GetChild (i).GetComponent<ClanMenberItem> ();
- }
- item.gameObject.SetActive (true);
- item.SetUserData (data.userList [i]);
- index++;
- }
- }
- while(index < menberContainer.childCount)
- {
- menberContainer.GetChild (index).gameObject.SetActive (false);
- index++;
- }
- }
- public void ClanEdit()
- {
- if(clanData != null && clanData.founder == Session.myUserId)
- ClanPanel.ShowEdit();
- }
- public void ClanAction()
- {
- int myClanId = Session.GetInstance ().myUserData.clanId;
- if (myClanId == 0) {
- ClanRequest.Join (clanData.id).ResultEvent.AddListener((bool success, LitJson.JsonData data)=>{
- if(success)
- {
- int clanId = JsonUtil.ToInt(data);
- ClanManager.GetInstance().RemoveClan(clanId);
- Session.GetInstance().myUserData.clanId = clanId;
- ClanPanel.ShowClanInfo(clanId);
- Session.GetInstance().GetBattleSession().GetMessageManager().ClanJoin();
- }
- });
- } else if (clanData.id == myClanId) {
- ClanRequest.Leave ().ResultEvent.AddListener((bool success, LitJson.JsonData data)=>{
- if(success)
- {
- int clanId = JsonUtil.ToInt(data);
- ClanManager.GetInstance().RemoveClan(clanId);
- Session.GetInstance().myUserData.clanId = 0;
- ClanPanel.ShowClanInfo(0);
- Session.GetInstance().GetBattleSession().GetMessageManager().ClanLeft();
- }
- });
- }
- }
- public bool IsFounder()
- {
- if (clanData != null && clanData.founder == Session.myUserId)
- return true;
- return false;
- }
- public void Kick(int id, ClanMenberItem item)
- {
- if (!IsFounder ())
- return;
- string info = Language.GetStr ("ClanPanel", "kick").Replace ("%NICK%", UserCache.GetNick(id));
- AlertPanel.Show (info, AlertPanel.YES|AlertPanel.NO, (AlertCloseEvent evt) => {
- if(evt.detail == AlertPanel.YES)
- {
- ClanRequest.Kick (id, clanData.id).ResultEvent.AddListener((bool success, LitJson.JsonData data)=>{
- if(success)
- {
- item.transform.SetAsLastSibling();
- item.gameObject.SetActive(false);
- }
- });
- }
- });
- }
- }
|