> For the complete documentation index, see [llms.txt](https://ak-scripts.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ak-scripts.gitbook.io/docs/yi-lai/markdown/ti-huan-kuang-jia-mo-ren-zhi/qbcore/wen-ben-textui.md).

# 文本（TextUI）

## ⚙️ 如何更改 QBCore 的默认**文本**

> 本节将教你如何将 `QBCore` **默认文本** 替换为 `ak-lib` **文本**。
>
> 由于 `QBCore` 不同版本在函数结构上略有差异，本次示例基于 `QBCore` `1.3.0` 进行讲解。

***

### 🧭 步骤一：导航到函数文件

前往以下路径：

```
qb-core\client\drawtext.lua
```

***

### 🧩 步骤二：替换 QBcore 整个文本函数内容

```lua
local QB_CORE_TEXTUI_ID = "qb-core-default"

local function convertPosition(qbPosition)
    if not qbPosition or type(qbPosition) ~= 'string' then 
        return 'middle-left'
    end
    local positionMap = {
        ['left'] = 'middle-left',
        ['right'] = 'middle-right',
        ['top'] = 'top-center',
        ['bottom'] = 'bottom-center',
        ['center'] = 'middle-center'
    }
    if positionMap[qbPosition] then
        return positionMap[qbPosition]
    end
    return qbPosition
end

local function hideText()
    exports['ak-lib']:HideTextUI(QB_CORE_TEXTUI_ID)
end

local function drawText(text, position)
    if not text then return end
    local akPosition = convertPosition(position)
    exports['ak-lib']:TextUI({
        id = QB_CORE_TEXTUI_ID,
        message = text,
        position = akPosition,
        duration = 0,
    })
end

local function changeText(text, position)
    if not text then return end
    local akPosition = convertPosition(position)
    local isOpen, _ = exports['ak-lib']:IsTextUIOpen(QB_CORE_TEXTUI_ID)
    if isOpen then
        exports['ak-lib']:UpdateTextUI({
            id = QB_CORE_TEXTUI_ID,
            message = text,
            position = akPosition
        }, QB_CORE_TEXTUI_ID)
    else
        drawText(text, position)
    end
end

local function keyPressed()
    CreateThread(function()
        Wait(500)
        hideText()
    end)
end

RegisterNetEvent('qb-core:client:DrawText', function(text, position)
    drawText(text, position)
end)

RegisterNetEvent('qb-core:client:ChangeText', function(text, position)
    changeText(text, position)
end)

RegisterNetEvent('qb-core:client:HideText', function()
    hideText()
end)

RegisterNetEvent('qb-core:client:KeyPressed', function()
    keyPressed()
end)

exports('DrawText', drawText)
exports('ChangeText', changeText)
exports('HideText', hideText)
exports('KeyPressed', keyPressed)

```

***


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ak-scripts.gitbook.io/docs/yi-lai/markdown/ti-huan-kuang-jia-mo-ren-zhi/qbcore/wen-ben-textui.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
