ui/uiwindow
창 쌓기의 창 하나. (UIWindowLayer 가 띄우고 치운다)
A single window in the window stack. (UIWindowLayer opens and removes it)
UIWindowextends 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();A single window in the window stack. (UIWindowLayer opens and removes it)
- Dims the whole area (presses do not pass through to what is behind) and shows a panel in the center. The dim also covers the safe area (setViewBleed).
- The panel widens to fit the area's width but does not exceed maximumWidth. Its height is the value returned by layoutContent, and if it is larger than the area the whole panel is scaled down.
- The open and close motion is PopupMotion. When the close motion finishes, the window layer detaches it. (it does not receive presses in the meantime)
- Pressing outside (the dim) closes it. Turned off per window with setOutsideCloseEnabled. The window layer's closeTopWindow (back) also follows this value.
- Node structure: window (area size) ├ dim (dimNode, Paint + UIButton) └ frame (frameNode, panel center pivot, motion scale) └ panel (panelNode, a single Paint, content goes here)
- The panel look (decorations such as shadow, border, gloss) is up to the game. The game inherits this class, attaches decoration nodes to the frame in the constructor (setSiblingIndex(0) for things placed behind the panel), and overrides layoutPanel to fit them to the panel size. The default panel Paint is changed or turned off via getPanelPaint(). For the motion shape (a panel rising from below, etc.), override applyMotion.
- The derived class places the content inside the panel in layoutContent(panelWidth) and returns the panel's height. (default is the setPanelHeight value)
- Usage:
const window = new UIWindow("settings");
window.getPanelNode().addChild(contentNode);
windowLayer.openWindow(window);
window.close();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.
- namestring
- 창 이름. (UIWindowLayer.findWindow 로 찾는다)Window name. (found with UIWindowLayer.findWindow)
판 노드 반환. (내용을 여기에 붙인다)
Returns the panel node. (attach content here)
반환ReturnsWorldNode 판 노드.Panel node.
짝Counterpart: vanilla-engine UIWindow.get_panel_node
판의 Paint 반환. (색, 둥근 정도를 바꾸거나 setEnable(false) 로 끄고 게임의 판을 쓴다)
Returns the panel's Paint. (change its color or roundness, or turn it off with setEnable(false) and use the game's panel)
반환ReturnsPaint 판의 Paint.The panel's Paint.
짝Counterpart: vanilla-engine UIWindow.get_panel_paint
틀 노드 반환. (판과 함께 커지고 주는 꾸밈을 붙이는 곳)
Returns the frame node. (where decorations that grow and shrink with the panel are attached)
반환ReturnsWorldNode 틀 노드. (판의 가운데가 피봇)Frame node. (pivot at the panel center)
짝Counterpart: vanilla-engine UIWindow.get_frame_node
어둠 노드 반환.
Returns the dim node.
반환ReturnsWorldNode 어둠 노드.Dim node.
짝Counterpart: vanilla-engine UIWindow.get_dim_node
어둠의 Paint 반환. (색을 바꾼다)
Returns the dim's Paint. (to change its color)
반환ReturnsPaint 어둠의 Paint.The dim's Paint.
짝Counterpart: vanilla-engine UIWindow.get_dim_paint
어둠 색 설정. (어둠의 Paint 색을 바꾼다)
Sets the dim color. (changes the dim's Paint color)
- dimColorColor | string
- 어둠 색. (기본 검정 알파 0.55, 움직임이 알파를 0 ~ 1 배로 곱한다)Dim color. (default black with alpha 0.55, the motion multiplies the alpha by 0 ~ 1)
짝Counterpart: vanilla-engine UIWindow.set_dim_color
판 색 설정. (판의 Paint 색을 바꾼다)
Sets the panel color. (changes the panel's Paint color)
- panelColorColor | string
- 판 색.Panel color.
짝Counterpart: vanilla-engine UIWindow.set_panel_color
움직임 반환. (setInstantEnabled 로 움직임 없이 열고 닫는다)
Returns the motion. (setInstantEnabled opens and closes without motion)
반환ReturnsPopupMotion 이 창의 움직임.This window's motion.
짝Counterpart: vanilla-engine UIWindow.get_popup_motion
바깥 누르기(와 창 층의 closeTopWindow)로 닫히는지 설정. (기본 true)
Sets whether pressing outside (and the window layer's closeTopWindow) closes it. (default true)
- isOutsideCloseEnabledboolean
- 참이면 바깥을 누르거나 closeTopWindow 로 닫힌다.If true, it closes by pressing outside or by closeTopWindow.
짝Counterpart: vanilla-engine UIWindow.set_outside_close_enabled
바깥 누르기로 닫히는지.
Whether pressing outside closes it.
반환Returnsboolean 바깥 누르기로 닫히면 참.True if pressing outside closes it.
짝Counterpart: vanilla-engine UIWindow.is_outside_close_enabled
창 층에서 내려갈 때 알림 설정. (닫기 단추, 바깥 누르기, closeAllWindows 모두)
Sets the notification for when it is removed from the window layer. (close button, pressing outside, closeAllWindows, all of them)
- closeEventFunction | null
- () => void
짝Counterpart: vanilla-engine UIWindow.set_close_event
창의 가로 한계 설정. (영역이 좁으면 그보다 좁아진다)
Sets the window's width limit. (narrower than that if the area is narrow)
- maximumWidthnumber
- 판 너비의 한계. (UI 층 단위, 1 보다 작으면 1, 기본 480)Panel width limit. (UI layer units, 1 if less than 1, default 480)
짝Counterpart: vanilla-engine UIWindow.set_maximum_width
창의 가로 한계 반환.
Returns the window's width limit.
반환Returnsnumber 판 너비의 한계. (UI 층 단위)Panel width limit. (UI layer units)
짝Counterpart: vanilla-engine UIWindow.get_maximum_width
영역 가장자리와 판 사이 거리 설정.
Sets the distance between the area edge and the panel.
- marginnumber
- 영역 가장자리와 판 사이 거리. (UI 층 단위, 음수면 0, 기본 16)Distance between the area edge and the panel. (UI layer units, 0 if negative, default 16)
짝Counterpart: vanilla-engine UIWindow.set_margin
영역 가장자리와 판 사이 거리 반환.
Returns the distance between the area edge and the panel.
반환Returnsnumber 영역 가장자리와 판 사이 거리. (UI 층 단위)Distance between the area edge and the panel. (UI layer units)
짝Counterpart: vanilla-engine UIWindow.get_margin
판의 세로 설정. (layoutContent 를 덮어쓰지 않은 창이 쓴다)
Sets the panel's height. (used by windows that do not override layoutContent)
- panelHeightnumber
- 판의 세로. (UI 층 단위, 1 보다 작으면 1, 기본 240)Panel height. (UI layer units, 1 if less than 1, default 240)
짝Counterpart: vanilla-engine UIWindow.set_panel_height
판의 세로 반환.
Returns the panel's height.
반환Returnsnumber setPanelHeight 로 정한 판의 세로. (UI 층 단위)Panel height set with setPanelHeight. (UI layer units)
짝Counterpart: vanilla-engine UIWindow.get_panel_height
마지막으로 받은 영역의 너비. (UI 층 단위)
Width of the last received area. (UI layer units)
반환Returnsnumber 영역의 너비. (UI 층 단위, 받기 전이면 1)Area width. (UI layer units, 1 before it is received)
짝Counterpart: vanilla-engine UIWindow.get_view_width
마지막으로 받은 영역의 높이. (UI 층 단위, 내용이 세로를 채우는 창이 쓴다)
Height of the last received area. (UI layer units, used by windows whose content fills the height)
반환Returnsnumber 영역의 높이. (UI 층 단위, 받기 전이면 1)Area height. (UI layer units, 1 before it is received)
짝Counterpart: vanilla-engine UIWindow.get_view_height
영역 밖으로 더 덮는 너비 반환. { top, right, bottom, left }
Returns the extra width covered outside the area. { top, right, bottom, left }
반환Returnsobject 덮는 너비. ({ top, right, bottom, left }, UI 층 단위, 복사하지 않은 원본)Extra cover widths. ({ top, right, bottom, left }, UI layer units, the original, not a copy)
짝Counterpart: vanilla-engine UIWindow.get_view_bleed
마지막으로 놓은 판의 자리. (창 좌표, 움직임 전, 줄인 배율을 곱한 크기)
Rect of the last placed panel. (window coordinates, before motion, size multiplied by the shrink scale)
반환ReturnsRect 판의 자리. (창 좌표)Panel position. (window coordinates)
짝Counterpart: vanilla-engine UIWindow.get_panel_rect
판이 영역보다 커서 줄인 배율. (1 이하)
Scale by which the panel was shrunk because it was larger than the area. (1 or less)
반환Returnsnumber 줄인 배율. (0 초과 1 이하)Shrink scale. (greater than 0, at most 1)
짝Counterpart: vanilla-engine UIWindow.get_panel_scale
띄운 창 층 반환. (띄우기 전이나 내려간 뒤면 null)
Returns the window layer it is opened in. (null before opening or after removal)
반환Returns* 띄운 UIWindowLayer. (없으면 null)The UIWindowLayer showing it. (null if none)
띄운 창 층 설정. (창 층이 부른다)
Sets the window layer it is opened in. (called by the window layer)
- windowLayer*
- 띄운 UIWindowLayer. (내려가면 null)The UIWindowLayer showing it. (null when taken down)
닫기. (창 층에서 내린다. 닫는 움직임이 끝나면 떼어 낸다, 띄우지 않았으면 아무 일도 없다)
Closes. (removes it from the window layer, detaches it when the close motion finishes, does nothing if not opened)
창 층에서 내려감. (창 층이 부른다, 파생 클래스가 덮어쓰면 super 를 부른다)
Removed from the window layer. (called by the window layer, derived classes that override this call super)
짝Counterpart: vanilla-engine UIWindow.handle_closed
영역 밖으로 더 덮는 너비 알리기. (세이프에어리어, UI 층 단위, 어둠이 그 밑까지 덮는다)
Notifies the extra width covered outside the area. (safe area, UI layer units, the dim covers underneath it too)
- topnumber
- 위로 더 덮는 너비. (UI 층 단위, 음수면 0)Extra width to cover above. (UI layer units, 0 if negative)
- rightnumber
- 오른쪽으로 더 덮는 너비. (UI 층 단위, 음수면 0)Extra width to cover on the right. (UI layer units, 0 if negative)
- bottomnumber
- 아래로 더 덮는 너비. (UI 층 단위, 음수면 0)Extra width to cover below. (UI layer units, 0 if negative)
- leftnumber
- 왼쪽으로 더 덮는 너비. (UI 층 단위, 음수면 0)Extra width to cover on the left. (UI layer units, 0 if negative)
짝Counterpart: vanilla-engine UIWindow.set_view_bleed
어둠 놓기. (영역과 그 밖의 세이프에어리어까지)
Places the dim. (the area and the safe area beyond it)
영역의 크기 알리기. (어둠을 덮고, 판의 가로를 정해 내용을 놓은 뒤 가운데에 둔다)
Notifies the area size. (covers it with the dim, sets the panel width, lays out the content, then centers it)
- viewWidthnumber
- UI 층 단위.UI layer units.
- viewHeightnumber
- 영역의 높이. (UI 층 단위, 1 보다 작으면 1)Area height. (UI layer units, 1 if less than 1)
짝Counterpart: vanilla-engine UIWindow.set_view_size
다시 놓기. (내용이 바뀌어 판의 세로가 달라질 때, 마지막 영역의 크기로)
Lays out again. (when the content changes and the panel height differs, with the last area size)
짝Counterpart: vanilla-engine UIWindow.refresh_layout
내용 놓기. (파생 클래스가 덮어써 판 안에 내용을 놓고 판의 세로를 돌려준다)
Lays out the content. (derived classes override this to place content inside the panel and return the panel's height)
- panelWidthnumber
- 판의 너비. (UI 층 단위, 영역 너비에서 여백을 뺀 값과 가로 한계 가운데 작은 것)Panel width. (UI layer units, the smaller of the area width minus margins and the width limit)
반환Returnsnumber 판의 세로. (UI 층 단위, 기본은 getPanelHeight)Panel height. (UI layer units, getPanelHeight by default)
판 놓기. (판의 크기를 정한다, 꾸밈을 단 파생 클래스가 덮어써 super 를 부른 뒤 꾸밈을 놓는다)
Lays out the panel. (sets the panel size, derived classes with decorations override this, call super, then place the decorations)
- panelWidthnumber
- 판의 너비. (UI 층 단위, 줄이기 전)Panel width. (UI layer units, before shrinking)
- panelHeightnumber
- 판의 세로. (UI 층 단위, 줄이기 전)Panel height. (UI layer units, before shrinking)
움직임을 틀과 어둠에 걸기. (틀 배율 = 줄인 배율 x 움직임 배율, 어둠 진하기 = 움직임 비율, 파생 클래스가 덮어써 모양을 바꾼다)
Applies the motion to the frame and the dim. (frame scale = shrink scale x motion scale, dim strength = motion ratio, derived classes override this to change the look)
여는 움직임 시작. (창 층이 띄울 때 부른다)
Starts the open motion. (called by the window layer when opening)
짝Counterpart: vanilla-engine UIWindow.start_open_motion
닫는 움직임 시작. (창 층이 내릴 때 부른다, 그동안은 누름을 받지 않는다)
Starts the close motion. (called by the window layer when removing, it does not receive presses in the meantime)
짝Counterpart: vanilla-engine UIWindow.start_close_motion
닫는 움직임이 끝났는지. (창 층이 떼어 낼 때를 본다)
Whether the close motion has finished. (the window layer checks when to detach)
반환Returnsboolean 움직임이 닫힘 상태면 참.True if the motion is in the closed state.
짝Counterpart: vanilla-engine UIWindow.is_close_motion_finished
매 프레임. (자식 다음에 움직임)
Every frame. (motion after children)
- timeDeltanumber
- 지난 프레임부터의 시간. (초)Time since the last frame. (Seconds)
다른 창에 덮였는지 알리기. (맨 위의 창만 보인다, 기본은 덮이면 숨고 드러나면 다시 보인다)
- DOM 입력처럼 캔버스 밖에 붙인 것이 있으면 파생 클래스가 덮어써 함께 치운다.
Notifies whether it is covered by another window. (only the top window is visible, by default it hides when covered and shows again when uncovered)
- If something is attached outside the canvas, such as DOM input, derived classes override this to put it away as well.
- isCoveredboolean
- 참이면 다른 창에 덮였다.If true, it is covered by another window.
짝Counterpart: vanilla-engine UIWindow.set_covered
마우스 휠. (맨 위의 창이면 창 층이 먼저 준다, 받았으면 true, 파생 클래스가 덮어쓴다)
Mouse wheel. (if it is the top window the window layer gives it first, true if handled, overridden by derived classes)
- viewInputPositionVector2
- 입력 위치. (뷰 좌표)Input position. (view coordinates)
- wheelDeltaVector2
- 휠 누적값.Accumulated wheel delta.
반환Returnsboolean 받았으면 참. (기본은 늘 거짓)True if handled. (always false by default)
짝Counterpart: vanilla-engine UIWindow.handle_wheel
떼어 낼 때. (DOM 입력처럼 엔진 밖에 붙인 것을 정리한다, 파생 클래스가 덮어쓴다)
On detach. (cleans up things attached outside the engine such as DOM input, overridden by derived classes)
짝Counterpart: vanilla-engine UIWindow.dispose