CEF CHATBUBBLES

MSIshka

Участник
Автор темы
96
13
Версия SA-MP
  1. 0.3.7 (R1)
Кто знает из-за чего это или как иначе можно пофиксить, чтобы пузырь не плыл к координате, а прилипал к ней. На видео это не так сильно заметно из-за ограна ютуба в 60фпс(при 0.25x отчетливо видно). При рендере прямоугольника(renderDrawBox) все нормально. Использую webcore lua
Lua:
function sampev.onPlayerChatBubble(playerId, color, distance, duration, message)
    if ini.settings.custombubble == true then
        if not query[playerId] then
            query[playerId] = {}
        end
       
        local a, r, g, b = explode_argb(color)
       
        query[playerId] = {
            message = u8:encode(message),
            create_time = os.clock(),
            duration = duration / 1000,
            distance = distance,
            r = a,
            g = r,
            b = g,
            a = 0,
            playerId = playerId
        }
       
        return false
    else
        return true
    end
end

function onD3DPresent()
    if not browser2 then return end
    if ini.settings.custombubble == false then return end
   
    local current_time = os.clock()
    local data_strings = {}
   
    for playerId, data in pairs(query) do
        local elapsed = current_time - data.create_time
       
        if elapsed > data.duration then
            query[playerId] = nil
        else
            local res, handle = sampGetCharHandleBySampPlayerId(tonumber(playerId))
            if handle and doesCharExist(handle) and wallPlayer(handle, 50) then
                local x, y, z = getNameTagPosForText(handle)
                if isPointOnScreen(x,y,z,0.1) then
                    local screenX, screenY = convert3DCoordsToScreen(x, y, z)
                   
                    if screenX and screenY then
                        table.insert(data_strings, string.format("[%d,%d,%d,%d,%d,%d,'%s']",
                            playerId, screenX, screenY, data.r, data.g, data.b, data.message:gsub("'", "\\'")))
                        --renderDrawBox(screenX, screenY, 300, 100, -1)
                    end
                end
            end
        end
    end
   
    if #data_strings > 0 then
        local final_query = "[" .. table.concat(data_strings, ",") .. "]"
        browser2:execute_js(string.format("updateBubbles(%s)", final_query))
    else
        browser2:execute_js("updateBubbles([])")
    end
end

JavaScript:
function getMessageDiv(wrapper, index) {
    let el = wrapper.children[index];
   
    if (!el) {
        el = document.createElement('div');
        el.className = 'bubble-message';
        wrapper.appendChild(el);
    }

    return el;
}

function updateBubbles(bubblesData) {
    const currentIds = new Set();

    for (let i = 0; i < bubblesData.length; i++) {
        const [id, x, y, r, g, b, text] = bubblesData[i];
        const key = `player_${id}`;
        currentIds.add(key);

        let wrapper = activeBubbles.get(key);
        if (!wrapper) {
            wrapper = document.createElement('div');
            wrapper.className = 'bubble-wrapper';
            const msgDiv = document.createElement('div');
            msgDiv.className = 'bubble-message';
            wrapper.appendChild(msgDiv);
           
            bubblesContainer.appendChild(wrapper);
            activeBubbles.set(key, wrapper);
        }

        wrapper.style.left = `${x}px`;
        wrapper.style.top = `${y}px`;
       
        const messageDiv = wrapper.firstChild;
        const newContent = HTMLstringify(highlightMentions(replaceTextWithEmojis(replaceMediaTags(colorify(escapeHtml(text))))));
        if (messageDiv.innerHTML !== newContent) {
            messageDiv.innerHTML = newContent;
        }
        messageDiv.style.color = `rgb(${r}, ${g}, ${b})`;
    }

    activeBubbles.forEach((wrapper, key) => {
        if (!currentIds.has(key)) {
            wrapper.remove();
            activeBubbles.delete(key);
        }
    });
}
 
Последнее редактирование: