2023-12-31 23:30:37 +00:00
|
|
|
import BattleScene, { Button, bypassLogin } from "../battle-scene";
|
2023-11-12 05:31:40 +00:00
|
|
|
import { TextStyle, addTextObject } from "./text";
|
|
|
|
import { Mode } from "./ui";
|
|
|
|
import * as Utils from "../utils";
|
2024-04-01 02:14:35 +01:00
|
|
|
import { addWindow } from "./ui-theme";
|
2023-12-26 19:49:23 +00:00
|
|
|
import MessageUiHandler from "./message-ui-handler";
|
|
|
|
import { GameDataType } from "../system/game-data";
|
2024-04-13 23:59:58 +01:00
|
|
|
import { OptionSelectConfig, OptionSelectItem } from "./abstact-option-select-ui-handler";
|
2024-02-14 15:44:55 +00:00
|
|
|
import { Tutorial, handleTutorial } from "../tutorial";
|
2024-02-20 01:36:10 +00:00
|
|
|
import { updateUserInfo } from "../account";
|
2023-11-12 05:31:40 +00:00
|
|
|
|
|
|
|
export enum MenuOptions {
|
2023-12-30 23:41:25 +00:00
|
|
|
GAME_SETTINGS,
|
2023-12-20 04:51:48 +00:00
|
|
|
ACHIEVEMENTS,
|
2024-01-11 17:26:32 +00:00
|
|
|
STATS,
|
2023-12-20 04:51:48 +00:00
|
|
|
VOUCHERS,
|
|
|
|
EGG_LIST,
|
2023-12-26 19:49:23 +00:00
|
|
|
EGG_GACHA,
|
2024-01-11 17:26:32 +00:00
|
|
|
MANAGE_DATA,
|
2024-02-13 16:53:09 +00:00
|
|
|
COMMUNITY,
|
2024-04-01 02:14:35 +01:00
|
|
|
RETURN_TO_TITLE,
|
2023-12-30 23:41:25 +00:00
|
|
|
LOG_OUT
|
2023-11-12 05:31:40 +00:00
|
|
|
}
|
|
|
|
|
2024-04-03 14:26:48 +01:00
|
|
|
const wikiUrl = 'https://wiki.pokerogue.net';
|
2024-02-13 16:53:09 +00:00
|
|
|
const discordUrl = 'https://discord.gg/uWpTfdKG49';
|
|
|
|
const githubUrl = 'https://github.com/Flashfyre/pokerogue';
|
|
|
|
|
2023-12-26 19:49:23 +00:00
|
|
|
export default class MenuUiHandler extends MessageUiHandler {
|
2023-11-12 05:31:40 +00:00
|
|
|
private menuContainer: Phaser.GameObjects.Container;
|
2023-12-26 19:49:23 +00:00
|
|
|
private menuMessageBoxContainer: Phaser.GameObjects.Container;
|
2023-11-12 05:31:40 +00:00
|
|
|
|
|
|
|
private menuBg: Phaser.GameObjects.NineSlice;
|
|
|
|
protected optionSelectText: Phaser.GameObjects.Text;
|
|
|
|
|
|
|
|
private cursorObj: Phaser.GameObjects.Image;
|
|
|
|
|
2023-12-31 23:30:37 +00:00
|
|
|
protected ignoredMenuOptions: MenuOptions[];
|
|
|
|
protected menuOptions: MenuOptions[];
|
|
|
|
|
2024-01-11 17:26:32 +00:00
|
|
|
protected manageDataConfig: OptionSelectConfig;
|
2024-02-13 16:53:09 +00:00
|
|
|
protected communityConfig: OptionSelectConfig;
|
2024-01-11 17:26:32 +00:00
|
|
|
|
2023-11-12 05:31:40 +00:00
|
|
|
constructor(scene: BattleScene, mode?: Mode) {
|
|
|
|
super(scene, mode);
|
2023-12-31 23:30:37 +00:00
|
|
|
|
2024-01-11 17:26:32 +00:00
|
|
|
this.ignoredMenuOptions = !bypassLogin
|
|
|
|
? [ ]
|
|
|
|
: [ MenuOptions.LOG_OUT ];
|
2024-04-01 02:14:35 +01:00
|
|
|
this.menuOptions = Utils.getEnumKeys(MenuOptions).map(m => parseInt(MenuOptions[m]) as MenuOptions).filter(m => !this.ignoredMenuOptions.includes(m));
|
2023-11-12 05:31:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setup() {
|
|
|
|
const ui = this.getUi();
|
|
|
|
|
|
|
|
this.menuContainer = this.scene.add.container(1, -(this.scene.game.canvas.height / 6) + 1);
|
|
|
|
|
|
|
|
this.menuContainer.setInteractive(new Phaser.Geom.Rectangle(0, 0, this.scene.game.canvas.width / 6, this.scene.game.canvas.height / 6), Phaser.Geom.Rectangle.Contains);
|
|
|
|
|
2023-12-26 19:49:23 +00:00
|
|
|
this.menuBg = addWindow(this.scene, (this.scene.game.canvas.width / 6) - 100, 0, 98, (this.scene.game.canvas.height / 6) - 2);
|
2023-11-12 05:31:40 +00:00
|
|
|
this.menuBg.setOrigin(0, 0);
|
|
|
|
|
|
|
|
this.menuContainer.add(this.menuBg);
|
|
|
|
|
2023-12-31 23:30:37 +00:00
|
|
|
this.optionSelectText = addTextObject(this.scene, 0, 0, this.menuOptions.map(o => Utils.toReadableString(MenuOptions[o])).join('\n'), TextStyle.WINDOW, { maxLines: this.menuOptions.length });
|
2023-11-12 05:31:40 +00:00
|
|
|
this.optionSelectText.setPositionRelative(this.menuBg, 14, 6);
|
|
|
|
this.optionSelectText.setLineSpacing(12);
|
|
|
|
this.menuContainer.add(this.optionSelectText);
|
|
|
|
|
|
|
|
ui.add(this.menuContainer);
|
|
|
|
|
2023-12-26 19:49:23 +00:00
|
|
|
this.menuMessageBoxContainer = this.scene.add.container(0, 130);
|
|
|
|
this.menuMessageBoxContainer.setVisible(false);
|
|
|
|
this.menuContainer.add(this.menuMessageBoxContainer);
|
|
|
|
|
|
|
|
const menuMessageBox = addWindow(this.scene, 0, -0, 220, 48);
|
|
|
|
menuMessageBox.setOrigin(0, 0);
|
|
|
|
this.menuMessageBoxContainer.add(menuMessageBox);
|
|
|
|
|
|
|
|
const menuMessageText = addTextObject(this.scene, 8, 8, '', TextStyle.WINDOW, { maxLines: 2 });
|
|
|
|
menuMessageText.setWordWrapWidth(1224);
|
|
|
|
menuMessageText.setOrigin(0, 0);
|
|
|
|
this.menuMessageBoxContainer.add(menuMessageText);
|
|
|
|
|
|
|
|
this.message = menuMessageText;
|
|
|
|
|
|
|
|
this.menuContainer.add(this.menuMessageBoxContainer);
|
|
|
|
|
2024-01-11 17:26:32 +00:00
|
|
|
const manageDataOptions = [];
|
|
|
|
|
2024-03-15 19:13:32 +00:00
|
|
|
const confirmSlot = (message: string, slotFilter: (i: integer) => boolean, callback: (i: integer) => void) => {
|
|
|
|
ui.revertMode();
|
|
|
|
ui.showText(message, null, () => {
|
|
|
|
const config: OptionSelectConfig = {
|
|
|
|
options: new Array(3).fill(null).map((_, i) => i).filter(slotFilter).map(i => {
|
|
|
|
return {
|
|
|
|
label: `Slot ${i + 1}`,
|
|
|
|
handler: () => {
|
|
|
|
callback(i);
|
|
|
|
ui.revertMode();
|
|
|
|
ui.showText(null, 0);
|
2024-04-13 23:59:58 +01:00
|
|
|
return true;
|
2024-03-15 19:13:32 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}).concat([{
|
|
|
|
label: 'Cancel',
|
|
|
|
handler: () => {
|
|
|
|
ui.revertMode();
|
|
|
|
ui.showText(null, 0);
|
2024-04-13 23:59:58 +01:00
|
|
|
return true;
|
2024-03-15 19:13:32 +00:00
|
|
|
}
|
|
|
|
}]),
|
|
|
|
xOffset: 98
|
|
|
|
};
|
2024-03-15 22:02:05 +00:00
|
|
|
ui.setOverlayMode(Mode.MENU_OPTION_SELECT, config);
|
2024-03-15 19:13:32 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2024-04-09 22:22:38 +01:00
|
|
|
if (Utils.isLocal) {
|
2024-04-04 04:47:27 +01:00
|
|
|
manageDataOptions.push({
|
|
|
|
label: 'Import Session',
|
2024-04-13 23:59:58 +01:00
|
|
|
handler: () => {
|
|
|
|
confirmSlot('Select a slot to import to.', () => true, slotId => this.scene.gameData.importData(GameDataType.SESSION, slotId));
|
|
|
|
return true;
|
|
|
|
},
|
2024-04-04 04:47:27 +01:00
|
|
|
keepOpen: true
|
|
|
|
});
|
|
|
|
}
|
2024-01-11 17:26:32 +00:00
|
|
|
manageDataOptions.push({
|
|
|
|
label: 'Export Session',
|
2024-03-15 19:13:32 +00:00
|
|
|
handler: () => {
|
|
|
|
const dataSlots: integer[] = [];
|
|
|
|
Promise.all(
|
|
|
|
new Array(3).fill(null).map((_, i) => {
|
|
|
|
const slotId = i;
|
|
|
|
return this.scene.gameData.getSession(slotId).then(data => {
|
|
|
|
if (data)
|
|
|
|
dataSlots.push(slotId);
|
|
|
|
})
|
|
|
|
})).then(() => {
|
|
|
|
confirmSlot('Select a slot to export from.',
|
|
|
|
i => dataSlots.indexOf(i) > -1,
|
|
|
|
slotId => this.scene.gameData.tryExportData(GameDataType.SESSION, slotId));
|
|
|
|
});
|
2024-04-13 23:59:58 +01:00
|
|
|
return true;
|
2024-03-15 19:13:32 +00:00
|
|
|
},
|
2024-01-11 17:26:32 +00:00
|
|
|
keepOpen: true
|
|
|
|
});
|
2024-04-09 22:22:38 +01:00
|
|
|
if (Utils.isLocal) {
|
2024-04-04 04:47:27 +01:00
|
|
|
manageDataOptions.push({
|
|
|
|
label: 'Import Data',
|
2024-04-13 23:59:58 +01:00
|
|
|
handler: () => {
|
|
|
|
this.scene.gameData.importData(GameDataType.SYSTEM);
|
|
|
|
return true;
|
|
|
|
},
|
2024-04-04 04:47:27 +01:00
|
|
|
keepOpen: true
|
|
|
|
});
|
|
|
|
}
|
2024-01-11 17:26:32 +00:00
|
|
|
manageDataOptions.push(
|
|
|
|
{
|
|
|
|
label: 'Export Data',
|
2024-04-13 23:59:58 +01:00
|
|
|
handler: () => {
|
|
|
|
this.scene.gameData.tryExportData(GameDataType.SYSTEM);
|
|
|
|
return true;
|
|
|
|
},
|
2024-01-11 17:26:32 +00:00
|
|
|
keepOpen: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Cancel',
|
2024-04-13 23:59:58 +01:00
|
|
|
handler: () => {
|
|
|
|
this.scene.ui.revertMode();
|
|
|
|
return true;
|
|
|
|
}
|
2024-01-11 17:26:32 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
this.manageDataConfig = {
|
|
|
|
xOffset: 98,
|
|
|
|
options: manageDataOptions
|
|
|
|
};
|
|
|
|
|
2024-04-13 23:59:58 +01:00
|
|
|
const communityOptions: OptionSelectItem[] = [
|
2024-04-03 14:26:48 +01:00
|
|
|
{
|
|
|
|
label: 'Wiki',
|
2024-04-13 23:59:58 +01:00
|
|
|
handler: () => {
|
|
|
|
window.open(wikiUrl, '_blank').focus();
|
|
|
|
return true;
|
|
|
|
},
|
2024-04-03 14:26:48 +01:00
|
|
|
keepOpen: true
|
|
|
|
},
|
2024-02-13 16:53:09 +00:00
|
|
|
{
|
|
|
|
label: 'Discord',
|
2024-04-13 23:59:58 +01:00
|
|
|
handler: () => {
|
|
|
|
window.open(discordUrl, '_blank').focus();
|
|
|
|
return true;
|
|
|
|
},
|
2024-02-13 16:53:09 +00:00
|
|
|
keepOpen: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'GitHub',
|
2024-04-13 23:59:58 +01:00
|
|
|
handler: () => {
|
|
|
|
window.open(githubUrl, '_blank').focus();
|
|
|
|
return true;
|
|
|
|
},
|
2024-02-13 16:53:09 +00:00
|
|
|
keepOpen: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Cancel',
|
2024-04-13 23:59:58 +01:00
|
|
|
handler: () => {
|
|
|
|
this.scene.ui.revertMode();
|
|
|
|
return true;
|
|
|
|
}
|
2024-02-13 16:53:09 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
this.communityConfig = {
|
|
|
|
xOffset: 98,
|
|
|
|
options: communityOptions
|
|
|
|
};
|
|
|
|
|
2023-11-12 05:31:40 +00:00
|
|
|
this.setCursor(0);
|
|
|
|
|
|
|
|
this.menuContainer.setVisible(false);
|
|
|
|
}
|
|
|
|
|
2023-12-30 23:41:25 +00:00
|
|
|
show(args: any[]): boolean {
|
2023-11-12 05:31:40 +00:00
|
|
|
super.show(args);
|
|
|
|
|
|
|
|
this.menuContainer.setVisible(true);
|
|
|
|
this.setCursor(0);
|
|
|
|
|
|
|
|
this.getUi().moveTo(this.menuContainer, this.getUi().length - 1);
|
|
|
|
|
|
|
|
this.getUi().hideTooltip();
|
|
|
|
|
|
|
|
this.scene.playSound('menu_open');
|
2023-12-30 23:41:25 +00:00
|
|
|
|
2024-02-14 15:44:55 +00:00
|
|
|
handleTutorial(this.scene, Tutorial.Menu);
|
|
|
|
|
2023-12-30 23:41:25 +00:00
|
|
|
return true;
|
2023-11-12 05:31:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
processInput(button: Button): boolean {
|
|
|
|
const ui = this.getUi();
|
|
|
|
|
|
|
|
let success = false;
|
2023-12-20 04:51:48 +00:00
|
|
|
let error = false;
|
2023-11-12 05:31:40 +00:00
|
|
|
|
|
|
|
if (button === Button.ACTION) {
|
2023-12-31 23:30:37 +00:00
|
|
|
let adjustedCursor = this.cursor;
|
|
|
|
for (let imo of this.ignoredMenuOptions) {
|
|
|
|
if (adjustedCursor >= imo)
|
|
|
|
adjustedCursor++;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (adjustedCursor) {
|
2023-12-30 23:41:25 +00:00
|
|
|
case MenuOptions.GAME_SETTINGS:
|
2024-01-11 17:26:32 +00:00
|
|
|
ui.setOverlayMode(Mode.SETTINGS);
|
2023-11-12 05:31:40 +00:00
|
|
|
success = true;
|
|
|
|
break;
|
|
|
|
case MenuOptions.ACHIEVEMENTS:
|
2024-01-11 17:26:32 +00:00
|
|
|
ui.setOverlayMode(Mode.ACHIEVEMENTS);
|
|
|
|
success = true;
|
|
|
|
break;
|
|
|
|
case MenuOptions.STATS:
|
|
|
|
ui.setOverlayMode(Mode.GAME_STATS);
|
2023-11-12 05:31:40 +00:00
|
|
|
success = true;
|
|
|
|
break;
|
2023-12-20 04:51:48 +00:00
|
|
|
case MenuOptions.VOUCHERS:
|
2024-01-11 17:26:32 +00:00
|
|
|
ui.setOverlayMode(Mode.VOUCHERS);
|
2023-12-20 04:51:48 +00:00
|
|
|
success = true;
|
|
|
|
break;
|
|
|
|
case MenuOptions.EGG_LIST:
|
|
|
|
if (this.scene.gameData.eggs.length) {
|
2024-01-11 17:26:32 +00:00
|
|
|
ui.revertMode();
|
|
|
|
ui.setOverlayMode(Mode.EGG_LIST);
|
2023-12-20 04:51:48 +00:00
|
|
|
success = true;
|
|
|
|
} else
|
|
|
|
error = true;
|
|
|
|
break;
|
|
|
|
case MenuOptions.EGG_GACHA:
|
2024-01-11 17:26:32 +00:00
|
|
|
ui.revertMode();
|
|
|
|
ui.setOverlayMode(Mode.EGG_GACHA);
|
2023-12-26 19:49:23 +00:00
|
|
|
success = true;
|
|
|
|
break;
|
2024-01-11 17:26:32 +00:00
|
|
|
case MenuOptions.MANAGE_DATA:
|
2024-03-15 22:02:05 +00:00
|
|
|
ui.setOverlayMode(Mode.MENU_OPTION_SELECT, this.manageDataConfig);
|
2023-12-26 19:49:23 +00:00
|
|
|
success = true;
|
|
|
|
break;
|
2024-02-13 16:53:09 +00:00
|
|
|
case MenuOptions.COMMUNITY:
|
2024-03-15 22:02:05 +00:00
|
|
|
ui.setOverlayMode(Mode.MENU_OPTION_SELECT, this.communityConfig);
|
2024-02-13 16:53:09 +00:00
|
|
|
success = true;
|
|
|
|
break;
|
2024-04-01 02:14:35 +01:00
|
|
|
case MenuOptions.RETURN_TO_TITLE:
|
|
|
|
if (this.scene.currentBattle) {
|
|
|
|
success = true;
|
|
|
|
ui.showText('You will lose any progress since the beginning of the battle. Proceed?', null, () => {
|
|
|
|
ui.setOverlayMode(Mode.CONFIRM, () => this.scene.reset(true), () => {
|
|
|
|
ui.revertMode();
|
|
|
|
ui.showText(null, 0);
|
|
|
|
}, false, -98);
|
|
|
|
});
|
|
|
|
} else
|
|
|
|
error = true;
|
|
|
|
break;
|
2023-12-30 23:41:25 +00:00
|
|
|
case MenuOptions.LOG_OUT:
|
|
|
|
success = true;
|
|
|
|
const doLogout = () => {
|
|
|
|
Utils.apiPost('account/logout').then(res => {
|
|
|
|
if (!res.ok)
|
|
|
|
console.error(`Log out failed (${res.status}: ${res.statusText})`);
|
|
|
|
Utils.setCookie(Utils.sessionIdKey, '');
|
2024-04-09 23:48:34 +01:00
|
|
|
updateUserInfo().then(() => this.scene.reset(true, true));
|
2023-12-30 23:41:25 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
if (this.scene.currentBattle) {
|
2024-01-11 17:26:32 +00:00
|
|
|
ui.showText('You will lose any progress since the beginning of the battle. Proceed?', null, () => {
|
|
|
|
ui.setOverlayMode(Mode.CONFIRM, doLogout, () => {
|
|
|
|
ui.revertMode();
|
|
|
|
ui.showText(null, 0);
|
2024-02-07 04:11:00 +00:00
|
|
|
}, false, -98);
|
2023-12-30 23:41:25 +00:00
|
|
|
});
|
|
|
|
} else
|
|
|
|
doLogout();
|
|
|
|
break;
|
2023-11-12 05:31:40 +00:00
|
|
|
}
|
|
|
|
} else if (button === Button.CANCEL) {
|
|
|
|
success = true;
|
2024-03-23 21:47:15 +00:00
|
|
|
ui.revertMode().then(result => {
|
|
|
|
if (!result)
|
|
|
|
ui.setMode(Mode.MESSAGE);
|
|
|
|
});
|
2023-11-12 05:31:40 +00:00
|
|
|
} else {
|
|
|
|
switch (button) {
|
|
|
|
case Button.UP:
|
|
|
|
if (this.cursor)
|
|
|
|
success = this.setCursor(this.cursor - 1);
|
|
|
|
break;
|
|
|
|
case Button.DOWN:
|
2023-12-31 23:30:37 +00:00
|
|
|
if (this.cursor + 1 < this.menuOptions.length)
|
2023-11-12 05:31:40 +00:00
|
|
|
success = this.setCursor(this.cursor + 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
ui.playSelect();
|
2023-12-20 04:51:48 +00:00
|
|
|
else if (error)
|
|
|
|
ui.playError();
|
2023-11-12 05:31:40 +00:00
|
|
|
|
2023-12-30 23:41:25 +00:00
|
|
|
return success || error;
|
2023-11-12 05:31:40 +00:00
|
|
|
}
|
|
|
|
|
2023-12-26 19:49:23 +00:00
|
|
|
showText(text: string, delay?: number, callback?: Function, callbackDelay?: number, prompt?: boolean, promptDelay?: number): void {
|
|
|
|
this.menuMessageBoxContainer.setVisible(!!text);
|
|
|
|
|
|
|
|
super.showText(text, delay, callback, callbackDelay, prompt, promptDelay);
|
|
|
|
}
|
|
|
|
|
2023-11-12 05:31:40 +00:00
|
|
|
setCursor(cursor: integer): boolean {
|
|
|
|
const ret = super.setCursor(cursor);
|
|
|
|
|
|
|
|
if (!this.cursorObj) {
|
|
|
|
this.cursorObj = this.scene.add.image(0, 0, 'cursor');
|
|
|
|
this.cursorObj.setOrigin(0, 0);
|
|
|
|
this.menuContainer.add(this.cursorObj);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.cursorObj.setPositionRelative(this.menuBg, 7, 9 + this.cursor * 16);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
clear() {
|
|
|
|
super.clear();
|
|
|
|
this.menuContainer.setVisible(false);
|
|
|
|
this.eraseCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
eraseCursor() {
|
|
|
|
if (this.cursorObj)
|
|
|
|
this.cursorObj.destroy();
|
|
|
|
this.cursorObj = null;
|
|
|
|
}
|
|
|
|
}
|