3DMGAME 3DM首页 新闻中心 前瞻 | 评测 游戏库 热门 | 最新 攻略中心 攻略 | 秘籍 下载中心 游戏 | 汉化 购买正版 论坛

注册 登录

QQ登录

只需一步,快速开始

查看: 206|回复: 1
打印 上一主题 下一主题

[资源分享] 让ai做了个改进版标签翻译工具,可以放进ce自启动文件夹。

[复制链接]

49

主题

139

帖子

622

积分

超级玩家

Rank: 5Rank: 5

贡献度
63
金元
3698
积分
622
精华
0
注册时间
2022-1-11
跳转到指定楼层
主题
发表于 2025-12-27 23:29 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
ai总是喜欢自己给你加点别的东西,而且还要改很多次报错,可能是那个ai不行。全翻译多了ctrl+a全选。菜单是ai设的大小挤在一起了,可以手动改。可以手动放到lua执行,但让ai做成这样是为了放到菜单栏做常备工具。
ai帮你写代码太有耐心了,对新手太有帮助了,尤其是报错,让你体验找bug.

这是代码:

-- batch_labels.lua - 批量修改标签工具(仅限选中项)
-- 保存为lua文件,放到CE安装目录/autorun/ 文件夹下可实现自动加载

-- 定义窗体变量
local batchLabelForm = nil

-- 获取选中地址项的辅助函数
local function getSelectedAddressItems()
    local al = getAddressList()
    local selectedItems = {}
    local selectedCount = 0
   
    -- 遍历所有地址项,收集选中的项
    for n = 0, al.Count - 1 do
        local item = al[n]
        if item.selected then
            selectedCount = selectedCount + 1
            selectedItems[selectedCount] = item
        end
    end
   
    return selectedItems, selectedCount
end

