Roblox · Сбор-а-тон · урок 3

Журнал находок

Журнал со всеми предметами: картинка, название, цвет сложности. Найденные подсвечиваются, вверху счёт.

Структура

Синим — что добавляем на этом уроке.

StarterGui
└─ ListGui (ScreenGui) — ResetOnSpawn выкл.
   ├─ ListButton (TextButton) — «Журнал»
   ├─ ListFrame (Frame) — Visible выкл.
   │  ├─ Progress (TextLabel)
   │  └─ ScrollingList (ScrollingFrame) — AutomaticCanvasSize Y
   │     ├─ UIGridLayout (UIGridLayout) — CellSize 110 × 130
   │     ├─ UIPadding (UIPadding)
   │     └─ Sample (Frame) — шаблон, Visible выкл.
   │        ├─ ItemImage (ImageButton)
   │        ├─ ItemName (TextLabel)
   │        └─ Difficulty (Frame) — полоска сложности
   └─ ListLocal (LocalScript)

Шаги

  1. StarterGui → ScreenGui «ListGui» (ResetOnSpawn выкл.). Кнопка «ListButton» слева — открывает журнал.
  2. «ListFrame» (Visible выкл.): TextLabel «Progress» сверху, ниже ScrollingFrame «ScrollingList» (AutomaticCanvasSize = Y, CanvasSize = 0, 0, 0, 0 — прокрутка растёт сама).
  3. В ScrollingList — UIGridLayout (CellSize 110, 130 в пикселях, CellPadding 8) и UIPadding (8 со всех сторон).
  4. Шаблон «Sample» (Frame, Visible выкл.): ImageButton «ItemImage», TextLabel «ItemName», узкий Frame «Difficulty» — полоска цвета.
  5. LocalScript «ListLocal»: список строит сам игрок по папке Items — новые предметы появятся без правок интерфейса.
  6. LayoutOrder: лёгкие сверху, сложные внизу. Скрытые элементы UIGridLayout не учитывает — шаблон не занимает места.

Скрипты

ListLocal

Где: StarterGui → ListGui · LocalScript
Зачем: Журнал предметов.

-- игроки
local Players = game:GetService("Players")
-- этот игрок
local player = Players.LocalPlayer
-- все предметы
local items = workspace:WaitForChild("Items")
-- что игрок уже нашёл
local found = player:WaitForChild("Found")
-- ListGui
local gui = script.Parent
-- кнопка журнала
local listButton = gui:WaitForChild("ListButton")
-- журнал
local listFrame = gui:WaitForChild("ListFrame")
-- список с прокруткой
local scrolling = listFrame:WaitForChild("ScrollingList")
-- шаблон карточки
local sample = scrolling:WaitForChild("Sample")
-- «Найдено: 2 / 6»
local progress = listFrame:WaitForChild("Progress")
-- цвет сложности
local COLORS = {Easy = Color3.fromRGB(80, 220, 100), Medium = Color3.fromRGB(255, 150, 40), Hard = Color3.fromRGB(240, 60, 60)}
-- лёгкие — первыми
local ORDER = {Easy = 1, Medium = 2, Hard = 3}
-- найденная карточка
local FOUND_COLOR = Color3.fromRGB(150, 230, 120)
-- ещё не найденная
local HIDDEN_COLOR = Color3.fromRGB(60, 60, 75)
-- имя предмета → карточка
local cards = {}

-- перекрасить карточки и обновить счёт
local function Refresh()
    -- сколько найдено
    local count = 0
    -- каждая карточка
    for name, card in pairs(cards) do
        -- найден ли предмет
        local isFound = found:FindFirstChild(name) ~= nil
        -- цвет
        card.BackgroundColor3 = isFound and FOUND_COLOR or HIDDEN_COLOR
        -- считаем
        if isFound then count += 1 end
    -- конец перебора
    end
    -- счёт
    progress.Text = "Найдено: " .. count .. " / " .. #items:GetChildren()
-- конец функции
end

-- карточка на каждый предмет
for _, item in ipairs(items:GetChildren()) do
    -- копия шаблона
    local card = sample:Clone()
    -- имя
    card.Name = item.Name
    -- подпись
    card.ItemName.Text = item.Name
    -- картинка предмета
    local decal = item:FindFirstChildOfClass("Decal")
    -- на кнопку
    card.ItemImage.Image = decal and decal.Texture or ""
    -- фон — цвет предмета
    if item:IsA("BasePart") then card.ItemImage.BackgroundColor3 = item.Color end
    -- сложность
    local difficulty = item:FindFirstChild("Difficulty")
    -- Easy, если не указана
    local level = difficulty and difficulty.Value or "Easy"
    -- полоска цвета сложности
    card.Difficulty.BackgroundColor3 = COLORS[level] or COLORS.Easy
    -- порядок в списке
    card.LayoutOrder = ORDER[level] or 1
    -- шаблон был скрыт
    card.Visible = true
    -- в список
    card.Parent = scrolling
    -- запоминаем
    cards[item.Name] = card
-- конец перебора
end

-- нашёл новый — обновляем
found.ChildAdded:Connect(Refresh)
-- сразу при входе
Refresh()
-- кнопка журнала
listButton.MouseButton1Click:Connect(function()
    -- открыть / закрыть
    listFrame.Visible = not listFrame.Visible
-- конец функции
end)

Проверка

Запусти Play (или Run) и убедись: