Загрузка данных


-- WeaponMenu_kdm1eHvH.lua
-- Красно-чёрное меню выбора оружия (горизонтальное)

-- ============ Скрываем стандартный GMod-переключатель ============
hook.Add("HUDShouldDraw", "HideDefaultWeaponSelection", function(name)
    if name == "CHudWeaponSelection" then return false end
end)

-- ============ Шрифты ============
surface.CreateFont("wsel_title", { font = "Montserrat", size = 20, weight = 900, extended = true })
surface.CreateFont("wsel_num",   { font = "Montserrat", size = 32, weight = 900, extended = true })
surface.CreateFont("wsel_name",  { font = "Montserrat", size = 15, weight = 700, extended = true })
surface.CreateFont("wsel_ammo",  { font = "Montserrat", size = 18, weight = 800, extended = true })
surface.CreateFont("wsel_small", { font = "Montserrat", size = 13, weight = 600, extended = true })

-- ============ Цвета ============
local ACCENT   = Color(220, 40, 40)
local BG       = Color(12, 12, 18, 240)
local BG_SEL   = Color(45, 15, 15, 250)
local BG_ROW   = Color(24, 24, 32, 235)
local TEXT     = Color(235, 235, 235)
local TEXT_DIM = Color(140, 140, 150)

-- ============ Логика выбора оружия ============
-- При нажатии 1-9 вручную выбираем оружие из слота
local SLOT_KEYS = {
    [KEY_1] = 1,
    [KEY_2] = 2,
    [KEY_3] = 3,
    [KEY_4] = 4,
    [KEY_5] = 5,
    [KEY_6] = 6,
    [KEY_7] = 7,
    [KEY_8] = 8,
    [KEY_9] = 9,
}

-- Список слотов оружия GMod (по номерам)
local WEAPON_SLOTS = {
    [1] = { "weapon_physcannon", "weapon_physgun", "gmod_tool", "gmod_camera", "weapon_357", "weapon_pistol", "weapon_smg1", "weapon_ar2", "weapon_shotgun", "weapon_crossbow", "weapon_rpg", "weapon_frag", "weapon_slam", "weapon_crowbar", "weapon_stunstick", "weapon_bugbait" }
}

local lastSlotKey = nil

hook.Add("Think", "WeaponMenu_kdm1eHvH_Select", function()
    local ply = LocalPlayer()
    if not IsValid(ply) then return end

    -- Проверяем какая клавиша сейчас зажата
    local currentKey = nil
    for key, slot in pairs(SLOT_KEYS) do
        if input.IsKeyDown(key) then
            currentKey = key
            break
        end
    end

    -- Если клавиша изменилась — выбираем оружие
    if currentKey and currentKey ~= lastSlotKey then
        lastSlotKey = currentKey

        local slot = SLOT_KEYS[currentKey]
        local weps = ply:GetWeapons()

        -- Собираем оружие в этом слоте (по порядку в списке оружия игрока)
        local matching = {}
        for _, wep in ipairs(weps) do
            if IsValid(wep) and wep:GetSlot() == slot then
                table.insert(matching, wep)
            end
        end

        -- Если оружие в слоте есть — выбираем первое
        if #matching > 0 then
            ply:SelectWeapon(matching[1]:GetClass())
        end
    elseif not currentKey then
        lastSlotKey = nil
    end
end)

-- ============ Отрисовка меню ============
local function getWeaponAmmo(ply, wep)
    local clip = wep:Clip1()
    local reserve = ply:GetAmmoCount(wep:GetPrimaryAmmoType())
    if clip < 0 then clip = 0 end
    if reserve < 0 then reserve = 0 end
    return clip, reserve
end

