добавь переменную называющуюся как-то вроде scale и домножение всех графических…
- User
добавь переменную называющуюся как-то вроде scale и домножение всех графических элементов на нее при рендере. local isActive = true
local memory = require 'memory' require "socket" require"lib.sampfuncs"
local colors = {
-- светлая темаtmpTheme1 = { background = 0xD9FFFFFF, -- белый цвет с 85% прозрачностью text = 0xff000000, -- черный цвет с 100% прозрачностью border = 0xff000000, -- черный цвет с 100% прозрачностью
speed1 = 0x800000FF, -- синий цвет с 50% прозрачностью speed2 = 0x80FF00FF, -- фиолетовый цвет с 50% прозрачностью }, -- темная тема tmpTheme2 = { background = 0xD9000000, -- черный цвет с 85% прозрачностью text = 0xFFFFFFFF, -- белый цвет border = 0xFFFFFFFF, -- белый цвет speed1 = 0x80505FFF, -- синий цвет с 50% прозрачностью speed2 = 0x80FF50FF, -- фиолетовый цвет с 50% прозрачностью }, -- полупрозрачная темная тема tmpTheme3 = { background = 0x1A000000, -- черный цвет с 10% прозрачностью text = 0xFFFFFFFF, -- белый цвет border = 0xFFFFFFFF, -- белый цвет speed1 = 0x80505FFF, -- синий цвет с 50% прозрачностью speed2 = 0x80FF50FF, -- фиолетовый цвет с 50% прозрачностью }}
local fonts = { small = renderCreateFont('Arial', 6.5, 0), medium = renderCreateFont('Arial', 8.125), large = renderCreateFont('Arial', 16.25, 0) }
local сanvases = { speedometer = { maxSpeed = 160, width = 230, height = 90, posX = 1200, posY = 730, borderWidth = 1.1, color = 'background', bars = { speedBar = { minValue = 0, maxValue = 160, calcValue = function() return math.floor(getCarSpeed(storeCarCharIsInNoSave(playerPed)) * 2) end, allign = 'center', padding = 20, --width = 160, height = 25, offsetX = 100, offsetY = 10, color = 'speed1', ticks = { main = { milesPerTick = 20, milesOffset = 0, allign = 'end', height = 5, width = 1.1, text = true, textOffset = 8 }, secondary = { milesPerTick = 20, milesOffset = 10, allign = 'end', height = 3, width = 1.1, text = false, textOffset = false } } } } } }
local labels = { labelOffsetY = 62 }
function main() repeat wait(0) until isSampAvailable()
local theme = colors.tmpTheme1 while true do wait(0) if isCharInAnyCar(playerPed) then for _, canvas in pairs(сanvases) do --local offsetX -- отрисовка фона спидометра renderDrawBox(canvas.posX, canvas.posY, canvas.width, canvas.height, theme[canvas.color]) for _, bar in pairs(canvas.bars) do -- отрисовка спидбара local width = canvas.width - (bar.padding * 2) local offsetX = (bar.allign == 'start' and bar.offsetX) or (bar.allign == 'center' and bar.offsetX - width/2) or (bar.allign == 'end' and bar.offsetX - width) --local offsetX = canvas.width - (canvas.width/2) --local offsetX = offsetX - width/2 local calculatedVal = bar.calcValue() local minValue = calculatedVal > bar.maxValue and bar.maxValue * math.floor(calculatedVal / canvas.maxSpeed) or 0 local maxValue = minValue + bar.maxValue local barWidth = (calculatedVal - minValue) / maxValue * width renderDrawBox(canvas.posX + offsetX, canvas.posY + bar.offsetY, barWidth, bar.height, theme[bar.color]) -- отрисовка границ спидбара renderDrawLineEx(canvas.posX + offsetX, canvas.posY + bar.offsetY, canvas.posX + offsetX + width, canvas.posY + bar.offsetY, canvas.borderWidth, theme.border) renderDrawLineEx(canvas.posX + offsetX, canvas.posY + bar.offsetY + bar.height, canvas.posX + offsetX + width, canvas.posY + bar.offsetY + bar.height, canvas.borderWidth, theme.border) renderDrawLineEx(canvas.posX + offsetX, canvas.posY + bar.offsetY, canvas.posX + offsetX, canvas.posY + bar.offsetY + bar.height, canvas.borderWidth, theme.border) renderDrawLineEx(canvas.posX + offsetX + width, canvas.posY + bar.offsetY, canvas.posX + offsetX + width, canvas.posY + bar.offsetY + bar.height, canvas.borderWidth, theme.border) -- отрисовка текущей скорости renderFontDrawTextEx(fonts.large, tostring(calculatedVal), canvas.posX + offsetX + width/2, canvas.posY + ((bar.height / 2)+bar.offsetY), theme.text, _, 'center', 'center') -- отрисовка делений и чисел под ними for _, tick in pairs(bar.ticks) do local startX = canvas.posX + bar.padding local startY = ((tick.allign == 'start' and 0) or (tick.allign == 'center' and bar.height / 2) or (tick.allign == 'end' and bar.height)) + canvas.posY + bar.offsetY local endY = startY + tick.height local speedBarWidth = (canvas.width - (bar.padding * 2)) local pixelsPerMile = speedBarWidth / (canvas.maxSpeed) -- деление ширины спидбара на максимальную на нем скорость local pixelsOffset = tick.milesOffset * pixelsPerMile -- смещение от начала в пикселях local ticksSpacing = tick.milesPerTick * pixelsPerMile -- расстояние между делениями local numTicks = math.floor((speedBarWidth-pixelsOffset) / ticksSpacing) -- деление ширины спидбара на ширину тика if tick.milesPerTick then for i = 0, numTicks do local x = startX + ticksSpacing * i + pixelsOffset renderDrawLineEx(x, startY, x, endY, tick.width, theme.text) if tick.text then -- отрисовка текста под(над) черточкой скорости local speed = tick.milesPerTick * i + tick.milesOffset + minValue local textY = endY + tick.textOffset renderFontDrawTextEx(fonts.small, tostring(speed), x, textY, theme.text, _, 'center', 'center') -- !! НАПИСАТЬЬ ВЫРАВНИЕ ПО ЦЕНТРУ ПО ОБЕИМ(?) ОСЯМ ЧЕРЕЗ КАСТОМНУЮ ФУНКЦИЮ РЕНДЕРА !! end end end end -- отрисовка надписи "Speed(MPH)" renderFontDrawTextEx( fonts.medium, 'Speed(MPH)', canvas.posX + canvas.width / 2, canvas.posY + labels.labelOffsetY, theme.text, _, 'center', 'center') end end end endend
-- 'start' 'center' 'end'
-- 1 значение - одинаковый отступ со всех сторон -- 2 значения - первое для верха и низа, второе для левой и правой сторон -- 3 значения - первое для верха, второе для правой и левой, третье для низа -- 4 значения - отступы по часовой стрелке: верх, правая, низ, левая
function renderFontDrawTextEx(font, text, posX, posY, color, ignoreColorTags, allignX, allignY) local length = renderGetFontDrawTextLength(font, text) local height = renderGetFontDrawHeight(font)
if allignX == "center" then posX = posX - length / 2 elseif allignX == "end" then posX = posX - length end if allignY == "center" then posY = posY - height / 2 elseif allignY == "end" then posY = posY - height end return renderFontDrawText(font, text, posX, posY, color, ignoreColorTags)end
function renderDrawLineEx(pos1x, pos1y, pos2x, pos2y, width, color) renderSetRenderState(161, 1) -- D3DRS_MULTISAMPLEANTIALIAS renderBegin(5) -- D3DPT_TRIANGLESTRIP renderColor(color)
-- вычисление вектора между точками local dx, dy = pos2x - pos1x, pos2y - pos1y local length = math.sqrt(dx^2 + dy^2) -- нормализация вектора, если он не нулевой if length ~= 0 then dx, dy = dx / length, dy / length end -- вычисление перпендикулярного вектора local perpx, perpy = -dy * width / 2, dx * width / 2 renderVertex(pos1x + perpx, pos1y + perpy) -- левый нижний угол renderVertex(pos1x - perpx, pos1y - perpy) -- левый верхний угол renderVertex(pos2x + perpx, pos2y + perpy) -- правый нижний угол renderVertex(pos2x - perpx, pos2y - perpy) -- правый верхний угол renderEnd()end
- Assistant
local scale = 1.5 -- пример значения
function main() repeat wait(0) until isSampAvailable()
local theme = colors.tmpTheme1 while true do wait(0) if isCharInAnyCar(playerPed) then for _, canvas in pairs(сanvases) do --local offsetX -- отрисовка фона спидометра renderDrawBox(canvas.posX * scale, canvas.posY * scale, canvas.width * scale, canvas.height * scale, theme[canvas.color]) for _, bar in pairs(canvas.bars) do -- отрисовка спидбара local width = canvas.width * scale - (bar.padding * 2 * scale) local offsetX = ((bar.allign == 'start' and bar.offsetX) or (bar.allign == 'center' and bar.offsetX - width/2) or (bar.allign == 'end' and bar.offsetX - width)) * scale --local offsetX = canvas.width * scale - (canvas.width/2) --local offsetX = offsetX - width/2 local calculatedVal = bar.calcValue() * scale local minValue = calculatedVal > bar.maxValue and bar.maxValue * math.floor(calculatedVal / canvas.maxSpeed) or 0 local maxValue = minValue + bar.maxValue local barWidth = (calculatedVal - minValue) / maxValue * width renderDrawBox(canvas.posX * scale + offsetX, canvas.posY * scale + bar.offsetY * scale, barWidth, bar.height * scale, theme[bar.color]) -- отрисовка границ спидбара renderDrawLineEx(canvas.posX * scale + offsetX, canvas.posY * scale + bar.offsetY * scale, canvas.posX * scale + offsetX + width, canvas.posY * scale + bar.offsetY * scale, canvas.borderWidth * scale, theme.border) renderDrawLineEx(canvas.posX * scale + offsetX, canvas.posY * scale + bar.offsetY * scale + bar.height * scale, canvas.posX * scale + offsetX + width, canvas.posY * scale + bar.offsetY * scale + bar.height * scale, canvas.borderWidth * scale, theme.border) renderDrawLineEx(canvas.posX * scale + offsetX, canvas.posY * scale + bar.offsetY * scale, canvas.posX * scale + offsetX, canvas.posY * scale + bar.offsetY * scale + bar.height * scale, canvas.borderWidth * scale, theme.border) renderDrawLineEx(canvas.posX * scale + offsetX + width, canvas.posY * scale + bar.offsetY * scale, canvas.posX * scale + offsetX + width, canvas.posY * scale + bar.offsetY * scale + bar.height * scale, canvas.borderWidth * scale, theme.border) -- отрисовка текущей скорости renderFontDrawTextEx(fonts.large, tostring(calculatedVal), canvas.posX * scale + offsetX + width/2, canvas.posY * scale + ((bar.height / 2)+bar.offsetY * scale), theme.text, _, 'center', 'center') -- отрисовка делений и чисел под ними for _, tick in pairs(bar.ticks) do local startX = canvas.posX * scale + bar.padding * scale local startY = ((tick.allign == 'start' and 0) or (tick.allign == 'center' and bar.height / 2) or (tick.allign == 'end' and bar.height)) * scale + canvas.posY * scale + bar.offsetY * scale local endY = startY + tick.height * scale local speedBarWidth = (canvas.width - (bar.padding * 2) * scale) local pixelsPerMile = speedBarWidth / (canvas.maxSpeed) -- деление ширины спидбара на максимальную на нем скорость local pixelsOffset = tick.milesOffset * pixelsPerMile -- смещение от начала в пикселях local ticksSpacing = tick.milesPerTick * pixelsPerMile -- расстояние между делениями local numTicks = math.floor((speedBarWidth-pixelsOffset) / ticksSpacing) -- деление ширины спидбара на ширину тика if tick.milesPerTick then for i = 0, numTicks do local x = startX + ticksSpacing * i + pixelsOffset renderDrawLineEx(x, startY, x, endY, tick.width * scale, theme.text) if tick.text then -- отрисовка текста под(над) черточкой скорости local speed = tick.milesPerTick * i + tick.milesOffset + minValue local textY = endY + tick.textOffset * scale renderFontDrawTextEx(fonts.small, tostring(speed), x, textY, theme.text, _, 'center', 'center') -- !! НАПИСАТЬЬ ВЫРАВНИЕ ПО ЦЕНТРУ ПО ОБЕИМ(?) ОСЯМ ЧЕРЕЗ КАСТОМНУЮ ФУНКЦИЮ РЕНДЕРА !! end end end end -- отрисовка надписи "Speed(MPH)" renderFontDrawTextEx( fonts.medium, 'Speed(MPH)', canvas.posX * scale + canvas.width / 2, canvas.posY * scale + labels.labelOffsetY * scale, theme.text, _, 'center', 'center') end end end endend