Update
This commit is contained in:
commit
2d6a8a867d
1093 files changed
+2424571
No files matched your search
@@ -0,0 +1,549 @@
|
||||
-- MarketWindow: the cross-server "Рынок" window in the New Year shop style (frame, tabs, buttons: ShopKit).
|
||||
-- Tabs: Купить / Продать / Мои лоты / Как это работает. "Мои лоты" shows a badge with the number of active lots.
|
||||
-- Купить : toy + rarity filter chips, sort chips, refresh; listing cards. Buy button: ready -> confirm
|
||||
-- ("Точно? N", red, 3 s) -> busy -> done; off when you are short of shards or below the market level;
|
||||
-- "Твой лот" (blue, inert) on your own lots. Loading skeletons, empty state with a way out.
|
||||
-- Продать : your toys (tree toys hidden, fresh toys locked with a timer) + a sell box with a price stepper,
|
||||
-- quick price chips, payout after tax and a list button that says what is wrong with the price.
|
||||
-- Мои лоты : rows with time left (bar), price and "Снять"; empty state leads to "Продать".
|
||||
local K = require(script.Parent:WaitForChild("ShopKit"))
|
||||
|
||||
local M = {}
|
||||
|
||||
local WHITE, GOLD, SOFT, OK, WARN, NAVY, BODY, FONT = K.WHITE, K.GOLD, K.SOFT, K.OK, K.WARN, K.NAVY, K.BODY, K.FONT
|
||||
local tween, new, corner, art, label, maxText = K.tween, K.new, K.corner, K.art, K.label, K.maxText
|
||||
local pill, chip, pricePlate = K.pill, K.chip, K.pricePlate
|
||||
local DARK = Color3.fromRGB(10, 26, 34)
|
||||
|
||||
local function fmtLeft(s)
|
||||
local d, h, m = s // 86400, (s % 86400) // 3600, (s % 3600) // 60
|
||||
if d > 0 then return d .. "d " .. h .. "h" end
|
||||
if h > 0 then return h .. "h " .. m .. " min" end
|
||||
return math.max(1, m) .. " min"
|
||||
end
|
||||
|
||||
function M.install(ctx)
|
||||
local Config, player, fn = ctx.Config, ctx.player, ctx.remote
|
||||
local MK = Config.MARKET
|
||||
local fmt = ctx.fmtNum
|
||||
local function attr(n, d) local v = player:GetAttribute(n); if v == nil then return d end return v end
|
||||
local win = ctx.win
|
||||
local function call(action, ...)
|
||||
local ok, res = pcall(fn.InvokeServer, fn, action, ...)
|
||||
if not ok or type(res) ~= "table" then return { ok = false, msg = "No connection to the market" } end
|
||||
return res
|
||||
end
|
||||
local function gated() return attr("Level", 1) < MK.MIN_LEVEL end
|
||||
local GATE = "Level " .. MK.MIN_LEVEL .. "+"
|
||||
local TAX = math.floor(MK.TAX * 100 + 0.5)
|
||||
local DAYS = MK.DURATION // 86400
|
||||
local function variantOf(it) return it.Variant and Config.VariantById[it.Variant] end
|
||||
local function subLine(it)
|
||||
local r, v = Config.RarityById[it.Rarity], variantOf(it)
|
||||
return r.Name .. (v and (" · " .. v.Name) or ""), v and v.Color or r.Color
|
||||
end
|
||||
-- dark disc with the toy's pattern
|
||||
local function toyDisc(parent, it, size, pos, z)
|
||||
local r, v = Config.RarityById[it.Rarity], variantOf(it)
|
||||
local disc = new("Frame", { Position = pos, Size = UDim2.fromOffset(size, size), BackgroundColor3 = DARK, ZIndex = z, Parent = parent }, {
|
||||
corner(UDim.new(0.5, 0)), new("UIStroke", { Color = v and v.Color or r.Color, Thickness = 3 }),
|
||||
})
|
||||
local mini = ctx.miniPattern(Config.ToyById[it.Toy].Mask, r.Color, math.floor(size * 0.72), disc)
|
||||
mini.AnchorPoint = Vector2.new(0.5, 0.5)
|
||||
mini.Position = UDim2.fromScale(0.5, 0.5)
|
||||
for _, d in mini:GetDescendants() do if d:IsA("GuiObject") then d.ZIndex = z + 1 end end
|
||||
mini.ZIndex = z + 1
|
||||
return disc
|
||||
end
|
||||
|
||||
local onTab
|
||||
local TABS = {
|
||||
{ id = "Buy", text = "Buy", icon = "🛒", tip = "Listings from players on all servers. The first click on “Buy” prepares the purchase, the second confirms it." },
|
||||
{ id = "Sell", text = "Sell", icon = "💰", tip = "Tax " .. TAX .. "% per sale. Shards arrive even if you're offline." },
|
||||
{ id = "Mine", text = "My Listings", icon = "📦", tip = "A listing lasts " .. DAYS .. " days. If it doesn't sell, the ornament comes back to you." },
|
||||
{ id = "Help", text = "How It Works", icon = "📖", tip = "The market is shared by all servers — players set the prices." },
|
||||
}
|
||||
local ch = K.chrome({ win = win, title = "MARKET", subtitle = "Buy and sell ornaments\nacross all servers", tabs = TABS,
|
||||
closeWindow = ctx.closeWindow, fmtNum = fmt, onTab = function(id) onTab(id) end })
|
||||
local tabs = ch.tabs
|
||||
local mineCount = 0
|
||||
|
||||
---------------------------------------------------------------- BUY
|
||||
local buyG = ch.makePage("Buy")
|
||||
local filter = { toy = nil, rarity = nil, sort = "cheap" }
|
||||
local refreshBuy
|
||||
local function chipRow(y, entries, onPick)
|
||||
local row = new("Frame", { Position = UDim2.fromOffset(4, y), Size = UDim2.new(1, -8, 0, 54), BackgroundTransparency = 1, ZIndex = 4, Parent = buyG }, {
|
||||
new("UIListLayout", { FillDirection = Enum.FillDirection.Horizontal, Padding = UDim.new(0, 8), SortOrder = Enum.SortOrder.LayoutOrder, VerticalAlignment = Enum.VerticalAlignment.Center }),
|
||||
})
|
||||
local w = math.floor((1252 - 8 * (#entries - 1)) / #entries)
|
||||
local chips = {}
|
||||
for k, e in entries do
|
||||
chips[k] = { o = chip(row, { Size = UDim2.fromOffset(w, 50), LayoutOrder = k, ZIndex = 4 }, e.label, function() onPick(e.value) end, e.dot), value = e.value }
|
||||
end
|
||||
return chips
|
||||
end
|
||||
local toyEntries = { { label = "All ornaments", value = false } }
|
||||
for _, t in Config.TOYS do table.insert(toyEntries, { label = t.Name, value = t.Id }) end
|
||||
local rarityEntries = { { label = "All rarities", value = false } }
|
||||
for _, r in Config.RARITIES do table.insert(rarityEntries, { label = r.Name, value = r.Id, dot = r.Color }) end
|
||||
local toyChips = chipRow(0, toyEntries, function(v) filter.toy = v or nil; refreshBuy() end)
|
||||
local rarityChips = chipRow(60, rarityEntries, function(v) filter.rarity = v or nil; refreshBuy() end)
|
||||
local sortRow = new("Frame", { Position = UDim2.fromOffset(4, 120), Size = UDim2.fromOffset(560, 54), BackgroundTransparency = 1, ZIndex = 4, Parent = buyG }, {
|
||||
new("UIListLayout", { FillDirection = Enum.FillDirection.Horizontal, Padding = UDim.new(0, 8), SortOrder = Enum.SortOrder.LayoutOrder, VerticalAlignment = Enum.VerticalAlignment.Center }),
|
||||
})
|
||||
local sortChips = {}
|
||||
for k, e in { { label = "Cheapest", value = "cheap" }, { label = "Priciest", value = "expensive" }, { label = "Newest", value = "new" } } do
|
||||
sortChips[k] = { o = chip(sortRow, { Size = UDim2.fromOffset(176, 50), LayoutOrder = k, ZIndex = 4 }, e.label, function() filter.sort = e.value; refreshBuy() end), value = e.value }
|
||||
end
|
||||
local buyCount = maxText(label({ Position = UDim2.fromOffset(580, 128), Size = UDim2.fromOffset(400, 38), Text = "", TextScaled = true, FontFace = BODY,
|
||||
TextColor3 = SOFT, TextXAlignment = Enum.TextXAlignment.Right, ZIndex = 4, Parent = buyG }, 1.5), 22)
|
||||
local refreshBtn = pill(buyG, { Position = UDim2.fromOffset(1004, 120), Size = UDim2.fromOffset(248, 56), ZIndex = 4, TextMax = 28 }, function() refreshBuy() end)
|
||||
refreshBtn.set("alt", "Refresh")
|
||||
local buyList = K.scroll(buyG, UDim2.fromOffset(0, 186), UDim2.new(1, 0, 0, 380),
|
||||
new("UIGridLayout", { CellSize = UDim2.fromOffset(238, 330), CellPadding = UDim2.fromOffset(12, 14), SortOrder = Enum.SortOrder.LayoutOrder }))
|
||||
new("UIPadding", { PaddingLeft = UDim.new(0, 4), PaddingTop = UDim.new(0, 6), PaddingBottom = UDim.new(0, 6), Parent = buyList })
|
||||
local buyCards, buyEmpty, buyReq = {}, nil, 0
|
||||
|
||||
local function paintFilters()
|
||||
for _, c in toyChips do c.o.setSelected((c.value or nil) == filter.toy) end
|
||||
for _, c in rarityChips do c.o.setSelected((c.value or nil) == filter.rarity) end
|
||||
for _, c in sortChips do c.o.setSelected(c.value == filter.sort) end
|
||||
end
|
||||
local function clearBuy()
|
||||
for _, c in buyList:GetChildren() do if c:IsA("GuiObject") then c:Destroy() end end
|
||||
buyCards = {}
|
||||
if buyEmpty then buyEmpty:Destroy(); buyEmpty = nil end
|
||||
end
|
||||
local function skeletons()
|
||||
for k = 1, 5 do
|
||||
local s = new("Frame", { BackgroundColor3 = Color3.new(0, 0, 0), BackgroundTransparency = 0.6, LayoutOrder = k, ZIndex = 5, Parent = buyList }, { corner(UDim.new(0, 24)) })
|
||||
task.spawn(function()
|
||||
task.wait(k * 0.08)
|
||||
while s.Parent do
|
||||
tween(s, 0.6, { BackgroundTransparency = 0.8 }, Enum.EasingStyle.Sine).Completed:Wait()
|
||||
tween(s, 0.6, { BackgroundTransparency = 0.55 }, Enum.EasingStyle.Sine).Completed:Wait()
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
local function listingCard(l, order)
|
||||
local it = l.item
|
||||
local r, v = Config.RarityById[it.Rarity], variantOf(it)
|
||||
local card = new("Frame", { BackgroundColor3 = WHITE, LayoutOrder = order, ZIndex = 5, Parent = buyList }, {
|
||||
corner(UDim.new(0, 24)),
|
||||
new("UIGradient", { Rotation = 90, Color = ColorSequence.new(r.Color:Lerp(Color3.new(0, 0, 0), 0.45), Color3.fromRGB(10, 22, 34)) }),
|
||||
new("UIStroke", { Color = v and v.Color or r.Color, Thickness = v and 4 or 3 }),
|
||||
})
|
||||
toyDisc(card, it, 112, UDim2.new(0.5, -56, 0, 14), 6)
|
||||
if v then
|
||||
local tag = new("Frame", { Position = UDim2.fromOffset(8, 8), Size = UDim2.fromOffset(104, 30), BackgroundColor3 = v.Color, ZIndex = 8, Parent = card }, { corner(UDim.new(0.5, 0)) })
|
||||
maxText(label({ Position = UDim2.fromOffset(6, 3), Size = UDim2.new(1, -12, 1, -6), Text = v.Name, TextScaled = true, TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 9, Parent = tag }, 1.5), 18)
|
||||
end
|
||||
maxText(label({ Position = UDim2.fromOffset(10, 132), Size = UDim2.new(1, -20, 0, 32), Text = Config.ToyById[it.Toy].Name, TextScaled = true,
|
||||
TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 6, Parent = card }, 2.5), 30)
|
||||
maxText(label({ Position = UDim2.fromOffset(10, 166), Size = UDim2.new(1, -20, 0, 24), Text = r.Name, TextScaled = true, TextColor3 = r.Color,
|
||||
TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 6, Parent = card }, 2), 22)
|
||||
local _, price = pricePlate(card, UDim2.fromOffset(34, 198), UDim2.fromOffset(176, 46), 6)
|
||||
price.Text = fmt(l.price)
|
||||
maxText(label({ Position = UDim2.fromOffset(10, 250), Size = UDim2.new(1, -20, 0, 22), Text = "seller: " .. tostring(l.seller), TextScaled = true, FontFace = BODY,
|
||||
TextColor3 = SOFT, TextTruncate = Enum.TextTruncate.AtEnd, TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 6, Parent = card }, 1.5), 18)
|
||||
local c = { l = l, card = card, price = price, armed = false, busy = false, sold = false }
|
||||
local btn
|
||||
function c.paint()
|
||||
local shards = attr("Shards", 0)
|
||||
price.TextColor3 = (l.mine or shards >= l.price) and WHITE or WARN
|
||||
if c.sold then btn.set("done", "Bought")
|
||||
elseif c.busy then btn.set("busy")
|
||||
elseif l.mine then btn.set("info", "Your listing")
|
||||
elseif gated() then btn.set("off", GATE)
|
||||
elseif shards < l.price then btn.set("off", "Need " .. fmt(l.price - shards))
|
||||
elseif c.armed then btn.set("confirm", "Sure? " .. fmt(l.price))
|
||||
else btn.set("ready", "Buy") end
|
||||
end
|
||||
btn = pill(card, { Position = UDim2.fromOffset(14, 278), Size = UDim2.fromOffset(210, 46), ZIndex = 6, TextMax = 26 }, function(state)
|
||||
if state == "ready" then
|
||||
c.armed = true
|
||||
local token = {}
|
||||
c.token = token
|
||||
c.paint()
|
||||
task.delay(3, function() if c.token == token and c.armed then c.armed = false; c.paint() end end)
|
||||
elseif state == "confirm" then
|
||||
c.armed, c.busy = false, true
|
||||
c.paint()
|
||||
task.spawn(function()
|
||||
local res = call("Buy", l.id, l.price)
|
||||
c.busy = false
|
||||
ctx.toast(res.msg or (res.ok and "Bought" or "Failed"), res.ok and OK or WARN)
|
||||
if res.ok then
|
||||
c.sold = true
|
||||
c.paint()
|
||||
K.flash(card, 24)
|
||||
K.floatText(card, "Bought!")
|
||||
task.delay(1, refreshBuy)
|
||||
else
|
||||
c.paint()
|
||||
task.delay(0.4, refreshBuy)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end)
|
||||
c.btn = btn
|
||||
c.paint()
|
||||
return c
|
||||
end
|
||||
refreshBuy = function()
|
||||
paintFilters()
|
||||
buyReq += 1
|
||||
local my = buyReq
|
||||
if #buyCards == 0 then clearBuy(); skeletons() end
|
||||
buyCount.Text = "Loading…"
|
||||
refreshBtn.set("busy")
|
||||
task.spawn(function()
|
||||
local res = call("Browse", { toy = filter.toy, rarity = filter.rarity, sort = filter.sort })
|
||||
if my ~= buyReq then return end
|
||||
refreshBtn.set("alt", "Refresh")
|
||||
clearBuy()
|
||||
if not res.ok then buyCount.Text = res.msg or "" return end
|
||||
buyCount.Text = "showing " .. #res.items .. " of " .. res.total .. (res.remote and "" or " · Studio market")
|
||||
if #res.items == 0 then
|
||||
local filtered = filter.toy ~= nil or filter.rarity ~= nil
|
||||
buyEmpty = K.emptyState({ Position = UDim2.fromOffset(0, 186), Size = UDim2.new(1, 0, 0, 380), ZIndex = 4, Parent = buyG },
|
||||
filtered and "No matching listings" or "The market is empty",
|
||||
filtered and "Try another ornament or rarity." or "Nobody is selling yet — be the first to list an ornament!")
|
||||
local b = pill(buyEmpty, { Position = UDim2.new(0.5, -150, 0, 312), Size = UDim2.fromOffset(300, 62), ZIndex = 5, TextMax = 28 }, function()
|
||||
if filtered then filter.toy, filter.rarity = nil, nil; refreshBuy() else ch.showTab("Sell") end
|
||||
end)
|
||||
b.set("alt", filtered and "Reset filters" or "Sell an ornament")
|
||||
return
|
||||
end
|
||||
for k, l in res.items do table.insert(buyCards, listingCard(l, k)) end
|
||||
end)
|
||||
end
|
||||
|
||||
---------------------------------------------------------------- SELL
|
||||
local sellG = ch.makePage("Sell")
|
||||
local left = new("Frame", { Size = UDim2.fromOffset(770, 566), BackgroundColor3 = Color3.new(0, 0, 0), BackgroundTransparency = 0.55, ZIndex = 4, Parent = sellG }, {
|
||||
corner(UDim.new(0, 26)), new("UIStroke", { Color = GOLD, Thickness = 2, Transparency = 0.4 }),
|
||||
})
|
||||
maxText(label({ Position = UDim2.fromOffset(24, 12), Size = UDim2.fromOffset(360, 42), Text = "Your ornaments", TextScaled = true, ZIndex = 5, Parent = left }, 2.5), 34)
|
||||
local sellCount = maxText(label({ Position = UDim2.fromOffset(380, 18), Size = UDim2.fromOffset(366, 32), Text = "", TextScaled = true, FontFace = BODY, TextColor3 = SOFT,
|
||||
TextXAlignment = Enum.TextXAlignment.Right, ZIndex = 5, Parent = left }, 1.5), 20)
|
||||
local sellList = K.scroll(left, UDim2.fromOffset(12, 62), UDim2.fromOffset(750, 494),
|
||||
new("UIGridLayout", { CellSize = UDim2.fromOffset(136, 168), CellPadding = UDim2.fromOffset(10, 10), SortOrder = Enum.SortOrder.LayoutOrder }))
|
||||
new("UIPadding", { PaddingLeft = UDim.new(0, 6), PaddingTop = UDim.new(0, 6), PaddingBottom = UDim.new(0, 6), Parent = sellList })
|
||||
local sellEmpty
|
||||
|
||||
local right = new("Frame", { Position = UDim2.fromOffset(790, 0), Size = UDim2.fromOffset(470, 566), BackgroundColor3 = Color3.new(0, 0, 0), BackgroundTransparency = 0.55, ZIndex = 4, Parent = sellG }, {
|
||||
corner(UDim.new(0, 26)), new("UIStroke", { Color = GOLD, Thickness = 2, Transparency = 0.4 }),
|
||||
})
|
||||
local noSel = K.emptyState({ Position = UDim2.fromOffset(0, 70), Size = UDim2.new(1, 0, 0, 340), ZIndex = 5, Parent = right },
|
||||
"Pick an ornament", "Click an ornament on the left, then set a price — players on all servers will see the listing.")
|
||||
local selBox = new("Frame", { Size = UDim2.fromScale(1, 1), BackgroundTransparency = 1, Visible = false, ZIndex = 5, Parent = right })
|
||||
local selDiscHolder = new("Frame", { Position = UDim2.fromOffset(20, 20), Size = UDim2.fromOffset(130, 130), BackgroundTransparency = 1, ZIndex = 5, Parent = selBox })
|
||||
local selName = maxText(label({ Position = UDim2.fromOffset(166, 24), Size = UDim2.fromOffset(284, 44), Text = "", TextScaled = true, ZIndex = 6, Parent = selBox }, 2.5), 36)
|
||||
local selSub = maxText(label({ Position = UDim2.fromOffset(166, 70), Size = UDim2.fromOffset(284, 28), Text = "", TextScaled = true, ZIndex = 6, Parent = selBox }, 2), 24)
|
||||
local selValue = maxText(label({ Position = UDim2.fromOffset(166, 104), Size = UDim2.fromOffset(284, 44), Text = "", TextScaled = true, TextWrapped = true, FontFace = BODY,
|
||||
TextColor3 = SOFT, ZIndex = 6, Parent = selBox }, 1.5), 20)
|
||||
maxText(label({ Position = UDim2.fromOffset(22, 166), Size = UDim2.fromOffset(300, 32), Text = "Listing price", TextScaled = true, ZIndex = 6, Parent = selBox }, 2), 28)
|
||||
local priceWrap = new("Frame", { Position = UDim2.fromOffset(102, 206), Size = UDim2.fromOffset(266, 64), BackgroundColor3 = NAVY, ZIndex = 6, Parent = selBox }, {
|
||||
corner(UDim.new(0.5, 0)),
|
||||
})
|
||||
local priceStroke = new("UIStroke", { Color = Color3.fromRGB(190, 225, 255), Thickness = 3, Parent = priceWrap })
|
||||
art("crystal", { Position = UDim2.new(0, -8, 0.5, -32), Size = UDim2.fromOffset(64, 64), ZIndex = 7, Parent = priceWrap })
|
||||
local priceBox = new("TextBox", { Position = UDim2.fromOffset(56, 6), Size = UDim2.new(1, -72, 1, -12), BackgroundTransparency = 1, Text = "", PlaceholderText = "price",
|
||||
ClearTextOnFocus = false, FontFace = FONT, TextScaled = true, TextColor3 = WHITE, PlaceholderColor3 = Color3.fromRGB(150, 170, 190), ZIndex = 7, Parent = priceWrap })
|
||||
maxText(priceBox, 38)
|
||||
local sel
|
||||
local function priceNow() local p = tonumber(priceBox.Text); return p and math.floor(p) end
|
||||
local function setPrice(p) priceBox.Text = tostring(math.clamp(math.floor(p), 1, MK.MAX_PRICE)) end
|
||||
local function step() return sel and math.max(1, math.ceil(Config.MinPrice(sel.item) * 0.25)) or 1 end
|
||||
local minus = pill(selBox, { Position = UDim2.fromOffset(20, 206), Size = UDim2.fromOffset(74, 64), ZIndex = 6, TextMax = 40 }, function() setPrice((priceNow() or 0) - step()) end)
|
||||
local plus = pill(selBox, { Position = UDim2.fromOffset(376, 206), Size = UDim2.fromOffset(74, 64), ZIndex = 6, TextMax = 40 }, function() setPrice((priceNow() or 0) + step()) end)
|
||||
minus.set("alt", "-")
|
||||
plus.set("alt", "+")
|
||||
local quickRow = new("Frame", { Position = UDim2.fromOffset(20, 282), Size = UDim2.fromOffset(430, 48), BackgroundTransparency = 1, ZIndex = 6, Parent = selBox }, {
|
||||
new("UIListLayout", { FillDirection = Enum.FillDirection.Horizontal, Padding = UDim.new(0, 10), SortOrder = Enum.SortOrder.LayoutOrder, VerticalAlignment = Enum.VerticalAlignment.Center }),
|
||||
})
|
||||
local quick = {}
|
||||
for k, q in { { "Min", 1 }, { "x2", 2 }, { "x5", 5 }, { "x10", 10 } } do
|
||||
quick[k] = { o = chip(quickRow, { Size = UDim2.fromOffset(100, 46), LayoutOrder = k, ZIndex = 6 }, q[1], function() if sel then setPrice(Config.MinPrice(sel.item) * q[2]) end end), mult = q[2] }
|
||||
end
|
||||
local payout = maxText(label({ Position = UDim2.fromOffset(20, 340), Size = UDim2.fromOffset(430, 32), Text = "", TextScaled = true, FontFace = BODY, TextColor3 = OK,
|
||||
TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 6, Parent = selBox }, 1.5), 22)
|
||||
local listing = false
|
||||
local listBtn
|
||||
local selNote = maxText(label({ Position = UDim2.fromOffset(20, 480), Size = UDim2.fromOffset(430, 66), Text = "", TextScaled = true, TextWrapped = true, FontFace = BODY,
|
||||
TextColor3 = SOFT, TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 6, Parent = selBox }, 1.5), 19)
|
||||
local function paintSell()
|
||||
if not sel then return end
|
||||
local p, minP = priceNow(), Config.MinPrice(sel.item)
|
||||
local bad = (not p) or p < minP or p > MK.MAX_PRICE
|
||||
priceStroke.Color = bad and WARN or Color3.fromRGB(190, 225, 255)
|
||||
payout.Text = p and ("You get " .. fmt(math.floor(p * (1 - MK.TAX))) .. " after " .. TAX .. "%") or "Enter the price as a number"
|
||||
payout.TextColor3 = bad and WARN or OK
|
||||
for _, q in quick do q.o.setSelected(p == minP * q.mult) end
|
||||
selNote.Text = "Listings: " .. mineCount .. " / " .. MK.MAX_LISTINGS .. " · lasts " .. DAYS .. " days · visible on all servers"
|
||||
if listing then listBtn.set("busy")
|
||||
elseif gated() then listBtn.set("off", GATE)
|
||||
elseif mineCount >= MK.MAX_LISTINGS then listBtn.set("off", "All " .. MK.MAX_LISTINGS .. " listing slots are used")
|
||||
elseif not p then listBtn.set("off", "Enter a price")
|
||||
elseif p < minP then listBtn.set("off", "Price from " .. fmt(minP))
|
||||
elseif p > MK.MAX_PRICE then listBtn.set("off", "Max price " .. fmt(MK.MAX_PRICE))
|
||||
else listBtn.set("ready", "List for " .. fmt(p)) end
|
||||
end
|
||||
priceBox:GetPropertyChangedSignal("Text"):Connect(function()
|
||||
local digits = priceBox.Text:gsub("%D", "")
|
||||
if digits ~= priceBox.Text then priceBox.Text = digits return end
|
||||
paintSell()
|
||||
end)
|
||||
local refreshSell, refreshMine
|
||||
listBtn = pill(selBox, { Position = UDim2.fromOffset(20, 384), Size = UDim2.fromOffset(430, 84), ZIndex = 6, TextMax = 34 }, function()
|
||||
if not sel then return end
|
||||
listing = true
|
||||
paintSell()
|
||||
local uid, p = sel.uid, priceNow()
|
||||
task.spawn(function()
|
||||
local res = call("List", uid, p)
|
||||
listing = false
|
||||
ctx.toast(res.msg or (res.ok and "Listed" or "Failed"), res.ok and OK or WARN)
|
||||
if res.ok then
|
||||
K.flash(right, 26)
|
||||
K.floatText(right, "Listed!")
|
||||
sel = nil
|
||||
selBox.Visible, noSel.Visible = false, true
|
||||
mineCount += 1
|
||||
tabs.Mine.setBadge(mineCount)
|
||||
task.spawn(refreshMine)
|
||||
end
|
||||
paintSell()
|
||||
task.defer(refreshSell)
|
||||
end)
|
||||
end)
|
||||
local function select(c, it)
|
||||
sel = { uid = c.Name, item = it }
|
||||
for _, d in selDiscHolder:GetChildren() do d:Destroy() end
|
||||
toyDisc(selDiscHolder, it, 130, UDim2.new(), 6)
|
||||
selName.Text = Config.ToyById[it.Toy].Name
|
||||
local sub, col = subLine(it)
|
||||
selSub.Text, selSub.TextColor3 = sub, col
|
||||
selValue.Text = "Shredder value: " .. fmt(Config.Value(it)) .. "\nmin price: " .. fmt(Config.MinPrice(it))
|
||||
selBox.Visible, noSel.Visible = true, false
|
||||
setPrice(Config.MinPrice(it) * 2)
|
||||
paintSell()
|
||||
end
|
||||
local tiles = {}
|
||||
refreshSell = function()
|
||||
for _, t in tiles do t:Destroy() end
|
||||
tiles = {}
|
||||
if sellEmpty then sellEmpty:Destroy(); sellEmpty = nil end
|
||||
local inv = player:FindFirstChild("OrnamentInventory")
|
||||
local list, onTree = {}, 0
|
||||
for _, c in inv and inv:GetChildren() or {} do
|
||||
if c:GetAttribute("OnTree") then onTree += 1 else table.insert(list, c) end -- toys on the tree can not be sold
|
||||
end
|
||||
table.sort(list, function(x, y)
|
||||
local rx, ry = Config.RarityById[x:GetAttribute("Rarity")], Config.RarityById[y:GetAttribute("Rarity")]
|
||||
if rx.Index ~= ry.Index then return rx.Index > ry.Index end
|
||||
return (x:GetAttribute("Order") or 0) > (y:GetAttribute("Order") or 0)
|
||||
end)
|
||||
sellCount.Text = #list .. " pcs" .. (onTree > 0 and (" · " .. onTree .. " on the tree") or "")
|
||||
if sel and not (inv and inv:FindFirstChild(sel.uid)) then sel = nil; selBox.Visible, noSel.Visible = false, true end
|
||||
if #list == 0 then
|
||||
sellEmpty = K.emptyState({ Position = UDim2.fromOffset(0, 80), Size = UDim2.new(1, 0, 0, 340), ZIndex = 5, Parent = left },
|
||||
"Nothing to sell", "Make ornaments in the generator. Ornaments on the tree can't be sold — take them down first.")
|
||||
return
|
||||
end
|
||||
for k, c in list do
|
||||
local it = { Toy = c:GetAttribute("Toy"), Rarity = c:GetAttribute("Rarity"), Variant = c:GetAttribute("Variant") }
|
||||
local r, v = Config.RarityById[it.Rarity], variantOf(it)
|
||||
local chosen = sel and sel.uid == c.Name
|
||||
local tile = new("TextButton", { Text = "", AutoButtonColor = false, BackgroundColor3 = chosen and Color3.fromRGB(40, 70, 60) or DARK, LayoutOrder = k, ZIndex = 5, Parent = sellList }, {
|
||||
corner(UDim.new(0, 20)), new("UIStroke", { Color = chosen and GOLD or (v and v.Color or r.Color), Thickness = chosen and 5 or 2.5, ApplyStrokeMode = Enum.ApplyStrokeMode.Border }),
|
||||
})
|
||||
local sc = new("UIScale", { Scale = chosen and 1.04 or 1, Parent = tile })
|
||||
toyDisc(tile, it, 92, UDim2.new(0.5, -46, 0, 10), 6)
|
||||
maxText(label({ Position = UDim2.fromOffset(6, 106), Size = UDim2.new(1, -12, 0, 26), Text = Config.ToyById[it.Toy].Name, TextScaled = true,
|
||||
TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 6, Parent = tile }, 2), 22)
|
||||
local sub, col = subLine(it)
|
||||
maxText(label({ Position = UDim2.fromOffset(6, 134), Size = UDim2.new(1, -12, 0, 22), Text = sub, TextScaled = true, TextColor3 = col,
|
||||
TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 6, Parent = tile }, 1.5), 18)
|
||||
local age = os.time() - (c:GetAttribute("Created") or 0)
|
||||
local locked = age < Config.TRADE.MIN_AGE
|
||||
if locked then
|
||||
local lockF = new("Frame", { Size = UDim2.fromScale(1, 1), BackgroundColor3 = Color3.new(0, 0, 0), BackgroundTransparency = 0.12, ZIndex = 8, Parent = tile }, { corner(UDim.new(0, 20)) })
|
||||
maxText(label({ Position = UDim2.fromOffset(8, 34), Size = UDim2.new(1, -16, 0, 100), Text = "🔒\n" .. math.ceil((Config.TRADE.MIN_AGE - age) / 60) .. " min",
|
||||
TextScaled = true, TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 9, Parent = lockF }, 2), 26)
|
||||
end
|
||||
tile.MouseEnter:Connect(function() if not locked then tween(sc, 0.12, { Scale = 1.06 }, Enum.EasingStyle.Back) end end)
|
||||
tile.MouseLeave:Connect(function() tween(sc, 0.12, { Scale = chosen and 1.04 or 1 }) end)
|
||||
tile.InputBegan:Connect(function(i) if K.isPress(i) and not locked then tween(sc, 0.06, { Scale = 0.95 }) end end)
|
||||
tile.Activated:Connect(function()
|
||||
if locked then
|
||||
tween(tile, 0.05, { Rotation = -4 }).Completed:Wait()
|
||||
tween(tile, 0.07, { Rotation = 4 }).Completed:Wait()
|
||||
tween(tile, 0.06, { Rotation = 0 })
|
||||
ctx.toast("New ornaments can be listed in " .. (Config.TRADE.MIN_AGE // 60) .. " min", WARN)
|
||||
return
|
||||
end
|
||||
select(c, it)
|
||||
refreshSell()
|
||||
end)
|
||||
table.insert(tiles, tile)
|
||||
end
|
||||
end
|
||||
|
||||
---------------------------------------------------------------- MY LISTINGS
|
||||
local mineG = ch.makePage("Mine")
|
||||
local slotPlate = new("Frame", { Position = UDim2.fromOffset(4, 2), Size = UDim2.fromOffset(250, 52), BackgroundColor3 = NAVY, ZIndex = 4, Parent = mineG }, {
|
||||
corner(UDim.new(0.5, 0)), new("UIStroke", { Color = GOLD, Thickness = 2 }),
|
||||
})
|
||||
local slotText = maxText(label({ Position = UDim2.fromOffset(14, 8), Size = UDim2.new(1, -28, 1, -16), Text = "", TextScaled = true, TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 5, Parent = slotPlate }, 2), 28)
|
||||
local pipRow = new("Frame", { Position = UDim2.fromOffset(270, 14), Size = UDim2.fromOffset(340, 28), BackgroundTransparency = 1, ZIndex = 4, Parent = mineG }, {
|
||||
new("UIListLayout", { FillDirection = Enum.FillDirection.Horizontal, Padding = UDim.new(0, 6), SortOrder = Enum.SortOrder.LayoutOrder, VerticalAlignment = Enum.VerticalAlignment.Center }),
|
||||
})
|
||||
local slotPips = {}
|
||||
for k = 1, MK.MAX_LISTINGS do
|
||||
slotPips[k] = new("Frame", { Size = UDim2.fromOffset(26, 22), BackgroundColor3 = Color3.new(0, 0, 0), BackgroundTransparency = 0.5, LayoutOrder = k, ZIndex = 4, Parent = pipRow }, {
|
||||
corner(UDim.new(0.5, 0)), new("UIStroke", { Color = WHITE, Thickness = 1.5, Transparency = 0.5 }),
|
||||
})
|
||||
end
|
||||
maxText(label({ Position = UDim2.fromOffset(620, 10), Size = UDim2.fromOffset(632, 36), Text = "Sold listings close on their own — shards arrive automatically", TextScaled = true,
|
||||
FontFace = BODY, TextColor3 = SOFT, TextXAlignment = Enum.TextXAlignment.Right, ZIndex = 4, Parent = mineG }, 1.5), 20)
|
||||
local mineList = K.scroll(mineG, UDim2.fromOffset(0, 66), UDim2.new(1, 0, 0, 500),
|
||||
new("UIListLayout", { Padding = UDim.new(0, 12), SortOrder = Enum.SortOrder.LayoutOrder }))
|
||||
new("UIPadding", { PaddingLeft = UDim.new(0, 4), PaddingRight = UDim.new(0, 18), PaddingTop = UDim.new(0, 4), PaddingBottom = UDim.new(0, 4), Parent = mineList })
|
||||
local mineEmpty
|
||||
local function paintSlots()
|
||||
slotText.Text = "Listings: " .. mineCount .. " / " .. MK.MAX_LISTINGS
|
||||
for k, p in slotPips do
|
||||
local on = k <= mineCount
|
||||
p.BackgroundColor3 = on and GOLD or Color3.new(0, 0, 0)
|
||||
p.BackgroundTransparency = on and 0 or 0.5
|
||||
end
|
||||
tabs.Mine.setBadge(mineCount)
|
||||
end
|
||||
local mineReq = 0
|
||||
refreshMine = function()
|
||||
mineReq += 1
|
||||
local my = mineReq
|
||||
local res = call("Mine")
|
||||
if my ~= mineReq then return end
|
||||
for _, c in mineList:GetChildren() do if c:IsA("GuiObject") then c:Destroy() end end
|
||||
if mineEmpty then mineEmpty:Destroy(); mineEmpty = nil end
|
||||
if not res.ok then slotText.Text = res.msg or "" return end
|
||||
mineCount = #res.items
|
||||
paintSlots()
|
||||
paintSell()
|
||||
if #res.items == 0 then
|
||||
mineEmpty = K.emptyState({ Position = UDim2.fromOffset(0, 70), Size = UDim2.new(1, 0, 0, 420), ZIndex = 4, Parent = mineG },
|
||||
"You haven't listed anything yet", "List an ornament and players on all servers will see it.")
|
||||
local b = pill(mineEmpty, { Position = UDim2.new(0.5, -150, 0, 320), Size = UDim2.fromOffset(300, 64), ZIndex = 5, TextMax = 28 }, function() ch.showTab("Sell") end)
|
||||
b.set("alt", "Sell an ornament")
|
||||
return
|
||||
end
|
||||
for k, l in res.items do
|
||||
local it = l.item
|
||||
local r, v = Config.RarityById[it.Rarity], variantOf(it)
|
||||
local row = new("Frame", { Size = UDim2.new(1, 0, 0, 120), BackgroundColor3 = Color3.new(0, 0, 0), BackgroundTransparency = 0.45, LayoutOrder = k, ZIndex = 5, Parent = mineList }, {
|
||||
corner(UDim.new(0, 26)), new("UIStroke", { Color = v and v.Color or r.Color, Thickness = 2.5 }),
|
||||
})
|
||||
toyDisc(row, it, 96, UDim2.fromOffset(14, 12), 6)
|
||||
maxText(label({ Position = UDim2.fromOffset(128, 12), Size = UDim2.fromOffset(560, 40), Text = Config.ToyById[it.Toy].Name, TextScaled = true, ZIndex = 6, Parent = row }, 2.5), 34)
|
||||
local sub, col = subLine(it)
|
||||
maxText(label({ Position = UDim2.fromOffset(130, 52), Size = UDim2.fromOffset(560, 26), Text = sub, TextScaled = true, TextColor3 = col, ZIndex = 6, Parent = row }, 1.5), 22)
|
||||
local leftS = math.max(0, l.expires - os.time())
|
||||
local frac = math.clamp(leftS / MK.DURATION, 0, 1)
|
||||
local bar = new("Frame", { Position = UDim2.fromOffset(130, 88), Size = UDim2.fromOffset(330, 16), BackgroundColor3 = Color3.fromRGB(10, 20, 26), ZIndex = 6, Parent = row }, {
|
||||
corner(UDim.new(0.5, 0)), new("UIStroke", { Color = WHITE, Thickness = 1.5, Transparency = 0.6 }),
|
||||
})
|
||||
new("Frame", { Size = UDim2.fromScale(math.max(frac, 0.03), 1), BackgroundColor3 = frac > 0.5 and OK or frac > 0.2 and GOLD or WARN, ZIndex = 7, Parent = bar }, { corner(UDim.new(0.5, 0)) })
|
||||
maxText(label({ Position = UDim2.fromOffset(474, 82), Size = UDim2.fromOffset(230, 28), Text = "left: " .. fmtLeft(leftS), TextScaled = true, FontFace = BODY,
|
||||
TextColor3 = SOFT, ZIndex = 6, Parent = row }, 1.5), 20)
|
||||
local _, price = pricePlate(row, UDim2.fromOffset(726, 34), UDim2.fromOffset(190, 52), 6)
|
||||
price.Text = fmt(l.price)
|
||||
local btn
|
||||
btn = pill(row, { Position = UDim2.fromOffset(940, 26), Size = UDim2.fromOffset(280, 68), ZIndex = 6, TextMax = 30 }, function()
|
||||
btn.set("busy")
|
||||
task.spawn(function()
|
||||
local r2 = call("Cancel", l.id)
|
||||
ctx.toast(r2.msg or "", r2.ok and OK or WARN)
|
||||
if r2.ok then K.floatText(row, "Ornament returned") end
|
||||
task.delay(r2.ok and 0.8 or 0.2, refreshMine)
|
||||
end)
|
||||
end)
|
||||
btn.set("danger", "Remove listing")
|
||||
end
|
||||
end
|
||||
|
||||
---------------------------------------------------------------- HELP
|
||||
local _, heScroll = ch.makePage("Help", true)
|
||||
new("UIGridLayout", { CellSize = UDim2.fromOffset(404, 540), CellPadding = UDim2.fromOffset(20, 18), SortOrder = Enum.SortOrder.LayoutOrder, Parent = heScroll })
|
||||
new("UIPadding", { PaddingLeft = UDim.new(0, 4), PaddingTop = UDim.new(0, 4), Parent = heScroll })
|
||||
local HELP = {
|
||||
{ card = "cardCyan", icon = "🛒", title = "Buy", tab = "Buy",
|
||||
text = "Listings from players on all servers. Filter by ornament and rarity. The first click on “Buy” prepares the purchase, the second confirms it." },
|
||||
{ card = "cardViolet", icon = "💰", title = "Sell", tab = "Sell",
|
||||
text = "Pick an ornament and set a price — no lower than its shredder value. New ornaments can be listed " .. (Config.TRADE.MIN_AGE // 60) .. " min after they are made." },
|
||||
{ card = "cardOrange", icon = "📦", title = "My Listings", tab = "Mine",
|
||||
text = "Tax " .. TAX .. "% per sale. A listing lasts " .. DAYS .. " days, then the ornament comes back. Shards arrive even if you're offline. Up to " .. MK.MAX_LISTINGS .. " listings at once." },
|
||||
}
|
||||
for i, h in HELP do
|
||||
local card = art(h.card, { LayoutOrder = i, ScaleType = Enum.ScaleType.Slice, SliceCenter = K.CARD_SLICE, ZIndex = 4, Parent = heScroll })
|
||||
label({ AnchorPoint = Vector2.new(0.5, 0), Position = UDim2.new(0.5, 0, 0, 44), Size = UDim2.fromOffset(120, 110), Text = h.icon, TextSize = 84, TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 5, Parent = card }, 0)
|
||||
maxText(label({ Position = UDim2.fromOffset(24, 160), Size = UDim2.new(1, -48, 0, 50), Text = h.title, TextScaled = true, TextXAlignment = Enum.TextXAlignment.Center, ZIndex = 5, Parent = card }, 3), 42)
|
||||
maxText(label({ Position = UDim2.fromOffset(30, 218), Size = UDim2.new(1, -60, 0, 190), Text = h.text, TextScaled = true, TextWrapped = true, FontFace = BODY,
|
||||
TextColor3 = WHITE, TextXAlignment = Enum.TextXAlignment.Center, TextYAlignment = Enum.TextYAlignment.Top, ZIndex = 5, Parent = card }, 1.5), 24)
|
||||
local go = pill(card, { Position = UDim2.fromOffset(62, 420), Size = UDim2.fromOffset(280, 70), ZIndex = 5, TextMax = 30 }, function() ch.showTab(h.tab) end)
|
||||
go.set("alt", "Open")
|
||||
end
|
||||
|
||||
---------------------------------------------------------------- tab switching + live updates
|
||||
local function gateTip(id)
|
||||
if gated() and id ~= "Help" then
|
||||
ch.tip.Text = "🔒 Buying and selling unlocks at level " .. MK.MIN_LEVEL .. " — you can browse right now."
|
||||
ch.tip.TextColor3 = WARN
|
||||
end
|
||||
end
|
||||
onTab = function(id)
|
||||
if not win.overlay.Visible then return end
|
||||
ch.setBalance(attr("Shards", 0))
|
||||
gateTip(id)
|
||||
if id == "Buy" then refreshBuy()
|
||||
elseif id == "Sell" then refreshSell(); paintSell()
|
||||
elseif id == "Mine" then task.spawn(refreshMine) end
|
||||
end
|
||||
local function repaint()
|
||||
if not win.overlay.Visible then return end
|
||||
ch.setBalance(attr("Shards", 0))
|
||||
for _, c in buyCards do c.paint() end
|
||||
paintSell()
|
||||
end
|
||||
player:GetAttributeChangedSignal("Shards"):Connect(repaint)
|
||||
player:GetAttributeChangedSignal("Level"):Connect(function() repaint(); if win.overlay.Visible then ch.showTab(ch.current(), true) end end)
|
||||
task.spawn(function()
|
||||
local inv = player:WaitForChild("OrnamentInventory")
|
||||
local queued = false
|
||||
local function changed()
|
||||
if queued or not (win.overlay.Visible and ch.current() == "Sell") then return end
|
||||
queued = true
|
||||
task.delay(0.15, function() queued = false; refreshSell(); paintSell() end)
|
||||
end
|
||||
inv.ChildAdded:Connect(changed)
|
||||
inv.ChildRemoved:Connect(changed)
|
||||
end)
|
||||
paintFilters()
|
||||
paintSlots()
|
||||
ch.showTab("Buy")
|
||||
|
||||
return {
|
||||
open = function()
|
||||
ch.setBalance(attr("Shards", 0), true)
|
||||
ch.showTab(ch.current(), true)
|
||||
if ch.current() ~= "Mine" then task.spawn(refreshMine) end -- slot count + badge
|
||||
end,
|
||||
showTab = ch.showTab,
|
||||
}
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in new issue
Block a user