feat(bunsik): 화면 UI 개편 — 상점 탭 4개(업그레이드 갈래·꾸미기·알바생·내 가게), 꾸미기(배치) 화면, 홍보·손님 러시 버튼, 추천 구매 막대, 쫓아내기 버튼, 가게 이름·무지개 이름판, 4개 언어
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
266
bunsik-tycoon/src/client/Info.luau
Normal file
266
bunsik-tycoon/src/client/Info.luau
Normal file
@@ -0,0 +1,266 @@
|
||||
--!strict
|
||||
-- 화면 여러 곳(HUD, 상점 창, 요리 창, 꾸미기)에서 같이 쓰는 것:
|
||||
-- 플레이어 속성(NETWORK.md)에서 갈래 레벨·능력치·알바·배치 읽기,
|
||||
-- 업그레이드·물건별 그림(아이콘 그림에 없는 것은 이모지), 다음 단계 효과 글, 알림 글.
|
||||
|
||||
local HttpService = game:GetService("HttpService")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
|
||||
local Shared = ReplicatedStorage:WaitForChild("Shared")
|
||||
local Codec = require(Shared:WaitForChild("Codec"))
|
||||
local Economy = require(Shared:WaitForChild("Economy"))
|
||||
local Floor = require(Shared:WaitForChild("Floor"))
|
||||
local Icons = require(Shared:WaitForChild("Icons"))
|
||||
local Locale = require(Shared:WaitForChild("Locale"))
|
||||
local Products = require(Shared:WaitForChild("Products"))
|
||||
local Theme = require(script.Parent:WaitForChild("Theme"))
|
||||
|
||||
local Info = {}
|
||||
|
||||
function Info.attr(state: Instance, key: string, default: any): any
|
||||
local v = state:GetAttribute(key)
|
||||
if v == nil then
|
||||
return default
|
||||
end
|
||||
return v
|
||||
end
|
||||
|
||||
function Info.levels(state: Instance): Economy.Levels
|
||||
return Economy.cleanLevels(Codec.decodeMap(state:GetAttribute("Levels")))
|
||||
end
|
||||
|
||||
function Info.stats(state: Instance): Economy.Stats
|
||||
return Economy.stats(Info.levels(state), Info.attr(state, "Seats", 1))
|
||||
end
|
||||
|
||||
function Info.staff(state: Instance): { [string]: number }
|
||||
return Codec.decodeMap(state:GetAttribute("Staff"))
|
||||
end
|
||||
|
||||
function Info.layout(state: Instance): Floor.Layout
|
||||
local raw = state:GetAttribute("Layout")
|
||||
local decoded = nil
|
||||
if typeof(raw) == "string" and raw ~= "" then
|
||||
local ok, v = pcall(function()
|
||||
return HttpService:JSONDecode(raw)
|
||||
end)
|
||||
if ok then
|
||||
decoded = v
|
||||
end
|
||||
end
|
||||
return Floor.clean(decoded)
|
||||
end
|
||||
|
||||
function Info.now(): number
|
||||
return workspace:GetServerTimeNow()
|
||||
end
|
||||
|
||||
-- 초 → "2:05"
|
||||
function Info.clock(sec: number): string
|
||||
local s = math.max(0, math.ceil(sec))
|
||||
return string.format("%d:%02d", s // 60, s % 60)
|
||||
end
|
||||
|
||||
-- 1.25 → "1.25", 2 → "2"
|
||||
function Info.num(n: number): string
|
||||
return (string.format("%.2f", n):gsub("%.?0+$", ""))
|
||||
end
|
||||
|
||||
-- 그림: 아이콘 그림 이름(Icons.OFFSET) 또는 이모지
|
||||
Info.TRACK_ICON = {
|
||||
Stage = "store",
|
||||
Menu = "star",
|
||||
Price = "sauce",
|
||||
Speed = "sign",
|
||||
Stove = "flame",
|
||||
Tray = "tray",
|
||||
Staff = "chef",
|
||||
} :: { [string]: string }
|
||||
|
||||
Info.ROLE_ICON = { Cook = "chef", Server = "tray", Promoter = "📣" } :: { [string]: string }
|
||||
|
||||
Info.DECOR_ICON = {
|
||||
Plant = "🪴",
|
||||
Rug = "🧶",
|
||||
Balloons = "🎈",
|
||||
Lamp = "💡",
|
||||
Teddy = "🧸",
|
||||
Fridge = "🧊",
|
||||
} :: { [string]: string }
|
||||
|
||||
Info.SEAT_ICON = "🪑"
|
||||
|
||||
-- 로벅스 가격(배지 글자용, Products 키별). 실제 가격은 로블록스 상품 설정이 원본입니다.
|
||||
Info.ROBUX = {
|
||||
RAINBOW_NAME_PASS = 99,
|
||||
CANDY_DESIGN_PASS = 149,
|
||||
HANOK_DESIGN_PASS = 149,
|
||||
RUSH_PRODUCT = 15,
|
||||
KICK_PRODUCT = 15,
|
||||
} :: { [string]: number }
|
||||
|
||||
-- 그 상품이 열려 있으면 "R$99" 같은 배지 글자, 아니면 nil
|
||||
function Info.robux(productKey: string): string?
|
||||
local id = (Products :: any)[productKey]
|
||||
if typeof(id) ~= "number" or id == 0 then
|
||||
return nil
|
||||
end
|
||||
local price = Info.ROBUX[productKey]
|
||||
return if price then `R${price}` else "R$"
|
||||
end
|
||||
|
||||
-- 디자인 견본 색(벽, 지붕, 테두리). 서버 PlotBuilder.PALETTES와 같은 색
|
||||
Info.DESIGN_COLORS = {
|
||||
Basic = { Color3.fromRGB(250, 236, 205), Color3.fromRGB(150, 70, 55), Color3.fromRGB(240, 110, 40) },
|
||||
Mint = { Color3.fromRGB(214, 245, 234), Color3.fromRGB(70, 150, 130), Color3.fromRGB(120, 210, 190) },
|
||||
Brick = { Color3.fromRGB(178, 92, 70), Color3.fromRGB(70, 62, 62), Color3.fromRGB(215, 55, 50) },
|
||||
Candy = { Color3.fromRGB(255, 205, 228), Color3.fromRGB(196, 160, 255), Color3.fromRGB(255, 120, 170) },
|
||||
Hanok = { Color3.fromRGB(246, 236, 214), Color3.fromRGB(58, 64, 76), Color3.fromRGB(150, 40, 35) },
|
||||
} :: { [string]: { Color3 } }
|
||||
|
||||
-- 갈래 그림. 메뉴 갈래는 다음에 열리는 메뉴 그림
|
||||
function Info.trackIcon(levels: Economy.Levels, id: string): string
|
||||
if id == "Menu" then
|
||||
local nl = Economy.nextLevel(levels, id)
|
||||
if nl then
|
||||
return nl.value :: string
|
||||
end
|
||||
end
|
||||
return Info.TRACK_ICON[id] or "star"
|
||||
end
|
||||
|
||||
function Info.offerIcon(levels: Economy.Levels, offer: Economy.Offer): string
|
||||
if offer.id == "Seat" then
|
||||
return Info.SEAT_ICON
|
||||
elseif offer.id == "Table" then
|
||||
return "table"
|
||||
end
|
||||
return Info.trackIcon(levels, offer.id)
|
||||
end
|
||||
|
||||
-- 다음 단계가 하는 일(짧은 글). 다 샀으면 nil
|
||||
function Info.effect(lang: string, levels: Economy.Levels, id: string): string?
|
||||
local nl = Economy.nextLevel(levels, id)
|
||||
if not nl then
|
||||
return nil
|
||||
end
|
||||
local st = Economy.stats(levels, 1)
|
||||
local v = nl.value
|
||||
if id == "Stage" then
|
||||
return Locale.t(lang, "fx_Stage", {
|
||||
from = Locale.t(lang, `stage_{st.stage}`),
|
||||
to = Locale.t(lang, `stage_{v}`),
|
||||
})
|
||||
elseif id == "Menu" then
|
||||
return Locale.t(lang, "fx_Menu", { menuName = Locale.menuName(lang, v) })
|
||||
elseif id == "Price" then
|
||||
return Locale.t(lang, "fx_Price", { from = Info.num(st.price), to = Info.num(v) })
|
||||
elseif id == "Speed" then
|
||||
return Locale.t(lang, "fx_Speed", { from = Info.num(st.spawn), to = Info.num(v) })
|
||||
elseif id == "Stove" then
|
||||
local function pct(c: number): string
|
||||
return tostring(math.floor(c / Economy.START_COOK * 100 + 0.5))
|
||||
end
|
||||
return Locale.t(lang, "fx_Stove", { from = pct(st.cook), to = pct(v) })
|
||||
elseif id == "Tray" then
|
||||
return Locale.t(lang, "fx_Tray", { from = st.carry, to = v })
|
||||
end
|
||||
return Locale.t(lang, "fx_" .. id)
|
||||
end
|
||||
|
||||
-- 화면 아래 추천 막대 이름
|
||||
function Info.offerName(lang: string, levels: Economy.Levels, offer: Economy.Offer): string
|
||||
if offer.id == "Seat" or offer.id == "Table" then
|
||||
return Locale.t(lang, "thing_" .. offer.id)
|
||||
end
|
||||
local nl = Economy.nextLevel(levels, offer.id)
|
||||
if offer.id == "Menu" and nl then
|
||||
return Locale.t(lang, "fx_Menu", { menuName = Locale.menuName(lang, nl.value) })
|
||||
elseif offer.id == "Stage" and nl then
|
||||
return Locale.t(lang, `stage_{nl.value}`)
|
||||
end
|
||||
return `{Locale.t(lang, "track_" .. offer.id)} Lv{Economy.level(levels, offer.id) + 1}`
|
||||
end
|
||||
|
||||
-- 알림 글. 서버는 메뉴·갈래·역할·소품·디자인을 id로 보내고, 이름은 내 언어로 바꿔 씁니다.
|
||||
function Info.toast(lang: string, key: string, args: { [string]: any }?): string
|
||||
local a: { [string]: any }? = nil
|
||||
if args then
|
||||
local t = table.clone(args)
|
||||
if typeof(t.menu) == "string" then
|
||||
t.menuName = Locale.menuName(lang, t.menu)
|
||||
end
|
||||
if typeof(t.track) == "string" then
|
||||
t.name = Locale.t(lang, "track_" .. t.track)
|
||||
end
|
||||
if typeof(t.role) == "string" then
|
||||
t.name = Locale.t(lang, "role_" .. t.role)
|
||||
end
|
||||
if typeof(t.kind) == "string" then
|
||||
t.name = Locale.t(lang, "decor_" .. t.kind)
|
||||
end
|
||||
if typeof(t.design) == "string" then
|
||||
t.name = Locale.t(lang, "design_" .. t.design)
|
||||
end
|
||||
if typeof(t.why) == "string" then
|
||||
t.reason = Locale.t(lang, "why_" .. t.why)
|
||||
end
|
||||
a = t
|
||||
end
|
||||
return Locale.t(lang, key, a)
|
||||
end
|
||||
|
||||
-- 아이콘 그림 또는 이모지를 같은 자리에 보여 주는 칸
|
||||
export type Glyph = {
|
||||
frame: Frame,
|
||||
image: ImageLabel,
|
||||
emoji: TextLabel,
|
||||
set: (key: string) -> (),
|
||||
fade: (transparency: number) -> (),
|
||||
zindex: (z: number) -> (),
|
||||
}
|
||||
|
||||
function Info.glyph(parent: Instance, name: string, key: string): Glyph
|
||||
local f = Theme.frame(parent, name)
|
||||
local ratio = Instance.new("UIAspectRatioConstraint")
|
||||
ratio.AspectRatio = 1
|
||||
ratio.Parent = f
|
||||
local img = Theme.icon(f, "Image", "star")
|
||||
img.Size = UDim2.fromScale(1, 1)
|
||||
local emoji = Theme.text(f, "Emoji")
|
||||
emoji.Size = UDim2.fromScale(0.86, 0.86)
|
||||
emoji.Position = UDim2.fromScale(0.07, 0.07)
|
||||
emoji.TextColor3 = Theme.WHITE
|
||||
local function set(k: string)
|
||||
local offset: Vector2? = Icons.OFFSET[k]
|
||||
local isIcon = offset ~= nil
|
||||
img.Visible = isIcon
|
||||
emoji.Visible = not isIcon
|
||||
if isIcon then
|
||||
Icons.apply(img, k)
|
||||
else
|
||||
emoji.Text = k
|
||||
end
|
||||
end
|
||||
set(key)
|
||||
local function zindex(z: number)
|
||||
f.ZIndex = z
|
||||
img.ZIndex = z
|
||||
emoji.ZIndex = z
|
||||
end
|
||||
-- 처음에는 부모 위에 보이게
|
||||
zindex(if parent:IsA("GuiObject") then parent.ZIndex + 1 else 1)
|
||||
return {
|
||||
frame = f,
|
||||
image = img,
|
||||
emoji = emoji,
|
||||
set = set,
|
||||
fade = function(t: number)
|
||||
img.ImageTransparency = t
|
||||
emoji.TextTransparency = t
|
||||
end,
|
||||
zindex = zindex,
|
||||
}
|
||||
end
|
||||
|
||||
return Info
|
||||
Reference in New Issue
Block a user