-- 创建主窗体的函数
function createBatchLabelForm()
    -- 检查是否已经存在窗体,如果存在则显示并置顶
    if batchLabelForm and not batchLabelForm.isDestroyed then
        batchLabelForm.show()
        batchLabelForm.BringToFront()
        return
    end
   
    -- 如果窗体已被销毁,重置变量
    if batchLabelForm and batchLabelForm.isDestroyed then
        batchLabelForm = nil
    end
   
    -- 创建主窗体
    batchLabelForm = createForm(false)
    batchLabelForm.Position = poDesktopCenter
    batchLabelForm.Width = 512
    batchLabelForm.Height = 600
    batchLabelForm.Caption = '批量修改标签 - 仅选中项 v1.1'
   
    -- 创建分组框
    local gb1 = createGroupBox(batchLabelForm)
    gb1.Left = 10
    gb1.Top = 10
    gb1.Width = 490
    gb1.Height = 100
    gb1.Caption = '操作'
   
    -- 创建按钮
    local b1 = createButton(gb1)
    b1.Left = 20
    b1.Top = 20
    b1.Width = 100
    b1.Height = 30
    b1.caption = '读取选中项 (F5)'
    b1.ShowHint = true
    b1.Hint = '从选中的地址列表中读取标签'
   
    local b2 = createButton(gb1)
    b2.Left = 140
    b2.Top = 20
    b2.Width = 100
    b2.Height = 30
    b2.caption = '修改选中项 (F6)'
    b2.ShowHint = true
    b2.Hint = '将修改应用到选中的地址列表项'
   
    local b3 = createButton(gb1)
    b3.Left = 260
    b3.Top = 20
    b3.Width = 100
    b3.Height = 30
    b3.caption = '清空 (F7)'
    b3.ShowHint = true
    b3.Hint = '清空编辑框内容'
   
    local b4 = createButton(gb1)
    b4.Left = 380
    b4.Top = 20
    b4.Width = 100
    b4.Height = 30
    b4.caption = '保存到文件'
    b4.ShowHint = true
    b4.Hint = '将当前内容保存到文本文件'
   
    local b5 = createButton(gb1)
    b5.Left = 140
    b5.Top = 60
    b5.Width = 100
    b5.Height = 30
    b5.caption = '清空选中项标签'
    b5.ShowHint = true
    b5.Hint = '清空所有选中项的标签'
   
    local b6 = createButton(gb1)
    b6.Left = 260
    b6.Top = 60
    b6.Width = 100
    b6.Height = 30
    b6.caption = '反转选中状态'
    b6.ShowHint = true
    b6.Hint = '反转当前所有地址项的选中状态'
   
    -- 创建统计标签
    local lblStats = createLabel(batchLabelForm)
    lblStats.Left = 15
    lblStats.Top = 120
    lblStats.Caption = '状态: 就绪'
    lblStats.Font.Size = 10
   
    -- 创建Memo控件
    local gb2 = createGroupBox(batchLabelForm)
    gb2.Left = 10
    gb2.Top = 140
    gb2.Width = 490
    gb2.Height = 450
    gb2.Caption = '标签编辑区'
   
    local m = createMemo(gb2)
    m.Height = 420
    m.Left = 10
    m.Top = 20
    m.Width = 470
    m.WordWrap = false
    m.ScrollBars = "ssAutoBoth"
    m.Font.Name = "Consolas"
    m.Font.Size = 10
   
    -- 状态更新函数
    local function updateStatus(message)
        lblStats.Caption = '状态: ' .. message
    end
   
    -- 显示确认对话框
    local function showConfirm(message)
        return messageDialog(message, mtConfirmation, mbYesNo) == mrYes
    end
   
    -- 读取按钮功能(仅读取选中项)
    b1.OnClick = function()
        local selectedItems, selectedCount = getSelectedAddressItems()
        
        if selectedCount == 0 then
            updateStatus("没有选中任何地址项")
            messageDialog("请先在地址列表中选中要操作的地址项", mtWarning, mbOK)
            return
        end
        
        m.clear()
        local lines = {}
        local hasDescription = 0
        
        for i = 1, selectedCount do
            local item = selectedItems[i]
            local description = item.description or ""
            
            if description ~= "" then
                hasDescription = hasDescription + 1
            end
            
            -- 只显示标签内容,不显示地址
            lines[i] = description
        end
        
        m.Lines.Text = table.concat(lines, "\r\n")
        updateStatus("读取完成: 共选中 " .. tostring(selectedCount) .. " 个地址," .. tostring(hasDescription) .. " 个有标签")
    end
   
    -- 修改按钮功能(仅修改选中项)
    b2.OnClick = function()
        local selectedItems, selectedCount = getSelectedAddressItems()
        
        if selectedCount == 0 then
            updateStatus("没有选中任何地址项")
            messageDialog("请先在地址列表中选中要操作的地址项", mtWarning, mbOK)
            return
        end
        
        local memoText = m.Lines.Text
        if memoText == "" then
            updateStatus("编辑框为空")
            return
        end
        
        local lines = m.Lines
        local lineCount = lines.Count
        local modifiedCount = 0
        
        -- 计算需要处理的行数(取较小值)
        local processCount
        if lineCount < selectedCount then
            processCount = lineCount
            updateStatus("警告: 编辑框行数(" .. tostring(lineCount) .. ")少于选中地址数(" .. tostring(selectedCount) .. ")")
        else
            processCount = selectedCount
        end
        
        for i = 0, processCount - 1 do
            local line = lines[i]
            -- 直接使用整行作为标签
            selectedItems[i + 1].description = line
            modifiedCount = modifiedCount + 1
        end
        
        if lineCount > selectedCount then
            local ignoredCount = lineCount - selectedCount
            updateStatus("修改完成: " .. tostring(modifiedCount) .. "/" .. tostring(selectedCount) ..
                         " 个选中标签已更新(超出 " .. tostring(ignoredCount) .. " 行被忽略)")
        else
            updateStatus("修改完成: " .. tostring(modifiedCount) .. "/" .. tostring(selectedCount) .. " 个选中标签已更新")
        end
    end
   
    -- 清空按钮功能
    b3.OnClick = function()
        if m.Lines.Text ~= "" then
            if showConfirm("确定要清空编辑框内容吗?") then
                m.clear()
                updateStatus("编辑框已清空")
            end
        else
            updateStatus("编辑框已经是空的")
        end
    end
   
    -- 清空选中项标签功能
    b5.OnClick = function()
        local selectedItems, selectedCount = getSelectedAddressItems()
        
        if selectedCount == 0 then
            updateStatus("没有选中任何地址项")
            messageDialog("请先在地址列表中选中要操作的地址项", mtWarning, mbOK)
            return
        end
        
        if showConfirm("确定要清空所有选中地址项的标签吗?(共" .. tostring(selectedCount) .. "个)") then
            for i = 1, selectedCount do
                selectedItems[i].description = ""
            end
            updateStatus("已清空 " .. tostring(selectedCount) .. " 个选中地址项的标签")
        end
    end
   
    -- 反转选中状态功能
    b6.OnClick = function()
        local al = getAddressList()
        local totalCount = al.Count
        local selectedCount = 0
        
        for n = 0, totalCount - 1 do
            local item = al[n]
            item.selected = not item.selected
            if item.selected then
                selectedCount = selectedCount + 1
            end
        end
        
        updateStatus("已反转选中状态,当前选中 " .. tostring(selectedCount) .. "/" .. tostring(totalCount) .. " 个地址")
    end
   
    -- 保存到文件功能
    b4.OnClick = function()
        local memoText = m.Lines.Text
        if memoText == "" then
            updateStatus("没有内容可保存")
            messageDialog("编辑框为空,无法保存", mtWarning, mbOK)
            return
        end
        
        local sd = createSaveDialog(batchLabelForm)
        sd.Filter = '文本文件 (*.txt)|*.txt|所有文件 (*.*)|*.*'
        sd.Title = '保存标签到文件'
        sd.FileName = 'cheat_engine_labels_' .. os.date("%Y%m%d_%H%M%S") .. '.txt'
        
        if sd.execute() then
            local filename = sd.FileName
            local file = io.open(filename, "w")
            if file then
                file:write(memoText)
                file:close()
                updateStatus("已保存到: " .. filename)
            else
                updateStatus("保存失败")
                messageDialog("无法保存文件: " .. filename, mtError, mbOK)
            end
        end
    end
   
    -- 添加键盘快捷键
    batchLabelForm.OnKeyDown = function(sender, key)
        if key == VK_F5 then
            b1.OnClick()
        elseif key == VK_F6 then
            b2.OnClick()
        elseif key == VK_F7 then
            b3.OnClick()
        elseif key == VK_ESCAPE then
            batchLabelForm.close()
        end
    end
   
    -- 添加窗体关闭确认
    batchLabelForm.OnClose = function()
        local memoText = m.Lines.Text
        if memoText ~= "" then
            if not showConfirm("编辑框中有未保存的内容,确定要关闭吗?") then
                return caNone
            end
        end
        
        -- 窗体关闭后,重置变量引用,允许重新创建
        batchLabelForm = nil
        return caFree
    end
   
    -- 显示窗体
    batchLabelForm.show()
    updateStatus("就绪 - 按F5读取选中项标签,F6修改选中项标签,F7清空,ESC关闭")
   
    -- 自动调整窗体位置
    batchLabelForm.BringToFront()
