|
ChildTrainView = ChildTrainView or BaseClass(BaseView)
|
|
local ChildTrainView = ChildTrainView
|
|
|
|
local STAR_COUNT = 10 -- 星星数(每阶有多少级)
|
|
|
|
function ChildTrainView:__init()
|
|
self.base_file = "child"
|
|
self.layout_file = "ChildTrainView"
|
|
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.fire_change_visible_event = true
|
|
self.close_fog = true
|
|
self.model = ChildModel:getInstance()
|
|
self.show_figure_id = -1
|
|
|
|
self.attr_item_list = {} -- 属性item
|
|
self.img_moon_list = {} -- 进阶的星级
|
|
self.awardItems = {} -- 进阶展示的奖励
|
|
self.is_effect = false -- 是否正在播放逗BB特效
|
|
|
|
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 ChildTrainView:Open( )
|
|
--self.data = data
|
|
BaseView.Open(self)
|
|
end
|
|
|
|
function ChildTrainView:LoadSuccess()
|
|
local nodes = {
|
|
"bg:raw",
|
|
"btn_doubaobao:obj", "btn_show:obj", "btn_nice:obj", "btn_rank:obj",
|
|
"showBaby_con/tips_bg",
|
|
"showBaby_con/tips_bg/showCSBtn:obj", "showBaby_con/tips_bg/showWorldBtn:obj",
|
|
"showBaby_con/tips_bg/showGuildBtn:obj",
|
|
"showBaby_con:obj",
|
|
"rename_bg/btn_rename:obj", "rename_bg/text_name:tmp",
|
|
"toggle_show:obj", "qiPao_bg/qipao_text:tmp", "qiPao_bg:obj",
|
|
"effect_doubaobao","rt_image_show", "effectCon",
|
|
"close_btn:obj",
|
|
--------------------------------------------
|
|
"makeCon/btn_grow_all:obj",
|
|
"makeCon/ScrollView_attr_make/Viewport/attrContent_make", "makeCon/itemCon",
|
|
"makeCon/grow_loading_bg/grow_loading:img", "makeCon/grow_loading_bg/text_descr:tmp",
|
|
"makeCon/fightNum:txt",
|
|
"makeCon/levelText:tmp",
|
|
"makeCon/btn_grow_all/btn_grow_all_red_dot:obj",
|
|
}
|
|
self:GetChildren(nodes)
|
|
self.toggle_show_tog = self:GetChild("toggle_show"):GetComponent("Toggle")
|
|
|
|
-- 培养星级
|
|
for i = 1, STAR_COUNT do
|
|
self.img_moon_list[i] = {}
|
|
local temp = self.img_moon_list[i]
|
|
temp.transform = self:GetChild("makeCon/bg1/img_moon" .. i)
|
|
-- temp.img = temp.transform:GetComponent("Image")
|
|
temp.obj = temp.transform.gameObject
|
|
end
|
|
|
|
SetSizeDelta(self.showBaby_con, ScreenWidth, ScreenHeight)
|
|
|
|
self:UpdateBaseView()
|
|
end
|
|
|
|
function ChildTrainView:UpdateBaseView( )
|
|
lua_resM:setOutsideRawImage(self, self.bg_raw, GameResPath.GetViewBigBg("child_train_bg_1173_663"))
|
|
-- 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_train_bg_1173_663")
|
|
-- self.tab_win:SetTitleText("宝宝培养")
|
|
-- self.tab_win:ChangeShowFlag("Child")
|
|
|
|
-- 培养奖励
|
|
self.feedList = self.model:GetChildFeedList()
|
|
local start_x = 10
|
|
local start_y = -5
|
|
local item_width = 78
|
|
local inter_x = 29
|
|
for i = 1, #self.feedList do
|
|
self.awardItems[i] = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem,self.itemCon)
|
|
self.awardItems[i]:SetItemSize(item_width, item_width)
|
|
self.awardItems[i]:SetAnchoredPosition((i - 1) * (inter_x + item_width) + start_x, start_y)
|
|
-- SetLocalPosition(self.awardItems[i].transform, GetLocalPositionX(self.item_parent)+108*i,0, 0)
|
|
if self.feedList[i] then
|
|
self.awardItems[i]:SetData(self.feedList[i][1])
|
|
self.awardItems[i].ClickCallFun = function (target,target2,x,y) --覆盖AwardItem 的点击方法
|
|
local hadNum = GoodsModel:getInstance():GetTypeGoodsNum(self.feedList[i][1]) or 0
|
|
if hadNum >=1 then
|
|
self.model:Fire(ChildConst.CHILD_REQ_EVENT, 16504,0,self.awardItems[i].type_id,1)
|
|
else
|
|
UIToolTipMgr.getInstance():AppendGoodsTips(self.awardItems[i].type_id)
|
|
return
|
|
end
|
|
end
|
|
end
|
|
end
|
|
self:UpdateFeedItemNum()
|
|
|
|
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
|
|
--self.titleTmp_tmp.text = "宝宝培养"
|
|
local pos_x,pos_y = GetAnchoredPosition(self.btn_show)
|
|
SetAnchoredPosition(self.tips_bg, pos_x + 120, pos_y - 50)
|
|
end
|
|
|
|
function ChildTrainView:AddEvent()
|
|
local onBtnClickHandler = function ( target )
|
|
if target == self.btn_rank_obj then -- 宝宝排行
|
|
self.model:Fire(ChildConst.OPEN_CHILD_RANK_VIEW,true)
|
|
elseif target == self.btn_show_obj then -- 晒娃
|
|
self.model:Fire(ChildConst.OPEN_SHOW_BABY_VIEW, true)
|
|
elseif target == self.btn_nice_obj then -- 点赞记录
|
|
self.model:Fire(ChildConst.OPEN_CHILD_NICE_RECORD_VIEW,true)
|
|
elseif target == self.btn_doubaobao_obj then -- 逗娃
|
|
local function callback( )
|
|
if self.is_effect then
|
|
self.qiPao_bg_obj:SetActive(false)
|
|
self.is_effect = false
|
|
end
|
|
end
|
|
local time = 1.5
|
|
if self.is_effect == false then
|
|
self.is_effect = true
|
|
self.qiPao_bg_obj:SetActive(true)
|
|
local randomNum = math.random(1,#ChildConst.ChildMainViewDouBaoBaoSaying)
|
|
self.qipao_text_tmp.text = ChildConst.ChildMainViewDouBaoBaoSaying[randomNum] or "宝宝无话可说"
|
|
self.doubaobao_effect_id = self:AddUIEffect("ui_doubaobao", self.effect_doubaobao, "UI", Vector3(0,0,0), 1, false, time, nil, callback)
|
|
end
|
|
-- 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 target == self.btn_rename_obj then -- 宝宝改名
|
|
self.model:Fire(ChildConst.OPEN_CHILD_RENAME_VIEW, true)
|
|
elseif target == self.toggle_show_obj then -- 宝宝跟随
|
|
self.model:Fire(ChildConst.CHILD_REQ_EVENT, 16516)
|
|
elseif target == self.btn_grow_all_obj then
|
|
self.model:Fire(ChildConst.CHILD_REQ_EVENT, 16504,1,0,0)
|
|
-- 点击一键成长时要刷进度条和属性特效
|
|
self.has_click_all_need_effect = true
|
|
elseif target == self.close_btn_obj then
|
|
self:Close()
|
|
end
|
|
end
|
|
-- 左侧按钮
|
|
AddClickEvent(self.btn_doubaobao_obj, onBtnClickHandler)
|
|
AddClickEvent(self.btn_rank_obj, onBtnClickHandler, LuaSoundManager.SOUND_UI.NONE)
|
|
AddClickEvent(self.btn_show_obj, onBtnClickHandler)
|
|
AddClickEvent(self.btn_nice_obj, onBtnClickHandler, LuaSoundManager.SOUND_UI.NONE)
|
|
-- 晒娃按钮
|
|
-- AddClickEvent(self.showBaby_con_obj, onBtnClickHandler)
|
|
-- AddClickEvent(self.showWorldBtn_obj, onBtnClickHandler)
|
|
-- AddClickEvent(self.showCSBtn_obj, onBtnClickHandler)
|
|
-- AddClickEvent(self.showGuildBtn_obj, onBtnClickHandler)
|
|
-- 改名/跟随
|
|
AddClickEvent(self.btn_rename_obj, onBtnClickHandler)
|
|
AddClickEvent(self.toggle_show_obj, onBtnClickHandler)
|
|
-- 右边
|
|
AddClickEvent(self.btn_grow_all_obj, onBtnClickHandler)
|
|
AddClickEvent(self.close_btn_obj, onBtnClickHandler)
|
|
|
|
local function update_make_con(need_anim)
|
|
self:UpdateView(need_anim)
|
|
end
|
|
self:BindEvent(self.model, ChildConst.UPDATA_CHILD_MAIN_INFO, update_make_con)
|
|
end
|
|
|
|
function ChildTrainView:OpenSuccess()
|
|
self:UpdateView()
|
|
end
|
|
|
|
function ChildTrainView:UpdateView(need_anim)
|
|
local list = self.model:GetChildInfo()
|
|
self.text_name_tmp.text = list.child_name or ""
|
|
self.toggle_show_tog.isOn = list.is_follow == 1 and true or false
|
|
self.toggle_show_obj:SetActive(self.model:GetChildCurState( ) ~= ChildConst.BABY_STATE.BABY)
|
|
self:UpdateMakeCon( need_anim )
|
|
end
|
|
|
|
function ChildTrainView:UpdateFeedItemNum( )
|
|
local bool = self.model:GetChildRedDotList()[ChildConst.TabId.ChildTrain]
|
|
self.btn_grow_all_red_dot_obj:SetActive(bool)
|
|
for i = 1, #self.feedList do
|
|
local hadNum = GoodsModel:getInstance():GetTypeGoodsNum(self.feedList[i][1]) or 0
|
|
self.awardItems[i]:SetNumText(hadNum)
|
|
end
|
|
end
|
|
|
|
function ChildTrainView:UpdateMakeCon( need_anim )
|
|
local list = self.model:GetChildInfo()
|
|
local growUpList = self.model:GetChildNowGrowUpInfo()
|
|
local growUpNextList = self.model:GetChildNextGrowUpInfo()
|
|
if not growUpList then return end
|
|
|
|
-- 下一阶级的属性
|
|
local attr_list_next = {}
|
|
if growUpNextList then
|
|
attr_list_next = stringtotable(growUpNextList.attr_list)
|
|
--self.img_arrow_obj:SetActive(true)
|
|
else --满级时
|
|
--self.img_arrow_obj:SetActive(false)
|
|
end
|
|
|
|
|
|
local yearNum = math.floor((growUpList.month) / STAR_COUNT) -- 进阶数 (原来叫法是年份)
|
|
local monthNum = (growUpList.month) % STAR_COUNT -- 当前阶级星级数 (原来叫法的月份)
|
|
-- 阶数
|
|
local last_num = tonumber(self.levelText_tmp.text)
|
|
self.levelText_tmp.text = yearNum
|
|
-- 当前阶级星星数
|
|
local is_up = false
|
|
self.showing_star_effect = self.showing_star_effect or {}
|
|
for i = 1, STAR_COUNT do
|
|
if self.has_init_star_effect then -- 非第一次创建
|
|
if (i <= monthNum and self.img_moon_list[i].obj.activeSelf == false) or -- 由灰转亮
|
|
(i <= monthNum and last_num < yearNum) then -- 跳阶段
|
|
if not self.showing_star_effect[i] then
|
|
local function call_back( )
|
|
self.showing_star_effect[i] = false
|
|
end
|
|
self:ClearUIEffect(self.img_moon_list[i].transform)
|
|
self:AddUIEffect("ui_jinjiestar", self.img_moon_list[i].transform, self.layer_name, nil, 1, false, nil, nil, call_back)
|
|
self.showing_star_effect[i] = true
|
|
end
|
|
|
|
is_up = true
|
|
end
|
|
end
|
|
self.img_moon_list[i].obj:SetActive(i <= monthNum)
|
|
end
|
|
if not self.has_init_star_effect then
|
|
self.has_init_star_effect = true
|
|
end
|
|
|
|
-- 属性
|
|
local attr_list = stringtotable(growUpList.attr_list)
|
|
for k,v in pairs(attr_list) do
|
|
local item = self.attr_item_list[k]
|
|
if item == nil then
|
|
item = ChildGrowItem.New(self.attrContent_make)
|
|
self.attr_item_list[k] = item
|
|
end
|
|
local num2 = nil
|
|
for k2,v_next_lv in pairs(attr_list_next) do
|
|
if v[1] == v_next_lv[1] then
|
|
num2 = v_next_lv[2]
|
|
end
|
|
end
|
|
self.attr_item_list[k]:SetData(v[1],v[2],num2,k, is_up or self.has_click_all_need_effect)
|
|
end
|
|
|
|
-- 进阶进度条
|
|
local new_rate = list.child_age_exp/growUpList.need_exp
|
|
local old_rate = tonumber(self.grow_loading_img.fillAmount)
|
|
-- print('=======Msh:ChildTrainView.lua[310] =======', self.model:GetPreAgeMonth(), old_rate, new_rate, need_anim)
|
|
-- PrintCallStack()
|
|
if need_anim then
|
|
local old_age_month = self.model:GetPreAgeMonth( )
|
|
local set_func = function( )
|
|
self.text_descr_tmp.text = string.format("<color=#ffffff>%s</color>/%s", list.child_age_exp, growUpList.need_exp)
|
|
end
|
|
local need_time
|
|
local need_time_2
|
|
--print('Msh:ChildTrainView.lua[317] data', old_age_month, list.child_age_month)
|
|
if old_age_month ~= -1 and old_age_month < list.child_age_month then -- 涨满再归零再涨
|
|
--logWarn('=======Msh:ChildTrainView.lua[318]=======')
|
|
need_time = 1 * (1 - old_rate)
|
|
need_time = need_time >= 0.3 and need_time or 0.3
|
|
need_time_2 = 1 * new_rate
|
|
need_time_2 = need_time_2 >= 0.3 and need_time_2 or 0.3
|
|
local end_func = function ()
|
|
self:ShowFillAmountAnim(0, new_rate, set_func, need_time_2 )
|
|
end
|
|
self:ShowFillAmountAnim( old_rate, 1, end_func, need_time )
|
|
else -- 直接涨
|
|
--logWarn('=======Msh:ChildTrainView.lua[328]=======')
|
|
need_time = 1 * (new_rate - old_rate)
|
|
need_time = need_time >= 0.3 and need_time or 0.3
|
|
self:ShowFillAmountAnim( old_rate, new_rate, set_func, need_time )
|
|
end
|
|
else
|
|
self.grow_loading_img.fillAmount = new_rate
|
|
self.text_descr_tmp.text = string.format("<color=#ffffff>%s</color>/%s", list.child_age_exp, growUpList.need_exp)
|
|
end
|
|
|
|
|
|
-- 战力
|
|
self.fightNum_txt.text = "f" .. GetFighting(attr_list)
|
|
|
|
self:UpdateRoleModel( )
|
|
|
|
-- 点击过一键成长的要强制播特效
|
|
if self.has_click_all_need_effect then
|
|
self:PlayUpEffect(0) -- 进度条
|
|
else
|
|
if is_up then
|
|
self:PlayUpEffect(0) -- 进度条
|
|
self:PlayUpEffect(1) -- 模型
|
|
end
|
|
end
|
|
|
|
self.has_click_all_need_effect = false -- 重置点击状态
|
|
|
|
self:UpdateFeedItemNum( )
|
|
end
|
|
|
|
-- 进度条动画 注意:new_rate > old_rate
|
|
function ChildTrainView:ShowFillAmountAnim( old_rate, new_rate, end_fun, need_time )
|
|
cc.ActionManager:getInstance():removeAllActionsFromTarget(self.transform)
|
|
if new_rate <= old_rate then
|
|
self.grow_loading_img.fillAmount = new_rate
|
|
if end_fun then
|
|
end_fun()
|
|
end
|
|
return
|
|
-- print('=======Msh:ChildTrainView.lua[363] ===有问题哟====', old_rate, new_rate)
|
|
end
|
|
-- 进度条
|
|
local function rotate_front2(percent)
|
|
self.grow_loading_img.fillAmount = old_rate + (new_rate - old_rate) * percent
|
|
end
|
|
local action1 = cc.CustomUpdate.New(need_time, rotate_front2)
|
|
|
|
-- 结束动画
|
|
local function callback_1()
|
|
if end_fun then
|
|
end_fun()
|
|
end
|
|
end
|
|
local call_func_1 = cc.CallFunc.New(callback_1)
|
|
local action9 = cc.Sequence.New( action1, call_func_1)--顺序
|
|
cc.ActionManager:getInstance():addAction(action9, self.transform)
|
|
end
|
|
|
|
function ChildTrainView:PlayUpEffect( id )
|
|
if id == 0 then -- 进度条
|
|
if not self.showing_effect_per_1 then
|
|
local function call_back( )
|
|
self.showing_effect_per_1 = false
|
|
end
|
|
self:ClearUIEffect(self.grow_loading)
|
|
self:AddUIEffect("ui_jinjiejindu", self.grow_loading, self.layer_name, Vector3(-120,0,0), 1, false, 0.6, nil, call_back)
|
|
self.showing_effect_per_1 = true
|
|
end
|
|
elseif id == 1 then
|
|
if not self.showing_effect_model 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( 14, 80, 0), 1, false, 1.5, nil, call_back)
|
|
self.showing_effect_model = true
|
|
end
|
|
end
|
|
end
|
|
|
|
function ChildTrainView:UpdateRoleModel(need_effect)
|
|
local show_figure_id = self.model:GetChildCloth()
|
|
-- if need_effect then
|
|
-- self:ClearUIEffect(self.rt_image_show)
|
|
-- self:AddUIEffect("ui_jinjie", self.rt_image_show, self.layer_name, nil, 1, false, 1.5, nil)
|
|
-- end
|
|
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.rt_image_show,
|
|
fashion_type = FuncOpenModel.TypeId.Child,
|
|
figure_id = show_figure_id,
|
|
ui_model_type = UIModelCommon.ModelType.BackModel,
|
|
can_rotate = true,
|
|
}
|
|
FuncOpenModel:getInstance():SetModelRes(res_data)
|
|
end
|
|
|
|
function ChildTrainView:SwitchTab( index )
|
|
|
|
end
|
|
|
|
function ChildTrainView:DestroySuccess( )
|
|
for i, v in pairs(self.attr_item_list) do
|
|
v:DeleteMe()
|
|
v = nil
|
|
end
|
|
self.attr_item_list = {}
|
|
|
|
if self.doubaobao_effect_id then
|
|
self.particle_mgr:DelEffect(self.doubaobao_effect_id)
|
|
self.doubaobao_effect_id = false
|
|
end
|
|
|
|
for i=1,#self.awardItems do
|
|
if self.awardItems[i] then
|
|
UIObjPool:getInstance():PushItem(UIObjPool.UIType.AwardItem, self.awardItems[i])
|
|
self.awardItems[i] = nil
|
|
end
|
|
end
|
|
|
|
-- if self.tab_win then
|
|
-- self.tab_win:DeleteMe()
|
|
-- self.tab_win = nil
|
|
-- end
|
|
|
|
cc.ActionManager:getInstance():removeAllActionsFromTarget(self.transform)
|
|
end
|