local function drawWeaponMenu()
    local ply = LocalPlayer()
    if not IsValid(ply) then return end

    -- Определяем активный слот
    local activeSlot = 0
    for key, slot in pairs(SLOT_KEYS) do
        if input.IsKeyDown(key) then
            activeSlot = slot
            break
        end
    end

    -- Собираем оружие активного слота
    local list = {}
    for _, wep in ipairs(ply:GetWeapons()) do
        if IsValid(wep) and wep:GetSlot() == activeSlot then
            local clip, reserve = getWeaponAmmo(ply, wep)
            table.insert(list, {
                wep = wep,
                name = wep:GetPrintName() or wep:GetClass(),
                clip = clip,
                reserve = reserve,
                selected = (ply:GetActiveWeapon() == wep)
            })
        end
    end

    if #list == 0 then return end

    -- Размеры плашек (горизонтальные)
    local cardW = 180
    local cardH = 130
    local gap = 12
    local headerH = 36
    local padding = 14

    local totalW = math.max(#list * cardW + (#list - 1) * gap, 300) + padding * 2
    local totalH = headerH + cardH + padding * 2

    local x = (ScrW() - totalW) / 2
    local y = ScrH() * 0.65  -- чуть ниже центра

    -- Тень
    surface.SetDrawColor(0, 0, 0, 180)
    surface.DrawRect(x + 5, y + 5, totalW, totalH)

    -- Фон
    surface.SetDrawColor(BG)
    surface.DrawRect(x, y, totalW, totalH)

    -- Красная полоса сверху
    surface.SetDrawColor(ACCENT)
    surface.DrawRect(x, y, totalW, 3)

    -- Заголовок с логотипом
    local titleText = "ВЫБОР ОРУЖИЯ — СЛОТ " .. activeSlot
    draw.SimpleText(titleText, "wsel_small",
        x + totalW / 2, y + 3 + headerH / 2,
        TEXT_DIM, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)

    -- Логотип kdm1eHvH справа в заголовке
    surface.SetFont("wsel_small")
    local t1, t2 = "kdm1e", "HvH"
    local w1 = surface.GetTextSize(t1)
    local w2 = surface.GetTextSize(t2)
    draw.SimpleText(t1, "wsel_small", x + totalW - w1 - w2 - 15, y + 3 + headerH / 2,
        color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)
    draw.SimpleText(t2, "wsel_small", x + totalW - w2 - 15, y + 3 + headerH / 2,
        ACCENT, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER)

    -- Карточки оружия
    local startX = x + padding
    local startY = y + 3 + headerH + padding

    for i, data in ipairs(list) do
        local cx = startX + (i - 1) * (cardW + gap)
        local cy = startY

        -- Фон карточки
        if data.selected then
            surface.SetDrawColor(BG_SEL)
        else
            surface.SetDrawColor(BG_ROW)
        end
        surface.DrawRect(cx, cy, cardW, cardH)

        -- Рамка
        if data.selected then
            surface.SetDrawColor(ACCENT)
            surface.DrawOutlinedRect(cx, cy, cardW, cardH, 2)
        else
            surface.SetDrawColor(60, 60, 80, 150)
            surface.DrawOutlinedRect(cx, cy, cardW, cardH, 1)
        end

        -- Номер слота в углу
        draw.SimpleText(
            tostring(i),
            "wsel_num",
            cx + 12, cy + 10,
            data.selected and ACCENT or TEXT_DIM,
            TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP
        )

        -- Название оружия (снизу карточки)
        local nameColor = data.selected and Color(255, 220, 220) or TEXT
        draw.SimpleText(
            data.name,
            "wsel_name",
            cx + cardW / 2, cy + cardH - 50,
            nameColor,
            TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP
        )

        -- Патроны (снизу карточки)
        draw.SimpleText(
            data.clip .. " / " .. data.reserve,
            "wsel_ammo",
            cx + cardW / 2, cy + cardH - 26,
            data.selected and ACCENT or TEXT_DIM,
            TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP
        )
    end
end

-- ============ Показываем меню ============
local function isWeaponKeyDown()
    for key, _ in pairs(SLOT_KEYS) do
        if input.IsKeyDown(key) then return true end
    end
    return false
end

hook.Add("HUDPaint", "WeaponMenu_kdm1eHvH", function()
    if not isWeaponKeyDown() then return end
    if gui.IsGameUIVisible() then return end

    drawWeaponMenu()
end)

print("[kdm1eHvH] Меню выбора оружия загружено")