|
ChildVehicleViewNew = ChildVehicleViewNew or BaseClass(BaseView)
|
|
local ChildVehicleViewNew = ChildVehicleViewNew
|
|
|
|
function ChildVehicleViewNew:__init()
|
|
self.base_file = "child"
|
|
self.layout_file = "ChildVehicleViewNew"
|
|
self.layer_name = "UI"
|
|
self.destroy_imm = true
|
|
self.use_background = G_USING_BG --全屏界面默认使用这个参数
|
|
self.hide_maincancas = true --全屏界面需要放开隐藏主UI
|
|
self.change_scene_close = true
|
|
self.append_to_ctl_queue = false --是否要添加进界面堆栈
|
|
self.need_show_money = false --是否要显示顶部的金钱栏
|
|
|
|
self.model = ChildModel:GetInstance()
|
|
|
|
self.vehicle_item_list = {}
|
|
self.attr_item_list = {}
|
|
self.skill_item_list = {}
|
|
self.select_item = 0
|
|
|
|
self.img_star_list = {}
|
|
|
|
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 ChildVehicleViewNew:Open( )
|
|
--self.data = data
|
|
BaseView.Open(self)
|
|
end
|
|
|
|
function ChildVehicleViewNew:LoadSuccess()
|
|
self.nodes = {
|
|
"bg:raw",
|
|
"close:obj",
|
|
"left/ScrollView_item/Viewport/Content_item",
|
|
--------------------------------
|
|
"right/ScrollView_attr/Viewport/Content_attr",
|
|
"right/awardCon:obj",
|
|
"right/btn_upgrade/btn_upgrade_red_dot:obj",
|
|
"right/btn_upgrade/btn_upgrade_txt:tmp",
|
|
"right/btn_upgrade:obj",
|
|
"right/txt_fight:txt",
|
|
"right/right_bg:img",
|
|
-- "right/level_bg/txt_lv_after:tmp",
|
|
-- "right/level_bg/txt_lv:tmp",
|
|
-- "right/level_bg/img_arrow_level:obj",
|
|
--"right/fight_bg/txt_fight:tmp",
|
|
--"right/fight_bg/txt_fight_after:tmp",
|
|
--"right/fight_bg/img_arrow_fight:obj",
|
|
--"right/itemCon/ui_num_bg/item_num_txt:tmp",
|
|
-------------------------------
|
|
"mid/skill_con",
|
|
"mid/btn_wear:obj",
|
|
"mid/btn_unwear:obj",
|
|
"mid/rt_image_show",
|
|
"mid/name_bg/text_name:tmp",
|
|
"mid/mid_bg:img",
|
|
"mid/mid_bg2:img",
|
|
"mid/levelText:tmp",
|
|
"mid/effectCon",
|
|
}
|
|
self:GetChildren(self.nodes)
|
|
|
|
-- 进阶星星
|
|
for i = 1, 5 do
|
|
self.img_star_list[i] = self:GetChild("right/stars/star"..i):GetComponent("Image")
|
|
end
|
|
|
|
self:UpdateBaseView( )
|
|
end
|
|
|
|
function ChildVehicleViewNew:UpdateBaseView( )
|
|
self.up_item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem,self.awardCon)
|
|
self.up_item:SetItemSize(74, 74)
|
|
|
|
lua_resM:setOutsideRawImage(self, self.bg_raw, GameResPath.GetViewBigBg("child_vehicle_bg_1173_669"))
|
|
-- local close_callback = function()
|
|
-- self:Close()
|
|
-- end
|
|
-- self.tab_win = UITabWindow.New(self.transform, nil, nil,
|
|
-- close_callback, self.background_wnd, nil, UITabWindow.SizeSmallHallNoTab, false,nil,true)
|
|
-- self.tab_win:SetBackgroundRes("child_dress_bg_1280_720")
|
|
-- self.tab_win:SetTitleText("宝宝载具")
|
|
-- self.tab_win:ChangeShowFlag("Child")
|
|
local function bg_back_func( ... )
|
|
if self.background_wnd and self.background_wnd:GetComponent("RawImageExtend") then
|
|
self:MoveUIToBack(self.background_wnd:GetComponent("RawImageExtend"))
|
|
end
|
|
self:MoveUIToBack(self.bg_raw)
|
|
end
|
|
if self.background_wnd then
|
|
bg_back_func()
|
|
else
|
|
self.bg_back_func = bg_back_func
|
|
end
|
|
|
|
-- lua_resM:setOutsideImageSprite(self, self.right_bg_img, GameResPath.GetChildIcon("child_carrier_right_bg"), false)
|
|
-- lua_resM:setOutsideImageSprite(self, self.mid_bg2_img, GameResPath.GetChildIcon("child_base_table"), false)
|
|
-- lua_resM:setOutsideImageSprite(self, self.mid_bg_img, GameResPath.GetChildIcon("child_carrier_mid_bg"), false)
|
|
end
|
|
|
|
function ChildVehicleViewNew:AddEvent()
|
|
local function updata_child_vehicle_info_fun()
|
|
self.need_check_effect = true
|
|
self:UpdateView(self.select_item) -- 刷新页签
|
|
if self.select_item then
|
|
self:SetItemCon(self.select_item) -- 刷新载具信息
|
|
end
|
|
end
|
|
self.UPDATA_CHILD_VEHICLE_INFO_id = self.model:Bind(ChildConst.UPDATA_CHILD_VEHICLE_INFO, updata_child_vehicle_info_fun,vo) --41404成功后返回
|
|
|
|
--[[type :int8 //1-出战 2-取消出战
|
|
vehicle_id :int16 //载具Id 0-没有幻化的载具 其他-具体幻化载具Id
|
|
}]] --落单了,单独刷新吧
|
|
local function updata_child_vehicle_follow_fun(type,vehicle_id)
|
|
if type == 2 then
|
|
self.btn_unwear_obj:SetActive(false)
|
|
self.btn_wear_obj:SetActive(true)
|
|
elseif type == 1 and self.select_item and self.select_item.data.fashion_id == vehicle_id then
|
|
self.btn_unwear_obj:SetActive(true)
|
|
self.btn_wear_obj:SetActive(false)
|
|
end
|
|
end
|
|
self.updata_child_vehicle_follow_id = self.model:Bind(ChildConst.UPDATA_CHILD_VEHICLE_FOLLOW, updata_child_vehicle_follow_fun,vo)
|
|
|
|
local function updata_Child_RED_DOT_VIEW_fun(id)
|
|
if id ~= ChildConst.TabId.ChildVehicle then return end
|
|
self:UpdateRedDot()
|
|
self:UpdateRedDotUpBtn(self.select_item.data.fashion_id,self.select_item.stage)
|
|
end
|
|
self.updata_Child_RED_DOT_VIEW_id = self.model:Bind(ChildConst.Child_RED_DOT_VIEW, updata_Child_RED_DOT_VIEW_fun) --红点更新
|
|
|
|
|
|
local function onBtnClickHandler(target, x, y)
|
|
if target == self.btn_upgrade_obj then
|
|
if self.select_item.type == ChildConst.ChildDressItemType.Lock then
|
|
Message.show("载具材料不足喔")
|
|
return
|
|
end
|
|
if self.select_item.type == ChildConst.ChildDressItemType.CanActive then
|
|
self.model:Fire(ChildConst.CHILD_REQ_EVENT, 16515, 1, self.select_item.data.fashion_id)
|
|
else
|
|
self.model:Fire(ChildConst.CHILD_REQ_EVENT, 16515, 2, self.select_item.data.fashion_id)
|
|
end
|
|
elseif target == self.btn_unwear_obj then
|
|
self.model:Fire(ChildConst.CHILD_REQ_EVENT, 16517,2,self.select_item.data.fashion_id)
|
|
elseif target == self.btn_wear_obj then
|
|
local cur_state = self.model:GetChildCurState( )
|
|
if cur_state < self.select_item.data.can_on_age then
|
|
Message.show("现在孩子还坐不了哦")
|
|
return
|
|
end
|
|
self.model:Fire(ChildConst.CHILD_REQ_EVENT, 16517,1,self.select_item.data.fashion_id)
|
|
elseif target == self.close_obj then
|
|
self:Close()
|
|
end
|
|
|
|
end
|
|
AddClickEvent(self.close_obj, onBtnClickHandler)
|
|
AddClickEvent(self.btn_upgrade_obj, onBtnClickHandler)
|
|
AddClickEvent(self.btn_wear_obj, onBtnClickHandler)
|
|
AddClickEvent(self.btn_unwear_obj, onBtnClickHandler)
|
|
end
|
|
|
|
function ChildVehicleViewNew:OpenSuccess()
|
|
self:UpdateView()
|
|
end
|
|
|
|
function ChildVehicleViewNew:UpdateView(select_item)
|
|
local vehicle_list = self.model:GetChildVehicleList()
|
|
-- print('Msh:ChildVehicleViewNew.lua[151] data', TableSize(vehicle_list))
|
|
|
|
local function callback( item )
|
|
for k,v in pairs(self.vehicle_item_list) do
|
|
v:SetChosen(false)
|
|
end
|
|
item:SetChosen(true)
|
|
self:SetItemCon(item)
|
|
self.select_item = item
|
|
self:UpdateRedDotUpBtn(item.vehicle_id,item.stage)
|
|
end
|
|
local is_select = false
|
|
for k,v in pairsByKeys(vehicle_list) do
|
|
local item = self.vehicle_item_list[k]
|
|
if item == nil then
|
|
item = ChildVehicleItem.New(self.Content_item)
|
|
self.vehicle_item_list[k] = item
|
|
end
|
|
--local data = self.model:GetConfigChildSkillInfo(v.skill_id,v.skill_lv)
|
|
self.vehicle_item_list[k]:SetData(v,callback)
|
|
if not is_select and not select_item then
|
|
is_select = true
|
|
self:SetItemCon(item)
|
|
self.select_item = self.vehicle_item_list[k]
|
|
self.vehicle_item_list[k]:SetChosen(true)
|
|
self:UpdateRedDotUpBtn(v.vehicle_id,v.stage)
|
|
end
|
|
end
|
|
|
|
self:UpdateRedDot()
|
|
end
|
|
|
|
function ChildVehicleViewNew:UpdateRedDotUpBtn(vehicle_id,stage)
|
|
-- local selectList_next = self.model:GetConfigChildVehicleInfo(vehicle_id,stage+1)
|
|
-- if TableSize(selectList_next) > 0 then
|
|
-- local upgrade_cost = stringtotable(selectList_next.upgrade_cost)
|
|
-- if upgrade_cost[1][1] == 0 then
|
|
-- local hadNum = GoodsModel:getInstance():GetTypeGoodsNum(upgrade_cost[1][2]) or 0
|
|
-- self.btn_upgrade_red_dot_obj:SetActive(hadNum >= upgrade_cost[1][3])
|
|
-- end
|
|
-- else -- 满级时隐藏
|
|
-- self.btn_upgrade_red_dot_obj:SetActive(false)
|
|
-- end
|
|
end
|
|
|
|
function ChildVehicleViewNew:UpdateRedDot( )
|
|
for k,v in pairs(self.vehicle_item_list) do
|
|
local cost_num = stringtotable(v.data.upgrade_cost)[1][3]
|
|
local num = GoodsModel:getInstance():GetTypeGoodsNum(v.data.fashion_id)
|
|
if cost_num <= num then
|
|
local is_max = self.model:IsChildVehicleLvMax(v.data.fashion_id,v.data.lv)
|
|
self.vehicle_item_list[k]:SetRedDot(true)
|
|
else
|
|
self.vehicle_item_list[k]:SetRedDot(false)
|
|
end
|
|
end
|
|
--local isRedDot = false
|
|
-- local redVehicleList = {}
|
|
-- local vehicleList = self.model:GetChildVehicleList( )
|
|
|
|
-- for k,v in pairs(vehicleList) do
|
|
-- local selectList_next = self.model:GetConfigChildVehicleInfo(v.vehicle_id,v.stage+1)
|
|
-- if TableSize(selectList_next) > 0 then -- 是否是最高级
|
|
-- local upgrade_cost = stringtotable(selectList_next.upgrade_cost)
|
|
-- if upgrade_cost[1][1] == 0 then
|
|
-- local hadNum = GoodsModel:getInstance():GetTypeGoodsNum(upgrade_cost[1][2]) or 0
|
|
-- --print("============>>> YiRan:ChildVehicleView [start:187] hadNum :",hadNum,"upgrade_cost[1][3]:",upgrade_cost[1][3])
|
|
-- --print("============>>> YiRan:ChildVehicleView [start:191] hadNum >= upgrade_cost[1][3] :",hadNum >= upgrade_cost[1][3])
|
|
-- self.vehicle_item_list[k]:SetRedDot(hadNum >= upgrade_cost[1][3])
|
|
-- end
|
|
-- end
|
|
-- end
|
|
end
|
|
|
|
function ChildVehicleViewNew:SelectTabFresh( )
|
|
self:UpdateRoleModel(self.select_item.data)
|
|
end
|
|
|
|
function ChildVehicleViewNew:UpdateRoleModel(data, need_effect)
|
|
-- 特效
|
|
if (not self.showing_effect_model) and need_effect then
|
|
-- print('=======Msh:ChildVehicleViewNew.lua[266] =======')
|
|
local function call_back( )
|
|
self.showing_effect_model = false
|
|
end
|
|
self:ClearUIEffect(self.effectCon)
|
|
self:AddUIEffect("ui_jinjie", self.effectCon, self.layer_name, Vector3(25,-35, 0), 1, false, 1.5, nil, call_back)
|
|
self.showing_effect_model = true
|
|
end
|
|
|
|
-- 计算一下人模型的id
|
|
local figure_id = self.model:GetVehicleModelID(data.fashion_id)
|
|
|
|
local clothe_res_id = false
|
|
if data.can_on_age == ChildConst.BABY_STATE.YOUNG then
|
|
if self.model:GetChildCurState( ) < ChildConst.BABY_STATE.YOUNG then -- 还没会走路
|
|
clothe_res_id = self.model:GetBaseChildModelID( ChildConst.BABY_STATE.YOUNG, self.model.childInfo.child_sex )
|
|
else -- 会走路就拿当前形象
|
|
clothe_res_id = self.model:GetChildCloth()
|
|
end
|
|
else -- 是爬或襁褓 则用默认形象
|
|
clothe_res_id = self.model:GetBaseChildModelID( data.can_on_age, self.model.childInfo.child_sex )
|
|
end
|
|
|
|
local res_data = {
|
|
father_node = self,
|
|
transform = self.rt_image_show,
|
|
fashion_type = FuncOpenModel.TypeId.ChildInVehicle,
|
|
figure_id = figure_id,
|
|
ui_model_type = UIModelCommon.ModelType.BackModel,
|
|
action_name_list = {"idle"},
|
|
clothe_res_id = clothe_res_id,
|
|
}
|
|
FuncOpenModel:getInstance():SetModelRes(res_data)
|
|
end
|
|
|
|
function ChildVehicleViewNew:SetItemCon( item )
|
|
local selectList = item.data
|
|
local check_effect = self.need_check_effect -- 是否要检查特效播放
|
|
|
|
local type_id = selectList.fashion_id
|
|
local isMax = self.model:IsChildVehicleLvMax(type_id, selectList.lv)
|
|
|
|
local is_active = item.type == ChildConst.ChildDressItemType.isActive
|
|
local goods_name = GoodsModel:getInstance():getGoodsName(type_id, true)
|
|
local have_num = GoodsModel:getInstance():GetTypeGoodsNum(type_id) or 0
|
|
local need_num = stringtotable(selectList.upgrade_cost)[1][3]
|
|
|
|
if not isMax then
|
|
self.btn_upgrade_red_dot_obj:SetActive(have_num >= need_num)
|
|
else
|
|
self.btn_upgrade_red_dot_obj:SetActive(false)
|
|
end
|
|
|
|
-- 名字
|
|
self.text_name_tmp.text = selectList.fashion_name
|
|
|
|
local dressList = self.model:GetChildDressList()
|
|
for k,v in pairsByKeys(dressList) do
|
|
if v.fashion_id == selectList.fashion_id then
|
|
selectList = v --协议回来的更到最新
|
|
end
|
|
end
|
|
|
|
-- 按钮描述
|
|
self.btn_upgrade_txt_tmp.text = item.type == ChildConst.ChildDressItemType.isActive and "升级" or "激活"
|
|
|
|
-- 材料item
|
|
if isMax then -- 时装已经激活 且 升满
|
|
self.btn_upgrade_txt_tmp.text = "已满"
|
|
self.awardCon_obj:SetActive(false)
|
|
else -- 没有满级
|
|
self.awardCon_obj:SetActive(true)
|
|
if not self.up_item then
|
|
self.up_item = UIObjPool:PopItem(UIObjPool.UIType.AwardItem, self.awardCon)
|
|
self.up_item:SetItemSize(62, 62)
|
|
end
|
|
|
|
self.up_item:SetData(type_id)
|
|
local get_str = HtmlColorTxt(have_num, have_num < need_num and ColorUtil.RED_DARK or ColorUtil.GREEN_DARK) .."/".. need_num
|
|
self.up_item:SetNumStr("")
|
|
self.up_item:IsGetGoods(true, get_str, true)
|
|
end
|
|
|
|
-- 时装战力
|
|
local attr_list
|
|
if selectList.lv > 0 then
|
|
attr_list = stringtotable(selectList.attr_list)
|
|
else
|
|
attr_list = stringtotable(Config.Childvehicle[selectList.fashion_id .. "@1"].add_attr)
|
|
end
|
|
|
|
|
|
local new_fight = "f"..GetFighting(attr_list)
|
|
local need_effect = false -- 是否需要属性刷新特效
|
|
if check_effect and (self.pre_lv and self.pre_lv < selectList.lv) then
|
|
if not self.show_fight_effect then -- 特效
|
|
need_effect = true
|
|
local function call_back( )
|
|
self.show_fight_effect = false
|
|
end
|
|
self.show_fight_effect = true
|
|
self:ClearUIEffect(self.txt_fight)
|
|
self:AddUIEffect("ui_jinjieshuxing", self.txt_fight,
|
|
self.layer_name, Vector3(-150, 37, 0), 1.3, false, 0.75, nil, call_back)
|
|
end
|
|
end
|
|
self.txt_fight_txt.text = new_fight
|
|
|
|
self:UpdateRoleModel(selectList, need_effect)
|
|
|
|
-- 时装属性
|
|
local index = 0
|
|
if need_effect then -- 特效刷新则滚到最上面
|
|
SetLocalPositionY(self.Content_attr, 0)
|
|
end
|
|
for k,v in pairs(attr_list) do
|
|
index = index + 1
|
|
local item = self.attr_item_list[k]
|
|
if item == nil then
|
|
item = ChildDressAttrItem.New(self.Content_attr)
|
|
self.attr_item_list[k] = item
|
|
end
|
|
local num = v[2]
|
|
self.attr_item_list[k]:SetData(k,v[1],num, need_effect and index <= 3) -- 只显示前三个
|
|
end
|
|
|
|
|
|
-- 设置进阶星星数
|
|
local nowLevel = tonumber(selectList.lv)
|
|
self.pre_lv = nowLevel
|
|
self.levelText_tmp.text = nowLevel
|
|
for i = 1, 5 do
|
|
if i < nowLevel/2 then
|
|
if check_effect and tonumber(self.img_star_list[i].fillAmount) < 1 then
|
|
self:PlayStarEffect(self.img_star_list[i].transform, i)
|
|
end
|
|
self.img_star_list[i].gameObject:SetActive(true)
|
|
self.img_star_list[i].fillAmount = 1
|
|
elseif (i-1) < nowLevel/2 then -- 最后一个
|
|
self.img_star_list[i].gameObject:SetActive(true)
|
|
if nowLevel % 2 ~= 0 then -- 单数就是一半
|
|
if check_effect and tonumber(self.img_star_list[i].fillAmount) < 0.5 then
|
|
self:PlayStarEffect(self.img_star_list[i].transform, i)
|
|
end
|
|
self.img_star_list[i].fillAmount = 0.5
|
|
else
|
|
if check_effect and tonumber(self.img_star_list[i].fillAmount) < 1 then
|
|
self:PlayStarEffect(self.img_star_list[i].transform, i)
|
|
end
|
|
self.img_star_list[i].fillAmount = 1
|
|
end
|
|
else
|
|
self.img_star_list[i].gameObject:SetActive(false)
|
|
self.img_star_list[i].fillAmount = 0
|
|
end
|
|
end
|
|
|
|
|
|
-- 穿戴/脱下 按钮
|
|
local cur_wear_id = self.model:GetChildVehicleID( )
|
|
self.btn_wear_obj:SetActive(cur_wear_id ~= selectList.fashion_id)
|
|
self.btn_unwear_obj:SetActive(cur_wear_id == selectList.fashion_id)
|
|
|
|
-- 按钮红点
|
|
if not isMax then
|
|
self.btn_upgrade_red_dot_obj:SetActive(have_num >= need_num )
|
|
else
|
|
self.btn_upgrade_red_dot_obj:SetActive(false)
|
|
end
|
|
|
|
|
|
|
|
-- -- 技能
|
|
local skill_list = self.model:GetChildVehicleSkillList(selectList.fashion_id)
|
|
for i=1,#self.skill_item_list do
|
|
self.skill_item_list[i]:SetVisible(false)
|
|
end
|
|
if skill_list then
|
|
for k,v in pairs(skill_list) do
|
|
local item = self.skill_item_list[k]
|
|
if item == nil then
|
|
item = ChildVehicleSkillItem.New(self.skill_con)
|
|
self.skill_item_list[k] = item
|
|
end
|
|
self.skill_item_list[k]:SetData(v.fashion_id, v.lv, nowLevel, v.active_skill)
|
|
item:SetVisible(true)
|
|
end
|
|
end
|
|
|
|
-- 初始化特效
|
|
if self.need_check_effect then
|
|
self.need_check_effect = false
|
|
end
|
|
end
|
|
|
|
-- 播星星点亮特效
|
|
function ChildVehicleViewNew:PlayStarEffect( tran, i )
|
|
self.showing_star_effect = self.showing_star_effect or {}
|
|
if not self.showing_star_effect[i] then
|
|
local function call_back( )
|
|
self.showing_star_effect[i] = false
|
|
end
|
|
self:ClearUIEffect(tran)
|
|
self:AddUIEffect("ui_jinjiestar", tran, self.layer_name, nil, 1, false, nil, nil, call_back)
|
|
self.showing_star_effect[i] = true
|
|
end
|
|
end
|
|
|
|
function ChildVehicleViewNew:SwitchTab( index )
|
|
|
|
end
|
|
|
|
function ChildVehicleViewNew:DestroySuccess( )
|
|
for i, v in ipairs(self.attr_item_list) do
|
|
v:DeleteMe()
|
|
v = nil
|
|
end
|
|
self.attr_item_list = {}
|
|
|
|
for i, v in pairs(self.vehicle_item_list) do
|
|
v:DeleteMe()
|
|
v = nil
|
|
end
|
|
self.vehicle_item_list = {}
|
|
|
|
for i, v in ipairs(self.skill_item_list) do
|
|
v:DeleteMe()
|
|
v = nil
|
|
end
|
|
self.skill_item_list = {}
|
|
|
|
|
|
if self.UPDATA_CHILD_VEHICLE_INFO_id then
|
|
self.model:UnBind(self.UPDATA_CHILD_VEHICLE_INFO_id)
|
|
self.UPDATA_CHILD_VEHICLE_INFO_id = nil
|
|
end
|
|
|
|
if self.updata_child_vehicle_follow_id then
|
|
self.model:UnBind(self.updata_child_vehicle_follow_id)
|
|
self.updata_child_vehicle_follow_id = nil
|
|
end
|
|
|
|
if self.updata_Child_RED_DOT_VIEW_id then
|
|
self.model:UnBind(self.updata_Child_RED_DOT_VIEW_id)
|
|
self.updata_Child_RED_DOT_VIEW_id = nil
|
|
end
|
|
|
|
|
|
UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, self.up_item)
|
|
self.up_item = nil
|
|
|
|
-- if self.tab_win then
|
|
-- self.tab_win:DeleteMe()
|
|
-- self.tab_win = nil
|
|
-- end
|
|
end
|