EscortMainView = EscortMainView or BaseClass(BaseView) local EscortMainView = EscortMainView function EscortMainView:__init() self.base_file = "escort" self.layout_file = "EscortMainView" self.layer_name = "UI" self.destroy_imm = true self.use_background = true --全屏界面默认使用这个参数 self.hide_maincancas = true --全屏界面需要放开隐藏主UI self.blur_activity_bg = true self.close_fog = true self.change_scene_close = true self.append_to_ctl_queue = false --是否要添加进界面堆栈 self.need_show_money = true --是否要显示顶部的金钱栏 self.improve_target_id = 0 self.item_list = {} self.awarditem_list = {} self.position_data = { [1] = {15, -202}, [2] = {207, -41}, [3] = {457, -64}, [4] = {617, -254}, } self.model = EscortModel:getInstance() self.is_auto_buy = self.model.is_auto_buy self.model:Fire(EscortConst.REQUEST_SCMD_EVENT, 50000) self.load_callback = function () self:LoadSuccess() self:AddEvent() 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 EscortMainView:Open( ) --self.data = data BaseView.Open(self) end function EscortMainView:LoadSuccess() local nodes = { "fresh_btn:obj", "buy_toggle:tog:obj", "bg:raw", "tip_btn:obj", "close_btn:obj", "escort_btn:obj", "item_con", "cost_image:img:obj", "reward_con", "time_text2:tmp", "cost_text:tmp", "time_text1:tmp", "num_text:tmp", "con_money", "progress_text:tmp", "progress_image:img", "desc_text:tmp" } self:GetChildren(nodes) local pos_x = GetAnchoredPosition(self.desc_text) SetAnchoredPositionX(self.desc_text, pos_x - 12) lua_resM:setOutsideRawImage(self,self.bg_raw,GameResPath.GetViewBigBg("escort_bg"),false) lua_resM:setOutsideImageSprite(self, self.cost_image_img, GameResPath.GetGoodsIcon(EscortConst.ESCORT_GOODS_ID),false) self.buy_toggle_tog.isOn = self.is_auto_buy self:CreateMoneyView() self:UpdateEscortItem() self:SetDoubleExpTime() end function EscortMainView:AddEvent() local on_click = function ( click_obj ) if self.close_btn_obj == click_obj then self:Close() elseif self.tip_btn_obj == click_obj then EventSystem.Fire(GlobalEventSystem,EventName.OPEN_INSTRUCTION_VIEW, 50000) elseif self.fresh_btn_obj == click_obj then self:StartFresh() elseif self.escort_btn_obj == click_obj then if self.model:CurTimeIsDouble() then self.model:Fire(EscortConst.REQUEST_SCMD_EVENT, 50002, 1) else self:AskCall() end elseif self.buy_toggle_obj == click_obj then self.is_auto_buy = not self.is_auto_buy self.model.is_auto_buy = self.is_auto_buy elseif self.cost_image_obj == click_obj then UIToolTipMgr:getInstance():AppendGoodsTips(EscortConst.ESCORT_GOODS_ID, x, y, nil, nil, nil,nil,false) end end AddClickEvent(self.close_btn_obj, on_click) AddClickEvent(self.support_btn_obj, on_click) AddClickEvent(self.tip_btn_obj, on_click) AddClickEvent(self.fresh_btn_obj, on_click) AddClickEvent(self.escort_btn_obj, on_click) AddClickEvent(self.buy_toggle_obj, on_click) AddClickEvent(self.cost_image_obj, on_click) local function on_update( ) local base_info = self.model:GetEscortBaseInfo() if base_info.is_convoy == 1 then--如果已经开始护送了 就别刷新界面了 会刷到下一次的信息 else self:UpdateView() end end self.update_id = self.model:BindOne("escort_base_info", on_update) end function EscortMainView:AskCall( ) local cost = self.model.double_escort_cost[1][3] -- config local cost_type = self.model.double_escort_cost[1][1] local jin = RoleManager.Instance.mainRoleInfo.jin local jinLock = RoleManager.Instance.mainRoleInfo.jinLock local function recharge_call_back( ... )--充值 local args = {...} local use_lockjin = args[1] -- 关闭道具tips UIToolTipMgr:getInstance():CloseGoodsTips() local qc_data = { price = cost - (use_lockjin and jinLock or 0), close_callback = nil, qc_type = 0, } GlobalEventSystem:Fire(EventName.OPEN_RECHARGE_TIP_VIEW, true, qc_data) end local function invest_call_back( ... )--前往投资 -- 关闭道具tips UIToolTipMgr:getInstance():CloseGoodsTips() OpenFun.Open(420,1) end -- 双倍护送 local function ok_callback() if cost_type == 1 then if jin < cost then--彩钻不足 recharge_call_back() else self.model:Fire(EscortConst.REQUEST_SCMD_EVENT, 50002, 1) end elseif cost_type == 2 then if jinLock < cost then local ok = function ( ) if jinLock + jin < cost then recharge_call_back(true) else self.model:Fire(EscortConst.REQUEST_SCMD_EVENT, 50002, 1) end end local jin_type_img = WordManager:GetMoneyFaceStr( 1 ) local jinLock_type_name = GoodsModel:getInstance():getGoodsName(100001, false) local str = string.format("您的%s不足,是否使用 %s%s 补全?",jinLock_type_name,jin_type_img,cost - jinLock) if VipModel:getInstance():HasBoughtAllInvestmentTypes() then -- 已经购买了全部的投资类型,则不提示前往投资 Alert.show(str, Alert.Type.Two, ok, nil, "彩钻补全", "取消") else Alert.show(str, Alert.Type.Two, ok, invest_call_back, "彩钻补全", "前往投资") end else self.model:Fire(EscortConst.REQUEST_SCMD_EVENT, 50002, 1) end end end -- 单倍护送 local function cancel_callback() self.model:Fire(EscortConst.REQUEST_SCMD_EVENT, 50002, 0) end local function toggle_function( flag ) self.model.not_show_go_ask = flag end -- 屏蔽接口里面的recharge_callback 跳转到自己的函数 local function rechanger_callback(...) ok_callback() end local time_str = HtmlColorTxt("(17:00-17:30 21:30-22:00)", ColorUtil.GREEN_DARK) local str = string.format("现在不是 %s\n%s", HtmlColorTxt("双倍护送时间", ColorUtil.GREEN_DARK), time_str) local toggle_tip_data = { insufficientText = str, titleText = "提示", nameText = "是否花费 ", priceText = string.format("%s 进行护送获得双倍奖励", HtmlColorTxt(cost, "#fdffc2")), okText = "确认双倍", cancelText = "坚持单倍", toggleText = " 记住本次选择",--8字符 ok_callback = ok_callback, close_callback = cancel_callback, rechanger_callback = rechanger_callback, toggle_function = toggle_function, is_complex_ok_callback = false, gold_res = "ui_momey_icon_" .. cost_type, price = cost, -- config } if not self.model.not_show_go_ask_indeed or self.model.last_double_escort == nil then GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data) else if self.model.last_double_escort == 1 then ok_callback() elseif self.model.last_double_escort == 0 then cancel_callback() end end end function EscortMainView:StartFresh( ) -- local goods_num = GoodsModel:getInstance():GetTypeGoodsNum(EscortConst.ESCORT_GOODS_ID) -- local buy_price = GoodsModel:getInstance():GetGoodsPrice(EscortConst.ESCORT_GOODS_ID) -- local cost_price = (self.need_num - goods_num) * buy_price -- local price_asset, price_icon = WordManager:GetCommonMoneyIcon(2) -- local toggle_tip_data = { -- gold_ab_res = price_asset, -- gold_res = price_icon, -- price = cost_price, -- insufficientText = "", -- priceText = string.format("%s 补齐所需的护送令牌",cost_price), -- titleText = "提示", -- ok_callback = ok_callback, -- toggle_function = toggle_function, -- is_complex_ok_callback = true, -- } -- if not self.model.not_show_escort_ask and cost_price ~= 0 and self.is_auto_buy then -- GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data) -- else -- ok_callback() -- end local function ok_callback() local auto_buy = self.is_auto_buy and 1 or 0 -- local auto_buy = 1--这里改了 永远都要自动购买 self.model:Fire(EscortConst.REQUEST_SCMD_EVENT, 50001, auto_buy) end local function toggle_function( flag ) self.model.not_show_escort_ask = flag end local function use_function( toggle_tip_data,call_fun_sum ) if not self.model.not_show_escort_ask then GlobalEventSystem:Fire(EventName.OPEN_COM_TOGGLE_TIP_VIEW, toggle_tip_data) else call_fun_sum() end end local goods_num = GoodsModel:getInstance():GetTypeGoodsNum(EscortConst.ESCORT_GOODS_ID) local buy_price = GoodsModel:getInstance():GetGoodsPrice(EscortConst.ESCORT_GOODS_ID) local cost_price = (self.need_num - goods_num) * buy_price if not self.model.not_show_escort_ask and cost_price ~= 0 and not self.is_auto_buy then local buy_tip_data = { gold_type = 2,--货币类型 cost_price = cost_price,--消耗金额 ok_callback = ok_callback,--成功 toggle_function = toggle_function,--多选 togglePriceStr = string.format("%s 补齐所需的%s", cost_price, HtmlColorTxt(" [外送凭证]", ColorUtil.BLUE_DARK)),--提示语 use_function = use_function,--最终调用 } CustomActivityModel:getInstance():BuyTips(buy_tip_data) else ok_callback() end end function EscortMainView:OpenSuccess() self:UpdateView() end function EscortMainView:UpdateView() self.base_info = self.model:GetEscortBaseInfo() local index = self.model:GetEscortObjectIndexById(self.base_info.object_id or 1001) local cfg = Config.Convoyobject local cur_id = self.base_info.object_id or 1001 if cfg[cur_id] then self.progress_text_tmp.text = string.format("%s/%s", self.base_info.pray_val or 0, cfg[cur_id].up_next_val) self.progress_image_img.fillAmount = (self.base_info.pray_val or 0)/cfg[cur_id].up_next_val end -- lua_resM:setImageSprite(self, self.type_image_img, "escort_asset", "escort_text"..index) -- self:UpdateDropDown() self:SetSelect() self:UpdateNeedCost() self:UpdateRewardCon() if self.model:IsOverMaxCount() then self.num_text_tmp.text = string.format("剩余次数:%s/%s", HtmlColorTxt(0, ColorUtil.RED_DARK), self.model.max_escort_num) else local left_num = self.model.max_escort_num-self.model:GetEscortTimes() self.num_text_tmp.text = string.format("剩余次数:%s/%s", HtmlColorTxt(left_num, ColorUtil.GREEN_DARK), self.model.max_escort_num) end end function EscortMainView: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() end function EscortMainView:SetSelect( ) local index = self.model:GetEscortObjectIndexById(self.base_info.object_id or 0) for i,v in ipairs(self.item_list) do v:SetSelect(i==index) end end --双倍时间 function EscortMainView:SetDoubleExpTime() local cfg1 = DailyModel:getInstance():GetAcConfig(500, 1, 2) if cfg1 then local time = ErlangParser:GetInstance():Parse(cfg1.time_region) for i=1,2 do for j=1,2 do if tonumber(time[1][i][j]) < 10 and #(tostring(time[1][i][j])) == 1 then time[1][i][j] = "0"..time[1][i][j] end if tonumber(time[2][i][j]) < 10 and #(tostring(time[2][i][j])) == 1 then time[2][i][j] = "0"..time[2][i][j] end end end local time1 = string.format("%s:%s-%s:%s", time[1][1][1], time[1][1][2],time[1][2][1], time[1][2][2]) local time2 = string.format("%s:%s-%s:%s", time[2][1][1], time[2][1][2],time[2][2][1], time[2][2][2]) self.time_text2_tmp.text = string.format("%s %s", HtmlColorTxt(time1, ColorUtil.GREEN_DARK), HtmlColorTxt(time2, ColorUtil.GREEN_DARK)) -- self.time_text2_tmp.text = string.format("%s:%s-%s:%s", time[2][1][1], time[2][1][2], -- time[2][2][1], time[2][2][2]) end -- local cfg2 = DailyModel:getInstance():GetAcConfig(500, 1, 2) -- if cfg2 then -- local time = ErlangParser:GetInstance():Parse(cfg2.time_region) -- for j=1,2 do -- for k=1,2 do -- if tonumber(time[1][j][k]) < 10 then -- time[1][j][k] = "0"..time[1][j][k] -- end -- end -- end -- self.time_text2_tmp.text = string.format("%s:%s-%s:%s", time[1][1][1], time[1][1][2], -- time[1][2][1], time[1][2][2]) -- end end function EscortMainView:UpdateDropDown( ) local list = {} local cfg_list = {} local cfg = Config.Convoyobject local first = true local cur_index = self.base_info.object_id local last_cfg = {} local count = 1 for i,v in pairsByKeys(cfg) do if first then first = false cur_index = cur_index or i end if i > cur_index then local name = self:GetColorName(v.name, v.id) table.insert(list, name) table.insert(cfg_list, v) end if count == TableSize(cfg) then last_cfg = v end count = count + 1 end if TableSize(cfg_list) == 0 then local name = self:GetColorName(last_cfg.name, last_cfg.id) table.insert(list, name) table.insert(cfg_list, last_cfg) end self.improve_index = 1 self.improve_target_id = cfg_list[self.improve_index].id local function update_object_id_func(index) self.improve_index = index self.improve_target_id = cfg_list[index].id self:UpdateNeedCost() end local prefab_data = {Combox = "Combox",ComboxView = "ComboxView", ComboxItem = "ComboxItem", offset_y = -#list*ComboxItem.Height -10} if not self.object_drop_down then self.object_drop_down = Combox.New(self.improve_con,list,update_object_id_func,138,30,nil,prefab_data) else self.object_drop_down:ResetData(list,self.improve_index,update_object_id_func,138,30) end end function EscortMainView:UpdateNeedCost( ) local cur_id = self.base_info.object_id if cur_id == 0 or not cur_id then return end local cfg = Config.Convoyobject local num = 0 local goods_num = GoodsModel:getInstance():GetTypeGoodsNum(EscortConst.ESCORT_GOODS_ID) if self.is_improve_to then for k,v in pairsByKeys(cfg) do if k >= cur_id and k < self.improve_target_id then num = num + stringtotable(v.upgrade_cost)[1][3] end end else local data = stringtotable(cfg[cur_id].upgrade_cost) if TableSize(data) > 0 then num = data[1][3] end end local color_str = ColorUtil.GREEN_DARK if goods_num < num then color_str = ColorUtil.RED_DARK end self.need_num = num self.cost_text_tmp.text = string.format("剩余:%s/%s", HtmlColorTxt(goods_num, color_str), num) end function EscortMainView:GetColorName(name,id) local index = self.model:GetEscortObjectIndexById(id) local color_str = { [1] = "#ffffff", [2] = "#10aaf1",--7bb1ff [3] = "#d322ff",--f280f7 [4] = "#ffea9c",--ffe96c } return HtmlColorTxt(name, color_str[index]) end function EscortMainView:UpdateEscortItem( ) local data = Config.Convoyobject local count = 1 local x_offset = 290 for i,v in pairsByKeys(data) do local item = self.item_list[count] if not item then item = EscortItem.New(self.item_con) self.item_list[count] = item end item:SetData(v, count) -- item:SetPosition(self.position_data[count][1], self.position_data[count][2]) item:SetPosition((count - 1) * x_offset-10, -168) count = count + 1 end end function EscortMainView:UpdateRewardCon( ) local cur_id = self.base_info.object_id or 1001 cur_id = cur_id == 0 and 1001 or cur_id local exp_num = self.model:GetEscortExpByLv(RoleManager.Instance.mainRoleInfo.level, cur_id, false) local data = stringtotable(Config.Convoyobject[cur_id].award) or {} local exp_data = { [1] = 0, [2] = EscortConst.EXP_TPYE_ID, [3] = exp_num } table.insert(data, exp_data) for i,v in ipairs(data) do local item = self.awarditem_list[i] if not item then item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.reward_con) item:SetItemSize(59,59) item:SetPosition(64*(i-1), 0) self.awarditem_list[i] = item end item:SetData(v[2],v[3]) end end function EscortMainView:DestroySuccess( ) for i,v in ipairs(self.item_list) do v:DeleteMe() v = nil end self.item_list = {} if self.drop_down then self.drop_down:DeleteMe() self.drop_down = nil end if self.update_id then self.model:UnBind(self.update_id) self.update_id = nil end if self.money_view then self.money_view:DeleteMe() self.money_view = nil end if self.object_drop_down then self.object_drop_down:DeleteMe() self.object_drop_down = nil end for i,v in ipairs(self.awarditem_list) do UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, v) end self.awarditem_list = {} end