Files
roblox-project/bunsik-tycoon/src/client/Hud.luau
EJClaw 4d861b8fd3 feat(bunsik): 이웃 가게·손님 방문 멀티플레이, 4개 언어, 설정 창, 마우스 회전, 김밥 해금 효과
- 빈 부지에 NPC 사장님이 운영하는 이웃 가게(크기 제각각), 플레이어가 오면 그 자리를 넘겨줌
- 다른 가게 입구에서 손님으로 앉기: 주인은 2배 값, 손님은 시식 보너스(1분에 한 번)
- 한국어·영어·일본어·중국어(계정 언어 자동 선택), 이름판·메뉴판은 보는 사람 언어로
- 오른쪽 위 언어 버튼을 설정 창으로: 언어, 마우스로 화면 돌리기(PC 기본 켜짐), 효과음
- 메뉴 해금 시 진열대 모형이 생기고 다음 손님이 바로 새 메뉴를 주문
- 통합 테스트 600개 통과

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 05:37:46 +09:00

582 lines
18 KiB
Lua
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
--!strict
-- 화면 UI: 돈, 다음 업그레이드, 업그레이드 목록, 2배 수익·돈 부스트 버튼, 설정(언어·마우스 회전·효과음), 안내 문구, 알림.
-- 상태는 `state` 인스턴스(실제 게임에서는 Player)의 속성에서 읽습니다. 서버에서도 만들 수 있어서 원격 테스트로 검사합니다.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local Shared = ReplicatedStorage:WaitForChild("Shared")
local Economy = require(Shared:WaitForChild("Economy"))
local Locale = require(Shared:WaitForChild("Locale"))
local Products = require(Shared:WaitForChild("Products"))
local Hud = {}
export type HudHandle = {
gui: ScreenGui,
refresh: () -> (),
notify: (key: string, args: { [string]: any }?) -> (),
setScale: (number) -> (),
menuOpen: () -> boolean, -- 업그레이드·설정 창이 열려 있으면 true(마우스 커서를 풀어 줌)
destroy: () -> (),
}
local ORANGE = Color3.fromRGB(255, 130, 50)
local GREEN = Color3.fromRGB(70, 190, 90)
local GRAY = Color3.fromRGB(150, 150, 150)
local DARK = Color3.fromRGB(45, 35, 35)
local CREAM = Color3.fromRGB(255, 248, 235)
local function corner(parent: Instance, r: number)
local c = Instance.new("UICorner")
c.CornerRadius = UDim.new(0, r)
c.Parent = parent
end
local function stroke(parent: Instance, color: Color3, thickness: number): UIStroke
local s = Instance.new("UIStroke")
s.Color = color
s.Thickness = thickness
s.ApplyStrokeMode = Enum.ApplyStrokeMode.Border
s.Parent = parent
return s
end
local function frame(parent: Instance, name: string, size: UDim2, pos: UDim2, anchor: Vector2, color: Color3?): Frame
local f = Instance.new("Frame")
f.Name = name
f.Size = size
f.Position = pos
f.AnchorPoint = anchor
f.BackgroundColor3 = color or CREAM
f.BackgroundTransparency = if color then 0 else 1
f.BorderSizePixel = 0
f.Parent = parent
return f
end
local function text(parent: Instance, name: string, size: UDim2, pos: UDim2, color: Color3?): TextLabel
local t = Instance.new("TextLabel")
t.Name = name
t.Size = size
t.Position = pos
t.BackgroundTransparency = 1
t.TextColor3 = color or DARK
t.Font = Enum.Font.FredokaOne
t.TextScaled = true
t.AutoLocalize = false
t.Text = ""
t.Parent = parent
return t
end
local function button(
parent: Instance,
name: string,
size: UDim2,
pos: UDim2,
anchor: Vector2,
color: Color3
): TextButton
local b = Instance.new("TextButton")
b.Name = name
b.Size = size
b.Position = pos
b.AnchorPoint = anchor
b.BackgroundColor3 = color
b.TextColor3 = Color3.new(1, 1, 1)
b.Font = Enum.Font.FredokaOne
b.TextScaled = true
b.AutoLocalize = false
b.AutoButtonColor = true
b.Text = ""
b.Parent = parent
corner(b, 14)
stroke(b, Color3.fromRGB(255, 255, 255), 3)
local pad = Instance.new("UIPadding")
pad.PaddingTop = UDim.new(0.14, 0)
pad.PaddingBottom = UDim.new(0.14, 0)
pad.PaddingLeft = UDim.new(0, 8)
pad.PaddingRight = UDim.new(0, 8)
pad.Parent = b
return b
end
local function attr(state: Instance, key: string, default: any): any
local v = state:GetAttribute(key)
if v == nil then
return default
end
return v
end
function Hud.build(parent: Instance, state: Instance, send: (string, any?) -> ()): HudHandle
local gui = Instance.new("ScreenGui")
gui.Name = "BunsikHud"
gui.ResetOnSpawn = false
gui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
gui.Parent = parent
local root = frame(gui, "Root", UDim2.fromScale(1, 1), UDim2.fromScale(0, 0), Vector2.zero)
local scale = Instance.new("UIScale")
scale.Parent = root
-- UIScale은 자식 크기를 키우므로, 기준 화면(1100x620) 크기의 루트에 붙이고 가운데에 둡니다.
root.Size = UDim2.fromOffset(1100, 620)
root.AnchorPoint = Vector2.new(0.5, 0.5)
root.Position = UDim2.fromScale(0.5, 0.5)
-- 돈
local money = frame(root, "Money", UDim2.fromOffset(300, 62), UDim2.new(0.5, 0, 0, 6), Vector2.new(0.5, 0), ORANGE)
corner(money, 31)
stroke(money, Color3.new(1, 1, 1), 4)
local moneyText = text(money, "Text", UDim2.new(1, -24, 1, -14), UDim2.fromOffset(12, 7), Color3.new(1, 1, 1))
local carry = text(root, "Carry", UDim2.fromOffset(160, 28), UDim2.new(0.5, -80, 0, 72), DARK)
-- 안내 문구(튜토리얼)
local hint = frame(
root,
"Hint",
UDim2.fromOffset(640, 54),
UDim2.new(0.5, 0, 0, 104),
Vector2.new(0.5, 0),
Color3.fromRGB(255, 235, 120)
)
corner(hint, 14)
stroke(hint, ORANGE, 3)
local hintText = text(hint, "Text", UDim2.new(1, -20, 1, -10), UDim2.fromOffset(10, 5))
-- 알림
local toasts = frame(root, "Toasts", UDim2.fromOffset(560, 200), UDim2.new(0.5, 0, 0, 166), Vector2.new(0.5, 0))
local list = Instance.new("UIListLayout")
list.HorizontalAlignment = Enum.HorizontalAlignment.Center
list.Padding = UDim.new(0, 6)
list.Parent = toasts
-- 다음 업그레이드 카드(아래 가운데)
local card = frame(root, "Next", UDim2.fromOffset(500, 96), UDim2.new(0.5, 0, 1, -8), Vector2.new(0.5, 1), CREAM)
corner(card, 18)
stroke(card, ORANGE, 4)
local cardTitle = text(card, "Title", UDim2.new(1, -170, 0, 40), UDim2.fromOffset(14, 8))
cardTitle.TextXAlignment = Enum.TextXAlignment.Left
local cardCost =
text(card, "Cost", UDim2.new(1, -170, 0, 26), UDim2.fromOffset(14, 48), Color3.fromRGB(120, 90, 60))
cardCost.TextXAlignment = Enum.TextXAlignment.Left
local barBg = frame(
card,
"Bar",
UDim2.new(1, -170, 0, 10),
UDim2.fromOffset(14, 78),
Vector2.zero,
Color3.fromRGB(230, 220, 200)
)
corner(barBg, 5)
local barFill = frame(barBg, "Fill", UDim2.fromScale(0, 1), UDim2.fromScale(0, 0), Vector2.zero, GREEN)
corner(barFill, 5)
local buyBtn = button(card, "Buy", UDim2.fromOffset(140, 72), UDim2.new(1, -12, 0.5, 0), Vector2.new(1, 0.5), GREEN)
local buyStroke = buyBtn:FindFirstChildOfClass("UIStroke") :: UIStroke
-- 업그레이드 목록 버튼과 창
local listBtn =
button(root, "ListButton", UDim2.fromOffset(150, 56), UDim2.new(1, -10, 0.5, -40), Vector2.new(1, 0.5), ORANGE)
local panel =
frame(root, "Panel", UDim2.fromOffset(520, 430), UDim2.fromScale(0.5, 0.48), Vector2.new(0.5, 0.5), CREAM)
panel.Visible = false
corner(panel, 20)
stroke(panel, ORANGE, 4)
local panelTitle = text(panel, "Title", UDim2.new(1, -120, 0, 44), UDim2.fromOffset(16, 10))
panelTitle.TextXAlignment = Enum.TextXAlignment.Left
local closeBtn = button(
panel,
"Close",
UDim2.fromOffset(90, 42),
UDim2.new(1, -12, 0, 10),
Vector2.new(1, 0),
Color3.fromRGB(220, 80, 70)
)
local scroll = Instance.new("ScrollingFrame")
scroll.Name = "List"
scroll.Size = UDim2.new(1, -24, 1, -70)
scroll.Position = UDim2.fromOffset(12, 62)
scroll.BackgroundTransparency = 1
scroll.BorderSizePixel = 0
scroll.ScrollBarThickness = 8
scroll.AutomaticCanvasSize = Enum.AutomaticSize.Y
scroll.CanvasSize = UDim2.new()
scroll.Parent = panel
local rows = Instance.new("UIListLayout")
rows.Padding = UDim.new(0, 6)
rows.SortOrder = Enum.SortOrder.LayoutOrder
rows.Parent = scroll
-- 왼쪽: 2배 수익, 돈 부스트
local passBtn = button(
root,
"Double",
UDim2.fromOffset(170, 64),
UDim2.new(0, 10, 0.5, -40),
Vector2.new(0, 0.5),
Color3.fromRGB(150, 80, 220)
)
local boostBtn = button(
root,
"Boost",
UDim2.fromOffset(170, 64),
UDim2.new(0, 10, 0.5, 34),
Vector2.new(0, 0.5),
Color3.fromRGB(240, 170, 30)
)
-- 개발자(게임 주인)만 보는 테스트 버튼
local dev = frame(
root,
"Dev",
UDim2.fromOffset(170, 150),
UDim2.new(0, 10, 0.5, 80),
Vector2.new(0, 0),
Color3.fromRGB(40, 40, 50)
)
dev.BackgroundTransparency = 0.3
corner(dev, 12)
local devTitle = text(dev, "Title", UDim2.new(1, -10, 0, 22), UDim2.fromOffset(5, 4), Color3.new(1, 1, 1))
local devButtons: { [string]: TextButton } = {}
for i, key in { "devMoney", "devDouble", "devReset" } do
local b = button(
dev,
key,
UDim2.new(1, -16, 0, 34),
UDim2.fromOffset(8, 30 + (i - 1) * 39),
Vector2.zero,
Color3.fromRGB(90, 90, 110)
)
devButtons[key] = b
end
-- 오른쪽 위: 설정 버튼과 설정 창(언어, 마우스로 화면 돌리기, 효과음)
local settingsBtn = button(
root,
"Settings",
UDim2.fromOffset(130, 44),
UDim2.new(1, -10, 0, 6),
Vector2.new(1, 0),
Color3.fromRGB(80, 140, 230)
)
local settings = frame(
root,
"SettingsPanel",
UDim2.fromOffset(520, 330),
UDim2.fromScale(0.5, 0.48),
Vector2.new(0.5, 0.5),
CREAM
)
settings.Visible = false
corner(settings, 20)
stroke(settings, Color3.fromRGB(80, 140, 230), 4)
local settingsTitle = text(settings, "Title", UDim2.new(1, -120, 0, 44), UDim2.fromOffset(16, 10))
settingsTitle.TextXAlignment = Enum.TextXAlignment.Left
local settingsClose = button(
settings,
"Close",
UDim2.fromOffset(90, 42),
UDim2.new(1, -12, 0, 10),
Vector2.new(1, 0),
Color3.fromRGB(220, 80, 70)
)
local function rowLabel(name: string, y: number): TextLabel
local t = text(settings, name, UDim2.new(1, -32, 0, 30), UDim2.fromOffset(16, y))
t.TextXAlignment = Enum.TextXAlignment.Left
return t
end
local langLabel = rowLabel("LangLabel", 64)
-- 언어 버튼: 자동("") + 네 언어
local langChoices = { "" }
for _, l in Locale.LANGS do
table.insert(langChoices, l)
end
local langButtons: { [string]: TextButton } = {}
for i, l in langChoices do
local b = button(
settings,
"Lang_" .. (if l == "" then "auto" else l),
UDim2.fromOffset(92, 44),
UDim2.fromOffset(16 + (i - 1) * 98, 100),
Vector2.zero,
GRAY
)
langButtons[l] = b
end
local mouseLabel = rowLabel("MouseLabel", 160)
local mouseBtn =
button(settings, "MouseLook", UDim2.fromOffset(110, 40), UDim2.new(1, -16, 0, 156), Vector2.new(1, 0), GRAY)
mouseLabel.Size = UDim2.new(1, -150, 0, 30)
local mouseHint =
text(settings, "MouseHint", UDim2.new(1, -32, 0, 22), UDim2.fromOffset(16, 200), Color3.fromRGB(120, 90, 60))
mouseHint.TextXAlignment = Enum.TextXAlignment.Left
local sfxLabel = rowLabel("SfxLabel", 246)
sfxLabel.Size = UDim2.new(1, -150, 0, 30)
local sfxBtn =
button(settings, "Sfx", UDim2.fromOffset(110, 40), UDim2.new(1, -16, 0, 242), Vector2.new(1, 0), GRAY)
local function lang(): string
return attr(state, "Lang", "ko")
end
local function L(key: string, args: { [string]: any }?): string
return Locale.t(lang(), key, args)
end
local function pname(p: Economy.Purchase): string
return Locale.itemName(lang(), p.id)
end
local function toggle(b: TextButton, on: boolean)
b.Text = L(if on then "on" else "off")
b.BackgroundColor3 = if on then GREEN else GRAY
end
local pulse: Tween? = nil
local listKey = ""
local function refresh()
local m = attr(state, "Money", 0)
local bought = attr(state, "Bought", 0)
local stats = Economy.statsAt(bought)
moneyText.Text = "💰 " .. L("money", { money = Locale.number(m) })
local held = attr(state, "Carry", 0)
carry.Text = if held > 0 then `🍽️ {held}/{stats.carry}` else ""
local nextP = Economy.PURCHASES[bought + 1]
if nextP then
cardTitle.Text = `{L("next")}: {pname(nextP)}`
cardCost.Text = L("money", { money = Locale.number(nextP.cost) })
barFill.Size = UDim2.fromScale(math.clamp(m / nextP.cost, 0, 1), 1)
local can = m >= nextP.cost
buyBtn.Text = L("buy")
buyBtn.BackgroundColor3 = if can then GREEN else GRAY
buyBtn.Visible = true
else
cardTitle.Text = L("maxed")
cardCost.Text = ""
barFill.Size = UDim2.fromScale(1, 1)
buyBtn.Visible = false
end
-- 튜토리얼 안내
local tut = attr(state, "Tut", 0)
if tut == 1 or tut == 2 or tut == 3 then
hint.Visible = true
hintText.Text = L("tut" .. tut)
else
hint.Visible = false
end
if tut == 3 and not pulse then
buyStroke.Color = Color3.fromRGB(255, 220, 0)
local tw = TweenService:Create(
buyStroke,
TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, -1, true),
{ Thickness = 9 }
)
tw:Play()
pulse = tw
elseif tut ~= 3 and pulse then
pulse:Cancel()
pulse = nil
buyStroke.Thickness = 3
buyStroke.Color = Color3.new(1, 1, 1)
end
dev.Visible = attr(state, "Dev", false) == true
devTitle.Text = "🛠 " .. L("devTitle")
for key, b in devButtons do
b.Text = L(key)
end
listBtn.Text = "📋 " .. L("shop")
settingsBtn.Text = "⚙️ " .. L("settings")
closeBtn.Text = L("close")
settingsTitle.Text = "⚙️ " .. L("settings")
settingsClose.Text = L("close")
langLabel.Text = "🌐 " .. L("language")
local current = attr(state, "LangSetting", "")
for l, b in langButtons do
b.Text = if l == "" then L("langAuto") else Locale.LANG_NAMES[l]
b.BackgroundColor3 = if l == current then Color3.fromRGB(80, 140, 230) else GRAY
end
mouseLabel.Text = "🖱️ " .. L("mouseLook")
mouseHint.Text = L("mouseHint")
toggle(mouseBtn, attr(state, "MouseLook", true) == true)
sfxLabel.Text = "🔊 " .. L("sfx")
toggle(sfxBtn, attr(state, "Sfx", true) == true)
local double = attr(state, "Double", false)
passBtn.Visible = Products.DOUBLE_MONEY_PASS ~= 0
passBtn.Text = if double then "✅ " .. L("doubleOwned") else "💰x2 " .. L("double")
passBtn.Active = not double
passBtn.AutoButtonColor = not double
boostBtn.Visible = Products.MONEY_BOOST_PRODUCT ~= 0 and nextP ~= nil
boostBtn.Text = "⚡ " .. L("boost") .. "\n+" .. Locale.number(attr(state, "Boost", Economy.BOOST_MIN))
-- 업그레이드 목록(지금 단계 것만). 산 개수나 언어가 바뀔 때만 다시 그립니다.
local key = `{bought}:{lang()}`
if key == listKey then
return
end
listKey = key
local stage = stats.stage
panelTitle.Text = L(if stage >= 2 then "stage2" else "stage1")
for _, c in scroll:GetChildren() do
if c:IsA("Frame") then
c:Destroy()
end
end
local from = if stage >= 2 then 11 else 1
local to = if stage >= 2 then #Economy.PURCHASES else 10
for i = from, to do
local p = Economy.PURCHASES[i]
local row =
frame(scroll, "Row" .. i, UDim2.new(1, -12, 0, 46), UDim2.new(), Vector2.zero, Color3.new(1, 1, 1))
row.LayoutOrder = i
corner(row, 10)
local done = i <= bought
local isNext = i == bought + 1
row.BackgroundColor3 = if done
then Color3.fromRGB(215, 245, 215)
elseif isNext then Color3.fromRGB(255, 240, 200)
else Color3.fromRGB(240, 240, 240)
local status = if done then "✅" elseif isNext then "👉" else "🔒"
local name = text(row, "Name", UDim2.new(0.66, -10, 1, -12), UDim2.fromOffset(10, 6))
name.TextXAlignment = Enum.TextXAlignment.Left
name.Text = `{status} {pname(p)}`
local cost =
text(row, "Cost", UDim2.new(0.34, -10, 1, -12), UDim2.new(0.66, 0, 0, 6), Color3.fromRGB(120, 90, 60))
cost.TextXAlignment = Enum.TextXAlignment.Right
cost.Text = if done then L("bought") else L("money", { money = Locale.number(p.cost) })
end
end
local function notify(key: string, args: { [string]: any }?)
-- 서버는 메뉴·업그레이드를 키(menu, item)로 보내고, 이름은 내 언어로 바꿔 씁니다.
if args then
args = table.clone(args)
if typeof(args.menu) == "string" then
args.menuName = Locale.menuName(lang(), args.menu)
end
if typeof(args.item) == "string" then
args.name = Locale.itemName(lang(), args.item)
end
end
local toast =
frame(toasts, "Toast", UDim2.fromOffset(540, 46), UDim2.new(), Vector2.zero, Color3.fromRGB(45, 45, 60))
corner(toast, 12)
local t = text(toast, "Text", UDim2.new(1, -20, 1, -10), UDim2.fromOffset(10, 5), Color3.new(1, 1, 1))
t.Text = L(key, args)
task.delay(2.6, function()
TweenService:Create(toast, TweenInfo.new(0.4), { BackgroundTransparency = 1 }):Play()
TweenService:Create(t, TweenInfo.new(0.4), { TextTransparency = 1 }):Play()
task.wait(0.45)
toast:Destroy()
end)
end
local conns: { RBXScriptConnection } = {}
table.insert(
conns,
buyBtn.Activated:Connect(function()
send("buy")
end)
)
table.insert(
conns,
listBtn.Activated:Connect(function()
panel.Visible = not panel.Visible
settings.Visible = false
end)
)
table.insert(
conns,
closeBtn.Activated:Connect(function()
panel.Visible = false
end)
)
table.insert(
conns,
settingsBtn.Activated:Connect(function()
settings.Visible = not settings.Visible
panel.Visible = false
end)
)
table.insert(
conns,
settingsClose.Activated:Connect(function()
settings.Visible = false
end)
)
for l, b in langButtons do
table.insert(
conns,
b.Activated:Connect(function()
send("lang", l)
end)
)
end
table.insert(
conns,
mouseBtn.Activated:Connect(function()
send("mouseLook", attr(state, "MouseLook", true) ~= true)
end)
)
table.insert(
conns,
sfxBtn.Activated:Connect(function()
send("sfx", attr(state, "Sfx", true) ~= true)
end)
)
table.insert(
conns,
passBtn.Activated:Connect(function()
if not attr(state, "Double", false) then
send("pass")
end
end)
)
table.insert(
conns,
boostBtn.Activated:Connect(function()
send("boost")
end)
)
local devKinds: { [string]: string } = { devMoney = "dev_money", devDouble = "dev_double", devReset = "dev_reset" }
for key, kind in devKinds do
table.insert(
conns,
devButtons[key].Activated:Connect(function()
send(kind)
end)
)
end
table.insert(conns, state.AttributeChanged:Connect(refresh))
refresh()
return {
gui = gui,
refresh = refresh,
notify = notify,
setScale = function(s: number)
scale.Scale = s
end,
menuOpen = function(): boolean
return panel.Visible or settings.Visible
end,
destroy = function()
for _, c in conns do
c:Disconnect()
end
gui:Destroy()
end,
}
end
-- 화면 크기에 맞춘 UI 배율(기준 1100x620)
function Hud.scaleFor(viewport: Vector2): number
return math.clamp(math.min(viewport.X / 1100, viewport.Y / 620), 0.5, 1.4)
end
return Hud