源战役客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

275 行
8.3 KiB

  1. CSMainExploitRankView = CSMainExploitRankView or BaseClass(BaseView)
  2. local CSMainExploitRankView = CSMainExploitRankView
  3. function CSMainExploitRankView:__init()
  4. self.base_file = "csMain"
  5. self.layout_file = "CSMainExploitRankView"
  6. self.layer_name = "Activity"
  7. self.destroy_imm = true
  8. self.use_background = true
  9. self.change_scene_close = true
  10. self.hide_maincancas = true --是否隐藏主界面
  11. self.append_to_ctl_queue = false --是否要添加进界面堆栈
  12. self.need_show_money = false --是否要显示顶部的金钱栏
  13. self.is_set_zdepth = true
  14. self.mainVo = RoleManager.Instance.mainRoleInfo
  15. self.tab_item_list = {}
  16. self.top_item_list = {}
  17. self.model = CSMainModel:getInstance()
  18. self.current_index = nil
  19. self.my_contray_id = KfWorldModel:GetInstance():GetMyCountryId()
  20. self.load_callback = function ()
  21. self:LoadSuccess()
  22. self:AddEvent()
  23. end
  24. self.open_callback = function ( )
  25. self:OpenSuccess()
  26. end
  27. self.destroy_callback = function ( )
  28. self:DestroySuccess()
  29. end
  30. end
  31. function CSMainExploitRankView:Open(index)
  32. self.current_index = index or 1
  33. BaseView.Open(self)
  34. end
  35. function CSMainExploitRankView:LoadSuccess()
  36. local nodes = {
  37. "closeBtn:obj", "bg:raw", "tabCon", "topbg:img",
  38. "myRankCon:obj", "myRankCon/myRankIcon:img:obj", "myRankCon/mySex:img",
  39. "myRankCon/myVipCon", "myRankCon/myRank:tmp", "myRankCon/myName:tmp", "myRankCon/myGuildName:tmp", "myRankCon/myScore:tmp",
  40. "rankScrollView", "rankScrollView/Viewport/rankContent",
  41. "topCon", "titleCon",
  42. "rewardBtn:obj", "rewardBtn/rewardRed:obj",
  43. "rankEmpty:obj", "rankEmpty/rankEmptyTalkBg:raw",
  44. "myRankCon/myMilitaryRank:img",
  45. }
  46. self:GetChildren(nodes)
  47. lua_resM:setOutsideRawImage(self,self.bg_raw,GameResPath.GetViewBigBg("cs_main_exploit_bg"))
  48. lua_resM:setOutsideRawImage(self, self.rankEmptyTalkBg_raw, GameResPath.GetRoleBg("empty_bg_small"))
  49. self.model:Fire(CSMainConst.REQUEST_CCMD_EVENT,60308)
  50. self.myVipItem = RoleVipItem.New(self.myVipCon)
  51. end
  52. function CSMainExploitRankView:AddEvent()
  53. local on_click = function ( click_obj )
  54. if self.closeBtn_obj == click_obj then
  55. self:Close()
  56. elseif self.rewardBtn_obj == click_obj then
  57. self.model:Fire(CSMainConst.OPEN_CS_MAIN_EXPLOIT_RANK_DAILY_REWARD_VIEW)
  58. end
  59. end
  60. AddClickEvent(self.closeBtn_obj, on_click)
  61. AddClickEvent(self.rewardBtn_obj, on_click)
  62. -- --60308
  63. -- local function on_update_rank_data_extra()
  64. -- end
  65. -- self:BindEvent(self.model, CSMainConst.UPDATE_EXPLOIT_RANK_DATA_EXTRA, on_update_rank_data_extra)
  66. --60307
  67. local function on_update_rank_con(vo)
  68. if self.current_contray_index and vo.fact == self.current_contray_index then
  69. self:UpdateRankCon(vo)
  70. end
  71. end
  72. self:BindEvent(self.model, CSMainConst.UPDATE_EXPLOIT_RANK_CON, on_update_rank_con)
  73. local function update_red_dot(tab_id)
  74. if not self.is_loaded then return end
  75. if tab_id == CSMainConst.RedType.DailyReward then
  76. self:RefreshRed()
  77. end
  78. end
  79. self:BindEvent(self.model, CSMainConst.ANS_UPDATE_RED_DOT, update_red_dot)
  80. local function CLICK_GET_WAY_ITEM( )
  81. self:Close()
  82. end
  83. self:BindEvent(GlobalEventSystem, EventName.CLICK_GET_WAY_ITEM, CLICK_GET_WAY_ITEM)
  84. end
  85. function CSMainExploitRankView:OpenSuccess()
  86. self:InitTab()
  87. self:RefreshRed()
  88. end
  89. function CSMainExploitRankView:RefreshRed( )
  90. local red = self.model:GetDailyRewardRed()
  91. self.rewardRed_obj:SetActive(red)
  92. end
  93. function CSMainExploitRankView:InitTab( )
  94. if not self.my_contray_id then return end
  95. local contray_list = KfWorldModel:GetInstance():GetContrayList()
  96. local tab_data = {}
  97. local first_data = {name = contray_list[self.my_contray_id], contray_id = self.my_contray_id}
  98. table.insert(tab_data, first_data)
  99. for i,v in ipairs(contray_list) do
  100. if i ~= self.my_contray_id then
  101. local temp = {name = v, contray_id = i}
  102. table.insert(tab_data, temp)
  103. end
  104. end
  105. local function call_back(tab_index,contray_id)
  106. self:SwitchTab(tab_index,contray_id)
  107. end
  108. for k,v in pairs(self.tab_item_list) do
  109. v:SetVisible(false)
  110. end
  111. for i,v in ipairs(tab_data) do
  112. local item = self.tab_item_list[i]
  113. if not item then
  114. item = CSMainExploitRankTab.New(self.tabCon)
  115. self.tab_item_list[i] = item
  116. end
  117. item:SetVisible(true)
  118. item:SetData(v,i,call_back)
  119. item:SetAnchoredPosition(-2, 41-(i-1)*(74-5))
  120. end
  121. for k,v in pairs(self.tab_item_list) do
  122. v:OnClick(self.current_index)
  123. end
  124. end
  125. function CSMainExploitRankView:SwitchTab( index,contray_id )
  126. self.current_index = index
  127. self.current_contray_index = contray_id
  128. self.model:Fire(CSMainConst.REQUEST_CCMD_EVENT,60307,contray_id)
  129. end
  130. function CSMainExploitRankView:UpdateRankCon(vo)
  131. if not self.my_contray_id then return end
  132. local is_my_contray = vo.fact == self.my_contray_id
  133. if is_my_contray then
  134. SetAnchoredPositionY(self.titleCon,73.5)
  135. SetSizeDeltaY(self.rankScrollView,275)
  136. SetAnchoredPositionY(self.rankScrollView,-82)
  137. lua_resM:setOutsideImageSprite(self, self.png_img, GameResPath.GetCSMainImage("cs_main_top_di_long"),true)
  138. else
  139. SetAnchoredPositionY(self.titleCon,112)
  140. SetSizeDeltaY(self.rankScrollView,305)
  141. SetAnchoredPositionY(self.rankScrollView,-58)
  142. lua_resM:setOutsideImageSprite(self, self.png_img, GameResPath.GetCSMainImage("cs_main_top_di_short"),true)
  143. end
  144. --排行榜
  145. local sort_func = function ( a, b )
  146. return a.rank < b.rank
  147. end
  148. table.sort(vo.ranks, sort_func)
  149. local final_rank_list = {}
  150. local max_show_ranks = Config.Legionkv["honor_max_rank"].value
  151. for i=1,max_show_ranks do
  152. if vo.ranks[i] then
  153. table.insert(final_rank_list,vo.ranks[i])
  154. end
  155. end
  156. if not self.item_list_com then
  157. self.item_list_com = self:AddUIComponent(UI.ItemListCreator)
  158. end
  159. self.item_list_com:Reset()
  160. local info = {
  161. data_list = final_rank_list,
  162. item_con = self.rankContent,
  163. item_class = CSMainExploitRankItem,
  164. item_width = 900,
  165. item_height = 50,
  166. -- space_x = 0,
  167. -- space_y = 0,
  168. start_x = 0,
  169. start_y = -0.5,
  170. scroll_view = self.rankScrollView,
  171. create_frequency = 0.01,
  172. on_update_item = function(item, i, v)
  173. item:SetData(v,i)
  174. end,
  175. }
  176. self.item_list_com:UpdateItems(info)
  177. self.rankEmpty_obj:SetActive(#vo.ranks == 0)
  178. --top5
  179. for k,v in pairs(self.top_item_list) do
  180. v:SetVisible(false)
  181. end
  182. for i=1,5 do
  183. local top_rank_data = vo.ranks and vo.ranks[i] or nil
  184. local item = self.top_item_list[i]
  185. if not item then
  186. item = CSMainExploitRankTopItem.New(self.topCon)
  187. self.top_item_list[i] = item
  188. end
  189. item:SetData(top_rank_data,i,is_my_contray)
  190. item:SetAnchoredPosition(CSMainConst.ExploitTopItemPos[i].main_pos_x, CSMainConst.ExploitTopItemPos[i].main_pos_y)
  191. item:SetVisible(true)
  192. end
  193. --我的排名
  194. if is_my_contray then
  195. lua_resM:setOutsideImageSprite(self, self.topbg_img, GameResPath.GetCSMainImage("cs_main_top_di_long"), true)
  196. self.myVipItem:SetData(self.mainVo.vip_flag,self.mainVo.sup_vip_type)
  197. self.myName_tmp.text = GetCSLongName(self.mainVo.name,self.mainVo.server_num)
  198. local sex_res = self.mainVo.sex == 1 and "com_boy" or "com_girl"
  199. lua_resM:setImageSprite(self, self.mySex_img, "common_asset", sex_res, true)
  200. SetAnchoredPositionX(self.mySex, -288+self.myName_tmp.preferredWidth+15)
  201. self.myGuildName_tmp.text = self.mainVo.guild_name ~= "" and self.mainVo.guild_name or "暂无社团"
  202. --拿到自己的排名
  203. local my_rank = vo.myrank
  204. local my_score = vo.myscore
  205. if my_rank == 0 then
  206. self.myRankIcon_obj:SetActive(false)
  207. self.myRank_tmp.text = "未上榜"
  208. elseif my_rank >= 1 and my_rank <= 5 then
  209. self.myRankIcon_obj:SetActive(true)
  210. self.myRank_tmp.text = ""
  211. lua_resM:setImageSprite(self, self.myRankIcon_img, "csMain_asset","cs_main_rank_"..my_rank,true)
  212. else
  213. self.myRankIcon_obj:SetActive(false)
  214. self.myRank_tmp.text = my_rank
  215. end
  216. self.myRankCon_obj:SetActive(true)
  217. self.myScore_tmp.text = my_score
  218. lua_resM:setOutsideImageSprite(self, self.myMilitaryRank_img, GameResPath.GetMilitaryImage("military_ranks_"..RoleManager.Instance.mainRoleInfo.military_ranks), true)
  219. else
  220. lua_resM:setOutsideImageSprite(self, self.topbg_img, GameResPath.GetCSMainImage("cs_main_top_di_short"), true)
  221. self.myRankCon_obj:SetActive(false)
  222. end
  223. end
  224. function CSMainExploitRankView:DestroySuccess( )
  225. for i, v in ipairs(self.tab_item_list) do
  226. v:DeleteMe()
  227. end
  228. self.tab_item_list = {}
  229. for i, v in ipairs(self.top_item_list) do
  230. v:DeleteMe()
  231. end
  232. self.top_item_list = {}
  233. if self.myVipItem then
  234. self.myVipItem:DeleteMe()
  235. self.myVipItem = nil
  236. end
  237. end