Files

211 lines
10 KiB
Luau

-- Rewards window (same look as the Workshop: ShopKit chrome, ray cards, pill buttons): daily login gifts (7-day
-- cycle) + playtime gifts (9 tiers per day). HUD button = a copy of the Workshop button with the gift art and a red
-- badge with the number of gifts ready. Server: OrnamentRewardsServer (RW_* player attributes, RewardsRemote).
local Players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
local player = Players.LocalPlayer
local folder = RS:WaitForChild("OrnamentMachine")
local Config = require(folder:WaitForChild("Config"))
local remote = folder:WaitForChild("RewardsRemote")
local K = require(player:WaitForChild("PlayerScripts"):WaitForChild("OrnamentCraftUI"):WaitForChild("ShopKit"))
local R = Config.REWARDS
local new, art, label, maxText = K.new, K.art, K.label, K.maxText
local GOLD, WHITE, SOFT = K.GOLD, K.WHITE, K.SOFT
local function attr(k, d) local v = player:GetAttribute(k); if v == nil then return d end return v end
local function rewardLines(g)
local t = {}
if g.Shards then table.insert(t, { string.format("+%d shards", g.Shards), Color3.fromRGB(150, 230, 255) }) end
for _, id in { "Luck2", "Luck3" } do
local n = g.Boosters and g.Boosters[id]
if n then table.insert(t, { string.format(id == "Luck2" and "+%d Luck x2" or "+%d Luck x3", n), id == "Luck2" and Color3.fromRGB(150, 255, 160) or GOLD }) end
end
if g.XP then table.insert(t, { string.format("+%d XP", g.XP), Color3.fromRGB(255, 190, 255) }) end
return t
end
local function timeText(m)
if m < 60 then return string.format("%d min", m) end
if m % 60 == 0 then return string.format("%d h", m // 60) end
return string.format("%d h %d min", m // 60, m % 60)
end
local function iconOf(g)
if g.Boosters and g.Boosters.Luck3 then return "🍀" elseif g.Boosters then return "☘️" elseif (g.Shards or 0) >= 100 then return "💎" end
return "❄️"
end
---------------------------------------------------------------- window (design canvas 1400 x 1000, scaled to the screen)
local gui = new("ScreenGui", { Name = "RewardsGui", ResetOnSpawn = false, DisplayOrder = 30, Enabled = false, IgnoreGuiInset = true,
ZIndexBehavior = Enum.ZIndexBehavior.Sibling, Parent = player:WaitForChild("PlayerGui") })
local overlay = new("TextButton", { Text = "", AutoButtonColor = false, Size = UDim2.fromScale(1, 1), BackgroundColor3 = Color3.new(0, 0, 0),
BackgroundTransparency = 0.45, Parent = gui })
local panel = new("Frame", { AnchorPoint = Vector2.new(0.5, 0.5), Position = UDim2.fromScale(0.5, 0.53), Size = UDim2.fromOffset(1400, 1000),
BackgroundTransparency = 1, Parent = overlay })
local uiScale = new("UIScale", { Parent = panel })
local function rescale()
local v = workspace.CurrentCamera.ViewportSize
uiScale.Scale = math.min(v.X / 1480, v.Y / 1120)
end
rescale(); workspace.CurrentCamera:GetPropertyChangedSignal("ViewportSize"):Connect(rescale)
local refresh
local function closeWin() gui.Enabled = false end
overlay.Activated:Connect(function() end)
local ch = K.chrome({
win = { panel = panel, overlay = overlay }, title = "Rewards", subtitle = "Gifts for coming in and for playing",
tabs = {
{ id = "Daily", text = "Daily login", icon = "📅", tip = "Come in every day for a gift! Missing a day doesn't reset your progress." },
{ id = "Play", text = "Playtime", icon = "⏰", tip = "" },
},
closeWindow = closeWin, fmtNum = function(v) return tostring(math.floor(v + 0.5)) end,
onTab = function() if refresh then refresh() end end,
})
ch.setBalance(attr("Shards", 0), true)
player:GetAttributeChangedSignal("Shards"):Connect(function() ch.setBalance(attr("Shards", 0)) end)
local busy = false
local function claim(action, idx, pill)
if busy then return end
busy = true
pill.set("busy")
local ok, res = pcall(function() return remote:InvokeServer(action, idx) end)
busy = false
if ok and res then K.floatText(pill.button.Parent, "🎁", GOLD) end
refresh()
end
-- a gift card: ray card art, title, big icon, reward lines, pill button
local function card(page, x, y, w, h, title, g, big, onClick)
local c = art(big and "cardViolet" or "cardOrange", { Position = UDim2.fromOffset(x, y), Size = UDim2.fromOffset(w, h),
ScaleType = Enum.ScaleType.Slice, SliceCenter = K.CARD_SLICE, ZIndex = 5, Parent = page })
maxText(label({ Position = UDim2.fromOffset(14, 22), Size = UDim2.new(1, -28, 0, 40), Text = title, TextScaled = true, TextColor3 = GOLD,
TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 6, Parent = c }, 2.5), 34)
label({ Position = UDim2.fromOffset(14, 62), Size = UDim2.new(1, -28, 0, 58), Text = iconOf(g), TextScaled = true,
TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 6, Parent = c }, 0)
local lines = rewardLines(g)
local lh = math.min(30, 84 / #lines)
for i, ln in lines do
maxText(label({ Position = UDim2.fromOffset(10, 124 + (i - 1) * lh), Size = UDim2.new(1, -20, 0, lh - 2), Text = ln[1], TextScaled = true,
TextColor3 = ln[2], TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 6, Parent = c }, 2), 26)
end
local pill
pill = K.pill(c, { Position = UDim2.new(0, 16, 1, -70), Size = UDim2.new(1, -32, 0, 56), ZIndex = 7, TextMax = 26 }, function() onClick(pill) end)
return { frame = c, pill = pill }
end
local dailyPage = ch.makePage("Daily")
local dailyCards = {}
for i, g in R.LOGIN do
local row, col = (i - 1) // 4, (i - 1) % 4
local x = row == 0 and col * 315 or 157 + col * 315
dailyCards[i] = card(dailyPage, x, row * 288, 300, 276, string.format("Day %d", i), g, i == #R.LOGIN, function(p) claim("Login", nil, p) end)
end
local playPage = ch.makePage("Play")
local playCards = {}
for i, g in R.PLAYTIME do
local row, col = (i - 1) // 5, (i - 1) % 5
local x = row == 0 and col * 255 or 127 + col * 255
playCards[i] = card(playPage, x, row * 288, 240, 276, timeText(g.Minutes), g, i == #R.PLAYTIME, function(p) claim("Play", i, p) end)
end
---------------------------------------------------------------- state -> cards
local playAt = os.clock()
player:GetAttributeChangedSignal("RW_PlaySec"):Connect(function() playAt = os.clock() end)
local function playSec() return attr("RW_PlaySec", 0) + math.min(os.clock() - playAt, 10) end
local function untilMidnight()
local t = os.date("!*t")
return 86400 - (t.hour * 3600 + t.min * 60 + t.sec)
end
local function countdown(s)
s = math.max(0, math.floor(s))
if s >= 3600 then return string.format("in %d:%02d:%02d", s // 3600, s // 60 % 60, s % 60) end
return string.format("in %d:%02d", s // 60, s % 60)
end
local function isClaimed(mask, i) return math.floor(mask / 2 ^ (i - 1)) % 2 == 1 end
local function counts()
local daily = attr("RW_LoginReady", false) and 1 or 0
local mask, sec, play = attr("RW_PlayClaimed", 0), playSec(), 0
for i, g in R.PLAYTIME do if not isClaimed(mask, i) and sec >= g.Minutes * 60 then play += 1 end end
return daily, play
end
local function setCard(cd, state, text)
if cd.pill.state ~= "busy" or not busy then cd.pill.set(state, text) end
cd.frame.ImageTransparency = state == "done" and 0.35 or 0
end
function refresh()
local total, ready, n = attr("RW_LoginDay", 0), attr("RW_LoginReady", false), #R.LOGIN
local done = total % n
if not ready and done == 0 and total > 0 then done = n end
for i, cd in dailyCards do
if i <= done then setCard(cd, "done", "Claimed")
elseif i == done + 1 and ready then setCard(cd, "ready", "Claim")
elseif i == done + 1 then setCard(cd, "off", countdown(untilMidnight()))
else setCard(cd, "off", (i == done + 2 and not ready) and "Tomorrow" or string.format("Day %d", i)) end
end
local mask, sec = attr("RW_PlayClaimed", 0), playSec()
for i, cd in playCards do
local need = R.PLAYTIME[i].Minutes * 60
if isClaimed(mask, i) then setCard(cd, "done", "Claimed")
elseif sec >= need then setCard(cd, "ready", "Claim")
else setCard(cd, "off", countdown(need - sec)) end
end
local d, p = counts()
ch.tabs.Daily.setBadge(d); ch.tabs.Play.setBadge(p)
if ch.current() == "Play" then
local s = math.floor(sec)
ch.tip.Text = string.format("Today's playtime: %d:%02d · resets at 00:00 UTC", s // 3600, s // 60 % 60)
end
end
local function open(tab)
gui.Enabled = true
ch.showTab(tab or (attr("RW_LoginReady", false) and "Daily" or ch.current() or "Daily"), true)
panel.Position = UDim2.fromScale(0.5, 0.56)
K.tween(panel, 0.25, { Position = UDim2.fromScale(0.5, 0.53) }, Enum.EasingStyle.Back)
refresh()
end
---------------------------------------------------------------- HUD button (copy of the Workshop button, gift art)
task.spawn(function()
local menu = player.PlayerGui:WaitForChild("OrnamentCraftGui"):WaitForChild("Hud"):WaitForChild("Menu")
local tpl = menu:WaitForChild("WorkshopButton", 30)
if not tpl then return end
local b = tpl:Clone()
b.Name = "RewardsButton"
b.LayoutOrder = 999
local badge, strip
for _, d in b:GetDescendants() do
if d:IsA("TextLabel") and d.Text == "Workshop" then d.Text = "Rewards"
elseif d:IsA("TextLabel") and d.Parent:IsA("Frame") and d.Parent.BackgroundTransparency < 0.5 then badge = d -- red count circle
elseif d:IsA("ImageLabel") then
-- own 3-state strip (normal / hover / pressed), made from the Shop button art: GUI\HUD\button-states-v2\rewards-states.png
d.Image = "rbxassetid://127792380990286"
strip = d
end
end
b.Parent = menu
b.Activated:Connect(function() if gui.Enabled then closeWin() else open() end end)
if strip then -- show frame 1 / 2 / 3 of the strip like the other HUD buttons
local hover, down = false, false
local function paint() strip.Position = UDim2.fromScale(down and -2 or hover and -1 or 0, 0) end
b.MouseEnter:Connect(function() hover = true; paint() end)
b.MouseLeave:Connect(function() hover, down = false, false; paint() end)
b.MouseButton1Down:Connect(function() down = true; paint() end)
b.MouseButton1Up:Connect(function() down = false; paint() end)
paint()
end
while true do
local d, p = counts()
if badge then
badge.Text = tostring(d + p)
local box = badge.Parent
if box and box:IsA("GuiObject") and box ~= b then box.Visible = d + p > 0 else badge.Visible = d + p > 0 end
end
if gui.Enabled then refresh() end
task.wait(1)
end
end)
-- today's login gift waiting -> open the window a few seconds after joining
task.delay(6, function()
if attr("RW_LoginReady", false) and not gui.Enabled then open("Daily") end
end)