подгрузка .txt и вывод в новое окно

Citrys

Участник
Автор темы
175
5
Версия MoonLoader
Другое
как сделать так, что при нажатии на imgui.Button, открывалось второе окно с нужным мне текстом, при этот текст загружался с GitHub (типо файл как .txt загружался и от туда в новое окно текст писался)
(вот пример чего-то подобного)

Lua:
function checkData()
    log('Проверка наличия файлов для работы скрипта')
    local bLibs = checklibs()
    if bLibs then
        lua_thread.create(function()
            createDirectory(getWorkingDirectory()..'\\BHelper')
            downloadFile('Устав ЦБ', getWorkingDirectory()..'\\BHelper\\Устав_ЦБ.txt', 'https://gitlab.com/uploads/-/system/personal_snippet/1978930/6b234161b85b07fdee8306e9e4b0fd11/%D0%A3%D1%81%D1%82%D0%B0%D0%B2_%D0%A6%D0%91.txt')
            while not doesFileExist(getWorkingDirectory()..'\\BHelper\\Устав_ЦБ.txt') do wait(0) end
            downloadFile('Кредитование', getWorkingDirectory()..'\\BHelper\\Кредитование.txt', 'https://gitlab.com/uploads/-/system/personal_snippet/1978930/889dbc2cc55e5c10b1f723c856e81800/%D0%9A%D1%80%D0%B5%D0%B4%D0%B8%D1%82%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5.txt')
            while not doesFileExist(getWorkingDirectory()..'\\BHelper\\Кредитование.txt') do wait(0) end
            downloadFile('Binds.png', getWorkingDirectory()..'\\BHelper\\binds.png', 'https://gitlab.com/uploads/-/system/personal_snippet/1978930/be6cc2e15f5ef2b34399c5d7a82aa3b6/binds.png')
            while not doesFileExist(getWorkingDirectory()..'\\BHelper\\binds.png') do wait(0) end
            bindsPng = imgui.CreateTextureFromFile('moonloader/BHelper/binds.png')
            downloadFile('Main.png', getWorkingDirectory()..'\\BHelper\\main.png', 'https://gitlab.com/uploads/-/system/personal_snippet/1978930/edd6b17cdd809bc687a7ab1482f2d13b/main.png')
            while not doesFileExist(getWorkingDirectory()..'\\BHelper\\main.png') do wait(0) end
            mainPng = imgui.CreateTextureFromFile('moonloader/BHelper/main.png')
            downloadFile('Кадр. система', getWorkingDirectory()..'\\BHelper\\Кадровая система.txt', 'https://gitlab.com/uploads/-/system/personal_snippet/1978930/6274f2bc275e2c6f7ca9d3f1a3f47053/%D0%9A%D0%B0%D0%B4%D1%80%D0%BE%D0%B2%D0%B0%D1%8F_%D1%81%D0%B8%D1%81%D1%82%D0%B5%D0%BC%D0%B0.txt')
            while not doesFileExist(getWorkingDirectory()..'\\BHelper\\Кадровая система.txt') do wait(0) end
        end)
        return true
    end
    bindsPng = imgui.CreateTextureFromFile('moonloader/BHelper/binds.png')
    mainPng = imgui.CreateTextureFromFile('moonloader/BHelper/main.png')
    return false
end

function checklibs()
    if not bFa or not bLfs or not bAddons or not bNotf then
        lua_thread.create(function()
            log('Подгрузка необходимых библиотек..')
            createDirectory(getWorkingDirectory()..'\\BHelper')
            createDirectory(getWorkingDirectory()..'\\resource\\fonts')
            downloadFile('fa-solid-900', getWorkingDirectory()..'\\resource\\fonts\\fa-solid-900.ttf', 'https://gitlab.com/uploads/-/system/personal_snippet/1978930/95884378224857885f0917483e9f73c2/fa-solid-900.ttf')
             while not doesFileExist(getWorkingDirectory()..'\\resource\\fonts\\fa-solid-900.ttf') do wait(0) end
             downloadFile('fAwesome5', getWorkingDirectory()..'\\lib\\fAwesome5.lua', 'https://gitlab.com/uploads/-/system/personal_snippet/1978930/02ce83c901aa017f6c2c706c41913a33/fAwesome5.lua')
            while not doesFileExist(getWorkingDirectory()..'\\lib\\fAwesome5.lua') do wait(0) end
            downloadFile('Notify 2.0', getWorkingDirectory()..'\\BHelper\\notify 2.0.lua', 'https://gitlab.com/uploads/-/system/personal_snippet/1978930/461fef60379cb4a4e182ed6fd998efdb/notify_2.0.lua')
            while not doesFileExist(getWorkingDirectory()..'\\BHelper\\notify 2.0.lua') do wait(0) end
            downloadFile('imgui_addons', getWorkingDirectory()..'\\lib\\imgui_addons.lua', 'https://gitlab.com/uploads/-/system/personal_snippet/1978930/4de4d446323a40abfa7689794e60adb8/imgui_addons.lua')
            while not doesFileExist(getWorkingDirectory()..'\\lib\\imgui_addons.lua') do wait(0) end
            downloadFile('lfs', getWorkingDirectory()..'\\lib\\lfs.dll', 'https://gitlab.com/uploads/-/system/personal_snippet/1978930/bb78870f18d0ecdab8edfff37d3f84b7/lfs.dll')
            while not doesFileExist(getWorkingDirectory()..'\\lib\\lfs.dll') do wait(0) end
            log('Подгрузка необходимых библиотек окончена. Перезагружаюсь..')
            noErrorDialog = true
            wait(1000)
            thisScript():reload()
        end)
        return false
    end
    return true
