Imgui Пожалуйста, помогите.

saradaken

Участник
Автор темы
41
6
Версия MoonLoader
Другое
Привет, у меня проблема. Использование (imgui.hint из https://www.blast.hk/threads/13380/post-778921)
Когда я навожу курсор мыши на (Show.Hint) ui, он перестает работать и больше не может быть использован. Как это исправить?

1728103900213.png



Lua:
local imgui = require 'imgui'
local key = require 'vkeys'
local fa = require("fAwesome5")
local encoding = require 'encoding'
u8 = encoding.UTF8
encoding.default = 'CP1251'

local main_window_state = imgui.ImBool(false)


function imgui.Hint(str_id, hint_text, color, no_center)
    color = color or imgui.GetStyle().Colors[imgui.Col.PopupBg]
    local p_orig = imgui.GetCursorPos()
    local hovered = imgui.IsItemHovered()
    imgui.SameLine(nil, 0)

    local animTime = 0.2
    local show = true

    if not POOL_HINTS then POOL_HINTS = {} end
    if not POOL_HINTS[str_id] then
        POOL_HINTS[str_id] = {
            status = false,
            timer = 0
        }
    end

    if hovered then
        for k, v in pairs(POOL_HINTS) do
            if k ~= str_id and os.clock() - v.timer <= animTime  then
                show = false
            end
        end
    end

    if show and POOL_HINTS[str_id].status ~= hovered then
        POOL_HINTS[str_id].status = hovered
        POOL_HINTS[str_id].timer = os.clock()
    end

    local getContrastColor = function(col)
        local luminance = 1 - (0.299 * col.x + 0.587 * col.y + 0.114 * col.z)
        return luminance < 0.5 and imgui.ImVec4(0, 0, 0, 1) or imgui.ImVec4(1, 1, 1, 1)
    end

    local rend_window = function(alpha)
        local size = imgui.GetItemRectSize()
        local scrPos = imgui.GetCursorScreenPos()
        local DL = imgui.GetWindowDrawList()
        local center = imgui.ImVec2( scrPos.x - (size.x / 2), scrPos.y + (size.y / 2) - (alpha * 4) + 10 )
        local a = imgui.ImVec2( center.x - 7, center.y - size.y - 3 )
        local b = imgui.ImVec2( center.x + 7, center.y - size.y - 3)
        local c = imgui.ImVec2( center.x, center.y - size.y + 3 )
        local col = imgui.ColorConvertFloat4ToU32(imgui.ImVec4(color.x, color.y, color.z, alpha))

        DL:AddTriangleFilled(a, b, c, col)
        imgui.SetNextWindowPos(imgui.ImVec2(center.x, center.y - size.y - 3), imgui.Cond.Always, imgui.ImVec2(0.5, 1.0))
        imgui.PushStyleColor(imgui.Col.PopupBg, color)
        imgui.PushStyleColor(imgui.Col.Border, color)
        imgui.PushStyleColor(imgui.Col.Text, getContrastColor(color))
        imgui.PushStyleVarVec2(imgui.StyleVar.WindowPadding, imgui.ImVec2(8, 8))
        imgui.PushStyleVarFloat(imgui.StyleVar.WindowRounding, 6)
        imgui.PushStyleVarFloat(imgui.StyleVar.Alpha, alpha)

        local max_width = function(text)
            local result = 0
            for line in text:gmatch('[^\n]+') do
                local len = imgui.CalcTextSize(line).x
                if len > result then
                    result = len
                end
            end
            return result
        end

        local hint_width = max_width(hint_text) + (imgui.GetStyle().WindowPadding.x * 2)
        imgui.SetNextWindowSize(imgui.ImVec2(hint_width, -1), imgui.Cond.Always)
        imgui.Begin('##' .. str_id, _, imgui.WindowFlags.Tooltip + imgui.WindowFlags.NoResize + imgui.WindowFlags.NoScrollbar + imgui.WindowFlags.NoTitleBar)
            for line in hint_text:gmatch('[^\n]+') do
                if no_center then
                    imgui.Text(line)
                else
                    imgui.SetCursorPosX((hint_width - imgui.CalcTextSize(line).x) / 2)
                    imgui.Text(line)
                end
            end
        imgui.End()

        imgui.PopStyleVar(3)
        imgui.PopStyleColor(3)
    end

    if show then
        local between = os.clock() - POOL_HINTS[str_id].timer
        if between <= animTime then
            local s = function(f)
                return f < 0.0 and 0.0 or (f > 1.0 and 1.0 or f)
            end
            local alpha = hovered and s(between / animTime) or s(1.00 - between / animTime)
            rend_window(alpha)
        elseif hovered then
            rend_window(1.00)
        end
    end

    imgui.SetCursorPos(p_orig)
end



function imgui.OnDrawFrame()
    imgui.Process = main_window_state.v
    if main_window_state.v then
        testwindow()
    end
end



function testwindow()
    if not main_window_state.v then return end
        
       imgui.SetNextWindowSize(imgui.ImVec2(600, 300), imgui.Cond.Always, imgui.Cond.FirstUseEver)

        local style = imgui.GetStyle()
        style.WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
        
 
        imgui.PushStyleColor(imgui.Col.WindowBg, imgui.ImVec4(0.145, 0.145, 0.145, 1.0))
        imgui.PushStyleColor(imgui.Col.TitleBg, imgui.ImVec4(0.2627, 0.2078, 0.3922, 1.0))
        imgui.PushStyleColor(imgui.Col.TitleBgActive, imgui.ImVec4(0.2627, 0.2078, 0.3922, 1.0)) 
        imgui.PushStyleColor(imgui.Col.TitleBgCollapsed, imgui.ImVec4(0.2627, 0.2078, 0.3922, 1.0)) 

        imgui.PushStyleVar(imgui.StyleVar.FramePadding, imgui.ImVec2(10, 15))

        imgui.Begin('My window', main_window_state,
            imgui.WindowFlags.NoResize +
            imgui.WindowFlags.NoScrollbar +
            imgui.WindowFlags.NoCollapse)

        imgui.Text('Hello world') 
        
        imgui.Button(u8'Show Hint')
        imgui.Hint('firstranghello', 'С 1-го ранга')
        
        imgui.End()

  
        imgui.PopStyleVar()
        imgui.PopStyleColor()
        imgui.PopStyleColor()
        imgui.PopStyleColor()
        imgui.PopStyleColor()
  
        
end







function main()
    while true do
        wait(0)
        if wasKeyPressed(key.VK_N) then
            main_window_state.v = not main_window_state.v
        end
        imgui.Process = main_window_state.v
    end
end
 

chromiusj

Известный
Модератор
5,656
3,959
Потому что функция мимгуишная, в имгуи нет PushStyleVarVec2
Lua:
    IMGUI_API void          PushStyleColor(ImGuiCol idx, ImU32 col);
    IMGUI_API void          PushStyleColor(ImGuiCol idx, const ImVec4& col);
    IMGUI_API void          PopStyleColor(int count = 1);
    IMGUI_API void          PushStyleVar(ImGuiStyleVar idx, float val);
    IMGUI_API void          PushStyleVar(ImGuiStyleVar idx, const ImVec2& val);
    IMGUI_API void          PopStyleVar(int count = 1);
    IMGUI_API const ImVec4& GetStyleColorVec4(ImGuiCol idx);
 
Последнее редактирование: