214 lines
7.0 KiB
Lua
214 lines
7.0 KiB
Lua
|
|
RoleSetView = {}
|
|
local MonsterConfig = ConfigManager.GetConfig(ConfigName.MonsterConfig)
|
|
-- 初始化角色设置界面
|
|
function RoleSetView:Init(root)
|
|
self.gameObject = root
|
|
self.monsterId = Util.GetGameObject(root, "configId/input"):GetComponent("InputField")
|
|
self.btnLoad = Util.GetGameObject(root, "configId/load")
|
|
|
|
self.roleId = Util.GetGameObject(root, "roleId/input"):GetComponent("InputField")
|
|
self.passivity = Util.GetGameObject(root, "passivity/input"):GetComponent("InputField")
|
|
self.skill = Util.GetGameObject(root, "skill/input"):GetComponent("InputField")
|
|
self.readyACtion = Util.GetGameObject(root, "readyACtion/input"):GetComponent("InputField")
|
|
self.readyACtion.text="0"
|
|
self.skin = Util.GetGameObject(root, "skin/input"):GetComponent("InputField")
|
|
self.skin.text="0"
|
|
self.superSkill = Util.GetGameObject(root, "superSkill/input"):GetComponent("InputField")
|
|
self.star = Util.GetGameObject(root, "star/input"):GetComponent("InputField")
|
|
self.star.text="0"
|
|
self.props = Util.GetGameObject(root, "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
|
|
|
|
self.btnComfirm = Util.GetGameObject(root, "Root/confirm")
|
|
self.deletefirm = Util.GetGameObject(root, "Root/delete")
|
|
self.btnCancel = Util.GetGameObject(root, "Root/cancel")
|
|
self.content = Util.GetGameObject(root, "Root/cancel"):GetComponent("Text")
|
|
|
|
--
|
|
Util.AddOnceClick(self.btnComfirm, function()
|
|
self:ApplyData()
|
|
end)
|
|
--
|
|
Util.AddOnceClick(self.deletefirm, function()
|
|
self:RemoveData()
|
|
end)
|
|
--
|
|
Util.AddOnceClick(self.btnCancel, function()
|
|
self:Close()
|
|
end)
|
|
--
|
|
Util.AddOnceClick(self.btnLoad, function()
|
|
self:LoadFromConfig()
|
|
end)
|
|
end
|
|
|
|
-- 根据配置加载数据
|
|
function RoleSetView:LoadFromConfig()
|
|
local monsterId = tonumber(self.monsterId.text)
|
|
local config = MonsterConfig[monsterId]
|
|
if not config then
|
|
LogRed("未找到配置数据:"..monsterId)
|
|
return
|
|
end
|
|
|
|
local passivity = config.PassiveSkillList and table.concat(config.PassiveSkillList, "#") or ""
|
|
local skill = config.SkillList[1] or ""
|
|
local superSkill = config.SkillList[2] or ""
|
|
local skinId=tonumber(self.skin.text)
|
|
local star = tonumber(self.star.text)
|
|
self.localData = {
|
|
monsterId,
|
|
config.MonsterId, -- roleId
|
|
passivity,
|
|
skill,
|
|
superSkill,
|
|
skinId,
|
|
config.Level,
|
|
config.Hp,
|
|
config.Hp,
|
|
config.Attack,
|
|
config.PhysicalDefence,
|
|
config.MagicDefence,
|
|
config.Speed,
|
|
config.DamageBocusFactor,
|
|
config.DamageReduceFactor,
|
|
config.Hit,
|
|
config.CritFactor,
|
|
config.CritDamageFactor,
|
|
config.AntiCritDamageFactor,
|
|
config.TreatFacter,
|
|
config.CureFacter,
|
|
star,
|
|
}
|
|
|
|
|
|
-- 设置数据
|
|
self.roleId.text = self:GetLocalData(2)
|
|
self.passivity.text = self:GetLocalData(3)
|
|
self.skill.text = self:GetLocalData(4)
|
|
self.superSkill.text = self:GetLocalData(5)
|
|
self.skin.text = self:GetLocalData(6)
|
|
self.star.text = self:GetLocalData(23)
|
|
for propIndex, prop in ipairs(self.propList) do
|
|
prop.text = self:GetLocalData(propIndex + 6)
|
|
end
|
|
end
|
|
|
|
-- 从本地加载数据
|
|
function RoleSetView:loadFromLocal()
|
|
local dataStr = PlayerPrefs.GetString("test_battle_role_"..self.camp..self.pos)
|
|
--LogGreen(dataStr)
|
|
self.localData = string.split(dataStr, "|")
|
|
end
|
|
|
|
-- 保存数据到本地
|
|
function RoleSetView:saveToLocal()
|
|
local str = ""
|
|
str = str .. (self.data.monsterId or "")
|
|
str = str .. "|"..(self.data.roleId or "")
|
|
str = str .. "|"..(self.data.passivity or "")
|
|
str = str .. "|"..(self.data.skill or "")
|
|
str = str .. "|"..(self.data.superSkill or "")
|
|
str = str .. "|"..(self.data.skinId or "")
|
|
for propIndex, prop in ipairs(self.data.props) do
|
|
str = str .. "|"..(prop or "")
|
|
end
|
|
--LogGreen(str)
|
|
PlayerPrefs.SetString("test_battle_role_"..self.camp..self.pos, str)
|
|
end
|
|
|
|
function RoleSetView:GetLocalData(index)
|
|
local defaultData = {
|
|
"", -- monsterID
|
|
10001, -- roleID
|
|
"", -- 被动
|
|
1011, -- 普技
|
|
1012, -- 特殊
|
|
0, --皮肤
|
|
100, -- 等级
|
|
100000, -- hp
|
|
100000, -- maxhp
|
|
100, -- attack
|
|
0, -- 物抗
|
|
0, -- 魔抗
|
|
0, -- 速度(未使用)
|
|
0, -- 伤害加成系数
|
|
0, -- 伤害减免系数
|
|
1, -- 命中率(未使用)
|
|
0, -- 闪避率(未使用)
|
|
0.2, -- 暴击率
|
|
1.5, -- 爆伤系数
|
|
0, -- 抗暴率
|
|
1, -- 治疗系数
|
|
1, -- 治愈系数
|
|
10,
|
|
}
|
|
if not self.localData[index] or self.localData[index] == "" then
|
|
return (defaultData[index] or 0)
|
|
end
|
|
return self.localData[index]
|
|
end
|
|
|
|
function RoleSetView:Show(camp, pos, data, func)
|
|
data = data or {props = {}}
|
|
self.gameObject:SetActive(true)
|
|
self.camp = camp
|
|
self.pos = pos
|
|
self.data = data
|
|
self.func = func
|
|
self:loadFromLocal() -- 加载本地资源
|
|
|
|
-- 设置数据
|
|
self.monsterId.text = data.monsterId or self:GetLocalData(1)
|
|
self.roleId.text = data.roleId or self:GetLocalData(2)
|
|
self.passivity.text = data.passivity or self:GetLocalData(3)
|
|
self.skill.text = data.skill or self:GetLocalData(4)
|
|
self.superSkill.text = data.superSkill or self:GetLocalData(5)
|
|
self.skin.text = data.skinId or self:GetLocalData(6)
|
|
self.star.text = data.star or self:GetLocalData(23)
|
|
for propIndex, prop in ipairs(self.propList) do
|
|
prop.text = data.props[propIndex] or self:GetLocalData(propIndex + 6)
|
|
end
|
|
end
|
|
|
|
-- 应用数据
|
|
function RoleSetView:ApplyData()
|
|
self.data.monsterId = tonumber(self.monsterId.text)
|
|
self.data.roleId = tonumber(self.roleId.text)
|
|
self.data.passivity = self.passivity.text
|
|
self.data.skill = tonumber(self.skill.text)
|
|
self.data.superSkill = tonumber(self.superSkill.text)
|
|
self.data.skinId=tonumber(self.skin.text)
|
|
LogError("star text:"..self.star.text)
|
|
self.data.star = tonumber(self.star.text)
|
|
self.data.readyAction = tonumber(self.readyACtion.text)
|
|
for propIndex, prop in ipairs(self.propList) do
|
|
local value = prop.text == "" and 0 or tonumber(prop.text)
|
|
self.data.props[propIndex] = tonumber(value)
|
|
end
|
|
-- 保存数据到本地
|
|
self:saveToLocal()
|
|
-- 应用数据
|
|
if self.func then
|
|
self.func(self.camp, self.pos, self.data)
|
|
PopupTipPanel.ShowTip(Language[10212])
|
|
end
|
|
end
|
|
|
|
-- 应用数据
|
|
function RoleSetView:RemoveData()
|
|
-- 应用数据
|
|
if self.func then
|
|
self.func(self.camp, self.pos, nil)
|
|
PopupTipPanel.ShowTip(Language[10215])
|
|
end
|
|
end
|
|
-- 关闭界面
|
|
function RoleSetView:Close()
|
|
self.gameObject:SetActive(false)
|
|
|
|
end |