# ui/uiwindowlayer (vanilla.js 0.4.0)

> https://vanillapunch.com/docs/vanilla.js/0.4.0/api/ui/uiwindowlayer/

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

## UIWindowLayer extends WorldNode

창 층. (영역 위에 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: "정말 나갈까요?" }));

예제: 창 둘을 쌓고 맨 위 창 닫기

```js
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);
```

- `constructor()` (constructor, since 0.4.0): 생성.
- `setWindowChangeEvent(windowChangeEvent)` (method, since 0.4.0): 창이 뜨거나 닫힐 때 알림 설정.
  - `windowChangeEvent` Function | null: () => void
- `setUIScaleOptions(uiScaleOptions)` (method, since 0.4.0): UI 배율 설정. (UIScale.read 의 options, null 이면 키우지 않는다, 기본은 {} 로 UIScale 기본값)
  - `uiScaleOptions` object | null: UIScale.read 에 넘길 설정. (null 이면 배율 1, 바로 다시 놓는다)
- `getUIScale()` (method, since 0.4.0): 지금의 UI 배율.
  - returns number: 이 층에 건 UI 배율. (setViewSize 때 다시 읽는다)
- `hasOpenWindow()` (method, since 0.4.0): 창이 하나라도 떠 있는지. (닫는 움직임 중인 창은 셈하지 않는다)
  - returns boolean: 떠 있는 창이 있으면 참.
- `getWindowCount()` (method, since 0.4.0): 떠 있는 창의 수.
  - returns number: 떠 있는 창의 수. (닫는 움직임 중인 창은 빼고)
- `getTopWindow()` (method, since 0.4.0): 맨 위의 창. (없으면 null)
  - returns UIWindow | null: 맨 위의 창. (없으면 null)
- `findWindow(windowName)` (method, since 0.4.0): 그 이름의 창. (떠 있는 것 가운데 위에서부터, 없으면 null)
  - `windowName` string: 창 이름. (UIWindow 생성자에 준 이름)
  - returns UIWindow | null: 찾은 창. (없으면 null)
- `setViewSize(viewWidth, viewHeight)` (method, since 0.4.0): 영역의 크기 알리기. (UI 배율을 다시 읽고, 띄운 창을 모두 다시 놓는다)
  - `viewWidth` number: 부모 단위.
  - `viewHeight` number: 영역의 높이. (부모 단위, 1 보다 작으면 1)
- `setViewBleed(top, right, bottom, left)` (method, since 0.4.0): 영역 밖으로 더 덮는 너비 알리기. (세이프에어리어, 부모 단위)
  - `top` number: 위로 더 덮는 너비. (부모 단위, 음수면 0)
  - `right` number: 오른쪽으로 더 덮는 너비. (부모 단위, 음수면 0)
  - `bottom` number: 아래로 더 덮는 너비. (부모 단위, 음수면 0)
  - `left` number: 왼쪽으로 더 덮는 너비. (부모 단위, 음수면 0)
- `placeAllWindows()` (method, since 0.4.0): 띄운 창과 닫는 중인 창을 모두 다시 놓기.
- `placeWindow(window)` (method, since 0.4.0): 창 하나 놓기. (UI 배율로 나눈 영역의 크기와 덮는 너비를 알린다)
  - `window` UIWindow: 놓을 창.
- `openWindow(window)` (method, since 0.4.0): 창 띄우기. (맨 위에 쌓는다, 이미 떠 있으면 맨 위로 올린다)
  - `window` UIWindow: 띄울 창. (닫는 움직임 중이었으면 다시 연다)
- `closeWindow(window)` (method, since 0.4.0): 창 닫기. (목록에서 빼고 닫는 움직임을 시작한다, 떠 있지 않으면 아무 일도 없다)
  - `window` UIWindow: 닫을 창.
- `closeAllWindows()` (method, since 0.4.0): 창 모두 닫기. (위에서부터)
- `closeTopWindow()` (method, since 0.4.0): 맨 위의 창 닫기. (기기의 뒤로 가기 자리, 바깥 닫기를 끈 창이면 닫지 않는다, 닫았으면 true)
  - returns boolean: 닫았으면 참. (창이 없거나 바깥 닫기를 끈 창이면 거짓)
- `removeWindowNode(window)` (method, since 0.4.0): 창 노드 떼어 내기.
  - `window` UIWindow: 떼어 낼 창. (창 층을 null 로 하고 dispose 를 부른 뒤 자식에서 뺀다)
- `refreshWindowCovers()` (method, since 0.4.0): 창 덮기. (맨 위의 창만 보이고 아래 창은 숨긴다)
- `notifyWindowChange()` (method, since 0.4.0): 창이 뜨거나 닫혔다고 알리기.
- `tick(timeDelta)` (method, since 0.4.0): 매 프레임. (창들이 움직인 뒤 닫는 움직임이 끝난 창을 떼어 낸다)
  - `timeDelta` number: 지난 프레임부터의 시간. (초)
- `scrollWindowAt(viewInputPosition, wheelDelta)` (method, since 0.4.0): 마우스 휠을 맨 위의 창에 넘기기. (창이 받지 않으면 그 자리의 스크롤 뷰, 받았으면 true)
  - `viewInputPosition` Vector2: 입력 위치. (뷰 좌표)
  - `wheelDelta` Vector2: 휠 누적값.
  - returns boolean: 창이나 스크롤 뷰가 받았으면 참. (창이 없으면 거짓)
- `static findScrollViewAt(node, viewInputPosition)` (static, since 0.4.0): 그 자리를 덮는 맨 앞(나중에 그리는) 스크롤 뷰 찾기. (켜진 노드만, 없으면 null)
  - UIScrollView 를 들이지 않으려고 TouchRaycaster 처럼 wheel 과 getScrollContentSize 가 있는 컴포넌트로 본다.
  - `node` WorldNode: 찾기 시작할 노드. (자식을 뒤에서부터 먼저 본다)
  - `viewInputPosition` Vector2: 입력 위치. (뷰 좌표)
  - returns *: wheel 과 getScrollContentSize 가 있는 켜진 컴포넌트. (없으면 null)
- `static findWindowLayerOf(node)` (static, since 0.4.0): 노드가 들어 있는 창 층 찾기. (자기부터 부모 쪽으로, 없으면 null)
  - `node` *: 찾기 시작할 노드.
  - returns UIWindowLayer | null: 가장 가까운 창 층. (자기 자신일 수 있다, 없으면 null)
