vanilladocs
vanillapunch.com
API / ui/uiwindowlayer

ui/uiwindowlayer

창 층. (영역 위에 UIWindow 를 쌓는다)

Window layer. (stacks UIWindow over the area)

UIWindowLayerextends WorldNode

짝Counterpart: vanilla-engine UIWindowLayer

창 층. (영역 위에 UIWindow 를 쌓는다)

  • 창을 띄우면 맨 위에 쌓고, 맨 위의 창만 보인다. 위의 창이 닫히면 아래 창이 다시 보인다.
  • 닫으면 목록에서 바로 빠져 누름과 덮임이 바로 풀리고, 닫는 움직임(PopupMotion)이 끝난 뒤에 떼어 낸다. 덮여 있던 창을 닫으면 움직임 없이 바로 떼어 낸다.
  • 이 층은 UI 배율(UIScale.read)만큼 커지고, 창에는 그만큼 나눈 영역의 크기와 세이프에어리어 너비를 알린다. (작은 화면에서도 글자가 읽히게) setUIScaleOptions(null) 이면 키우지 않는다.
  • 창이 하나라도 떠 있는 동안은 놀이 밖이다. 창이 뜨고 닫힐 때 알리므로(setWindowChangeEvent) 게임이 놀이를 멈추고 이어 간다.
  • 휠은 맨 위의 창이 먼저 받는다(UIWindow.handleWheel), 받지 않으면 그 자리의 스크롤 뷰. GameScene 은 창 층 안을 가리킨 휠을 scrollWindowAt 으로 넘긴다.
  • 사용: (영역 노드의 맨 위 자식으로 두고, 영역 크기가 바뀔 때마다 알린다) const windowLayer = new UIWindowLayer(); playAreaNode.addChild(windowLayer); windowLayer.setViewSize(playAreaWidth, playAreaHeight); windowLayer.setViewBleed(insets.top, insets.right, insets.bottom, insets.left); windowLayer.setWindowChangeEvent(() => { game.setPaused(windowLayer.hasOpenWindow()); }); windowLayer.openWindow(new UIConfirmWindow("quit", { title: "나가기", message: "정말 나갈까요?" }));

Window layer. (stacks UIWindow over the area)

  • Opening a window stacks it on top, and only the top window is visible. When the upper window closes, the window below is visible again.
  • Closing removes it from the list immediately so presses and covering are released at once, and it is detached after the close motion (PopupMotion) finishes. Closing a window that was covered detaches it immediately without motion.
  • This layer is enlarged by the UI scale (UIScale.read), and windows are notified of the area size and safe area width divided by that amount. (so text is readable even on small screens) With setUIScaleOptions(null) it does not enlarge.
  • While even one window is open, play is suspended. It notifies when windows open and close (setWindowChangeEvent), so the game pauses and resumes play.
  • The top window receives the wheel first (UIWindow.handleWheel), and if it does not handle it, the scroll view at that position. GameScene passes wheel input pointing inside the window layer to scrollWindowAt.
  • Usage: (place it as the topmost child of the area node, and notify it whenever the area size changes) const windowLayer = new UIWindowLayer(); playAreaNode.addChild(windowLayer); windowLayer.setViewSize(playAreaWidth, playAreaHeight); windowLayer.setViewBleed(insets.top, insets.right, insets.bottom, insets.left); windowLayer.setWindowChangeEvent(() => { game.setPaused(windowLayer.hasOpenWindow()); }); windowLayer.openWindow(new UIConfirmWindow("quit", { title: "Quit", message: "Do you really want to quit?" }));
예제Example창 둘을 쌓고 맨 위 창 닫기Stacking two windows and closing the top one
import { Engine, EngineConfiguration, UIScene, UIWindow, UIWindowLayer } from "./build/vanilla.js";

class WindowLayerScene extends UIScene {
	initialize(engine) {
		super.initialize(engine);
		const root = this.getRoot();
		const rootSize = root.getContentSize();
		const windowLayer = new UIWindowLayer();
		root.addChild(windowLayer);
		windowLayer.setViewSize(rootSize.x, rootSize.y);
		windowLayer.setWindowChangeEvent(() => {
			const windowCount = windowLayer.getWindowCount();
			console.log(windowCount);
		});

		const settingsWindow = new UIWindow("settings");
		settingsWindow.setPanelHeight(220);
		windowLayer.openWindow(settingsWindow);
		const helpWindow = new UIWindow("help");
		helpWindow.setPanelHeight(140);
		helpWindow.setMaximumWidth(300);
		windowLayer.openWindow(helpWindow);

		const isClosed = windowLayer.closeTopWindow();
		const topWindow = windowLayer.getTopWindow();
		const topWindowName = topWindow.getName();
		console.log(isClosed, topWindowName);
	}
}

const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
const scene = new WindowLayerScene();
scene.setLoadingMinDurationMs(0);
engine.run(scene);
생성자constructorconstructor()#0.4.0 부터since 0.4.0소스source

생성.

Constructor.

짝Counterpart: vanilla-engine UIWindowLayer.new