end

-- 创建工具菜单项的函数
local function createToolsMenuItem()
    -- 检查是否已经存在这个菜单项
    local exists = false
    if MainForm and MainForm.Menu then
        for i = 0, MainForm.Menu.Items.Count-1 do
            if MainForm.Menu.Items[i].Caption == '批量修改标签(选中项)' then
                exists = true
                break
            end
        end
        
        if not exists then
            -- 创建工具菜单项
            local mi = createMenuItem(MainForm.Menu)
            mi.Caption = '批量修改标签(选中项)'
            mi.OnClick = function()
                -- 调用创建主窗体的函数
                createBatchLabelForm()
            end
            MainForm.Menu.Items.add(mi)
            return true
        end
    end
    return false
end

-- 工具菜单添加函数
local function addToToolsMenu()
    -- 检查是否已经添加了菜单项
    if not MainForm or not MainForm.Menu then
        -- 如果没有主菜单,则延迟添加
        local timer = createTimer(nil)
        timer.Interval = 1000
        timer.OnTimer = function(timer)
            timer.destroy()
            if MainForm and MainForm.Menu then
                createToolsMenuItem()
            end
        end
    else
        createToolsMenuItem()
    end
end

-- 延迟执行以确保CE完全启动
local startupTimer = createTimer(nil, false)
startupTimer.Interval = 1000
startupTimer.OnTimer = function(timer)
    timer.destroy()
    addToToolsMenu()
end
startupTimer.Enabled = true

评分

1

查看全部评分

回复

使用道具 举报

279

主题

2365

帖子

1万

积分

版主

Rank: 18Rank: 18Rank: 18Rank: 18Rank: 18

贡献度
293
金元
92638
积分
10436
精华
0
注册时间
2012-3-24

3DMer(永久)话题讨论高手

舒服的沙发
发表于 2025-12-28 10:52 | 只看该作者
谢谢分享                          
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|3DMGAME ( 京ICP备14006952号-1  沪公网安备 31011202006753号

GMT+8, 2026-3-24 04:15 , Processed in 0.026339 second(s), 17 queries , Memcached On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表