end

function downloadLections()
    createDirectory(getWorkingDirectory()..'\\BHelper\\Lections')
    downloadFile('Лекция: Внешний вид',                 getWorkingDirectory()..'\\BHelper\\Lections\\Внешний вид сотрудников.txt',             'https://gitlab.com/uploads/-/system/personal_snippet/1978930/679b2d6ec98190b68596a4f022d5e384/%D0%92%D0%BD%D0%B5%D1%88%D0%BD%D0%B8%D0%B9_%D0%B2%D0%B8%D0%B4_%D1%81%D0%BE%D1%82%D1%80%D1%83%D0%B4%D0%BD%D0%B8%D0%BA%D0%BE%D0%B2.txt')
    downloadFile('Лекция: Отлучение от дел',             getWorkingDirectory()..'\\BHelper\\Lections\\Временное отлучение от дел.txt',         'https://gitlab.com/uploads/-/system/personal_snippet/1978930/393ea47ec1ff4d0b72988685ee9cb23f/%D0%92%D1%80%D0%B5%D0%BC%D0%B5%D0%BD%D0%BD%D0%BE%D0%B5_%D0%BE%D1%82%D0%BB%D1%83%D1%87%D0%B5%D0%BD%D0%B8%D0%B5_%D0%BE%D1%82_%D0%B4%D0%B5%D0%BB.txt')
    downloadFile('Лекция: Обращение со старшими',         getWorkingDirectory()..'\\BHelper\\Lections\\Обращение со старшими.txt',             'https://gitlab.com/uploads/-/system/personal_snippet/1978930/f40ceaba851c01b6beb1dad8dcd74b56/%D0%9E%D0%B1%D1%80%D0%B0%D1%89%D0%B5%D0%BD%D0%B8%D0%B5_%D1%81%D0%BE_%D1%81%D1%82%D0%B0%D1%80%D1%88%D0%B8%D0%BC%D0%B8.txt')
    downloadFile('Лекция: Правила Банка',                 getWorkingDirectory()..'\\BHelper\\Lections\\Правила нашего банка.txt',             'https://gitlab.com/uploads/-/system/personal_snippet/1978930/067f3be8503724074fcd0738ae52a7ec/%D0%9F%D1%80%D0%B0%D0%B2%D0%B8%D0%BB%D0%B0_%D0%BD%D0%B0%D1%88%D0%B5%D0%B3%D0%BE_%D0%B1%D0%B0%D0%BD%D0%BA%D0%B0.txt')
    downloadFile('Лекция: Поведение при теракте',         getWorkingDirectory()..'\\BHelper\\Lections\\Правила поведения при теракте.txt',     'https://gitlab.com/uploads/-/system/personal_snippet/1978930/60b709983d9d30ae203a6d5c84b1029e/%D0%9F%D1%80%D0%B0%D0%B2%D0%B8%D0%BB%D0%B0_%D0%BF%D0%BE%D0%B2%D0%B5%D0%B4%D0%B5%D0%BD%D0%B8%D1%8F_%D0%BF%D1%80%D0%B8_%D1%82%D0%B5%D1%80%D0%B0%D0%BA%D1%82%D0%B5.txt')
    downloadFile('Лекция: Причастность к криминалу',     getWorkingDirectory()..'\\BHelper\\Lections\\Причастность к криминалу.txt',         'https://gitlab.com/uploads/-/system/personal_snippet/1978930/a5b674e13218e9e58e02a09bccd51dc1/%D0%9F%D1%80%D0%B8%D1%87%D0%B0%D1%81%D1%82%D0%BD%D0%BE%D1%81%D1%82%D1%8C_%D0%BA_%D0%BA%D1%80%D0%B8%D0%BC%D0%B8%D0%BD%D0%B0%D0%BB%D1%83.txt')
end


