# ui/uiwindow (vanilla.js 0.4.0)

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

창 쌓기의 창 하나. (UIWindowLayer 가 띄우고 치운다)

## UIWindow extends WorldNode

창 쌓기의 창 하나. (UIWindowLayer 가 띄우고 치운다)
- 영역 전체를 어둡게 덮고(뒤로 누름이 가지 않는다) 가운데에 판을 띄운다. 어둠은 세이프에어리어(setViewBleed)까지 덮는다.
- 판은 영역의 가로에 맞춰 넓어지되 maximumWidth 를 넘지 않는다. 세로는 layoutContent 가 돌려준 값이고, 영역보다 크면 판을 통째로 줄인다.
- 열고 닫는 움직임은 PopupMotion 이다. 닫는 움직임이 끝나면 창 층이 떼어 낸다. (그동안은 누름을 받지 않는다)
- 바깥(어둠)을 누르면 닫힌다. 창마다 setOutsideCloseEnabled 로 끈다. 창 층의 closeTopWindow(뒤로 가기)도 이 값을 따른다.
- 노드 구성: 창(영역 크기) ├ 어둠(dimNode, Paint + UIButton) └ 틀(frameNode, 판 가운데 피봇, 움직임 배율) └ 판(panelNode, Paint 한 장, 내용은 여기)
- 판 모양(그림자, 테, 글로시 같은 꾸밈)은 게임 몫이다. 게임은 이 클래스를 상속해 생성자에서 꾸밈 노드를 틀에 붙이고
  (판 뒤에 둘 것은 setSiblingIndex(0)), layoutPanel 을 덮어써 판 크기에 맞춰 놓는다. 기본 판 Paint 는 getPanelPaint() 로 바꾸거나 끈다.
  움직임 모양(아래에서 올라오는 판 등)은 applyMotion 을 덮어쓴다.
- 내용은 파생 클래스가 layoutContent(panelWidth) 에서 판 안에 놓고 판의 세로를 돌려준다. (기본은 setPanelHeight 의 값)
- 사용:
    const window = new UIWindow("settings");
    window.getPanelNode().addChild(contentNode);
    windowLayer.openWindow(window);
    window.close();

예제: 내용을 놓는 창을 상속해 띄우기

```js
import { Engine, EngineConfiguration, UIScene, UIWindow, UIWindowLayer, UILabel, WorldNode, Pivot, Vector2 } from "./build/vanilla.js";

class NoticeWindow extends UIWindow {
	#messageNode;

	constructor(name, messageText) {
		super(name);
		const messageNode = new WorldNode();
		messageNode.setPivot(Pivot.topLeft.clone());
		messageNode.setAnchor(Pivot.topLeft.clone());
		const messageLabel = messageNode.addComponent(UILabel);
		messageLabel.setText(messageText);
		messageLabel.setFontSize(18);
		const panelNode = this.getPanelNode();
		panelNode.addChild(messageNode);
		this.#messageNode = messageNode;
	}

	getMessageNode() {
		return this.#messageNode;
	}

	layoutContent(panelWidth) {
		const messageNode = this.getMessageNode();
		messageNode.setLocalPosition(Vector2.create(24, 24));
		messageNode.setContentSize(Vector2.create(panelWidth - 48, 64));
		return 112;
	}
}

class WindowScene 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);
		const noticeWindow = new NoticeWindow("notice", "New items arrived in the shop.");
		noticeWindow.setMaximumWidth(360);
		noticeWindow.setOutsideCloseEnabled(false);
		windowLayer.openWindow(noticeWindow);
	}
}

const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
const scene = new WindowScene();
scene.setLoadingMinDurationMs(0);
engine.run(scene);
```

- `constructor(name = "UIWindow")` (constructor, since 0.4.0): 생성.
  - `name` string: 창 이름. (UIWindowLayer.findWindow 로 찾는다)
- `getPanelNode()` (method, since 0.4.0): 판 노드 반환. (내용을 여기에 붙인다)
  - returns WorldNode: 판 노드.
- `getPanelPaint()` (method, since 0.4.0): 판의 Paint 반환. (색, 둥근 정도를 바꾸거나 setEnable(false) 로 끄고 게임의 판을 쓴다)
  - returns Paint: 판의 Paint.
- `getFrameNode()` (method, since 0.4.0): 틀 노드 반환. (판과 함께 커지고 주는 꾸밈을 붙이는 곳)
  - returns WorldNode: 틀 노드. (판의 가운데가 피봇)
- `getDimNode()` (method, since 0.4.0): 어둠 노드 반환.
  - returns WorldNode: 어둠 노드.
