# ui/uidialog (vanilla.js 0.4.0)

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

확인 대화 상자.

## UIDialog extends WorldNode

확인 대화 상자.
- 어둡게 가리는 막 + 가운데 카드 + 확인 / 취소 단추를 한 번의 show() 로 띄운다.
  등장 / 퇴장은 PopupMotion(되튕김 확대 / 수축)으로 움직인다.
- 막을 누르면 취소로 처리한다. onCancel 을 넘기지 않으면 확인만 있는 알림이 된다.
- 씬 뿌리의 맨 위(마지막 자식)에 addChild 해 두고 쓴다.
- 사용:
    const dialog = new UIDialog();
    scene.getRoot().addChild(dialog);
    dialog.show("정말 삭제할까요?", { onConfirm: () => remove(), onCancel: () => {} });

예제: 확인과 취소를 묻는 대화 상자

```js
import { Engine, EngineConfiguration, UIScene, UIDialog } from "./build/vanilla.js";

class DialogScene extends UIScene {
	initialize(engine) {
		super.initialize(engine);
		const dialog = new UIDialog({ width: 360, height: 200, confirmText: "Delete", cancelText: "Keep" });
		const root = this.getRoot();
		root.addChild(dialog);
		dialog.show("Delete this save file?", {
			onConfirm: () => {
				console.log("deleted");
			},
			onCancel: () => {
				console.log("kept");
			},
		});
	}
}

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

- `constructor(options = {})` (constructor, since 0.3.0): 생성.
  - `options` object: { width = 420, height = 240, confirmText = "확인", cancelText = "취소",
                            panelColor?, accentColor?, textColor? }
- `show(messageText, options = {})` (method, since 0.3.0): 대화 상자 열기.
  - onCancel 을 넘기지 않으면 취소 단추를 감추고 확인 단추를 가운데로 넓힌다.
  - `messageText` string: 본문 글. (카드 너비에 맞춰 줄을 바꾼다)
  - `options` object: { onConfirm?, onCancel?, confirmText?, cancelText? }
- `dismiss(isConfirmed)` (method, since 0.3.0): 닫기. (isConfirmed 에 따라 확인 / 취소 처리를 부른다)
  - `isConfirmed` boolean: 참이면 onConfirm, 거짓이면 onCancel 을 부른다. (다 열리기 전이면 아무것도 하지 않는다)
- `requestDismiss(isConfirmed)` (method, since 0.4.0): 다음 tick 에 닫기. (tick 밖에서 닫기를 미룰 때)
  - `isConfirmed` boolean: 참이면 확인, 거짓이면 취소로 닫는다.
- `tick(timeDelta)` (method, since 0.3.0): 갱신.
  - `timeDelta` number: 지난 프레임부터의 시간. (초)
- `isShowing()` (method, since 0.3.0): 표시 중 여부.
  - returns boolean: 닫힘 상태가 아니면 참. (여는 중, 닫는 중도 참)
- `setInstantEnabled(isInstantEnabled)` (method, since 0.3.0): 즉시 전환 여부 설정. (연출 없는 UI 톤)
  - `isInstantEnabled` boolean: 참이면 연출 없이 바로 열고 닫는다.
- `getPopupMotion()` (method, since 0.4.0): 연출 반환.
  - returns PopupMotion: 여닫는 연출.
- `getOverlayNode()` (method, since 0.4.0): 뒤를 덮는 막 노드 반환.
  - returns WorldNode: 막 노드.
- `getPanelNode()` (method, since 0.4.0): 판 노드 반환.
  - returns WorldNode: 판 노드.
- `getConfirmNode()` (method, since 0.4.0): 확인 단추 노드 반환.
  - returns WorldNode: 확인 단추 노드.

  예제: 확인 단추 노드를 찾아 이름과 크기 읽기

  ```js
  import { UIDialog } from "./build/vanilla.js";
  
  const dialog = new UIDialog({ confirmText: "OK", cancelText: "Cancel" });
  const confirmNode = dialog.getConfirmNode();
  const cancelNode = dialog.getCancelNode();
  console.log(confirmNode.getName(), cancelNode.getName(), dialog.getPanelNode().getName());
  ```

- `getCancelNode()` (method, since 0.4.0): 취소 단추 노드 반환.
  - returns WorldNode: 취소 단추 노드.