정적staticstatic findScrollViewAt(node, viewInputPosition)#0.4.0 부터since 0.4.0소스source

그 자리를 덮는 맨 앞(나중에 그리는) 스크롤 뷰 찾기. (켜진 노드만, 없으면 null)

  • UIScrollView 를 들이지 않으려고 TouchRaycaster 처럼 wheel 과 getScrollContentSize 가 있는 컴포넌트로 본다.

Finds the frontmost (drawn last) scroll view covering that position. (enabled nodes only, null if none)

  • To avoid importing UIScrollView, like TouchRaycaster it treats a component that has wheel and getScrollContentSize as one.
nodeWorldNode
찾기 시작할 노드. (자식을 뒤에서부터 먼저 본다)The node to start searching from. (children are checked first, from the last)
viewInputPositionVector2
입력 위치. (뷰 좌표)Input position. (view coordinates)

반환Returns* wheel 과 getScrollContentSize 가 있는 켜진 컴포넌트. (없으면 null)An enabled component that has wheel and getScrollContentSize. (null if none)

짝Counterpart: vanilla-engine UIWindowLayer.find_scroll_view_at

정적staticstatic findWindowLayerOf(node)#0.4.0 부터since 0.4.0소스source

노드가 들어 있는 창 층 찾기. (자기부터 부모 쪽으로, 없으면 null)

Finds the window layer containing the node. (from itself toward the parents, null if none)

node*
찾기 시작할 노드.The node to start searching from.

반환ReturnsUIWindowLayer | null 가장 가까운 창 층. (자기 자신일 수 있다, 없으면 null)The closest window layer. (can be the node itself, null if none)

짝Counterpart: vanilla-engine UIWindowLayer.find_window_layer_of

메서드methodsetWindowChangeEvent(windowChangeEvent)#0.4.0 부터since 0.4.0소스source

창이 뜨거나 닫힐 때 알림 설정.

Sets the notification for when a window opens or closes.

windowChangeEventFunction | null
() => void

짝Counterpart: vanilla-engine UIWindowLayer.set_window_change_event

메서드methodsetUIScaleOptions(uiScaleOptions)#0.4.0 부터since 0.4.0소스source

UI 배율 설정. (UIScale.read 의 options, null 이면 키우지 않는다, 기본은 {} 로 UIScale 기본값)

Sets the UI scale. (options of UIScale.read, null means no enlargement, default is {} for the UIScale defaults)

uiScaleOptionsobject | null
UIScale.read 에 넘길 설정. (null 이면 배율 1, 바로 다시 놓는다)Options to pass to UIScale.read. (scale 1 if null, re-lays out right away)

짝Counterpart: vanilla-engine UIWindowLayer.set_ui_scale_options

메서드methodgetUIScale()#0.4.0 부터since 0.4.0소스source

지금의 UI 배율.

Current UI scale.

반환Returnsnumber 이 층에 건 UI 배율. (setViewSize 때 다시 읽는다)UI scale applied to this layer. (re-read on setViewSize)

짝Counterpart: vanilla-engine UIWindowLayer.get_ui_scale

메서드methodhasOpenWindow()#0.4.0 부터since 0.4.0소스source

창이 하나라도 떠 있는지. (닫는 움직임 중인 창은 셈하지 않는다)

Whether at least one window is open. (windows in the close motion are not counted)

반환Returnsboolean 떠 있는 창이 있으면 참.True if any window is open.

짝Counterpart: vanilla-engine UIWindowLayer.has_open_window

메서드methodgetWindowCount()#0.4.0 부터since 0.4.0소스source

떠 있는 창의 수.

Number of open windows.

반환Returnsnumber 떠 있는 창의 수. (닫는 움직임 중인 창은 빼고)Number of open windows. (excluding windows in their closing motion)

짝Counterpart: vanilla-engine UIWindowLayer.get_window_count

메서드methodgetTopWindow()#0.4.0 부터since 0.4.0소스source

맨 위의 창. (없으면 null)

Top window. (null if none)

반환ReturnsUIWindow | null 맨 위의 창. (없으면 null)Top window. (null if none)

짝Counterpart: vanilla-engine UIWindowLayer.get_top_window

메서드methodfindWindow(windowName)#0.4.0 부터since 0.4.0소스source

그 이름의 창. (떠 있는 것 가운데 위에서부터, 없으면 null)

Window with that name. (from the top among the open ones, null if none)

windowNamestring
창 이름. (UIWindow 생성자에 준 이름)Window name. (the name given to the UIWindow constructor)

반환ReturnsUIWindow | null 찾은 창. (없으면 null)The found window. (null if none)

짝Counterpart: vanilla-engine UIWindowLayer.find_window

메서드methodsetViewSize(viewWidth, viewHeight)#0.4.0 부터since 0.4.0소스source

영역의 크기 알리기. (UI 배율을 다시 읽고, 띄운 창을 모두 다시 놓는다)

Notifies the area size. (rereads the UI scale and lays out all open windows again)

viewWidthnumber
부모 단위.Parent units.
viewHeightnumber
영역의 높이. (부모 단위, 1 보다 작으면 1)Area height. (parent units, 1 if less than 1)

