ServerListView.cs 2.4 KB

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