This commit is contained in:
Tiago Rodrigues 2025-06-19 08:44:36 +01:00 committed by GitHub
commit f2287eccf3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 590 additions and 15 deletions

View File

@ -0,0 +1,62 @@
{
"textures": [
{
"image": "party_discard.png",
"format": "RGBA8888",
"size": {
"w": 52,
"h": 32
},
"scale": 1,
"frames": [
{
"filename": "normal",
"rotated": false,
"trimmed": false,
"sourceSize": {
"w": 52,
"h": 16
},
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 52,
"h": 16
},
"frame": {
"x": 0,
"y": 0,
"w": 52,
"h": 16
}
},
{
"filename": "selected",
"rotated": false,
"trimmed": false,
"sourceSize": {
"w": 52,
"h": 16
},
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 52,
"h": 16
},
"frame": {
"x": 0,
"y": 16,
"w": 52,
"h": 16
}
}
]
}
],
"meta": {
"app": "https://www.codeandweb.com/texturepacker",
"version": "3.0",
"smartupdate": "$TexturePacker:SmartUpdate:17219773dfffd6b1204d988fea3f9462:1127ad21d64bc7ebb9df4fc28f3d2d39:7ad46e8fb4648c3d3d84a746ecb371ea$"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 214 B

View File

@ -0,0 +1,62 @@
{
"textures": [
{
"image": "party_transfer.png",
"format": "RGBA8888",
"size": {
"w": 52,
"h": 32
},
"scale": 1,
"frames": [
{
"filename": "normal",
"rotated": false,
"trimmed": false,
"sourceSize": {
"w": 52,
"h": 16
},
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 52,
"h": 16
},
"frame": {
"x": 0,
"y": 0,
"w": 52,
"h": 16
}
},
{
"filename": "selected",
"rotated": false,
"trimmed": false,
"sourceSize": {
"w": 52,
"h": 16
},
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 52,
"h": 16
},
"frame": {
"x": 0,
"y": 16,
"w": 52,
"h": 16
}
}
]
}
],
"meta": {
"app": "https://www.codeandweb.com/texturepacker",
"version": "3.0",
"smartupdate": "$TexturePacker:SmartUpdate:17219773dfffd6b1204d988fea3f9462:1127ad21d64bc7ebb9df4fc28f3d2d39:7ad46e8fb4648c3d3d84a746ecb371ea$"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 214 B

View File

@ -0,0 +1,62 @@
{
"textures": [
{
"image": "party_discard.png",
"format": "RGBA8888",
"size": {
"w": 75,
"h": 46
},
"scale": 1,
"frames": [
{
"filename": "normal",
"rotated": false,
"trimmed": false,
"sourceSize": {
"w": 75,
"h": 23
},
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 75,
"h": 23
},
"frame": {
"x": 0,
"y": 0,
"w": 75,
"h": 23
}
},
{
"filename": "selected",
"rotated": false,
"trimmed": false,
"sourceSize": {
"w": 75,
"h": 23
},
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 75,
"h": 23
},
"frame": {
"x": 0,
"y": 23,
"w": 75,
"h": 23
}
}
]
}
],
"meta": {
"app": "https://www.codeandweb.com/texturepacker",
"version": "3.0",
"smartupdate": "$TexturePacker:SmartUpdate:17219773dfffd6b1204d988fea3f9462:1127ad21d64bc7ebb9df4fc28f3d2d39:7ad46e8fb4648c3d3d84a746ecb371ea$"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

View File

@ -0,0 +1,62 @@
{
"textures": [
{
"image": "party_transfer.png",
"format": "RGBA8888",
"size": {
"w": 75,
"h": 46
},
"scale": 1,
"frames": [
{
"filename": "normal",
"rotated": false,
"trimmed": false,
"sourceSize": {
"w": 75,
"h": 23
},
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 75,
"h": 23
},
"frame": {
"x": 0,
"y": 0,
"w": 75,
"h": 23
}
},
{
"filename": "selected",
"rotated": false,
"trimmed": false,
"sourceSize": {
"w": 75,
"h": 23
},
"spriteSourceSize": {
"x": 0,
"y": 0,
"w": 75,
"h": 23
},
"frame": {
"x": 0,
"y": 23,
"w": 75,
"h": 23
}
}
]
}
],
"meta": {
"app": "https://www.codeandweb.com/texturepacker",
"version": "3.0",
"smartupdate": "$TexturePacker:SmartUpdate:17219773dfffd6b1204d988fea3f9462:1127ad21d64bc7ebb9df4fc28f3d2d39:7ad46e8fb4648c3d3d84a746ecb371ea$"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

View File

@ -2806,6 +2806,19 @@ export default class BattleScene extends SceneBase {
return false; return false;
} }
tryDiscardHeldItemModifier(itemModifier: PokemonHeldItemModifier, discardQuantity = 1): boolean {
const countTaken = Math.min(discardQuantity, itemModifier.stackCount);
itemModifier.stackCount -= countTaken;
const removeOld = itemModifier.stackCount === 0;
if (removeOld) {
return this.removeModifier(itemModifier);
}
return true;
}
canTransferHeldItemModifier(itemModifier: PokemonHeldItemModifier, target: Pokemon, transferQuantity = 1): boolean { canTransferHeldItemModifier(itemModifier: PokemonHeldItemModifier, target: Pokemon, transferQuantity = 1): boolean {
const mod = itemModifier.clone() as PokemonHeldItemModifier; const mod = itemModifier.clone() as PokemonHeldItemModifier;
const source = mod.pokemonId ? mod.getPokemon() : null; const source = mod.pokemonId ? mod.getPokemon() : null;

View File

@ -138,6 +138,8 @@ export class LoadingScene extends SceneBase {
this.loadAtlas("party_slot_hp_overlay", "ui"); this.loadAtlas("party_slot_hp_overlay", "ui");
this.loadAtlas("party_pb", "ui"); this.loadAtlas("party_pb", "ui");
this.loadAtlas("party_cancel", "ui"); this.loadAtlas("party_cancel", "ui");
this.loadAtlas("party_discard", "ui");
this.loadAtlas("party_transfer", "ui");
this.loadImage("summary_bg", "ui"); this.loadImage("summary_bg", "ui");
this.loadImage("summary_overlay_shiny", "ui"); this.loadImage("summary_overlay_shiny", "ui");

View File

@ -68,7 +68,7 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler {
if (context) { if (context) {
context.font = styleOptions.fontSize + "px " + styleOptions.fontFamily; context.font = styleOptions.fontSize + "px " + styleOptions.fontFamily;
this.transferButtonWidth = context.measureText(i18next.t("modifierSelectUiHandler:transfer")).width; this.transferButtonWidth = context.measureText("Manage Items").width; // Missing "Manage Items" call from locales.
this.checkButtonWidth = context.measureText(i18next.t("modifierSelectUiHandler:checkTeam")).width; this.checkButtonWidth = context.measureText(i18next.t("modifierSelectUiHandler:checkTeam")).width;
} }
@ -80,7 +80,7 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler {
this.transferButtonContainer.setVisible(false); this.transferButtonContainer.setVisible(false);
ui.add(this.transferButtonContainer); ui.add(this.transferButtonContainer);
const transferButtonText = addTextObject(-4, -2, i18next.t("modifierSelectUiHandler:transfer"), TextStyle.PARTY); const transferButtonText = addTextObject(-4, -2, "Manage Items", TextStyle.PARTY); // Missing "Manage Items" call from locales.
transferButtonText.setName("text-transfer-btn"); transferButtonText.setName("text-transfer-btn");
transferButtonText.setOrigin(1, 0); transferButtonText.setOrigin(1, 0);
this.transferButtonContainer.add(transferButtonText); this.transferButtonContainer.add(transferButtonText);

View File

@ -101,6 +101,11 @@ export enum PartyUiMode {
* This is generally used in for Mystery Encounter or special effects that require the player to select a Pokemon * This is generally used in for Mystery Encounter or special effects that require the player to select a Pokemon
*/ */
SELECT, SELECT,
/**
* Indicates that the party UI is open to select a party member from which to discard an item from
* This type of selection can be cancelled.
*/
DISCARD,
} }
export enum PartyOption { export enum PartyOption {
@ -119,6 +124,7 @@ export enum PartyOption {
RELEASE, RELEASE,
RENAME, RENAME,
SELECT, SELECT,
DISCARD,
SCROLL_UP = 1000, SCROLL_UP = 1000,
SCROLL_DOWN = 1001, SCROLL_DOWN = 1001,
FORM_CHANGE_ITEM = 2000, FORM_CHANGE_ITEM = 2000,
@ -153,6 +159,7 @@ export default class PartyUiHandler extends MessageUiHandler {
private partySlotsContainer: Phaser.GameObjects.Container; private partySlotsContainer: Phaser.GameObjects.Container;
private partySlots: PartySlot[]; private partySlots: PartySlot[];
private partyCancelButton: PartyCancelButton; private partyCancelButton: PartyCancelButton;
private PartyDiscardModeButton: PartyDiscardModeButton;
private partyMessageBox: Phaser.GameObjects.NineSlice; private partyMessageBox: Phaser.GameObjects.NineSlice;
private moveInfoOverlay: MoveInfoOverlay; private moveInfoOverlay: MoveInfoOverlay;
@ -306,6 +313,12 @@ export default class PartyUiHandler extends MessageUiHandler {
this.iconAnimHandler = new PokemonIconAnimHandler(); this.iconAnimHandler = new PokemonIconAnimHandler();
this.iconAnimHandler.setup(); this.iconAnimHandler.setup();
const partyDiscardModeButton = new PartyDiscardModeButton(60, -globalScene.game.canvas.height / 15 - 1);
partyContainer.add(partyDiscardModeButton);
this.PartyDiscardModeButton = partyDiscardModeButton;
// prepare move overlay. in case it appears to be too big, set the overlayScale to .5 // prepare move overlay. in case it appears to be too big, set the overlayScale to .5
const overlayScale = 1; const overlayScale = 1;
this.moveInfoOverlay = new MoveInfoOverlay({ this.moveInfoOverlay = new MoveInfoOverlay({
@ -349,6 +362,7 @@ export default class PartyUiHandler extends MessageUiHandler {
this.partyContainer.setVisible(true); this.partyContainer.setVisible(true);
this.partyBg.setTexture(`party_bg${globalScene.currentBattle.double ? "_double" : ""}`); this.partyBg.setTexture(`party_bg${globalScene.currentBattle.double ? "_double" : ""}`);
this.populatePartySlots(); this.populatePartySlots();
this.PartyDiscardModeButton.toggleIcon(this.partyUiMode);
this.setCursor(0); this.setCursor(0);
return true; return true;
@ -593,7 +607,7 @@ export default class PartyUiHandler extends MessageUiHandler {
const option = this.options[this.optionsCursor]; const option = this.options[this.optionsCursor];
if (button === Button.LEFT) { if (button === Button.LEFT) {
/** Decrease quantity for the current item and update UI */ /** Decrease quantity for the current item and update UI */
if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER) { if (this.isItemManageMode()) {
this.transferQuantities[option] = this.transferQuantities[option] =
this.transferQuantities[option] === 1 this.transferQuantities[option] === 1
? this.transferQuantitiesMax[option] ? this.transferQuantitiesMax[option]
@ -607,7 +621,7 @@ export default class PartyUiHandler extends MessageUiHandler {
if (button === Button.RIGHT) { if (button === Button.RIGHT) {
/** Increase quantity for the current item and update UI */ /** Increase quantity for the current item and update UI */
if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER) { if (this.isItemManageMode()) {
this.transferQuantities[option] = this.transferQuantities[option] =
this.transferQuantities[option] === this.transferQuantitiesMax[option] this.transferQuantities[option] === this.transferQuantitiesMax[option]
? 1 ? 1
@ -637,6 +651,34 @@ export default class PartyUiHandler extends MessageUiHandler {
return success; return success;
} }
private processDiscardMenuInput(pokemon: PlayerPokemon) {
const ui = this.getUi();
this.clearOptions();
const itemModifiers = this.getTransferrableItemsFromPokemon(pokemon);
let success = true;
if (this.optionsCursor === itemModifiers.length) {
for (let i = 0; i < itemModifiers.length; i++) {
success = globalScene.tryDiscardHeldItemModifier(itemModifiers[i], this.transferQuantities[i]);
}
} else {
success = globalScene.tryDiscardHeldItemModifier(
itemModifiers[this.optionsCursor],
this.transferQuantities[this.optionsCursor],
);
}
if (success) {
this.showText("Item has been discarded.", undefined, () => this.showText("", 0), null, true); // missing confirm message call from i18next.t.
ui.playSelect();
} else {
ui.playError();
}
return success;
}
private moveOptionCursor(button: Button.UP | Button.DOWN): boolean { private moveOptionCursor(button: Button.UP | Button.DOWN): boolean {
if (button === Button.UP) { if (button === Button.UP) {
return this.setCursor(this.optionsCursor ? this.optionsCursor - 1 : this.options.length - 1); return this.setCursor(this.optionsCursor ? this.optionsCursor - 1 : this.options.length - 1);
@ -723,6 +765,10 @@ export default class PartyUiHandler extends MessageUiHandler {
return this.processModifierTransferModeInput(pokemon); return this.processModifierTransferModeInput(pokemon);
} }
if (this.partyUiMode === PartyUiMode.DISCARD) {
return this.processDiscardMenuInput(pokemon);
}
// options specific to the mode (moves) // options specific to the mode (moves)
if (this.partyUiMode === PartyUiMode.REMEMBER_MOVE_MODIFIER) { if (this.partyUiMode === PartyUiMode.REMEMBER_MOVE_MODIFIER) {
return this.processRememberMoveModeInput(pokemon); return this.processRememberMoveModeInput(pokemon);
@ -862,7 +908,7 @@ export default class PartyUiHandler extends MessageUiHandler {
} }
if (button === Button.LEFT || button === Button.RIGHT) { if (button === Button.LEFT || button === Button.RIGHT) {
if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER) { if (this.isItemManageMode()) {
return this.processModifierTransferModeLeftRightInput(button); return this.processModifierTransferModeLeftRightInput(button);
} }
} }
@ -917,10 +963,17 @@ export default class PartyUiHandler extends MessageUiHandler {
return !(this.partyUiMode === PartyUiMode.FAINT_SWITCH || this.partyUiMode === PartyUiMode.REVIVAL_BLESSING); return !(this.partyUiMode === PartyUiMode.FAINT_SWITCH || this.partyUiMode === PartyUiMode.REVIVAL_BLESSING);
} }
private isItemManageMode(): boolean {
return this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER || this.partyUiMode === PartyUiMode.DISCARD;
}
private processPartyActionInput(): boolean { private processPartyActionInput(): boolean {
const ui = this.getUi(); const ui = this.getUi();
if (this.cursor < 6) { if (this.cursor < 6) {
if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER && !this.transferMode) { if (
(this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER && !this.transferMode) ||
this.partyUiMode === PartyUiMode.DISCARD
) {
/** Initialize item quantities for the selected Pokemon */ /** Initialize item quantities for the selected Pokemon */
const itemModifiers = globalScene.findModifiers( const itemModifiers = globalScene.findModifiers(
m => m =>
@ -934,6 +987,24 @@ export default class PartyUiHandler extends MessageUiHandler {
this.showOptions(); this.showOptions();
ui.playSelect(); ui.playSelect();
} }
if (this.cursor === 7) {
switch (this.partyUiMode) {
case PartyUiMode.DISCARD:
this.partyUiMode = PartyUiMode.MODIFIER_TRANSFER;
ui.playSelect();
break;
case PartyUiMode.MODIFIER_TRANSFER:
this.partyUiMode = PartyUiMode.DISCARD;
ui.playSelect();
break;
default:
ui.playError();
break;
}
this.PartyDiscardModeButton.toggleIcon(this.partyUiMode);
ui.playSelect();
}
// Pressing return button // Pressing return button
if (this.cursor === 6) { if (this.cursor === 6) {
if (!this.allowCancel()) { if (!this.allowCancel()) {
@ -954,6 +1025,7 @@ export default class PartyUiHandler extends MessageUiHandler {
this.clearTransfer(); this.clearTransfer();
ui.playSelect(); ui.playSelect();
} else if (this.allowCancel()) { } else if (this.allowCancel()) {
this.PartyDiscardModeButton.clear();
if (this.selectCallback) { if (this.selectCallback) {
const selectCallback = this.selectCallback; const selectCallback = this.selectCallback;
this.selectCallback = null; this.selectCallback = null;
@ -975,9 +1047,53 @@ export default class PartyUiHandler extends MessageUiHandler {
let success = false; let success = false;
switch (button) { switch (button) {
case Button.UP: case Button.UP:
if (this.cursor === 1) {
if (this.isItemManageMode()) {
success = this.setCursor(globalScene.currentBattle.double ? 0 : 7);
break;
}
}
if (this.cursor === 2) {
if (this.isItemManageMode()) {
success = this.setCursor(globalScene.currentBattle.double ? 7 : 1);
break;
}
}
if (this.cursor === 6) {
if (this.isItemManageMode()) {
success = this.setCursor(slotCount <= globalScene.currentBattle.getBattlerCount() ? 7 : slotCount - 1);
break;
}
}
if (this.cursor === 7) {
if (this.isItemManageMode()) {
success = this.setCursor(globalScene.currentBattle.double && slotCount > 1 ? 1 : 0);
break;
}
}
success = this.setCursor(this.cursor ? (this.cursor < 6 ? this.cursor - 1 : slotCount - 1) : 6); success = this.setCursor(this.cursor ? (this.cursor < 6 ? this.cursor - 1 : slotCount - 1) : 6);
break; break;
case Button.DOWN: case Button.DOWN:
if (this.cursor === 0) {
if (this.isItemManageMode()) {
success = this.setCursor(globalScene.currentBattle.double && slotCount > 1 ? 1 : 7);
break;
}
}
if (this.cursor === 1) {
if (this.isItemManageMode()) {
success = this.setCursor(globalScene.currentBattle.double ? 7 : slotCount > 2 ? 2 : 6);
break;
}
}
if (this.cursor === 7) {
if (this.isItemManageMode()) {
success = this.setCursor(
slotCount > globalScene.currentBattle.getBattlerCount() ? globalScene.currentBattle.getBattlerCount() : 6,
);
break;
}
}
success = this.setCursor(this.cursor < 6 ? (this.cursor < slotCount - 1 ? this.cursor + 1 : 6) : 0); success = this.setCursor(this.cursor < 6 ? (this.cursor < slotCount - 1 ? this.cursor + 1 : 6) : 0);
break; break;
case Button.LEFT: case Button.LEFT:
@ -986,7 +1102,7 @@ export default class PartyUiHandler extends MessageUiHandler {
} }
break; break;
case Button.RIGHT: case Button.RIGHT:
if (slotCount === battlerCount) { if ((this.cursor === 7 && this.isItemManageMode()) || slotCount === battlerCount) {
success = this.setCursor(6); success = this.setCursor(6);
break; break;
} }
@ -1042,11 +1158,15 @@ export default class PartyUiHandler extends MessageUiHandler {
this.partySlots[this.lastCursor].deselect(); this.partySlots[this.lastCursor].deselect();
} else if (this.lastCursor === 6) { } else if (this.lastCursor === 6) {
this.partyCancelButton.deselect(); this.partyCancelButton.deselect();
} else if (this.lastCursor === 7) {
this.PartyDiscardModeButton.deselect();
} }
if (cursor < 6) { if (cursor < 6) {
this.partySlots[cursor].select(); this.partySlots[cursor].select();
} else if (cursor === 6) { } else if (cursor === 6) {
this.partyCancelButton.select(); this.partyCancelButton.select();
} else if (cursor === 7) {
this.PartyDiscardModeButton.select();
} }
} }
return changed; return changed;
@ -1141,14 +1261,16 @@ export default class PartyUiHandler extends MessageUiHandler {
optionsMessage = i18next.t("partyUiHandler:selectAnotherPokemonToSplice"); optionsMessage = i18next.t("partyUiHandler:selectAnotherPokemonToSplice");
} }
break; break;
case PartyUiMode.DISCARD:
optionsMessage = "Select a held item to discard.\nUse < and > to change quantity."; //Missing discard i18next.t call message
} }
this.showText(optionsMessage, 0); this.showText(optionsMessage, 0);
this.updateOptions(); this.updateOptions();
/** When an item is being selected for transfer, the message box is taller as the message occupies two lines */ /** When an item is being selected for transfer or discard, the message box is taller as the message occupies two lines */
if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER) { if (this.isItemManageMode()) {
this.partyMessageBox.setSize(262 - Math.max(this.optionsBg.displayWidth - 56, 0), 42); this.partyMessageBox.setSize(262 - Math.max(this.optionsBg.displayWidth - 56, 0), 42);
} else { } else {
this.partyMessageBox.setSize(262 - Math.max(this.optionsBg.displayWidth - 56, 0), 30); this.partyMessageBox.setSize(262 - Math.max(this.optionsBg.displayWidth - 56, 0), 30);
@ -1274,6 +1396,9 @@ export default class PartyUiHandler extends MessageUiHandler {
this.addCommonOptions(pokemon); this.addCommonOptions(pokemon);
} }
break; break;
case PartyUiMode.DISCARD:
this.updateOptionsWithModifierTransferMode(pokemon);
break;
// TODO: This still needs to be broken up. // TODO: This still needs to be broken up.
// It could use a rework differentiating different kind of switches // It could use a rework differentiating different kind of switches
// to treat baton passing separately from switching on faint. // to treat baton passing separately from switching on faint.
@ -1378,7 +1503,8 @@ export default class PartyUiHandler extends MessageUiHandler {
optionName = "↓"; optionName = "↓";
} else if ( } else if (
(this.partyUiMode !== PartyUiMode.REMEMBER_MOVE_MODIFIER && (this.partyUiMode !== PartyUiMode.REMEMBER_MOVE_MODIFIER &&
(this.partyUiMode !== PartyUiMode.MODIFIER_TRANSFER || this.transferMode)) || (this.partyUiMode !== PartyUiMode.MODIFIER_TRANSFER || this.transferMode) &&
this.partyUiMode !== PartyUiMode.DISCARD) ||
option === PartyOption.CANCEL option === PartyOption.CANCEL
) { ) {
switch (option) { switch (option) {
@ -1441,7 +1567,7 @@ export default class PartyUiHandler extends MessageUiHandler {
const itemModifiers = this.getItemModifiers(pokemon); const itemModifiers = this.getItemModifiers(pokemon);
const itemModifier = itemModifiers[option]; const itemModifier = itemModifiers[option];
if ( if (
this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER && this.isItemManageMode() &&
this.transferQuantitiesMax[option] > 1 && this.transferQuantitiesMax[option] > 1 &&
!this.transferMode && !this.transferMode &&
itemModifier !== undefined && itemModifier !== undefined &&
@ -1471,7 +1597,6 @@ export default class PartyUiHandler extends MessageUiHandler {
optionText.x = 15 - this.optionsBg.width; optionText.x = 15 - this.optionsBg.width;
} }
} }
startTransfer(): void { startTransfer(): void {
this.transferMode = true; this.transferMode = true;
this.transferCursor = this.cursor; this.transferCursor = this.cursor;
@ -1660,7 +1785,7 @@ class PartySlot extends Phaser.GameObjects.Container {
? -184 + ? -184 +
(globalScene.currentBattle.double ? -40 : 0) + (globalScene.currentBattle.double ? -40 : 0) +
(28 + (globalScene.currentBattle.double ? 8 : 0)) * slotIndex (28 + (globalScene.currentBattle.double ? 8 : 0)) * slotIndex
: -124 + (globalScene.currentBattle.double ? -8 : 0) + slotIndex * 64, : -124 + (globalScene.currentBattle.double ? -20 : 0) + slotIndex * 55,
); );
this.slotIndex = slotIndex; this.slotIndex = slotIndex;
@ -1916,7 +2041,6 @@ class PartySlot extends Phaser.GameObjects.Container {
class PartyCancelButton extends Phaser.GameObjects.Container { class PartyCancelButton extends Phaser.GameObjects.Container {
private selected: boolean; private selected: boolean;
private partyCancelBg: Phaser.GameObjects.Sprite; private partyCancelBg: Phaser.GameObjects.Sprite;
private partyCancelPb: Phaser.GameObjects.Sprite; private partyCancelPb: Phaser.GameObjects.Sprite;
@ -1925,7 +2049,6 @@ class PartyCancelButton extends Phaser.GameObjects.Container {
this.setup(); this.setup();
} }
setup() { setup() {
const partyCancelBg = globalScene.add.sprite(0, 0, "party_cancel"); const partyCancelBg = globalScene.add.sprite(0, 0, "party_cancel");
this.add(partyCancelBg); this.add(partyCancelBg);
@ -1963,3 +2086,94 @@ class PartyCancelButton extends Phaser.GameObjects.Container {
this.partyCancelPb.setFrame("party_pb"); this.partyCancelPb.setFrame("party_pb");
} }
} }
class PartyDiscardModeButton extends Phaser.GameObjects.Container {
private selected: boolean;
private transferIcon: Phaser.GameObjects.Sprite;
private discardIcon: Phaser.GameObjects.Sprite;
private partyDiscardPb: Phaser.GameObjects.Sprite;
private textBox: Phaser.GameObjects.Text;
constructor(x: number, y: number) {
super(globalScene, x, y);
this.setup();
}
setup() {
this.transferIcon = globalScene.add.sprite(0, 0, "party_transfer");
this.discardIcon = globalScene.add.sprite(0, 0, "party_discard");
this.partyDiscardPb = globalScene.add.sprite(-20, 0, "party_pb");
this.textBox = addTextObject(-8, -7, i18next.t("partyUiHandler:TRANSFER"), TextStyle.PARTY);
this.add(this.transferIcon);
this.add(this.discardIcon);
this.add(this.partyDiscardPb);
this.add(this.textBox);
this.clear();
}
select() {
if (this.selected) {
return;
}
this.selected = true;
this.transferIcon.setFrame("selected");
this.discardIcon.setFrame("selected");
this.partyDiscardPb.setFrame("party_pb_sel");
}
deselect() {
if (!this.selected) {
return;
}
this.selected = false;
this.transferIcon.setFrame("normal");
this.discardIcon.setFrame("normal");
this.partyDiscardPb.setFrame("party_pb");
}
toggleIcon(partyMode: number) {
switch (partyMode) {
case PartyUiMode.DISCARD:
this.transferIcon.setVisible(true);
this.discardIcon.setVisible(false);
this.partyDiscardPb.setVisible(true);
this.textBox.setVisible(true);
this.textBox.setText(i18next.t("partyUiHandler:TRANSFER"));
this.setPosition(
globalScene.currentBattle.double ? 64 : 60,
globalScene.currentBattle.double ? -48 : -globalScene.game.canvas.height / 15 - 1,
);
this.transferIcon.displayWidth = this.textBox.text.length * 9 + 3;
break;
case PartyUiMode.MODIFIER_TRANSFER:
this.transferIcon.setVisible(false);
this.discardIcon.setVisible(true);
this.partyDiscardPb.setVisible(true);
this.textBox.setVisible(true);
this.textBox.setText("Discard");
this.setPosition(
globalScene.currentBattle.double ? 64 : 60,
globalScene.currentBattle.double ? -48 : -globalScene.game.canvas.height / 15 - 1,
);
this.discardIcon.displayWidth = this.textBox.text.length * 9 + 3;
break;
default:
return;
}
}
clear() {
this.transferIcon.setVisible(false);
this.discardIcon.setVisible(false);
this.textBox.setVisible(false);
this.partyDiscardPb.setVisible(false);
}
}

View File

@ -0,0 +1,98 @@
import { BerryType } from "#app/enums/berry-type";
import { Button } from "#app/enums/buttons";
import { MoveId } from "#enums/move-id";
import { SpeciesId } from "#enums/species-id";
import ModifierSelectUiHandler from "#app/ui/modifier-select-ui-handler";
import PartyUiHandler, { PartyUiMode } from "#app/ui/party-ui-handler";
import { UiMode } from "#enums/ui-mode";
import GameManager from "#test/testUtils/gameManager";
import Phaser from "phaser";
import { afterEach, beforeAll, beforeEach, describe, expect, it } from "vitest";
describe("UI - Transfer Items", () => {
let phaserGame: Phaser.Game;
let game: GameManager;
beforeAll(() => {
phaserGame = new Phaser.Game({
type: Phaser.HEADLESS,
});
});
afterEach(() => {
game.phaseInterceptor.restoreOg();
});
beforeEach(async () => {
game = new GameManager(phaserGame);
game.override.battleStyle("single");
game.override.startingLevel(100);
game.override.startingWave(1);
game.override.startingHeldItems([
{ name: "BERRY", count: 1, type: BerryType.SITRUS },
{ name: "BERRY", count: 2, type: BerryType.APICOT },
{ name: "BERRY", count: 2, type: BerryType.LUM },
]);
game.override.moveset([MoveId.DRAGON_CLAW]);
game.override.enemySpecies(SpeciesId.MAGIKARP);
game.override.enemyMoveset([MoveId.SPLASH]);
await game.classicMode.startBattle([SpeciesId.RAYQUAZA, SpeciesId.RAYQUAZA, SpeciesId.RAYQUAZA]);
game.move.select(MoveId.DRAGON_CLAW);
});
it("manage button exists in the proper screen", async () => {
game.onNextPrompt("SelectModifierPhase", UiMode.MODIFIER_SELECT, () => {
expect(game.scene.ui.getHandler()).toBeInstanceOf(ModifierSelectUiHandler);
const handler = game.scene.ui.getHandler() as ModifierSelectUiHandler;
handler.setCursor(1); //manage items menu, manage button should exist
handler.processInput(Button.ACTION);
void game.scene.ui.setModeWithoutClear(UiMode.PARTY, PartyUiMode.MODIFIER_TRANSFER);
});
await game.phaseInterceptor.to("BattleEndPhase");
game.phaseInterceptor.addToNextPrompt("SelectModifierPhase", UiMode.PARTY, () => {
expect(game.scene.ui.getHandler()).toBeInstanceOf(PartyUiHandler);
const handler = game.scene.ui.getHandler() as PartyUiHandler;
handler.processInput(Button.DOWN);
handler.processInput(Button.ACTION);
expect(handler.optionsContainer.list.length).toBe(0); //should select manage button,which has no menu
game.phaseInterceptor.unlock();
});
await game.phaseInterceptor.to("SelectModifierPhase");
}, 20000);
it("manage button doesn't exist in the other screens", async () => {
game.onNextPrompt("SelectModifierPhase", UiMode.MODIFIER_SELECT, () => {
expect(game.scene.ui.getHandler()).toBeInstanceOf(ModifierSelectUiHandler);
const handler = game.scene.ui.getHandler() as ModifierSelectUiHandler;
handler.setCursor(2); //check team menu,manage button shouldn't exist
handler.processInput(Button.ACTION);
void game.scene.ui.setModeWithoutClear(UiMode.PARTY, PartyUiMode.MODIFIER_TRANSFER);
});
await game.phaseInterceptor.to("BattleEndPhase");
game.phaseInterceptor.addToNextPrompt("SelectModifierPhase", UiMode.PARTY, () => {
expect(game.scene.ui.getHandler()).toBeInstanceOf(PartyUiHandler);
const handler = game.scene.ui.getHandler() as PartyUiHandler;
handler.processInput(Button.DOWN);
handler.processInput(Button.ACTION);
expect(handler.optionsContainer.list.length).toBeGreaterThan(0); //should select a pokemon, which has at least the cancel option
game.phaseInterceptor.unlock();
});
await game.phaseInterceptor.to("SelectModifierPhase");
}, 20000);
});