源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
4.0 KiB

  1. CSMainMilitaryRanksRankView = CSMainMilitaryRanksRankView or BaseClass(BaseItem)
  2. local CSMainMilitaryRanksRankView = CSMainMilitaryRanksRankView
  3. function CSMainMilitaryRanksRankView:__init()
  4. self.base_file = "csMain"
  5. self.layout_file = "CSMainMilitaryRanksRankView"
  6. self.model = CSMainModel:getInstance()
  7. self.mainVo = RoleManager.Instance.mainRoleInfo
  8. self:Load()
  9. end
  10. function CSMainMilitaryRanksRankView:Load_callback()
  11. self.nodes = {
  12. "myCon/myName:tmp", "myCon/militarySmallIcon:img", "myCon/militaryBigIcon:img",
  13. "myCon/myVipCon", "myCon/myRankIcon:obj:img", "myCon/myContrayName:tmp", "myCon/mySex:img",
  14. "ScrollView", "ScrollView/Viewport/Content", "myCon/myRank:tmp",
  15. "empty:obj", "empty/emptyGirl:raw",
  16. }
  17. self:GetChildren(self.nodes)
  18. lua_resM:setOutsideRawImage(self, self.emptyGirl_raw, GameResPath.GetRoleBg("setting_girl"))
  19. self.myVipItem = RoleVipItem.New(self.myVipCon)
  20. self:AddEvents()
  21. if self.need_refreshData then
  22. self:RequesData()
  23. end
  24. end
  25. function CSMainMilitaryRanksRankView:AddEvents( )
  26. local function on_update_rank_view(vo)
  27. self:UpdateRankView(vo)
  28. end
  29. self:BindEvent(self.model, CSMainConst.UPDATE_MILITARY_RANKS_RANK_VIEW, on_update_rank_view)
  30. end
  31. function CSMainMilitaryRanksRankView:UpdateRankView(vo)
  32. local rank_data = vo and vo.ranks or {}
  33. local sort_func = function ( a, b )
  34. return a.rank < b.rank
  35. end
  36. table.sort(rank_data, sort_func)
  37. local final_rank_list = {}
  38. local max_show_ranks = Config.Legionkv["military_max_rank"].value
  39. for i=1,max_show_ranks do
  40. if rank_data[i] then
  41. table.insert(final_rank_list,rank_data[i])
  42. end
  43. end
  44. if not self.item_list_com then
  45. self.item_list_com = self:AddUIComponent(UI.ItemListCreator)
  46. end
  47. local info = {
  48. data_list = final_rank_list,
  49. item_con = self.Content,
  50. item_class = CSMainMilitaryRanksRankItem,
  51. item_width = 905,
  52. item_height = 50,
  53. -- space_x = 0,
  54. -- space_y = 0,
  55. start_x = 1.5,
  56. start_y = -1.5,
  57. scroll_view = self.ScrollView,
  58. create_frequency = 0.01,
  59. on_update_item = function(item, i, v)
  60. item:SetData(v)
  61. end,
  62. }
  63. self.item_list_com:UpdateItems(info)
  64. self.empty_obj:SetActive(#rank_data==0)
  65. self.myVipItem:SetData(self.mainVo.vip_flag,self.mainVo.sup_vip_type)
  66. self.myName_tmp.text = GetCSLongName(self.mainVo.name,self.mainVo.server_num)
  67. local sex_res = self.mainVo.sex == 1 and "com_boy" or "com_girl"
  68. lua_resM:setImageSprite(self, self.mySex_img, "common_asset", sex_res, true)
  69. SetAnchoredPositionX(self.mySex, -228+self.myName_tmp.preferredWidth+20)
  70. if vo.my_rank == 0 then
  71. self.myRankIcon_obj:SetActive(false)
  72. self.myRank_tmp.text = "未上榜"
  73. elseif vo.my_rank >= 1 and vo.my_rank <= 3 then
  74. lua_resM:setImageSprite(self, self.myRankIcon_img, "csMain_asset","cs_main_rank_"..vo.my_rank,true)
  75. self.myRankIcon_obj:SetActive(true)
  76. self.myRank_tmp.text = ""
  77. else
  78. self.myRankIcon_obj:SetActive(false)
  79. self.myRank_tmp.text = vo.my_rank
  80. end
  81. local my_country_id = KfWorldModel:GetInstance():GetMyCountryId() and KfWorldModel:GetInstance():GetMyCountryId() or 1
  82. local my_country_name = KfWorldModel:GetInstance():GetContrayNameById(my_country_id)
  83. self.myContrayName_tmp.text = my_country_name
  84. local my_military_ranks = self.model:GetCSMainMilitaryRanks()
  85. lua_resM:setOutsideImageSprite(self, self.militarySmallIcon_img, GameResPath.GetMilitaryImage("military_ranks_"..my_military_ranks), true)
  86. -- local high_military_ranks = self.model:GetCSMainHighMilitaryRanks(my_military_ranks)
  87. -- lua_resM:setOutsideImageSprite(self, self.militaryBigIcon_img, GameResPath.GetCSMainImage("military_ranks_big_icon_"..high_military_ranks), true)
  88. end
  89. function CSMainMilitaryRanksRankView:RequesData( )
  90. self.model:Fire(CSMainConst.REQUEST_CCMD_EVENT,60313)
  91. end
  92. function CSMainMilitaryRanksRankView:SetData()
  93. if self.is_loaded then
  94. self.need_refreshData = false
  95. self:RequesData()
  96. else
  97. self.need_refreshData = true
  98. end
  99. end
  100. function CSMainMilitaryRanksRankView:__delete( )
  101. if self.myVipItem then
  102. self.myVipItem:DeleteMe()
  103. self.myVipItem = nil
  104. end
  105. end