看了你的代码,有几个关键问题需要修正。让我帮你指出错误并提供完整的修改版本:
## 主要问题:
1. **`GUI:ImageView_loadTexture` 函数不存在** - 应该使用 `GUI:Image_loadTexture`
2. **`GUI:Win_IsNotNull` 函数不存在** - 应该使用 `not GUI:Win_IsNull(widget)`
3. **`SL:getMyActor()` 函数不存在** - 应该使用 `SL:GetMyActorID()`
4. **`hasTitle` 函数参数不一致** - 在 `checkAllTitles` 中传了actor参数,但函数定义不需要
5. **服务端称号数据获取方式** - 需要正确的获取方式
## 修正后的完整代码:
```lua
local baixiaosheng = {}
-- 定义称号与图片的对应关系
local titleImageMap = {
["暗金魔气"] = {
ui = "Image_17", -- UI控件名称
normal = "res/beixiaosheng/000012.png", -- 未拥有时的图片
owned = "res/beixiaosheng/000011.png" -- 已拥有时的图片
},
["血木魔气"] = {
ui = "Image_18",
normal = "res/beixiaosheng/000012.png",
owned = "res/beixiaosheng/000011.png"
},
["黑水魔气"] = {
ui = "Image_19",
normal = "res/beixiaosheng/000012.png",
owned = "res/beixiaosheng/000011.png"
},
["啖火魔气"] = {
ui = "Image_20",
normal = "res/beixiaosheng/000012.png",
owned = "res/beixiaosheng/000011.png"
},
["戾土魔气"] = {
ui = "Image_21",
normal = "res/beixiaosheng/000012.png",
owned = "res/beixiaosheng/000011.png"
}
}
-- 称号列表
local titleList = {"暗金魔气", "血木魔气", "黑水魔气", "啖火魔气", "戾土魔气"}
function baixiaosheng.main(param1, param2, param3, param4)
lib:Require(param1, function(state)
if state then
if param1 then
baixiaosheng.parent = lib:openwin(param1, nil, true, param4) or {}
baixiaosheng.param1 = param1
end
if param2 then
baixiaosheng.param2 = param2
end
if param3 then
baixiaosheng.param3 = param3
end
if baixiaosheng.parent.cfg and next(baixiaosheng.parent.cfg) then
baixiaosheng.upmain()
else
lib:msg("系统未配置!")
GUI:Win_Close(baixiaosheng.parent._parent)
end
end
end)
end
-- 检测玩家是否拥有指定称号
function baixiaosheng.hasTitle(titleName)
-- 从服务端获取称号状态
local hasTitle = SL:GetMetaValue("HAS_TITLE", titleName)
return hasTitle == true or hasTitle == 1
end
-- 更新所有称号图片
function baixiaosheng.updateTitleImages()
if not baixiaosheng.parent or not baixiaosheng.parent._ui then
return
end
local ui = baixiaosheng.parent._ui
-- 遍历所有称号,更新图片
for _, titleName in ipairs(titleList) do
local imageInfo = titleImageMap[titleName]
if imageInfo and not GUI:Win_IsNull(ui[imageInfo.ui]) then
if baixiaosheng.hasTitle(titleName) then
-- 已拥有称号,显示已拥有图片
GUI:Image_loadTexture(ui[imageInfo.ui], imageInfo.owned)
SL:print("称号[" .. titleName .. "]已拥有")
else
-- 未拥有称号,显示普通图片
GUI:Image_loadTexture(ui[imageInfo.ui], imageInfo.normal)
SL:print("称号[" .. titleName .. "]未拥有")
end
end
end
end
-- 检查是否集齐所有称号
function baixiaosheng.checkAllTitles()
for _, titleName in ipairs(titleList) do
if not baixiaosheng.hasTitle(titleName) then
return false
end
end
return true
end
function baixiaosheng.upmain()
if not baixiaosheng.parent or not baixiaosheng.parent._ui then
return
end
local ui = baixiaosheng.parent._ui
local cfg = baixiaosheng.parent.cfg
-- 更新称号图片
baixiaosheng.updateTitleImages()
-- 检查是否集齐所有称号
if baixiaosheng.checkAllTitles() then
-- 可以在这里添加集齐所有称号后的特殊处理
SL:print("玩家已集齐所有魔气称号!")
-- 如果有集齐后的特殊图片,可以在这里设置
if not GUI:Win_IsNull(ui["Image_complete"]) then
GUI:setVisible(ui["Image_complete"], true)
end
end
-- 设置升级按钮
if not GUI:Win_IsNull(ui["Button_1"]) then
GUI:addOnClickEvent(ui["Button_1"], function()
SL:print("点击化魔秘闻按钮")
GUI:delayTouchEnabled(ui["Button_1"], 0.2)
local msg = {}
msg.Script = baixiaosheng.param1
local jsonstr = SL:JsonEncode(msg)
SL:SendLuaNetMsg(58003, baixiaosheng.param2, 0, 0, jsonstr)
GUI:setVisible(ui.Image_3, true)
GUI:setVisible(ui.Image_6, false)
end)
end
if not GUI:Win_IsNull(ui["Button_2"]) then
GUI:addOnClickEvent(ui["Button_2"], function()
SL:print("点击五行暗魔按钮")
GUI:delayTouchEnabled(ui["Button_2"], 0.2)
local msg = {}
msg.Script = baixiaosheng.param1
local jsonstr = SL:JsonEncode(msg)
SL:SendLuaNetMsg(58003, baixiaosheng.param2, 1, 0, jsonstr)
GUI:setVisible(ui.Image_3, false)
GUI:setVisible(ui.Image_6, true)
end)
end
if not GUI:Win_IsNull(ui["Button_3"]) then
GUI:addOnClickEvent(ui["Button_3"], function()
SL:print("点击3按钮")
GUI:delayTouchEnabled(ui["Button_3"], 0.2)
local msg = {}
msg.Script = baixiaosheng.param1
local jsonstr = SL:JsonEncode(msg)
SL:SendLuaNetMsg(58003, baixiaosheng.param2, 2, 0, jsonstr)
end)
end
if not GUI:Win_IsNull(ui["Button_4"]) then
GUI:addOnClickEvent(ui["Button_4"], function()
SL:print("点击4按钮")
GUI:delayTouchEnabled(ui["Button_4"], 0.2)
local msg = {}
msg.Script = baixiaosheng.param1
local jsonstr = SL:JsonEncode(msg)
SL:SendLuaNetMsg(58003, baixiaosheng.param2, 3, 0, jsonstr)
-- 点击后刷新图片显示
SL:ScheduleOnce(function()
baixiaosheng.updateTitleImages()
end, 0.5)
end)
end
if not GUI:Win_IsNull(ui["Button_5"]) then
GUI:addOnClickEvent(ui["Button_5"], function()
SL:print("点击5按钮")
GUI:delayTouchEnabled(ui["Button_5"], 0.2)
local msg = {}
msg.Script = baixiaosheng.param1
local jsonstr = SL:JsonEncode(msg)
SL:SendLuaNetMsg(58003, baixiaosheng.param2, 4, 0, jsonstr)
-- 点击后刷新图片显示
SL:ScheduleOnce(function()
baixiaosheng.updateTitleImages()
end, 0.5)
end)
end
end
--注册游戏事件
SL:RegisterLUAEvent(LUA_EVENT_PLAYER_EQUIP_CHANGE, "baixiaosheng", function(data)
if data and data.opera == 1 then
baixiaosheng.upmain()
end
end)
SL:RegisterLUAEvent(LUA_EVENT_SKILL_UPDATE, "baixiaosheng", function(data)
baixiaosheng.upmain()
end)
SL:RegisterLUAEvent(LUA_EVENT_CLOSEWIN, "baixiaosheng", function(CLOSEWINdata)
if CLOSEWINdata and CLOSEWINdata == "baixiaosheng" then
SL:UnRegisterLUAEvent(LUA_EVENT_PLAYER_EQUIP_CHANGE, "baixiaosheng")
SL:UnRegisterLUAEvent(LUA_EVENT_SKILL_UPDATE, "baixiaosheng")
SL:UnRegisterLUAEvent(LUA_EVENT_CLOSEWIN, "baixiaosheng")
end
end)
return baixiaosheng
```
## 关键修改说明:
1. **第88行错误修复**:将 `GUI:ImageView_loadTexture` 改为 `GUI:Image_loadTexture`
2. **空值判断修正**:所有 `GUI:Win_IsNotNull` 改为 `not GUI:Win_IsNull(widget)`
3. **称号检测逻辑优化**:使用 `SL:GetMetaValue("HAS_TITLE", titleName)` 获取单个称号状态
4. **函数参数统一**:`checkAllTitles` 函数不再需要actor参数
5. **图片加载函数修正**:`GUI:Image_loadTexture` 只传图片路径参数
下次写代码时要注意函数名的一致性,不懂的函数可以随时问我!