--[[
|
|
@ 道具选择面板中的可选择Item
|
|
--]]
|
|
|
|
OptionalItem = OptionalItem or BaseClass(BaseItem)
|
|
local OptionalItem = OptionalItem
|
|
|
|
OptionalItem.Type =
|
|
{
|
|
EQUIP = 1, --装备道具(显示战力)
|
|
LUCKY = 2, --幸运物道具(显示幸运值)
|
|
NORMAL = 3, --普通物品(显示数量)
|
|
}
|
|
|
|
function OptionalItem:__init(parent_wnd,prefab_asset,layer_name, item_type)
|
|
|
|
self.layout_file = "OptionalItem"
|
|
self.prefab_asset = UiFactory.getPrefab(UIType.BarsItem)
|
|
self.is_delay_callback = true
|
|
|
|
self.item_type = item_type or OptionalItem.Type.EQUIP
|
|
|
|
self:Load()
|
|
end
|
|
|
|
function OptionalItem:__delete()
|
|
if self.icon_item then
|
|
self.icon_item:DeleteMe()
|
|
self.icon_item = nil
|
|
end
|
|
end
|
|
|
|
function OptionalItem:Load_callback()
|
|
self.icon = self:GetChild("icon")
|
|
self.name, self.desc = GetChildTexts(self.transform, {"name","desc"})
|
|
self.clickBg = self:GetChild("clickBg").gameObject
|
|
|
|
self.icon_item = AwardItem.New(self.icon, false, self.layer_name)
|
|
self.icon_item:SetItemSize(74, 74)
|
|
self.icon_item:SetLoadCall(function ()
|
|
self.icon_item.stren.alignment = UnityEngine.TextAnchor.MiddleCenter
|
|
self.icon_item.stren_prefix = "Lv."
|
|
SetAnchoredPosition(self.icon_item.stren.transform, 0, -28)
|
|
end)
|
|
|
|
self:InitEvent()
|
|
|
|
if self.need_refresh then
|
|
self:SetData(self.goods_vo, self.callback)
|
|
end
|
|
end
|
|
|
|
function OptionalItem:InitEvent()
|
|
local function onBtnClickHandler(target)
|
|
if self.callback ~= nil then
|
|
self.callback(self.goods_vo)
|
|
end
|
|
end
|
|
AddClickEvent(self.clickBg, onBtnClickHandler, 2)
|
|
end
|
|
|
|
function OptionalItem:SetData(goods_vo, callback)
|
|
|
|
self.goods_vo = goods_vo
|
|
self.callback = callback
|
|
|
|
if self.is_loaded then
|
|
--[[local function callback(dynamic)
|
|
print("OptionalItem:SetData() dynamic = ")
|
|
PrintTable(dynamic)
|
|
end
|
|
GoodsModel:getInstance():GetDynamic(self.goods_vo.goods_id, callback)--]]
|
|
|
|
local type_id = tonumber(self.goods_vo.type_id)
|
|
self.icon_item:SetData(type_id, nil, nil, self.goods_vo.stren)
|
|
self.name.text = "<color="..ColorUtil:GetColor(self.goods_vo.color)..">"..Trim(self.goods_vo.goods_name).."</color>"
|
|
|
|
if self.item_type == OptionalItem.Type.EQUIP then
|
|
self.desc.text = "<color=#7B432C>战力:</color>"..self:GetItemFightValue(self.goods_vo)
|
|
elseif self.item_type == OptionalItem.Type.LUCKY then
|
|
self.desc.text = "<color=#7B432C>幸运值</color>:"..self:GetItemLuckyValue(self.goods_vo)
|
|
else
|
|
self.desc.text = "<color=#7B432C>数量:</color>"..self:GetItemNum(self.goods_vo)
|
|
end
|
|
else
|
|
self.need_refresh = true
|
|
end
|
|
end
|
|
|
|
function OptionalItem:GetItemLuckyValue(goods_vo)
|
|
local type_id = tonumber(goods_vo.type_id)
|
|
local cur_formula = WingModel:getInstance().cur_formula
|
|
if Config.Twingcomposeratio[type_id] and cur_formula then
|
|
local grade = cur_formula.grade
|
|
local ratio_list = ErlangParser:GetInstance():Parse(Config.Twingcomposeratio[type_id].ratio)
|
|
for i, v in ipairs(ratio_list) do
|
|
if tonumber(v[1]) == grade then
|
|
return v[2]
|
|
end
|
|
end
|
|
return 0
|
|
end
|
|
end
|
|
|
|
function OptionalItem:GetItemFightValue(goods_vo)
|
|
local type_id = tonumber(goods_vo.type_id)
|
|
local basic = GoodsModel:getInstance():GetGoodsBasicByTypeId(type_id)
|
|
if basic.type == 20 and Config.Twing[type_id] then
|
|
return Config.Twing[type_id].power
|
|
else
|
|
return goods_vo.combat_power
|
|
end
|
|
end
|
|
|
|
function OptionalItem:GetItemNum(goods_vo)
|
|
local type_id = tonumber(goods_vo.type_id)
|
|
local have_num = GoodsModel:getInstance():GetTypeGoodsNum(type_id)
|
|
return have_num or 0
|
|
end
|