--[[@------------------------------------------------------------------
|
|
@description:云购界面
|
|
@author:wyb
|
|
----------------------------------------------------------------------]]
|
|
|
|
CloudShoppingView = CloudShoppingView or BaseClass(BaseView)
|
|
|
|
function CloudShoppingView:__init()
|
|
self.base_file = "cloudShopping"
|
|
self.layout_file = "CloudShoppingView"
|
|
self.layer_name = "UI"
|
|
-- self.use_local_view = true
|
|
self.use_background = true
|
|
self.close_mode = CloseMode.CloseDestroy
|
|
self.destroy_imm = true
|
|
self.append_to_ctl_queue = true
|
|
|
|
self.model = CustomActivityModel:getInstance()
|
|
self.item_list = {}
|
|
self.event_list = {}
|
|
self.first_open_view = false
|
|
self.base_type = CustomActivityModel.CustomActBaseType.CLOUD_SHOPPING
|
|
|
|
self.load_callback = function ()
|
|
self:LoadSuccess()
|
|
self:InitEvent()
|
|
end
|
|
self.open_callback = function ()
|
|
if self.sub_type then
|
|
self.model:Fire(CustomActivityModel.PROTO_CCMD_EVENT, 33112, self.sub_type)
|
|
end
|
|
end
|
|
self.close_callback = function ()
|
|
self:Remove()
|
|
end
|
|
end
|
|
|
|
function CloudShoppingView:Open(sub_type, open_type)
|
|
self.sub_type = sub_type
|
|
self.open_type = open_type
|
|
|
|
BaseView.Open(self)
|
|
end
|
|
|
|
function CloudShoppingView:Remove()
|
|
self:CancelLeftTimer()
|
|
for _, v in pairs(self.event_list) do
|
|
self.model:UnBind(v)
|
|
v = nil
|
|
end
|
|
for _, v in pairs(self.item_list) do
|
|
v:DeleteMe()
|
|
v = nil
|
|
end
|
|
self.item_list = {}
|
|
self.first_open_view = false
|
|
self:CancelTimer()
|
|
end
|
|
|
|
function CloudShoppingView:LoadSuccess()
|
|
self.bg2,
|
|
self.iconOne,
|
|
self.iconTen
|
|
= GetChildImages(self.transform, {
|
|
"bg2",
|
|
"rightCon/poolCon/btnOne/icon",
|
|
"rightCon/poolCon/btnTen/icon"
|
|
})
|
|
-- lua_resM:setOutsideImageSprite(self, self.bg2, GameResPath.GetJpgImage("cloud_shopping_bg.jpg"), false)
|
|
|
|
self.txtProgress,
|
|
self.txtPrice,
|
|
self.txtTime,
|
|
self.txtBuy,
|
|
self.txtLimit,
|
|
self.txtOne,
|
|
self.txtTen,
|
|
self.txtName
|
|
= GetChildTexts(self.transform, {
|
|
"leftCon/txtProgress",
|
|
"leftCon/priceCon/txtPrice",
|
|
"rightCon/timeCon/txtTime",
|
|
"rightCon/poolCon/txtBuy",
|
|
"rightCon/poolCon/txtLimit",
|
|
"rightCon/poolCon/btnOne/text",
|
|
"rightCon/poolCon/btnTen/text",
|
|
"leftCon/nameCon/txtName",
|
|
})
|
|
|
|
self.imgGoods,
|
|
self.effect
|
|
= GetChildTransforms(self.transform, {
|
|
"leftCon/imgGoods",
|
|
"leftCon/effect",
|
|
})
|
|
self.timeCon,
|
|
self.imgOver,
|
|
self.btnHelp,
|
|
self.btnReward,
|
|
self.btnOne,
|
|
self.btnTen,
|
|
self.probBtn,
|
|
self.btnGL,
|
|
self.clickGo
|
|
= GetChildGameObjects(self.transform, {
|
|
"rightCon/timeCon",
|
|
"rightCon/imgOver",
|
|
"rightCon/btnHelp",
|
|
"rightCon/btnReward",
|
|
"rightCon/poolCon/btnOne",
|
|
"rightCon/poolCon/btnTen",
|
|
"Window/probBtn",
|
|
"rightCon/btnGL",
|
|
"clickGo"
|
|
})
|
|
|
|
self.box_list = {}
|
|
for i = 1, 14 do
|
|
self.box_list[i] = self:GetChild("rightCon/poolCon/BoxCon/Box" .. i)
|
|
end
|
|
self:AddUIEffect("effect_xunbao_001_3", self.effect, self.layer_name, nil, 0.7, true)
|
|
end
|
|
|
|
function CloudShoppingView:InitEvent()
|
|
local onClickHandler = function (target, x, y)
|
|
if not self.goods_basic then
|
|
return
|
|
end
|
|
|
|
local onGotoBag = function ()
|
|
local ok_callback = function ()
|
|
GlobalEventSystem:Fire(EventName.OPEN_BAG_VIEW)
|
|
end
|
|
Alert.show("您的背包已满,无法购买,是否前往整理背包!", Alert.Type.Two, ok_callback, nil, "确定", "取消")
|
|
end
|
|
|
|
local empty = GoodsModel:getInstance():GetEmptyGrid()
|
|
local goodsNum = GoodsModel:getInstance():GetTypeGoodsNum(self.type_id)
|
|
|
|
if self.btnOne == target then
|
|
if empty <= 0 then
|
|
onGotoBag()
|
|
return
|
|
end
|
|
|
|
if goodsNum >= self.cost then
|
|
self.model:Fire(CustomActivityModel.PROTO_CCMD_EVENT, 33113, self.sub_type, 1, 0)
|
|
else
|
|
if TreasureHuntModel:getInstance().not_show["cloud_shopping"] then
|
|
self.model:Fire(CustomActivityModel.PROTO_CCMD_EVENT, 33113, self.sub_type, 1, 1)
|
|
else
|
|
self:TipsFunc(self.cost, 1)
|
|
end
|
|
end
|
|
elseif self.btnTen == target then
|
|
if empty < 10 then
|
|
onGotoBag()
|
|
return
|
|
end
|
|
|
|
if goodsNum >= (self.cost * 10) then
|
|
self.model:Fire(CustomActivityModel.PROTO_CCMD_EVENT, 33113, self.sub_type, 10, 0)
|
|
else
|
|
if TreasureHuntModel:getInstance().not_show["cloud_shopping"] then
|
|
self.model:Fire(CustomActivityModel.PROTO_CCMD_EVENT, 33113, self.sub_type, 10, 1)
|
|
else
|
|
self:TipsFunc(self.cost * 10, 10)
|
|
end
|
|
end
|
|
elseif self.btnReward == target then
|
|
self.model:Fire(CustomActivityModel.OPEN_CLOUD_REWARD_VIEW, self.sub_type)
|
|
elseif self.btnHelp == target then
|
|
if not self.open_type then return end
|
|
if self.open_type == CustomActivityModel.CloudShoppingType.BenFu then
|
|
UIToolTipMgr:getInstance():AppendSimpleTips(Config.ConfigActStatic.CloudShoppingDescBenFu, x, y)
|
|
elseif self.open_type == CustomActivityModel.CloudShoppingType.KuaFu then
|
|
UIToolTipMgr:getInstance():AppendSimpleTips(Config.ConfigActStatic.CloudShoppingDescKuaFu, x, y)
|
|
end
|
|
elseif self.probBtn == target then
|
|
elseif self.clickGo == target then
|
|
self:ClickBigRewardFunc(x, y)
|
|
elseif target == self.btnGL then
|
|
self.model:Fire(CustomActivityModel.OPEN_CLOUD_SHOP_ODDS_VIEW)
|
|
end
|
|
end
|
|
AddClickEvent(self.btnOne, onClickHandler)
|
|
AddClickEvent(self.btnTen, onClickHandler)
|
|
AddClickEvent(self.btnReward, onClickHandler)
|
|
AddClickEvent(self.btnHelp, onClickHandler)
|
|
AddClickEvent(self.probBtn, onClickHandler)
|
|
AddClickEvent(self.btnGL, onClickHandler)
|
|
AddClickEvent(self.clickGo, onClickHandler)
|
|
|
|
local onUpdate = function ()
|
|
self:SetData()
|
|
if self.first_open_view == false then
|
|
-- self:UpdateItems()
|
|
self.first_open_view = true
|
|
end
|
|
end
|
|
self.event_list[1] = self.model:Bind(CustomActivityModel.UPDATE_CLOUD_SHOPPING_VIEW, onUpdate)
|
|
|
|
local onUpateItem = function ()
|
|
--购买成功之后的处理
|
|
self:UpdateItems()
|
|
end
|
|
self.event_list[2] = self.model:Bind(CustomActivityModel.UPDATE_CLOUD_BUY_LIST, onUpateItem)
|
|
end
|
|
|
|
function CloudShoppingView:TipsFunc(costNum, buyNum)
|
|
local goodsNum = GoodsModel:getInstance():GetTypeGoodsNum(self.type_id)
|
|
local goodsPrice, _ = GoodsModel:getInstance():GetGoodsPrice(self.goods_basic.type_id)
|
|
local str_color = WordManager.GetGoodsColor(self.goods_basic.color)
|
|
local need_price = (costNum - goodsNum) * goodsPrice
|
|
local content = string.format("当前材料<color=%s>%s</color>不足\n",
|
|
str_color, Trim(self.goods_basic.goods_name))
|
|
local per_str = "是否使用"..need_price
|
|
local cur_str = "立即补充<color=#4eae1a>" .. (costNum - goodsNum) .. "</color>个"
|
|
local jin = RoleManager.Instance.mainRoleInfo:GetRealJin()
|
|
local function ok_callback()
|
|
if jin >= need_price then
|
|
self.model:Fire(CustomActivityModel.PROTO_CCMD_EVENT, 33113, self.sub_type, buyNum, 1)
|
|
else
|
|
Message.show("您的彩钻不足")
|
|
end
|
|
end
|
|
TreasureHuntModel:getInstance():Fire(TreasureHuntModel.OPEN_HINT_VIEW, "cloud_shopping", content, ok_callback, per_str, cur_str)
|
|
|
|
end
|
|
|
|
function CloudShoppingView:SetData()
|
|
self.act_data = self.model:getActList(self.base_type)
|
|
self.data = self.model:GetCloudShoppingInfo()
|
|
if not self.act_data or not self.data then
|
|
return
|
|
end
|
|
|
|
self:SetLeftTime()
|
|
self:CreateItems()
|
|
end
|
|
|
|
function CloudShoppingView:SetLeftTime()
|
|
local time = self.data.next_reward_time - TimeUtil:getServerTime()
|
|
local function timer_func()
|
|
self:CancelLeftTimer()
|
|
local timeStr = TimeUtil:timeConvert9(time)
|
|
self.txtTime.text = time > 0 and timeStr or ""
|
|
if time <= 0 then
|
|
self:CancelLeftTimer()
|
|
end
|
|
if time - 3600 > 0 then --大于1小时的
|
|
local duration = 60
|
|
local first_time = time % 60 --先计算秒数的
|
|
if first_time ~= 0 then
|
|
duration = first_time
|
|
end
|
|
local function delayFunc( )
|
|
time = time - duration
|
|
|
|
timer_func()
|
|
end
|
|
self.left_time_id = GlobalTimerQuest:AddPeriodQuest(delayFunc, duration)
|
|
else
|
|
local function delayFunc( )
|
|
time = time - 1
|
|
timer_func()
|
|
end
|
|
self.left_time_id = GlobalTimerQuest:AddPeriodQuest(delayFunc, 1)
|
|
end
|
|
end
|
|
timer_func()
|
|
self.imgOver:SetActive(time <= 0)
|
|
self.timeCon:SetActive(time > 0)
|
|
end
|
|
|
|
function CloudShoppingView:CancelLeftTimer()
|
|
if self.left_time_id then
|
|
GlobalTimerQuest:CancelQuest(self.left_time_id)
|
|
self.left_time_id = nil
|
|
end
|
|
end
|
|
|
|
function CloudShoppingView:CreateItems()
|
|
local cfg = Config.Cloudbuy[self.data.big_reward_id]
|
|
if cfg then
|
|
local boxList = ErlangParser:GetInstance():Parse(cfg.happy_awards)
|
|
if TableSize(boxList) > 0 then
|
|
local onSortFunc = function (a, b)
|
|
return tonumber(a[2]) < tonumber(b[2])
|
|
end
|
|
table.sort(boxList, onSortFunc)
|
|
|
|
local item = nil
|
|
for i, v in ipairs(boxList) do
|
|
if self.box_list[i] then
|
|
local reward_id = tonumber(v[2])
|
|
item = self.item_list[reward_id]
|
|
if item == nil then
|
|
item = CloudShoppingItem.New(self.box_list[i])
|
|
self.item_list[reward_id] = item
|
|
end
|
|
item:SetData(reward_id)
|
|
end
|
|
end
|
|
end
|
|
|
|
local total_count = tonumber(cfg.total_count)
|
|
local buyNumStr = "<color="..ColorUtil.GREEN..">" .. self.data.all_buy_num .. "</color>"
|
|
self.txtProgress.text = string.format("开奖进度:%s/%d", buyNumStr, total_count)
|
|
self.txtPrice.text = cfg.worth
|
|
buyNumStr = "<color="..ColorUtil.GREEN..">" .. self.data.self_buy_num .. "</color>"
|
|
local leftStr = total_count - self.data.all_buy_num > 0 and "<color="..ColorUtil.GREEN..">" .. (total_count - self.data.all_buy_num) .. "</color>" or "<color="..ColorUtil.RED..">0</color>"
|
|
self.txtBuy.text = string.format("您已购买%s份(剩余%s份)", buyNumStr, leftStr)
|
|
|
|
local unlimited_time, award_time = self:GetActCondition()
|
|
if unlimited_time and award_time then
|
|
local cur_hour = os.date("%H", TimeUtil:getServerTime())
|
|
cur_hour = tonumber(cur_hour)
|
|
local str = ""
|
|
local buy_time_str = self.data.less_buy_num > 0 and self.data.less_buy_num or "<color="..ColorUtil.RED..">0</color>"
|
|
if cur_hour < unlimited_time or cur_hour > award_time then
|
|
str = string.format("(还可购买%s份,开奖前%d小时不限制)", buy_time_str, award_time - unlimited_time)
|
|
else
|
|
str = string.format("(还可购买%s份)", buy_time_str)
|
|
end
|
|
self.txtLimit.text = str
|
|
end
|
|
|
|
self:SetGiftName(cfg)
|
|
self:SetGiftModel(cfg)
|
|
self:SetCost(cfg.cost)
|
|
end
|
|
end
|
|
|
|
function CloudShoppingView:SetGiftName(cfg)
|
|
local reward = ErlangParser:GetInstance():Parse(cfg.rewards)
|
|
if TableSize(reward) > 0 then
|
|
local type_id = 0
|
|
if cfg.reward_type == 2 then --按职业区分
|
|
local career = RoleManager.Instance:GetMainRoleVo().career
|
|
for _,v in pairs(reward) do
|
|
if career == tonumber(v[1]) then
|
|
type_id = tonumber(v[2][1][2])
|
|
break
|
|
end
|
|
end
|
|
else
|
|
type_id = tonumber(reward[1][2])
|
|
end
|
|
local goods_basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(type_id)
|
|
if goods_basic then
|
|
local goodsName = "<color="..WordManager.GetGoodsColor(goods_basic.color) .. "><a@><u>"..Trim(goods_basic.goods_name) .. "</u></a></color>"
|
|
local numStr = "<color="..ColorUtil.GREEN..">(" .. cfg.award_count .. "份)</color>"
|
|
self.txtName.text = goodsName .. numStr
|
|
|
|
local call_back = function(param, x, y)
|
|
self:ClickBigRewardFunc(x, y)
|
|
end
|
|
AddUnderLineAndClick(self, self.txtName.transform, call_back, false, true)
|
|
end
|
|
end
|
|
end
|
|
|
|
function CloudShoppingView:ClickBigRewardFunc(x, y)
|
|
local cfg = Config.Cloudbuy[self.data.big_reward_id]
|
|
if not cfg then
|
|
return
|
|
end
|
|
local reward = ErlangParser:GetInstance():Parse(cfg.rewards)
|
|
if TableSize(reward) > 0 then
|
|
local type_id = 0
|
|
if cfg.reward_type == 2 then --按职业区分
|
|
local career = RoleManager.Instance:GetMainRoleVo().career
|
|
for _,v in pairs(reward) do
|
|
if career == tonumber(v[1]) then
|
|
type_id = tonumber(v[2][1][2])
|
|
break
|
|
end
|
|
end
|
|
else
|
|
type_id = tonumber(reward[1][2])
|
|
end
|
|
local goods_basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(type_id)
|
|
if goods_basic then
|
|
if goods_basic.type == GoodsModel.TYPE.EQUIP then
|
|
local target_config = Config.Equipattr[type_id]
|
|
if target_config then
|
|
local dynamic = {}
|
|
dynamic.type_id = type_id
|
|
dynamic.rating = target_config.base_rating
|
|
dynamic.equip_extra_attr = {}
|
|
dynamic.equip_type = goods_basic.equip_type
|
|
local target_pro = ErlangParser:GetInstance():Parse(target_config.recommend_attr)
|
|
for i, v in ipairs(target_pro) do
|
|
local attr = {}
|
|
attr.color = tonumber(v[2][1])
|
|
attr.attr_id = tonumber(v[2][2])
|
|
if #v[2] == 5 then
|
|
attr.type_id = 1
|
|
attr.plus_interval = tonumber(v[2][4])
|
|
attr.plus_unit = tonumber(v[2][5])
|
|
else
|
|
attr.type_id = 2
|
|
attr.attr_val = tonumber(v[2][3])
|
|
end
|
|
table.insert(dynamic.equip_extra_attr, attr)
|
|
end
|
|
|
|
UIToolTipMgr:getInstance():AppendEquipShowTips(dynamic, x, y, EquipShowTips.EQUIP_RECOMMAND_TARGET)
|
|
end
|
|
else
|
|
UIToolTipMgr:getInstance():AppendGoodsTips(type_id, x, y)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function CloudShoppingView:SetGiftModel(cfg)
|
|
local resouce_id_list = ErlangParser:GetInstance():Parse(cfg.resouce_id)
|
|
local res_id = 0
|
|
local career = RoleManager.Instance.mainRoleInfo.career
|
|
for _,v in pairs(resouce_id_list) do
|
|
if tonumber(v[1]) == career then
|
|
res_id = tonumber(v[2])
|
|
break
|
|
end
|
|
end
|
|
local scale = tonumber(cfg.resouce_size)
|
|
if scale and scale > 0 then
|
|
scale = scale
|
|
else
|
|
scale = nil
|
|
end
|
|
local posList = ErlangParser:GetInstance():Parse(cfg.resouce_height)
|
|
local x, y = 0, 0
|
|
if TableSize(posList) > 0 then
|
|
x = tonumber(posList[1][1])
|
|
y = tonumber(posList[1][2])
|
|
end
|
|
|
|
local data = {
|
|
clothe_res_id = res_id,
|
|
type = SceneBaseType.Role,
|
|
layer_name = self.layer_name,
|
|
action_name_list = {"show", "idle"},
|
|
can_rotate = true,
|
|
layout_file = self.layout_file
|
|
-- position = Vector3(x, y, 0),
|
|
}
|
|
|
|
lua_resM:SetRoleModel(self, self.imgGoods, data)
|
|
|
|
--lua_resM:SetRoleModel(self,self.imgGoods,nil,nil,res_id,nil,nil,SceneBaseType.Role,self.layer_name,nil,{"show","idle"},false,scale,Vector3(x, y, 0))
|
|
|
|
self.imgGoods:GetComponent("RawImage").raycastTarget = true
|
|
end
|
|
|
|
function CloudShoppingView:SetCost(costList)
|
|
local cost_list = ErlangParser:GetInstance():Parse(costList)
|
|
if TableSize(cost_list) > 0 then
|
|
self.cost_type = tonumber(cost_list[1][1])
|
|
self.cost = tonumber(cost_list[1][3])
|
|
self.type_id = tonumber(cost_list[1][2])
|
|
|
|
self.txtOne.text = self.cost
|
|
self.txtTen.text = self.cost * 10
|
|
|
|
self.goods_basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(self.type_id)
|
|
if self.goods_basic then
|
|
lua_resM:setOutsideImageSprite(self, self.iconOne, GameResPath.GetGoodsIcon(self.goods_basic.goods_icon))
|
|
lua_resM:setOutsideImageSprite(self, self.iconTen, GameResPath.GetGoodsIcon(self.goods_basic.goods_icon))
|
|
end
|
|
end
|
|
end
|
|
|
|
function CloudShoppingView:UpdateItems()
|
|
local buy_list = self.model:GetCloudBuyList()
|
|
for _, item in pairs(self.item_list) do
|
|
item:ResetItem()
|
|
end
|
|
self:CancelTimer()
|
|
local last_item = nil
|
|
local len = TableSize(buy_list)
|
|
if len > 0 then
|
|
local index = 1
|
|
local sub_index = 1
|
|
function go_next()
|
|
local data = buy_list[index]
|
|
self:CancelTimer()
|
|
if data then
|
|
sub_index = sub_index % 14
|
|
if sub_index == 0 then
|
|
sub_index = 14
|
|
end
|
|
local function show_anim()
|
|
local item = self.item_list[sub_index]
|
|
if item then
|
|
local find = false
|
|
if not item.stop_change then
|
|
local bool, num = self:ShowItemLightBg(buy_list, sub_index)
|
|
if bool then
|
|
item:ShowLightBg(bool, num)
|
|
find = true
|
|
else
|
|
item:ShowLightBg(true, 0, true)
|
|
end
|
|
end
|
|
if last_item then
|
|
if not last_item.stop_change then
|
|
last_item:ShowLightBg(false, 0, true)
|
|
end
|
|
end
|
|
last_item = item
|
|
if find then
|
|
go_next()
|
|
return
|
|
end
|
|
end
|
|
sub_index = sub_index + 1
|
|
end
|
|
self.timer_id_1 = GlobalTimerQuest:AddPeriodQuest(show_anim, 0.1, -1)
|
|
show_anim()
|
|
end
|
|
index = index + 1
|
|
end
|
|
go_next()
|
|
end
|
|
end
|
|
|
|
function CloudShoppingView:ShowItemLightBg(buy_list, reward_id)
|
|
local bool = false
|
|
local num = 0
|
|
for _, v in pairs(buy_list) do
|
|
if v.reward_id == reward_id then
|
|
bool = true
|
|
num = v.reward_num
|
|
break
|
|
end
|
|
end
|
|
return bool, num
|
|
end
|
|
|
|
--获得活动条件
|
|
function CloudShoppingView:GetActCondition()
|
|
local act_data = self.model:getActList(self.base_type)
|
|
--不限购时间和开奖时间
|
|
local unlimited_time, award_time
|
|
if act_data and act_data.condition_list then
|
|
local condList = act_data.condition_list
|
|
if TableSize(condList) > 0 then
|
|
for _, v in ipairs(condList) do
|
|
if Trim(v[1]) == "unlimited_time" then
|
|
unlimited_time = tonumber(v[2][1])
|
|
end
|
|
if Trim(v[1]) == "award_time" then
|
|
award_time = tonumber(v[2][1])
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
return unlimited_time, award_time
|
|
end
|
|
|
|
function CloudShoppingView:CancelTimer()
|
|
if self.timer_id_1 then
|
|
GlobalTimerQuest:CancelQuest(self.timer_id_1)
|
|
self.timer_id_1 = nil
|
|
end
|
|
if self.timer_id_2 then
|
|
GlobalTimerQuest:CancelQuest(self.timer_id_2)
|
|
self.timer_id_2 = nil
|
|
end
|
|
end
|