SettingPerformItem = SettingPerformItem or BaseClass(BaseItem)
|
|
|
|
-- 性能设置项
|
|
|
|
function SettingPerformItem:__init(parent)
|
|
self.base_file = "setting"
|
|
self.layout_file = "SettingPerformItem"
|
|
self.item_list = {}
|
|
self.model = GameSettingModel:GetInstance()
|
|
self.curr_select_index = 1
|
|
self.val2index = {}
|
|
self:Load()
|
|
end
|
|
|
|
function SettingPerformItem:Load_callback()
|
|
self:LoadSuccess()
|
|
--self:InitEvent()
|
|
end
|
|
|
|
function SettingPerformItem:LoadSuccess()
|
|
self.item_con = self:GetChild("btn_con")
|
|
self.title = self:GetChild("title"):GetComponent("TextMeshProUGUI")
|
|
|
|
if self.need_refreshData then
|
|
self:SetData(self.info,self.call_back)
|
|
end
|
|
|
|
if self.need_select then
|
|
self:SelectBtnByVal(self.select_val)
|
|
end
|
|
end
|
|
|
|
|
|
function SettingPerformItem:SetData(info,call_back)
|
|
self.info = info
|
|
self.call_back = call_back
|
|
for i,v in ipairs(info.val_list) do
|
|
self.val2index[v] = i
|
|
end
|
|
if self.is_loaded then
|
|
local call_fun = function (index)
|
|
self:SelectBtn(index)
|
|
self.call_back(self.info.setting_str,self.info.val_list[index])
|
|
end
|
|
|
|
self.title.text = info.title or ""
|
|
|
|
print(info.title)
|
|
|
|
local item = nil
|
|
for i,v in ipairs(info.name_list) do
|
|
item = self.item_list[i]
|
|
if item == nil then
|
|
item = SettingBtnItem.New(self.item_con)
|
|
self.item_list[i] = item
|
|
end
|
|
self.item_list[i]:SetData(v,i,call_fun)
|
|
if i==1 then
|
|
item:SetAnchoredPosition(56,26)
|
|
elseif i==2 then
|
|
item:SetAnchoredPosition(196,26)
|
|
elseif i==3 then
|
|
item:SetAnchoredPosition(370,26)
|
|
end
|
|
end
|
|
self.need_refreshData = true
|
|
else
|
|
self.need_refreshData = true
|
|
end
|
|
end
|
|
|
|
function SettingPerformItem:SelectBtn( index,force )
|
|
if index == self.curr_select_index and not force then return end
|
|
if self.item_list[self.curr_select_index] then
|
|
self.item_list[self.curr_select_index]:SetSelect(false)
|
|
end
|
|
self.curr_select_index = index
|
|
if self.item_list[self.curr_select_index] then
|
|
self.item_list[self.curr_select_index]:SetSelect(true)
|
|
end
|
|
end
|
|
|
|
function SettingPerformItem:SelectBtnByVal(val)
|
|
self.select_val = val
|
|
if self.is_loaded then
|
|
if val == nil or self.val2index[val] == nil then
|
|
val = GameSettingManager.PerformanceList[1].val_list[2]
|
|
self.select_val = val
|
|
end
|
|
self:SelectBtn(self.val2index[val],true)
|
|
self.need_select = false
|
|
else
|
|
self.need_select = true
|
|
end
|
|
end
|
|
|
|
function SettingPerformItem:__delete( )
|
|
for i,v in ipairs(self.item_list) do
|
|
v:DeleteMe()
|
|
v = nil
|
|
end
|
|
end
|