源战役客户端
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

147 lines
3.4 KiB

--[[
@ 道具选择面板
--]]
OptionalItemTips = OptionalItemTips or BaseClass(BaseView)
local OptionalItemTips = OptionalItemTips
function OptionalItemTips:__init()
self.base_file = "common"
self.layout_file = "OptionalItemTips"
self.layer_name = "Top"
self.destroy_imm = true
self.use_background = true
self.click_bg_toClose = true
self.is_set_zdepth = true
self.wait_for_hide = true
self.item_list = {}
self.load_callback = function()
self:LoadSuccess()
self:AdjustLayoutPos()
end
self.open_callback = function()
self:SetLabel()
self:SetContent()
end
self.destroy_callback = function ()
self:Remove()
end
end
function OptionalItemTips:Remove()
for i, v in ipairs(self.item_list) do
v:DeleteMe()
v = nil
end
self.item_list = {}
end
function OptionalItemTips:LoadSuccess()
self.layout,
self.bg,
self.content_parent
= self:GetChildTransforms(
{
"layout",
"layout/bg",
"layout/itemScrollView/Viewport/Content"
})
self.title,
self.label,
self.tips
= self:GetChildTexts(
{
"layout/title",
"layout/EmptyCon/text",
"layout/tips",
})
self.empty
= self:GetChildGameObjects(
{
"layout/EmptyCon",
})
self.item_mask
= self:GetChildImages(
{
"layout/itemScrollView/Viewport"
})
SetSizeDelta(self.transform, ScreenWidth, ScreenHeight)
end
function OptionalItemTips:SetLabel()
local str = WordManager:GetGoodsTypeStr(self.goods_type)
str = string.len(str) == 0 and "材料" or str
self.title.text = "点击选择"..(self.grade and ((self.grade - 1) .."") or "").. str
self.label.text = "背包中没有可选择的"..str
end
function OptionalItemTips:Open(x, y, goods_type, goods_list, callback, item_type,grade)
self.goods_type = goods_type
self.goods_list = goods_list
self.grade = grade
self.pos_x = x
self.pos_y = y
self.callback = callback
self.item_type = item_type or OptionalItem.Type.EQUIP
BaseView.Open(self)
end
function OptionalItemTips:SetContent()
if self.goods_list and TableSize(self.goods_list) > 0 then
self.empty:SetActive(false)
self:SetItem()
else
local str = WordManager:GetGoodsTypeStr(self.goods_type)
str = string.len(str) == 0 and "材料" or str
self.title.text = "背包中没有可选择的"..(self.grade and ((self.grade - 1) .."") or "")..str
self.empty:SetActive(true)
end
end
function OptionalItemTips:SetItem()
local function onSelectCallback(goods_vo)
if self.callback ~= nil then
self.callback(goods_vo)
end
self:Close()
end
local count = 0
table.sort( self.goods_list, function ( a,b )
return a.color > b.color
end )
for k, v in ipairs(self.goods_list) do
count = count + 1
self.item_list[count] = self.item_list[count] or OptionalItem.New(self.content_parent, nil, self.layer_name, self.item_type)
self.item_list[count]:SetData(v, onSelectCallback)
end
for i = count + 1, #self.item_list do
self.item_list[i]:SetVisible(false)
end
end
function OptionalItemTips:AdjustLayoutPos()
if self.pos_x and self.pos_y then
local layout_width = self.bg.sizeDelta.x
local layout_height = self.bg.sizeDelta.y
local x,y = ScreenToViewportPoint(self.pos_x,self.pos_y)
local iphone_x_offset = math.max(ClientConfig.iphone_x_offset_left,ClientConfig.iphone_x_offset_right)
if x + layout_width + 50 + iphone_x_offset * 2 > SrcScreenWidth then
x = SrcScreenWidth - layout_width - 90 - iphone_x_offset * 2
end
if y < layout_height + 50 then
y = layout_height + 50
end
self.layout.anchoredPosition = Vector2(x,y - ScreenHeight)
end
end