增加游戏玩法界面和各个弹窗初版
This commit is contained in:
1 parent
e84e14783e
commit
eb48d8e845
211 files changed
+59920
-21
No files matched your search
@@ -0,0 +1,567 @@
|
||||
import { BlockInputEvents, Button, Label, Node, Sprite, SpriteFrame, UITransform } from 'cc';
|
||||
import type { GameSession, GameState } from './GameSession';
|
||||
import { SYMBOL_ART } from './OrchardAssets';
|
||||
import { PAYLINES, PAYTABLE } from './SlotsMath';
|
||||
import type { OrdinarySymbol } from './SlotsMath';
|
||||
import { director } from 'cc';
|
||||
|
||||
/**
|
||||
* Coordinates are screen centres in the 1080 x 1920 reference layout (origin: top left).
|
||||
* Every group stays at the Canvas origin; the composer converts leaf coordinates.
|
||||
* Gold labels use the composer's bitmap font; all other labels use Arial.
|
||||
*/
|
||||
export interface DialogComposer {
|
||||
group(name: string, parent?: Node): Node;
|
||||
image(name: string, key: string, x: number, y: number, w: number, h: number, parent?: Node): Node;
|
||||
text(name: string, value: string, x: number, y: number, w: number, h: number, size: number, parent?: Node, gold?: boolean): Node;
|
||||
button(name: string, key: string, x: number, y: number, w: number, h: number, parent?: Node): Node;
|
||||
shade(name: string, parent: Node): Node;
|
||||
}
|
||||
|
||||
export type DialogKind = 'repeat' | 'preferences' | 'gift' | 'empty' | 'award' | 'summary' | 'guide';
|
||||
type PreferenceKey = keyof GameState['settings'];
|
||||
type VisibleDialog = DialogKind | 'error';
|
||||
|
||||
const GROUP_NAMES: Record<VisibleDialog, string> = {
|
||||
repeat: 'RepeatDialog',
|
||||
preferences: 'PreferencesDialog',
|
||||
gift: 'GiftDialog',
|
||||
empty: 'EmptyWalletDialog',
|
||||
award: 'BonusAwardDialog',
|
||||
summary: 'BonusSummaryDialog',
|
||||
guide: 'GuideDialog',
|
||||
error: 'ErrorDialog',
|
||||
};
|
||||
|
||||
const AUTO_OPTIONS = [
|
||||
{ count: 10, key: 'ten', x: 340, y: 880 },
|
||||
{ count: 25, key: 'quarter', x: 740, y: 880 },
|
||||
{ count: 50, key: 'half', x: 340, y: 1080 },
|
||||
{ count: 100, key: 'century', x: 740, y: 1080 },
|
||||
] as const;
|
||||
|
||||
const PREFERENCES: readonly { key: PreferenceKey; name: string; art: string; y: number }[] = [
|
||||
{ key: 'music', name: 'Music', art: 'melody-row', y: 790 },
|
||||
{ key: 'sound', name: 'Sound', art: 'effects-row', y: 955 },
|
||||
{ key: 'vibration', name: 'Vibration', art: 'haptics-row', y: 1120 },
|
||||
];
|
||||
|
||||
const PAYING_SYMBOLS = Object.keys(PAYTABLE) as OrdinarySymbol[];
|
||||
const SYMBOL_NAMES: Record<OrdinarySymbol, string> = {
|
||||
seven: 'SEVEN', bell: 'BELL', bar: 'BAR', strawberry: 'STRAWBERRY',
|
||||
blueberry: 'BLUEBERRY', plum: 'PLUM', cherry: 'CHERRY', watermelon: 'WATERMELON',
|
||||
};
|
||||
const GUIDE_TITLES = ['PAYTABLE 1 / 2', 'PAYTABLE 2 / 2', 'RULES & SYMBOLS', '20 PAYLINES', 'BONUS & DAILY COINS'];
|
||||
const DAILY_COINS = 20_000;
|
||||
const FAILURE = {
|
||||
open: 'Unable to open this dialog. Please try again.',
|
||||
repeat: 'Unable to start auto spin. Please try again.',
|
||||
selection: 'Unable to update the selection. Please try again.',
|
||||
preference: 'Unable to save your preference. Please try again. Your saved data has not been reset.',
|
||||
gift: 'Unable to collect daily coins. Please try again. Your saved data has not been reset.',
|
||||
clock: 'Unable to check the daily gift time. Please try again.',
|
||||
award: 'Unable to start free spins. Please try again. Your saved progress has not been reset.',
|
||||
summary: 'Unable to close the free-spin result. Please try again. Your saved progress has not been reset.',
|
||||
guide: 'Unable to display this help page. Please try again.',
|
||||
restore: 'Unable to restore the dialog. Please try again.',
|
||||
};
|
||||
|
||||
function coins(value: number): string {
|
||||
return value.toLocaleString('en-US');
|
||||
}
|
||||
|
||||
/** Plain text buttons avoid reusing artwork that already contains an unrelated caption. */
|
||||
function labelButton(ui: DialogComposer, name: string, value: string, x: number, y: number, w: number, parent: Node): Node {
|
||||
const node = ui.text(name, value, x, y, w, 90, 36, parent);
|
||||
const button = node.getComponent(Button) ?? node.addComponent(Button);
|
||||
button.transition = Button.Transition.SCALE;
|
||||
button.zoomScale = 0.96;
|
||||
return node;
|
||||
}
|
||||
|
||||
function body(ui: DialogComposer, name: string, value: string, y: number, h: number, parent: Node): Node {
|
||||
const node = ui.text(name, value, 540, y, 820, h, 34, parent);
|
||||
const label = node.getComponent(Label);
|
||||
if (label) {
|
||||
label.horizontalAlign = Label.HorizontalAlign.LEFT;
|
||||
label.verticalAlign = Label.VerticalAlign.CENTER;
|
||||
label.lineHeight = 48;
|
||||
label.enableWrapText = true;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Authors ModalLayer/ Shade + eight independent dialog groups. No scene is saved here.
|
||||
* Button and live-label names below are the shared authoring/runtime contract.
|
||||
*/
|
||||
export function authorDialogs(ui: DialogComposer): void {
|
||||
const layer = ui.group('ModalLayer');
|
||||
const shade = ui.shade('Shade', layer);
|
||||
if (!shade.getComponent(BlockInputEvents)) shade.addComponent(BlockInputEvents);
|
||||
const groups = {} as Record<VisibleDialog, Node>;
|
||||
for (const kind of Object.keys(GROUP_NAMES) as VisibleDialog[]) {
|
||||
groups[kind] = ui.group(GROUP_NAMES[kind], layer);
|
||||
groups[kind].active = false;
|
||||
}
|
||||
|
||||
const repeat = groups.repeat;
|
||||
ui.image('RepeatShell', 'repeat-shell', 540, 960, 870, 990, repeat);
|
||||
ui.image('RepeatTitle', 'repeat-title', 540, 600, 630, 145, repeat);
|
||||
ui.image('RepeatGarnish', 'repeat-garnish', 225, 705, 150, 140, repeat);
|
||||
ui.text('RepeatHint', 'CHOOSE YOUR SPINS', 595, 735, 570, 60, 34, repeat);
|
||||
for (const option of AUTO_OPTIONS) {
|
||||
ui.button(`RepeatCount${option.count}`, `${option.key}-${option.count === 10 ? 'picked' : 'idle'}`,
|
||||
option.x, option.y, 360, 170, repeat);
|
||||
}
|
||||
ui.button('RepeatStart', 'repeat-confirm', 540, 1300, 735, 185, repeat);
|
||||
ui.button('RepeatClose', 'dismiss-orb', 900, 510, 114, 112, repeat);
|
||||
|
||||
const preferences = groups.preferences;
|
||||
ui.image('PreferencesShell', 'preferences-shell', 540, 960, 879, 1035, preferences);
|
||||
ui.image('PreferencesTitle', 'preferences-heading', 540, 568, 505, 85, preferences);
|
||||
for (const preference of PREFERENCES) {
|
||||
ui.image(`Preferences${preference.name}Row`, preference.art, 540, preference.y, 788, 155, preferences);
|
||||
ui.button(`Preferences${preference.name}Toggle`, 'toggle-lit', 795, preference.y, 216, 94, preferences);
|
||||
}
|
||||
ui.button('PreferencesGuide', 'instructions-pill', 540, 1318, 630, 133, preferences);
|
||||
ui.text('PreferencesNote', 'Preferences are saved on this device.', 540, 1430, 790, 50, 32, preferences);
|
||||
ui.button('PreferencesClose', 'dismiss-orb', 900, 510, 114, 112, preferences);
|
||||
|
||||
const gift = groups.gift;
|
||||
ui.image('GiftShell', 'gift-shell', 540, 960, 928, 1205, gift);
|
||||
ui.image('GiftTitle', 'gift-heading', 540, 465, 590, 105, gift);
|
||||
ui.image('GiftGarnish', 'gift-garnish', 540, 760, 415, 397, gift);
|
||||
ui.image('GiftAmountPlate', 'gift-amount', 540, 1030, 782, 166, gift);
|
||||
ui.text('GiftAmount', coins(DAILY_COINS), 600, 1030, 530, 120, 96, gift, true);
|
||||
ui.image('GiftDailyLabel', 'gift-daily', 540, 1180, 738, 66, gift);
|
||||
ui.button('GiftClaim', 'gift-collect', 540, 1340, 642, 196, gift);
|
||||
ui.image('GiftCollected', 'gift-collected', 540, 1340, 585, 147, gift).active = false;
|
||||
ui.text('GiftCountdown', 'Available once per UTC day.', 540, 1480, 820, 60, 32, gift);
|
||||
ui.button('GiftClose', 'dismiss-orb', 920, 405, 114, 112, gift);
|
||||
|
||||
const empty = groups.empty;
|
||||
ui.image('EmptyWalletShell', 'empty-wallet-shell', 540, 960, 862, 1113, empty);
|
||||
ui.image('EmptyWalletTitle', 'empty-wallet-heading', 540, 600, 705, 310, empty);
|
||||
ui.image('EmptyWalletNote', 'empty-wallet-note', 540, 825, 523, 108, empty);
|
||||
ui.image('EmptyWalletGarnish', 'empty-wallet-garnish', 540, 1050, 661, 365, empty);
|
||||
ui.button('EmptyWalletGift', 'empty-wallet-gift', 540, 1300, 703, 158, empty);
|
||||
ui.button('EmptyWalletLater', 'empty-wallet-later', 540, 1435, 350, 85, empty);
|
||||
ui.button('EmptyWalletClose', 'dismiss-orb', 902, 465, 108, 108, empty);
|
||||
|
||||
const award = groups.award;
|
||||
ui.image('BonusAwardShell', 'repeat-shell', 540, 960, 870, 990, award);
|
||||
ui.image('BonusAwardTitle', 'bonus-award-title', 540, 620, 824, 244, award);
|
||||
ui.image('BonusAwardCaption', 'bonus-award-caption', 540, 822, 680, 109, award);
|
||||
ui.text('BonusAwardCount', '0', 540, 985, 440, 200, 180, award, true);
|
||||
for (let index = 0; index < 3; index++) {
|
||||
ui.image(`BonusAwardScatter${index + 1}`, 'bonus-award-emblem', 350 + index * 190, 1145, 155, 153, award);
|
||||
}
|
||||
ui.button('BonusAwardStart', 'bonus-begin', 540, 1340, 640, 217, award);
|
||||
|
||||
const summary = groups.summary;
|
||||
ui.image('BonusSummaryShell', 'bonus-summary-shell', 540, 960, 1060, 945, summary);
|
||||
ui.image('BonusSummaryTitle', 'bonus-summary-title', 540, 650, 770, 250, summary);
|
||||
ui.image('BonusSummaryCaption', 'bonus-summary-caption', 540, 852, 690, 75, summary);
|
||||
ui.image('BonusSummaryGarnish', 'bonus-summary-garnish', 850, 1180, 330, 171, summary);
|
||||
ui.image('BonusSummaryAmountPlate', 'bonus-summary-amount', 540, 1018, 780, 205, summary);
|
||||
ui.text('BonusSummaryAmount', '0', 540, 1018, 680, 150, 108, summary, true);
|
||||
ui.button('BonusSummaryContinue', 'bonus-dismiss', 540, 1280, 630, 190, summary);
|
||||
|
||||
const guide = groups.guide;
|
||||
ui.image('GuideShell', 'preferences-shell', 540, 960, 980, 1550, guide);
|
||||
ui.text('GuideTitle', GUIDE_TITLES[0], 540, 310, 760, 85, 44, guide);
|
||||
ui.button('GuideClose', 'dismiss-orb', 960, 260, 90, 90, guide);
|
||||
const pages = GUIDE_TITLES.map((_, index) => ui.group(`GuidePage${index}`, guide));
|
||||
for (let page = 0; page < 2; page++) {
|
||||
const parent = pages[page];
|
||||
ui.text(`GuidePaytableHint${page}`, 'MATCHING SYMBOLS FROM THE LEFT', 540, 405, 820, 55, 32, parent);
|
||||
for (let column = 0; column < 3; column++) {
|
||||
ui.text(`GuidePaytableHeader${page}_${column}`, `${column + 3} MATCH`, 450 + column * 200, 490, 180, 55, 34, parent);
|
||||
}
|
||||
PAYING_SYMBOLS.slice(page * 4, page * 4 + 4).forEach((symbol, row) => {
|
||||
const y = 625 + row * 225;
|
||||
ui.image(`GuideSymbol_${symbol}`, SYMBOL_ART[symbol], 215, y, 145, 145, parent);
|
||||
ui.text(`GuideSymbolName_${symbol}`, SYMBOL_NAMES[symbol], 215, y + 96, 230, 48, 32, parent);
|
||||
PAYTABLE[symbol].forEach((multiplier, column) => {
|
||||
ui.text(`GuideMultiplier_${symbol}_${column + 3}`, `${multiplier}x`, 450 + column * 200, y, 180, 80, 36, parent);
|
||||
});
|
||||
});
|
||||
ui.text(`GuideLineBetCaption${page}`, 'LINE BET', 300, 1450, 280, 65, 34, parent);
|
||||
ui.text(`GuideLineBet${page}`, '0', 685, 1450, 450, 70, 52, parent, true);
|
||||
ui.text(`GuidePaytableNote${page}`, `Award = multiplier x line bet. All ${PAYLINES.length} lines play.`, 540, 1535, 850, 65, 32, parent);
|
||||
}
|
||||
|
||||
ui.image('GuideWildSymbol', SYMBOL_ART.wild, 330, 510, 150, 150, pages[2]);
|
||||
ui.image('GuideScatterSymbol', SYMBOL_ART.scatter, 750, 510, 150, 150, pages[2]);
|
||||
ui.text('GuideWildCaption', 'WILD', 330, 615, 300, 55, 36, pages[2]);
|
||||
ui.text('GuideScatterCaption', 'SCATTER', 750, 615, 300, 55, 36, pages[2]);
|
||||
body(ui, 'GuideRules', [
|
||||
`${PAYLINES.length} active lines. 5 reels, 3 rows.`,
|
||||
'',
|
||||
'Matching symbols pay from left to right.',
|
||||
'Start on reel 1. Match 3, 4 or 5 symbols.',
|
||||
'Only the best award pays on each line.',
|
||||
'Wins on different lines are added.',
|
||||
'',
|
||||
'WILD replaces regular symbols.',
|
||||
'It does not replace SCATTER.',
|
||||
'',
|
||||
'SCATTER counts anywhere on the reels.',
|
||||
'3 / 4 / 5+ award 8 / 12 / 16 free spins.',
|
||||
'SCATTER has no separate coin payout.',
|
||||
].join('\n'), 1080, 800, pages[2]);
|
||||
|
||||
ui.text('GuideLineLegend', 'T = TOP M = MIDDLE B = BOTTOM', 540, 435, 850, 70, 32, pages[3]);
|
||||
const linesPerColumn = Math.ceil(PAYLINES.length / 2);
|
||||
PAYLINES.forEach((line, index) => {
|
||||
const parent = ui.group(`GuidePayline${index + 1}`, pages[3]);
|
||||
const x = 170 + Math.floor(index / linesPerColumn) * 420;
|
||||
const y = 570 + index % linesPerColumn * 80;
|
||||
ui.text(`GuidePaylineNumber${index + 1}`, String(index + 1).padStart(2, '0'), x, y, 65, 65, 36, parent);
|
||||
// Individual fixed-width Arial cells preserve alignment without changing the font contract.
|
||||
line.forEach((row, reel) => {
|
||||
ui.text(`GuidePayline${index + 1}Reel${reel + 1}`, ['T', 'M', 'B'][row],
|
||||
x + 85 + reel * 50, y, 45, 65, 36, parent);
|
||||
});
|
||||
});
|
||||
ui.text('GuideLineDirection', 'Read each sequence from reel 1 to reel 5.', 540, 1470, 850, 100, 32, pages[3]);
|
||||
|
||||
ui.text('GuideFreeTitle', 'FREE SPINS', 540, 465, 820, 65, 36, pages[4]);
|
||||
body(ui, 'GuideFreeRules', [
|
||||
'3 / 4 / 5+ SCATTERs award 8 / 12 / 16.',
|
||||
'Free spins keep the triggering bet.',
|
||||
'Each spin makes one whole reel WILD;',
|
||||
'SCATTERs stay unchanged.',
|
||||
'Free spins do not retrigger.',
|
||||
].join('\n'), 665, 290, pages[4]);
|
||||
ui.text('GuideAutoTitle', 'AUTO SPIN', 540, 900, 820, 65, 36, pages[4]);
|
||||
body(ui, 'GuideAutoRules', [
|
||||
`Choose ${AUTO_OPTIONS.map(option => option.count).join(' / ')} spins.`,
|
||||
'Only paid spins use this counter.',
|
||||
'Opening a dialog stops auto spin.',
|
||||
'Insufficient coins or a bonus stops it.',
|
||||
].join('\n'), 1075, 240, pages[4]);
|
||||
ui.text('GuideDailyTitle', 'DAILY COINS', 540, 1270, 820, 65, 36, pages[4]);
|
||||
ui.text('GuideDailyAmount', coins(DAILY_COINS), 540, 1360, 600, 80, 60, pages[4], true);
|
||||
body(ui, 'GuideDailyRules', 'Coins, once per UTC day.\nResets at 00:00 UTC.\nSaved locally for this guest account.', 1470, 160, pages[4]);
|
||||
pages.forEach((page, index) => { page.active = index === 0; });
|
||||
labelButton(ui, 'GuidePrevious', 'PREVIOUS', 260, 1640, 300, guide);
|
||||
ui.text('GuidePageNumber', '1 / 5', 540, 1640, 180, 70, 34, guide);
|
||||
labelButton(ui, 'GuideNext', 'NEXT', 820, 1640, 300, guide);
|
||||
|
||||
const error = groups.error;
|
||||
ui.image('ErrorShell', 'repeat-shell', 540, 960, 870, 990, error);
|
||||
ui.text('ErrorTitle', 'PLEASE TRY AGAIN', 540, 665, 740, 90, 44, error);
|
||||
const message = body(ui, 'ErrorMessage', 'Unable to complete the action. Please try again.', 965, 390, error);
|
||||
const messageLabel = message.getComponent(Label);
|
||||
if (messageLabel) messageLabel.horizontalAlign = Label.HorizontalAlign.CENTER;
|
||||
labelButton(ui, 'ErrorAcknowledge', 'OK', 540, 1300, 600, error);
|
||||
layer.active = false;
|
||||
}
|
||||
|
||||
function findNode(root: Node, name: string): Node | null {
|
||||
if (root.name === name) return root;
|
||||
for (const child of root.children) {
|
||||
const found = findNode(child, name);
|
||||
if (found) return found;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Owns only modal presentation; closing a dialog never resets the game phase. */
|
||||
export class OrchardDialogs {
|
||||
private readonly layer: Node;
|
||||
private readonly groups: Record<VisibleDialog, Node>;
|
||||
private readonly nodes = new Map<string, Node>();
|
||||
private readonly listeners: { node: Node; callback: () => void }[] = [];
|
||||
private visible: VisibleDialog | null = null;
|
||||
private errorReturn: DialogKind | null = null;
|
||||
private guideReturn: 'preferences' | null = null;
|
||||
private selectedCount: number = AUTO_OPTIONS[0].count;
|
||||
private guidePage = 0;
|
||||
private working = false;
|
||||
private persistenceFailed = false;
|
||||
private disposed = false;
|
||||
|
||||
/** root may be the Canvas, its scene ancestor, or ModalLayer itself. */
|
||||
constructor(
|
||||
root: Node,
|
||||
private readonly session: GameSession,
|
||||
private readonly art: (key: string) => SpriteFrame,
|
||||
private readonly onAuto: (count: number) => void,
|
||||
private readonly onResume: () => void,
|
||||
private readonly onChange: () => void,
|
||||
) {
|
||||
const layer = findNode(root, 'ModalLayer');
|
||||
if (!layer) throw new Error('Missing ModalLayer. Run authorDialogs before binding OrchardDialogs.');
|
||||
this.layer = layer;
|
||||
this.groups = {} as Record<VisibleDialog, Node>;
|
||||
for (const kind of Object.keys(GROUP_NAMES) as VisibleDialog[]) {
|
||||
this.groups[kind] = this.required(GROUP_NAMES[kind]);
|
||||
}
|
||||
const shade = this.required('Shade');
|
||||
if (!shade.getComponent(BlockInputEvents)) shade.addComponent(BlockInputEvents);
|
||||
shade.active = true;
|
||||
this.bindControls();
|
||||
this.close();
|
||||
}
|
||||
|
||||
get opened(): boolean {
|
||||
return !this.disposed && this.layer.isValid && this.layer.active;
|
||||
}
|
||||
|
||||
show(kind: DialogKind): void {
|
||||
if (this.disposed) return;
|
||||
try {
|
||||
if (kind === 'guide' && this.visible !== 'guide' && this.visible !== 'error') {
|
||||
this.guideReturn = this.visible === 'preferences' ? 'preferences' : null;
|
||||
this.guidePage = 0;
|
||||
}
|
||||
this.refresh(kind);
|
||||
this.activate(kind);
|
||||
} catch {
|
||||
this.error(FAILURE.open);
|
||||
}
|
||||
}
|
||||
|
||||
close(): void {
|
||||
if (this.disposed) return;
|
||||
for (const group of Object.values(this.groups)) group.active = false;
|
||||
this.layer.active = false;
|
||||
this.visible = null;
|
||||
this.errorReturn = null;
|
||||
this.guideReturn = null;
|
||||
}
|
||||
|
||||
/** Call from the view update loop; the session supplies the UTC clock. */
|
||||
tick(): void {
|
||||
if (!this.opened || this.visible !== 'gift') return;
|
||||
try {
|
||||
this.refreshGift();
|
||||
} catch {
|
||||
this.error(FAILURE.clock);
|
||||
}
|
||||
}
|
||||
|
||||
error(message: string, reload = false): void {
|
||||
if (this.disposed) return;
|
||||
if (reload) this.persistenceFailed = true;
|
||||
if (this.visible !== 'error') this.errorReturn = this.visible;
|
||||
this.label('ErrorMessage').string = message.trim().slice(0, 300) || FAILURE.open;
|
||||
this.activate('error');
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
if (this.disposed) return;
|
||||
for (const listener of this.listeners) {
|
||||
if (listener.node.isValid) listener.node.off(Button.EventType.CLICK, listener.callback, this);
|
||||
}
|
||||
this.listeners.length = 0;
|
||||
if (this.layer.isValid) this.close();
|
||||
this.nodes.clear();
|
||||
this.disposed = true;
|
||||
}
|
||||
|
||||
private bindControls(): void {
|
||||
for (const name of ['RepeatClose', 'PreferencesClose', 'GiftClose', 'EmptyWalletClose', 'EmptyWalletLater']) {
|
||||
this.bind(name, () => this.close(), FAILURE.open);
|
||||
}
|
||||
for (const option of AUTO_OPTIONS) {
|
||||
this.bind(`RepeatCount${option.count}`, () => {
|
||||
this.selectedCount = option.count;
|
||||
this.refreshRepeat();
|
||||
}, FAILURE.selection);
|
||||
}
|
||||
this.bind('RepeatStart', () => {
|
||||
if (this.session.state.phase !== 'idle') throw new Error('Auto spin requires the idle phase.');
|
||||
this.close();
|
||||
this.onAuto(this.selectedCount);
|
||||
}, FAILURE.repeat);
|
||||
for (const preference of PREFERENCES) {
|
||||
this.bind(`Preferences${preference.name}Toggle`, () => {
|
||||
this.session.setPreference(preference.key, !this.session.state.settings[preference.key]);
|
||||
this.refreshPreferences();
|
||||
this.onChange();
|
||||
}, FAILURE.preference);
|
||||
}
|
||||
this.bind('PreferencesGuide', () => this.show('guide'), FAILURE.guide);
|
||||
this.bind('EmptyWalletGift', () => this.show('gift'), FAILURE.gift);
|
||||
this.bind('GiftClaim', () => {
|
||||
const claimed = this.session.claimDaily();
|
||||
this.refreshGift();
|
||||
if (claimed) this.onChange();
|
||||
}, FAILURE.gift);
|
||||
// These are the only controls on the two mandatory free-spin dialogs.
|
||||
this.bind('BonusAwardStart', () => {
|
||||
this.session.startFree();
|
||||
this.close();
|
||||
this.onResume();
|
||||
}, FAILURE.award);
|
||||
this.bind('BonusSummaryContinue', () => {
|
||||
this.session.closeFreeResult();
|
||||
this.close();
|
||||
this.onChange();
|
||||
}, FAILURE.summary);
|
||||
this.bind('GuidePrevious', () => this.turnGuide(-1), FAILURE.guide);
|
||||
this.bind('GuideNext', () => this.turnGuide(1), FAILURE.guide);
|
||||
this.bind('GuideClose', () => {
|
||||
if (this.guideReturn === 'preferences') this.show('preferences');
|
||||
else this.close();
|
||||
}, FAILURE.guide);
|
||||
this.bind('ErrorAcknowledge', () => {
|
||||
if (this.persistenceFailed) {
|
||||
// 旧会话不能盲目重放不确定提交,重新登录后从已保存阶段恢复。 / Reload the committed snapshot instead of replaying an uncertain mutation.
|
||||
director.loadScene('Welcome');
|
||||
return;
|
||||
}
|
||||
const next = this.recoverKind(this.errorReturn);
|
||||
if (next === null) this.close();
|
||||
else this.show(next);
|
||||
}, FAILURE.restore);
|
||||
}
|
||||
|
||||
private bind(name: string, action: () => void, failure: string): void {
|
||||
const node = this.required(name);
|
||||
const button = node.getComponent(Button);
|
||||
if (!button) throw new Error(`Missing dialog Button: ${name}`);
|
||||
const callback = (): void => {
|
||||
if (this.disposed || this.working || !this.opened || !node.activeInHierarchy || !button.interactable) return;
|
||||
const previous = this.visible;
|
||||
this.working = true;
|
||||
try {
|
||||
action();
|
||||
} catch {
|
||||
if ([FAILURE.preference, FAILURE.gift, FAILURE.award, FAILURE.summary].includes(failure)) {
|
||||
this.persistenceFailed = true;
|
||||
this.error('Unable to confirm the saved change. Tap OK to return to login and safely restore your saved progress.');
|
||||
return;
|
||||
}
|
||||
this.error(failure);
|
||||
if (previous !== 'error') this.errorReturn = previous;
|
||||
} finally {
|
||||
this.working = false;
|
||||
}
|
||||
};
|
||||
node.on(Button.EventType.CLICK, callback, this);
|
||||
this.listeners.push({ node, callback });
|
||||
}
|
||||
|
||||
private activate(kind: VisibleDialog): void {
|
||||
for (const key of Object.keys(this.groups) as VisibleDialog[]) this.groups[key].active = key === kind;
|
||||
this.visible = kind;
|
||||
this.layer.active = true;
|
||||
}
|
||||
|
||||
private refresh(kind: DialogKind): void {
|
||||
switch (kind) {
|
||||
case 'repeat': this.refreshRepeat(); break;
|
||||
case 'preferences': this.refreshPreferences(); break;
|
||||
case 'gift': this.refreshGift(); break;
|
||||
case 'award': {
|
||||
const state = this.session.state;
|
||||
if (state.phase !== 'free-trigger' || state.free === null) throw new Error('No free-spin award is pending.');
|
||||
this.label('BonusAwardCount').string = String(state.free.awarded);
|
||||
break;
|
||||
}
|
||||
case 'summary': {
|
||||
const state = this.session.state;
|
||||
if (state.phase !== 'free-result' || state.free === null) throw new Error('No free-spin result is pending.');
|
||||
this.label('BonusSummaryAmount').string = coins(state.free.total);
|
||||
break;
|
||||
}
|
||||
case 'guide': this.refreshGuide(); break;
|
||||
case 'empty': break;
|
||||
}
|
||||
}
|
||||
|
||||
private refreshRepeat(): void {
|
||||
for (const option of AUTO_OPTIONS) {
|
||||
this.setArt(`RepeatCount${option.count}`, `${option.key}-${option.count === this.selectedCount ? 'picked' : 'idle'}`);
|
||||
}
|
||||
}
|
||||
|
||||
private refreshPreferences(): void {
|
||||
const settings = this.session.state.settings;
|
||||
for (const preference of PREFERENCES) {
|
||||
this.setArt(`Preferences${preference.name}Toggle`, settings[preference.key] ? 'toggle-lit' : 'toggle-dim');
|
||||
}
|
||||
}
|
||||
|
||||
private refreshGift(): void {
|
||||
const available = this.session.canClaimDaily();
|
||||
for (const [name, key, x, y, w, h] of (available ? [
|
||||
['GiftShell', 'gift-shell', 540, 960, 928, 1205],
|
||||
['GiftTitle', 'gift-heading', 540, 465, 590, 105],
|
||||
['GiftGarnish', 'gift-garnish', 540, 760, 415, 397],
|
||||
['GiftDailyLabel', 'gift-daily', 540, 1180, 738, 66],
|
||||
] : [
|
||||
['GiftShell', 'claimed-shell', 540, 960, 925, 1150],
|
||||
['GiftTitle', 'claimed-heading', 540, 520, 755, 368],
|
||||
['GiftGarnish', 'claimed-garnish', 540, 840, 355, 252],
|
||||
['GiftDailyLabel', 'claimed-caption', 540, 1180, 764, 62],
|
||||
]) as [string, string, number, number, number, number][]) {
|
||||
this.setArt(name, key);
|
||||
this.required(name).setPosition(x - 540, 960 - y, 0);
|
||||
this.required(name).getComponent(UITransform)!.setContentSize(w, h);
|
||||
}
|
||||
this.required('GiftClaim').active = available;
|
||||
this.required('GiftCollected').active = !available;
|
||||
this.label('GiftAmount').string = coins(DAILY_COINS);
|
||||
const seconds = Math.ceil(Math.max(0, this.session.nextResetMs()) / 1000);
|
||||
const hours = Math.floor(seconds / 3600);
|
||||
const minutes = Math.floor(seconds % 3600 / 60);
|
||||
const remaining = seconds % 60;
|
||||
const time = [hours, minutes, remaining].map(value => String(value).padStart(2, '0')).join(':');
|
||||
this.label('GiftCountdown').string = `${available ? 'Resets' : 'Next gift'} in ${time} (UTC)`;
|
||||
}
|
||||
|
||||
private turnGuide(direction: number): void {
|
||||
this.guidePage = Math.max(0, Math.min(GUIDE_TITLES.length - 1, this.guidePage + direction));
|
||||
this.refreshGuide();
|
||||
}
|
||||
|
||||
private refreshGuide(): void {
|
||||
const state = this.session.state;
|
||||
const lineBet = (state.free?.bet ?? state.bet) / PAYLINES.length;
|
||||
for (let page = 0; page < GUIDE_TITLES.length; page++) {
|
||||
this.required(`GuidePage${page}`).active = page === this.guidePage;
|
||||
}
|
||||
for (let page = 0; page < 2; page++) this.label(`GuideLineBet${page}`).string = coins(lineBet);
|
||||
this.label('GuideTitle').string = this.guidePage === 3 ? `${PAYLINES.length} PAYLINES` : GUIDE_TITLES[this.guidePage];
|
||||
this.label('GuidePageNumber').string = `${this.guidePage + 1} / ${GUIDE_TITLES.length}`;
|
||||
this.component('GuidePrevious', Button).interactable = this.guidePage > 0;
|
||||
this.component('GuideNext', Button).interactable = this.guidePage < GUIDE_TITLES.length - 1;
|
||||
}
|
||||
|
||||
/** Restore pending confirmations after an error without replaying successful mutations. */
|
||||
private recoverKind(previous: DialogKind | null): DialogKind | null {
|
||||
const phase = this.session.state.phase;
|
||||
if (phase === 'free-trigger') return 'award';
|
||||
if (phase === 'free-result') return 'summary';
|
||||
return previous === 'award' || previous === 'summary' ? null : previous;
|
||||
}
|
||||
|
||||
private required(name: string): Node {
|
||||
const cached = this.nodes.get(name);
|
||||
if (cached) return cached;
|
||||
const node = findNode(this.layer, name);
|
||||
if (!node) throw new Error(`Missing authored dialog node: ${name}`);
|
||||
this.nodes.set(name, node);
|
||||
return node;
|
||||
}
|
||||
|
||||
private component<T extends Label | Sprite | Button>(name: string, type: new () => T): T {
|
||||
const component = this.required(name).getComponent(type);
|
||||
if (!component) throw new Error(`Missing dialog component on: ${name}`);
|
||||
return component;
|
||||
}
|
||||
|
||||
private label(name: string): Label {
|
||||
return this.component(name, Label);
|
||||
}
|
||||
|
||||
private setArt(name: string, key: string): void {
|
||||
this.component(name, Sprite).spriteFrame = this.art(key);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user