짝Counterpart: vanilla-engine UIWindowLayer.set_view_size

메서드methodsetViewBleed(top, right, bottom, left)#0.4.0 부터since 0.4.0소스source

영역 밖으로 더 덮는 너비 알리기. (세이프에어리어, 부모 단위)

Notifies the extra width covered outside the area. (safe area, parent units)

topnumber
위로 더 덮는 너비. (부모 단위, 음수면 0)Extra width to cover above. (parent units, 0 if negative)
rightnumber
오른쪽으로 더 덮는 너비. (부모 단위, 음수면 0)Extra width to cover on the right. (parent units, 0 if negative)
bottomnumber
아래로 더 덮는 너비. (부모 단위, 음수면 0)Extra width to cover below. (parent units, 0 if negative)
leftnumber
왼쪽으로 더 덮는 너비. (부모 단위, 음수면 0)Extra width to cover on the left. (parent units, 0 if negative)

짝Counterpart: vanilla-engine UIWindowLayer.set_view_bleed

메서드methodplaceAllWindows()#0.4.0 부터since 0.4.0소스source

띄운 창과 닫는 중인 창을 모두 다시 놓기.

Lays out all open windows and closing windows again.

메서드methodplaceWindow(window)#0.4.0 부터since 0.4.0소스source

창 하나 놓기. (UI 배율로 나눈 영역의 크기와 덮는 너비를 알린다)

Lays out one window. (notifies the area size divided by the UI scale and the covering width)

windowUIWindow
놓을 창.The window to place.
메서드methodopenWindow(window)#0.4.0 부터since 0.4.0소스source

창 띄우기. (맨 위에 쌓는다, 이미 떠 있으면 맨 위로 올린다)

Opens a window. (stacks it on top, brings it to the top if already open)

windowUIWindow
띄울 창. (닫는 움직임 중이었으면 다시 연다)The window to show. (reopened if it was in its closing motion)

짝Counterpart: vanilla-engine UIWindowLayer.open_window

메서드methodcloseWindow(window)#0.4.0 부터since 0.4.0소스source

창 닫기. (목록에서 빼고 닫는 움직임을 시작한다, 떠 있지 않으면 아무 일도 없다)

Closes a window. (removes it from the list and starts the close motion, does nothing if not open)

windowUIWindow
닫을 창.The window to close.

짝Counterpart: vanilla-engine UIWindowLayer.close_window

메서드methodcloseAllWindows()#0.4.0 부터since 0.4.0소스source

창 모두 닫기. (위에서부터)

Closes all windows. (from the top)

짝Counterpart: vanilla-engine UIWindowLayer.close_all_windows

메서드methodcloseTopWindow()#0.4.0 부터since 0.4.0소스source

맨 위의 창 닫기. (기기의 뒤로 가기 자리, 바깥 닫기를 끈 창이면 닫지 않는다, 닫았으면 true)

Closes the top window. (for the device's back button, does not close a window with outside close turned off, true if closed)

반환Returnsboolean 닫았으면 참. (창이 없거나 바깥 닫기를 끈 창이면 거짓)True if closed. (false if there is no window or the window has outside close turned off)

짝Counterpart: vanilla-engine UIWindowLayer.close_top_window

메서드methodremoveWindowNode(window)#0.4.0 부터since 0.4.0소스source

창 노드 떼어 내기.

Detaches a window node.

windowUIWindow
떼어 낼 창. (창 층을 null 로 하고 dispose 를 부른 뒤 자식에서 뺀다)The window to detach. (sets its window layer to null, calls dispose and removes it from the children)
메서드methodrefreshWindowCovers()#0.4.0 부터since 0.4.0소스source

창 덮기. (맨 위의 창만 보이고 아래 창은 숨긴다)

Covers windows. (only the top window is visible, the windows below are hidden)

메서드methodnotifyWindowChange()#0.4.0 부터since 0.4.0소스source

창이 뜨거나 닫혔다고 알리기.

Notifies that a window opened or closed.

메서드methodtick(timeDelta)#0.4.0 부터since 0.4.0소스source

매 프레임. (창들이 움직인 뒤 닫는 움직임이 끝난 창을 떼어 낸다)

Every frame. (after the windows move, detaches windows whose close motion has finished)

timeDeltanumber
지난 프레임부터의 시간. (초)Time since the last frame. (Seconds)
메서드methodscrollWindowAt(viewInputPosition, wheelDelta)#0.4.0 부터since 0.4.0소스source

마우스 휠을 맨 위의 창에 넘기기. (창이 받지 않으면 그 자리의 스크롤 뷰, 받았으면 true)

Passes the mouse wheel to the top window. (if the window does not handle it, the scroll view at that position, true if handled)

viewInputPositionVector2
입력 위치. (뷰 좌표)Input position. (view coordinates)
wheelDeltaVector2
휠 누적값.Accumulated wheel delta.

반환Returnsboolean 창이나 스크롤 뷰가 받았으면 참. (창이 없으면 거짓)True if the window or a scroll view handled it. (false if there is no window)

짝Counterpart: vanilla-engine UIWindowLayer.scroll_window_at