|
EnlargeView = EnlargeView or BaseClass(BaseView)
|
|
function EnlargeView:__init()
|
|
self.base_file = "bag"
|
|
self.layout_file = "EnlargeView"
|
|
self.layer_name = "Top"
|
|
self.use_background = true
|
|
self.is_set_zdepth = true
|
|
self.model = GoodsModel:getInstance()
|
|
self.load_callback = function ()
|
|
self:LocalSuccess()
|
|
end
|
|
self.open_callback = function ()
|
|
self:SetData()
|
|
end
|
|
self.destroy_callback = function ()
|
|
self:Remove()
|
|
end
|
|
|
|
end
|
|
|
|
function EnlargeView:Remove()
|
|
if self.icon_item then
|
|
self.icon_item:ReleaseObj()
|
|
self.icon_item = nil
|
|
end
|
|
end
|
|
|
|
function EnlargeView:LocalSuccess()
|
|
self.icon_item = UIObjPool:getInstance():PopItem(UIObjPool.UIType.AwardItem, self:GetChild("iconItem"))
|
|
self.icon_item:ChangeCountVisible(false)
|
|
|
|
self.bg_raw = self:GetChild("Window"):GetComponent("RawImage")
|
|
self.num = self:GetChild("num"):GetComponent("TextMeshProUGUI")
|
|
self.count_text = self:GetChild("countbg/count"):GetComponent("TextMeshProUGUI")
|
|
self.btn_text = self:GetChild("confirmBtn/Text"):GetComponent("TextMeshProUGUI")
|
|
self.name_text = self:GetChild("namebg/name"):GetComponent("TextMeshProUGUI")
|
|
self.confirmBtn,self.lblTip, self.cancelBtn, self.addBtn, self.subBtn =GetChildGameObjects (self.transform,
|
|
{
|
|
"confirmBtn","lblTip", "cancelBtn", "addBtn", "subBtn",
|
|
})
|
|
lua_resM:setOutsideRawImage(self, self.bg_raw, GameResPath.GetViewBigBg("tips_comm_bg6"), false)
|
|
self:InitEvent()
|
|
end
|
|
function EnlargeView:InitEvent()
|
|
local function onBtnClickHandler(target)
|
|
if target == self.confirmBtn then
|
|
local own_count = GoodsModel:getInstance():GetTypeGoodsNum(102601)
|
|
if own_count >= self.total_count then
|
|
if target == self.confirmBtn then
|
|
GoodsModel:getInstance():Fire(GoodsModel.REQUEST_CCMD_EVENT,15002,self.pos,self.lock_index)
|
|
end
|
|
else
|
|
local function ok()
|
|
GoodsModel:getInstance():Fire(GoodsModel.REQUEST_CCMD_EVENT,15002,self.pos,self.lock_index)
|
|
end
|
|
Alert.show(string.format("您的扩展钥匙不足,是否花费%d红钻补足缺额",self.total_cost),Alert.Type.Two,ok)
|
|
end
|
|
self:Close()
|
|
elseif target == self.cancelBtn then
|
|
self:Close()
|
|
|
|
elseif target == self.addBtn then
|
|
self:ChangeCount(self.lock_index + 1)
|
|
|
|
elseif target == self.subBtn then
|
|
self:ChangeCount(self.lock_index - 1)
|
|
end
|
|
|
|
end
|
|
AddClickEvent(self.confirmBtn,onBtnClickHandler)
|
|
AddClickEvent(self.cancelBtn,onBtnClickHandler)
|
|
AddClickEvent(self.addBtn,onBtnClickHandler)
|
|
AddClickEvent(self.subBtn,onBtnClickHandler)
|
|
end
|
|
|
|
function EnlargeView:Open(pos,lock_index)
|
|
self.pos = pos or GoodsModel.GOODS_POS_TYPE.bag
|
|
self.lock_index = lock_index
|
|
BaseView.Open(self)
|
|
end
|
|
|
|
function EnlargeView:SetData()
|
|
local good_vo = GoodsModel:getInstance():GetGoodsBasicByTypeId(102601)
|
|
self.base_view_titleText:GetComponent("TextMeshProUGUI").text = string.format("拓展%s",self.pos == GoodsModel.GOODS_POS_TYPE.bag and "背包" or "仓库")
|
|
self.btn_text.text = self.pos == GoodsModel.GOODS_POS_TYPE.bag and "拓展背包" or "拓展仓库"
|
|
self.icon_item:SetData(102601, 1, nil, nil, true)
|
|
self.icon_item:SetItemSize(62, 62)
|
|
self.name_text.text = HtmlColorTxt(good_vo.goods_name, WordManager.GetGoodsColor(good_vo.color))
|
|
local own_count = GoodsModel:getInstance():GetTypeGoodsNum(102601)
|
|
local info
|
|
if self.pos == GoodsModel.GOODS_POS_TYPE.bag then
|
|
info = self.model.slot_info_pos_2
|
|
else
|
|
info = self.model.slot_info_pos_3
|
|
end
|
|
local slot_num = info.slot_num or 0 --开放格子
|
|
local def_num = info.def_cell or 0 --默认开放格子数
|
|
local isOpenNum = slot_num - def_num
|
|
self.total_count,self.total_cost = 0,0
|
|
for i=1,self.lock_index do
|
|
local num,cost = self:GetEnlargeCost(i+isOpenNum)
|
|
self.total_count = self.total_count + num
|
|
if own_count < self.total_count then
|
|
self.total_cost = self.total_cost + cost
|
|
end
|
|
end
|
|
local color = own_count >= self.total_count and ColorUtil.GREEN or ColorUtil.RED
|
|
self.icon_item:SetNumText("")
|
|
self.count_text.text = string.format("<color=%s>%d</color>/%d",color,own_count,self.total_count)
|
|
--self.count_text.text = string.format("%d/%d",own_count,self.total_count)
|
|
|
|
self.num.text = self.lock_index
|
|
--self.lblTip:SetActive(own_count < self.total_count)
|
|
self.lblTip:SetActive(false)
|
|
end
|
|
|
|
function EnlargeView:GetEnlargeCost( open_index )
|
|
local num,cost = 0,0
|
|
for k,v in pairs(Config.Expandbagcosts) do
|
|
if self.pos == v.bag_type and v.min_cell <= open_index and v.max_cell >= open_index then
|
|
local list = ErlangParser:GetInstance():Parse(v.cost_goods_list)
|
|
if list then
|
|
num = list[1][3]
|
|
end
|
|
|
|
local goods_price = Config.Goodsprice[102601]
|
|
price = goods_price and goods_price.price or 5
|
|
cost = price * num
|
|
break
|
|
end
|
|
end
|
|
return num,cost
|
|
end
|
|
|
|
function EnlargeView:ChangeCount(count)
|
|
if count < 1 then
|
|
return
|
|
end
|
|
local info
|
|
if self.pos == GoodsModel.GOODS_POS_TYPE.bag then
|
|
info = self.model.slot_info_pos_2
|
|
else
|
|
info = self.model.slot_info_pos_3
|
|
end
|
|
if count > info.all_slot - info.slot_num then
|
|
return
|
|
end
|
|
self.lock_index = count
|
|
self:SetData()
|
|
end
|