local rongyuchenghao = {}
function rongyuchenghao.main(param1, param2, param3, param4)
lib:Require(param1, function(state)
if state then
if param1 then
rongyuchenghao.parent = lib:openwin(param1, nil, true, pa
根据你的需求,我为你编写一个完整的称号升级特效显示系统。这个系统会根据升级次数显示对应的特效,并在升级到下一称号时重置。
```lua
-- 在rongyuchenghao模块中添加升级计数和特效管理
local rongyuchenghao = {}
rongyuchenghao.upgradeCount = 0 -- 当前称号的升级次数
rongyuchenghao.currentEffect = nil -- 当前显示的特效
-- 创建特效显示函数
local function createUpgradeEffect(ui, effectName, effectId, x, y)
if GUI:Win_IsNull(ui.Image_2) then
return nil
end
-- 如果已有特效,先移除
if rongyuchenghao.currentEffect then
GUI:removeFromParent(rongyuchenghao.currentEffect)
rongyuchenghao.currentEffect = nil
end
-- 创建新特效
local effect = GUI:Effect_Create(ui.Image_2, effectName, x, y, 0, effectId, 0, 0, 0, 1)
GUI:setTag(effect, 0)
rongyuchenghao.currentEffect = effect
return effect
end
-- 更新特效显示
local function updateUpgradeEffect(ui, upgradeCount)
local var = tonumber(lib:getstr("U34") or 0) or 0
local cfg = rongyuchenghao.parent.cfg
local current_level = var
-- 处理等级上限
if current_level > 25 then
current_level = 25
end
-- 0级不显示
if current_level == 0 then
GUI:setVisible(ui.Image_2, false)
GUI:setVisible(ui.Image_6, false)
if rongyuchenghao.currentEffect then
GUI:removeFromParent(rongyuchenghao.currentEffect)
rongyuchenghao.currentEffect = nil
end
return
end
-- 确保控件可见
GUI:setVisible(ui.Image_2, true)
GUI:setVisible(ui.Image_6, true)
-- 根据升级次数显示不同特效
if upgradeCount == 1 then
-- 升级1次显示Effect_2
createUpgradeEffect(ui, "Effect_2", 32174, 0, 0) -- 使用资料1中的s_2特效ID
elseif upgradeCount == 2 then
-- 升级2次显示Effect_3
createUpgradeEffect(ui, "Effect_3", 32175, 0, 0) -- 使用资料1中的s_3特效ID
elseif upgradeCount == 3 then
-- 升级3次显示Effect_4
createUpgradeEffect(ui, "Effect_4", 32176, 0, 0) -- 使用资料1中的s_4特效ID
elseif upgradeCount == 4 then
-- 升级4次显示Effect_5
createUpgradeEffect(ui, "Effect_5", 32177, 0, 0) -- 使用资料1中的s_5特效ID
else
-- 没有升级或升级次数为0,移除特效
if rongyuchenghao.currentEffect then
GUI:removeFromParent(rongyuchenghao.currentEffect)
rongyuchenghao.currentEffect = nil
end
end
end
-- 修改upmain函数中的升级按钮点击事件
function rongyuchenghao.upmain()
if not rongyuchenghao.parent or not rongyuchenghao.parent._ui then
return
end
local ui = rongyuchenghao.parent._ui
local cfg = rongyuchenghao.parent.cfg
if not cfg then
return
end
local var = tonumber(lib:getstr("U34") or 0) or 0
if var == "" then var = 0 end
var = tonumber(var) or 0
local next_level = var + 1
local next_data = cfg[next_level]
-- 检查是否已满级
if var >= #cfg then
lib:msg("荣誉称号已满级!")
if GUI:Win_IsNotNull(ui["Button_1"]) then
GUI:setTouchEnabled(ui["Button_1"], false)
end
if GUI:Win_IsNotNull(ui.Image_2) then
GUI:Image_loadTexture(ui.Image_2, "res/yidalu/chenghao/" .. (var) .. ".png")
end
-- 满级时显示最高级特效
updateUpgradeEffect(ui, 4)
return
end
-- 创建属性显示
if next_data then
create_attr(next_data)
end
-- 显示当前宝石图片
if GUI:Win_IsNotNull(ui.Image_2) then
local current_level = var
if current_level > 25 then
current_level = 25
end
if current_level == 0 then
GUI:setVisible(ui.Image_2, false)
GUI:setVisible(ui.Image_6, false)
else
GUI:setVisible(ui.Image_2, true)
GUI:setVisible(ui.Image_6, true)
GUI:Image_loadTexture(ui.Image_2, "res/yidalu/chenghao/" .. (current_level) .. ".png")
end
end
if GUI:Win_IsNotNull(ui.Image_3) then
local current_level = var
GUI:Image_loadTexture(ui.Image_3, "res/yidalu/chenghao/" .. (current_level + 1) .. ".png")
end
-- 设置升级按钮
if GUI:Win_IsNotNull(ui["Button_1"]) then
GUI:addOnClickEvent(ui["Button_1"], function()
SL:print("点击称号升级按钮,当前升级次数:" .. (rongyuchenghao.upgradeCount + 1))
GUI:delayTouchEnabled(ui["Button_1"], 0.2)
-- 增加升级计数
rongyuchenghao.upgradeCount = rongyuchenghao.upgradeCount + 1
-- 如果升级4次,重置计数(进入下一称号)
if rongyuchenghao.upgradeCount >= 4 then
rongyuchenghao.upgradeCount = 0
-- 发送升级请求到服务端
local msg = {}
msg.Script = rongyuchenghao.param1
local jsonstr = SL:JsonEncode(msg)
SL:SendLuaNetMsg(58003, rongyuchenghao.param2, 0, 0, jsonstr)
else
-- 只更新前端特效显示,不发送服务端请求
updateUpgradeEffect(ui, rongyuchenghao.upgradeCount)
end
end)
end
-- 每次打开界面时更新特效显示
updateUpgradeEffect(ui, rongyuchenghao.upgradeCount)
-- 注册游戏事件
SL:RegisterLUAEvent(LUA_EVENT_PLAYER_EQUIP_CHANGE, "rongyuchenghao", function(data)
if data and data.opera == 1 then
-- 装备变化时重置升级计数
rongyuchenghao.upgradeCount = 0
rongyuchenghao.upmain()
end
end)
SL:RegisterLUAEvent(LUA_EVENT_SERVER_VALUE_CHANGE, "rongyuchenghao", function(data)
if next(data) and data.key == "U34" then
-- 称号等级变化时重置升级计数
rongyuchenghao.upgradeCount = 0
rongyuchenghao.upmain()
end
end)
SL:RegisterLUAEvent(LUA_EVENT_CLOSEWIN, "rongyuchenghao", function(CLOSEWINdata)
if CLOSEWINdata and CLOSEWINdata == "rongyuchenghao" then
-- 关闭窗口时清理
if rongyuchenghao.currentEffect then
GUI:removeFromParent(rongyuchenghao.currentEffect)
rongyuchenghao.currentEffect = nil
end
rongyuchenghao.upgradeCount = 0
SL:UnRegisterLUAEvent(LUA_EVENT_PLAYER_EQUIP_CHANGE, "rongyuchenghao")
SL:UnRegisterLUAEvent(LUA_EVENT_CLOSEWIN, "rongyuchenghao")
end
end)
end
return rongyuchenghao
```
这个系统实现了以下功能:
1. **升级计数管理**:使用`rongyuchenghao.upgradeCount`记录当前称号的升级次数
2. **特效显示**:根据升级次数显示对应的特效(Effect_2到Effect_5)
3. **自动重置**:升级4次后自动重置计数,并发送服务端请求升级到下一称号
4. **事件处理**:在称号等级变化或装备变化时自动重置升级计数
5. **资源清理**:窗口关闭时清理特效和重置计数
**使用说明**:
- 每次点击升级按钮,前端会显示对应的特效
- 第4次点击时,会发送服务端请求真正升级称号
- 切换称号时,升级计数会自动重置
- 特效ID使用了资料1中的示例,你可以根据需要修改为实际的特效ID
注意:你需要确保特效资源文件存在,并且特效ID正确。如果特效位置需要调整,可以修改`createUpgradeEffect`函数中的x,y参数。