162 lines
4.6 KiB
Lua
162 lines
4.6 KiB
Lua
|
|
-- 异妖设置界面
|
|
MonsterSetView = {}
|
|
|
|
-- 初始化角色设置界面
|
|
function MonsterSetView:Init(root)
|
|
self.gameObject = root
|
|
|
|
self.btnComfirm = Util.GetGameObject(root, "Root/confirm")
|
|
self.btnCancel = Util.GetGameObject(root, "Root/cancel")
|
|
-- self.content = Util.GetGameObject(root, "Root/cancel"):GetComponent("Text")
|
|
|
|
self.btnList = {}
|
|
for i = 1, 6 do
|
|
self.btnList[i] = Util.GetGameObject(root, "btnList/btn"..i)
|
|
Util.AddOnceClick(self.btnList[i], function()
|
|
if self.curChoose == i then
|
|
return
|
|
end
|
|
self:ChooseMonster(i)
|
|
end)
|
|
end
|
|
|
|
self.monsterTip = Util.GetGameObject(root, "monster"):GetComponent("Text")
|
|
self.mId = Util.GetGameObject(root, "monster/id"):GetComponent("InputField")
|
|
self.star = Util.GetGameObject(root, "monster/star"):GetComponent("InputField")
|
|
self.props = Util.GetGameObject(root, "monster/props")
|
|
self.propList = {}
|
|
for i = 1, self.props.transform.childCount do
|
|
self.propList[i] = Util.GetGameObject(self.props.transform:GetChild(i-1), "input"):GetComponent("InputField")
|
|
end
|
|
--
|
|
Util.AddOnceClick(self.btnComfirm, function()
|
|
self:ApplyData()
|
|
end)
|
|
--
|
|
Util.AddOnceClick(self.btnCancel, function()
|
|
self:Close()
|
|
end)
|
|
|
|
end
|
|
|
|
function MonsterSetView:Show(camp, data, func)
|
|
self.gameObject:SetActive(true)
|
|
self.camp = camp
|
|
self.data = data
|
|
self.func = func
|
|
self.curChoose = nil
|
|
self.curData = nil
|
|
self:loadFromLocal() -- 加载本地资源
|
|
self:ChooseMonster(1)
|
|
end
|
|
|
|
function MonsterSetView:ChooseMonster(pos)
|
|
-- 切换时保存数据
|
|
self:ApplyData()
|
|
--
|
|
self.curChoose = pos
|
|
self.curData = self.data[pos] or {props = {}}
|
|
self.monsterTip.text = Language[10214]..pos
|
|
|
|
self.mId.text = self.curData.id or self:GetLocalData(self.camp, pos, 1)
|
|
self.star.text = self.curData.star or self:GetLocalData(self.camp, pos, 2)
|
|
for propIndex, prop in ipairs(self.propList) do
|
|
prop.text = self.curData.props[propIndex] or self:GetLocalData(self.camp, pos, propIndex + 2)
|
|
end
|
|
end
|
|
|
|
|
|
|
|
-- 应用数据
|
|
function MonsterSetView:ApplyData()
|
|
if not self.curData then
|
|
return
|
|
end
|
|
self.curData.id = tonumber(self.mId.text)
|
|
self.curData.star = tonumber(self.star.text)
|
|
for propIndex, prop in ipairs(self.propList) do
|
|
local value = prop.text == "" and 0 or prop.text
|
|
self.curData.props[propIndex] = tonumber(value)
|
|
end
|
|
self.data[self.camp * 6 + self.curChoose] = self.curData
|
|
self:saveToLocal()
|
|
|
|
-- 应用数据
|
|
if self.func then
|
|
if self.func(self.data) then
|
|
PopupTipPanel.ShowTip(Language[10212])
|
|
return
|
|
end
|
|
end
|
|
PopupTipPanel.ShowTip(Language[10213])
|
|
end
|
|
|
|
|
|
-- 从本地加载数据
|
|
function MonsterSetView:loadFromLocal()
|
|
self.localData = {}
|
|
for i = 1, 12 do
|
|
local camp = math.floor((i-1)/6)
|
|
local pos = (i - 1)%6 + 1
|
|
local dataStr = PlayerPrefs.GetString("test_battle_monster_"..camp..pos)
|
|
--LogGreen(dataStr)
|
|
self.localData[i] = string.split(dataStr, "|")
|
|
end
|
|
end
|
|
|
|
-- 保存数据到本地
|
|
function MonsterSetView:saveToLocal()
|
|
for i = 1, #self.data do
|
|
if self.data and self.data[i] then
|
|
|
|
local camp = self.camp
|
|
local pos = i
|
|
|
|
local str = ""
|
|
str = str .. (self.data[i].id or "")
|
|
str = str .. "|"..(self.data[i].star or "")
|
|
|
|
for propIndex, prop in ipairs(self.data[i].props) do
|
|
str = str .. "|"..(prop or "")
|
|
end
|
|
--LogGreen(str)
|
|
PlayerPrefs.SetString("test_battle_monster_"..camp..pos, str)
|
|
|
|
end
|
|
end
|
|
end
|
|
function MonsterSetView:GetLocalData(camp, pos, index)
|
|
local defaultData = {
|
|
20001, -- roleID
|
|
0, -- star
|
|
|
|
100, -- 等级
|
|
100000, -- hp
|
|
100000, -- maxhp
|
|
100, -- attack
|
|
0, -- 物抗
|
|
0, -- 魔抗
|
|
0, -- 速度(未使用)
|
|
0, -- 伤害加成系数
|
|
0, -- 伤害减免系数
|
|
1, -- 命中率(未使用)
|
|
0, -- 闪避率(未使用)
|
|
0.2, -- 暴击率
|
|
1.5, -- 爆伤系数
|
|
0, -- 抗暴率
|
|
1, -- 治疗系数
|
|
1, -- 治愈系数
|
|
}
|
|
local i = camp * 6 + pos
|
|
if not self.localData[i][index] or self.localData[i][index] == "" then
|
|
return (defaultData[index] or 0)
|
|
end
|
|
return self.localData[i][index]
|
|
end
|
|
|
|
|
|
-- 关闭界面
|
|
function MonsterSetView:Close()
|
|
self.gameObject:SetActive(false)
|
|
end |