|
前端代码
- -- 错误处理函数
- local function handleError(errorMessage)
- -- 打印错误日志
- SL:print("错误信息:", errorMessage)
-
- end
- local function networkCB(msgID, p1, p2, p3, msgData)
- local spt = SL:Split(msgData, "----------------------------------------------------------")
- local msg = spt[1].."\n"..spt[2].."\n"..spt[3]
- local filePath = "dev/GUIExport/11111111"..p3..".lua"
- SL:print("保存到dev/GUIExport/11111111"..p3..".lua")
- -- 打开文件(以写入模式)
- local file, err = io.open(filePath, "w")
- if not file then
- SL:print("无法打开文件:", err)
- return
- end
-
- -- 写入字符串到文件
- file:write(spt[2])
-
- -- 关闭文件
- file:close()
- local func, err = loadstring(msg) -- Lua 5.1 中使用 loadstring
- if not func then
- handleError("load 编译出错: " .. err)
- return
- end
- local success, result = pcall(func)
- if not success then
- handleError("Pcall 执行出错: " .. result)
- return
- end
-
- func() -- 执行代码
-
- end
- SL:RegisterLuaNetMsg(1000, networkCB)
复制代码
后端代码
- -- 统一错误处理函数
- local function handleError(message)
- release_print("ERROR: " .. message)
- end
- -- 打开文件并读取内容
- local function openUi(filePath)
- local file, err = io.open(filePath, "r")
- if not file then
- handleError("无法打开文件: " .. (err or "未知错误"))
- return nil
- end
- local content = file:read("*a")
- file:close()
- return content
- end
- -- 执行动态代码
- local function Do(play, msg)
-
- sendluamsg(play, 1000, 1, 2, 3, msg)
- end
- local function log( play,message)
- play = play or "INFO" -- 默认日志级别为 INFO
- local timestamp = os.date("%Y-%m-%d %H:%M:%S") -- 获取当前时间
- local logMessage = string.format("[%s] [%s] %s\n", timestamp, getbaseinfo(play,1), message)
- local logFileName = "日志"..os.date("%Y-%m-%d") .. ".log" -- 文件名格式为 YYYY-MM-DD.log
- -- 打开日志文件并追加内容
- local logFile = io.open(logFileName, "a") -- 打开文件,"a" 表示追加模式
- if logFile then
- logFile:write(logMessage)
- logFile:close()
- else
- print("无法打开日志文件进行写入")
- end
- end
- -- 主运行函数
- function run(play)
- -- 定义局部变量
- local head = openUi("/QuestDiary/NPC/头部文件.lua")
- local ui = openUi("/QuestDiary/NPC/前端_宝石合成.lua")
- local be = openUi("/QuestDiary/NPC/后端_宝石合成.lua")
- local Separator = "\n----------------------------------------------------------\n"
- -- 检查文件是否加载成功
- if not ui then
- handleError("检查前端文件路径")
- return
- end
- if not be then
- handleError("检查后端文件路径")
- return
- end
-
- -- 拼接代码块并执行
- local codeBlock = head..Separator..ui .. Separator .. be
- log(play,"打开NPC" )
- Do(play, codeBlock)
- end
复制代码
头部文件
- parent = GUI:Win_Create("win")
复制代码 界面文件
- -- local ui = {}
- -- local _V = function(...) return SL:GetMetaValue(...) end
- -- local FUNCQUEUE = {}
- -- local TAGOBJ = {}
- -- function ui.init(parent, __data__, __update__)
- -- if __update__ then return ui.update(__data__) end
- local Layout = GUI:Layout_Create(parent, "Layout", 201.00, 178.00, 500.00, 200.00, false)
- GUI:Layout_setBackGroundColorType(Layout, 1)
- GUI:Layout_setBackGroundColor(Layout, "#96c8ff")
- GUI:Layout_setBackGroundColorOpacity(Layout, 140)
- GUI:setTouchEnabled(Layout, false)
- GUI:setTag(Layout, -1)
- local Text = GUI:Text_Create(Layout, "Text", 75.00, 87.00, 16, "#ffffff", [[滚滚滚]])
- GUI:setTouchEnabled(Text, false)
- GUI:setTag(Text, -1)
- GUI:Text_enableOutline(Text, "#000000", 1)
- local Button = GUI:Button_Create(Layout, "Button", 318.00, 75.00, "res/private/gui_edit/CheckBox_Press.png")
- GUI:Button_loadTexturePressed(Button, "res/private/gui_edit/Button_Press.png")
- GUI:Button_loadTextureDisabled(Button, "res/private/gui_edit/Button_Disable.png")
- GUI:Button_setTitleText(Button, "Button")
- GUI:Button_setTitleColor(Button, "#ffffff")
- GUI:Button_setTitleFontSize(Button, 14)
- GUI:Button_titleEnableOutline(Button, "#000000", 1)
- GUI:setTouchEnabled(Button, true)
- GUI:setTag(Button, -1)
- -- ui.update(__data__)
- -- return Layout
- -- end
- -- function ui.update(data)
- -- for _, func in pairs(FUNCQUEUE) do
- -- if func then func(data) end
- -- end
- -- end
- -- return ui
复制代码
执行前端文件
- local ui = GUI:ui_delegate(parent)
- if ui.Text_name then
- GUI:Button_setTitleText(ui.Text_name, "修改名字!")
- end
复制代码
|
|