|
|
- TreasureHouseView = TreasureHouseView or BaseClass(BaseView)
- local TreasureHouseView = TreasureHouseView
- --[[
- TreasureHouseView.TabData = {
- [1] = {name = "人物", level = MainRoleModel.TabOpenLevel[1]},
- }
- --]]
-
- function TreasureHouseView:__init()
- self.base_file = "treasureHouse"
- self.layout_file = "TreasureHouseView"
- self.layer_name = "UI"
- self.destroy_imm = true
- self.use_background = true --全屏界面默认使用这个参数
- self.hide_maincancas = true --全屏界面需要放开隐藏主UI
- self.change_scene_close = true
- self.append_to_ctl_queue = true --是否要添加进界面堆栈
- self.need_show_money = true --是否要显示顶部的金钱栏
- self:AddPreLoadList("treasureHouse", {"TreasureHouseRecordItem"})
- self.model = TreasureHouseModel:getInstance()
- self.model:Fire(TreasureHouseConst.REQ_TREASURE_HOUSE_SCMD, 10400)
- self.model:Fire(TreasureHouseConst.REQ_TREASURE_HOUSE_SCMD, 10403)
- self.model:Fire(TreasureHouseConst.REQ_TREASURE_HOUSE_SCMD, 10406)
- self.reward_item_list = {}
- self.reward_item_con = {}--item节点
- self.record_item_list = {}
- self.reward_count_item_list = {}--保底奖励列表
- self.is_not_show_action = false
- self.load_callback = function ()
- self:LoadSuccess()
- end
- self.open_callback = function ( )
- self:OpenSuccess()
- end
- self.switch_callback = function(index)
- self:SwitchTab(index)
- end
- self.destroy_callback = function ( )
- self:DestroySuccess()
- end
- end
-
- function TreasureHouseView:Open( )
- BaseView.Open(self)
- end
-
- function TreasureHouseView:LoadSuccess()
- local nodes = {
- "bg:raw", "one_btn:obj", "tip_text:tmp", "record_scroll/Viewport/record_con",
- "record_scroll", "reward_btn:obj", "task_scroll/Viewport/task_con", "cur_ratio_text:tmp",
- "task_scroll", "close_btn:obj", "ten_btn:obj", "progress_image:img", "Toggle:tog:obj",
- "reward_con", "role_con", "time_text:tmp", "goods_name_text:tmp",
- "con_money", "title_image", "cost_image2:img", "cost_text1:tmp", "cost_image1:img", "cost_text2:tmp",
- "num_text:txt", "di_image", "recordTips:tmp",
- }
- self:GetChildren(nodes)
- for i=1,15 do
- self.reward_item_con[i] = self:GetChild("item_con/item_con"..i)
- end
- self:AddEvent()
- self:CreateMoneyView()
- lua_resM:setOutsideRawImage(self,self.bg_raw,GameResPath.GetViewBigBg("treasureHouse_bg"),false)
- local goods_icon = GoodsModel:getInstance():GetGoodsBasicByTypeId( TreasureHouseConst.TREASURE_HOUSE_TICKET_ID ).goods_icon
- lua_resM:setOutsideImageSprite(self,self.cost_image1_img,GameResPath.GetGoodsIcon(goods_icon),false)
- lua_resM:setOutsideImageSprite(self,self.cost_image2_img,GameResPath.GetGoodsIcon(goods_icon),false)
- local str = ChuanWenManager:getInstance():FormatColorTag2(TreasureHouseConst.TIP_DESC, true)
- self.tip_text_tmp.text = str
- if self.model:IsTreasureHouseUpRatio() then
- local ratio = stringtotable(Config.Treasurehousekv["prob_up"].value)
- local ratio_str = HtmlColorTxt(string.format("大奖概率*%s%%",ratio[1][2]), ColorUtil.YELLOW_DARK )
- local str = string.format("当前加成:%s", ratio_str)
- self.cur_ratio_text_tmp.text = str
- else
- self.cur_ratio_text_tmp.text = "当前加成:无"
- end
- local function bg_back_func( ... )
- if self.background_wnd and self.background_wnd:GetComponent("RawImageExtend") then
- self:MoveUIToBack(self.background_wnd:GetComponent("RawImageExtend"))
- self:MoveUIToBack(self.bg_raw)
- self:MoveUIToBack(self.title_image)
- self:MoveUIToBack(self.di_image)
- end
- end
- if self.background_wnd then
- bg_back_func()
- else
- self.bg_back_func = bg_back_func
- end
- end
-
- function TreasureHouseView:AddEvent()
- local function on_click( target )
- if target == self.close_btn_obj then
- self:Close()
- elseif target == self.one_btn_obj then
- self:OnDrawBtnClick(1)
- elseif target == self.ten_btn_obj then
- self:OnDrawBtnClick(10)
- elseif target == self.Toggle_obj then
- self.is_not_show_action = not self.is_not_show_action
- elseif target == self.reward_btn_obj then
- self.model:Fire(TreasureHouseConst.OPEN_TREASURE_HOUSE_REWARD_VIEW)
- end
- end
- AddClickEvent(self.close_btn_obj, on_click)
- AddClickEvent(self.one_btn_obj, on_click)
- AddClickEvent(self.ten_btn_obj, on_click)
- AddClickEvent(self.Toggle_obj, on_click)
- AddClickEvent(self.reward_btn_obj, on_click)
- local function on_update_record_list( )
- self:UpdateRecordItemList()
- end
- self.on_update_record_list_id = self.model:BindOne("treasure_house_record_info", on_update_record_list)
- local function on_update_base_info( )
- self:UpdateCountRewardList()
- self:UpdateModel()
- end
- self.on_update_base_info_id = self.model:BindOne("treasure_house_base_info", on_update_base_info)
- local function on_update_task_info( )
- self:UpdateTaskItem()
- end
- self.on_update_task_info_id = self.model:BindOne("treasure_house_task_info", on_update_task_info)
- end
-
- function TreasureHouseView:OpenSuccess()
- self:UpdateView()
- end
-
- function TreasureHouseView:CreateMoneyView( )
- if not self.money_view then
- self.money_view = UIMoneyView.New(self.con_money)
- end
- self.money_view:SetPosition(0,0)
- self.money_view:SetData()
- self.money_view:ChangeShowFlag("treasureHouse",TreasureHouseConst.TREASURE_HOUSE_TICKET_ID)
- end
-
- function TreasureHouseView:UpdateView()
- self:UpdateRewardItem()
- self:UpdateTaskItem()
- self:UpdateRecordItemList()
- self:UpdateCountRewardList()
- self:UpdateModel()
- end
-
- function TreasureHouseView:UpdateRewardItem( )
- local data = self.model:GetTreasureHouseRewardList()
- for i=1,15 do
- local item = self.reward_item_list[i]
- if not item then
- item = TreasureHouseItem.New(self.reward_item_con[i])
- self.reward_item_list[i] = item
- end
- item:SetData(data[i], i)
- end
- end
-
- function TreasureHouseView:UpdateTaskItem( )
- local cfg = Config.Treasurehousetask
- local server_data = self.model:GetTreasureHouseTaskInfo()
- if not self.task_list_com then
- self.task_list_com = self:AddUIComponent(UI.ItemListCreator)
- end
- local info = {
- data_list = cfg,
- item_con = self.task_con,
- scroll_view = self.task_scroll,
- item_class = TreasureHouseTaskItem,
- start_y = 0, start_x = -2,
- create_frequency = 0.02,
- create_num_per_time = 3,
- item_height = 72,
- space_y = 2,
- on_update_item = function(item, i, v)
- item:SetData(i, v)
- item:SetServerData(server_data[v.id])
- end,
- }
- self.task_list_com:UpdateItems(info)
- end
-
- function TreasureHouseView:UpdateCountRewardList( )
- local period = 1
- local round = 1
- local base_info = self.model:GetTreasureHouseBaseInfo()
- local count_awards = base_info.count_awards or {}
- if TableSize(base_info) > 0 then
- period = base_info.curr_period
- local max_round = self.model:GetMaxRoundByPeriod(period)
- round = base_info.award_round > max_round and max_round or base_info.award_round
- end
- local data = self.model:GetTreasureHouseCFG(period,round)
- local sort_func = function ( a, b )
- return a.count < b.count
- end
- table.sort(data, sort_func)
- local x_offset = 85+30
- for i,v in ipairs(data) do
- local item = self.reward_count_item_list[i]
- if not item then
- item = TreasureHouseItem.New(self.reward_con)
- item:SetPosition((i-1)*x_offset, -2)
- self.reward_count_item_list[i] = item
- end
- item:SetData(v,i, true)
- item:SetServerData(count_awards[i])
- end
- self:UpdateProgress()
- self.time_text_tmp.text = self.model:GetTreasureTime()
- end
-
- function TreasureHouseView:UpdateProgress( )
- local base_info = self.model:GetTreasureHouseBaseInfo()
- local num = 0
- local cfg_data = DeepCopy(self.model:GetTreasureHouseCFG(1,1))
- if TableSize(base_info) > 0 then
- local max_round = self.model:GetMaxRoundByPeriod(base_info.curr_period)
- cfg_data = DeepCopy(self.model:GetTreasureHouseCFG(base_info.curr_period, base_info.award_round > max_round and max_round or base_info.award_round))
- num = base_info.curr_count
- if base_info.award_round ~= base_info.real_round then--如果有轮次没领的
- for i=base_info.award_round,base_info.real_round-1 do
- local round = i > max_round and max_round or i
- num = self.model:GetMaxNumByPeriodAndRound(base_info.curr_period, round) + num
- end
- end
- end
- self.num_text_txt.text = num
- local width_list = {[1] ={0.014,0.161}, [2] = {0.27,0.4},[3] ={0.53, 0.67},[4]= {0.8, 0.93},[5]= {1,1},}
- local per_space = 25
- local data = {}
- for i=1,4 do
- data[i] = cfg_data[i]
- if i~= 1 then
- data[i].min_count = data[i-1].count+1
- else
- data[i].min_count = 0
- end
- end
- local index = 1
- for i,v in ipairs(data) do
- if num>= v.min_count and num <= v.count then
- index = i
- break
- end
- end
- data[5] = { min_count = data[4].count, count = 999 }
- if num >= data[5].min_count then
- index = 5
- end
- local min_percent = 0
- local max_percent = 0
- if index then
- min_percent = width_list[index][1]
- max_percent = width_list[index][2]
- end
- local offset_percent = max_percent - min_percent
- local time_offset = data[index].count - data[index].min_count + 1
- local percent = (num - data[index].min_count + 1) / time_offset * offset_percent + min_percent
- self.progress_image_img.fillAmount = percent
- end
-
- function TreasureHouseView:UpdateModel( )
- local data = self.model:GetTreasureHouseBaseInfo()
- local period = 1
- local cfg = Config.Treasurehouseperiod[period]
- if cfg then
- local fashion_id,color_id = FashionModel:getInstance():GetFashionIdByGoodsId(cfg.show)
- local goods_name = GoodsModel:getInstance():getGoodsName(cfg.show, false)
- self.goods_name_text_tmp.text = goods_name
- local res_data = {
- father_node = self,
- transform = self.role_con,
- fashion_type = FuncOpenModel.TypeId.Clothes,
- size = Vector2(720,720),
- raycast_size = Vector2(340,600),
- scale = 180,
- position = Vector3(-85,40,179),
- ui_model_type = UIModelCommon.ModelType.BackModel,
- }
- FuncOpenModel:getInstance():SetModelRes(res_data)
- end
- end
-
-
- -- 创建服务器记录
- function TreasureHouseView:UpdateRecordItemList( )
- -- 创建的时候要暂停动画
- self:StopRecordItemAction()
- local record_list = self.model:GetTreasureHouseRecordInfo()
- for k, v in pairs(self.record_item_list) do
- v:SetVisible(false)
- end
- -- 节点高度
- local max_item_num = 20 -- 最大节点数
- local node_height = self.record_scroll.sizeDelta.y
- local height = 0
- local item
- self.record_count = 0
- for k, v in ipairs(record_list) do
- if k > max_item_num then
- break
- end
- item = self.record_item_list[k]
- if not item then
- item = TreasureHouseRecordItem.New(self.record_con)
- self.record_item_list[k] = item
- end
- item:SetAnchoredPosition(2, -height)
- item:SetVisible(true)
- height = height + item:SetData(v, self.sub_type)
- self.record_count = self.record_count + 1
- end
- -- self.no_record_tmp.text = self.record_count == 0 and "暂无记录" or ""
- SetSizeDeltaY(self.record_con, height)
- -- 记录一下当前的节点数
- -- 生成节点的高度超过了容器高度,就需要展示轮播
- if height > node_height then
- self:StartRecordItemAction()
- end
-
- if #record_list == 0 then
- self.recordTips_tmp.text = "暂无全服记录"
- else
- self.recordTips_tmp.text = ""
- end
- end
-
- -- 招财记录动画相关
- -- 招财记录动画相关
- -- 招财记录动画相关
- -- 开始轮播招财记录动画
- function TreasureHouseView:StartRecordItemAction()
- self:StopRecordItemAction()
- local time = FortuneCatModel.RecordAnimDuration
- local function func()
- self:UpdateRecordItemPos()
- self:MoveRecordItem()
- end
- self.auto_record_item_anim_id = GlobalTimerQuest:AddPeriodQuest(func, time, -1)
- end
-
- function TreasureHouseView:StopRecordItemAction()
- if self.auto_record_item_anim_id then
- GlobalTimerQuest:CancelQuest(self.auto_record_item_anim_id)
- self.auto_record_item_anim_id = nil
- end
- self:StopRecordItemAnim()
- end
-
- -- 播放招财记录节点的动画
- function TreasureHouseView:MoveRecordItem()
- local first_text = self.record_item_list[1]
- local move_height = first_text:GetAnchoredPosition().y
- move_height = move_height > 0 and 0 or move_height
- for k,text in pairs(self.record_item_list) do
- text:StartAction(move_height)
- end
- end
-
- -- 停止招财记录节点的动画
- function TreasureHouseView:StopRecordItemAnim()
- for k,text in pairs(self.record_item_list) do
- text:StopAction()
- end
- end
-
- function TreasureHouseView:UpdateRecordItemPos()
- local delete_index = {}
- local height = 0
- local count = 0
- for i = 1, self.record_count do
- local text = self.record_item_list[i]
- if text then
- local vis = text:GetVisible()
- local h = text:GetRecordHeight()
- local y = text:GetAnchoredPosition().y
- height = height + (vis and h or 0)
- if y + h > 0.1 and vis then -- 将超出屏幕并显示中的节点保存到移动临时队列 0.1 由于浮点误差有可能出现不该隐藏的节点也添加到队列中,做加大误差处理
- table.insert(delete_index, i)
- end
- end
- end
-
- local del_num = 0
- local t = {}
- for i,v in ipairs(delete_index) do
- local index = v - del_num
- local text = table.remove(self.record_item_list, index)
- t[#t+1] = text
- del_num = del_num + 1
- end
- -- 将临时队列的节点存回去
- for i = 1, #t do
- t[i]:SetAnchoredPosition(2, -height)
- table.insert(self.record_item_list, t[i])
- end
- end
-
- function TreasureHouseView:OnDrawBtnClick( num )
- local goods_num = GoodsModel:getInstance():GetTypeGoodsNum(TreasureHouseConst.TREASURE_HOUSE_TICKET_ID)
- local need_show = goods_num < num
- local str = ""
- local buy_price = GoodsModel:getInstance():GetGoodsPrice(TreasureHouseConst.TREASURE_HOUSE_TICKET_ID)
- local cost_price = (num - goods_num) * buy_price
- local function ok_callback( ... )
- if GoodsModel:getInstance():IsJinEnough(cost_price) then
- self.model:Fire(TreasureHouseConst.REQ_TREASURE_HOUSE_SCMD, 10401, num)
- else
- local qc_data = {
- price = cost_price,
- }
- GlobalEventSystem:Fire(EventName.OPEN_RECHARGE_TIP_VIEW, true, qc_data)
- end
- end
- local function toggle_function( flag )
- self.model.not_show_treasure_house_tip = flag
- end
- local price_asset, price_icon = WordManager:GetCommonMoneyIcon(1)
- local toggle_tip_data = {
- gold_ab_res = price_asset,
- gold_res = price_icon,
- price = cost_price,
- insufficientText = "",
- priceText = string.format("<color=#fdffc2>%s</color> 补足所需的珍宝阁秘钥。",cost_price),
- titleText = "提示",
- ok_callback = ok_callback,
- toggle_function = toggle_function,
- is_complex_ok_callback = true,
- }
- if not self.model.not_show_treasure_house_tip and cost_price > 0 then
- GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data)
- else
- ok_callback()
- end
- end
-
- function TreasureHouseView:DestroySuccess( )
- for i,v in ipairs(self.reward_item_list) do
- v:DeleteMe()
- v = nil
- end
- self.reward_item_list = {}
- for i,v in ipairs(self.reward_count_item_list) do
- v:DeleteMe()
- v = nil
- end
- self.reward_count_item_list = {}
- if self.money_view then
- self.money_view:DeleteMe()
- self.money_view = nil
- end
- if self.on_update_record_list_id then
- self.model:UnBind(self.on_update_record_list_id)
- self.on_update_record_list_id = nil
- end
- if self.on_update_base_info_id then
- self.model:UnBind(self.on_update_base_info_id)
- self.on_update_base_info_id = nil
- end
- if self.on_update_task_info_id then
- self.model:UnBind(self.on_update_task_info_id)
- self.on_update_task_info_id = nil
- end
- self:StopRecordItemAction()
- for i,v in ipairs(self.record_item_list) do
- v:DeleteMe()
- v = nil
- end
- self.record_item_list = {}
- end
|