|
|
- ChildDressViewNew = ChildDressViewNew or BaseClass(BaseView)
- local ChildDressViewNew = ChildDressViewNew
- --[[
- ChildDressViewNew.TabData = {
- [1] = {name = "人物", level = MainRoleModel.TabOpenLevel[1]},
- }
- --]]
-
- function ChildDressViewNew:__init()
- self.base_file = "child"
- self.layout_file = "ChildDressViewNew"
- 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.blur_activity_bg = true
- self.close_fog = true
-
- self.model = ChildModel:getInstance()
-
- self.dress_item_list = {}
- self.attr_item_list = {}
- self.attr_sum_item_list = {}
- self.img_star_list = {}
- self.select_item2 = nil
- self.fashion_type_select = 0
-
- 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 ChildDressViewNew:Open( )
- --self.data = data
- BaseView.Open(self)
- end
-
- function ChildDressViewNew:LoadSuccess()
- local nodes = {
- "bg:raw",
- "mid/text_name:tmp", -- 名字
- "mid/rt_image_show", -- 模型
- "mid/btn_wear:obj:img",
- "mid/btn_unwear:obj:img",
- "mid/effectCon",
- -------------------------------
- "right/txt_fight:obj:txt", -- 战力
- "right/ScrollView_attr/Viewport/content_attr", -- 属性con
- "right/btn_upgrade:obj", -- 激活/升阶按钮
- "right/btn_upgrade/btn_upgrade_txt:tmp",
- "right/btn_upgrade/btn_upgrade_red_dot:obj",
- -- 时装item
- "right/ScrollView_up_item/Viewport/Content_up_item",
- "right/ScrollView_up_item/Viewport:obj",
- "right/ScrollView_up_item",
- "right/awardCon:obj",
- "close:obj",
- "right/ScrollView_up_item/Viewport/Content_up_item/di_bg_con:obj",
- "right/attrDes:tmp",
- }
- self:GetChildren(nodes)
-
- -- 进阶星星
- for i = 1, 5 do
- self.img_star_list[i] = self:GetChild("right/stars/star"..i):GetComponent("Image")
- end
-
- self:UpdateBaseView( )
- end
-
- function ChildDressViewNew:UpdateBaseView( )
- lua_resM:setOutsideRawImage(self, self.bg_raw, GameResPath.GetViewBigBg("child_dress_bg_1227_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:SetTitleRes("child_asset","child_title") --标题
- -- 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)
- -- self:MoveUIToBack(self.tab_win.win_bg)
- end
- if self.background_wnd then
- bg_back_func()
- else
- self.bg_back_func = bg_back_func
- end
- end
-
- function ChildDressViewNew:AddEvent()
- local function onBtnClickHandler(target, x, y)
- if target == self.btn_wear_obj then
- local data = self.select_item2.data
- if data.is_vehicle then
- self.model:Fire(ChildConst.CHILD_REQ_EVENT, 16517, 1, data.fashion_id)
- else
- --宝宝时装穿戴
- self.model:Fire(ChildConst.CHILD_REQ_EVENT, 16530, 1, data.fashion_type, data.fashion_id)
- end
- elseif target == self.btn_unwear_obj then
- local data = self.select_item2.data
- if data.is_vehicle then
- self.model:Fire(ChildConst.CHILD_REQ_EVENT, 16517, 2, data.fashion_id)
- else
- --宝宝时装脱下
- self.model:Fire(ChildConst.CHILD_REQ_EVENT, 16530, 2, data.fashion_type, data.fashion_id)
- end
- elseif target == self.close_obj then
- self:Close()
- elseif target == self.btn_upgrade_obj then
- local data = self.select_item2.data
- local function upFunc( )
- --宝宝时装激活
- if self.select_item2.type == ChildConst.ChildDressItemType.Lock then
- Message.show("物品不足")
- return
- end
- if self.select_item2.type == ChildConst.ChildDressItemType.CanActive then
- if data.is_vehicle then
- self.model:Fire(ChildConst.CHILD_REQ_EVENT, 16515, 1, data.fashion_id)
- else
- self.model:Fire(ChildConst.CHILD_REQ_EVENT, 16531, 1, data.fashion_id,0)
- end
- else --宝宝时装升级
- if data.is_vehicle then
- self.model:Fire(ChildConst.CHILD_REQ_EVENT, 16515, 2, data.fashion_id)
- else
- local isBoolNum = 0 -- 默认不自动购买了
- local buyType = self.select_item2.type == ChildConst.ChildDressItemType.Lock and 1 or 2
- self.model:Fire(ChildConst.CHILD_REQ_EVENT, 16531, buyType, data.fashion_id,isBoolNum)
- end
- end
- end
- local isMax
- if data.is_vehicle then
- isMax = self.model:IsChildVehicleLvMax(self.select_item2.data.fashion_id,self.select_item2.data.lv)
- else
- isMax = self.model:IsChildFashionLvMax(self.select_item2.data.fashion_id,self.select_item2.data.lv)
- end
-
- if isMax then
- Message.show("已经满级了哦", "fault")
- -- elseif self.isShowCostTipNum and self.toggle_bug_obj:GetComponent("Toggle").isOn then
- -- local listCost = stringtotable(self.select_item2.data.buy_price)
- -- local moneyTypeName = WordManager:GetCommonMoneyStr(listCost[1])
- -- local ask_str = "物品不足,是否消耗<color=#ff6519>"..self.isShowCostTipNum.."</color>"..moneyTypeName.."进行补全?"
- -- Alert.show(ask_str,Alert.Type.Two,upFunc,nil,"确定","取消")
- else
- upFunc()
- end
- end
- end
- AddClickEvent(self.btn_wear_obj, onBtnClickHandler)
- AddClickEvent(self.btn_unwear_obj, onBtnClickHandler)
- AddClickEvent(self.btn_upgrade_obj, onBtnClickHandler)
- AddClickEvent(self.close_obj, onBtnClickHandler)
-
- local function UPDATA_CHILD_DRESS_INFO_fun(type, check_effect)
- self.need_check_effect = true
- self:UpdateView(nil,self.select_item2, check_effect)
- if self.select_item2 then
- self:SetItemCon2(self.select_item2) -- 得拿到最新的
- end
- end
- self.UPDATA_CHILD_DRESS_INFO_id = self.model:Bind(ChildConst.UPDATA_CHILD_DRESS_INFO, UPDATA_CHILD_DRESS_INFO_fun,vo)
- self:BindEvent(self.model, ChildConst.UPDATA_CHILD_VEHICLE_FOLLOW, UPDATA_CHILD_DRESS_INFO_fun)
- end
-
- function ChildDressViewNew:UpdateRedDot()
- for k,v in pairs(self.dress_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 = false
- if v.data.is_vehicle then
- is_max = self.model:IsChildVehicleLvMax(v.data.fashion_id,v.data.lv)
- else
- is_max = self.model:IsChildFashionLvMax(v.data.fashion_id,v.data.lv)
- end
- if not is_max then
- self.dress_item_list[k]:SetRedDot(true)
- else
- self.dress_item_list[k]:SetRedDot(false)
- end
- else
- self.dress_item_list[k]:SetRedDot(false)
- end
- end
- end
-
- function ChildDressViewNew:UpdateRoleModel( figure_id, is_vehicle, need_effect )
- local show_figure_id
- if figure_id and not is_vehicle then -- 非载具时装的选中
- show_figure_id = self.model:GetFashionModelID(figure_id)
- else
- show_figure_id = self.model:GetChildCloth()
- end
-
- if (not self.showing_effect_model) and need_effect then
- local function call_back( )
- self.showing_effect_model = false
- end
- self:ClearUIEffect(self.effectCon)
- self:AddUIEffect("ui_jinjie", self.effectCon, self.layer_name, Vector3(15,0,0), 1, false, 1.5, nil, call_back)
- self.showing_effect_model = true
- end
-
- local action_name_list
- if is_vehicle then
- --action_name_list = {"ride"}
- -- SetLocalPositionY(self.rt_image_show, 287)
- -- local show_conf = ChildConst.ModelShowConfig[1011] -- 默认模型
- local res_data = {
- father_node = self,
- transform = self.rt_image_show,
- fashion_type = FuncOpenModel.TypeId.Child,
- -- figure_id = show_figure_id,
- ui_model_type = UIModelCommon.ModelType.BackModel,
- action_name_list = action_name_list,
- free_param = self.model:GetVehicleModelID(figure_id),
- type = SceneBaseType.Baby_Include_Horse,
- clothe_res_id = show_figure_id,
- position = Vector3(0, 100, 0),
- rotate = -50,
- scale = 6,
- raycast_size = Vector2(340,460),
- }
- lua_resM:SetBackRoleModel(self, res_data.transform, res_data)
- else
- -- SetLocalPositionY(self.rt_image_show, 163)
- local res_data = {
- father_node = self,
- transform = self.rt_image_show,
- fashion_type = FuncOpenModel.TypeId.Child,
- figure_id = show_figure_id,
- ui_model_type = UIModelCommon.ModelType.BackModel,
- action_name_list = action_name_list,
- }
- FuncOpenModel:getInstance():SetModelRes(res_data)
- end
- end
-
- function ChildDressViewNew:OpenSuccess()
- self:UpdateView()
- end
-
- function ChildDressViewNew:UpdateView(fashion_type_before_function, select_item, check_effect)
- local fashion_type = 1 --装饰已经永久取消了,仅有1
-
- local dressList = self.model:GetChildDressList()
- -- local vehicle_list = self.model:GetChildVehicleList()
-
- -- item参数
- local item_width = 196
- local item_height = 204
- local start_x = 7
- local start_y = 1
- local space_x = 5.5
- local space_y = 0
-
- -- 衣柜挡板
- local total_count = TableSize(dressList)
- local di_bg_count = math.ceil(total_count / 3)
- self.di_item_list = self.di_item_list or {}
- for k,v in pairs(self.di_item_list) do
- if v.obj then
- v.obj:SetActive(false)
- end
- end
- for i=1, di_bg_count do
- if not self.di_item_list[i] then
- self.di_item_list[i] = {}
- self.di_item_list[i].obj = UiFactory.createChild(self.di_bg_con, UIType.Image2)
- self.di_item_list[i].tran = self.di_item_list[i].obj.transform
- self.di_item_list[i].img = self.di_item_list[i].obj:GetComponent("Image")
- lua_resM:setOutsideImageSprite(self, self.di_item_list[i].img, GameResPath.GetChildIcon("child_dress_di_bg"), true)
- end
- local image_item = self.di_item_list[i]
- SetLocalPosition(image_item.tran, -24.5, space_y - i * (item_height + space_y) + 73, 0)
- image_item.obj:SetActive(true)
- end
-
- -- item创建
- local dress_count = 0
-
- local function callback( item )
- for k,v in pairs(self.dress_item_list) do
- v:SetChosen(false)
- end
- self.select_item2 = item
- item:SetChosen(true)
- self:SetItemCon2(item)
- end
-
- SetSizeDeltaY(self.Content_up_item, (item_height + space_y) * di_bg_count + 70)
- for k,v in pairsByKeys(dressList) do
- dress_count = dress_count + 1
- local k = dress_count
- local item = self.dress_item_list[k]
- if item == nil then
- item = ChildDressItem.New(self.Content_up_item)
- self.dress_item_list[k] = item
- end
-
- self.dress_item_list[k]:SetData(v,callback,k, check_effect)
- self.dress_item_list[k]:SetVisible(true)
- if (not select_item and k == 1) or -- 第一次打开 没有选中的 就选第一个
- (select_item and v.fashion_id == select_item.data.fashion_id) -- 已有选中的 且本次是它
- then
- self.select_item2 = self.dress_item_list[k]
- self.select_item2:SetChosen(true)
- self:SetItemCon2(self.select_item2)
- end
- local pos_x = start_x + ((dress_count - 1) % 3) * (space_x + item_width)
- local pos_y = start_y - math.floor((dress_count - 1) / 3) * (space_y + item_height)
- self.dress_item_list[k]:SetPosition(pos_x, pos_y)
- end
-
- --[[ -- 载具排后面
- for k,v in pairsByKeys(vehicle_list) do
- dress_count = dress_count + 1
- local k = dress_count
- local item = self.dress_item_list[k]
- if item == nil then
- item = ChildDressItem.New(self.Content_up_item)
- self.dress_item_list[k] = item
- end
-
- self.dress_item_list[k]:SetData(v,callback,k, check_effect)
- self.dress_item_list[k]:SetVisible(true)
- if (not select_item and k == 1) or -- 第一次打开 没有选中的 就选第一个
- (select_item and v.fashion_id == select_item.data.fashion_id) -- 已有选中的 且本次是它
- then
- self.select_item2 = self.dress_item_list[k]
- self.select_item2:SetChosen(true)
- self:SetItemCon2(self.select_item2)
- end
-
- local pos_x = start_x + ((dress_count - 1) % 3) * (space_x + item_width)
- local pos_y = start_y - math.floor((dress_count - 1) / 3) * (space_y + item_height)
- self.dress_item_list[k]:SetPosition(pos_x, pos_y)
- end--]]
-
- for i = dress_count + 1, #self.dress_item_list do
- self.dress_item_list[i]:SetVisible(false)
- end
- -----
- self:UpdateRedDot()
- end
-
- function ChildDressViewNew:SetItemCon2(item2 )
- -- print('Msh:ChildDressViewNew.lua[329] data')
- -- PrintCallStack()
- local selectList = item2.data
- local check_effect = self.need_check_effect -- 是否要检查特效播放
- -- btn红点
- -- 时装是否升到满级
- local type_id = selectList.fashion_id
-
- local isMax = false
-
- if selectList.is_vehicle then
- isMax = self.model:IsChildVehicleLvMax(type_id, selectList.lv)
- else
- isMax = self.model:IsChildFashionLvMax(type_id, selectList.lv)
- end
-
- local is_active = item2.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 = item2 .type == ChildConst.ChildDressItemType.isActive and "升级" or "激活"
- -- self.btn_upgrade_txt_tmp.text = item2.type == ChildConst.ChildDressItemType.Lock and "激活" or "升级"
- -- if item2.type == ChildConst.ChildDressItemType.CanActive then
- -- self.btn_upgrade_txt_tmp.text = "激活"
- -- end
-
- --logWarn('=======Msh:ChildDressView.lua[414]=======')
- --print('Msh:ChildDressView.lua[415] data', item2.type, is_active, goods_name, have_num, need_num, isMax)
- if isMax then -- 时装已经激活 且 升满
- self.btn_upgrade_txt_tmp.text = "已满"
- self.awardCon_obj:SetActive(false)
- else -- 没有满级
- --local listCost = stringtotable(selectList.buy_price)
- 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
- --logWarn('=======Msh:ChildDressViewNew.lua[341]=======', type_id)
- --if selectList.is_vehicle then
- -- type_id = tonumber(stringtotable(selectList.upgrade_cost)[1][2])
- --end
- self.up_item:SetData(type_id)
- --local basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(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
- if selectList.is_vehicle then
- attr_list = stringtotable(Config.Childvehicle[selectList.fashion_id .. "@1"].add_attr)
- else
- attr_list = stringtotable(Config.Childfashion[selectList.fashion_id .. "@1"].attr_list)
- end
- 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(-180, 20, 0), 1, false, 0.75, nil, call_back)
- end
- end
- self.txt_fight_txt.text = new_fight
-
- -- 模型
- self:UpdateRoleModel(selectList.fashion_id, selectList.is_vehicle, 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--]]
- self.attrDes_tmp.text = ""
- for k,v in pairsByKeys(attr_list) do
- local _, name1, _, val1 = WordManager:GetPropertyInfo(v[1], v[2])
- if self.attrDes_tmp.text ~= "" then
- self.attrDes_tmp.text = self.attrDes_tmp.text .. " "
- end
- self.attrDes_tmp.text = self.attrDes_tmp.text .. name1 .. ":" .. HtmlColorTxt( val1, ColorUtil.GREEN_DARK)
- end
-
-
- -- 设置进阶星星数
- local nowLevel = tonumber(selectList.lv)
- self.pre_lv = 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
-
- -- 按钮红点
- 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
-
- -- 穿戴/脱下 按钮
- if selectList.is_vehicle then
- 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)
- else
- local cur_wear_id = self.model:GetCurWearID( )
- self.btn_wear_obj:SetActive(cur_wear_id ~= selectList.fashion_id)
- self.btn_unwear_obj:SetActive(cur_wear_id == selectList.fashion_id)
- end
-
- -- 初始化特效
- if self.need_check_effect then
- self.need_check_effect = false
- end
- end
-
- -- 播星星点亮特效
- function ChildDressViewNew:PlayStarEffect( tran, i )
- self.showing_star_effect = self.showing_star_effect or {}
- if true then
- 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
- end
-
- function ChildDressViewNew:SwitchTab( index )
-
- end
-
- function ChildDressViewNew:DestroySuccess( )
- if self.up_item then
- UIObjPool:PushItem(UIObjPool.UIType.AwardItem, self.up_item)
- self.up_item = false
- end
-
- for i, v in pairs(self.attr_item_list) do
- v:DeleteMe()
- v = nil
- end
- self.attr_item_list = {}
-
- for i, v in pairs(self.dress_item_list) do
- v:DeleteMe()
- v = nil
- end
- self.dress_item_list = {}
-
- if self.UPDATA_CHILD_DRESS_INFO_id then
- self.model:UnBind(self.UPDATA_CHILD_DRESS_INFO_id)
- self.UPDATA_CHILD_DRESS_INFO_id = nil
- end
-
- -- if self.tab_win then
- -- self.tab_win:DeleteMe()
- -- self.tab_win = nil
- -- end
- end
|