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


-- ShopUI_kdm1eHvH.lua
-- Магазин на F1

-- ============================================================
-- Шрифты
-- ============================================================
surface.CreateFont("shop_title",  { font = "Montserrat", size = 28, weight = 900, extended = true })
surface.CreateFont("shop_text",   { font = "Montserrat", size = 16, weight = 600, extended = true })
surface.CreateFont("shop_price",  { font = "Montserrat", size = 18, weight = 800, extended = true })
surface.CreateFont("shop_btn",    { font = "Montserrat", size = 16, weight = 700, extended = true })
surface.CreateFont("shop_cat",    { font = "Montserrat", size = 14, weight = 700, extended = true })

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

-- ============================================================
-- Хранилище товаров
-- ============================================================
local shopItems = {}
local shopOpen = false
local selectedCategory = "Все"

-- ============================================================
-- Запрос товаров
-- ============================================================
local function requestShop()
    net.Start("kdm1e_ShopRequest")
    net.SendToServer()
end

net.Receive("kdm1e_ShopSend", function()
    local count = net.ReadUInt(16)
    shopItems = {}
    for i = 1, count do
        table.insert(shopItems, {
            id = net.ReadString(),
            name = net.ReadString(),
            price = net.ReadUInt(32),
            category = net.ReadString(),
            type = net.ReadString(),
        })
    end
end)

-- ============================================================
-- Меню
-- ============================================================
local function drawShop()
    if not shopOpen then return end

    local w, h = 700, 500
    local x = (ScrW() - w) / 2
    local y = (ScrH() - h) / 2

    -- Фон
    surface.SetDrawColor(0, 0, 0, 150)
    surface.DrawRect(0, 0, ScrW(), ScrH())

    surface.SetDrawColor(0, 0, 0, 200)
    surface.DrawRect(x + 5, y + 5, w, h)

    surface.SetDrawColor(BG)
    surface.DrawRect(x, y, w, h)

    -- Полоса
    surface.SetDrawColor(ACCENT)
    surface.DrawRect(x, y, w, 4)

    -- Заголовок
    surface.SetFont("shop_title")
    local title = "kdm1eHvH"
    local title2 = " — МАГАЗИН"
    local w1 = surface.GetTextSize(title)
    local w2 = surface.GetTextSize(title2)
    local totalW = w1 + w2
    draw.SimpleText(title, "shop_title", x + w/2 - totalW/2, y + 15, color_white, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
    draw.SimpleText(title2, "shop_title", x + w/2 - totalW/2 + w1, y + 15, ACCENT, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)

    -- Баланс токенов
    local tokens = LocalPlayer():GetNWInt("kdm1e_Tokens", 0)
    draw.SimpleText("Токенов: " .. tokens, "shop_price", x + w/2, y + 55, ACCENT, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)

    -- Кнопка "Задонатить"
    local donX, donY, donW, donH = x + w - 180, y + 55, 160, 28
    surface.SetDrawColor(BG_ROW)
    surface.DrawRect(donX, donY, donW, donH)
    surface.SetDrawColor(ACCENT)
    surface.DrawOutlinedRect(donX, donY, donW, donH, 1)
    draw.SimpleText("Задонатить", "shop_btn", donX + donW/2, donY + donH/2, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)

    -- Товары
    local listY = y + 100
    for i, item in ipairs(shopItems) do
        local ry = listY + (i - 1) * 60
        if ry + 60 > y + h - 10 then break end

        surface.SetDrawColor(BG_ROW)
        surface.DrawRect(x + 15, ry, w - 30, 55)

        surface.SetDrawColor(ACCENT)
        surface.DrawRect(x + 15, ry, 3, 55)

        draw.SimpleText(item.name, "shop_text", x + 30, ry + 10, TEXT, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
        draw.SimpleText(item.category, "shop_cat", x + 30, ry + 34, DIM, TEXT_ALIGN_LEFT, TEXT_ALIGN_TOP)
        draw.SimpleText(item.price .. " T", "shop_price", x + w - 30, ry + 18, ACCENT, TEXT_ALIGN_RIGHT, TEXT_ALIGN_TOP)

        -- Кнопка "Купить"
        local buyX, buyY, buyW, buyH = x + w - 130, ry + 12, 100, 30
        surface.SetDrawColor(ACCENT)
        surface.DrawRect(buyX, buyY, buyW, buyH)
        draw.SimpleText("КУПИТЬ", "shop_btn", buyX + buyW/2, buyY + buyH/2, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
    end

    -- Закрыть
    draw.SimpleText("[ESC] Закрыть", "shop_cat", x + w/2, y + h - 25, DIM, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
end

-- ============================================================
-- Открытие/закрытие
-- ============================================================
local function openShop()
    shopOpen = true
    requestShop()
    gui.EnableScreenClicker(true)
end

local function closeShop()
    shopOpen = false
    gui.EnableScreenClicker(false)
end

-- F1
hook.Add("PlayerBindPress", "ShopUI_kdm1eHvH", function(ply, bind, pressed)
    if bind == "gm_showhelp" and pressed then
        if shopOpen then closeShop() else openShop() end
        return true
    end
end)

-- ESC
hook.Add("PlayerBindPress", "ShopUI_ESC", function(ply, bind, pressed)
    if bind == "gm_showteam" and pressed and shopOpen then
        closeShop()
        return true
    end
end)

-- Отрисовка
hook.Add("HUDPaint", "ShopUI_kdm1eHvH_Draw", drawShop)

-- Клик
hook.Add("GUIMousePressed", "ShopUI_kdm1eHvH_Click", function(mcode, mpos)
    if not shopOpen then return end
    if mcode ~= MOUSE_LEFT then return end

    local w, h = 700, 500
    local x = (ScrW() - w) / 2
    local y = (ScrH() - h) / 2

    -- Кнопка "Задонатить"
    local donX, donY, donW, donH = x + w - 180, y + 55, 160, 28
    if mpos.x >= donX and mpos.x <= donX + donW and mpos.y >= donY and mpos.y <= donY + donH then
        chat.AddText(Color(255, 100, 100), "[kdm1eHvH] ", Color(255, 255, 255), "Чтобы задонатить, писать в Discord: ", Color(100, 200, 255), "kdm1e")
        return
    end

    -- Кнопки "Купить"
    local listY = y + 100
    for i, item in ipairs(shopItems) do
        local ry = listY + (i - 1) * 60
        local buyX, buyY, buyW, buyH = x + w - 130, ry + 12, 100, 30

        if mpos.x >= buyX and mpos.x <= buyX + buyW and mpos.y >= buyY and mpos.y <= buyY + buyH then
            net.Start("kdm1e_ShopBuy")
            net.WriteString(item.id)
            net.SendToServer()
            return
        end
    end
end)

print("[ShopUI] Меню магазина загружено (F1)")