- Версия SA-MP
-
- Любая
I want to create a Pie menu for quick command access, but I don't know how to add icons to menus like you guys usually do, and I need a sample code or demo.
Lua:
local imgui = require 'mimgui'
local vkeys = require 'vkeys'
local menuData = {
{label = "InGame", submenu = {
{label = "Accept Trade", cmd = "/accept trade "},
{label = "IC Info", cmd = "/menu"},
{label = "Quit-Job", cmd = "/quitjob"},
{label = "ID-Card", cmd = "/idcard"},
}},
{label = "Anims", submenu = {
{label = "Wave", cmd = "/wave "},
{label = "Hi", cmd = "/hi"},
{label = "Idle", cmd = "/idle"},
{label = "Lean", cmd = "/lean"},
{label = "Flip", cmd = "/nflip"},
{label = "Wallow 1", cmd = "/wallow 1"},
{label = "Wallow 2", cmd = "/wallow 2"},
{label = "Nam dau ngta", cmd = "/takehead"},
}},
{label = "Phuong Tien", submenu = {
{label = "List Car", cmd = "/v list"},
{label = "lock", cmd = "/v lock"},
{label = "Invent", cmd = "/v invent"},
{label = "Park", cmd = "/v park"},
{label = "Hood", cmd = "/v hood"},
{label = "Trunk", cmd = "/v trunk"},
{label = "Light", cmd = "/v light"},
}},
{label = "Weapons", submenu = {
{label = "Reload DE", cmd = "/reload 18"},
{label = "Reload M4", cmd = "/reload 30"},
{label = "Reload Rifle", cmd = "/reload 5"},
}},
{label = "Map-GPS", cmd = "/gps"},
{label = "Stop-Anim", cmd = "/stopanim"},
{label = "Drop-Truck", cmd = "/truck drop"},
}
local showPie = imgui.new.bool(false)
local currentMenu = menuData
local menuStack = {}
local screenX, screenY = getScreenResolution()
local COLOR_BG_NORMAL = 0xAA1A1A1A
local COLOR_BG_HOVER = 0xCC333333
local COLOR_BORDER_STATIC = 0x88FFAA00
local COLOR_BORDER_ACTIVE = 0xFFFFAA00
local COLOR_TEXT = 0xFFFFFFFF
local COLOR_CENTER_BG = 0xFF121212
function resetMenu()
showPie[0] = false
showCursor(false)
currentMenu = menuData
menuStack = {}
end
imgui.OnFrame(function() return showPie[0] end,
function(player)
imgui.SetNextWindowPos(imgui.ImVec2(0, 0))
imgui.SetNextWindowSize(imgui.ImVec2(screenX, screenY))
imgui.PushStyleColor(imgui.Col.WindowBg, imgui.ImVec4(0, 0, 0, 0))
imgui.Begin('PieMenuLayer', showPie, 645)
local drawList = imgui.GetWindowDrawList()
local center = imgui.ImVec2(screenX / 2, screenY / 2)
local mousePos = imgui.GetIO().MousePos
local innerRadius = 50
local outerRadius = 150
local padding = 0.02
local distFromCenter = math.sqrt((mousePos.x - center.x)^2 + (mousePos.y - center.y)^2)
local hoveredCenter = distFromCenter < innerRadius
local numItems = #currentMenu
local arcStep = (math.pi * 2) / numItems
local mouseAngle = math.atan2(mousePos.y - center.y, mousePos.x - center.x)
if mouseAngle < 0 then mouseAngle = mouseAngle + (math.pi * 2) end
for i, item in ipairs(currentMenu) do
local startArc = (i - 1) * arcStep + padding
local endArc = i * arcStep - padding
local isHovered = (distFromCenter > innerRadius and distFromCenter < outerRadius and mouseAngle > (i-1)*arcStep and mouseAngle < i*arcStep)
drawList:PathClear()
drawList:PathArcTo(center, innerRadius, startArc, endArc, 32)
drawList:PathArcTo(center, outerRadius, endArc, startArc, 32)
drawList:PathFillConvex(isHovered and COLOR_BG_HOVER or COLOR_BG_NORMAL)
drawList:PathClear()
drawList:PathArcTo(center, innerRadius, startArc, endArc, 32)
drawList:PathArcTo(center, outerRadius, endArc, startArc, 32)
drawList:PathStroke(isHovered and COLOR_BORDER_ACTIVE or COLOR_BORDER_STATIC, true, isHovered and 2.5 or 1.2)
local textAngle = (i - 1) * arcStep + (arcStep / 2)
local textPos = imgui.ImVec2(
center.x + math.cos(textAngle) * (innerRadius + outerRadius) / 2,
center.y + math.sin(textAngle) * (innerRadius + outerRadius) / 2
)
local label = item.label .. (item.submenu and " >" or "")
local textSize = imgui.CalcTextSize(label)
drawList:AddText(imgui.ImVec2(textPos.x - textSize.x/2, textPos.y - textSize.y/2), COLOR_TEXT, label)
if isHovered and imgui.IsMouseReleased(0) then
if item.submenu then
table.insert(menuStack, currentMenu)
currentMenu = item.submenu
else
sampSendChat(item.cmd)
resetMenu()
end
end
end
drawList:AddCircleFilled(center, innerRadius, hoveredCenter and 0xFF444444 or COLOR_CENTER_BG, 64)
drawList:AddCircle(center, innerRadius, hoveredCenter and COLOR_BORDER_ACTIVE or COLOR_BORDER_STATIC, 64, 2.0)
local centerLabel = #menuStack > 0 and "BACK" or "CLOSE"
local bSize = imgui.CalcTextSize(centerLabel)
drawList:AddText(imgui.ImVec2(center.x - bSize.x/2, center.y - bSize.y/2), COLOR_TEXT, centerLabel)
if hoveredCenter and imgui.IsMouseReleased(0) then
if #menuStack > 0 then
currentMenu = table.remove(menuStack)
else
resetMenu()
end
end
imgui.End()
imgui.PopStyleColor()
end)
function main()
while not isSampAvailable() do wait(100) end
while true do
wait(0)
if isKeyJustPressed(vkeys.VK_Z) and not sampIsChatInputActive() and not sampIsDialogActive() and not isSampfuncsConsoleActive() then
showPie[0] = not showPie[0]
showCursor(showPie[0])
if not showPie[0] then resetMenu() end
end
if showPie[0] and isKeyJustPressed(vkeys.VK_ESCAPE) then
resetMenu()
end
end
end