example
example

资源 计算小地图

Yann

站长
管理成员
GTAOS管理组
认证卖家
认证用户
本 月 名 人 榜 最 佳
1725773447657.png

根据 NUI Web 的安全区域获取小地图大小​

lua:
function CalculateMinimap()
    local safezoneSize = GetSafeZoneSize()
    local aspectRatio = GetAspectRatio(false)

    if aspectRatio > 2 then aspectRatio = 16 / 9 end

    local screenWidth, screenHeight = GetActiveScreenResolution()
    local xScale = 1.0 / screenWidth
    local yScale = 1.0 / screenHeight

    local minimap = {
        width = xScale * (screenWidth / (4 * aspectRatio)),
        height = yScale * (screenHeight / 5.674),
        leftX = xScale * (screenWidth * (1.0 / 20.0 * ((math.abs(safezoneSize - 1.0)) * 10))),
        bottomY = 1.0 - yScale * (screenHeight * (1.0 / 20.0 * ((math.abs(safezoneSize - 1.0)) * 10)))
    }
    
    if aspectRatio > 2 then
        minimap.leftX = minimap.leftX + minimap.width * 0.845
        minimap.width = minimap.width * 0.76
    elseif aspectRatio > 1.8 then
        minimap.leftX = minimap.leftX + minimap.width * 0.2225
        minimap.width = minimap.width * 0.995
    end
    
    minimap.topY = minimap.bottomY - minimap.height

    return {
        width = minimap.width * screenWidth,
        height = minimap.height * screenHeight,
        left = minimap.leftX * 100,
        top = minimap.topY * 100
    }
end

示例 TSX​

lua:
style={{
        left: minimap.left + "%",
        top: minimap.top + "%",
        width: minimap.width + "px",
        height: minimap.height + "px",
      }}
 
顶部