Почему багается mimgui

.KOHTOP.

Активный
Автор темы
226
35
Версия MoonLoader
.027.0-preview
1708611807511.png

Это когда делаю в main после запуска u8('Русский текст')

1708611836623.png


Это если English

Lua:
local bit                         = require 'bit'
require 'moonloader'
local inicfg                    = require 'inicfg'
local vkeys                        = require 'vkeys'
local ffi                         = require 'ffi'

local encodingcheck, encoding    = pcall(require, 'encoding')
local imguicheck, imgui            = pcall(require, 'mimgui')
local monetluacheck, monetlua     = pcall(require, 'MoonMonet')
local lfscheck, lfs             = pcall(require, 'lfs')
local sampevcheck, sampev        = pcall(require, 'lib.samp.events')

local faicons = require('fAwesome6')

local tag = '{ffbb00}[AdminTools]: '
local print, clock, sin, cos, floor, ceil, abs, format, gsub, gmatch, find, char, len, upper, lower, sub, u8, new, str, sizeof = print, os.clock, math.sin, math.cos, math.floor, math.ceil, math.abs, string.format, string.gsub, string.gmatch, string.find, string.char, string.len, string.upper, string.lower, string.sub, encoding.UTF8, imgui.new, ffi.string, ffi.sizeof


local notf_sX, notf_sY                = convertGameScreenCoordsToWindowScreenCoords(605, 438)
local notify                        = {
    msg = {},
    pos = {x = notf_sX - 500, y = notf_sY - 70}
}
notf_sX, notf_sY = nil, nil

function main()
    while not isSampAvailable() do wait(0) end
        addNotify(u8'Хеллоу', 3)
    while true do
        wait(0)
        
    end
end


local imgui_notify = imgui.OnFrame(
    function() return true end,
    function(player)
        player.HideCursor = true
        for k = 1, #notify.msg do
            if notify.msg[k] and notify.msg[k].active then
                local i = -1
                for d in gmatch(notify.msg[k].text, '[^\n]+') do
                    i = i + 1
                end
                if notify.pos.y - i * 21 > 0 then
                    if notify.msg[k].justshowed == nil then
                        notify.msg[k].justshowed = clock() - 0.05
                    end
                    if ceil(notify.msg[k].justshowed + notify.msg[k].time - clock()) <= 0 then
                        notify.msg[k].active = false
                    end
                    imgui.SetNextWindowPos(imgui.ImVec2(notify.pos.x, notify.pos.y - i * 21))
                    imgui.SetNextWindowSize(imgui.ImVec2(250, 60 + i * 21))
                    if clock() - notify.msg[k].justshowed < 0.3 then
                        imgui.PushStyleVarFloat(imgui.StyleVar.Alpha, ImSaturate((clock() - notify.msg[k].justshowed) * 3.34))
                    else
                        imgui.PushStyleVarFloat(imgui.StyleVar.Alpha, ImSaturate((notify.msg[k].justshowed + notify.msg[k].time - clock()) * 3.34))
                    end
                    imgui.PushStyleVarFloat(imgui.StyleVar.WindowBorderSize, 0)
                    imgui.Begin(u8('Notify ##'..k), _, imgui.WindowFlags.NoTitleBar + imgui.WindowFlags.NoResize + imgui.WindowFlags.NoMove + imgui.WindowFlags.NoScrollbar)
                        local style = imgui.GetStyle()
                        local pos = imgui.GetCursorScreenPos()
                        local DrawList = imgui.GetWindowDrawList()
                        DrawList:PathClear()
    
                        local num_segments = 80
                        local step = 6.28 / num_segments
                        local max = 6.28 * (1 - ((clock() - notify.msg[k].justshowed) / notify.msg[k].time))
                        local centre = imgui.ImVec2(pos.x + 15, pos.y + 15 + style.FramePadding.y)
    
                        for i = 0, max, step do
                            DrawList:PathLineTo(imgui.ImVec2(centre.x + 15 * cos(i), centre.y + 15 * sin(i)))
                        end
                        DrawList:PathStroke(imgui.ColorConvertFloat4ToU32(imgui.GetStyle().Colors[imgui.Col.TitleBgActive]), false, 5)
    
                        imgui.SetCursorPos(imgui.ImVec2(23 - imgui.CalcTextSize(u8(abs(ceil(notify.msg[k].time - (clock() - notify.msg[k].justshowed))))).x * 0.5, 19))
                        imgui.Text(tostring(abs(ceil(notify.msg[k].time - (clock() - notify.msg[k].justshowed)))))
    
                        imgui.PushFont(font)
                        imgui.SetCursorPos(imgui.ImVec2(105, 10))
                        imgui.TextColoredRGB('AdminTools')
                        imgui.PopFont()

                        imgui.SetCursorPosX(60)
                        imgui.BeginGroup()
                            imgui.Text(notify.msg[k].text)
                        imgui.EndGroup()
                    imgui.End()
                    imgui.PopStyleVar(2)
                    notify.pos.y = notify.pos.y - 70 - i * 21
                else
                    if k == 1 then
                        table.remove(notify.msg, k)
                    end
                end
            else
                table.remove(notify.msg, k)
            end
        end
        local notf_sX, notf_sY = convertGameScreenCoordsToWindowScreenCoords(605, 438)
        notify.pos = {x = notf_sX - 200, y = notf_sY - 70}
    end
)

