RadioButton / TextColored

альтушка

Активный
Автор темы
326
29
Версия MoonLoader
.026-beta
Вот как красить выбранный тэг номер 1? Т.е, если я обращаюсь от его лица или обращаются к нам
пример, что должно краситься (например в FFCC00 imgui.ImVec4(1.0, 0.8, 0.0, 1.0) ):

[D] .* nick_name [РКШД] - [ЛСПД]
[D] .* nick_name [ЛВПД] - [РКШД]


Lua:
local selectedTag1 = new.int(0)
local selectedTag2 = new.int(0)
local tags1 = {'[ЛСПД]', '[ЛВПД]', '[РКШД]', '[SWAT]', '[ФБР]', '[Пра-во]', '[МЮ]', '[МО]', '[МЗ]', '[ТСР]', '[ЛСа]', '[СФа]'}
local tags2 = {'[ЛСПД]', '[ЛВПД]', '[РКШД]', '[SWAT]', '[ФБР]', '[Пра-во]', '[Всем]', '[МЮ]', '[МО]', '[МЗ]', '[ТСР]', '[ЛСа]', '[СФа]'}

--

imgui.BeginChild('##MainChild', imgui.ImVec2(670, 370), true)

    for i, msg in ipairs(chatMessages) do
        imgui.TextColored(imgui.ImVec4(0.2, 0.6, 1.0, 1.0), u8(msg))
    end

    if shouldScrollToBottom then
        imgui.SetScrollHereY(1.0)
        shouldScrollToBottom = false
    end

imgui.EndChild()

--radiobutton's

imgui.CenterText(u8'Выберите первый тег:')

imgui.RadioButtonIntPtr(u8'[ЛСПД]##tag1', selectedTag1, 0)
imgui.SameLine()

imgui.RadioButtonIntPtr(u8'[ЛВПД]##tag1', selectedTag1, 1)
imgui.SameLine()

imgui.RadioButtonIntPtr(u8'[РКШД]##tag1', selectedTag1, 2)

imgui.RadioButtonIntPtr(u8'[SWAT]##tag1', selectedTag1, 3)
imgui.SameLine()

imgui.RadioButtonIntPtr(u8'[ФБР]##tag1', selectedTag1, 4)
imgui.SameLine()

imgui.RadioButtonIntPtr(u8'[Пра-во]##tag1', selectedTag1, 5)

imgui.RadioButtonIntPtr(u8'[МЮ]##tag1', selectedTag1, 6)
imgui.SameLine()

imgui.RadioButtonIntPtr(u8'[МО]##tag1', selectedTag1, 7)
imgui.SameLine()

imgui.RadioButtonIntPtr(u8'[МЗ]##tag1', selectedTag1, 8)

imgui.RadioButtonIntPtr(u8'[ТСР]##tag1', selectedTag1, 9)
imgui.SameLine()

imgui.RadioButtonIntPtr(u8'[ЛСа]##tag1', selectedTag1, 10)
imgui.SameLine()

imgui.RadioButtonIntPtr(u8'[СФа]##tag1', selectedTag1, 11)

imgui.Separator()

imgui.CenterText(u8'Выберите второй тег:')

imgui.RadioButtonIntPtr(u8'[ЛСПД]##tag2', selectedTag2, 0)
imgui.SameLine()

imgui.RadioButtonIntPtr(u8'[ЛВПД]##tag2', selectedTag2, 1)
imgui.SameLine()

imgui.RadioButtonIntPtr(u8'[РКШД]##tag2', selectedTag2, 2)

imgui.RadioButtonIntPtr(u8'[SWAT]##tag2', selectedTag2, 3)
imgui.SameLine()

imgui.RadioButtonIntPtr(u8'[ФБР]##tag2', selectedTag2, 4)
imgui.SameLine()

imgui.RadioButtonIntPtr(u8'[Пра-во]##tag2', selectedTag2, 5)

imgui.RadioButtonIntPtr(u8'[Всем]##tag2', selectedTag2, 6)
imgui.SameLine()

imgui.RadioButtonIntPtr(u8'[МЮ]##tag2', selectedTag2, 7)
imgui.SameLine()

imgui.RadioButtonIntPtr(u8'[МО]##tag2', selectedTag2, 8)

imgui.RadioButtonIntPtr(u8'[МЗ]##tag2', selectedTag2, 9)
imgui.SameLine()

imgui.RadioButtonIntPtr(u8'[ТСР]##tag2', selectedTag2, 10)
imgui.SameLine()

imgui.RadioButtonIntPtr(u8'[ЛСа]##tag2', selectedTag2, 11)

imgui.RadioButtonIntPtr(u8'[СФа]##tag2', selectedTag2, 12)

--

function sampev.onServerMessage(color, text)
    if text:find('^%[D%]') then
        local cleanText = text:gsub('{%x%x%x%x%x%x}', '')
        table.insert(chatMessages, cleanText)
        shouldScrollToBottom = true
        if #chatMessages > 1000 then
            table.remove(chatMessages, 1)
        end
    end
end
 

Вложения

  • 1771762958252.png
    1771762958252.png
    59.4 KB · Просмотры: 30
  • 1771763451828.png
    1771763451828.png
    29.1 KB · Просмотры: 30
Решение
Надеюсь помог.

Lua:
local colorYellow = imgui.ImVec4(1.0, 0.8, 0.0, 1.0)
local colorBlue   = imgui.ImVec4(0.2, 0.6, 1.0, 1.0)

-- в OnFrame, внутри BeginChild:
for i, msg in ipairs(chatMessages) do
   local currentTag = tags1[selectedTag1[0] + 1]
   local tagPattern = currentTag:gsub('([%[%]%-])', '%%%1')
   local color = msg:find(tagPattern) and colorYellow or colorBlue
   imgui.TextColored(color, u8(msg))
end

fsrxvdd

Активный
293
74
lua:
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], text[i])
                    imgui.SameLine(nil, 0)
                end
                imgui.NewLine()
            else imgui.Text(w) end
        end
    end
    render_text(text)
end
в любую часть кода и потом пишешь с цветами в формате {FFFFFF}
 

альтушка

Активный
Автор темы
326
29
lua:
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], text[i])
                    imgui.SameLine(nil, 0)
                end
                imgui.NewLine()
            else imgui.Text(w) end
        end
    end
    render_text(text)
end
в любую часть кода и потом пишешь с цветами в формате {FFFFFF}
возможно, ты немного не понял, что я написал в вопросе.
суть вопроса была такова: выделение строки с тегом жёлтым цветом, а остальное уже в синем.
 

e11evated

Участник
76
29
Надеюсь помог.

Lua:
local colorYellow = imgui.ImVec4(1.0, 0.8, 0.0, 1.0)
local colorBlue   = imgui.ImVec4(0.2, 0.6, 1.0, 1.0)

-- в OnFrame, внутри BeginChild:
for i, msg in ipairs(chatMessages) do
   local currentTag = tags1[selectedTag1[0] + 1]
   local tagPattern = currentTag:gsub('([%[%]%-])', '%%%1')
   local color = msg:find(tagPattern) and colorYellow or colorBlue
   imgui.TextColored(color, u8(msg))
end
 
  • Влюблен
Реакции: альтушка