Creating a new window from the Actor Command window

I've created a "Status" window that shows extra information about battlers, and I want it to be accessible from the Actor Command window.  I've got the window itself working, but when I add it to the Actor Command window, even though it's accessible really weird things start to happen once the player visits the Status window.


It seems like even when the Status window is up and active, the player is still able to select and execute actor commands on the now-invisible Actor Command window (or even go back to the Party Command window and try to escape).  You can, for example, keep clicking Confirm to start a round of combat where everyone attacks.  Moving around with the cursor on the Status window can change which enemies are attacked or which actions (like Skills) are selected instead of attacks, but it seems to be done with almost no rhyme or reason.


I don't understand what I've done wrong, so I would REALLY appreciate some help from someone who knows what they're doing here. 🙂   Below, I've pasted the entirety of the code that is used to add the Status window to the battle scene and enable it from the Actor Command window - if you need to see any of the code for the Window itself, please say so and I'll show you by PM.



A little extra info: I figured this was because the Command windows were still somehow active, but adding .deactivate() commands into the command_status function didn't do anything, and when I put in some debug code (see green text) to write out the active windows to the console, at the time the Status Window is visited it only shows that _helpWindow, _scrollTextWindow, and _messageWindow are active.  Also, interesting, the orange text near the end of the code - which is gibberish meant to throw errors - only seems to be run once the combat actions are being executed already or the player hits Cancel multiple times (probably going farther back in the chain than the Party Command phase).  Overwriting the isOkEnabled() function for this window to always return false seems to have done absolutely nothing.


Window_ActorCommand.prototype.make_commands_with_status = Window_ActorCommand.prototype.makeCommandList;
Window_ActorCommand.prototype.makeCommandList = function() {
    this.make_commands_with_status.call(this);
    if (this._actor) {
        this.add_status_command();
    }
}


Window_ActorCommand.prototype.add_status_command = function() {
    this.addCommand('Status', 'battler_states', true);
}


Scene_Battle.prototype.command_status = function() {
    this._actorCommandWindow.hide();
    this._actorCommandWindow.deactivate();
    this._partyCommandWindow.hide();
    this._partyCommandWindow.deactivate();
    this.states_window.refresh();
    this.states_window.show();
    this.states_window.activate();
    this.states_help_window.refresh();
    this.states_help_window.show();
    // FOR TESTING
    var culprits = [this._logWindow,this._statusWindow,this._partyCommandWindow,this._actorCommandWindow,this._helpWindow,
            this._skillWindow,this._itemWindow,this._actorWindow,this._enemyWindow,this._messageWindow,this._scrollTextWindow]
    for (cul = 0; cul < culprits.length; cul++) {
        if (culprits[cul].active) {
            console.log("Window" + cul + " is active");
        }
    }
    // END TESTING

};


Scene_Battle.prototype.create_actor_command_with_status = Scene_Battle.prototype.createActorCommandWindow;
Scene_Battle.prototype.createActorCommandWindow = function() {
    this.create_actor_command_with_status.call(this);
    this._actorCommandWindow.setHandler('battler_states', this.command_status.bind(this));
};


Scene_Battle.prototype.create_all_windows_with_status = Scene_Battle.prototype.createAllWindows;
Scene_Battle.prototype.createAllWindows = function() {
    this.create_all_windows_with_status.call(this);
    this.create_states_window();
    this.create_states_help_window();
};


Scene_Battle.prototype.create_states_window = function() {
    this.states_window = new Window_Battle_States();
    this.states_window.setHandler('cancel', this.on_status_cancel.bind(this));
    this.states_window.setHandler('ok', this.on_status_ok.bind(this));
    this.addWindow(this.states_window);
    this.states_window.hide();
};


Scene_Battle.prototype.create_states_help_window = function() {
    this.states_help_window = new Window_States_Help();
    this.addWindow(this.states_help_window);
    this.states_help_window.hide();
    this.states_window.setHelpWindow(this.states_help_window);
};


Scene_Battle.prototype.on_status_cancel = function() {
    var e67 = eeras;
    this.states_window.hide();
    this.states_window.deactivate();
    this.states_help_window.hide();
    this._actorCommandWindow.activate();
    this._actorCommandWindow.show();
};


Scene_Battle.prototype.on_status_ok = function() {
    this.states_window.abatooie(eep);
}
Your problem seems to be somewhat related to the number of times and which windows you show/activate/hide/deactivate (especially since you mentioned hitting cancel multiple times, that sounds like a case of windows being hidden but still active). I'd suggest finding all the places where you show/activate/hide/deactivate windows, then double-checking to see if that window is actually active.


There are two other things (unrelated to your current problem, but may be a problem in the future): 

Spoiler
in this, you hide/deactivate the party command:


Scene_Battle.prototype.command_status = function() {    this._actorCommandWindow.hide();    this._actorCommandWindow.deactivate();    this._partyCommandWindow.hide();    this._partyCommandWindow.deactivate();


but you never show/activate it later on in Scene_Battle.prototype.on_status_cancel. The other thing is that you're aliasing stuff but adding the aliases to the thing itself:


Window_ActorCommand.prototype.make_commands_with_status = Window_ActorCommand.prototype.makeCommandList;Window_ActorCommand.prototype.makeCommandList = function() {    this.make_commands_with_status.call(this);    if (this._actor) {        this.add_status_command();    }}


This is more of a stylistic thing, really, but usually aliases are done somewhat like this, so as not to clog the base code:


var alias_window_actorcommand_makecommandlist = Window_ActorCommand.prototype.makeCommandList;Window_ActorCommand.prototype.makeCommandList = function() {    alias_window_actorcommand_makecommandlist.call(this);    if (this._actor) {        this.add_status_command();    }}



Edit: oh, and in Scene_Battle.prototype.create_states_window you hid the window you made but never deactivated it. That might be a problem. 

Original thread: https://forums.rpgmakerweb.com/threads/creating-a-new-window-from-the-actor-command-window.64874/