ServerListView.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System.Linq;
  2. using ET;
  3. using FairyGUI;
  4. using UI.Login;
  5. namespace GFGGame
  6. {
  7. public class ServerListView : BaseWindow
  8. {
  9. private UI_ServerListUI _ui;
  10. private ServerInfosComponent serverInfosComponent;
  11. public override void Dispose()
  12. {
  13. base.Dispose();
  14. }
  15. protected override void OnInit()
  16. {
  17. base.OnInit();
  18. _ui = UI_ServerListUI.Create();
  19. this.viewCom = _ui.target;
  20. this.viewCom.Center();
  21. this.modal = true;
  22. _ui.m_list.itemRenderer = ListItemRender;
  23. _ui.m_list.onClickItem.Add(OnListItemClick);
  24. _ui.m_list.SetVirtual();
  25. }
  26. protected override void OnShown()
  27. {
  28. base.OnShown();
  29. serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  30. if (serverInfosComponent.ServerInfoList.Count <= 0)
  31. {
  32. _ui.m_btnCurServer.target.visible = false;
  33. return;
  34. }
  35. ServerInfo recentlyServerInfo = serverInfosComponent.recentlyServerInfo;
  36. _ui.m_btnCurServer.m_txtTitle.text = string.Format("{0}区 {1}", NumberUtil.GetChiniseNumberText((int)recentlyServerInfo.Id), recentlyServerInfo.ServerName);
  37. _ui.m_list.numItems = serverInfosComponent.ServerInfoList.Count;
  38. }
  39. protected override void OnHide()
  40. {
  41. base.OnHide();
  42. }
  43. private void ListItemRender(int index, GObject obj)
  44. {
  45. UI_Button2 item = UI_Button2.Proxy(obj);
  46. ServerInfo serverInfo = serverInfosComponent.ServerInfoList.ElementAt(index).Value;
  47. item.m_txtTitle.text = string.Format("{0}区 {1}", NumberUtil.GetChiniseNumberText((int)serverInfo.Id), serverInfo.ServerName);
  48. if (serverInfo.Id == serverInfosComponent.CurrentServerId) item.target.selected = true;
  49. item.target.data = serverInfo.Id;
  50. }
  51. private void OnListItemClick(EventContext context)
  52. {
  53. long id = (long)(context.data as GObject).data;
  54. serverInfosComponent.CurrentServerId = (int)id;
  55. EventAgent.DispatchEvent(ConstMessage.SERVER_CHANGE);
  56. }
  57. }
  58. }