- `getDimPaint()` (method, since 0.4.0): 어둠의 Paint 반환. (색을 바꾼다)
  - returns Paint: 어둠의 Paint.
- `setDimColor(dimColor)` (method, since 0.4.0): 어둠 색 설정. (어둠의 Paint 색을 바꾼다)
  - `dimColor` Color | string: 어둠 색. (기본 검정 알파 0.55, 움직임이 알파를 0 ~ 1 배로 곱한다)
- `setPanelColor(panelColor)` (method, since 0.4.0): 판 색 설정. (판의 Paint 색을 바꾼다)
  - `panelColor` Color | string: 판 색.
- `getPopupMotion()` (method, since 0.4.0): 움직임 반환. (setInstantEnabled 로 움직임 없이 열고 닫는다)
  - returns PopupMotion: 이 창의 움직임.
- `setOutsideCloseEnabled(isOutsideCloseEnabled)` (method, since 0.4.0): 바깥 누르기(와 창 층의 closeTopWindow)로 닫히는지 설정. (기본 true)
  - `isOutsideCloseEnabled` boolean: 참이면 바깥을 누르거나 closeTopWindow 로 닫힌다.
- `isOutsideCloseEnabled()` (method, since 0.4.0): 바깥 누르기로 닫히는지.
  - returns boolean: 바깥 누르기로 닫히면 참.
- `setCloseEvent(closeEvent)` (method, since 0.4.0): 창 층에서 내려갈 때 알림 설정. (닫기 단추, 바깥 누르기, closeAllWindows 모두)
  - `closeEvent` Function | null: () => void
- `setMaximumWidth(maximumWidth)` (method, since 0.4.0): 창의 가로 한계 설정. (영역이 좁으면 그보다 좁아진다)
  - `maximumWidth` number: 판 너비의 한계. (UI 층 단위, 1 보다 작으면 1, 기본 480)
- `getMaximumWidth()` (method, since 0.4.0): 창의 가로 한계 반환.
  - returns number: 판 너비의 한계. (UI 층 단위)
- `setMargin(margin)` (method, since 0.4.0): 영역 가장자리와 판 사이 거리 설정.
  - `margin` number: 영역 가장자리와 판 사이 거리. (UI 층 단위, 음수면 0, 기본 16)
- `getMargin()` (method, since 0.4.0): 영역 가장자리와 판 사이 거리 반환.
  - returns number: 영역 가장자리와 판 사이 거리. (UI 층 단위)
- `setPanelHeight(panelHeight)` (method, since 0.4.0): 판의 세로 설정. (layoutContent 를 덮어쓰지 않은 창이 쓴다)
  - `panelHeight` number: 판의 세로. (UI 층 단위, 1 보다 작으면 1, 기본 240)
- `getPanelHeight()` (method, since 0.4.0): 판의 세로 반환.
  - returns number: setPanelHeight 로 정한 판의 세로. (UI 층 단위)
- `getViewWidth()` (method, since 0.4.0): 마지막으로 받은 영역의 너비. (UI 층 단위)
  - returns number: 영역의 너비. (UI 층 단위, 받기 전이면 1)
- `getViewHeight()` (method, since 0.4.0): 마지막으로 받은 영역의 높이. (UI 층 단위, 내용이 세로를 채우는 창이 쓴다)
  - returns number: 영역의 높이. (UI 층 단위, 받기 전이면 1)
- `getViewBleed()` (method, since 0.4.0): 영역 밖으로 더 덮는 너비 반환. { top, right, bottom, left }
  - returns object: 덮는 너비. ({ top, right, bottom, left }, UI 층 단위, 복사하지 않은 원본)
- `getPanelRect()` (method, since 0.4.0): 마지막으로 놓은 판의 자리. (창 좌표, 움직임 전, 줄인 배율을 곱한 크기)
  - returns Rect: 판의 자리. (창 좌표)
- `getPanelScale()` (method, since 0.4.0): 판이 영역보다 커서 줄인 배율. (1 이하)
  - returns number: 줄인 배율. (0 초과 1 이하)
- `getWindowLayer()` (method, since 0.4.0): 띄운 창 층 반환. (띄우기 전이나 내려간 뒤면 null)
  - returns *: 띄운 UIWindowLayer. (없으면 null)
- `setWindowLayer(windowLayer)` (method, since 0.4.0): 띄운 창 층 설정. (창 층이 부른다)
  - `windowLayer` *: 띄운 UIWindowLayer. (내려가면 null)
