feat(bunsik): 화면 UI 개편 — 상점 탭 4개(업그레이드 갈래·꾸미기·알바생·내 가게), 꾸미기(배치) 화면, 홍보·손님 러시 버튼, 추천 구매 막대, 쫓아내기 버튼, 가게 이름·무지개 이름판, 4개 언어
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
772
bunsik-tycoon/src/client/Decorate.luau
Normal file
772
bunsik-tycoon/src/client/Decorate.luau
Normal file
@@ -0,0 +1,772 @@
|
||||
--!strict
|
||||
-- 꾸미기(배치) 화면: 상점 창 꾸미기 탭의 [배치하기]로 엽니다.
|
||||
-- - 카메라가 내 가게 위에서 내려다봅니다(1층/2층 바꾸기). 위를 가리는 지붕·천장·2층 바닥은 내 화면에서만 숨깁니다.
|
||||
-- - 물건(테이블·의자·소품·조리대)을 눌러 고르고, 바닥을 누르거나 끌어서 옮길 자리를 정합니다(0.5칸 단위).
|
||||
-- 조리대·소품은 [돌리기], 의자는 쪽 버튼(앞·오른쪽·뒤·왼쪽)과 다른 테이블 누르기로 옮깁니다.
|
||||
-- - 옮길 자리는 바닥에 초록(놓을 수 있음)/빨강(안 됨) 판으로 보이고, 안 되는 이유를 위에 씁니다.
|
||||
-- 검사는 서버와 같은 Floor.move이고, [놓기]를 누르면 서버에 "move"를 보냅니다(서버가 다시 검사하고 모델을 다시 지음).
|
||||
-- 캐릭터 조작 멈춤·다른 UI 숨기기는 Main이 onOpen/onClose로 합니다(요리 창과 같은 방식).
|
||||
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local UserInputService = game:GetService("UserInputService")
|
||||
|
||||
local Shared = ReplicatedStorage:WaitForChild("Shared")
|
||||
local Floor = require(Shared:WaitForChild("Floor"))
|
||||
local Locale = require(Shared:WaitForChild("Locale"))
|
||||
local Info = require(script.Parent:WaitForChild("Info"))
|
||||
local Layout = require(script.Parent:WaitForChild("Layout"))
|
||||
local Theme = require(script.Parent:WaitForChild("Theme"))
|
||||
|
||||
local Decorate = {}
|
||||
|
||||
export type Handle = {
|
||||
gui: ScreenGui,
|
||||
open: () -> (),
|
||||
close: () -> (),
|
||||
isOpen: () -> boolean,
|
||||
onOpen: (fn: () -> ()) -> (),
|
||||
onClose: (fn: () -> ()) -> (),
|
||||
setLayout: (lay: Layout.Result) -> (),
|
||||
notify: (key: string, args: { [string]: any }?) -> (),
|
||||
destroy: () -> (),
|
||||
}
|
||||
|
||||
type Selection = { kind: string, i: number }
|
||||
|
||||
local GOOD = Color3.fromRGB(70, 220, 120)
|
||||
local BAD = Color3.fromRGB(255, 70, 70)
|
||||
local HIDE_ABOVE = 4 -- 보는 층 바닥보다 이만큼 위에서 시작하는 부품은 숨김(천장·지붕·위층)
|
||||
|
||||
local function snap(v: number): number
|
||||
return math.floor(v * 2 + 0.5) / 2
|
||||
end
|
||||
|
||||
-- 검사 없이 옮긴 배치(바닥 판 그리기용). Floor.move와 같은 규칙으로 바꿉니다.
|
||||
local function applyMove(layout: Floor.Layout, m: Floor.Move): Floor.Layout
|
||||
local test = Floor.clone(layout)
|
||||
local f = if m.f == 2 then 2 else 1
|
||||
local r = math.floor(m.r or 0) % 4
|
||||
if m.kind == "stove" then
|
||||
test.stove = { x = m.x, z = m.z, r = r }
|
||||
elseif m.kind == "table" and test.tables[m.i] then
|
||||
test.tables[m.i] = { x = m.x, z = m.z, f = f }
|
||||
elseif m.kind == "decor" and test.decor[m.i] then
|
||||
local d = test.decor[m.i]
|
||||
test.decor[m.i] = { k = d.k, x = m.x, z = m.z, f = f, r = r }
|
||||
elseif m.kind == "chair" and test.chairs[m.i] then
|
||||
local c = test.chairs[m.i]
|
||||
if m.z ~= 0 and test.tables[m.z] then
|
||||
c.t = m.z
|
||||
end
|
||||
if Floor.SIDES[m.x] then
|
||||
c.s = m.x
|
||||
end
|
||||
end
|
||||
return test
|
||||
end
|
||||
|
||||
-- 물건의 층
|
||||
local function itemFloor(layout: Floor.Layout, kind: string, i: number): number
|
||||
if kind == "table" then
|
||||
local t = layout.tables[i]
|
||||
return if t then t.f else 1
|
||||
elseif kind == "chair" then
|
||||
local c = layout.chairs[i]
|
||||
local t = c and layout.tables[c.t]
|
||||
return if t then t.f else 1
|
||||
elseif kind == "decor" then
|
||||
local d = layout.decor[i]
|
||||
return if d then d.f else 1
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
-- 물건의 지금 자리를 옮기기 요청 모양으로
|
||||
local function currentMove(layout: Floor.Layout, sel: Selection): Floor.Move?
|
||||
if sel.kind == "stove" then
|
||||
local s = layout.stove
|
||||
return { kind = "stove", i = 1, x = s.x, z = s.z, f = 1, r = s.r }
|
||||
elseif sel.kind == "table" then
|
||||
local t = layout.tables[sel.i]
|
||||
return t and { kind = "table", i = sel.i, x = t.x, z = t.z, f = t.f, r = 0 }
|
||||
elseif sel.kind == "decor" then
|
||||
local d = layout.decor[sel.i]
|
||||
return d and { kind = "decor", i = sel.i, x = d.x, z = d.z, f = d.f, r = d.r }
|
||||
elseif sel.kind == "chair" then
|
||||
local c = layout.chairs[sel.i]
|
||||
return c and { kind = "chair", i = sel.i, x = c.s, z = 0, f = 1, r = 0 }
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function Decorate.build(parent: Instance, state: Instance, plot: Model, send: (string, any?) -> ()): Handle
|
||||
local function lang(): string
|
||||
return Info.attr(state, "Lang", "ko")
|
||||
end
|
||||
local function L(key: string, args: { [string]: any }?): string
|
||||
return Locale.t(lang(), key, args)
|
||||
end
|
||||
|
||||
local gui = Instance.new("ScreenGui")
|
||||
gui.Name = "BunsikDecorate"
|
||||
gui.ResetOnSpawn = false
|
||||
gui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
|
||||
gui.DisplayOrder = 5
|
||||
gui.Enabled = false
|
||||
gui.Parent = parent
|
||||
local root = Theme.frame(gui, "Root")
|
||||
local scale = Instance.new("UIScale")
|
||||
scale.Parent = root
|
||||
|
||||
local exitBtn, exitLabel = Theme.iconButton(root, "Exit", Theme.RED, "close")
|
||||
local floorBtn, floorLabel = Theme.textButton(root, "Floor", Theme.SKY, 22)
|
||||
local infoBox = Theme.frame(root, "Info", Theme.WHITE)
|
||||
Theme.round(infoBox)
|
||||
local infoStroke = Theme.stroke(infoBox, Theme.edge(Theme.MINT), 4)
|
||||
local infoIcon = Info.glyph(infoBox, "Icon", "hand")
|
||||
infoIcon.frame.AnchorPoint = Vector2.new(0, 0.5)
|
||||
infoIcon.frame.Position = UDim2.new(0, 10, 0.5, 0)
|
||||
infoIcon.frame.Size = UDim2.new(0, 48, 0.8, 0)
|
||||
local infoText = Theme.text(infoBox, "Text")
|
||||
infoText.Position = UDim2.new(0, 64, 0.14, 0)
|
||||
infoText.Size = UDim2.new(1, -80, 0.72, 0)
|
||||
infoText.ZIndex = 2
|
||||
|
||||
local rotateBtn, rotateLabel = Theme.textButton(root, "Rotate", Theme.LAVENDER, 22)
|
||||
local cancelBtn, cancelLabel = Theme.textButton(root, "Cancel", Theme.GRAY, 22)
|
||||
local okBtn, okLabel = Theme.textButton(root, "Place", Theme.MINT, 22)
|
||||
local sideBtns: { Theme.Button } = {}
|
||||
local sideLabels: { TextLabel } = {}
|
||||
for s = 1, 4 do
|
||||
local b, t = Theme.textButton(root, "Side" .. s, Theme.ORANGE, 22)
|
||||
sideBtns[s] = b
|
||||
sideLabels[s] = t
|
||||
end
|
||||
|
||||
-- 바닥 판과 고른 물건 빛
|
||||
local world = Instance.new("Folder")
|
||||
world.Name = "BunsikDecorateGhost"
|
||||
local highlight = Instance.new("Highlight")
|
||||
highlight.FillColor = Theme.YELLOW
|
||||
highlight.FillTransparency = 0.6
|
||||
highlight.OutlineColor = Theme.WHITE
|
||||
highlight.DepthMode = Enum.HighlightDepthMode.AlwaysOnTop
|
||||
highlight.Parent = world
|
||||
local ghostParts: { BasePart } = {}
|
||||
|
||||
local isOpen = false
|
||||
local floorNow = 1
|
||||
local sel: Selection? = nil
|
||||
local pending: Floor.Move? = nil
|
||||
local valid = false
|
||||
local why: string? = nil
|
||||
local message: string? = nil
|
||||
local messageToken = 0
|
||||
local dragging = false
|
||||
local dragOffset = Vector2.zero
|
||||
local openFns: { () -> () } = {}
|
||||
local closeFns: { () -> () } = {}
|
||||
local conns: { RBXScriptConnection } = {}
|
||||
local openConns: { RBXScriptConnection } = {}
|
||||
local hidden: { [BasePart]: boolean } = {}
|
||||
local saved: { kind: Enum.CameraType, fov: number }? = nil
|
||||
|
||||
local function origin(): CFrame?
|
||||
local o = plot:GetAttribute("Origin")
|
||||
return if typeof(o) == "CFrame" then o else nil
|
||||
end
|
||||
local function stage(): number
|
||||
return Info.attr(state, "Stage", 1)
|
||||
end
|
||||
local function floorY(f: number): number
|
||||
return Floor.BASE_Y + (if f == 2 then Floor.FLOOR2_Y else 0)
|
||||
end
|
||||
|
||||
-- 위를 가리는 부품 숨기기(내 화면에서만)
|
||||
local function hideCheck(p: BasePart, o: CFrame)
|
||||
local cf, sz = p.CFrame, p.Size
|
||||
local halfY = math.abs(cf.RightVector.Y) * sz.X / 2
|
||||
+ math.abs(cf.UpVector.Y) * sz.Y / 2
|
||||
+ math.abs(cf.LookVector.Y) * sz.Z / 2
|
||||
local bottom = o:PointToObjectSpace(p.Position).Y - halfY
|
||||
if bottom > floorY(floorNow) + HIDE_ABOVE then
|
||||
hidden[p] = true
|
||||
p.LocalTransparencyModifier = 1
|
||||
end
|
||||
end
|
||||
local function unhideAll()
|
||||
for p in hidden do
|
||||
p.LocalTransparencyModifier = 0
|
||||
end
|
||||
table.clear(hidden)
|
||||
end
|
||||
local function hideAll()
|
||||
unhideAll()
|
||||
local o = origin()
|
||||
local up = plot:FindFirstChild("Upgrades")
|
||||
if not o or not up then
|
||||
return
|
||||
end
|
||||
for _, d in up:GetDescendants() do
|
||||
if d:IsA("BasePart") then
|
||||
hideCheck(d, o)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function placeCamera()
|
||||
local o = origin()
|
||||
local camera = workspace.CurrentCamera
|
||||
if not o or not camera then
|
||||
return
|
||||
end
|
||||
local vp = camera.ViewportSize
|
||||
local aspect = if vp.Y > 0 then vp.X / vp.Y else 16 / 9
|
||||
camera.CameraType = Enum.CameraType.Scriptable
|
||||
camera.FieldOfView = 70
|
||||
local k = 2 * math.tan(math.rad(35))
|
||||
-- 깊이 56칸(+위아래 UI 자리), 너비 66칸이 다 보이는 높이
|
||||
local h = math.max(86 / k, 74 / (k * aspect))
|
||||
local center = o * CFrame.new(0, floorY(floorNow), (Floor.Z0 + Floor.Z1) / 2 + 3)
|
||||
local eye = center.Position + o.UpVector * h
|
||||
camera.CFrame = CFrame.lookAt(eye, center.Position, o.LookVector)
|
||||
end
|
||||
|
||||
-- 물건 모델 찾기
|
||||
local function itemModel(kind: string, i: number): Model?
|
||||
if kind == "stove" then
|
||||
local base = plot:FindFirstChild("Base")
|
||||
local stall = base and base:FindFirstChild("Stall")
|
||||
return if stall and stall:IsA("Model") then stall else nil
|
||||
end
|
||||
local up = plot:FindFirstChild("Upgrades")
|
||||
local furniture = up and up:FindFirstChild("Furniture")
|
||||
if not furniture then
|
||||
return nil
|
||||
end
|
||||
for _, d in furniture:GetDescendants() do
|
||||
if d:IsA("Model") and d:GetAttribute("ItemKind") == kind and d:GetAttribute("ItemIndex") == i then
|
||||
return d
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local function clearGhost()
|
||||
for _, p in ghostParts do
|
||||
p:Destroy()
|
||||
end
|
||||
table.clear(ghostParts)
|
||||
end
|
||||
|
||||
local function drawGhost(layout: Floor.Layout, m: Floor.Move, ok: boolean)
|
||||
clearGhost()
|
||||
local o = origin()
|
||||
if not o then
|
||||
return
|
||||
end
|
||||
for _, pc in Floor.pieces(layout) do
|
||||
local mine = pc.kind == m.kind and pc.index == m.i
|
||||
if m.kind == "table" and pc.kind == "chair" then
|
||||
local c = layout.chairs[pc.index]
|
||||
mine = c ~= nil and c.t == m.i
|
||||
end
|
||||
if mine then
|
||||
local r = pc.rect
|
||||
local p = Instance.new("Part")
|
||||
p.Name = "Ghost"
|
||||
p.Anchored = true
|
||||
p.CanCollide = false
|
||||
p.CanQuery = false
|
||||
p.CanTouch = false
|
||||
p.CastShadow = false
|
||||
p.Material = Enum.Material.SmoothPlastic
|
||||
p.Color = if ok then GOOD else BAD
|
||||
p.Transparency = 0.35
|
||||
p.Size = Vector3.new(math.max(0.2, r.x1 - r.x0), 0.3, math.max(0.2, r.z1 - r.z0))
|
||||
p.CFrame = o * CFrame.new((r.x0 + r.x1) / 2, floorY(r.f) + 0.3, (r.z0 + r.z1) / 2)
|
||||
p.Parent = world
|
||||
table.insert(ghostParts, p)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function itemName(s: Selection, layout: Floor.Layout): (string, string)
|
||||
if s.kind == "stove" then
|
||||
return L("stoveObject"), "flame"
|
||||
elseif s.kind == "table" then
|
||||
return `{L("thing_Table")} {s.i}`, "table"
|
||||
elseif s.kind == "chair" then
|
||||
return L("thing_Seat"), Info.SEAT_ICON
|
||||
end
|
||||
local d = layout.decor[s.i]
|
||||
local k = if d then d.k else ""
|
||||
return L("decor_" .. k), Info.DECOR_ICON[k] or "sparkle"
|
||||
end
|
||||
|
||||
local function place(o: GuiObject, r: Layout.Rect)
|
||||
o.AnchorPoint = Vector2.new(0.5, 0.5)
|
||||
o.Position = UDim2.fromOffset(r.x + r.w / 2, r.y + r.h / 2)
|
||||
o.Size = UDim2.fromOffset(r.w, r.h)
|
||||
end
|
||||
|
||||
-- 화면 다시 그리기(안내 글, 버튼, 바닥 판)
|
||||
local function redraw()
|
||||
local layout = Info.layout(state)
|
||||
local st = stage()
|
||||
exitLabel.Text = L("exit")
|
||||
floorBtn.button.Visible = st >= 3
|
||||
floorLabel.Text = L("floorN", { n = 3 - floorNow })
|
||||
rotateLabel.Text = L("rotate")
|
||||
cancelLabel.Text = L("cancel")
|
||||
okLabel.Text = L("placeIt")
|
||||
for s = 1, 4 do
|
||||
sideLabels[s].Text = L(`side_{s}`)
|
||||
end
|
||||
local s = sel
|
||||
local kind = if s then s.kind else ""
|
||||
local isChair = kind == "chair"
|
||||
rotateBtn.button.Visible = kind == "stove" or kind == "decor"
|
||||
for i, b in sideBtns do
|
||||
b.button.Visible = isChair
|
||||
local side = if pending and pending.kind == "chair"
|
||||
then pending.x
|
||||
elseif s and isChair and layout.chairs[s.i] then layout.chairs[s.i].s
|
||||
else 0
|
||||
b.setColor(if i == side then Theme.ORANGE else Theme.lighten(Theme.ORANGE, 0.45))
|
||||
end
|
||||
cancelBtn.button.Visible = pending ~= nil
|
||||
okBtn.button.Visible = s ~= nil
|
||||
okBtn.setColor(if pending and valid then Theme.MINT else Theme.GRAY)
|
||||
|
||||
-- 안내 글
|
||||
local text: string
|
||||
local color = Theme.MINT
|
||||
if message then
|
||||
text = message
|
||||
color = Theme.ORANGE
|
||||
elseif not s then
|
||||
text = L("decoPick")
|
||||
infoIcon.set("hand")
|
||||
elseif pending and not valid then
|
||||
text = L("why_" .. (why or "none"))
|
||||
color = Theme.RED
|
||||
elseif pending then
|
||||
text = L("decoOk")
|
||||
else
|
||||
text = if isChair then L("decoChair") else L("decoMove")
|
||||
end
|
||||
if s then
|
||||
local name, icon = itemName(s, layout)
|
||||
infoIcon.set(icon)
|
||||
text = `{name} · {text}`
|
||||
end
|
||||
infoText.Text = text
|
||||
infoText.TextColor3 = if color == Theme.RED then Theme.edge(Theme.RED) else Theme.TEXT
|
||||
infoStroke.Color = Theme.edge(color)
|
||||
|
||||
-- 고른 물건 빛, 바닥 판
|
||||
highlight.Adornee = if s then itemModel(s.kind, s.i) else nil
|
||||
if pending then
|
||||
drawGhost(applyMove(layout, pending), pending, valid)
|
||||
else
|
||||
clearGhost()
|
||||
end
|
||||
end
|
||||
|
||||
-- 옮길 자리 정하기(검사 포함)
|
||||
local function setPending(m: Floor.Move?)
|
||||
pending = m
|
||||
message = nil
|
||||
if m then
|
||||
local layout = Info.layout(state)
|
||||
local cur = sel and currentMove(layout, sel)
|
||||
-- 제자리면 옮길 것 없음
|
||||
if cur and cur.x == m.x and cur.z == m.z and (cur.f or 1) == (m.f or 1) and (cur.r or 0) == (m.r or 0) then
|
||||
pending = nil
|
||||
else
|
||||
local ok, reason = Floor.move(layout, stage(), m)
|
||||
valid = ok ~= nil
|
||||
why = reason
|
||||
end
|
||||
end
|
||||
redraw()
|
||||
end
|
||||
|
||||
local function choose(s: Selection?)
|
||||
sel = s
|
||||
dragging = false
|
||||
setPending(nil)
|
||||
end
|
||||
|
||||
-- 지금 옮기려는 모양(없으면 지금 자리)
|
||||
local function base(): Floor.Move?
|
||||
if pending then
|
||||
return table.clone(pending)
|
||||
end
|
||||
local s = sel
|
||||
return if s then currentMove(Info.layout(state), s) else nil
|
||||
end
|
||||
|
||||
local function floorPoint(sx: number, sy: number): Vector2?
|
||||
local o = origin()
|
||||
local camera = workspace.CurrentCamera
|
||||
if not o or not camera then
|
||||
return nil
|
||||
end
|
||||
local ray = camera:ScreenPointToRay(sx, sy)
|
||||
local n = o.UpVector
|
||||
local p0 = (o * CFrame.new(0, floorY(floorNow), 0)).Position
|
||||
local denom = ray.Direction:Dot(n)
|
||||
if math.abs(denom) < 1e-4 then
|
||||
return nil
|
||||
end
|
||||
local t = (p0 - ray.Origin):Dot(n) / denom
|
||||
if t < 0 then
|
||||
return nil
|
||||
end
|
||||
local hit = o:PointToObjectSpace(ray.Origin + ray.Direction * t)
|
||||
return Vector2.new(hit.X, hit.Z)
|
||||
end
|
||||
|
||||
local function pickItem(sx: number, sy: number): Selection?
|
||||
local camera = workspace.CurrentCamera
|
||||
if not camera then
|
||||
return nil
|
||||
end
|
||||
local layout = Info.layout(state)
|
||||
local list: { Instance } = {}
|
||||
local up = plot:FindFirstChild("Upgrades")
|
||||
local furniture = up and up:FindFirstChild("Furniture")
|
||||
if furniture then
|
||||
for _, d in furniture:GetDescendants() do
|
||||
local kind = d:GetAttribute("ItemKind")
|
||||
local i = d:GetAttribute("ItemIndex")
|
||||
if
|
||||
d:IsA("Model")
|
||||
and typeof(kind) == "string"
|
||||
and typeof(i) == "number"
|
||||
and itemFloor(layout, kind, i) == floorNow
|
||||
then
|
||||
table.insert(list, d)
|
||||
end
|
||||
end
|
||||
end
|
||||
if floorNow == 1 then
|
||||
local stall = itemModel("stove", 1)
|
||||
if stall then
|
||||
table.insert(list, stall)
|
||||
end
|
||||
end
|
||||
local params = RaycastParams.new()
|
||||
params.FilterType = Enum.RaycastFilterType.Include
|
||||
params.FilterDescendantsInstances = list
|
||||
local ray = camera:ScreenPointToRay(sx, sy)
|
||||
local res = workspace:Raycast(ray.Origin, ray.Direction * 1000, params)
|
||||
local inst: Instance? = res and res.Instance
|
||||
while inst and inst ~= plot do
|
||||
local kind = inst:GetAttribute("ItemKind")
|
||||
local i = inst:GetAttribute("ItemIndex")
|
||||
if inst:IsA("Model") and typeof(kind) == "string" and typeof(i) == "number" then
|
||||
return { kind = kind, i = i }
|
||||
end
|
||||
inst = inst.Parent
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local function moveTo(p: Vector2)
|
||||
local m = base()
|
||||
if not m or m.kind == "chair" then
|
||||
return
|
||||
end
|
||||
m.x = snap(p.X + dragOffset.X)
|
||||
m.z = snap(p.Y + dragOffset.Y)
|
||||
m.f = if m.kind == "stove" then 1 else floorNow
|
||||
setPending(m)
|
||||
end
|
||||
|
||||
-- 누르기: 물건이면 고르기(의자를 고른 상태에서 테이블이면 그 테이블로), 바닥이면 옮기기
|
||||
local function press(sx: number, sy: number)
|
||||
local hit = pickItem(sx, sy)
|
||||
local s = sel
|
||||
if hit and s and s.kind == "chair" and hit.kind == "table" then
|
||||
local m = base()
|
||||
if m then
|
||||
m.z = hit.i
|
||||
setPending(m)
|
||||
end
|
||||
return
|
||||
end
|
||||
if hit and s and hit.kind == s.kind and hit.i == s.i and s.kind ~= "chair" then
|
||||
-- 고른 물건을 다시 누르면 끌어서 옮기기
|
||||
local p = floorPoint(sx, sy)
|
||||
local m = base()
|
||||
if p and m then
|
||||
dragOffset = Vector2.new(m.x - p.X, m.z - p.Y)
|
||||
dragging = true
|
||||
end
|
||||
return
|
||||
end
|
||||
if hit then
|
||||
choose(hit)
|
||||
return
|
||||
end
|
||||
if s and s.kind ~= "chair" then
|
||||
local p = floorPoint(sx, sy)
|
||||
if p then
|
||||
dragOffset = Vector2.zero
|
||||
moveTo(p)
|
||||
dragging = true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function showMessage(text: string)
|
||||
message = text
|
||||
messageToken += 1
|
||||
local token = messageToken
|
||||
redraw()
|
||||
task.delay(3, function()
|
||||
if token == messageToken then
|
||||
message = nil
|
||||
if isOpen then
|
||||
redraw()
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
local function close()
|
||||
if not isOpen then
|
||||
return
|
||||
end
|
||||
isOpen = false
|
||||
gui.Enabled = false
|
||||
for _, c in openConns do
|
||||
c:Disconnect()
|
||||
end
|
||||
table.clear(openConns)
|
||||
sel = nil
|
||||
pending = nil
|
||||
dragging = false
|
||||
clearGhost()
|
||||
highlight.Adornee = nil
|
||||
world.Parent = nil
|
||||
unhideAll()
|
||||
local camera = workspace.CurrentCamera
|
||||
if camera and saved then
|
||||
camera.FieldOfView = saved.fov
|
||||
camera.CameraType = saved.kind
|
||||
end
|
||||
saved = nil
|
||||
for _, fn in closeFns do
|
||||
fn()
|
||||
end
|
||||
end
|
||||
|
||||
local function open()
|
||||
if isOpen or not origin() then
|
||||
return
|
||||
end
|
||||
isOpen = true
|
||||
floorNow = 1
|
||||
sel = nil
|
||||
pending = nil
|
||||
message = nil
|
||||
local camera = workspace.CurrentCamera
|
||||
if camera then
|
||||
saved = { kind = camera.CameraType, fov = camera.FieldOfView }
|
||||
end
|
||||
world.Parent = workspace
|
||||
gui.Enabled = true
|
||||
hideAll()
|
||||
placeCamera()
|
||||
local up = plot:FindFirstChild("Upgrades")
|
||||
if up then
|
||||
-- 서버가 건물·가구를 다시 지으면 새 부품도 숨기고, 고른 물건 빛을 새 모델에 붙입니다.
|
||||
table.insert(
|
||||
openConns,
|
||||
up.DescendantAdded:Connect(function(d)
|
||||
task.defer(function()
|
||||
local o = origin()
|
||||
if isOpen and o and d:IsA("BasePart") and d.Parent then
|
||||
hideCheck(d, o)
|
||||
end
|
||||
if isOpen and d:IsA("Model") then
|
||||
redraw()
|
||||
end
|
||||
end)
|
||||
end)
|
||||
)
|
||||
end
|
||||
if camera then
|
||||
table.insert(openConns, camera:GetPropertyChangedSignal("ViewportSize"):Connect(placeCamera))
|
||||
end
|
||||
redraw()
|
||||
for _, fn in openFns do
|
||||
fn()
|
||||
end
|
||||
end
|
||||
|
||||
-- 입력
|
||||
table.insert(
|
||||
conns,
|
||||
UserInputService.InputBegan:Connect(function(io: InputObject, processed: boolean)
|
||||
if not isOpen or processed then
|
||||
return
|
||||
end
|
||||
local t = io.UserInputType
|
||||
if t == Enum.UserInputType.MouseButton1 or t == Enum.UserInputType.Touch then
|
||||
press(io.Position.X, io.Position.Y)
|
||||
end
|
||||
end)
|
||||
)
|
||||
table.insert(
|
||||
conns,
|
||||
UserInputService.InputChanged:Connect(function(io: InputObject)
|
||||
if not isOpen or not dragging then
|
||||
return
|
||||
end
|
||||
local t = io.UserInputType
|
||||
if t == Enum.UserInputType.MouseMovement or t == Enum.UserInputType.Touch then
|
||||
local p = floorPoint(io.Position.X, io.Position.Y)
|
||||
if p then
|
||||
moveTo(p)
|
||||
end
|
||||
end
|
||||
end)
|
||||
)
|
||||
table.insert(
|
||||
conns,
|
||||
UserInputService.InputEnded:Connect(function(io: InputObject)
|
||||
local t = io.UserInputType
|
||||
if t == Enum.UserInputType.MouseButton1 or t == Enum.UserInputType.Touch then
|
||||
dragging = false
|
||||
end
|
||||
end)
|
||||
)
|
||||
table.insert(conns, exitBtn.button.Activated:Connect(close))
|
||||
table.insert(
|
||||
conns,
|
||||
floorBtn.button.Activated:Connect(function()
|
||||
floorNow = 3 - floorNow
|
||||
hideAll()
|
||||
placeCamera()
|
||||
-- 테이블·소품을 고른 채로 층을 바꾸면 그 층으로 옮기기
|
||||
local m = base()
|
||||
if m and (m.kind == "table" or m.kind == "decor") then
|
||||
m.f = floorNow
|
||||
setPending(m)
|
||||
else
|
||||
redraw()
|
||||
end
|
||||
end)
|
||||
)
|
||||
table.insert(
|
||||
conns,
|
||||
rotateBtn.button.Activated:Connect(function()
|
||||
local m = base()
|
||||
if m then
|
||||
m.r = ((m.r or 0) + 1) % 4
|
||||
setPending(m)
|
||||
end
|
||||
end)
|
||||
)
|
||||
for s, b in sideBtns do
|
||||
table.insert(
|
||||
conns,
|
||||
b.button.Activated:Connect(function()
|
||||
local m = base()
|
||||
if m and m.kind == "chair" then
|
||||
m.x = s
|
||||
setPending(m)
|
||||
end
|
||||
end)
|
||||
)
|
||||
end
|
||||
table.insert(
|
||||
conns,
|
||||
cancelBtn.button.Activated:Connect(function()
|
||||
setPending(nil)
|
||||
end)
|
||||
)
|
||||
table.insert(
|
||||
conns,
|
||||
okBtn.button.Activated:Connect(function()
|
||||
local m = pending
|
||||
if m and valid then
|
||||
send("move", { kind = m.kind, i = m.i, x = m.x, z = m.z, f = m.f, r = m.r })
|
||||
pending = nil
|
||||
redraw()
|
||||
end
|
||||
end)
|
||||
)
|
||||
table.insert(
|
||||
conns,
|
||||
state.AttributeChanged:Connect(function(key: string)
|
||||
if not isOpen then
|
||||
return
|
||||
end
|
||||
if key == "Layout" or key == "Stage" then
|
||||
local s = sel
|
||||
-- 물건이 없어졌으면 고르기 해제
|
||||
if s and not currentMove(Info.layout(state), s) then
|
||||
sel = nil
|
||||
end
|
||||
if stage() < 3 and floorNow == 2 then
|
||||
floorNow = 1
|
||||
hideAll()
|
||||
placeCamera()
|
||||
end
|
||||
setPending(pending)
|
||||
elseif key == "Lang" then
|
||||
redraw()
|
||||
end
|
||||
end)
|
||||
)
|
||||
|
||||
return {
|
||||
gui = gui,
|
||||
open = open,
|
||||
close = close,
|
||||
isOpen = function()
|
||||
return isOpen
|
||||
end,
|
||||
onOpen = function(fn)
|
||||
table.insert(openFns, fn)
|
||||
end,
|
||||
onClose = function(fn)
|
||||
table.insert(closeFns, fn)
|
||||
end,
|
||||
setLayout = function(lay: Layout.Result)
|
||||
scale.Scale = lay.scale
|
||||
root.Size = UDim2.fromOffset(math.ceil(lay.width), math.ceil(lay.height))
|
||||
local d = lay.deco
|
||||
place(exitBtn.button, d.exit)
|
||||
place(floorBtn.button, d.floor)
|
||||
place(infoBox, d.info)
|
||||
place(rotateBtn.button, d.tools[4])
|
||||
place(cancelBtn.button, d.tools[5])
|
||||
place(okBtn.button, d.tools[6])
|
||||
for s, b in sideBtns do
|
||||
place(b.button, d.tools[s])
|
||||
end
|
||||
end,
|
||||
notify = function(key: string, args: { [string]: any }?)
|
||||
if isOpen then
|
||||
showMessage(Info.toast(lang(), key, args))
|
||||
end
|
||||
end,
|
||||
destroy = function()
|
||||
close()
|
||||
for _, c in conns do
|
||||
c:Disconnect()
|
||||
end
|
||||
world:Destroy()
|
||||
gui:Destroy()
|
||||
end,
|
||||
}
|
||||
end
|
||||
|
||||
return Decorate
|
||||
Reference in New Issue
Block a user