Помощь по заметкам(шпорам)

W1ll04eison

Участник
Автор темы
328
19
Версия MoonLoader
.026-beta
1) Как сделать поиск слова в заметке

2)Как сделать обращение к определенной строке в блокноте(шпоре, т.е что бы я мог нажать на определенную строку и она выводилась в чат

Код:

Lua:
require "lib.moonloader"
local encoding = require "encoding"
local inicfg = require "inicfg"
local directIni = "moonloader\\Note.ini"
local sampev = require "lib.samp.events"
local imgui = require "imgui"
local fa = require 'fAwesome5'
imgui.ToggleButton = require('imgui_addons').ToggleButton
encoding.default = 'CP1251'
u8 = encoding.UTF8

if not doesFileExist("moonloader\\Note.ini") then
    file = io.open("moonloader\\Note.ini", "w+")
    file:close()
end

local mainIni = inicfg.load({}, directIni)
local show_input = false

function apply_custom_style()
     imgui.SwitchContext()
     local style = imgui.GetStyle()
     local colors = style.Colors
     local clr = imgui.Col
     local ImVec4 = imgui.ImVec4
     style.WindowRounding = 2.0
     style.WindowTitleAlign = imgui.ImVec2(0.5, 0.84)
     style.ChildWindowRounding = 2.0
     style.FrameRounding = 2.0
     style.ItemSpacing = imgui.ImVec2(5.0, 4.0)
     style.ScrollbarSize = 13.0
     style.ScrollbarRounding = 0
     style.GrabMinSize = 8.0
     style.GrabRounding = 1.0
     colors[clr.FrameBg]                = ImVec4(0.16, 0.29, 0.48, 0.54)
     colors[clr.FrameBgHovered]         = ImVec4(0.26, 0.59, 0.98, 0.40)
     colors[clr.FrameBgActive]          = ImVec4(0.26, 0.59, 0.98, 0.67)
     colors[clr.TitleBg]                = ImVec4(0.04, 0.04, 0.04, 1.00)
     colors[clr.TitleBgActive]          = ImVec4(0.16, 0.29, 0.48, 1.00)
     colors[clr.TitleBgCollapsed]       = ImVec4(0.00, 0.00, 0.00, 0.51)
     colors[clr.CheckMark]              = ImVec4(0.26, 0.59, 0.98, 1.00)
     colors[clr.SliderGrab]             = ImVec4(0.24, 0.52, 0.88, 1.00)
     colors[clr.SliderGrabActive]       = ImVec4(0.26, 0.59, 0.98, 1.00)
     colors[clr.Button]                 = ImVec4(0.26, 0.59, 0.98, 0.40)
     colors[clr.ButtonHovered]          = ImVec4(0.26, 0.59, 0.98, 1.00)
     colors[clr.ButtonActive]           = ImVec4(0.06, 0.53, 0.98, 1.00)
     colors[clr.Header]                 = ImVec4(0.26, 0.59, 0.98, 0.31)
     colors[clr.HeaderHovered]          = ImVec4(0.26, 0.59, 0.98, 0.80)
     colors[clr.HeaderActive]           = ImVec4(0.26, 0.59, 0.98, 1.00)
     colors[clr.Separator]              = colors[clr.Border]
     colors[clr.SeparatorHovered]       = ImVec4(0.26, 0.59, 0.98, 0.78)
     colors[clr.SeparatorActive]        = ImVec4(0.26, 0.59, 0.98, 1.00)
     colors[clr.ResizeGrip]             = ImVec4(0.26, 0.59, 0.98, 0.25)
     colors[clr.ResizeGripHovered]      = ImVec4(0.26, 0.59, 0.98, 0.67)
     colors[clr.ResizeGripActive]       = ImVec4(0.26, 0.59, 0.98, 0.95)
     colors[clr.TextSelectedBg]         = ImVec4(0.26, 0.59, 0.98, 0.35)
     colors[clr.Text]                   = ImVec4(1.00, 1.00, 1.00, 1.00)
     colors[clr.TextDisabled]           = ImVec4(0.50, 0.50, 0.50, 1.00)
     colors[clr.WindowBg]               = ImVec4(0.06, 0.06, 0.06, 0.94)
     colors[clr.ChildWindowBg]          = ImVec4(1.00, 1.00, 1.00, 0.00)
     colors[clr.PopupBg]                = ImVec4(0.08, 0.08, 0.08, 0.94)
     colors[clr.ComboBg]                = colors[clr.PopupBg]
     colors[clr.Border]                 = ImVec4(0.43, 0.43, 0.50, 0.50)
     colors[clr.BorderShadow]           = ImVec4(0.00, 0.00, 0.00, 0.00)
     colors[clr.MenuBarBg]              = ImVec4(0.14, 0.14, 0.14, 1.00)
     colors[clr.ScrollbarBg]            = ImVec4(0.02, 0.02, 0.02, 0.53)
     colors[clr.ScrollbarGrab]          = ImVec4(0.31, 0.31, 0.31, 1.00)
     colors[clr.ScrollbarGrabHovered]   = ImVec4(0.41, 0.41, 0.41, 1.00)
     colors[clr.ScrollbarGrabActive]    = ImVec4(0.51, 0.51, 0.51, 1.00)
     colors[clr.CloseButton]            = ImVec4(0.41, 0.41, 0.41, 0.50)
     colors[clr.CloseButtonHovered]     = ImVec4(0.98, 0.39, 0.36, 1.00)
     colors[clr.CloseButtonActive]      = ImVec4(0.98, 0.39, 0.36, 1.00)
     colors[clr.PlotLines]              = ImVec4(0.61, 0.61, 0.61, 1.00)
     colors[clr.PlotLinesHovered]       = ImVec4(1.00, 0.43, 0.35, 1.00)
     colors[clr.PlotHistogram]          = ImVec4(0.90, 0.70, 0.00, 1.00)
     colors[clr.PlotHistogramHovered]   = ImVec4(1.00, 0.60, 0.00, 1.00)
     colors[clr.ModalWindowDarkening]   = ImVec4(0.80, 0.80, 0.80, 0.35)
end
apply_custom_style()

sampRegisterChatCommand("note", function()
    imgui_active.v = not imgui_active.v
    imgui.Process = imgui_active.v
end)

imgui_active = imgui.ImBool(false)
local w, h = getScreenResolution()

local slot = 0

local name = imgui.ImBuffer(50)
local text1 = imgui.ImBuffer(65536)

local fa_font = nil
local fa_glyph_ranges = imgui.ImGlyphRanges({ fa.min_range, fa.max_range })
function imgui.BeforeDrawFrame()
    if fa_font == nil then
        local font_config = imgui.ImFontConfig()
        font_config.MergeMode = true
        fa_font = imgui.GetIO().Fonts:AddFontFromFileTTF('moonloader/resource/fonts/fa-solid-900.ttf', 13.0, font_config, fa_glyph_ranges)
    end
end

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then
        return
    end
    while not isSampAvailable() do
        wait(100)
    end
    wait(-1)
end

function imgui.OnDrawFrame()
    if imgui_active.v then
        imgui.SetNextWindowSize(imgui.ImVec2(750, 500), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowPos(imgui.ImVec2(w / 2, h / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.Begin(u8" Заметки", imgui_active, imgui.WindowFlags.NoResize)
        imgui.BeginChild("", imgui.ImVec2(150, 440), true)
        if #mainIni ~= 0 then
            for i = 1, #mainIni do
                if imgui.Selectable(u8(mainIni[i].name)) then
                    name.v = u8(mainIni[i].name)
                    text1.v = string.gsub(u8(mainIni[i].text1), "&", "\n")
                    slot = i
                end
            end
        else
            imgui.Text(u8"Тут пока ничего нет")
        end
        imgui.EndChild()
        imgui.SameLine()
        imgui.BeginChild(" ", imgui.ImVec2(579, 464), true)
        if slot ~= 0 then
            imgui.Text(u8"Название:")
            imgui.SameLine()
            if show_input then
                imgui.PushItemWidth(150)
                imgui.InputText(u8"", name)
            else
                imgui.Text(name.v)
            end
            if imgui.Button(u8" Редактировать", imgui.ImVec2(110, 20)) then
                show_input = true
                inicfg.save(mainIni, directIni)
            end
            imgui.SameLine()
            if imgui.Button(u8" Сохранить", imgui.ImVec2(125, 20)) then
                mainIni[slot].name = u8:decode(name.v)
                mainIni[slot].text1 = string.gsub(u8:decode(text1.v), "\n", "&")
                show_input = false
                inicfg.save(mainIni, directIni)
                sampAddChatMessage('{FFFFFF}Заметка "' .. u8:decode(name.v) .. '" сохранена.', 0x3399FF)
            end
            imgui.SameLine()
            if imgui.Button(u8" Удалить", imgui.ImVec2(125, 20)) then
                local kol = 0
                for k, v in pairs(mainIni) do
                    kol = kol + 1
                end
                if kol ~= 1 then
                    table.remove(mainIni, slot)
                    inicfg.save(mainIni, directIni)
                else
                    table.remove(mainIni, slot)
                    file = io.open("moonloader\\Note.ini", "w+")
                    file:close()
                end
                sampAddChatMessage('{FFFFFF}Заметка {FFE4B5}"' .. u8:decode(name.v) .. '" {FF0000}удалена.', 0x8A2BE2)
                slot = 0
            end
            if show_input then
                imgui.InputTextMultiline("    ", text1, imgui.ImVec2(562, 423))
            else
                imgui.Text(text1.v)
            end

        end
        imgui.EndChild()
        imgui.SetCursorPosY(475)
        if imgui.Button("+") then
            local tname = "Заметка № " .. #mainIni+1
            for k,v in pairs(mainIni) do
                if mainIni[k].name == tname then
                    tname = tname .. " (1)"
                end
            end
            table.insert(mainIni,{
            name=tname,
            text1="",})
            inicfg.save(mainIni, directIni)
        end
        imgui.End()
    else
        imgui.Process = false
    end
end
 
Последнее редактирование:
Решение
Чекай
Lua:
require "lib.moonloader"
local encoding = require "encoding"
local inicfg = require "inicfg"
local directIni = "moonloader\\Note.ini"
local sampev = require "lib.samp.events"
local imgui = require "imgui"
local fa = require 'fAwesome5'
local input = imgui.ImBuffer(256)
imgui.ToggleButton = require('imgui_addons').ToggleButton
encoding.default = 'CP1251'
u8 = encoding.UTF8

if not doesFileExist("moonloader\\Note.ini") then
    file = io.open("moonloader\\Note.ini", "w+")
    file:close()
end

local mainIni = inicfg.load({}, directIni)
local show_input = false

function apply_custom_style()
     imgui.SwitchContext()
     local style = imgui.GetStyle()
     local colors = style.Colors
     local clr = imgui.Col
     local ImVec4...

Adrian G.

Известный
Проверенный
520
457
Чекай
Lua:
require "lib.moonloader"
local encoding = require "encoding"
local inicfg = require "inicfg"
local directIni = "moonloader\\Note.ini"
local sampev = require "lib.samp.events"
local imgui = require "imgui"
local fa = require 'fAwesome5'
local input = imgui.ImBuffer(256)
imgui.ToggleButton = require('imgui_addons').ToggleButton
encoding.default = 'CP1251'
u8 = encoding.UTF8

if not doesFileExist("moonloader\\Note.ini") then
    file = io.open("moonloader\\Note.ini", "w+")
    file:close()
end

local mainIni = inicfg.load({}, directIni)
local show_input = false

function apply_custom_style()
     imgui.SwitchContext()
     local style = imgui.GetStyle()
     local colors = style.Colors
     local clr = imgui.Col
     local ImVec4 = imgui.ImVec4
     style.WindowRounding = 2.0
     style.WindowTitleAlign = imgui.ImVec2(0.5, 0.84)
     style.ChildWindowRounding = 2.0
     style.FrameRounding = 2.0
     style.ItemSpacing = imgui.ImVec2(5.0, 4.0)
     style.ScrollbarSize = 13.0
     style.ScrollbarRounding = 0
     style.GrabMinSize = 8.0
     style.GrabRounding = 1.0
     colors[clr.FrameBg]                = ImVec4(0.16, 0.29, 0.48, 0.54)
     colors[clr.FrameBgHovered]         = ImVec4(0.26, 0.59, 0.98, 0.40)
     colors[clr.FrameBgActive]          = ImVec4(0.26, 0.59, 0.98, 0.67)
     colors[clr.TitleBg]                = ImVec4(0.04, 0.04, 0.04, 1.00)
     colors[clr.TitleBgActive]          = ImVec4(0.16, 0.29, 0.48, 1.00)
     colors[clr.TitleBgCollapsed]       = ImVec4(0.00, 0.00, 0.00, 0.51)
     colors[clr.CheckMark]              = ImVec4(0.26, 0.59, 0.98, 1.00)
     colors[clr.SliderGrab]             = ImVec4(0.24, 0.52, 0.88, 1.00)
     colors[clr.SliderGrabActive]       = ImVec4(0.26, 0.59, 0.98, 1.00)
     colors[clr.Button]                 = ImVec4(0.26, 0.59, 0.98, 0.40)
     colors[clr.ButtonHovered]          = ImVec4(0.26, 0.59, 0.98, 1.00)
     colors[clr.ButtonActive]           = ImVec4(0.06, 0.53, 0.98, 1.00)
     colors[clr.Header]                 = ImVec4(0.26, 0.59, 0.98, 0.31)
     colors[clr.HeaderHovered]          = ImVec4(0.26, 0.59, 0.98, 0.80)
     colors[clr.HeaderActive]           = ImVec4(0.26, 0.59, 0.98, 1.00)
     colors[clr.Separator]              = colors[clr.Border]
     colors[clr.SeparatorHovered]       = ImVec4(0.26, 0.59, 0.98, 0.78)
     colors[clr.SeparatorActive]        = ImVec4(0.26, 0.59, 0.98, 1.00)
     colors[clr.ResizeGrip]             = ImVec4(0.26, 0.59, 0.98, 0.25)
     colors[clr.ResizeGripHovered]      = ImVec4(0.26, 0.59, 0.98, 0.67)
     colors[clr.ResizeGripActive]       = ImVec4(0.26, 0.59, 0.98, 0.95)
     colors[clr.TextSelectedBg]         = ImVec4(0.26, 0.59, 0.98, 0.35)
     colors[clr.Text]                   = ImVec4(1.00, 1.00, 1.00, 1.00)
     colors[clr.TextDisabled]           = ImVec4(0.50, 0.50, 0.50, 1.00)
     colors[clr.WindowBg]               = ImVec4(0.06, 0.06, 0.06, 0.94)
     colors[clr.ChildWindowBg]          = ImVec4(1.00, 1.00, 1.00, 0.00)
     colors[clr.PopupBg]                = ImVec4(0.08, 0.08, 0.08, 0.94)
     colors[clr.ComboBg]                = colors[clr.PopupBg]
     colors[clr.Border]                 = ImVec4(0.43, 0.43, 0.50, 0.50)
     colors[clr.BorderShadow]           = ImVec4(0.00, 0.00, 0.00, 0.00)
     colors[clr.MenuBarBg]              = ImVec4(0.14, 0.14, 0.14, 1.00)
     colors[clr.ScrollbarBg]            = ImVec4(0.02, 0.02, 0.02, 0.53)
     colors[clr.ScrollbarGrab]          = ImVec4(0.31, 0.31, 0.31, 1.00)
     colors[clr.ScrollbarGrabHovered]   = ImVec4(0.41, 0.41, 0.41, 1.00)
     colors[clr.ScrollbarGrabActive]    = ImVec4(0.51, 0.51, 0.51, 1.00)
     colors[clr.CloseButton]            = ImVec4(0.41, 0.41, 0.41, 0.50)
     colors[clr.CloseButtonHovered]     = ImVec4(0.98, 0.39, 0.36, 1.00)
     colors[clr.CloseButtonActive]      = ImVec4(0.98, 0.39, 0.36, 1.00)
     colors[clr.PlotLines]              = ImVec4(0.61, 0.61, 0.61, 1.00)
     colors[clr.PlotLinesHovered]       = ImVec4(1.00, 0.43, 0.35, 1.00)
     colors[clr.PlotHistogram]          = ImVec4(0.90, 0.70, 0.00, 1.00)
     colors[clr.PlotHistogramHovered]   = ImVec4(1.00, 0.60, 0.00, 1.00)
     colors[clr.ModalWindowDarkening]   = ImVec4(0.80, 0.80, 0.80, 0.35)
end
apply_custom_style()

sampRegisterChatCommand("note", function()
    imgui_active.v = not imgui_active.v
    imgui.Process = imgui_active.v
end)

imgui_active = imgui.ImBool(false)
local w, h = getScreenResolution()

local slot = 0

local name = imgui.ImBuffer(50)
local text1 = imgui.ImBuffer(65536)

local fa_font = nil
local fa_glyph_ranges = imgui.ImGlyphRanges({ fa.min_range, fa.max_range })
function imgui.BeforeDrawFrame()
    if fa_font == nil then
        local font_config = imgui.ImFontConfig()
        font_config.MergeMode = true
        fa_font = imgui.GetIO().Fonts:AddFontFromFileTTF('moonloader/resource/fonts/fa-solid-900.ttf', 13.0, font_config, fa_glyph_ranges)
    end
end

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then
        return
    end
    while not isSampAvailable() do
        wait(100)
    end
    wait(-1)
end

function imgui.OnDrawFrame()
    if imgui_active.v then
        imgui.SetNextWindowSize(imgui.ImVec2(750, 500), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowPos(imgui.ImVec2(w / 2, h / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.Begin(u8" Заметки", imgui_active, imgui.WindowFlags.NoResize)
        imgui.BeginChild("", imgui.ImVec2(150, 440), true)
        if #mainIni ~= 0 then
            for i = 1, #mainIni do
                if imgui.Selectable(u8(mainIni[i].name)) then
                    name.v = u8(mainIni[i].name)
                    text1.v = string.gsub(u8(mainIni[i].text1), "&", "\n")
                    slot = i
                end
            end
        else
            imgui.Text(u8"Тут пока ничего нет")
        end
        imgui.EndChild()
        imgui.SameLine()
        imgui.BeginChild(" ", imgui.ImVec2(579, 464), true)
        if slot ~= 0 then
            imgui.Text(u8"Название:")
            imgui.SameLine()
            if show_input then
                imgui.PushItemWidth(150)
                imgui.InputText(u8"", name)
            else
                imgui.Text(name.v)
            end
            
            
            
                
            
            
            if imgui.Button(u8" Редактировать", imgui.ImVec2(110, 20)) then
                show_input = true
                inicfg.save(mainIni, directIni)
            end
            imgui.SameLine()
            if imgui.Button(u8" Сохранить", imgui.ImVec2(125, 20)) then
                mainIni[slot].name = u8:decode(name.v)
                mainIni[slot].text1 = string.gsub(u8:decode(text1.v), "\n", "&")
                show_input = false
                inicfg.save(mainIni, directIni)
                sampAddChatMessage('{FFFFFF}Заметка "' .. u8:decode(name.v) .. '" сохранена.', 0x3399FF)
            end
            imgui.SameLine()
            if imgui.Button(u8" Удалить", imgui.ImVec2(125, 20)) then
                local kol = 0
                for k, v in pairs(mainIni) do
                    kol = kol + 1
                end
                if kol ~= 1 then
                    table.remove(mainIni, slot)
                    inicfg.save(mainIni, directIni)
                else
                    table.remove(mainIni, slot)
                    file = io.open("moonloader\\Note.ini", "w+")
                    file:close()
                end
                sampAddChatMessage('{FFFFFF}Заметка {FFE4B5}"' .. u8:decode(name.v) .. '" {FF0000}удалена.', 0x8A2BE2)
                slot = 0
            end
            if not show_input then
            imgui.InputText(u8'Поиск', input)
            end

            if input.v ~= '' then
                for line in text1.v:gmatch('[^\r\n]+') do
                    
                    if line:find(input.v) then
                        imgui.PushStyleColor(imgui.Col.HeaderHovered, 0)
                        imgui.PushStyleColor(imgui.Col.HeaderActive, 0)
                        imgui.PushStyleColor(imgui.Col.Header, 0)
                        if imgui.Selectable(line) then
                            
                            tekst = u8:decode(line):match('^[%s]+(.+)$')
                            if tekst ~= nil then
                                sampAddChatMessage(tekst, -1)
                            else
                                sampAddChatMessage(u8:decode(line), -1)
                            end
                        end
                        imgui.PopStyleColor(3)
                    end
                end
            else
                if not show_input then
                imgui.Text(text1.v)
                end
            end

            if show_input then
                imgui.InputTextMultiline("    ", text1, imgui.ImVec2(562, 423))
            --else
                --imgui.Text(text1.v)
            end

        end
        imgui.EndChild()
        imgui.SetCursorPosY(475)
        if imgui.Button("+") then
            local tname = "Заметка № " .. #mainIni+1
            for k,v in pairs(mainIni) do
                if mainIni[k].name == tname then
                    tname = tname .. " (1)"
                end
            end
            table.insert(mainIni,{
            name=tname,
            text1="",})
            inicfg.save(mainIni, directIni)
        end
        imgui.End()
    else
        imgui.Process = false
    end
end
 
  • Нравится
Реакции: W1ll04eison