math.randomseed(tostring(os.time()):reverse():sub(1, 6))
cogin = {}
cogin.drop = SL:Require("GUILayout/config/drop.lua", true)
local function init()
SL:Require("GUILayout/FeiJianAction", true)
end
local result, errinfo = pcall(init)
if not res
```lua
-- 将编码从GBK转换为UTF-8
math.randomseed(tostring(os.time()):reverse():sub(1, 6))
cogin = {}
cogin.drop = SL:Require("GUILayout/config/drop.lua", true)
local function init()
SL:Require("GUILayout/FeiJianAction", true)
end
local result, errinfo = pcall(init)
if not result then
SL:Print("初始化错误:", errinfo)
end
-- 注册NPC图层状态事件
SL:RegisterLUAEvent('LUA_EVENT_NPCLAYER_OPENSTATUS', 'jiemian', function(status)
if status then
local NPCLayerMediator = global.Facade:retrieveMediator("NPCLayerMediator")
if not NPCLayerMediator or not NPCLayerMediator._layer then
return nil
end
GUI:Timeline_Window2(NPCLayerMediator._layer)
end
end)
-- 注册PC小地图状态变化事件
SL:RegisterLUAEvent('LUA_EVENT_PCMINIMAP_STATUS_CHANGE', '绔為€熶箣鍦�', function(status)
if status == 3 then
SL:SendNetMsg(130)
end
end)
-- 创建地图名称显示模块
MapNameDisplay = {}
function MapNameDisplay:create()
-- 创建父节点 - 使用主界面附着点
local parent = GUI:Attach_Parent()
if GUI:Win_IsNull(parent) then
SL:Print("无法获取父节点,使用备用方案")
-- 创建备用父节点
parent = GUI:Win_Create("MapNameParent", 0, 0, 0, 0, false, false, true, false, false, false, 1)
end
if GUI:Win_IsNull(parent) then
SL:Print("无法创建有效的父节点")
return false
end
-- 创建文字控件
local textLabel = GUI:Text_Create(parent, "MapName_Display", 0, 0, 54, "#ffffff", "")
if GUI:Win_IsNull(textLabel) then
SL:Print("文字控件创建失败")
return false
end
-- 设置文字样式
GUI:setAnchorPoint(textLabel, 0.5, 0.5)
GUI:setVisible(textLabel, true)
GUI:setOpacity(textLabel, 0) -- 初始透明
-- 存储引用
MapNameDisplay._textLabel = textLabel
return true
end
function MapNameDisplay.onMapChange()
-- 检查控件是否存在
if not MapNameDisplay._textLabel or GUI:Win_IsNull(MapNameDisplay._textLabel) then
SL:Print("文字控件不存在,重新创建")
if not MapNameDisplay:create() then
SL:Print("创建控件失败")
return
end
end
-- 关键修改:在每次地图切换时获取当前分辨率
local screenW = SL:GetMetaValue("SCREEN_WIDTH")
local screenH = SL:GetMetaValue("SCREEN_HEIGHT")
local mapName = SL:GetMetaValue("MAP_NAME") or ""
-- 更新文字内容
GUI:Text_setString(MapNameDisplay._textLabel, "[~ "..mapName.." ~]")
-- 根据当前分辨率设置居中位置
GUI:setPosition(MapNameDisplay._textLabel, screenW/2, screenH/1.2)
-- 停止之前的动作
GUI:stopAllActions(MapNameDisplay._textLabel)
-- 设置初始透明度
GUI:setOpacity(MapNameDisplay._textLabel, 0)
-- 创建淡入淡出动画序列
local fadeIn = GUI:ActionFadeTo(1, 255) -- 0.5秒淡入
local delay = GUI:DelayTime(1.8) -- 保持1.5秒
local fadeOut = GUI:ActionFadeTo(1, 0) -- 0.5秒淡出
-- 创建动作序列
local sequence = GUI:ActionSequence(fadeIn, delay, fadeOut)
-- 执行动画
GUI:runAction(MapNameDisplay._textLabel, sequence)
end
-- 初始化
function MapNameDisplay.main()
-- 先创建控件
if MapNameDisplay:create() then
-- 再注册事件
SL:RegisterLUAEvent(LUA_EVENT_MAPINFOCHANGE, "MapNameDisplay", MapNameDisplay.onMapChange)
SL:Print("地图名称显示模块初始化成功")
else
SL:Print("地图名称显示模块初始化失败")
end
end
-- 延迟调用初始化
MapNameDisplay.main()
```