feat(bunsik): 휴대폰·태블릿 화면 배치
- Layout 모듈: 안전 영역(상단 바·노치 제외) 크기와 터치 여부로 배율·위치 계산 - 휴대폰: 기준 화면 900x400으로 글자·버튼 크게, 결제 버튼은 왼쪽 위, 사기 버튼은 조이스틱(왼쪽 40%×아래 2/3)과 점프 버튼 자리 사이, 마우스 회전 줄 숨김 - 루트가 화면을 꽉 채우고, 배율을 상단 바 뺀 영역 기준으로 계산(아래 카드 잘림 수정) - 개발자 테스트 버튼을 설정 창 안으로 이동 - 기기 12종 배치 단위 테스트, 배치 미리보기 도구(tools/hud_preview.py) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
--!strict
|
||||
-- 화면 UI: 돈, 다음 업그레이드, 업그레이드 목록, 2배 수익·돈 부스트 버튼, 설정(언어·마우스 회전·효과음), 안내 문구, 알림.
|
||||
-- 화면 UI: 돈, 다음 업그레이드, 업그레이드 목록, 2배 수익·돈 부스트 버튼, 설정(언어·마우스 회전·효과음·개발자 테스트), 안내 문구, 알림.
|
||||
-- 배치는 Layout 모듈이 화면 크기와 터치 여부로 정합니다(휴대폰은 조이스틱·점프 버튼 자리를 피함).
|
||||
-- 상태는 `state` 인스턴스(실제 게임에서는 Player)의 속성에서 읽습니다. 서버에서도 만들 수 있어서 원격 테스트로 검사합니다.
|
||||
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
@@ -9,6 +10,7 @@ local Shared = ReplicatedStorage:WaitForChild("Shared")
|
||||
local Economy = require(Shared:WaitForChild("Economy"))
|
||||
local Locale = require(Shared:WaitForChild("Locale"))
|
||||
local Products = require(Shared:WaitForChild("Products"))
|
||||
local Layout = require(script.Parent:WaitForChild("Layout"))
|
||||
|
||||
local Hud = {}
|
||||
|
||||
@@ -16,7 +18,9 @@ export type HudHandle = {
|
||||
gui: ScreenGui,
|
||||
refresh: () -> (),
|
||||
notify: (key: string, args: { [string]: any }?) -> (),
|
||||
setScale: (number) -> (),
|
||||
-- UI가 쓸 수 있는 화면 크기(픽셀, 상단 바 제외)와 터치 화면 여부로 배치를 다시 잡습니다.
|
||||
setLayout: (size: Vector2, touch: boolean) -> (),
|
||||
layout: () -> Layout.Result,
|
||||
menuOpen: () -> boolean, -- 업그레이드·설정 창이 열려 있으면 true(마우스 커서를 풀어 줌)
|
||||
destroy: () -> (),
|
||||
}
|
||||
@@ -117,13 +121,10 @@ function Hud.build(parent: Instance, state: Instance, send: (string, any?) -> ()
|
||||
gui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
|
||||
gui.Parent = parent
|
||||
|
||||
local root = frame(gui, "Root", UDim2.fromScale(1, 1), UDim2.fromScale(0, 0), Vector2.zero)
|
||||
-- 루트는 기준 단위(화면 픽셀 / 배율) 크기로 만들고 UIScale로 키워 화면을 꽉 채웁니다.
|
||||
local root = frame(gui, "Root", UDim2.fromOffset(1100, 620), 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)
|
||||
@@ -226,32 +227,7 @@ function Hud.build(parent: Instance, state: Instance, send: (string, any?) -> ()
|
||||
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",
|
||||
@@ -315,6 +291,79 @@ function Hud.build(parent: Instance, state: Instance, send: (string, any?) -> ()
|
||||
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 devTitle = rowLabel("DevLabel", 0)
|
||||
local devButtons: { [string]: TextButton } = {}
|
||||
for i, key in { "devMoney", "devDouble", "devReset" } do
|
||||
devButtons[key] = button(
|
||||
settings,
|
||||
key,
|
||||
UDim2.fromOffset(157, 40),
|
||||
UDim2.fromOffset(16 + (i - 1) * 165, 0),
|
||||
Vector2.zero,
|
||||
Color3.fromRGB(90, 90, 110)
|
||||
)
|
||||
end
|
||||
|
||||
-- 화면 크기에 맞춰 배치합니다(Layout 모듈). 개발자 줄이 생기거나 없어질 때도 다시 잡습니다.
|
||||
local function place(o: GuiObject, r: Layout.Rect)
|
||||
o.AnchorPoint = Vector2.zero
|
||||
o.Position = UDim2.fromOffset(r.x, r.y)
|
||||
o.Size = UDim2.fromOffset(r.w, r.h)
|
||||
end
|
||||
local screen = Vector2.new(1100, 620)
|
||||
local touch = false
|
||||
local layoutNow: Layout.Result
|
||||
local function relayout()
|
||||
local dev = attr(state, "Dev", false) == true
|
||||
local lay = Layout.compute(screen.X, screen.Y, touch, dev)
|
||||
layoutNow = lay
|
||||
scale.Scale = lay.scale
|
||||
-- Offset은 정수라서 올림해 화면을 다 덮습니다(1 기준 단위 미만 차이).
|
||||
root.Size = UDim2.fromOffset(math.ceil(lay.width), math.ceil(lay.height))
|
||||
place(money, lay.money)
|
||||
place(carry, lay.carry)
|
||||
place(hint, lay.hint)
|
||||
place(toasts, lay.toasts)
|
||||
place(card, lay.card)
|
||||
place(listBtn, lay.list)
|
||||
place(settingsBtn, lay.settings)
|
||||
place(passBtn, lay.double)
|
||||
place(boostBtn, lay.boost)
|
||||
place(panel, lay.panel)
|
||||
place(settings, lay.settingsPanel)
|
||||
local r = lay.rows
|
||||
closeBtn.Size = UDim2.fromOffset(90, r.closeH)
|
||||
settingsClose.Size = UDim2.fromOffset(90, r.closeH)
|
||||
for _, b in langButtons do
|
||||
b.Size = UDim2.fromOffset(92, r.langButtonH)
|
||||
end
|
||||
local mouseY = r.mouseY
|
||||
mouseLabel.Visible = mouseY ~= nil
|
||||
mouseBtn.Visible = mouseY ~= nil
|
||||
mouseHint.Visible = mouseY ~= nil
|
||||
if mouseY then
|
||||
mouseLabel.Position = UDim2.fromOffset(16, mouseY + 4)
|
||||
mouseBtn.Position = UDim2.new(1, -16, 0, mouseY)
|
||||
mouseHint.Position = UDim2.fromOffset(16, mouseY + 44)
|
||||
end
|
||||
sfxLabel.Position = UDim2.fromOffset(16, r.sfxY + (r.toggleH - 30) / 2)
|
||||
sfxBtn.Position = UDim2.new(1, -16, 0, r.sfxY)
|
||||
sfxBtn.Size = UDim2.fromOffset(110, r.toggleH)
|
||||
local devY = r.devY
|
||||
devTitle.Visible = devY ~= nil
|
||||
if devY then
|
||||
devTitle.Position = UDim2.fromOffset(16, devY)
|
||||
end
|
||||
for _, b in devButtons do
|
||||
b.Visible = devY ~= nil
|
||||
if devY then
|
||||
b.Position = UDim2.fromOffset(b.Position.X.Offset, devY + 30)
|
||||
b.Size = UDim2.fromOffset(157, r.devButtonH)
|
||||
end
|
||||
end
|
||||
end
|
||||
relayout()
|
||||
|
||||
local function lang(): string
|
||||
return attr(state, "Lang", "ko")
|
||||
@@ -381,7 +430,9 @@ function Hud.build(parent: Instance, state: Instance, send: (string, any?) -> ()
|
||||
buyStroke.Color = Color3.new(1, 1, 1)
|
||||
end
|
||||
|
||||
dev.Visible = attr(state, "Dev", false) == true
|
||||
if (layoutNow.rows.devY ~= nil) ~= (attr(state, "Dev", false) == true) then
|
||||
relayout()
|
||||
end
|
||||
devTitle.Text = "🛠 " .. L("devTitle")
|
||||
for key, b in devButtons do
|
||||
b.Text = L(key)
|
||||
@@ -463,7 +514,7 @@ function Hud.build(parent: Instance, state: Instance, send: (string, any?) -> ()
|
||||
end
|
||||
end
|
||||
local toast =
|
||||
frame(toasts, "Toast", UDim2.fromOffset(540, 46), UDim2.new(), Vector2.zero, Color3.fromRGB(45, 45, 60))
|
||||
frame(toasts, "Toast", UDim2.new(1, -20, 0, 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)
|
||||
@@ -558,8 +609,13 @@ function Hud.build(parent: Instance, state: Instance, send: (string, any?) -> ()
|
||||
gui = gui,
|
||||
refresh = refresh,
|
||||
notify = notify,
|
||||
setScale = function(s: number)
|
||||
scale.Scale = s
|
||||
setLayout = function(size: Vector2, isTouch: boolean)
|
||||
screen = size
|
||||
touch = isTouch
|
||||
relayout()
|
||||
end,
|
||||
layout = function(): Layout.Result
|
||||
return layoutNow
|
||||
end,
|
||||
menuOpen = function(): boolean
|
||||
return panel.Visible or settings.Visible
|
||||
@@ -573,9 +629,4 @@ function Hud.build(parent: Instance, state: Instance, send: (string, any?) -> ()
|
||||
}
|
||||
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
|
||||
|
||||
158
bunsik-tycoon/src/client/Layout.luau
Normal file
158
bunsik-tycoon/src/client/Layout.luau
Normal file
@@ -0,0 +1,158 @@
|
||||
--!strict
|
||||
-- 화면 UI 배치 계산(로블록스 서비스 없이 숫자만 다룸, lune 단위 테스트로 검사).
|
||||
-- 입력은 UI가 쓸 수 있는 화면 크기(상단 바·노치를 뺀 안전 영역, 픽셀)와 터치 화면 여부입니다.
|
||||
-- 결과 좌표는 기준 단위이고, 화면 픽셀 = 기준 단위 × scale 입니다.
|
||||
-- 터치 화면에서는 로블록스 기본 조이스틱 자리(왼쪽 40% × 아래 2/3)와 점프 버튼 자리(오른쪽 아래)에
|
||||
-- 누르는 버튼을 두지 않습니다. 두 자리의 크기는 로블록스 PlayerModule(TouchJump, DynamicThumbstick)에서 가져왔습니다.
|
||||
|
||||
local Layout = {}
|
||||
|
||||
export type Rect = { x: number, y: number, w: number, h: number }
|
||||
|
||||
export type Result = {
|
||||
scale: number,
|
||||
width: number, -- 기준 단위 화면 너비
|
||||
height: number,
|
||||
touch: boolean,
|
||||
money: Rect,
|
||||
carry: Rect,
|
||||
hint: Rect,
|
||||
toasts: Rect,
|
||||
card: Rect,
|
||||
buy: Rect, -- 카드 안의 [사기] 버튼(화면 기준 위치)
|
||||
settings: Rect,
|
||||
list: Rect,
|
||||
double: Rect,
|
||||
boost: Rect,
|
||||
panel: Rect,
|
||||
settingsPanel: Rect,
|
||||
-- 설정 창 안쪽 줄(설정 창 기준 y)
|
||||
rows: {
|
||||
langButtonH: number,
|
||||
mouseY: number?, -- 터치 화면에서는 마우스 줄을 숨김(nil)
|
||||
sfxY: number,
|
||||
toggleH: number,
|
||||
devY: number?, -- 개발자 줄(게임 주인에게만)
|
||||
devButtonH: number,
|
||||
closeH: number,
|
||||
},
|
||||
}
|
||||
|
||||
local CARD_W, CARD_H = 500, 96
|
||||
local BUY_W, BUY_H = 140, 72
|
||||
local PANEL_W = 520
|
||||
|
||||
local function rect(x: number, y: number, w: number, h: number): Rect
|
||||
return { x = x, y = y, w = w, h = h }
|
||||
end
|
||||
|
||||
-- 로블록스 터치 조작이 차지하는 자리(픽셀). 점프 버튼은 두 가지 배치(기본, 아바타 능력 UI)를 모두 덮는 상자입니다.
|
||||
function Layout.touchZones(w: number, h: number): { stick: Rect, jump: Rect }
|
||||
local small = math.min(w, h) <= 500
|
||||
local jx = if small then 136 else 220
|
||||
local jy = if small then 136 else 232
|
||||
return {
|
||||
stick = rect(0, h / 3, w * 0.4, h * 2 / 3),
|
||||
jump = rect(w - jx, h - jy, jx, jy),
|
||||
}
|
||||
end
|
||||
|
||||
function Layout.scaleFor(w: number, h: number, touch: boolean): number
|
||||
if touch then
|
||||
-- 휴대폰은 화면이 작아서 기준 화면을 900x400으로 줄여 글자·버튼을 크게 보여 줍니다.
|
||||
return math.clamp(math.min(w / 900, h / 400), 0.5, 1.4)
|
||||
end
|
||||
return math.clamp(math.min(w / 1100, h / 620), 0.5, 1.4)
|
||||
end
|
||||
|
||||
function Layout.compute(w: number, h: number, touch: boolean, dev: boolean): Result
|
||||
local s = Layout.scaleFor(w, h, touch)
|
||||
local W, H = w / s, h / s
|
||||
local cx = W / 2
|
||||
|
||||
local money = rect(cx - 150, 6, 300, 62)
|
||||
local carry = rect(cx - 80, 72, 160, 28)
|
||||
|
||||
local settings, list, double, boost
|
||||
local hintW
|
||||
if touch then
|
||||
-- 오른쪽 위: 설정, 업그레이드 목록. 왼쪽 위: 2배 수익, 돈 부스트(조이스틱 자리 H/3 위쪽).
|
||||
settings = rect(W - 160, 6, 150, 52)
|
||||
list = rect(W - 160, 66, 150, 56)
|
||||
double = rect(10, 6, 170, 58)
|
||||
boost = rect(10, 70, 170, 58)
|
||||
hintW = math.min(640, W - 2 * 190)
|
||||
else
|
||||
settings = rect(W - 140, 6, 130, 44)
|
||||
list = rect(W - 160, H / 2 - 68, 150, 56)
|
||||
double = rect(10, H / 2 - 72, 170, 64)
|
||||
boost = rect(10, H / 2 + 2, 170, 64)
|
||||
hintW = 640
|
||||
end
|
||||
local hint = rect(cx - hintW / 2, 104, hintW, 54)
|
||||
|
||||
-- 아래 카드: 터치 화면에서는 점프 버튼 왼쪽까지 밀어 둡니다.
|
||||
local cardX = cx - CARD_W / 2
|
||||
if touch then
|
||||
local zones = Layout.touchZones(w, h)
|
||||
cardX = math.min(cardX, zones.jump.x / s - 8 - CARD_W)
|
||||
end
|
||||
cardX = math.max(cardX, 10)
|
||||
local card = rect(cardX, H - 8 - CARD_H, CARD_W, CARD_H)
|
||||
local buy = rect(card.x + CARD_W - 12 - BUY_W, card.y + (CARD_H - BUY_H) / 2, BUY_W, BUY_H)
|
||||
|
||||
local toastsW = math.min(560, hintW)
|
||||
local toasts = rect(cx - toastsW / 2, 166, toastsW, math.max(0, card.y - 6 - 166))
|
||||
|
||||
local panelH = math.min(430, H - 20)
|
||||
local panel = rect(cx - PANEL_W / 2, math.max(6, H * 0.48 - panelH / 2), PANEL_W, panelH)
|
||||
|
||||
-- 설정 창 줄: 제목(10~54), 언어 이름(64), 언어 버튼(100~), 마우스(PC만), 효과음, 개발자(주인만)
|
||||
local langButtonH = if touch then 52 else 44
|
||||
local toggleH = if touch then 48 else 40
|
||||
local y = 100 + langButtonH + 12
|
||||
local mouseY: number? = nil
|
||||
if not touch then
|
||||
mouseY = y
|
||||
y += 90
|
||||
end
|
||||
local sfxY = y
|
||||
y += toggleH + 12
|
||||
local devY: number? = nil
|
||||
if dev then
|
||||
devY = y
|
||||
y += 30 + toggleH + 12
|
||||
end
|
||||
local setH = y + 4
|
||||
local settingsPanel = rect(cx - PANEL_W / 2, math.max(6, H * 0.48 - setH / 2), PANEL_W, setH)
|
||||
|
||||
return {
|
||||
scale = s,
|
||||
width = W,
|
||||
height = H,
|
||||
touch = touch,
|
||||
money = money,
|
||||
carry = carry,
|
||||
hint = hint,
|
||||
toasts = toasts,
|
||||
card = card,
|
||||
buy = buy,
|
||||
settings = settings,
|
||||
list = list,
|
||||
double = double,
|
||||
boost = boost,
|
||||
panel = panel,
|
||||
settingsPanel = settingsPanel,
|
||||
rows = {
|
||||
langButtonH = langButtonH,
|
||||
mouseY = mouseY,
|
||||
sfxY = sfxY,
|
||||
toggleH = toggleH,
|
||||
devY = devY,
|
||||
devButtonH = toggleH,
|
||||
closeH = if touch then 48 else 42,
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
return Layout
|
||||
@@ -25,12 +25,34 @@ while not player:GetAttribute("Ready") do
|
||||
end
|
||||
|
||||
local hud = Hud.build(player:WaitForChild("PlayerGui"), player, send)
|
||||
local UserInputService = game:GetService("UserInputService")
|
||||
local GuiService = game:GetService("GuiService")
|
||||
local camera = workspace.CurrentCamera
|
||||
local function rescale()
|
||||
hud.setScale(Hud.scaleFor(camera.ViewportSize))
|
||||
-- 휴대폰·태블릿 배치: 마지막 입력이 터치면 켜고, 마우스·게임패드면 끕니다(키보드 입력은 채팅일 수 있어 무시).
|
||||
local touch = UserInputService.TouchEnabled and not UserInputService.MouseEnabled
|
||||
local function relayout()
|
||||
-- ScreenGui 크기는 상단 바·노치를 뺀 영역입니다. 첫 프레임 전이라 0이면 화면 크기에서 상단 바만 뺍니다.
|
||||
local size = hud.gui.AbsoluteSize
|
||||
if size.X < 2 or size.Y < 2 then
|
||||
size = camera.ViewportSize - Vector2.new(0, GuiService:GetGuiInset().Y)
|
||||
end
|
||||
hud.setLayout(size, touch)
|
||||
end
|
||||
camera:GetPropertyChangedSignal("ViewportSize"):Connect(rescale)
|
||||
rescale()
|
||||
UserInputService.LastInputTypeChanged:Connect(function(t)
|
||||
local isTouch: boolean? = nil
|
||||
if t == Enum.UserInputType.Touch then
|
||||
isTouch = true
|
||||
elseif t.Name:sub(1, 5) == "Mouse" or t.Name:sub(1, 7) == "Gamepad" then
|
||||
isTouch = false
|
||||
end
|
||||
if isTouch ~= nil and isTouch ~= touch then
|
||||
touch = isTouch
|
||||
relayout()
|
||||
end
|
||||
end)
|
||||
hud.gui:GetPropertyChangedSignal("AbsoluteSize"):Connect(relayout)
|
||||
camera:GetPropertyChangedSignal("ViewportSize"):Connect(relayout)
|
||||
relayout()
|
||||
-- 구매·확장 효과음은 내 화면에서만 크게(위치 없이) 들립니다.
|
||||
local Sounds = require(ReplicatedStorage:WaitForChild("Shared"):WaitForChild("Sounds"))
|
||||
local sfxGroup = SoundService:WaitForChild("Sfx") :: SoundGroup
|
||||
@@ -76,7 +98,6 @@ Plots.start(world:WaitForChild("Plots"), player, player.UserId, send)
|
||||
|
||||
Guide.start(player)
|
||||
MouseLook.start(player, hud.menuOpen)
|
||||
local UserInputService = game:GetService("UserInputService")
|
||||
if player:GetAttribute("MouseLook") == true and UserInputService.MouseEnabled and UserInputService.KeyboardEnabled then
|
||||
hud.notify("mouseHint")
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user