Okay I might have gone a bit crazy trying to do this how I believe is right.
Okay first how to bind the 'confirm' and 'cancel'. This is done using the method 'setHandler' like this:
Code:
this._actionConfirmWindow.setHandler('confirm', this.commandConfirmActions.bind(this));
this._actionConfirmWindow.setHandler('cancel', this.commandCancelActions.bind(this));
The first argument of the 'setHandler' should be the symbol (key) you used for the command and the second should be the method which should be called.
In your case we want a method for the 'confirm' and 'cancel' commands. I chose to make the methods like this:
Code:
Scene_Battle.prototype.commandConfirmActions = function(){
this._actionConfirmWindow.close();
BattleManager.startTurn();
}
Scene_Battle.prototype.commandCancelActions = function(){
BattleManager._phase = 'input';
do {
this.selectPreviousCommand();
} while(BattleManager._actorIndex >= 1);
this._actionConfirmWindow.close();
}
As you can see I have actually moved the commands to the Scene_Battle. The reason for this is because I chose to create the the
Window_ActionConfirm in the Scene_Battle not the BattleManager. The reason for this is because Windows should be in Scenes, and the Scene_Battle is the one that contains the windows for Battles.
In the confirmAction method I call the close method to hide the Window_ActionConfirm after we have selected the command (the same for the cancel method), afterwards the startTurn method of the BattleManager is called.
The cancel method looks a bit more complicated, however it is "simple enough" it changes the phase of the BattleManager to 'input' (this is becuase of a change I made another place in the code), and then simply callse the selectPreviousCommand method until we are back at the first actor.
Now as I said I moved the creation of the Window_ActionConfirm to the Scene_Battle like this:
Code:
Scene_Battle.prototype.createConfirmWindow = function() {
this._actionConfirmWindow = new Window_ActionConfirm(300, 300);
this._actionConfirmWindow.setHandler('confirm', this.commandConfirmActions.bind(this));
this._actionConfirmWindow.setHandler('cancel', this.commandCancelActions.bind(this));
this._actionConfirmWindow.deselect();
this._actionConfirmWindow.close();
this.addWindow(this._actionConfirmWindow);
}
This method is to be called in the createAllWindows method of Scene_Battle. The method is simple enough, it binds the methods to the commands, adds the window to the scene, and closes the window as it shouldn't be visible yet.
Now we need to make the window appear at an appropriate time. You identified a place yourself. What I choose to do is change the phase of the BattleManager to a phase I call 'pre_turn'.
Code:
BattleManager.selectNextCommand = function() {
do {
if (!this.actor() || !this.actor().selectNextCommand()) {
this.changeActor(this._actorIndex + 1, 'waiting');
if (this._actorIndex >= $gameParty.size()) {
this._phase = 'pre_turn';
break;
}
}
} while (!this.actor().canInput());
};
So how does this make the window show? It does in the changeInputWindow method of the Scene_Battle like this.
Code:
var MRP_TEST_SB_CHANGEINPUTWINDOW = Scene_Battle.prototype.changeInputWindow;
Scene_Battle.prototype.changeInputWindow = function() {
MRP_TEST_SB_CHANGEINPUTWINDOW.call(this);
if(BattleManager.isInPreTurn()) {
this._actionConfirmWindow.setup();
}
};
BattleManager.isInPreTurn = function() {
return this._phase === 'pre_turn';
};
As you can see it calls a method called setup of the Window_ActionConfirm. You did not write a method like that, it could look like this:
Code:
Window_ActionConfirm.prototype.setup = function() {
this.clearCommandList();
this.makeCommandList();
this.refresh();
this.select(0);
this.activate();
this.open();
};
This refreshes the window and command list, selects the first command, activates and opens the window.
This basically covers what you want. However there are a few more changes we need to make in order to make it work properly. We have to add the window to the isAnyInputWindowActive of Scene_Battle.
Code:
var MRP_TEST_SB_ISANYINPUTWINDOWACTIVE = Scene_Battle.prototype.isAnyInputWindowActive;
Scene_Battle.prototype.isAnyInputWindowActive = function() {
return MRP_TEST_SB_ISANYINPUTWINDOWACTIVE.call(this) || this._actionConfirmWindow.active;
};
The initialize function of Window_ActionConfirm should also do a bit extra like this as it should start closed and deactivated:
Code:
Window_ActionConfirm.prototype.constructor = Window_ActionConfirm;
Window_ActionConfirm.prototype.initialize = function(x, y) {
Window_Command.prototype.initialize.call(this, x, y);
this.openness = 0;
this.deactivate();
};
I also changed the fittingHeight parameter to be 2 instead of 3 as we only have 2 commands.
Code:
Window_ActionConfirm.prototype.windowHeight = function() {
return this.fittingHeight(2);
};
If you have any questions about this feel free to ask me
🙂
Spoiler: Entire code snippet
Code:
//-----------------------------------------------------------------------------
// Window_ActionConfirm
//
// The window for confirming actions selected
function Window_ActionConfirm() {
this.initialize.apply(this, arguments);
}
Window_ActionConfirm.prototype = Object.create(Window_Command.prototype);
Window_ActionConfirm.prototype.constructor = Window_ActionConfirm;
Window_ActionConfirm.prototype.initialize = function(x, y) {
Window_Command.prototype.initialize.call(this, x, y);
this.openness = 0;
this.deactivate();
};
Window_ActionConfirm.prototype.windowWidth = function() {
return 300;
};
Window_ActionConfirm.prototype.windowHeight = function() {
return this.fittingHeight(2);
};
Window_ActionConfirm.prototype.makeCommandList = function() {
this.addCommand("Confirm Actions", 'confirm');
this.addCommand("Cancel", 'cancel');
};
Window_ActionConfirm.prototype.setup = function() {
this.clearCommandList();
this.makeCommandList();
this.refresh();
this.select(0);
this.activate();
this.open();
};
//-----------------------------------------------------------------------------
// Scene_Battle
//
// Changes to Scene_Battle.
var MRP_TEST_SB_CREATEALLWINDOWS = Scene_Battle.prototype.createAllWindows;
Scene_Battle.prototype.createAllWindows = function() {
MRP_TEST_SB_CREATEALLWINDOWS.call(this);
this.createConfirmWindow();
};
Scene_Battle.prototype.createConfirmWindow = function() {
this._actionConfirmWindow = new Window_ActionConfirm(300, 300);
this._actionConfirmWindow.setHandler('confirm', this.commandConfirmActions.bind(this));
this._actionConfirmWindow.setHandler('cancel', this.commandCancelActions.bind(this));
this._actionConfirmWindow.deselect();
this._actionConfirmWindow.close();
this.addWindow(this._actionConfirmWindow);
}
Scene_Battle.prototype.commandConfirmActions = function(){
this._actionConfirmWindow.close();
BattleManager.startTurn();
}
Scene_Battle.prototype.commandCancelActions = function(){
BattleManager._phase = 'input';
do {
this.selectPreviousCommand();
} while(BattleManager._actorIndex >= 1);
this._actionConfirmWindow.close();
}
var MRP_TEST_SB_CHANGEINPUTWINDOW = Scene_Battle.prototype.changeInputWindow;
Scene_Battle.prototype.changeInputWindow = function() {
MRP_TEST_SB_CHANGEINPUTWINDOW.call(this);
if(BattleManager.isInPreTurn()) {
this._actionConfirmWindow.setup();
}
};
var MRP_TEST_SB_ISANYINPUTWINDOWACTIVE = Scene_Battle.prototype.isAnyInputWindowActive;
Scene_Battle.prototype.isAnyInputWindowActive = function() {
return MRP_TEST_SB_ISANYINPUTWINDOWACTIVE.call(this) || this._actionConfirmWindow.active;
};
//-----------------------------------------------------------------------------
// BattleManager
//
// Changes to BattleManager.
BattleManager.isInPreTurn = function() {
return this._phase === 'pre_turn';
};
BattleManager.selectNextCommand = function() {
do {
if (!this.actor() || !this.actor().selectNextCommand()) {
this.changeActor(this._actorIndex + 1, 'waiting');
if (this._actorIndex >= $gameParty.size()) {
this._phase = 'pre_turn';
break;
}
}
} while (!this.actor().canInput());
};