core/modaldialog
모달 질문 창. (게임이 부르던 브라우저 window.alert, window.confirm, window.prompt 자리, 러스트 판 core/modaldialog.rs 와 같다)
- 엔진이 캔버스 위에 크롬 탭 모달 대화 상자(JavaScriptTabModalDialogViewViews)와 같은 질문 창을 그린다. (브라우저 창을 띄우지 않는다)
- 자리: 캔버스 안쪽 가로 가운데, 위 끝. 제목은 "이 페이지 내용:" (브라우저 화면 언어, core/browseruitext.js) 닫기 X 는 없다.
- alert 는 확인만, confirm 과 prompt 는 확인과 취소. 기본 단추는 확인이다. 단추 차례는 크롬처럼 윈도우
[확인][취소], 그 밖[취소][확인]. - prompt 입력 칸은 기본값을 넣고 모두 고른 채로 초점을 받는다. Enter 는 확인, Escape 는 취소.
- 떠 있는 동안 씬을 갱신하지 않고(그리기는 멈춘 화면 그대로), 키보드 초점은 창이 가진다. 닫히면 눌린 키와 단추를 비우고 초점을 돌려준다.
- 입력 칸 글은 숨긴 DOM 입력이 받는다(IME, 편집 키, 되돌리기). 누르고 끌어 커서와 선택을 정한다.
- 여러 개를 한 프레임에 부르면 차례로 띄운다.
- 그림자는 크롬 bubble_border 의 두 겹(아래로 2, 흐림 8 과 12)을 views 시그마의 가우스로 구워 그린다. (core/blurshadow.js)
Modal dialog. (in place of the browser window.alert, window.confirm and window.prompt that games called, same as core/modaldialog.rs in the Rust edition)
- The engine draws a dialog like the Chrome tab modal dialog (JavaScriptTabModalDialogViewViews) on top of the canvas. (no browser dialog is opened)
- Position: horizontal center at the top edge of the canvas. The title is "This page says" (in the browser UI language, core/browseruitext.js). There is no close X.
- alert has only OK, confirm and prompt have OK and Cancel. The default button is OK. The button order follows Chrome:
[OK][Cancel]on Windows,[Cancel][OK]elsewhere. - The prompt field gets the default value fully selected and takes focus. Enter confirms, Escape cancels.
- While open, scenes are not updated (the frozen screen is still drawn) and the dialog holds the keyboard focus. When it closes, pressed keys and buttons are cleared and focus is given back.
- A hidden DOM input receives the field text (IME, editing keys, undo). Pressing and dragging sets the cursor and selection.
- Several dialogs requested in one frame are shown one after another.
- The shadow bakes the two layers of the Chrome bubble_border (offset 2 down, blur 8 and 12) as Gaussians with the views sigma. (core/blurshadow.js)
ModalDialogResult
질문 창의 답. (러스트 판 ModalDialogResult 의 Confirmed(글), Cancelled)
The dialog answer. (Confirmed(text) and Cancelled of the Rust ModalDialogResult)
import { ModalDialogResult } from "./build/vanilla.js";
const confirmed = ModalDialogResult.confirmed("hello");
const cancelled = ModalDialogResult.cancelled();
console.log(confirmed.isConfirmed(), confirmed.getText(), cancelled.isConfirmed());생성. (confirmed, cancelled 로 만든다)
Constructor. (create with confirmed or cancelled)
- isConfirmedboolean
- 확인했으면 참.true if confirmed.
- textstring
- 확인한 글.The confirmed text.
확인한 답.
A confirmed answer.
- textstring
- 확인한 글. (prompt 는 입력한 글, alert 와 confirm 은 빈 글)The confirmed text. (the entered text for prompt, an empty string for alert and confirm)
반환ReturnsModalDialogResult 확인한 답.A confirmed answer.
취소한 답. (prompt 의 null, confirm 의 false)
A cancelled answer. (null for prompt, false for confirm)
반환ReturnsModalDialogResult 취소한 답.A cancelled answer.
확인했는지 반환.
Returns whether it was confirmed.
반환Returnsboolean 확인했으면 참.true if confirmed.
확인한 글 반환.
Returns the confirmed text.
반환Returnsstring 확인한 글. (취소했으면 빈 글)The confirmed text. (an empty string if cancelled)
ModalDialogHandle
질문 창 손잡이. (러스트 판 ModalDialogHandle)
- 답하면 끝나고(isFinished), 답은 getResult, isConfirmed, getPromptText 로 읽는다.
- Engine.alert, Engine.confirm, Engine.prompt 가 엔진이 그린 질문 창을 띄우고 돌려준다. (러스트 판 Engine::alert, confirm, prompt 와 같다)
- 창에 답하면 끝난다. 두 엔진 모두 끝난 뒤 부를 함수는 setCallback 으로 건다.
- await 하는 꼴은 Engine.alertAsync, confirmAsync, promptAsync 다.
- 캔버스가 없는 곳(node)에서는 그 자리에서 alert 는 확인, confirm 과 prompt 는 취소로 끝난다.
Modal dialog handle. (ModalDialogHandle in the Rust edition)
- It finishes when answered (isFinished), and the answer is read with getResult, isConfirmed and getPromptText.
- Engine.alert, Engine.confirm and Engine.prompt open an engine-drawn dialog and return it. (same as Engine::alert, confirm and prompt in the Rust edition)
- It finishes when the dialog is answered. In both engines the function to call afterwards is set with setCallback.
- The await form is Engine.alertAsync, confirmAsync and promptAsync.
- Where there is no canvas (node) it finishes right away: alert as confirmed, confirm and prompt as cancelled.
import { Engine, EngineConfiguration } from "./build/vanilla.js";
const engine = new Engine(new EngineConfiguration());
async function deleteSaveData() {
if (await engine.confirmAsync("Delete the save data?")) {
console.log("deleted");
}
}
function askName() {
engine.prompt("Name?", "Hero").setCallback((result) => {
console.log(result.isConfirmed() ? result.getText() : "cancelled");
});
}
console.log(typeof deleteSaveData, typeof askName, engine.isModalDialogOpen()); // function function false생성. (답을 기다리는 손잡이)
Constructor. (a handle waiting for the answer)
끝났는지 반환.
Returns whether it has finished.
반환Returnsboolean 답했으면 참.true if answered.
짝Counterpart: vanilla-engine ModalDialogHandle.is_finished
답 반환.
Returns the answer.
반환ReturnsModalDialogResult | null 답. (끝나기 전이면 null)The answer. (null before it finishes)
짝Counterpart: vanilla-engine ModalDialogHandle.get_result
확인했는지 반환.
Returns whether it was confirmed.
반환Returnsboolean 끝났고 확인했으면 참.true if finished and confirmed.
짝Counterpart: vanilla-engine ModalDialogHandle.is_confirmed
입력한 글 반환. (prompt)
Returns the entered text. (prompt)
반환Returnsstring | null 확인한 글. (끝나기 전이거나 취소했으면 null)The confirmed text. (null before it finishes or if cancelled)
짝Counterpart: vanilla-engine ModalDialogHandle.get_prompt_text
끝난 뒤 부를 함수 걸기. (이미 끝났으면 그 자리에서 부른다)
Sets the function to call after it finishes. (called on the spot if already finished)
- callbackFunction
- (result: ModalDialogResult) => void
짝Counterpart: vanilla-engine ModalDialogHandle.set_callback
ModalDialogKindenum
질문 창 종류. (window.alert, window.confirm, window.prompt)
Dialog kind. (window.alert, window.confirm, window.prompt)
| 이름Name | 값Value | 설명Description |
|---|---|---|
alert | alert | 알림 창. (확인만 있다)Alert dialog. (only OK) |
confirm | confirm | 확인 창. (확인과 취소)Confirm dialog. (OK and Cancel) |
prompt | prompt | 입력 창. (입력 칸과 확인과 취소)Prompt dialog. (an input field, OK and Cancel) |