- `close()` (method, since 0.4.0): 닫기. (창 층에서 내린다. 닫는 움직임이 끝나면 떼어 낸다, 띄우지 않았으면 아무 일도 없다)
- `handleClosed()` (method, since 0.4.0): 창 층에서 내려감. (창 층이 부른다, 파생 클래스가 덮어쓰면 super 를 부른다)
- `setViewBleed(top, right, bottom, left)` (method, since 0.4.0): 영역 밖으로 더 덮는 너비 알리기. (세이프에어리어, UI 층 단위, 어둠이 그 밑까지 덮는다)
  - `top` number: 위로 더 덮는 너비. (UI 층 단위, 음수면 0)
  - `right` number: 오른쪽으로 더 덮는 너비. (UI 층 단위, 음수면 0)
  - `bottom` number: 아래로 더 덮는 너비. (UI 층 단위, 음수면 0)
  - `left` number: 왼쪽으로 더 덮는 너비. (UI 층 단위, 음수면 0)
- `placeDimNode()` (method, since 0.4.0): 어둠 놓기. (영역과 그 밖의 세이프에어리어까지)
- `setViewSize(viewWidth, viewHeight)` (method, since 0.4.0): 영역의 크기 알리기. (어둠을 덮고, 판의 가로를 정해 내용을 놓은 뒤 가운데에 둔다)
  - `viewWidth` number: UI 층 단위.
  - `viewHeight` number: 영역의 높이. (UI 층 단위, 1 보다 작으면 1)
- `refreshLayout()` (method, since 0.4.0): 다시 놓기. (내용이 바뀌어 판의 세로가 달라질 때, 마지막 영역의 크기로)
- `layoutContent(panelWidth)` (method, since 0.4.0): 내용 놓기. (파생 클래스가 덮어써 판 안에 내용을 놓고 판의 세로를 돌려준다)
  - `panelWidth` number: 판의 너비. (UI 층 단위, 영역 너비에서 여백을 뺀 값과 가로 한계 가운데 작은 것)
  - returns number: 판의 세로. (UI 층 단위, 기본은 getPanelHeight)
- `layoutPanel(panelWidth, panelHeight)` (method, since 0.4.0): 판 놓기. (판의 크기를 정한다, 꾸밈을 단 파생 클래스가 덮어써 super 를 부른 뒤 꾸밈을 놓는다)
  - `panelWidth` number: 판의 너비. (UI 층 단위, 줄이기 전)
  - `panelHeight` number: 판의 세로. (UI 층 단위, 줄이기 전)
- `applyMotion()` (method, since 0.4.0): 움직임을 틀과 어둠에 걸기. (틀 배율 = 줄인 배율 x 움직임 배율, 어둠 진하기 = 움직임 비율, 파생 클래스가 덮어써 모양을 바꾼다)
- `startOpenMotion()` (method, since 0.4.0): 여는 움직임 시작. (창 층이 띄울 때 부른다)
- `startCloseMotion()` (method, since 0.4.0): 닫는 움직임 시작. (창 층이 내릴 때 부른다, 그동안은 누름을 받지 않는다)
- `isCloseMotionFinished()` (method, since 0.4.0): 닫는 움직임이 끝났는지. (창 층이 떼어 낼 때를 본다)
  - returns boolean: 움직임이 닫힘 상태면 참.
- `tick(timeDelta)` (method, since 0.4.0): 매 프레임. (자식 다음에 움직임)
  - `timeDelta` number: 지난 프레임부터의 시간. (초)
- `setCovered(isCovered)` (method, since 0.4.0): 다른 창에 덮였는지 알리기. (맨 위의 창만 보인다, 기본은 덮이면 숨고 드러나면 다시 보인다)
  - DOM 입력처럼 캔버스 밖에 붙인 것이 있으면 파생 클래스가 덮어써 함께 치운다.
  - `isCovered` boolean: 참이면 다른 창에 덮였다.
- `handleWheel(viewInputPosition, wheelDelta)` (method, since 0.4.0): 마우스 휠. (맨 위의 창이면 창 층이 먼저 준다, 받았으면 true, 파생 클래스가 덮어쓴다)
  - `viewInputPosition` Vector2: 입력 위치. (뷰 좌표)
  - `wheelDelta` Vector2: 휠 누적값.
  - returns boolean: 받았으면 참. (기본은 늘 거짓)
- `dispose()` (method, since 0.4.0): 떼어 낼 때. (DOM 입력처럼 엔진 밖에 붙인 것을 정리한다, 파생 클래스가 덮어쓴다)
