ui/toastmotion
알림이 나오고 사라지는 모습. (토스트 노드에 붙이는 컴포넌트, UIToast 는 줄 세운 알약 알림을 스스로 만들고 이것은 게임이 만든 알림 노드를 움직인다)
How a notification appears and disappears. (a component attached to a toast node, UIToast builds queued pill notifications itself, while this moves a notification node made by the game)
ToastMotionextends Component
알림이 나오고 사라지는 모습. (토스트 노드에 붙이는 컴포넌트, UIToast 는 줄 세운 알약 알림을 스스로 만들고 이것은 게임이 만든 알림 노드를 움직인다) 알림 노드에 붙여 show 로 띄운다. 바깥쪽(위 알림은 위, 아래 알림은 아래)에서 미끄러져 들어오며 보이고 살짝 커졌다 돌아오고, 머무는 시간이 지나면 떠오르며 사라진 뒤 노드를 끈다. 떠 있는 동안 다른 글이 오면 앞 것이 빨리 비키고 새 글이 들어오며, 같은 글이 또 오면 시간만 다시 채우고 통 튄다. 노드의 자리는 화면이 놓은 자리를 기준으로 그 둘레에서만 움직인다. (그 사이 화면이 다시 놓으면 그 자리가 새 기준)
How a notification appears and disappears. (a component attached to a toast node, UIToast builds queued pill notifications itself, while this moves a notification node made by the game) Attach it to a notification node and pop it up with show. It slides in from the outside (top notifications from above, bottom ones from below) as it becomes visible, grows slightly and settles back, and after the stay time it floats up, disappears, and turns the node off. If another text arrives while it is up, the previous one quickly gets out of the way and the new text comes in, and if the same text arrives again it only refills the time and gives a bounce. The node's position moves only around the position the screen placed it at. (if the screen places it again meanwhile, that position becomes the new reference)
import { Engine, EngineConfiguration, UIScene, UILabel, WorldNode, Paint, Color, Pivot, Vector2, attachToastMotion, readToastSeconds } from "./build/vanilla.js";
class ToastScene extends UIScene {
create() {
super.create();
const toastNode = new WorldNode();
toastNode.setPivot(Pivot.topLeft.clone());
toastNode.setAnchor(Pivot.topLeft.clone());
toastNode.setContentSize(Vector2.create(240, 40));
toastNode.setLocalPosition(Vector2.create(200, 24));
toastNode.setActive(false);
const toastPaint = toastNode.addComponent(Paint);
toastPaint.setColor(new Color(0.08, 0.1, 0.14, 0.95));
toastPaint.setRoundSize(20);
const toastLabel = toastNode.addComponent(UILabel);
const toastMotion = attachToastMotion(toastNode, -1);
const root = this.getRoot();
root.addChild(toastNode);
const text = "Game saved";
const seconds = readToastSeconds(text, 1.5);
toastMotion.show(text, seconds, () => {
toastLabel.setText(text);
});
}
}
const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
const scene = new ToastScene();
scene.setLoadingMinDurationMs(0);
engine.run(scene);들어오는 쪽 정하기. (-1 이면 위에서, 1 이면 아래에서)
Sets the entry side. (-1 from above, 1 from below)
- enterSidenumber
- 들어오는 쪽. (-1 이면 위에서, 1 이면 아래에서, 들어오는 거리 10 픽셀에 곱한다)Entering side. (-1 enters from above, 1 from below, multiplied by the 10 pixel entering distance)
짝Counterpart: vanilla-engine ToastMotion.set_enter_side
띄우기. (applyText 가 노드에 글과 색을 넣음, 떠 있는 다른 글은 빨리 비킨 뒤 띄움)
Pops it up. (applyText puts the text and color into the node, any other text showing quickly gets out of the way first)
- textstring
- 알림 글. (떠 있는 글과 같으면 머무는 초만 다시 채우고 통 튄다)Notification text. (if it is the same as the shown text, only the stay seconds are refilled and it pops)
- secondsnumber
- 머무는 초.Seconds to stay.
- applyTextfunction(): void
- 노드에 글과 색을 넣는 함수. (나오기 시작할 때 부른다)Function that puts the text and colors on the node. (called when it starts entering)
짝Counterpart: vanilla-engine ToastMotion.show
떠 있는지. (나오는 중, 머무는 중, 사라지는 중)
Whether it is up. (appearing, staying, disappearing)
반환Returnsboolean 숨음 단계가 아니면 참.True unless in the hidden phase.
짝Counterpart: vanilla-engine ToastMotion.is_showing
단계 반환. (ToastPhase)
Returns the phase. (ToastPhase)
반환Returnsstring 단계. (ToastPhase 의 값)Phase. (a ToastPhase value)
짝Counterpart: vanilla-engine ToastMotion.get_phase
곧바로 끄기. (판이 바뀔 때)
Turns it off immediately. (when the round changes)
짝Counterpart: vanilla-engine ToastMotion.hide_now
나오기 시작.
Starts appearing.
- textstring
- 알림 글.Notification text.
- secondsnumber
- 머무는 초.Seconds to stay.
- applyTextfunction(): void
- 노드에 글과 색을 넣는 함수. (곧바로 부른다)Function that puts the text and colors on the node. (called right away)
사라지기 시작.
Starts disappearing.
- exitLengthnumber
- 사라지는 초. (보통 0.25, 새 알림에 비킬 때 0.12)Seconds to exit. (normally 0.25, 0.12 when making way for a new notification)
갱신. (단계마다 자리와 크기와 불투명도)
Update. (position, size and opacity per phase)
- timeDeltanumber
- 지난 프레임부터의 시간. (초)Time since the last frame. (Seconds)
화면이 놓은 자리를 기준으로 가운데를 두고 그 크기와 위아래 비킴, 불투명도로 놓기.
Places it centered on the position the screen placed, with that size, vertical offset and opacity.
- nodeWorldNode
- 알림 노드.Notification node.
- scalenumber
- 배율. (1 이 보통 크기, 가운데를 두고 키운다)Scale. (1 is the normal size, grows around the center)
- offsetYnumber
- 기준 자리에서 세로로 비킬 거리. (픽셀, 아래가 +)Vertical offset from the base position. (pixels, down is +)
- opacitynumber
- 불투명도. (0 ~ 1)Opacity. (0 ~ 1)
함수Functions
알림 머무는 시간. (표의 시간에 긴 글이면 LONG_TEXT_CHARACTERS 자마다 LONG_TEXT_EXTRA_SECONDS 를 더하고 MAXIMUM_STAY_SECONDS 까지)
Notification stay duration. (for long text, adds LONG_TEXT_EXTRA_SECONDS to the table's time for every LONG_TEXT_CHARACTERS characters, up to MAXIMUM_STAY_SECONDS)
- textstring
- 알림 글. (글자 수는 코드 포인트로 센다)Notification text. (characters are counted as code points)
- baseSecondsnumber
- 표의 머무는 초.Base stay seconds from the table.
반환Returnsnumber 머무는 초. (20 자를 넘으면 20 자마다 0.5 초를 더하고, 4 초를 넘지 않는다)Seconds to stay. (adds 0.5 seconds for every 20 characters past 20, never more than 4 seconds)
짝Counterpart: vanilla-engine read_toast_seconds
import { readToastSeconds } from "./build/vanilla.js";
const shortSeconds = readToastSeconds("Saved", 1.5);
const longSeconds = readToastSeconds("The cloud save finished uploading just now", 1.5);
const cappedSeconds = readToastSeconds("x".repeat(200), 1.5);
console.log(shortSeconds, longSeconds, cappedSeconds);알림 노드에 나옴과 사라짐 붙이기. (ToastMotion 을 돌려줌)
Attaches appearing and disappearing to a notification node. (returns a ToastMotion)
- nodeWorldNode
- 알림 노드.Notification node.
- enterSidenumber
- -1 이면 위에서, 1 이면 아래에서 들어온다.-1 means it enters from above, 1 means from below.
반환ReturnsToastMotion 붙인 컴포넌트.The attached component.
짝Counterpart: vanilla-engine attach_toast_motion
ToastPhaseenum
알림의 단계.
Notification phases.
| 이름Name | 값Value | 설명Description |
|---|---|---|
enter | enter | 나오는 중. (미끄러져 들어오며 보이고 살짝 커졌다 돌아온다)Entering. (slides in while appearing, grows slightly and settles) |
stay | stay | 머무는 중. (머무는 초를 센다)Staying. (counts down the stay seconds) |
exit | exit | 사라지는 중. (떠오르며 투명해진다)Exiting. (rises while fading out) |