require("game.proto.422.Require422")
|
|
require("game.wardrobe.WardrobeModel")
|
|
require("game.wardrobe.WardrobeConst")
|
|
require("game.wardrobe.WardrobeMainView")
|
|
require("game.wardrobe.WardrobeTotalItem")--总览item
|
|
require("game.wardrobe.WardrobeVerTabItem")--左边tab
|
|
require("game.wardrobe.WardrobeShopItem")--商店item
|
|
require("game.wardrobe.WardrobeShopView")--风采商店
|
|
require("game.wardrobe.WardrobeTipsView")--tip界面
|
|
|
|
WardrobeController = WardrobeController or BaseClass(BaseController, true)
|
|
local WardrobeController = WardrobeController
|
|
|
|
WardrobeController.IsDebug = true
|
|
|
|
function WardrobeController:__init()
|
|
WardrobeController.Instance = self
|
|
self.model = WardrobeModel:GetInstance()
|
|
self:AddEvents()
|
|
self:RegisterAllProtocal()
|
|
|
|
end
|
|
|
|
function WardrobeController:__delete()
|
|
end
|
|
|
|
function WardrobeController:RegisterAllProtocal( )
|
|
self:RegisterProtocal(42200, "Handle42200")--风采总览
|
|
self:RegisterProtocal(42201, "Handle42201")--风采值更新(推送单个类型)
|
|
self:RegisterProtocal(42202, "Handle42202")--商城信息
|
|
self:RegisterProtocal(42203, "Handle42203")--商城购买
|
|
end
|
|
|
|
function WardrobeController:AddEvents()
|
|
local function on_game_start()
|
|
self.model:Reset()
|
|
end
|
|
GlobalEventSystem:Bind(EventName.GAME_START, on_game_start)
|
|
|
|
local function onRequestHandler(...)
|
|
local args = {...}
|
|
if args[1] == 42202 then
|
|
self:SendFmtToGame(args[1], "c", args[2])
|
|
elseif args[1] == 42203 then
|
|
self:SendFmtToGame(args[1], "cii", args[2], args[3], args[4])
|
|
else
|
|
self:SendFmtToGame(args[1])
|
|
end
|
|
end
|
|
self.model:Bind(WardrobeConst.REQ_WARDROBE_SCMD, onRequestHandler)
|
|
|
|
local function update_red_dot_by_tab_id_func( tab_id )--主要的更新红点方法
|
|
if not tab_id then
|
|
self.model:IsNeedRedAll()
|
|
else
|
|
self.model:IsNeedRed(tab_id)
|
|
end
|
|
local red_dot = self.model:GetWardrobeAllRedDot()
|
|
local bool = false
|
|
for i,v in pairs(red_dot) do
|
|
if v then
|
|
bool = true
|
|
break
|
|
end
|
|
end
|
|
GlobalEventSystem:Fire(EventName.SHOW_FUNCTION_RED_POINT, 422, bool)
|
|
end
|
|
self.model:Bind(WardrobeConst.UPDATE_RED_DOT,update_red_dot_by_tab_id_func)
|
|
|
|
local on_open_main_view = function (index, sub_index, param_list)
|
|
if self.wardrobe_main_view == nil then
|
|
self.wardrobe_main_view = WardrobeMainView.New()
|
|
end
|
|
if self.wardrobe_main_view:HasOpen() then
|
|
self.wardrobe_main_view:ReOpen(index, sub_index, param_list)
|
|
else
|
|
self.wardrobe_main_view:Open(index, sub_index, param_list)
|
|
end
|
|
end
|
|
GlobalEventSystem:Bind(WardrobeConst.OPEN_WARDROBE_MAIN_VIEW, on_open_main_view)
|
|
|
|
local function open_wardrobe_tips_view(show)
|
|
if RoleManager.Instance.mainRoleInfo.level < Config.Moduleid[422].open_lv then return end
|
|
-- 如果界面还没加载完或者已经存在且在动画中则跳出
|
|
if self.tips_view and (not self.tips_view:HasOpen() or self.tips_view.is_animating) then return end
|
|
|
|
local function close_tips_view()
|
|
if self.tips_view:HasOpen() then
|
|
self.tips_view:Close()
|
|
end
|
|
end
|
|
if show then
|
|
local tip_data = self.model:GetWardrobeTipData()
|
|
if tip_data then
|
|
if self.tips_view == nil then
|
|
self.tips_view = WardrobeTipsView.New()
|
|
end
|
|
if not self.tips_view:HasOpen() then
|
|
self.tips_view:Open(tip_data)
|
|
else
|
|
self.tips_view:ResetViewInfo(tip_data)
|
|
end
|
|
else
|
|
close_tips_view()
|
|
end
|
|
else
|
|
close_tips_view()
|
|
end
|
|
end
|
|
self.model:Bind(WardrobeConst.OPEN_WARDROBE_TIP_VIEW, open_wardrobe_tips_view)
|
|
end
|
|
|
|
function WardrobeController:OnWardrobeGoodsUpdate( )
|
|
self.model:Fire(WardrobeConst.UPDATE_RED_DOT, WardrobeConst.TabId.DRESS)
|
|
end
|
|
|
|
-- ############## 风采总览 ##############
|
|
-- protocol=42200
|
|
-- {
|
|
-- c2s{
|
|
-- }
|
|
-- s2c{
|
|
-- stage :int8 // 阶数
|
|
-- sum_wardrobe_value :int32 // 总风采值
|
|
-- wardrobe_list:array{
|
|
-- type :int8 // 类型
|
|
-- wardrobe_value :int32 // 风采值
|
|
-- collect :int8 // 收集进度
|
|
-- sum_collect :int8 // 总收集量(每类外观配置决定)
|
|
-- }
|
|
-- }
|
|
-- }
|
|
function WardrobeController:Handle42200( )
|
|
local vo = SCMD42200.New(true)
|
|
-- print("HWR:WardrobeController [start:86] vo:", vo)
|
|
-- PrintTable(vo)
|
|
-- print("HWR:WardrobeController [end]")
|
|
self.model:SetWardrobeTotalInfo(vo)
|
|
end
|
|
|
|
-- ############## 风采值更新(推送单个类型) ##############
|
|
-- protocol=42201
|
|
-- {
|
|
-- s2c{
|
|
-- // 总风采
|
|
-- stage :int8 // 阶数
|
|
-- sum_wardrobe_value :int32 // 总风采值
|
|
-- // 单个类型进度
|
|
-- type :int8 // 类型
|
|
-- wardrobe_value :int32 // 风采值
|
|
-- collect :int8 // 收集进度
|
|
-- sum_collect :int8 // 总收集量(每类外观配置决定)
|
|
-- // 新激活外观信息
|
|
-- id :int32 // 进阶和伙伴是系统类型,其他是物品Id
|
|
-- color :int8 // 品质(进阶和伙伴是阶数,物品是颜色)
|
|
-- }
|
|
-- }
|
|
|
|
function WardrobeController:Handle42201( )
|
|
local vo = SCMD42201.New(true)
|
|
-- print("HWR:WardrobeController [start:157] vo:", vo)
|
|
-- PrintTable(vo)
|
|
-- print("HWR:WardrobeController [end]")
|
|
local need_add_extra = false--是否需要额外加一个商城出现的
|
|
-- local last_stage = self.model:GetMyWardrobeStage() --上次阶数
|
|
-- if vo.stage > last_stage then
|
|
-- local last_shop = 0
|
|
-- for i,v in ipairs(Config.Wardrobeopen) do--遍历第一次找上次商城id
|
|
-- if last_stage >= v.condition then
|
|
-- last_shop = v.store_id
|
|
-- end
|
|
-- end
|
|
-- --遍历第二次找激活的商城
|
|
-- local cur_shop = 0
|
|
-- for i=last_shop,#Config.Wardrobeopen do
|
|
-- if Config.Wardrobeopen[i] then
|
|
-- if vo.stage >= Config.Wardrobeopen[i].condition then
|
|
-- cur_shop = Config.Wardrobeopen[i].store_id
|
|
-- end
|
|
-- end
|
|
-- end
|
|
-- need_add_extra = cur_shop > last_shop
|
|
-- end
|
|
local up_value = vo.sum_wardrobe_value - self.model:GetMyWardrobeValue()
|
|
vo.up_value = up_value
|
|
self.model:SetWardrobeTotalOneInfo(vo)
|
|
self.model:SetWardrobeTipData(vo)
|
|
-- if need_add_extra then
|
|
-- vo.is_unlock = true
|
|
-- self.model:SetWardrobeTipData(vo)
|
|
-- end
|
|
end
|
|
|
|
-- ############## 商城信息 ##############
|
|
-- protocol=42202
|
|
-- {
|
|
-- c2s{
|
|
-- store_id :int8 // 货柜层数
|
|
-- }
|
|
-- s2c{
|
|
-- store_id :int8 // 货柜层数
|
|
-- goods_list:array{
|
|
-- pos :int16 // 商品位置
|
|
-- gtype_id :int32 // 商品类型Id
|
|
-- num :int32 // 已经购买的次数
|
|
-- }
|
|
-- }
|
|
-- }
|
|
|
|
function WardrobeController:Handle42202( )
|
|
local vo = SCMD42202.New(true)
|
|
self.model:SetWardrobeShopInfo(vo)
|
|
end
|
|
|
|
-- ############## 商城购买 ##############
|
|
-- protocol=42203
|
|
-- {
|
|
-- c2s{
|
|
-- store_id :int8 // 货柜层数
|
|
-- gtype_id :int32 // 商品类型Id
|
|
-- buy_times :int32 // 购买个数
|
|
-- }
|
|
-- s2c{
|
|
-- res :int32 // 返回码
|
|
-- store_id :int8 // 货柜层数
|
|
-- pos :int16 // 商品位置
|
|
-- gtype_id :int32 // 商品类型Id
|
|
-- num :int32 // 已经购买的次数
|
|
-- }
|
|
-- }
|
|
|
|
function WardrobeController:Handle42203( )
|
|
local vo = SCMD42203.New(true)
|
|
if vo.res == 1 then
|
|
Message.show("购买成功")
|
|
else
|
|
ErrorCodeShow(vo.res)
|
|
end
|
|
self.model:Fire(WardrobeConst.REQ_WARDROBE_SCMD, 42202, vo.store_id)
|
|
end
|