Add command cancelling and 2nd battler move memory

This commit is contained in:
Flashfyre committed 2023-10-18 23:16:38 -04:00
1 parent 83c70889fc
commit eab6d082fd
4 files changed
+51 -16

No files matched your search

+30 -12
View File
@@ -13,6 +13,9 @@ export default class FightUiHandler extends UiHandler {
private ppText: Phaser.GameObjects.Text;
private cursorObj: Phaser.GameObjects.Image;
protected fieldIndex: integer = 0;
protected cursor2: integer = 0;
constructor(scene: BattleScene) {
super(scene, Mode.FIGHT);
}
@@ -36,9 +39,11 @@ export default class FightUiHandler extends UiHandler {
show(args: any[]) {
super.show(args);
this.fieldIndex = args.length ? args[0] as integer : 0;
const messageHandler = this.getUi().getMessageHandler();
messageHandler.bg.setTexture('bg_fight');
this.setCursor(this.cursor);
this.setCursor(this.getCursor());
this.displayMoves();
}
@@ -47,9 +52,11 @@ export default class FightUiHandler extends UiHandler {
let success = false;
const cursor = this.getCursor();
if (button === Button.CANCEL || button === Button.ACTION) {
if (button === Button.ACTION) {
if ((this.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, this.cursor, false))
if ((this.scene.getCurrentPhase() as CommandPhase).handleCommand(Command.FIGHT, cursor, false))
success = true;
else
ui.playError();
@@ -60,20 +67,20 @@ export default class FightUiHandler extends UiHandler {
} else {
switch (button) {
case Button.UP:
if (this.cursor >= 2)
success = this.setCursor(this.cursor - 2);
if (cursor >= 2)
success = this.setCursor(cursor - 2);
break;
case Button.DOWN:
if (this.cursor < 2)
success = this.setCursor(this.cursor + 2);
if (cursor < 2)
success = this.setCursor(cursor + 2);
break;
case Button.LEFT:
if (this.cursor % 2 === 1)
success = this.setCursor(this.cursor - 1);
if (cursor % 2 === 1)
success = this.setCursor(cursor - 1);
break;
case Button.RIGHT:
if (this.cursor % 2 === 0)
success = this.setCursor(this.cursor + 1);
if (cursor % 2 === 0)
success = this.setCursor(cursor + 1);
break;
}
}
@@ -82,9 +89,20 @@ export default class FightUiHandler extends UiHandler {
ui.playSelect();
}
getCursor(): integer {
return !this.fieldIndex ? this.cursor : this.cursor2;
}
setCursor(cursor: integer): boolean {
const ui = this.getUi();
const ret = super.setCursor(cursor);
const changed = this.getCursor() !== cursor;
if (changed) {
if (!this.fieldIndex)
this.cursor = cursor;
else
this.cursor2 = cursor;
}
if (!this.cursorObj) {
this.cursorObj = this.scene.add.image(0, 0, 'cursor');
@@ -110,7 +128,7 @@ export default class FightUiHandler extends UiHandler {
this.cursorObj.setPosition(13 + (cursor % 2 === 1 ? 100 : 0), -31 + (cursor >= 2 ? 15 : 0));
return ret;
return changed;
}
displayMoves() {