function addNotify(msg, time)
    local col = imgui.ColorConvertU32ToFloat4(4281558783)
    local r,g,b = col.x*255, col.y*255, col.z*255
    msg = gsub(msg, '{WC}', '{SSSSSS}')
    msg = gsub(msg, '{MC}', format('{%06X}', bit.bor(bit.bor(b, bit.lshift(g, 8)), bit.lshift(r, 16))))

    notify.msg[#notify.msg+1] = {text = msg, time = time, active = true, justshowed = nil}
end
function ImSaturate(f)
    return f < 0.0 and 0.0 or (f > 1.0 and 1.0 or f)
end

imgui.OnInitialize(function()
    local glyph_ranges = imgui.GetIO().Fonts:GetGlyphRangesCyrillic()
    font = imgui.GetIO().Fonts:AddFontFromFileTTF(getWorkingDirectory() .. '\\resource\\fonts\\EagleSans.ttf', 16, imgui.ImFontConfig(), glyph_ranges) -- или getWorkingDirectory() .. '\\recource\\EagleSans.ttf'
     -- или getWorkingDirectory() .. '\\recource\\EagleSans.ttf'
    imgui.GetIO().IniFilename = nil
    local config = imgui.ImFontConfig()
    config.MergeMode = true
    config.PixelSnapH = true
    iconRanges = imgui.new.ImWchar[3](faicons.min_range, faicons.max_range, 0)
    imgui.GetIO().Fonts:AddFontFromMemoryCompressedBase85TTF(faicons.get_font_data_base85('solid'), 15, config, iconRanges)
    local glyph_rangess = imgui.GetIO().Fonts:GetGlyphRangesCyrillic()
    fontd = imgui.GetIO().Fonts:AddFontFromFileTTF(getWorkingDirectory() .. '\\resource\\fonts\\EagleSans.ttf', 25, imgui.ImFontConfig(), glyph_rangess) -- или getWorkingDirectory() .. '\\recource\\EagleSans.ttf'
    local glyph_rangesss = imgui.GetIO().Fonts:GetGlyphRangesCyrillic()
    zagol = imgui.GetIO().Fonts:AddFontFromFileTTF(getWorkingDirectory() .. '\\resource\\fonts\\EagleSans.ttf', 21, imgui.ImFontConfig(), glyph_rangesss) -- или getWorkingDirectory() .. '\\recource\\EagleSans.ttf'
    
end)

function imgui.CenterText(text)
    imgui.SetCursorPosX(imgui.GetWindowWidth()/2-imgui.CalcTextSize(u8(text)).x/2)
    imgui.Text(u8(text))
end

function imgui.TextColoredRGB(text)
    local style = imgui.GetStyle()
    local colors = style.Colors
    local ImVec4 = imgui.ImVec4

    local explode_argb = function(argb)
        local a = bit.band(bit.rshift(argb, 24), 0xFF)
        local r = bit.band(bit.rshift(argb, 16), 0xFF)
        local g = bit.band(bit.rshift(argb, 8), 0xFF)
        local b = bit.band(argb, 0xFF)
        return a, r, g, b
    end
    local getcolor = function(color)
        if color:sub(1, 6):upper() == 'SSSSSS' then
            local r, g, b = colors[1].x, colors[1].y, colors[1].z
            local a = tonumber(color:sub(7, 8), 16) or colors[1].w * 255
            return ImVec4(r, g, b, a / 255)
        end
        local color = type(color) == 'string' and tonumber(color, 16) or color
        if type(color) ~= 'number' then return end
        local r, g, b, a = explode_argb(color)
        return imgui.ImVec4(r/255, g/255, b/255, a/255)
    end
    local render_text = function(text_)
        for w in text_:gmatch('[^\r\n]+') do
            local text, colors_, m = {}, {}, 1
            w = w:gsub('{(......)}', '{%1FF}')
            while w:find('{........}') do
                local n, k = w:find('{........}')
                local color = getcolor(w:sub(n + 1, k - 1))
                if color then
                    text[#text], text[#text + 1] = w:sub(m, n - 1), w:sub(k + 1, #w)
                    colors_[#colors_ + 1] = color
                    m = n
                end
                w = w:sub(1, n - 1) .. w:sub(k + 1, #w)
            end
            if text[0] then
                for i = 0, #text do
                    imgui.TextColored(colors_[i] or colors[1], u8(text[i]))
                    imgui.SameLine(nil, 0)
                end
                imgui.NewLine()
            else imgui.Text(u8(w)) end
        end
    end
    render_text(text)
end
 
  • Ха-ха
  • Злость
Реакции: recxvery и Vespan