Lua:
    if ustav_window.v then
        local xx, yy = getScreenResolution()
        imgui.SetNextWindowSize(imgui.ImVec2(xx / 1.5, yy / 1.5), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowPos(imgui.ImVec2(xx / 2, yy / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.Begin(u8'Устав Центрального Банка', ustav_window, imgui.WindowFlags.NoCollapse + imgui.WindowFlags.NoScrollbar)
           
            imgui.SetCursorPosX((imgui.GetWindowWidth() - 200) / 2)
            imgui.PushItemWidth(200)
            imgui.PushAllowKeyboardFocus(false)
            imgui.InputText("##search_ustav", search_ustav, imgui.InputTextFlags.EnterReturnsTrue)
            imgui.PopAllowKeyboardFocus()
            imgui.PopItemWidth()
            if not imgui.IsItemActive() and #search_ustav.v == 0 then
                imgui.SameLine((imgui.GetWindowWidth() - imgui.CalcTextSize(fa.ICON_FA_SEARCH..u8(' Поиск по уставу')).x) / 2)
                imgui.TextColored(imgui.ImVec4(0.5, 0.5, 0.5, 1), fa.ICON_FA_SEARCH..u8(' Поиск по уставу'))
            end
            imgui.CenterTextColoredRGB('{868686}Двойной клик по строке, выведет её в поле ввода в чате')
            imgui.Separator()
            local ustav = io.open("moonloader/BHelper/Устав_ЦБ.txt", "r+")
            for line in ustav:lines() do
                if #search_ustav.v < 1 then
                    imgui.TextWrapped(u8(line))
                    imgui.Hint(u8'Кликните дважды, что бы скопировать строку в чат', 2)
                    if imgui.IsItemHovered() and imgui.IsMouseDoubleClicked(0) then
                        sampSetChatInputEnabled(true)
                        sampSetChatInputText(line)
                    end
                else
                    if string.rlower(line):find(string.rlower(u8:decode(search_ustav.v))) then
                        imgui.TextWrapped(u8(line))
                        imgui.Hint(u8'Кликните дважды, что бы скопировать строку в чат', 2)
                        if imgui.IsItemHovered() and imgui.IsMouseDoubleClicked(0) then
                            sampSetChatInputEnabled(true)
                            sampSetChatInputText(line)
                        end
                    end
                end
            end
            ustav:close()
        imgui.End()
    end
 
Последнее редактирование:

Manuel Leon

Известный
266
166
Активацию 1 окна сам добавь

Lua:
local window1 = imgui.ImBool(false)    -- 1 окно
local window2 = imgui.ImBool(false) -- 2 окно

function main()
    while not isSampAvailable() do wait(100) end
    repeat wait(0) until sampIsLocalPlayerSpawned()

    if not doesFileExist(getWorkingDirectory()..'путь.txt') then -- если файла нет, то скачаем
        downloadFile('название', getWorkingDirectory()..'путь.txt','ссылка на txt')
    end

    local File = io.open(getWorkingDirectory()..'путь.txt',"r") -- открываем файл
    local FileText = {} -- таблица для заноса текста
    for line in File:lines() do -- для строк из файла
        table.insert( FileText, line) -- заносим строку в таблицу
    end
    File:close() -- закрываем файл

    while true do
    wait(0)
         imgui.Process = window1.v or window2.v
    end
end



function imgui.OnDrawFrame()
    if window1.v then
        imgui.Begin('Window1', window1)
            if imgui.Button('название',imgui.ImVec2(100,40)) then -- если кнопка нажата открываем/закрываем 2 окно
                window2.v = not window2.v
            end
        imgui.End()
    end
    if window2.v then -- если 2 окно открыто
    imgui.Begin('Window2', window2)
        for k,v in ipairs(FileText) do -- для ключа, значения в таблице FileText
            imgui.Text(v) -- делаем imgui Text со значением
        end
    imgui.End()
    end
end
 
Последнее редактирование:
  • Нравится
Реакции: Citrys

Citrys

Участник
Автор темы
175
5
Активацию 1 окна сам добавь

Lua:
local window1 = imgui.ImBool(false)    -- 1 окно
local window2 = imgui.ImBool(false) -- 2 окно

function main()
    while not isSampAvailable() do wait(100) end
    repeat wait(0) until sampIsLocalPlayerSpawned()

    if not doesFileExist(getWorkingDirectory()..'путь.txt') then -- если файла нет, то скачаем
        downloadFile('название', getWorkingDirectory()..'путь.txt','ссылка на txt')
    end

    local File = io.open(getWorkingDirectory()..'путь.txt',"r") -- открываем файл
    local FileText = {} -- таблица для заноса текста
    for line in File:lines() do -- для строк из файла
        table.insert( FileText, line) -- заносим строку в таблицу
    end
    File:close() -- закрываем файл

    while true do
    wait(0)
         imgui.Process = window1.v or window2.v
    end
end



function imgui.OnDrawFrame()
    if window1.v then
        imgui.Begin('Window1', window1)
            if imgui.Button('название',imgui.ImVec2(100,40)) then -- если кнопка нажата открываем/закрываем 2 окно
                window2.v = not window2.v
            end
        imgui.End()
    end
    if window2.v then -- если 2 окно открыто
    imgui.Begin('Window2', window2)
        for k,v in ipairs(FileText) do -- для ключа, значения в таблице FileText
            imgui.Text(v) -- делаем imgui Text со значением
        end
    imgui.End()
    end
end
ссылку для скачки .txt нужно брать с GitHub или чего то подобного?
 

Citrys

Участник
Автор темы
175
5
if not doesFileExist(getWorkingDirectory()..'путь.txt') then -- если файла нет, то скачаем downloadFile('название', getWorkingDirectory()..'путь.txt','ссылка на txt') end
путь .txt - сюда ссылку с GitHub, или путь к созданной папке moonloader
ссылка на .txt - тот же самый вопрос
 

Manuel Leon

Известный
266
166
путь .txt - сюда ссылку с GitHub, или путь к созданной папке moonloader
ссылка на .txt - тот же самый вопрос
Пример:
Lua:
if not doesFileExist(getWorkingDirectory()..'\\test.txt') then -- Скачает файл в папку moonloader
    downloadUrlToFile('https://github.com/Kaster31/MoonloaderLib/releases/download/Tests/test.txt', getWorkingDirectory()..'\\test.txt')
end
Функция downloadFile не работает чёт у меня, может самописная использовалась в коде, откуда ты это брал
 

Citrys

Участник
Автор темы
175
5
Пример:
Lua:
if not doesFileExist(getWorkingDirectory()..'\\test.txt') then -- Скачает файл в папку moonloader
    downloadUrlToFile('https://github.com/Kaster31/MoonloaderLib/releases/download/Tests/test.txt', getWorkingDirectory()..'\\test.txt')
end
Функция downloadFile не работает чёт у меня, может самописная использовалась в коде, откуда ты это брал
из одного хелпера, код был Компилирован, я его декомпилировал, может из-за этого?

слушай, а не мог бы ты пожалуйста написать код который загружает файл из GitHub, при этом создает папку в папке moonloader, и этот файл с gitHub загружает в новую созданную папку надеюсь это не звучит слишком нагло и дерзко, надеюсь поможешь)
 

Manuel Leon

Известный
266
166
из одного хелпера, код был Компилирован, я его декомпилировал, может из-за этого?

слушай, а не мог бы ты пожалуйста написать код который загружает файл из GitHub, при этом создает папку в папке moonloader, и этот файл с gitHub загружает в новую созданную папку надеюсь это не звучит слишком нагло и дерзко, надеюсь поможешь)
Lua:
if not doesDirectoryExist(getWorkingDirectory() .. "/TestPapka/") then
    createDirectory(getWorkingDirectory() .. "/TestPapka/")
end
if not doesFileExist(getWorkingDirectory() .. "/TestPapka/test.txt") then
    downloadUrlToFile(https://github.com/Kaster31/MoonloaderLib/releases/download/Tests/test.txt, getWorkingDirectory().."/TestPapka/test.txt")
end
 

Citrys

Участник
Автор темы
175
5
Lua:
if not doesDirectoryExist(getWorkingDirectory() .. "/TestPapka/") then
    createDirectory(getWorkingDirectory() .. "/TestPapka/")
end
if not doesFileExist(getWorkingDirectory() .. "/TestPapka/test.txt") then
    downloadUrlToFile(https://github.com/Kaster31/MoonloaderLib/releases/download/Tests/test.txt, getWorkingDirectory().."/TestPapka/test.txt")
end
может есть какой-то local или function? или же function mai и есть та самая функция?
 

Manuel Leon

Известный
266
166
я имел в виду, нужно писать новую отдельную функцию, или просто данные строки написать в функции main?
В main можешь засунуть, можешь над main'ом . Если ты про это:
Lua:
if not doesDirectoryExist(getWorkingDirectory() .. "/TestPapka/") then
    createDirectory(getWorkingDirectory() .. "/TestPapka/")
end
if not doesFileExist(getWorkingDirectory() .. "/TestPapka/test.txt") then
    downloadUrlToFile(https://github.com/Kaster31/MoonloaderLib/releases/download/Tests/test.txt, getWorkingDirectory().."/TestPapka/test.txt")
end
В main можешь засунуть, можешь над main'ом . Если ты про это:
Только не в бесконечный цикл
 

Citrys

Участник
Автор темы
175
5
может есть какой-то local или function? или же function mai и есть та самая функция?
В main можешь засунуть, можешь над main'ом . Если ты про это:


Только не в бесконечный цикл
папка создается, текстовый документ не загружается