Make party UI more flexible

pull/1/head
Flashfyre 2023-04-05 22:22:03 -04:00
parent 2d819a0ea4
commit 56c776834f
3 changed files with 57 additions and 24 deletions

View File

@ -6,7 +6,7 @@ import { Mode } from './ui/ui';
import { Command } from "./ui/command-ui-handler"; import { Command } from "./ui/command-ui-handler";
import { Stat } from "./pokemon-stat"; import { Stat } from "./pokemon-stat";
import { ExpBoosterModifier, ExpShareModifier, ExtraModifierModifier, getModifierTypesForWave, ModifierType, PokemonModifierType, regenerateModifierPoolThresholds } from "./modifier"; import { ExpBoosterModifier, ExpShareModifier, ExtraModifierModifier, getModifierTypesForWave, ModifierType, PokemonModifierType, regenerateModifierPoolThresholds } from "./modifier";
import PartyUiHandler from "./ui/party-ui-handler"; import PartyUiHandler, { PartyUiMode } from "./ui/party-ui-handler";
import { doPokeballBounceAnim, getPokeballAtlasKey, getPokeballCatchMultiplier, getPokeballTintColor as getPokeballTintColor, PokeballType } from "./pokeball"; import { doPokeballBounceAnim, getPokeballAtlasKey, getPokeballCatchMultiplier, getPokeballTintColor as getPokeballTintColor, PokeballType } from "./pokeball";
import { pokemonLevelMoves } from "./pokemon-level-moves"; import { pokemonLevelMoves } from "./pokemon-level-moves";
import { MoveAnim, initAnim, loadMoveAnimAssets } from "./battle-anims"; import { MoveAnim, initAnim, loadMoveAnimAssets } from "./battle-anims";
@ -687,7 +687,7 @@ export class SwitchPhase extends BattlePhase {
start() { start() {
super.start(); super.start();
this.scene.ui.setMode(Mode.PARTY, this.isModal, (slotIndex: integer) => { this.scene.ui.setMode(Mode.PARTY, this.isModal ? PartyUiMode.SWITCH : PartyUiMode.FORCE_SWITCH, (slotIndex: integer) => {
if (slotIndex && slotIndex < 6) if (slotIndex && slotIndex < 6)
this.scene.unshiftPhase(new SwitchSummonPhase(this.scene, slotIndex, this.doReturn)); this.scene.unshiftPhase(new SwitchSummonPhase(this.scene, slotIndex, this.doReturn));
this.scene.ui.setMode(Mode.MESSAGE); this.scene.ui.setMode(Mode.MESSAGE);
@ -965,7 +965,7 @@ export class SelectModifierPhase extends BattlePhase {
const modifierType = types[cursor]; const modifierType = types[cursor];
if (modifierType instanceof PokemonModifierType) { if (modifierType instanceof PokemonModifierType) {
const pokemonModifierType = modifierType as PokemonModifierType; const pokemonModifierType = modifierType as PokemonModifierType;
this.scene.ui.setModeWithoutClear(Mode.PARTY, false, (slotIndex: integer) => { this.scene.ui.setModeWithoutClear(Mode.PARTY, PartyUiMode.MODIFIER, (slotIndex: integer) => {
if (slotIndex < 6) { if (slotIndex < 6) {
this.scene.ui.setMode(Mode.MODIFIER_SELECT); this.scene.ui.setMode(Mode.MODIFIER_SELECT);
this.scene.addModifier(types[cursor].newModifier(this.scene.getParty()[slotIndex])).then(() => super.end()); this.scene.addModifier(types[cursor].newModifier(this.scene.getParty()[slotIndex])).then(() => super.end());

View File

@ -2,6 +2,7 @@ import { CommandPhase } from "../battle-phase";
import BattleScene from "../battle-scene"; import BattleScene from "../battle-scene";
import { addTextObject, TextStyle } from "../text"; import { addTextObject, TextStyle } from "../text";
import { toPokemonUpperCase } from "../utils"; import { toPokemonUpperCase } from "../utils";
import { PartyUiMode } from "./party-ui-handler";
import UI, { Mode } from "./ui"; import UI, { Mode } from "./ui";
import UiHandler from "./uiHandler"; import UiHandler from "./uiHandler";
@ -65,7 +66,7 @@ export default class CommandUiHandler extends UiHandler {
success = true; success = true;
break; break;
case 2: case 2:
ui.setMode(Mode.PARTY); ui.setMode(Mode.PARTY, PartyUiMode.SWITCH);
success = true; success = true;
break; break;
} }

View File

@ -4,11 +4,27 @@ import { PlayerPokemon } from "../pokemon";
import { addTextObject, TextStyle } from "../text"; import { addTextObject, TextStyle } from "../text";
import { Command } from "./command-ui-handler"; import { Command } from "./command-ui-handler";
import MessageUiHandler from "./message-ui-handler"; import MessageUiHandler from "./message-ui-handler";
import UI, { Mode } from "./ui"; import { Mode } from "./ui";
const defaultMessage = 'Choose a Pokémon.'; const defaultMessage = 'Choose a Pokémon.';
export enum PartyUiMode {
SWITCH,
FORCE_SWITCH,
MODIFIER
}
export enum PartyOption {
SHIFT,
SEND_OUT,
APPLY,
SUMMARY,
CANCEL
}
export default class PartyUiHandler extends MessageUiHandler { export default class PartyUiHandler extends MessageUiHandler {
private partyUiMode: PartyUiMode;
private partyContainer: Phaser.GameObjects.Container; private partyContainer: Phaser.GameObjects.Container;
private partySlotsContainer: Phaser.GameObjects.Container; private partySlotsContainer: Phaser.GameObjects.Container;
private partySlots: PartySlot[]; private partySlots: PartySlot[];
@ -19,9 +35,9 @@ export default class PartyUiHandler extends MessageUiHandler {
private optionsCursor: integer; private optionsCursor: integer;
private optionsContainer: Phaser.GameObjects.Container; private optionsContainer: Phaser.GameObjects.Container;
private optionsCursorObj: Phaser.GameObjects.Image; private optionsCursorObj: Phaser.GameObjects.Image;
private options: integer[];
private lastCursor: integer = 0; private lastCursor: integer = 0;
private isModal: boolean;
private selectCallback: Function; private selectCallback: Function;
private selectFilter: Function; private selectFilter: Function;
@ -82,17 +98,23 @@ export default class PartyUiHandler extends MessageUiHandler {
this.optionsContainer = this.scene.add.container((this.scene.game.canvas.width / 6) - 1, -1); this.optionsContainer = this.scene.add.container((this.scene.game.canvas.width / 6) - 1, -1);
partyContainer.add(this.optionsContainer); partyContainer.add(this.optionsContainer);
this.options = [];
this.partySlots = []; this.partySlots = [];
} }
show(args: any[]) { show(args: any[]) {
if (!args.length)
return;
super.show(args); super.show(args);
this.partyUiMode = args[0] as PartyUiMode;
this.partyContainer.setVisible(true); this.partyContainer.setVisible(true);
this.populatePartySlots(); this.populatePartySlots();
this.setCursor(this.cursor < 6 ? this.cursor : 0); this.setCursor(this.cursor < 6 ? this.cursor : 0);
this.isModal = args.length && args[0];
if (args.length > 1 && args[1] instanceof Function) if (args.length > 1 && args[1] instanceof Function)
this.selectCallback = args[1]; this.selectCallback = args[1];
this.selectFilter = args.length > 2 && args[2] instanceof Function this.selectFilter = args.length > 2 && args[2] instanceof Function
@ -124,7 +146,8 @@ export default class PartyUiHandler extends MessageUiHandler {
if (this.optionsMode) { if (this.optionsMode) {
if (keyCode === keyCodes.Z) { if (keyCode === keyCodes.Z) {
if (!this.optionsCursor) { const option = this.options[this.optionsCursor];
if (option === PartyOption.SHIFT || option === PartyOption.SEND_OUT || option === PartyOption.APPLY) {
let filterResult: string = this.selectFilter(this.scene.getParty()[this.cursor]); let filterResult: string = this.selectFilter(this.scene.getParty()[this.cursor]);
if (filterResult === null) { if (filterResult === null) {
this.clearOptions(); this.clearOptions();
@ -145,11 +168,11 @@ export default class PartyUiHandler extends MessageUiHandler {
this.message.y += 15; this.message.y += 15;
}, null, true); }, null, true);
} }
} else if (this.optionsCursor === 1) { } else if (option === PartyOption.SUMMARY) {
this.clearOptions(); this.clearOptions();
ui.playSelect(); ui.playSelect();
ui.setMode(Mode.SUMMARY); ui.setMode(Mode.SUMMARY);
} else } else if (option === PartyOption.CANCEL)
this.processInput(keyCodes.X); this.processInput(keyCodes.X);
} else if (keyCode === keyCodes.X) { } else if (keyCode === keyCodes.X) {
this.clearOptions(); this.clearOptions();
@ -158,10 +181,10 @@ export default class PartyUiHandler extends MessageUiHandler {
else { else {
switch (keyCode) { switch (keyCode) {
case keyCodes.UP: case keyCodes.UP:
success = this.setCursor(this.optionsCursor ? this.optionsCursor - 1 : 2); success = this.setCursor(this.optionsCursor ? this.optionsCursor - 1 : this.options.length - 1);
break; break;
case keyCodes.DOWN: case keyCodes.DOWN:
success = this.setCursor(this.optionsCursor < 2 ? this.optionsCursor + 1 : 0); success = this.setCursor(this.optionsCursor < this.options.length - 1 ? this.optionsCursor + 1 : 0);
break; break;
} }
} }
@ -170,13 +193,13 @@ export default class PartyUiHandler extends MessageUiHandler {
if (this.cursor < 6) { if (this.cursor < 6) {
this.showOptions(); this.showOptions();
ui.playSelect(); ui.playSelect();
} else if (this.isModal) } else if (this.partyUiMode === PartyUiMode.FORCE_SWITCH)
ui.playError(); ui.playError();
else else
this.processInput(keyCodes.X); this.processInput(keyCodes.X);
return; return;
} else if (keyCode === keyCodes.X) { } else if (keyCode === keyCodes.X) {
if (!this.isModal) { if (this.partyUiMode !== PartyUiMode.FORCE_SWITCH) {
if (this.selectCallback) { if (this.selectCallback) {
const selectCallback = this.selectCallback; const selectCallback = this.selectCallback;
this.selectCallback = null; this.selectCallback = null;
@ -244,8 +267,7 @@ export default class PartyUiHandler extends MessageUiHandler {
this.optionsCursorObj.setOrigin(0, 0); this.optionsCursorObj.setOrigin(0, 0);
this.optionsContainer.add(this.optionsCursorObj); this.optionsContainer.add(this.optionsCursorObj);
} }
console.log(this.optionsCursor) this.optionsCursorObj.setPosition(-86, -19 - (16 * ((this.options.length - 1) - this.optionsCursor)));
this.optionsCursorObj.setPosition(-86, -19 - (16 * (2 - this.optionsCursor)));
} else { } else {
changed = this.cursor !== cursor; changed = this.cursor !== cursor;
if (changed) { if (changed) {
@ -278,16 +300,25 @@ export default class PartyUiHandler extends MessageUiHandler {
optionsBottom.setOrigin(1, 1); optionsBottom.setOrigin(1, 1);
this.optionsContainer.add(optionsBottom); this.optionsContainer.add(optionsBottom);
const options = [ switch (this.partyUiMode) {
this.isModal ? 'SEND OUT' : 'SHIFT', case PartyUiMode.SWITCH:
'SUMMARY', if (this.cursor)
'CANCEL' this.options.push(PartyOption.SHIFT);
]; break;
case PartyUiMode.FORCE_SWITCH:
this.options.push(PartyOption.SEND_OUT);
break;
case PartyUiMode.MODIFIER:
this.options.push(PartyOption.APPLY);
break;
}
for (let o = 0; o < options.length; o++) { this.options.push(PartyOption.SUMMARY, PartyOption.CANCEL);
for (let o = 0; o < this.options.length; o++) {
const yCoord = -6 - 16 * o; const yCoord = -6 - 16 * o;
const optionBg = this.scene.add.image(0, yCoord, 'party_options_center'); const optionBg = this.scene.add.image(0, yCoord, 'party_options_center');
const optionText = addTextObject(this.scene, -79, yCoord - 16, options[options.length - (o + 1)], TextStyle.WINDOW); const optionText = addTextObject(this.scene, -79, yCoord - 16, PartyOption[this.options[this.options.length - (o + 1)]].replace(/\_/g, ' '), TextStyle.WINDOW);
optionBg.setOrigin(1, 1); optionBg.setOrigin(1, 1);
optionText.setOrigin(0, 0); optionText.setOrigin(0, 0);
@ -296,7 +327,7 @@ export default class PartyUiHandler extends MessageUiHandler {
this.optionsContainer.add(optionText); this.optionsContainer.add(optionText);
} }
const optionsTop = this.scene.add.image(0, -6 - 16 * options.length, 'party_options_top'); const optionsTop = this.scene.add.image(0, -6 - 16 * this.options.length, 'party_options_top');
optionsTop.setOrigin(1, 1); optionsTop.setOrigin(1, 1);
this.optionsContainer.add(optionsTop); this.optionsContainer.add(optionsTop);
@ -305,6 +336,7 @@ export default class PartyUiHandler extends MessageUiHandler {
clearOptions() { clearOptions() {
this.optionsMode = false; this.optionsMode = false;
this.options.splice(0, this.options.length);
this.optionsContainer.removeAll(true); this.optionsContainer.removeAll(true);
this.eraseOptionsCursor(); this.eraseOptionsCursor();