renderFontDrawText / Текст накладывается друг на друга

stool

Новичок
Автор темы
11
20
Версия MoonLoader
Другое
Как можно проверить, что надпись накладывается на другую и добавить оффсет, чтобы этого не происходило?
Lua:
function renderTracers()
    local maxdist = getMaxDist()
    if bizlist.list then
        x,y,z = getCharCoordinates(PLAYER_PED)
        local cx, cy = convert3DCoordsToScreen(x,y,z)
        for i, item in ipairs(bizlist.list) do
            local id = next(item)
            if id then
                local biz = item[id]
                if validBiz(biz.distance_plr, biz.profit, id) and tonumber(biz.profit) > 0 then
                    offy = -50
                    local bx,by,bz
                    bx = biz.location.x by = biz.location.y bz = biz.location.z
                    local screen_x, screen_y = convert3DCoordsToScreen(bx,by,bz)
                    local distcolor
                    if trace_dist[0] then
                        distcolor = colorFromDistance(biz.distance_plr, tonumber(maxdist), {255, 0, 0}, {0,255,0})
                    else
                        distcolor = {255,255,255}
                    end
                    if isPointCorrect(bx,by,bz,1) then
                        if cfg.settings.v_draw_trace then
                            renderDrawLine(cx,cy, screen_x, screen_y, tracer_width[0], makeHexColor({tracer_alpha[0], distcolor[1], distcolor[2], distcolor[3]}))
                        end
                        if cfg.settings.v_draw_binfo then
                            renderFontDrawTextAlign(font_big, "[{ff0000}".. id .. "{ffffff}] " .. biz.name, screen_x, screen_y+offy, makeHexColor({vbinfo_alpha[0],255,255,255}), 2)
                            offy = offy + 15
                            renderFontDrawTextAlign(font, biz.distance_plr .. "м | {00ff00}$" .. add_delimiters(biz.profit), screen_x, screen_y+offy, makeHexColor({vbinfo_alpha[0],255,255,255}), 2)
                        end
                    end
                end
            end
        end
    end
end


1714568586882.png
 
  • Нравится
Реакции: Масюня

movebx

Потрачен
57
162
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Я не знаю где хранить для сравнения
Не могу придумать алгоритм для проверки
Lua:
local o_renderFontDrawText = renderFontDrawText
local text_cached = { };
local text_data = { } do
    text_data.new = function( self, position, size )
        local text_data = { }
            text_data.position = position;
            text_data.size = size;
        return setmetatable( text_data, {
            __index = self
        } )
    end
    text_data.fix_interception = function( other, additional_offset )
        local delta_pos = { x = 0, y = 0 };
        local add_offset = 0;
        local x1, y1, w1, h1 = self.position.x, self.position.y, self.size.width, self.size.height;
        local x2, y2, w2, h2 = other.position.x, other.position.y, other.size.width, other.size.height;
          if x1 < x2 + w2 and x1 + w1 > x2 and y1 < y2 + h2 and y1 + h1 > y2 then
            if x1 < x2 then
                delta_pos.x = x2 - (x1 + w1);
            else
                delta_pos.x = x2 + w2 - x1;
            end
       
            if y1 < y2 then
                delta_pos.y = y2 - (y1 + h1);
            else
                delta_pos.y = y2 + h2 - y1;
            end
            add_offset = additional_offset
        end
       
        self.position.x = self_position.x + delta_pos.x + add_offset;
        self.position.y = self.position.y + delpta_pos.y + add_offset;
    end
    setmetatable( text_data, {
        __call = text_data.new
    } )
end
renderFontDrawText = function( font, text, posX, posY, color, ignoreColorTags )
    ignoreColorTags = ignoreColorTags or false;
    table.insert( text_cached, text_data(
        { x = posX, y = posY },
        {
            width = renderGetFontDrawTextLength( font, text, ignoreColorTags ),
            height = renderGetFontDrawHeight( font )
        }
    ) );
    o_renderFontDrawText( font, text, posX, posY, color, ignoreColorTags );
end
--EXAMPLE USAGE
for i = 1, #text_cached do
    for j = i+1, #text_cached do
        text_cached[i]:fix_interception(text_cached[j], 5)
    end
end
Набросал за 3 минуты на коленке.
Хукнута функция renderFontDrawText , которая при ее вызове собирает инфу о твоем тексте и пушит в отдельную таблицу.
Дальше, после рендера делаешь второй цикл и фиксишь пересечения.
 
  • Клоун
Реакции: percheklii

stool

Новичок
Автор темы
11
20
Lua:
local o_renderFontDrawText = renderFontDrawText
local text_cached = { };
local text_data = { } do
    text_data.new = function( self, position, size )
        local text_data = { }
            text_data.position = position;
            text_data.size = size;
        return setmetatable( text_data, {
            __index = self
        } )
    end
    text_data.fix_interception = function( other, additional_offset )
        local delta_pos = { x = 0, y = 0 };
        local add_offset = 0;
        local x1, y1, w1, h1 = self.position.x, self.position.y, self.size.width, self.size.height;
        local x2, y2, w2, h2 = other.position.x, other.position.y, other.size.width, other.size.height;
          if x1 < x2 + w2 and x1 + w1 > x2 and y1 < y2 + h2 and y1 + h1 > y2 then
            if x1 < x2 then
                delta_pos.x = x2 - (x1 + w1);
            else
                delta_pos.x = x2 + w2 - x1;
            end
      
            if y1 < y2 then
                delta_pos.y = y2 - (y1 + h1);
            else
                delta_pos.y = y2 + h2 - y1;
            end
            add_offset = additional_offset
        end
      
        self.position.x = self_position.x + delta_pos.x + add_offset;
        self.position.y = self.position.y + delpta_pos.y + add_offset;
    end
    setmetatable( text_data, {
        __call = text_data.new
    } )
end
renderFontDrawText = function( font, text, posX, posY, color, ignoreColorTags )
    ignoreColorTags = ignoreColorTags or false;
    table.insert( text_cached, text_data(
        { x = posX, y = posY },
        {
            width = renderGetFontDrawTextLength( font, text, ignoreColorTags ),
            height = renderGetFontDrawHeight( font )
        }
    ) );
    o_renderFontDrawText( font, text, posX, posY, color, ignoreColorTags );
end
--EXAMPLE USAGE
for i = 1, #text_cached do
    for j = i+1, #text_cached do
        text_cached[i]:fix_interception(text_cached[j], 5)
    end
end
Набросал за 3 минуты на коленке.
Хукнута функция renderFontDrawText , которая при ее вызове собирает инфу о твоем тексте и пушит в отдельную таблицу.
Дальше, после рендера делаешь второй цикл и фиксишь пересечения.
чатжпт накодил нерабочий код спс
 
  • Нравится
Реакции: Масюня