|
|
- CollectingActSubView = CollectingActSubView or BaseClass(BaseItem)
-
- function CollectingActSubView:__init(parent, prefab_asset, layer_name, index, base_type, sub_type, kind)
- self.base_file = "collectingAct"
- self.layout_file = "CollectingActSubView"
- self.layer_name = layer_name or "UI"
- self.data = nil
- self.cus_model = CustomActivityModel:getInstance()
- self.model = KFRevelModel:getInstance()
- self.exchange_list = {}
- self.exchange_item_list = {}
- self.show_num_index = nil
- self.base_type = CustomActivityModel.CustomActBaseType.KF_JI_ZI
- self.sub_type = sub_type
- self.act_type = self.cus_model:getActType(self.base_type,self.sub_type)
- self.grade = nil
- self.mod_id = nil
- self.counter_id = nil
- self.counter2index = {}
- -- self.use_local_view = true
- self:Load()
- end
-
- function CollectingActSubView:Load_callback()
- self.txtScroll
- = GetChildGameObjects(self.transform,
- {
- "title/txtScroll",
- })
- self.scroll,
- self.item_con,
- self.txt_content,
- self.title
- = GetChildTransforms(self.transform,
- {
- "scrollView",
- "scrollView/Viewport/Content",
- "title/txtScroll/Viewport/Content",
- "title",
- })
-
- self.time,
- self.desc,
- self.time_txt,
- self.desc_txt,
- self.leftTime_txt,
- self.leftTime
- = GetChildTexts(self.transform,
- {
- "title/time/val",
- "title/desc/val",
- "title/time",
- "title/desc",
- "title/leftTime",
- "title/leftTime/text",
- })
-
- self.bg,
- self.bg2,
- self.left_bg,
- self.left_bg2
- = GetChildImages(self.transform,
- {
- "bg",
- "bg2",
- "left_bg",
- "left_bg2",
- })
- self.time_parent_outline = self.time_txt.transform:GetComponent("Outline")
- self.desc_parent_outline = self.desc_txt.transform:GetComponent("Outline")
- self.time_outline = self.time.transform:GetComponent("Outline")
- self.desc_outline = self.desc.transform:GetComponent("Outline")
- -- self.transform.localPosition = Vector2(-542, 290)
- local color = Color(219/255, 98/255, 77/255, 1)
- if self.act_type and self.act_type == Config.ConfigActStatic.ActType.OPEN then
- -- lua_resM:setOutsideImageSprite(self,self.bg,GameResPath.GetJpgImage("bg_kfColllecting"),false)
- -- lua_resM:setOutsideImageSprite(self,self.left_bg,GameResPath.GetKFActivityImage("kfCollecting_leftBg"),false)
- -- lua_resM:setOutsideImageSprite(self,self.left_bg,GameResPath.GetKFRevelActImage("kfkh_qtws"))
- lua_resM:setOutsideImageSprite(self, self.left_bg, GameResPath.GetKFRevelActImage("kfkh_jz_bg1"), false)
- -- self.scroll.transform.sizeDelta = Vector2(725,422)
- -- self.scroll.transform.anchoredPosition = co.TableXYZ(12.5, -128, 0)
- -- self.txtScroll:SetActive(true)
- self.time_txt.gameObject:SetActive(true)
- self.desc_txt.gameObject:SetActive(true)
- -- self.leftTime_txt.gameObject:SetActive(true)
- lua_resM:setOutsideImageSprite(self, self.bg2, GameResPath.GetKFRevelActImage("kfkh_jz_bg"), false)
- elseif self.act_type and self.act_type == Config.ConfigActStatic.ActType.RUN then
- self.title.anchoredPosition = co.TableXYZ(-53.6, 180, 0)
- self.item_con.sizeDelta = co.TableXY(816, self.item_con.sizeDelta.y)
- self.grid_layout = self.item_con:GetComponent("GridLayoutGroup")
- self.grid_layout.cellSize = Vector2(816, 105)
- self.grid_layout.spacing = Vector2(0, 1)
- self.scroll.transform.sizeDelta = Vector2(816,345)
- self.scroll.transform.anchoredPosition = Vector2(74,-178)
- self.transform.anchoredPosition = co.TableXYZ(0,0,0)
- self.bg.transform.sizeDelta = co.TableXY(861, 538)
- self.bg.transform.anchoredPosition = co.TableXYZ(0,0,0)
- lua_resM:setImageSprite(self, self.bg, "operateActivity_asset", "jcui_wpl_bg", false)
- self.bg2.transform.sizeDelta = co.TableXY(828, 140)
- self.bg2.transform.anchoredPosition = co.TableXYZ(0, 183, 0)
- lua_resM:setOutsideImageSprite(self, self.bg2, GameResPath.GetOperateActImage("jcui_xc8"), false)
- self.bg.gameObject:SetActive(true)
- self.bg2.gameObject:SetActive(true)
- self.time_txt.gameObject:SetActive(true)
- self.desc_txt.gameObject:SetActive(true)
- self.leftTime_txt.gameObject:SetActive(true)
- self.time_txt.transform.anchoredPosition = co.TableXYZ(-291, 60, 0)
- self.desc_txt.transform.anchoredPosition = co.TableXYZ(-291, 33, 0)
- self.leftTime_txt.transform.anchoredPosition = co.TableXYZ(-291, self.leftTime_txt.transform.anchoredPosition.y, 0)
- -- lua_resM:setImageSprite(self, self.left_bg2, "common_asset", "tyui_05b")
- self.left_bg2.transform.sizeDelta = co.TableXY(830, 357)
- self.left_bg2.transform.anchoredPosition = co.TableXYZ(0, -72, 0)
- self.left_bg2.gameObject:SetActive(true)
- self.desc.transform.sizeDelta = co.TableXY(780, 50)
- self.desc.transform.anchoredPosition = co.TableXYZ(344, -38, 0)
- color = Color(184/255, 81/255, 57/255, 1)
- end
- self.time_parent_outline.effectColor = color
- self.desc_parent_outline.effectColor = color
- self.time_outline.effectColor = color
- self.desc_outline.effectColor = color
-
- self:InitEvent()
- self:GetRewardList()
- if self.need_refreshData then
- self:RealSetData()
- end
- end
-
- function CollectingActSubView:InitEvent()
- local function updateExchange(data)
- if data == nil then return end
- if data.base_type == self.base_type and data.sub_type == self.sub_type then
- local index = self.counter2index[data.mod_id][data.counter_id]
- if index and self.exchange_item_list[index] then
- -- self.exchange_item_list[index]:SetText(data.count)
- end
- end
- end
- self.update_exchange_event_id = self.cus_model:Bind(CustomActivityModel.UPDATE_COLLECTING_EXCHANGE_NUM,updateExchange)
-
- local function updateItem(base_type, sub_type)
- -- 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
- local list = self.cus_model.jizi_today_max_num_list
- for k,v in pairs(self.exchange_list) do
- if list then
- local vo
- for i,j in pairs(list) do
- if j and j.grade and v and v.grade and j.grade == v.grade then
- vo = j
- end
- end
- if vo and self.exchange_item_list[k] then
- self.exchange_item_list[k]:SetText2("今日可兑换:"..(vo.max_times - vo.receive_times))
- end
- end
- end
- -- end
- end
- -- self.update_item_id = self.model:Bind(KFRevelModel.UPDATE_KF_VIEW_RED_SHOW, updateItem)
- self.update_item_id = self.cus_model:Bind(CustomActivityModel.UPDATE_ZIJI_MAXNUM, updateItem)
-
- local function requestExchangeNum(data)
- if data == nil or data.base_type ~= self.base_type or data.sub_type ~= self.sub_type then return end
- if self.base_type and self.sub_type then
- -- for i,v in ipairs(self.exchange_list) do
- -- if v.mod_id and v.counter_id then
- -- self.cus_model:Fire(CustomActivityModel.PROTO_CCMD_EVENT,33106,self.base_type,self.sub_type,v.mod_id,v.counter_id)
- -- end
- -- end
- self.cus_model:Fire(CustomActivityModel.PROTO_CCMD_EVENT, 33129, self.sub_type)
- end
- end
- self.request_exchange_event_id = self.cus_model:Bind(CustomActivityModel.REQUEST_COLLECTING_EXCHANGE_NUM,requestExchangeNum)
-
- end
-
- function CollectingActSubView:GetRewardList()
- local vo = self.cus_model:getActList(self.base_type,self.sub_type)
- local data = self.cus_model:getOneActRewardList(self.base_type,self.sub_type)
- if data == nil then return end
- self.exchange_list = data.reward_list
- table.sort(self.exchange_list,function(a,b) return a.grade > b.grade end)
- for i,v in ipairs(self.exchange_list) do
- 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
- v.mod_id = tonumber(v.condition_list[1][3])
- v.counter_id = tonumber(v.condition_list[1][4])
- self.counter2index[v.mod_id]={}
- self.counter2index[v.mod_id][v.counter_id] = i
- end
- end
- end
-
- -- 开服活动调的是setData()方法
- function CollectingActSubView:setData()
- self:RealSetData()
- end
-
- -- 运营活动调的是SetData()方法
- function CollectingActSubView:SetData()
- self:RealSetData()
- end
-
- function CollectingActSubView:RealSetData()
- if not self.is_loaded then
- self.need_refreshData = true
- return
- end
- local len = #self.exchange_list
- for i = 1,len do
- if self.exchange_item_list[i] == nil then
- self.exchange_item_list[i] = ClActExchangeItem.New(self.item_con)
- end
- self.exchange_item_list[i]:SetData(self.exchange_list[i], self.base_type, self.sub_type)
- --self.exchange_item_list[i]:SetText()
- end
-
-
- local act_data = self.cus_model:getActList(self.base_type,self.sub_type)
- if act_data == nil then return end
- local start_time = TimeUtil:timeConversion(act_data.stime,"yyyy年mm月dd日 hh-MM")
- local end_time = TimeUtil:timeConversion(act_data.etime,"yyyy年mm月dd日 hh-MM")
- -- self.time.text = "<color=".."#a77755"..">"..start_time.." ~ "..end_time.."</color>"
- -- self.desc.text = "<color=".."#a77755"..">"..act_data.desc.."</color>"
- -- self.time.transform.parent.gameObject:SetActive(false)
- -- self.desc.transform.parent.gameObject:SetActive(false)
- if self.act_type and self.act_type == Config.ConfigActStatic.ActType.OPEN then
- -- if not self.has_set_data then
- -- local total_vo = {}
- -- local text_vo = {text = "<color=#835741>【活动时间】</color>", fontSize = 22, offset_x = 0}
- -- table.insert(total_vo, text_vo)
- -- text_vo = {text = "<color=#a77755>"..start_time.." ~ "..end_time.."</color>", fontSize = 20, offset_x = 20}
- -- table.insert(total_vo, text_vo)
- -- text_vo = {text = "<color=#835741>【活动介绍】</color>", fontSize = 22, offset_x = 0}
- -- table.insert(total_vo, text_vo)
- -- text_vo = {text = "<color=#a77755>"..act_data.desc.."</color>", fontSize = 20, offset_x = 20}
- -- table.insert(total_vo, text_vo)
- -- self:SetScrollText(self.txt_content, total_vo)
- -- end
- self.time.text = start_time.." ~ "..end_time
- self.desc.text = act_data.desc
- elseif self.act_type and self.act_type == Config.ConfigActStatic.ActType.RUN then
- self.time.text = start_time.." ~ "..end_time
- self.desc.text = act_data.desc
- -- self.leftTime.text = TimeUtil:timeConvert9(act_data.etime-act_data.stime)--TimeUtil:timeConvert12(act_data.etime-act_data.stime)
- self:StartTimer(act_data)
- end
-
- if self.base_type and self.sub_type then
- -- for i,v in ipairs(self.exchange_list) do
- -- if v.mod_id and v.counter_id then
- -- self.cus_model:Fire(CustomActivityModel.PROTO_CCMD_EVENT,33106,self.base_type,self.sub_type,v.mod_id,v.counter_id)
- -- end
- -- end
- self.cus_model:Fire(CustomActivityModel.PROTO_CCMD_EVENT, 33129, self.sub_type)
- end
- end
-
- function CollectingActSubView:StartTimer(act_data)
- if act_data then
- local function timer_func()
- local rest_time = act_data.etime - act_data.stime
- if rest_time and rest_time > 0 then
- local day = math.floor(rest_time / (24*60*60))
- local hour = math.floor((rest_time % (24*60*60)) / (60*60))
- local min = math.floor(((rest_time % (24*60*60)) % (60*60)) / 60)
- if day == 0 and hour == 0 and min == 0 then
- self.leftTime.text = string.format("0分%d秒", rest_time)
- else
- self.leftTime.text = string.format("%d天%d时%d分", day, hour, min)
- end
- else
- self:CancelTimer()
- end
- end
- if not self.timer then
- self.timer = GlobalTimerQuest:AddPeriodQuest(timer_func, 1)
- end
- timer_func()
- end
- end
-
- function CollectingActSubView:CancelTimer()
- self.leftTime.text = "活动已结束"
- if self.timer then
- GlobalTimerQuest:CancelQuest(self.timer)
- self.timer = nil
- end
- end
-
- function CollectingActSubView:__delete()
- if self.request_exchange_event_id then
- self.cus_model:UnBind(self.request_exchange_event_id)
- self.request_exchange_event_id = nil
- end
-
- if self.update_exchange_event_id then
- self.cus_model:UnBind(self.update_exchange_event_id)
- self.update_exchange_event_id = nil
- end
-
- if self.update_item_id then
- self.cus_model:UnBind(self.update_item_id)
- self.update_item_id = nil
- end
-
- for k,v in pairs(self.exchange_item_list) do
- v:DeleteMe()
- v = nil
- end
- self.exchange_item_list = {}
- end
-
- -- function CollectingActSubView:SetScrollText(parent_trans, total_vo)
- -- if not parent_trans and not total_vo and #total_vo < 0 then return end
-
- -- self.text_item = {}
- -- local len = #total_vo
- -- local offset_y = 0
- -- for i = 1, len do
- -- local text_root
- -- local text_txt
- -- text_root = UiFactory.createChild(self.txt_content, UIType.Label, "label")
- -- text_txt = text_root:GetComponent("Text")
- -- text_txt.text = total_vo[i].text
- -- text_root.transform.pivot = Vector2(0,1)
- -- text_root.transform.anchorMin = Vector2(0, 1)
- -- text_root.transform.anchorMax = Vector2(0, 1)
- -- text_txt.alignment = UnityEngine.TextAnchor.UpperLeft
- -- text_txt.fontSize = total_vo[i].fontSize
- -- text_root.transform.sizeDelta = co.TableXY(self.txt_content.sizeDelta.x - total_vo[i].offset_x, text_txt.preferredHeight)
- -- text_root.transform.localPosition = co.TableXYZ(total_vo[i].offset_x, offset_y, 0)
- -- offset_y = offset_y + text_txt.preferredHeight
- -- table.insert(self.text_item, text_root)
- -- end
- -- self.txt_content.sizeDelta = co.TableXY(self.txt_content.sizeDelta.x, offset_y)
- -- self:ReSetPos(self.text_item, total_vo)
- -- end
-
- -- function CollectingActSubView:ReSetPos(text_item, total_vo)
- -- if not text_item and not total_vo then return end
-
- -- local offset_y = 0
- -- for k,v in pairs(text_item) do
- -- if v then
- -- v.transform.localPosition = co.TableXYZ(total_vo[k].offset_x, offset_y, 0)
- -- local text_com = v:GetComponent("Text")
- -- offset_y = offset_y - text_com.preferredHeight
- -- end
- -- end
- -- self.has_set_data = true
- -- end
|