源战役客户端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

250 строки
7.7 KiB

4 недель назад
  1. -- <*
  2. -- @Author: msh
  3. -- @Description: 跨国团战公示界面view
  4. -- *>
  5. CSGWarShowView = CSGWarShowView or BaseClass(BaseView)
  6. local CSGWarShowView = CSGWarShowView
  7. function CSGWarShowView:__init()
  8. self.base_file = "CSGWar"
  9. self.layout_file = "CSGWarShowView"
  10. self.layer_name = "UI"
  11. self.destroy_imm = true
  12. self.use_background = G_USING_BG --全屏界面默认使用这个参数
  13. --self.hide_maincancas = true --全屏界面需要放开隐藏主UI
  14. self.change_scene_close = true
  15. self.append_to_ctl_queue = false --是否要添加进界面堆栈
  16. self.need_show_money = false --是否要显示顶部的金钱栏
  17. self.close_fog = true
  18. self.model = CSGWarModel:GetInstance()
  19. self.model:Fire(CSGWarConst.REQ_CSGWAR_SCMD, 60101)
  20. self.show_item_list = {}
  21. self.cur_area_index = 1 -- 只会是1
  22. self.load_callback = function ()
  23. self:LoadSuccess()
  24. self:AddEvent()
  25. end
  26. self.open_callback = function ( )
  27. self:OpenSuccess()
  28. end
  29. self.switch_callback = function(index)
  30. self:SwitchTab(index)
  31. end
  32. self.destroy_callback = function ( )
  33. self:DestroySuccess()
  34. end
  35. end
  36. function CSGWarShowView:Open( )
  37. --self.data = data
  38. BaseView.Open(self)
  39. self.model:SetLoginRed( false )
  40. end
  41. function CSGWarShowView:LoadSuccess()
  42. local nodes = {
  43. "tip_text:tmp",
  44. "title:img",
  45. "bg:obj:raw",
  46. "show_con/power_text:txt",
  47. "show_con/show_item_con",
  48. "show_con:obj",
  49. "show_con/occupy_server_text:tmp",
  50. "show_con/receive_image:obj:img",
  51. "show_con/guild_text:tmp",
  52. "show_con/name_text:tmp",
  53. "show_con/occupy_bg:obj",
  54. "show_con/occupy_text:tmp",
  55. "show_con/role_con",
  56. "show_con/reward_image:obj:img",
  57. "show_con/reward_red_image:obj",
  58. "pic_close:obj",
  59. }
  60. self:GetChildren(nodes)
  61. self:UpdateBaseView( )
  62. end
  63. function CSGWarShowView:UpdateBaseView( )
  64. lua_resM:setOutsideRawImage(self,self.bg_raw,GameResPath.GetViewBigBg("CSGWar_show_bg_1044_540"),false)
  65. lua_resM:setOutsideImageSprite(self,self.title_img,GameResPath.GetCSGWarImage("CSGWar_show_title"),false)
  66. local function bg_back_func( ... )
  67. if self.background_wnd and self.background_wnd:GetComponent("RawImageExtend") then
  68. self:MoveUIToBack(self.background_wnd:GetComponent("RawImageExtend"))
  69. end
  70. self:MoveUIToBack(self.bg)
  71. self:MoveUIToBack(self.title)
  72. end
  73. if self.background_wnd then
  74. bg_back_func()
  75. else
  76. self.bg_back_func = bg_back_func
  77. end
  78. end
  79. function CSGWarShowView:AddEvent()
  80. local on_click = function ( click_obj )
  81. if self.pic_close_obj == click_obj then
  82. self:Close()
  83. elseif click_obj == self.reward_image_obj then
  84. self.model:Fire(CSGWarConst.REQ_CSGWAR_SCMD, 60107, self.cur_area_index, 1)
  85. end
  86. end
  87. AddClickEvent(self.pic_close_obj, on_click)
  88. AddClickEvent(self.reward_image_obj, on_click)
  89. local function on_update_show_item( )
  90. self:UpdateShowItem()
  91. self:UpdateCentralInfo()
  92. self:UpdateRedDot()
  93. end
  94. self.on_update_show_item_id = self.model:BindOne("CSGWar_occupy_info", on_update_show_item)
  95. local function on_update_red( )
  96. self:UpdateRedDot()
  97. end
  98. self.on_update_red_id = self.model:Bind(CSGWarConst.ANS_CSGWAR_RED, on_update_red)
  99. end
  100. function CSGWarShowView:OpenSuccess()
  101. self:UpdateView()
  102. end
  103. function CSGWarShowView:UpdateView()
  104. -- local str = ChuanWenManager:getInstance():FormatColorTag2(CSGWarConst.TIP_DESC, true)
  105. -- self.tip_text_tmp.text = str
  106. -- SetAnchoredPosition(self.tip_text, -262, -190)
  107. self:UpdateShowItem()
  108. self:UpdateCentralInfo()
  109. self:SetTimerShow()
  110. self:UpdateRedDot()
  111. end
  112. function CSGWarShowView:UpdateShowItem( )
  113. local data = self.model:GetCSGWarOccupyInfo() or {}
  114. local x_offset = 352
  115. local y_offset = 208
  116. for i=1,4 do
  117. local item = self.show_item_list[i]
  118. if not item then
  119. item = CSGWarShowItem.New(self.show_item_con)
  120. item:SetPosition((i - 1) % 2 * x_offset-6, -math.floor((i - 1) / 2) * y_offset+8)
  121. self.show_item_list[i] = item
  122. end
  123. item:SetData(data[i+1], i, self.cur_area_index)
  124. end
  125. end
  126. --更新中心城区信息
  127. function CSGWarShowView:UpdateCentralInfo( )
  128. local data = self.model:GetCSGWarOccupyInfo() or {}
  129. if data[1] then
  130. local guild_str = GetCSLongName(data[1].guild_name, data[1].server_num, false, ColorUtil.GREEN_DARK)
  131. local boss_str = string.format("%s %s", HtmlColorTxt("团长:", ColorUtil.YELLOW_DARK), data[1].chief_name)
  132. local str = string.format("%s\n%s", guild_str, boss_str)
  133. self.occupy_text_tmp.text = str
  134. -- self.occupy_server_text_tmp.text = GetCSLongName("服", data[1].server_num, true)
  135. self.occupy_server_text_tmp.text = KfWorldModel:GetInstance():GetContrayNameById(data[1].fact_id)
  136. local server_id = RoleManager.Instance.mainRoleInfo.server_id
  137. self.reward_image_obj:SetActive(server_id == data[1].server_id)
  138. self.receive_image_obj:SetActive(data[1].is_received_reward == 1)
  139. if data[1].is_received_reward == 1 then
  140. lua_resM:setImageSprite(self, self.reward_image_img, "CSGWar_asset", "CSGWar_item3")
  141. else
  142. lua_resM:setImageSprite(self, self.reward_image_img, "CSGWar_asset", "CSGWar_item2")
  143. end
  144. self.guild_text_tmp.text = guild_str
  145. self.name_text_tmp.text = boss_str
  146. self.power_text_txt.text = "f"..data[1].chief_power
  147. self:SetRoleModel(data[1].chief_id)
  148. else
  149. local guild_str = "暂无占领"
  150. local boss_str = "团长: 暂无"
  151. local str = string.format("%s\n%s", guild_str, boss_str)
  152. self.occupy_text_tmp.text = str
  153. self.occupy_server_text_tmp.text = "暂无占领"
  154. self.receive_image_obj:SetActive(false)
  155. self.reward_image_obj:SetActive(false)
  156. self.guild_text_tmp.text = guild_str
  157. self.name_text_tmp.text = boss_str
  158. self.power_text_txt.text = ""
  159. self:SetRoleModel()
  160. end
  161. end
  162. function CSGWarShowView:SetRoleModel( role_id )
  163. role_id = role_id or 0
  164. self.role_id = role_id
  165. if role_id ~= 0 then
  166. SetLocalScale(self.role_con, 1, 1, 1)
  167. else
  168. SetLocalScale(self.role_con, 0.001, 0.001, 0.001)
  169. end
  170. local res_data = {
  171. father_node = self,
  172. transform = self.role_con,
  173. fashion_type = FuncOpenModel.TypeId.Clothes,
  174. size = Vector2(720,720),
  175. scale = 180,
  176. position = Vector3(90,-100,0),
  177. ui_model_type = UIModelCommon.ModelType.BackModel,
  178. }
  179. FuncOpenModel:getInstance():SetRoleModelByID(role_id, res_data)
  180. end
  181. -- 结束倒计时
  182. function CSGWarShowView:SetTimerShow()
  183. local _, end_show_time = self.model:NeedShowCSGWarResult()
  184. if end_show_time and end_show_time - TimeUtil:getServerTime() > 0 then
  185. local function onTimer()
  186. local sec = end_show_time - TimeUtil:getServerTime()
  187. if sec > 0 then
  188. self.tip_text_tmp.text = string.format("公示结束倒计时:<color=%s>%s</color>", ColorUtil.GREEN_DARK,TimeUtil:timeConvert6(sec, false))
  189. else
  190. self.tip_text_tmp.text = string.format("公示结束倒计时:<color=%s>已结束</color>",ColorUtil.RED_DARK)
  191. GlobalTimerQuest:CancelQuest(self.timer_id)
  192. self.timer_id = nil
  193. end
  194. end
  195. if not self.timer_id then
  196. self.timer_id = GlobalTimerQuest:AddPeriodQuest(onTimer, 1, -1)
  197. end
  198. else
  199. self.tip_text_tmp.text = string.format("公示结束倒计时:<color=%s>已结束</color>",ColorUtil.RED_DARK)
  200. end
  201. end
  202. function CSGWarShowView:UpdateRedDot( )
  203. local red_data = self.model:GetCSGWarRedData()
  204. if red_data.occupy_red and red_data.occupy_red_data[1] then
  205. self.reward_red_image_obj:SetActive(true)
  206. else
  207. self.reward_red_image_obj:SetActive(false)
  208. end
  209. end
  210. function CSGWarShowView:SwitchTab( index )
  211. end
  212. function CSGWarShowView:DestroySuccess( )
  213. for i,v in ipairs(self.show_item_list) do
  214. v:DeleteMe()
  215. v = nil
  216. end
  217. self.show_item_list = {}
  218. if self.timer_id then
  219. GlobalTimerQuest:CancelQuest(self.timer_id)
  220. self.timer_id = nil
  221. end
  222. if self.on_update_show_item_id then
  223. self.model:UnBind(self.on_update_show_item_id)
  224. self.on_update_show_item_id = nil
  225. end
  226. if self.on_update_red_id then
  227. self.model:UnBind(self.on_update_red_id)
  228. self.on_update_red_id = nil
  229. end
  230. end