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

351 行
13 KiB

  1. CollectingActSubView = CollectingActSubView or BaseClass(BaseItem)
  2. function CollectingActSubView:__init(parent, prefab_asset, layer_name, index, base_type, sub_type, kind)
  3. self.base_file = "collectingAct"
  4. self.layout_file = "CollectingActSubView"
  5. self.layer_name = layer_name or "UI"
  6. self.data = nil
  7. self.cus_model = CustomActivityModel:getInstance()
  8. self.model = KFRevelModel:getInstance()
  9. self.exchange_list = {}
  10. self.exchange_item_list = {}
  11. self.show_num_index = nil
  12. self.base_type = CustomActivityModel.CustomActBaseType.KF_JI_ZI
  13. self.sub_type = sub_type
  14. self.act_type = self.cus_model:getActType(self.base_type,self.sub_type)
  15. self.grade = nil
  16. self.mod_id = nil
  17. self.counter_id = nil
  18. self.counter2index = {}
  19. -- self.use_local_view = true
  20. self:Load()
  21. end
  22. function CollectingActSubView:Load_callback()
  23. self.txtScroll
  24. = GetChildGameObjects(self.transform,
  25. {
  26. "title/txtScroll",
  27. })
  28. self.scroll,
  29. self.item_con,
  30. self.txt_content,
  31. self.title
  32. = GetChildTransforms(self.transform,
  33. {
  34. "scrollView",
  35. "scrollView/Viewport/Content",
  36. "title/txtScroll/Viewport/Content",
  37. "title",
  38. })
  39. self.time,
  40. self.desc,
  41. self.time_txt,
  42. self.desc_txt,
  43. self.leftTime_txt,
  44. self.leftTime
  45. = GetChildTexts(self.transform,
  46. {
  47. "title/time/val",
  48. "title/desc/val",
  49. "title/time",
  50. "title/desc",
  51. "title/leftTime",
  52. "title/leftTime/text",
  53. })
  54. self.bg,
  55. self.bg2,
  56. self.left_bg,
  57. self.left_bg2
  58. = GetChildImages(self.transform,
  59. {
  60. "bg",
  61. "bg2",
  62. "left_bg",
  63. "left_bg2",
  64. })
  65. self.time_parent_outline = self.time_txt.transform:GetComponent("Outline")
  66. self.desc_parent_outline = self.desc_txt.transform:GetComponent("Outline")
  67. self.time_outline = self.time.transform:GetComponent("Outline")
  68. self.desc_outline = self.desc.transform:GetComponent("Outline")
  69. -- self.transform.localPosition = Vector2(-542, 290)
  70. local color = Color(219/255, 98/255, 77/255, 1)
  71. if self.act_type and self.act_type == Config.ConfigActStatic.ActType.OPEN then
  72. -- lua_resM:setOutsideImageSprite(self,self.bg,GameResPath.GetJpgImage("bg_kfColllecting"),false)
  73. -- lua_resM:setOutsideImageSprite(self,self.left_bg,GameResPath.GetKFActivityImage("kfCollecting_leftBg"),false)
  74. -- lua_resM:setOutsideImageSprite(self,self.left_bg,GameResPath.GetKFRevelActImage("kfkh_qtws"))
  75. lua_resM:setOutsideImageSprite(self, self.left_bg, GameResPath.GetKFRevelActImage("kfkh_jz_bg1"), false)
  76. -- self.scroll.transform.sizeDelta = Vector2(725,422)
  77. -- self.scroll.transform.anchoredPosition = co.TableXYZ(12.5, -128, 0)
  78. -- self.txtScroll:SetActive(true)
  79. self.time_txt.gameObject:SetActive(true)
  80. self.desc_txt.gameObject:SetActive(true)
  81. -- self.leftTime_txt.gameObject:SetActive(true)
  82. lua_resM:setOutsideImageSprite(self, self.bg2, GameResPath.GetKFRevelActImage("kfkh_jz_bg"), false)
  83. elseif self.act_type and self.act_type == Config.ConfigActStatic.ActType.RUN then
  84. self.title.anchoredPosition = co.TableXYZ(-53.6, 180, 0)
  85. self.item_con.sizeDelta = co.TableXY(816, self.item_con.sizeDelta.y)
  86. self.grid_layout = self.item_con:GetComponent("GridLayoutGroup")
  87. self.grid_layout.cellSize = Vector2(816, 105)
  88. self.grid_layout.spacing = Vector2(0, 1)
  89. self.scroll.transform.sizeDelta = Vector2(816,345)
  90. self.scroll.transform.anchoredPosition = Vector2(74,-178)
  91. self.transform.anchoredPosition = co.TableXYZ(0,0,0)
  92. self.bg.transform.sizeDelta = co.TableXY(861, 538)
  93. self.bg.transform.anchoredPosition = co.TableXYZ(0,0,0)
  94. lua_resM:setImageSprite(self, self.bg, "operateActivity_asset", "jcui_wpl_bg", false)
  95. self.bg2.transform.sizeDelta = co.TableXY(828, 140)
  96. self.bg2.transform.anchoredPosition = co.TableXYZ(0, 183, 0)
  97. lua_resM:setOutsideImageSprite(self, self.bg2, GameResPath.GetOperateActImage("jcui_xc8"), false)
  98. self.bg.gameObject:SetActive(true)
  99. self.bg2.gameObject:SetActive(true)
  100. self.time_txt.gameObject:SetActive(true)
  101. self.desc_txt.gameObject:SetActive(true)
  102. self.leftTime_txt.gameObject:SetActive(true)
  103. self.time_txt.transform.anchoredPosition = co.TableXYZ(-291, 60, 0)
  104. self.desc_txt.transform.anchoredPosition = co.TableXYZ(-291, 33, 0)
  105. self.leftTime_txt.transform.anchoredPosition = co.TableXYZ(-291, self.leftTime_txt.transform.anchoredPosition.y, 0)
  106. -- lua_resM:setImageSprite(self, self.left_bg2, "common_asset", "tyui_05b")
  107. self.left_bg2.transform.sizeDelta = co.TableXY(830, 357)
  108. self.left_bg2.transform.anchoredPosition = co.TableXYZ(0, -72, 0)
  109. self.left_bg2.gameObject:SetActive(true)
  110. self.desc.transform.sizeDelta = co.TableXY(780, 50)
  111. self.desc.transform.anchoredPosition = co.TableXYZ(344, -38, 0)
  112. color = Color(184/255, 81/255, 57/255, 1)
  113. end
  114. self.time_parent_outline.effectColor = color
  115. self.desc_parent_outline.effectColor = color
  116. self.time_outline.effectColor = color
  117. self.desc_outline.effectColor = color
  118. self:InitEvent()
  119. self:GetRewardList()
  120. if self.need_refreshData then
  121. self:RealSetData()
  122. end
  123. end
  124. function CollectingActSubView:InitEvent()
  125. local function updateExchange(data)
  126. if data == nil then return end
  127. if data.base_type == self.base_type and data.sub_type == self.sub_type then
  128. local index = self.counter2index[data.mod_id][data.counter_id]
  129. if index and self.exchange_item_list[index] then
  130. -- self.exchange_item_list[index]:SetText(data.count)
  131. end
  132. end
  133. end
  134. self.update_exchange_event_id = self.cus_model:Bind(CustomActivityModel.UPDATE_COLLECTING_EXCHANGE_NUM,updateExchange)
  135. local function updateItem(base_type, sub_type)
  136. -- if base_type and sub_type and self.base_type and self.sub_type and self.base_type == base_type and self.sub_type == sub_type then
  137. local list = self.cus_model.jizi_today_max_num_list
  138. for k,v in pairs(self.exchange_list) do
  139. if list then
  140. local vo
  141. for i,j in pairs(list) do
  142. if j and j.grade and v and v.grade and j.grade == v.grade then
  143. vo = j
  144. end
  145. end
  146. if vo and self.exchange_item_list[k] then
  147. self.exchange_item_list[k]:SetText2("今日可兑换:"..(vo.max_times - vo.receive_times))
  148. end
  149. end
  150. end
  151. -- end
  152. end
  153. -- self.update_item_id = self.model:Bind(KFRevelModel.UPDATE_KF_VIEW_RED_SHOW, updateItem)
  154. self.update_item_id = self.cus_model:Bind(CustomActivityModel.UPDATE_ZIJI_MAXNUM, updateItem)
  155. local function requestExchangeNum(data)
  156. if data == nil or data.base_type ~= self.base_type or data.sub_type ~= self.sub_type then return end
  157. if self.base_type and self.sub_type then
  158. -- for i,v in ipairs(self.exchange_list) do
  159. -- if v.mod_id and v.counter_id then
  160. -- self.cus_model:Fire(CustomActivityModel.PROTO_CCMD_EVENT,33106,self.base_type,self.sub_type,v.mod_id,v.counter_id)
  161. -- end
  162. -- end
  163. self.cus_model:Fire(CustomActivityModel.PROTO_CCMD_EVENT, 33129, self.sub_type)
  164. end
  165. end
  166. self.request_exchange_event_id = self.cus_model:Bind(CustomActivityModel.REQUEST_COLLECTING_EXCHANGE_NUM,requestExchangeNum)
  167. end
  168. function CollectingActSubView:GetRewardList()
  169. local vo = self.cus_model:getActList(self.base_type,self.sub_type)
  170. local data = self.cus_model:getOneActRewardList(self.base_type,self.sub_type)
  171. if data == nil then return end
  172. self.exchange_list = data.reward_list
  173. table.sort(self.exchange_list,function(a,b) return a.grade > b.grade end)
  174. for i,v in ipairs(self.exchange_list) do
  175. if v.condition_list[1][3] ~= nil and tonumber(v.condition_list[1][3]) ~= 0 and v.condition_list[1][4] ~= nil and tonumber(v.condition_list[1][4]) ~= 0 then
  176. v.mod_id = tonumber(v.condition_list[1][3])
  177. v.counter_id = tonumber(v.condition_list[1][4])
  178. self.counter2index[v.mod_id]={}
  179. self.counter2index[v.mod_id][v.counter_id] = i
  180. end
  181. end
  182. end
  183. -- 开服活动调的是setData()方法
  184. function CollectingActSubView:setData()
  185. self:RealSetData()
  186. end
  187. -- 运营活动调的是SetData()方法
  188. function CollectingActSubView:SetData()
  189. self:RealSetData()
  190. end
  191. function CollectingActSubView:RealSetData()
  192. if not self.is_loaded then
  193. self.need_refreshData = true
  194. return
  195. end
  196. local len = #self.exchange_list
  197. for i = 1,len do
  198. if self.exchange_item_list[i] == nil then
  199. self.exchange_item_list[i] = ClActExchangeItem.New(self.item_con)
  200. end
  201. self.exchange_item_list[i]:SetData(self.exchange_list[i], self.base_type, self.sub_type)
  202. --self.exchange_item_list[i]:SetText()
  203. end
  204. local act_data = self.cus_model:getActList(self.base_type,self.sub_type)
  205. if act_data == nil then return end
  206. local start_time = TimeUtil:timeConversion(act_data.stime,"yyyy年mm月dd日 hh-MM")
  207. local end_time = TimeUtil:timeConversion(act_data.etime,"yyyy年mm月dd日 hh-MM")
  208. -- self.time.text = "<color=".."#a77755"..">"..start_time.." ~ "..end_time.."</color>"
  209. -- self.desc.text = "<color=".."#a77755"..">"..act_data.desc.."</color>"
  210. -- self.time.transform.parent.gameObject:SetActive(false)
  211. -- self.desc.transform.parent.gameObject:SetActive(false)
  212. if self.act_type and self.act_type == Config.ConfigActStatic.ActType.OPEN then
  213. -- if not self.has_set_data then
  214. -- local total_vo = {}
  215. -- local text_vo = {text = "<color=#835741>【活动时间】</color>", fontSize = 22, offset_x = 0}
  216. -- table.insert(total_vo, text_vo)
  217. -- text_vo = {text = "<color=#a77755>"..start_time.." ~ "..end_time.."</color>", fontSize = 20, offset_x = 20}
  218. -- table.insert(total_vo, text_vo)
  219. -- text_vo = {text = "<color=#835741>【活动介绍】</color>", fontSize = 22, offset_x = 0}
  220. -- table.insert(total_vo, text_vo)
  221. -- text_vo = {text = "<color=#a77755>"..act_data.desc.."</color>", fontSize = 20, offset_x = 20}
  222. -- table.insert(total_vo, text_vo)
  223. -- self:SetScrollText(self.txt_content, total_vo)
  224. -- end
  225. self.time.text = start_time.." ~ "..end_time
  226. self.desc.text = act_data.desc
  227. elseif self.act_type and self.act_type == Config.ConfigActStatic.ActType.RUN then
  228. self.time.text = start_time.." ~ "..end_time
  229. self.desc.text = act_data.desc
  230. -- self.leftTime.text = TimeUtil:timeConvert9(act_data.etime-act_data.stime)--TimeUtil:timeConvert12(act_data.etime-act_data.stime)
  231. self:StartTimer(act_data)
  232. end
  233. if self.base_type and self.sub_type then
  234. -- for i,v in ipairs(self.exchange_list) do
  235. -- if v.mod_id and v.counter_id then
  236. -- self.cus_model:Fire(CustomActivityModel.PROTO_CCMD_EVENT,33106,self.base_type,self.sub_type,v.mod_id,v.counter_id)
  237. -- end
  238. -- end
  239. self.cus_model:Fire(CustomActivityModel.PROTO_CCMD_EVENT, 33129, self.sub_type)
  240. end
  241. end
  242. function CollectingActSubView:StartTimer(act_data)
  243. if act_data then
  244. local function timer_func()
  245. local rest_time = act_data.etime - act_data.stime
  246. if rest_time and rest_time > 0 then
  247. local day = math.floor(rest_time / (24*60*60))
  248. local hour = math.floor((rest_time % (24*60*60)) / (60*60))
  249. local min = math.floor(((rest_time % (24*60*60)) % (60*60)) / 60)
  250. if day == 0 and hour == 0 and min == 0 then
  251. self.leftTime.text = string.format("0分%d秒", rest_time)
  252. else
  253. self.leftTime.text = string.format("%d天%d时%d分", day, hour, min)
  254. end
  255. else
  256. self:CancelTimer()
  257. end
  258. end
  259. if not self.timer then
  260. self.timer = GlobalTimerQuest:AddPeriodQuest(timer_func, 1)
  261. end
  262. timer_func()
  263. end
  264. end
  265. function CollectingActSubView:CancelTimer()
  266. self.leftTime.text = "活动已结束"
  267. if self.timer then
  268. GlobalTimerQuest:CancelQuest(self.timer)
  269. self.timer = nil
  270. end
  271. end
  272. function CollectingActSubView:__delete()
  273. if self.request_exchange_event_id then
  274. self.cus_model:UnBind(self.request_exchange_event_id)
  275. self.request_exchange_event_id = nil
  276. end
  277. if self.update_exchange_event_id then
  278. self.cus_model:UnBind(self.update_exchange_event_id)
  279. self.update_exchange_event_id = nil
  280. end
  281. if self.update_item_id then
  282. self.cus_model:UnBind(self.update_item_id)
  283. self.update_item_id = nil
  284. end
  285. for k,v in pairs(self.exchange_item_list) do
  286. v:DeleteMe()
  287. v = nil
  288. end
  289. self.exchange_item_list = {}
  290. end
  291. -- function CollectingActSubView:SetScrollText(parent_trans, total_vo)
  292. -- if not parent_trans and not total_vo and #total_vo < 0 then return end
  293. -- self.text_item = {}
  294. -- local len = #total_vo
  295. -- local offset_y = 0
  296. -- for i = 1, len do
  297. -- local text_root
  298. -- local text_txt
  299. -- text_root = UiFactory.createChild(self.txt_content, UIType.Label, "label")
  300. -- text_txt = text_root:GetComponent("Text")
  301. -- text_txt.text = total_vo[i].text
  302. -- text_root.transform.pivot = Vector2(0,1)
  303. -- text_root.transform.anchorMin = Vector2(0, 1)
  304. -- text_root.transform.anchorMax = Vector2(0, 1)
  305. -- text_txt.alignment = UnityEngine.TextAnchor.UpperLeft
  306. -- text_txt.fontSize = total_vo[i].fontSize
  307. -- text_root.transform.sizeDelta = co.TableXY(self.txt_content.sizeDelta.x - total_vo[i].offset_x, text_txt.preferredHeight)
  308. -- text_root.transform.localPosition = co.TableXYZ(total_vo[i].offset_x, offset_y, 0)
  309. -- offset_y = offset_y + text_txt.preferredHeight
  310. -- table.insert(self.text_item, text_root)
  311. -- end
  312. -- self.txt_content.sizeDelta = co.TableXY(self.txt_content.sizeDelta.x, offset_y)
  313. -- self:ReSetPos(self.text_item, total_vo)
  314. -- end
  315. -- function CollectingActSubView:ReSetPos(text_item, total_vo)
  316. -- if not text_item and not total_vo then return end
  317. -- local offset_y = 0
  318. -- for k,v in pairs(text_item) do
  319. -- if v then
  320. -- v.transform.localPosition = co.TableXYZ(total_vo[k].offset_x, offset_y, 0)
  321. -- local text_com = v:GetComponent("Text")
  322. -- offset_y = offset_y - text_com.preferredHeight
  323. -- end
  324. -- end
  325. -- self.has_set_data = true
  326. -- end