> For the complete documentation index, see [llms.txt](https://docs.kensohub.ru/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kensohub.ru/instrukcii/demo-plagin.md).

# Демо-плагин

KL-DEMO.plugin

```lua
-- =============================================================================
-- ДЕМОНСТРАЦИОННЫЙ ПЛАГИН GUI
-- =============================================================================
VERS = "1.0"
MODULE = "KL-GUIDEMO "..VERS.." (Plugin for KensoUltra+) [by Kelix.me]"
print(string.format("[KensoLUA] Инициализация модуля: %s", MODULE))

-- =============================================================================
-- СОЗДАНИЕ ВКЛАДКИ В МЕНЮ
-- =============================================================================
gui:CreateTab("plugin_guidemo", "GUI Demo >", {
    {"guidemo-elements", "Все элементы"},
    {"guidemo-controls", "Управление"},
    {"guidemo-info", "Информация"},
})

-- =============================================================================
-- ОПРЕДЕЛЕНИЕ ВСЕХ ЭЛЕМЕНТОВ GUI
-- =============================================================================

-- ---- ТЕКСТОВЫЕ ЭЛЕМЕНТЫ ----
demo_label = gui:Label({
    RU = "=== ДЕМОНСТРАЦИЯ GUI ЭЛЕМЕНТОВ ===",
    EN = "=== GUI ELEMENTS DEMONSTRATION ==="
})

demo_textline = gui:TextLine({
    RU="Разделитель настроек",
    EN="Settings separator",
})

-- ---- ЧЕКБОКСЫ (все типы) ----
demo_checkbox = gui:CheckBox({
    RU = "Обычный чекбокс",
    EN = "Regular checkbox"
}, false)

demo_checkbox_with_color = gui:CheckBox({
    RU = "Чекбокс с цветом",
    EN = "Checkbox with color"
}, false, true, color_t(215/255, 254/255, 123/255, 1))

demo_checkbox_button = gui:Button({
    RU = "Кнопка (нажми меня!)",
    EN = "Button (click me!)"
}, false)

-- ---- ВЫПАДАЮЩИЕ СПИСКИ ----
demo_dropdown = gui:Dropdown({
    RU = "Выпадающий список",
    EN = "Dropdown list"
}, {
    {RU = "Пункт 1", EN = "Item 1"},
    {RU = "Пункт 2", EN = "Item 2"},
    {RU = "Пункт 3", EN = "Item 3"},
    {RU = "Пункт 4", EN = "Item 4"},
}, 1)

demo_combobox = gui:ComboBox({
    RU = "Множественный выбор",
    EN = "Multi-select"
}, ParamsBox({
    {"Опция 1", false},
    {"Опция 2", false},
    {"Опция 3", false},
    {"Опция 4", false},
}))

-- ---- СЛАЙДЕРЫ ----
demo_slider = gui:Slider({
    RU = "Ползунок (0-100)",
    EN = "Slider (0-100)"
}, 50, 0, 100, 1)

demo_slider_float = gui:Slider({
    RU = "Ползунок с плавающей точкой",
    EN = "Float slider"
}, 0.5, 0, 1, 0.01)

-- ---- ТЕКСТОВЫЙ ВВОД ----
demo_text_input = gui:TextInput({
    RU = "Текстовое поле",
    EN = "Text input"
}, "Введите текст...")

-- ---- КЕЙБИНД ----
demo_keybind = gui:KeyBind({
    RU = "Привязка клавиши",
    EN = "Key bind"
}, function() 
    engine.chat_print("[GUI Demo] Кейбинд сработал!")
end, 2, 0x4E) -- По умолчанию 'N'

-- ---- ИНФОРМАЦИОННЫЕ ЭЛЕМЕНТЫ ----
demo_steam_info = gui:SteamInfo(
    "Steam User: DemoPlayer\nSteamID64: 76561197960265728\nSteamID32: STEAM_1:1:123456"
)

demo_info_label = gui:Label({
    RU = table.concat({
        "• Это информационная метка", '\n',
        "• Поддерживает многострочный текст", '\n',
        "• Можно использовать для справки"
    }),
    EN = table.concat({
        "• This is an info label", '\n',
        "• Supports multi-line text", '\n',
        "• Can be used for help"
    })
})

-- ---- ДОПОЛНИТЕЛЬНЫЕ ЭЛЕМЕНТЫ ----
demo_empty = gui:Label({RU = "", EN = ""})
demo_separator = gui:TextLine("---")

-- =============================================================================
-- ГРУППИРОВКА ЭЛЕМЕНТОВ ПО КАТЕГОРИЯМ
-- =============================================================================

-- Вкладка "Все элементы" - полный список
gui:AddElements('guidemo-elements', {
    demo_label,
    demo_empty,
    demo_textline,
    demo_empty,
    demo_checkbox,
    demo_checkbox_with_color,
    demo_checkbox_button,
    demo_empty,
    demo_dropdown,
    demo_combobox,
    demo_empty,
    demo_slider,
    demo_slider_float,
    demo_empty,
    demo_text_input,
    demo_keybind,
    demo_empty,
    demo_steam_info,
    demo_info_label,
})

-- Вкладка "Управление" - элементы управления
gui:AddElements('guidemo-controls', {
    demo_label,
    demo_textline,
    demo_checkbox,
    demo_checkbox_with_color,
    demo_checkbox_button,
    demo_dropdown,
    demo_combobox,
    demo_slider,
    demo_slider_float,
    demo_text_input,
    demo_keybind,
})

-- Вкладка "Информация" - информационные элементы
gui:AddElements('guidemo-info', {
    demo_label,
    demo_steam_info,
    demo_info_label,
})

-- =============================================================================
-- ЛОГИКА ПЛАГИНА (демонстрация работы элементов)
-- =============================================================================

-- Обработка кнопки
local button_clicked = false

register_callback("paint", function()
    -- Демонстрация работы кнопки
    if demo_checkbox_button and demo_checkbox_button.value then
        if not button_clicked then
            button_clicked = true
            engine.chat_print("[GUI Demo] Кнопка нажата!")
            print("[GUI Demo] Кнопка нажата!")
            demo_checkbox_button.value = false
        end
    else
        button_clicked = false
    end
    -- Демонстрация работы кейбинда
    if demo_keybind and demo_keybind.value then
        local key_state = bit.band(ffi.C.GetAsyncKeyState(demo_keybind.value), 0x8000) ~= 0
        if key_state then
            engine.chat_print("[GUI Demo] Кейбинд активирован!")
            print("[GUI Demo] Кейбинд активирован!")
        end
    end
end)

-- =============================================================================
-- КОНФИГУРАЦИЯ ДЛЯ СОХРАНЕНИЯ НАСТРОЕК
-- =============================================================================

config_file_demo = SCFG..'kl-guidemo.jsonc'

-- Синхронизация с оригинальной системой сохранения
original_save_demo = saveSettings
saveSettings = function()
    original_save_demo()
    setting:SaveConfig(config_file_demo, {
        demo_checkbox,
        demo_checkbox_with_color,
        demo_dropdown,
        demo_combobox,
        demo_slider,
        demo_slider_float,
        demo_text_input,
        demo_keybind,
    })
end

original_load_demo = loadSettings
loadSettings = function()
    original_load_demo()
    setting:LoadConfig(config_file_demo)
end

-- =============================================================================
-- ИНИЦИАЛИЗАЦИЯ
-- =============================================================================

print(string.format("[KensoLUA] Плагин GUI Demo загружен!"))
print(string.format("[KensoLUA] Доступные элементы: Чекбоксы, Дропдауны, Слайдеры, Кейбинды и др."))

-- Загрузка сохранённых настроек
function init()
    local wait_count = 0
    local max_wait = 200
    while wait_count < max_wait and (not HWID_auth or HWID_auth ~= 1) do
        wait_count = wait_count + 1
        coroutine.yield()
    end
    if HWID_auth == 1 then
        setting:LoadConfig(config_file_demo)
        print("[KensoLUA] GUI Demo: Настройки загружены")
    end
end
function safe_init()
    local co = coroutine.create(init)
    local function step()
        if coroutine.status(co) ~= "dead" then
            coroutine.resume(co)
        end
    end
    register_callback("paint", step)
end
safe_init()
```


---

# 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, and the optional `goal` query parameter:

```
GET https://docs.kensohub.ru/instrukcii/demo-plagin.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
