|
ChildMainViewNew = ChildMainViewNew or BaseClass(BaseView)
|
|
local ChildMainViewNew = ChildMainViewNew
|
|
--[[
|
|
ChildMainViewNew.TabData = {
|
|
[1] = {name = "人物", level = MainRoleModel.TabOpenLevel[1]},
|
|
}
|
|
--]]
|
|
|
|
function ChildMainViewNew:__init()
|
|
self.base_file = "child"
|
|
self.layout_file = "ChildMainViewNew"
|
|
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 = false --是否要添加进界面堆栈
|
|
self.need_show_money = false --是否要显示顶部的金钱栏
|
|
self.fire_change_visible_event = false
|
|
self.model = ChildModel:getInstance()
|
|
self.show_figure_id = -1
|
|
self.close_fog = true
|
|
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 ChildMainViewNew:Open( view_id, param)
|
|
self.view_id = view_id
|
|
self.param = param
|
|
BaseView.Open(self)
|
|
end
|
|
|
|
function ChildMainViewNew:LoadSuccess()
|
|
local nodes = {
|
|
"trainBtn:obj", "handBookBtn:obj", "dressBtn:obj","vehicleBtn:obj",
|
|
"skillBtn:obj", "bg:raw", "tabWinCon",
|
|
---------------------------
|
|
"showBaby_con/tips_bg/showCSBtn:obj", "showBaby_con/tips_bg/showWorldBtn:obj",
|
|
"showBaby_con/tips_bg/showGuildBtn:obj", "showBaby_con:obj",
|
|
"modelCon",
|
|
"trainBtn/trainBtnRed:obj", --"showBabyBtn/showBabyBtnRed:obj",
|
|
"dressBtn/dressBtnRed:obj", "handBookBtn/handBookBtnRed:obj",
|
|
"skillBtn/skillBtnRed:obj", "vehicleBtn/vehicleBtnRed:obj",
|
|
--晒娃
|
|
"con_show_baby:obj",
|
|
"con_show_baby/showBabyBtn/showBabyBtnRed:obj",
|
|
"con_show_baby/showBabyBtn:obj",
|
|
"con_show_baby/icon_can_get:obj",
|
|
"con_show_baby/icon_has_get:obj",
|
|
"con_show_baby/btn_baby_nice_record:obj",
|
|
"con_show_baby/btn_show_baby_rank:obj",
|
|
"con_show_baby/con_award",
|
|
"con_show_baby/lb_reward_count:tmp",
|
|
"con_show_baby/show_baby_bg:img",
|
|
"con_show_baby/btn_show_baby_rank/red_btn_show_baby_rank:obj",
|
|
}
|
|
self:GetChildren(nodes)
|
|
self:UpdateBaseView( )
|
|
end
|
|
|
|
function ChildMainViewNew:UpdateBaseView( )
|
|
lua_resM:setOutsideRawImage(self, self.bg_raw, GameResPath.GetJpgImage("baby_main_1280_720"), false)
|
|
lua_resM:setOutsideImageSprite(self, self.show_baby_bg_img, GameResPath.GetChildIcon("child_show_baby_bg"), false)
|
|
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
|
|
-- 针对特殊分辨率下模型位置会偏移的处理
|
|
if ScreenWidth / ScreenHeight < 1280 / 720 then
|
|
local cur_height = (720 * ScreenWidth) / 1280
|
|
self.add_height = (ScreenHeight - cur_height) / 4
|
|
else
|
|
self.add_height = 0
|
|
end
|
|
end
|
|
|
|
function ChildMainViewNew:AddEvent()
|
|
local onBtnClickHandler = function ( target )
|
|
if self.trainBtn_obj == target then -- 打开孩子培养
|
|
self.model:Fire(ChildConst.OPEN_CHILD_TRAIN_VIEW, true)
|
|
elseif self.handBookBtn_obj == target then -- 打开玩具收集
|
|
self.model:Fire(ChildConst.OPEN_CHILD_HAND_BOOK_VIEW, true)
|
|
elseif self.dressBtn_obj == target then -- 打开孩子时装/载具
|
|
if self.model:CheckDressIsOpen() then
|
|
self.model:Fire(ChildConst.OPEN_CHILD_DRESS_VIEW, true)
|
|
else
|
|
local str = string.format('宝宝时装在宝宝%s阶时开放', math.floor(self.model:GetChildMaxGrowState() / 10) )
|
|
Message.show(str)
|
|
end
|
|
elseif self.showBabyBtn_obj == target then -- 晒娃
|
|
self.model:Fire(ChildConst.OPEN_SHOW_BABY_VIEW, true)
|
|
elseif target == self.btn_show_baby_rank_obj then -- 宝宝排行
|
|
self.model:Fire(ChildConst.OPEN_CHILD_RANK_VIEW, true)
|
|
elseif target == self.btn_baby_nice_record_obj then -- 点赞记录
|
|
self.model:Fire(ChildConst.OPEN_CHILD_NICE_RECORD_VIEW,true)
|
|
-- self.showBaby_con_obj:SetActive(true)
|
|
-- elseif target == self.showBaby_con_obj then -- 关闭晒娃
|
|
-- self.showBaby_con_obj:SetActive(false)
|
|
-- elseif target == self.showWorldBtn_obj then -- 世界晒娃
|
|
-- self.showBaby_con_obj:SetActive(false)
|
|
-- if RoleManager.Instance.mainRoleInfo.level >= Config.Moduleid[110].open_lv then
|
|
-- self.model:Fire(ChildConst.CHILD_REQ_EVENT, 16509,ChatModel.CHANNEL_WORLD)
|
|
-- else
|
|
-- Message.show("等级不足"..Config.Moduleid[110].open_lv, "fault")
|
|
-- end
|
|
-- elseif target == self.showCSBtn_obj then -- 跨服晒
|
|
-- self.showBaby_con_obj:SetActive(false)
|
|
-- if RoleManager.Instance.mainRoleInfo.level >= Config.ConfigOpenLv.ChatOpenLevel.CROSS then
|
|
-- self.model:Fire(ChildConst.CHILD_REQ_EVENT, 16509,ChatModel.CHANNEL_CROSS)
|
|
-- else
|
|
-- Message.show("等级不足"..Config.ConfigOpenLv.ChatOpenLevel.CROSS, "fault")
|
|
-- end
|
|
-- --Message.show("2")
|
|
-- elseif target == self.showGuildBtn_obj then -- 社团晒
|
|
-- self.showBaby_con_obj:SetActive(false)
|
|
-- if RoleManager.Instance.mainRoleInfo.level >= Config.ConfigOpenLv.ChatOpenLevel.GUILD and ( RoleManager.Instance:GetMainRoleVo().guild_id and RoleManager.Instance:GetMainRoleVo().guild_id ~= 0) then
|
|
-- self.model:Fire(ChildConst.CHILD_REQ_EVENT, 16509,ChatModel.CHANNEL_GUILD)
|
|
-- else
|
|
-- Message.show("社团频道还未开启哦", "fault")
|
|
-- end
|
|
elseif self.skillBtn_obj == target then -- 打开孩子技能
|
|
if self.model:CheckSkillIsOpen() then
|
|
self.model:Fire(ChildConst.OPEN_CHILD_SKILL_VIEW, true)
|
|
else
|
|
local str = string.format('宝宝技能在宝宝%s阶时开放', self.model:GetConfigChildKvVal("skill_open_stage"))
|
|
Message.show(str)
|
|
end
|
|
elseif self.vehicleBtn_obj == target then
|
|
self.model:Fire(ChildConst.OPEN_CHILD_VEHICLE_VIEW, true)
|
|
end
|
|
end
|
|
-- 功能跳转
|
|
AddClickEvent(self.trainBtn_obj, onBtnClickHandler)
|
|
AddClickEvent(self.handBookBtn_obj, onBtnClickHandler)
|
|
AddClickEvent(self.dressBtn_obj, onBtnClickHandler)
|
|
AddClickEvent(self.showBabyBtn_obj, onBtnClickHandler)
|
|
AddClickEvent(self.skillBtn_obj, onBtnClickHandler)
|
|
AddClickEvent(self.vehicleBtn_obj, onBtnClickHandler)
|
|
-- 晒娃
|
|
-- AddClickEvent(self.showBaby_con_obj, onBtnClickHandler)
|
|
-- AddClickEvent(self.showWorldBtn_obj, onBtnClickHandler)
|
|
-- AddClickEvent(self.showCSBtn_obj, onBtnClickHandler)
|
|
-- AddClickEvent(self.showGuildBtn_obj, onBtnClickHandler)
|
|
AddClickEvent(self.btn_baby_nice_record_obj, onBtnClickHandler)
|
|
AddClickEvent(self.btn_show_baby_rank_obj, onBtnClickHandler)
|
|
|
|
|
|
local function on_ans_update_red_dot( tab_id )--设置红点的状态注意此处的协议是从model那边发过来的
|
|
self:UpdateRedDot(tab_id)
|
|
end
|
|
self.on_ans_update_red_dot_id = self.model:Bind(ChildConst.Child_RED_DOT_VIEW, on_ans_update_red_dot)
|
|
|
|
local function update_model()
|
|
self:UpdateRoleModel( )
|
|
end
|
|
self:BindEvent(self.model, ChildConst.UPDATA_CHILD_MAIN_INFO, update_model)
|
|
self:BindEvent(self.model, ChildConst.UPDATA_CHILD_DRESS_INFO, update_model)
|
|
|
|
local function update_reward_func()
|
|
self:UpdateShowBaby()
|
|
end
|
|
self:BindEvent(self.model, ChildConst.UPDATE_RANK_REWARD_RED, update_reward_func)
|
|
|
|
local function play_show_baby_effect_func()
|
|
self.param = self.param or {}
|
|
self.param.need_show_baby_effect = true
|
|
self:UpdateShowBaby()
|
|
end
|
|
self:BindEvent(self.model, ChildConst.PLAY_SHOW_BABY_EFFECT, play_show_baby_effect_func)
|
|
end
|
|
|
|
function ChildMainViewNew:OpenSuccess()
|
|
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_base_bg")
|
|
self.tab_win:SetTitleText("宝宝")
|
|
self.tab_win:ChangeShowFlag("Child")
|
|
self:UpdateView()
|
|
if self.view_id then
|
|
self:OpenSubView(self.view_id)
|
|
self.view_id = nil
|
|
end
|
|
end
|
|
|
|
-- 跳转到子界面
|
|
function ChildMainViewNew:OpenSubView( view_id )
|
|
if view_id == ChildConst.TabId.ChildTrain then -- 打开孩子培养
|
|
self.model:Fire(ChildConst.OPEN_CHILD_TRAIN_VIEW, true)
|
|
elseif view_id == ChildConst.TabId.ChildHandbook then -- 打开玩具收集
|
|
self.model:Fire(ChildConst.OPEN_CHILD_HAND_BOOK_VIEW, true)
|
|
elseif view_id == ChildConst.TabId.ChildDress then -- 打开孩子时装/载具
|
|
if self.model:CheckDressIsOpen() then
|
|
self.model:Fire(ChildConst.OPEN_CHILD_DRESS_VIEW, true)
|
|
else
|
|
local str = string.format('宝宝时装在宝宝%s阶时开放', math.floor(self.model:GetChildMaxGrowState() / 10) )
|
|
Message.show(str)
|
|
end
|
|
elseif view_id == ChildConst.TabId.ChildSkill then -- 打开孩子技能
|
|
if self.model:CheckSkillIsOpen() then
|
|
self.model:Fire(ChildConst.OPEN_CHILD_SKILL_VIEW, true)
|
|
else
|
|
local str = string.format('宝宝技能在宝宝%s阶时开放', self.model:GetConfigChildKvVal("skill_open_stage"))
|
|
Message.show(str)
|
|
end
|
|
elseif view_id == ChildConst.TabId.ChildVehicle then -- 孩子载具
|
|
self.model:Fire(ChildConst.OPEN_CHILD_VEHICLE_VIEW, true)
|
|
end
|
|
end
|
|
|
|
function ChildMainViewNew:UpdateView()
|
|
self:UpdateRoleModel()
|
|
self:UpdateShowBaby()
|
|
self:UpdateRedDot()
|
|
end
|
|
|
|
function ChildMainViewNew:UpdateRoleModel( )
|
|
local show_figure_id = self.model:GetChildCloth()
|
|
-- if self.show_figure_id == show_figure_id then
|
|
-- return
|
|
-- end
|
|
self.show_figure_id = show_figure_id
|
|
local res_data = {
|
|
father_node = self,
|
|
transform = self.modelCon,
|
|
fashion_type = FuncOpenModel.TypeId.Child,
|
|
figure_id = show_figure_id,
|
|
ui_model_type = UIModelCommon.ModelType.BackModel,
|
|
can_rotate = false,
|
|
}
|
|
FuncOpenModel:getInstance():SetModelRes(res_data)
|
|
|
|
local PARAM = ChildConst.MainViewModelAnimParams
|
|
|
|
SetLocalPosition(self.modelCon, PARAM.START_POS_X, PARAM.START_POS_Y + self.add_height, 0)
|
|
cc.ActionManager:getInstance():removeAllActionsFromTarget(self.modelCon)
|
|
GlobalTimerQuest:CancelQuest(self.delay_id)
|
|
|
|
if self.model:GetChildCurState( ) ~= ChildConst.BABY_STATE.BABY then -- 非襁褓期才播动画
|
|
local function delay_method( )
|
|
self:UpdateAnimation( )
|
|
end
|
|
self.delay_id = GlobalTimerQuest:AddPeriodQuest(delay_method, 4, 1)
|
|
end
|
|
end
|
|
|
|
function ChildMainViewNew:UpdateAnimation( )
|
|
local child_model = lua_resM:GetPartModel(self, self.modelCon)
|
|
|
|
if child_model then
|
|
local PARAM = ChildConst.MainViewModelAnimParams
|
|
|
|
|
|
------------------------------------------------
|
|
-- 停一停 循环开始
|
|
local action1 = cc.DelayTime.New( PARAM.WAIT_TIME_LEFT )
|
|
|
|
-- 切换为奔跑动作
|
|
local function callback_1()
|
|
child_model:ClearActionTimerList()
|
|
child_model:PlayActions({"run"})
|
|
end
|
|
local call_func_1 = cc.CallFunc.New(callback_1)
|
|
|
|
-- 转向 180 -> 90
|
|
local function rotate_right(percent)
|
|
child_model.transform.localRotation = Quaternion.Euler(Vector3(0, 180 - (90 * percent),0))
|
|
end
|
|
local action2 = cc.CustomUpdate.New(PARAM.ROTATE_TIME, rotate_right)
|
|
|
|
-- 移动
|
|
local function move_right(percent)
|
|
SetAnchoredPositionX(self.modelCon, PARAM.START_POS_X + PARAM.MOVE_DIST * percent)
|
|
end
|
|
local action3 = cc.CustomUpdate.New(PARAM.MOVE_TIME, move_right)
|
|
|
|
-- 转向 90 -> 180
|
|
local function rotate_front(percent)
|
|
child_model.transform.localRotation = Quaternion.Euler(Vector3(0, 90 + (90 * percent),0))
|
|
end
|
|
local action4 = cc.CustomUpdate.New(PARAM.ROTATE_TIME, rotate_front)
|
|
|
|
-- 切换为show2动作
|
|
local function callback_2()
|
|
child_model:ClearActionTimerList()
|
|
child_model:PlayActions({"show2", "show"})
|
|
end
|
|
local call_func_2 = cc.CallFunc.New(callback_2)
|
|
|
|
-- 停一停
|
|
local action5 = cc.DelayTime.New( PARAM.WAIT_TIME_RIGHT )
|
|
|
|
-- 向左看 并 切换为奔跑动作
|
|
local function callback_3()
|
|
child_model:ClearActionTimerList()
|
|
child_model:PlayActions({"run"})
|
|
end
|
|
local call_func_3 = cc.CallFunc.New(callback_3)
|
|
|
|
-- 转向 180 -> 270
|
|
local function rotate_left(percent)
|
|
child_model.transform.localRotation = Quaternion.Euler(Vector3(0, 180 + (90 * percent),0))
|
|
end
|
|
local action6 = cc.CustomUpdate.New(PARAM.ROTATE_TIME, rotate_left)
|
|
|
|
-- 移动
|
|
local function move_left(percent)
|
|
SetAnchoredPositionX(self.modelCon, PARAM.START_POS_X + PARAM.MOVE_DIST * (1-percent))
|
|
end
|
|
local action7 = cc.CustomUpdate.New(PARAM.MOVE_TIME, move_left)
|
|
|
|
-- 转向 180 -> 270
|
|
local function rotate_front2(percent)
|
|
child_model.transform.localRotation = Quaternion.Euler(Vector3(0, 270 - (90 * percent),0))
|
|
end
|
|
local action8 = cc.CustomUpdate.New(PARAM.ROTATE_TIME, rotate_front2)
|
|
|
|
-- 切换为show2动作(复用上面的方法)
|
|
|
|
-- 循环结束
|
|
------------------------------------------------
|
|
local action9 = cc.Sequence.New( action1, call_func_1, action2, action3, action4, call_func_2, action5,call_func_3, action6, action7, action8, call_func_2)--顺序
|
|
local action10 = cc.RepeatForever.New( action9 )
|
|
cc.ActionManager:getInstance():addAction(action10, self.modelCon)
|
|
end
|
|
end
|
|
|
|
function ChildMainViewNew:UpdateRedDot(id)
|
|
if id == ChildConst.TabId.ChildTrain then -- 宝宝培养
|
|
self:UpdateTrainRed()
|
|
elseif id == ChildConst.TabId.ChildVehicle then -- 坐骑
|
|
self:UpdateVehicleRed()
|
|
elseif id == ChildConst.TabId.ChildDress then -- 时装
|
|
self:UpdateDressRed()
|
|
elseif id == ChildConst.TabId.ChildSkill then -- 技能
|
|
self:UpdateSkillRed()
|
|
elseif id == ChildConst.TabId.ChildHandbook then -- 玩具
|
|
self:UpdateHandbookRed()
|
|
else
|
|
self:UpdateTrainRed()
|
|
self:UpdateDressRed()
|
|
self:UpdateSkillRed()
|
|
self:UpdateHandbookRed()
|
|
self:UpdateVehicleRed()
|
|
end
|
|
end
|
|
|
|
function ChildMainViewNew:UpdateTrainRed( )
|
|
local bool = self.model:GetChildRedDotList()[ChildConst.TabId.ChildTrain]
|
|
self.trainBtnRed_obj:SetActive(bool)
|
|
end
|
|
|
|
function ChildMainViewNew:UpdateDressRed( )
|
|
local bool = self.model:GetChildRedDotList()[ChildConst.TabId.ChildDress]
|
|
self.dressBtnRed_obj:SetActive( self.model:CheckDressIsOpen( ) and bool )
|
|
end
|
|
|
|
function ChildMainViewNew:UpdateVehicleRed( )
|
|
local bool = self.model:GetChildRedDotList()[ChildConst.TabId.ChildVehicle]
|
|
self.vehicleBtnRed_obj:SetActive( bool )
|
|
end
|
|
|
|
function ChildMainViewNew:UpdateSkillRed( )
|
|
local bool = self.model:GetChildRedDotList()[ChildConst.TabId.ChildSkill]
|
|
self.skillBtnRed_obj:SetActive(bool)
|
|
end
|
|
|
|
function ChildMainViewNew:UpdateHandbookRed( )
|
|
local bool = self.model:GetChildRedDotList()[ChildConst.TabId.ChildHandbook]
|
|
self.handBookBtnRed_obj:SetActive(bool)
|
|
end
|
|
|
|
function ChildMainViewNew:SwitchTab( index )
|
|
|
|
end
|
|
|
|
function ChildMainViewNew:HideChangeCall( bool )
|
|
if bool then
|
|
self:UpdateRoleModel()
|
|
end
|
|
end
|
|
|
|
----------晒娃相关-start---------
|
|
function ChildMainViewNew:UpdateShowBaby( )
|
|
local childList = self.model:GetChildInfo()
|
|
local get_count = childList.share_reward == 2 and 0 or 1
|
|
local color = get_count > 0 and ColorUtil.GREEN_DARK or ColorUtil.RED_DARK
|
|
self.lb_reward_count_tmp.text = string.format('今日领奖次数:%s/1', HtmlColorTxt( get_count, color))
|
|
|
|
-- 奖励item
|
|
self.award_item = self.award_item or UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self.con_award)
|
|
self.award_item:SetItemSize(78, 78)
|
|
local reward = stringtotable(self.model:GetConfigChildKvVal("show_gift"))[1]
|
|
self.award_item:SetVisible(reward and true or false)
|
|
if reward then
|
|
local typeId, lock = GoodsModel:getInstance():GetMappingTypeId(reward[1], reward[2])
|
|
self.award_item:SetData(typeId, reward[3], nil, nil, lock)
|
|
end
|
|
self.icon_can_get_obj:SetActive(childList.share_reward == 1)
|
|
self.icon_has_get_obj:SetActive(childList.share_reward == 2)
|
|
self.award_item:SetGray(childList.share_reward == 2)
|
|
if childList.share_reward == 1 then
|
|
self.award_item:SetCallBack(function ()
|
|
self.model:Fire(ChildConst.CHILD_REQ_EVENT, 16540, 1)
|
|
end)
|
|
else
|
|
self.award_item:SetCallBack( nil )
|
|
end
|
|
|
|
self.showBabyBtnRed_obj:SetActive(childList.share_reward == 0)
|
|
if self.param and self.param.need_show_baby_effect then
|
|
self:ClearUIEffect(self.showBabyBtn)
|
|
self:AddUIEffect("ui_jujiaodianji", self.showBabyBtn, self.layer_name, nil, 1, false, 3)
|
|
self.param.need_show_baby_effect = nil
|
|
end
|
|
|
|
self.red_btn_show_baby_rank_obj:SetActive(self.model:GetShowBabyRankReward())
|
|
end
|
|
----------晒娃相关-end-----------
|
|
|
|
function ChildMainViewNew:DestroySuccess( )
|
|
if self.tab_win then
|
|
self.tab_win:DeleteMe()
|
|
self.tab_win = nil
|
|
end
|
|
|
|
if self.on_ans_update_red_dot_id then
|
|
self.model:UnBind(self.on_ans_update_red_dot_id)
|
|
self.on_ans_update_red_dot_id = nil
|
|
end
|
|
|
|
if self.delay_id then
|
|
GlobalTimerQuest:CancelQuest(self.delay_id)
|
|
end
|
|
|
|
cc.ActionManager:getInstance():removeAllActionsFromTarget(self.modelCon)
|
|
|
|
if self.award_item then
|
|
UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, self.award_item)
|
|
end
|
|
self.award_item = nil
|
|
|
|
self:ClearUIEffect(self.showBabyBtn)
|
|
end
|