local zhuansheng = {}
function zhuansheng.main(param1, param2, param3, param4)
SL:print("===== 转生界面打开 =====")
lib:Require(param1, function(state)
if state then
if param1 then
zhuansheng.parent = lib:o
你的问题在于动作执行后没有保存最终位置状态。当界面重新打开时,控件会恢复到原始位置。以下是完整的修复代码:
```lua
local zhuansheng = {}
function zhuansheng.main(param1, param2, param3, param4)
SL:print("===== 转生界面打开 =====")
lib:Require(param1, function(state)
if state then
if param1 then
zhuansheng.parent = lib:openwin(param1, nil, true, param4) or {}
zhuansheng.param1 = param1
end
if param2 then
zhuansheng.param2 = param2
end
if param3 then
zhuansheng.param3 = param3
end
-- 检查配置
if zhuansheng.parent and zhuansheng.parent.cfg and next(zhuansheng.parent.cfg) then
zhuansheng.upmain()
else
lib:msg("系统未配置!")
if zhuansheng.parent and zhuansheng.parent._parent then
GUI:Win_Close(zhuansheng.parent._parent)
end
end
end
end)
end
--创建属性框
local function create_attr(next_data)
local ui = zhuansheng.parent._ui
if not next_data or not next(next_data) then
return
end
-- 只更新攻击和生命显示
if GUI:Win_IsNotNull(ui["next_attack"]) then
local attack_value = next_data.cur_attr_4 or 0
GUI:Text_setString(ui["next_attack"], tostring(attack_value) .. "%")
end
if GUI:Win_IsNotNull(ui["next_hp"]) then
local hp_value = next_data.cur_attr_1 or 0
GUI:Text_setString(ui["next_hp"], tostring(hp_value))
end
end
-- 显示特效图标
local function update_effect_icons()
local ui = zhuansheng.parent._ui
-- 获取当前转生等级
local curLevel = SL:GetMetaValue("RELEVEL") or 0
local cfg = zhuansheng.parent.cfg
if not cfg or not cfg[curLevel] then
return
end
local brightCount = 0
if cfg[curLevel].brightpicture then
brightCount = cfg[curLevel].brightpicture
else
-- 如果没有 brightpicture
brightCount = (curLevel - 1) % 5 + 1
end
-- 循环处理5个特效图标
for i = 1, 5 do
local objectName = "Effect_" .. i
if GUI:Win_IsNotNull(ui[objectName]) then
if i <= brightCount then
GUI:setVisible(ui[objectName], true)
else
GUI:setVisible(ui[objectName], false)
end
end
end
-- 先隐藏所有Image控件
for i = 9, 13 do
local objectName = "Image_" .. i
if GUI:Win_IsNotNull(ui[objectName]) then
GUI:setVisible(ui[objectName], false)
end
end
-- 根据转生等级显示对应的Image控件
if curLevel >= 1 then
if GUI:Win_IsNotNull(ui["Image_9"]) then
GUI:setVisible(ui["Image_9"], true)
end
end
if curLevel >= 2 then
if GUI:Win_IsNotNull(ui["Image_10"]) then
GUI:setVisible(ui["Image_10"], true)
end
end
if curLevel >= 3 then
if GUI:Win_IsNotNull(ui["Image_11"]) then
GUI:setVisible(ui["Image_11"], true)
end
end
if curLevel >= 4 then
if GUI:Win_IsNotNull(ui["Image_12"]) then
GUI:setVisible(ui["Image_12"], true)
end
end
if curLevel >= 5 then
if GUI:Win_IsNotNull(ui["Image_13"]) then
GUI:setVisible(ui["Image_13"], true)
end
end
end
-- 保存Image_9的位置状态
local savedImage9Position = nil
function zhuansheng.upmain()
SL:print("===== 更新转生界面 =====")
if not zhuansheng.parent or not zhuansheng.parent._ui then
return
end
local ui = zhuansheng.parent._ui
local cfg = zhuansheng.parent.cfg
if not cfg then
return
end
-- 获取当前转生等级
local curlevel = SL:GetMetaValue("RELEVEL") or 0
local next_level = curlevel + 1
local next_data = cfg[next_level]
-- 检查地图条件
if cfg[SL:GetMetaValue("RELEVEL") + 1] and
cfg[SL:GetMetaValue("RELEVEL") + 1].name3 ~= SL:GetMetaValue("MAP_ID") then
SL:print(cfg[SL:GetMetaValue("RELEVEL") + 1].name3, SL:GetMetaValue("MAP_ID"))
local myStr = "提示:请前往正确大路提升!!!"
local coloredStr = string.format("<outline color = '#FF0000' size = '1'>%s</outline>", myStr)
SL:ShowSystemTips(coloredStr)
GUI:Win_CloseAll()
return
end
-- 检查是否已满级
if curlevel >= #cfg then
lib:msg("您已满级!")
if zhuansheng.parent._parent then
GUI:Win_Close(zhuansheng.parent._parent)
end
return
end
-- 创建属性显示
if next_data then
create_attr(next_data)
end
-- 更新等级显示
local level_widgets = {"lv", "Label_lv", "Text_lv", "Label_level"}
for _, widget_name in ipairs(level_widgets) do
if GUI:Win_IsNotNull(ui[widget_name]) then
GUI:Text_setString(ui[widget_name], "Lv" .. tostring(curlevel))
break
end
end
-- 更新特效图标
update_effect_icons()
-- 检查升级条件
if next_data and lib and lib.checkitem then
local check_data = {
count = 2,
type1 = "物品",
name1 = next_data.name1 or "转生石",
value1 = tonumber(next_data.value1) or 0,
type2 = "货币",
name2 = next_data.name2 or "金币",
value2 = tonumber(next_data.value2) or 0,
}
local can_upgrade = lib:checkitem(check_data, true)
if can_upgrade then
if lib.create_green_point then
zhuansheng.btn_green_frames = lib:create_green_point(ui["Button_1"], 100, -12)
end
end
end
-- 设置升级按钮
if GUI:Win_IsNotNull(ui["Button_1"]) then
GUI:addOnClickEvent(ui["Button_1"], function()
SL:print("点击升级按钮")
GUI:delayTouchEnabled(ui["Button_1"], 0.2)
local msg = {}
msg.Script = zhuansheng.param1
local jsonstr = SL:JsonEncode(msg)
SL:SendLuaNetMsg(58003, zhuansheng.param2, 0, 0, jsonstr)
-- 检查条件
if next_data and lib and lib.checkitem then
local check_data = {
count = 2,
type1 = "物品",
name1 = next_data.name1 or "转生石",
value1 = tonumber(next_data.value1) or 0,
type2 = "货币",
name2 = next_data.name2 or "金币",
value2 = tonumber(next_data.value2) or 0,
}
local can_upgrade = lib:checkitem(check_data)
if not can_upgrade then
return
end
-- 先获取最终的目标位置
local targetX = 77
local targetY = 281
-- 保存位置状态
savedImage9Position = {x = targetX, y = targetY}
-- 修改动作序列
GUI:runAction(ui.Image_9, GUI:ActionSequence(
GUI:ActionScaleTo(0.5, 1.4),
GUI:ActionScaleTo(0.5, 1),
GUI:ActionMoveTo(0.5, 0, 0),
GUI:ActionMoveBy(0.2, 77, 281),
GUI:CallFunc(function()
-- 设置控件到最终位置
GUI:setPosition(ui.Image_9, targetX, targetY)
SL:print("Image_9已固定在最终位置")
end)
))
end
end)
end
-- 恢复Image_9的保存位置
if savedImage9Position and GUI:Win_IsNotNull(ui["Image_9"]) then
GUI:setPosition(ui.Image_9, savedImage9Position.x, savedImage9Position.y)
SL:print("已恢复Image_9位置到: " .. savedImage9Position.x .. ", " .. savedImage9Position.y)
end
-- 显示物品需求
if GUI:Win_IsNotNull(ui.itemroom) and next_data then
GUI:removeAllChildren(ui.itemroom)
-- 转生石检查
local item_name = next_data.name1 or "转生石"
local itemCount = tonumber(SL:GetMetaValue("ITEM_COUNT", item_name)) or 0
local needItemCount = tonumber(next_data.value1) or 0
-- 金币检查
local goldCount = tonumber(SL:GetMetaValue("MONEY", 1)) or 0
local needGold = tonumber(next_data.value2) or 0
-- 获取物品ID
local item_id = 0
if next_data.itemid then
item_id = tonumber(next_data.itemid) or 11533
else
item_id = lib:getitemidx(item_name) or 11533
end
-- 获取货币ID
local money_id = tonumber(next_data.moneyid) or 1
local function safe_lt(a, b)
local num_a = tonumber(a) or 0
local num_b = tonumber(b) or 0
return num_a < num_b
end
-- 根据是否足够设置颜色
local itemColor = 255
if safe_lt(itemCount, needItemCount) then
itemColor = 58
end
local goldColor = 255
if safe_lt(goldCount, needGold) then
goldColor = 58
end
-- 创建转生石显示
GUI:ItemShow_Create(ui.itemroom, "ItemShow_zs", 101, 62, {
index = item_id,
count = needItemCount,
look = true,
bgVisible = false,
color = itemColor
})
-- 创建金币显示
GUI:ItemShow_Create(ui.itemroom, "ItemShow_god", 181, 62, {
index = money_id,
count = needGold,
look = true,
bgVisible = false,
color = goldColor
})
end
SL:print("===== 界面更新完成 =====")
end
--注册游戏事件
SL:RegisterLUAEvent(LUA_EVENT_PLAYER_EQUIP_CHANGE, "zhuansheng", function(data)
if data and data.opera == 1 then
zhuansheng.upmain()
end
end)
SL:RegisterLUAEvent(LUA_EVENT_REINLEVELCHANGE, "zhuansheng", function(data)
zhuansheng.upmain()
end)
SL:RegisterLUAEvent(LUA_EVENT_CLOSEWIN, "zhuansheng", function(CLOSEWINdata)
if CLOSEWINdata and CLOSEWINdata == "zhuansheng" then
SL:UnRegisterLUAEvent(LUA_EVENT_PLAYER_EQUIP_CHANGE, "zhuansheng")
SL:UnRegisterLUAEvent(LUA_EVENT_REINLEVELCHANGE, "zhuansheng")
SL:UnRegisterLUAEvent(LUA_EVENT_CLOSEWIN, "zhuansheng")
end
end)
return zhuansheng
```
主要修改:
1. 添加了 `savedImage9Position` 全局变量来保存位置状态
2. 在升级按钮点击时保存位置到 `savedImage9Position`
3. 在 `upmain()` 函数中恢复保存的位置
4. 使用 `GUI:setPosition()` 函数直接设置控件坐标
这样每次重新打开界面时,Image_9都会保持在最后停留的位置。