ServerListView.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. if (_ui != null)
  14. {
  15. _ui.Dispose();
  16. _ui = null;
  17. }
  18. base.Dispose();
  19. }
  20. protected override void OnInit()
  21. {
  22. base.OnInit();
  23. _ui = UI_ServerListUI.Create();
  24. this.viewCom = _ui.target;
  25. this.viewCom.Center();
  26. this.modal = true;
  27. _ui.m_list.itemRenderer = ListItemRender;
  28. _ui.m_list.onClickItem.Add(OnListItemClick);
  29. _ui.m_list.SetVirtual();
  30. }
  31. protected override void OnShown()
  32. {
  33. base.OnShown();
  34. serverInfosComponent = GameGlobal.zoneScene.GetComponent<ServerInfosComponent>();
  35. if (serverInfosComponent.ServerInfoList.Count <= 0)
  36. {
  37. _ui.m_btnCurServer.target.visible = false;
  38. return;
  39. }
  40. ServerInfo recentlyServerInfo = serverInfosComponent.recentlyServerInfo;
  41. _ui.m_btnCurServer.m_txtTitle.text = string.Format("{0}区 {1}", NumberUtil.GetChiniseNumberText((int)recentlyServerInfo.Id), recentlyServerInfo.ServerName);
  42. _ui.m_list.numItems = serverInfosComponent.ServerInfoList.Count;
  43. }
  44. protected override void OnHide()
  45. {
  46. base.OnHide();
  47. }
  48. private void ListItemRender(int index, GObject obj)
  49. {
  50. UI_Button2 item = UI_Button2.Proxy(obj);
  51. ServerInfo serverInfo = serverInfosComponent.ServerInfoList.ElementAt(index).Value;
  52. item.m_txtTitle.text = string.Format("{0}区 {1}", NumberUtil.GetChiniseNumberText((int)serverInfo.Id), serverInfo.ServerName);
  53. if (serverInfo.Id == serverInfosComponent.CurrentServerId) item.target.selected = true;
  54. item.target.data = serverInfo.Id;
  55. UI_Button2.ProxyEnd();
  56. }
  57. private void OnListItemClick(EventContext context)
  58. {
  59. long id = (long)(context.data as GObject).data;
  60. serverInfosComponent.CurrentServerId = (int)id;
  61. EventAgent.DispatchEvent(ConstMessage.SERVER_CHANGE);
  62. }
  63. }
  64. }