Advanced Menus (huge mouse navigation improvements!) [BETA]

orlando

Veteran
Veteran
Joined
May 24, 2014
Messages
177
Reaction score
84
What is this?


Welcome to the Advanced Menus plugin in a beta version which provides enhanced menu functionality for better mouse/touch navigation.


Features:

  • makes menus activate with single click even when another menu item is selected. (places like the item list where you need to be able to select items to read their detail description are exempted) No more awkward clicking twice everywhere.

  • makes many inactive menus clickable and "does the right thing", so you aren't forced to back out of submenus first before e.g. changing the Item Category with a click in the Items screen. This vastly improves the intuitiveness of mouse navigation.

    Please note this is enabled on a case-by-case basis, so if one menu isn't clickable in a specific situation where you'd expect it to, I probably missed it - drop me a note.
  • adds back buttons all over the important places. This essentially makes the entire game and all menus usable with just left clicks, you just still need Escape and/or right-click to enter the ingame escape menu and for nothing else.

    This again makes for much more intuitive and comfortable mouse navigation.

!! COMPATIBILITY WARNING !!


Please note this plugin is rather intrusive, so if you use any other plugin that modifies the menus and which isn't aware of this plugin, then it might possibly not work.


To increase compatibility, you can try those two things: 1. Put this plugin after the other unaware plugin in the plugin manager, and if that doesn't help 2. disable back buttons in the plugin options.


If none of those helps, you will probably need to contact the plugin author to ask them to make his/her plugin compatible with Advanced Menus.


Note to plugin authors: You can detect this plugin by checking for Imported.AdvancedMenus being present. You can make use of inactive menus becoming clickable yourself by implementing ._activateWhenOutOfFocus for your own menus (see the source code for examples) to make Advanced Menus allow them to be activated.


Script Contents / Download:


Here are the plugin contents, for license terms please read the embedded license at the top:


(just copy & paste the code below in a file named AdvancedMenus.js and put it in your js/plugins/ folder to use it)

Code:
// Advanced Menus
// by orlando, BigTaro (rpgmakerweb.com forums)
// Date: 25/03/2017

var Imported = Imported || {};
Imported.AdvancedMenus = "1.0.3";

// LICENSE PLEASE READ:
// ====================
//
// Copyright (C) 2015-2017 orlando, BigTaro (rpgmakerweb.com forums)
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
//    claim that you wrote the original software. If you use this software
//    in a product, an acknowledgement in the product documentation would be
//    appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
//    misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.

//===========================================================================


/*:
 * @plugindesc 1.0.3 Advanced Menus to fix countless details with mouse/touch navigation   id:AdvancedMenus
 *
 * @param Add back buttons
 * @desc Alter common menus to include back buttons. Disable if you use any plugin that does intrusive modifications to the ingame menu
 * @default true
 *
 * @param Back Text
 * @desc The text used for the back buttons
 * @default Back...
 *
 * @param Cancel Text
 * @desc The text used for the item change cancel button
 * @default Cancel...
 *
 * @author orlando (rpgmakerweb.com forums)
 */

(function() {

var parameters = $plugins.filter(function(p){return p.description.contains("id:AdvancedMenus")})[0].parameters;
var back_buttons = Boolean((parameters['Add back buttons'] === 'true') || false);
var back_text = String(parameters['Back Text']);
var cancel_text = String(parameters['Cancel Text']);

AdvancedMenus = function() {
    throw("this is a static class");
}

AdvancedMenus.menuSoundsMuted = false;
AdvancedMenus.backText = back_text;
AdvancedMenus.cancelText = cancel_text;

// ---- SPECIFIC MENUS EXPANDED TO HAVE A BACK BUTTON (IF ENABLED) ----

if (back_buttons) {
    // Window_ItemCategory "Back..." button:
    Window_ItemCategory.prototype._preAdvancedMenus_makeCommandList =
        Window_ItemCategory.prototype.makeCommandList;
    Window_ItemCategory.prototype.makeCommandList = function() {
        // Detect if we are inside a shop. If yes, don't add "Back...":
        var is_shop = false;
        var windows = AdvancedMenus.listOfWindows();
        for (var j = 0; j < windows.length; j++) {
            if (Window_ShopCommand.prototype.isPrototypeOf(windows[j])) {
                is_shop = true;
                break;
            }
        }

        this._preAdvancedMenus_makeCommandList();
        
        // Add if not a shop:
        if (!is_shop) {
            this.addCommand(AdvancedMenus.backText, 'cancel');
        }
        
    };

    // Make room for back button in Window_ItemCategory:
    Window_ItemCategory.prototype._preAdvancedMenus_maxCols =
        Window_ItemCategory.prototype.maxCols;
    Window_ItemCategory.prototype.maxCols = function() {
        // Detect if we are inside a shop. If yes, nothing needs to be added:
        var is_shop = false;
        var windows = AdvancedMenus.listOfWindows();
        for (var j = 0; j < windows.length; j++) {
            if (Window_ShopCommand.prototype.isPrototypeOf(windows[j])) {
                is_shop = true;
                break;
            }
        }
        if (is_shop) {
            return this._preAdvancedMenus_maxCols();
        } else {
            return this._preAdvancedMenus_maxCols() + 1;
        }
    };

    // Window_SkillType "Back..." button:
    Window_SkillType.prototype._preAdvancedMenus_makeCommandList =
        Window_SkillType.prototype.makeCommandList;
    Window_SkillType.prototype.makeCommandList = function() {

        this._preAdvancedMenus_makeCommandList();
        
        if (this._actor) {
            this.addCommand(AdvancedMenus.backText, 'cancel');
        }
        
    };

    // Main command list "Back..." button:
    Window_MenuCommand.prototype._preAdvancedMenus_makeCommandList =
        Window_MenuCommand.prototype.makeCommandList;
    Window_MenuCommand.prototype.makeCommandList = function() {

        this._preAdvancedMenus_makeCommandList();
        this.addCommand(AdvancedMenus.backText, 'cancel', true);
        
    };

    // Window_EquipCommand "Back..." button:
    Window_EquipCommand.prototype._preAdvancedMenus_makeCommandList =
        Window_EquipCommand.prototype.makeCommandList;
    Window_EquipCommand.prototype.makeCommandList = function() {
        this._preAdvancedMenus_makeCommandList();
        this.addCommand(AdvancedMenus.backText, 'cancel');
    };
    // Note: no need to make room for back button in Window_EquipCommand,
    // since we remove the "Equip" button later

    // Make down/up go from Window_EquipCommand to Window_EquipSlot
    Window_EquipCommand.prototype._preAdvancedMenus_cursorDown =
        Window_EquipCommand.prototype.cursorDown;
    Window_EquipCommand.prototype.cursorDown = function() {
        this.select(-1);
        SoundManager.playCursor();
        this.updateInputData();
        this.deactivate();
        SceneManager._scene.commandEquip();
    }
    Window_EquipCommand.prototype._preAdvancedMenus_cursorUp =
        Window_EquipCommand.prototype.cursorUp;
    Window_EquipCommand.prototype.cursorUp = function() {
        this.select(-1);
        SoundManager.playCursor();
        this.updateInputData();
        this.deactivate();
        SceneManager._scene.commandEquip();
        // make sure last item is selected in Window_EquipSlot:
        var windows = AdvancedMenus.listOfWindows();
        for (var j = 0; j < windows.length; j++) {
            if (Window_EquipSlot.prototype.isPrototypeOf(windows[j])) {
                windows[j].select(windows[j].maxItems() - 1);
                windows[j].refresh();
                break;
            }
        }
    }

    // Make down/up go from Window_EquipSlot to Window_EquipCommand if current
    // item is last/first:
    Window_EquipSlot.prototype._preAdvancedMenus_cursorDown =
        Window_EquipSlot.prototype.cursorDown;
    Window_EquipSlot.prototype.cursorDown = function(wrap) {
        if (this.index() >= this.maxItems() - 1 && wrap) {
            SoundManager.playCursor();
            this.updateInputData();
            this.deactivate();
            this.callCancelHandler();
            return;
        } else {
            return this._preAdvancedMenus_cursorDown(wrap);
        }
    }
    Window_EquipSlot.prototype._preAdvancedMenus_cursorUp =
        Window_EquipSlot.prototype.cursorUp;
    Window_EquipSlot.prototype.cursorUp = function(wrap) {
        if (this.index() <= 0 && wrap) {
            SoundManager.playCursor();
            this.updateInputData();
            this.deactivate();
            this.callCancelHandler();
            return;
        } else {
            return this._preAdvancedMenus_cursorUp(wrap);
        }
    }

    // Make sure leaving Window_EquipSlot will set a visible focus on the
    // menu Window_EquipCommand (instead of no selection):
    Window_EquipCommand.prototype._preAdvancedMenus_activate =
        Window_EquipCommand.prototype.activate;
    Window_EquipCommand.prototype.activate = function() {
        // make sure Window_ItemList is no longer active:
        var windows = AdvancedMenus.listOfWindows();
        for (var j = 0; j < windows.length; j++) {
            if (Window_ItemList.prototype.isPrototypeOf(windows[j]) &&
                    windows[j].active && windows[j].visible) {
                windows[j].select(-1);
                windows[j].deactivate();
                windows[j]._data = [];
                windows[j].refresh();
                break;
            }
        }

        // ensure visible selection:
        this._preAdvancedMenus_activate();
        if (this._index < 0) {
            this.select(0);
        }
    }

    // Remove "Equip" button from Window_EquipCommand:
    Window_EquipCommand.prototype._preAdvancedMenus_addCommand =
        Window_EquipCommand.prototype.addCommand;
    Window_EquipCommand.prototype.addCommand = function(name, symbol, enabled, ext) {
        if (name == "Equip") {
            return;
        }
        this._preAdvancedMenus_addCommand(name, symbol, enabled, ext);
    }
    // Note: no need to remove space from removal in Window_EquipCommand,
    // since we added the "Back..." button earlier

    // Options menu "Back..." button:
    Window_Options.prototype._preAdvancedMenus_makeCommandList =
        Window_Options.prototype.makeCommandList;
    Window_Options.prototype.makeCommandList = function() {
        this._preAdvancedMenus_makeCommandList();
        this.addCommand(AdvancedMenus.backText, 'cancel', true);
    };

    // Make sure no option value is drawn for the Options menu "Back" button:
    Window_Options.prototype._preAdvancedMenus_statusText =
        Window_Options.prototype.statusText;
    Window_Options.prototype.statusText = function(index) {
        if (this.commandName(index) != AdvancedMenus.backText) {
            return this._preAdvancedMenus_statusText(index);
        }
        return "";
    };

    // Make Options menu "Back" button trigger the escape:
    Window_Options.prototype._preAdvancedMenus_changeValue =
        Window_Options.prototype.changeValue;
    Window_Options.prototype.changeValue = function(symbol, value) {
        if (symbol != "cancel") {
            return this._preAdvancedMenus_changeValue(symbol, value);
        }
        this.playOkSound();
        this.callCancelHandler();
    };

    // Provide a new menu with "Back..." button for the Scene_Status screen:
    function Window_StatusBackButton() {
        this.initialize.apply(this, arguments);
    }

    Window_StatusBackButton.prototype = Object.create(Window_Command.prototype);
    Window_StatusBackButton.prototype.constructor = Window_StatusBackButton;
    Window_StatusBackButton.prototype.initialize = function(x, y) {
        Window_Command.prototype.initialize.call(this, x, y);
        this._margin = 0;
        this._refreshAllParts();
        this.refresh();
    }
    Window_StatusBackButton.prototype.makeCommandList = function() {
        this.addCommand(AdvancedMenus.backText, "cancel", true);
    }

    // Modify Scene_Status to show our "Back..." menu:
    Scene_Status.prototype._preAdvancedMenus_create =
        Scene_Status.prototype.create;
    Scene_Status.prototype.create = function() {
        this._preAdvancedMenus_create();
        // disable focus of actual status window:
        this._statusWindow.deactivate();
        this._statusWindow.refresh();

        // add "Back..." menu on top:
        this._statusWindowBackButton = new Window_StatusBackButton(
            Graphics.width - 240, 0);
        this._statusWindowBackButton.setHandler('cancel',
            this.popScene.bind(this));
        this.addWindow(this._statusWindowBackButton);
    }

    // Provide a new menu with "Cancel..." button for the Scene_EventItem
    // screen:
    function Window_EventItemCancelButton() {
        this.initialize.apply(this, arguments);
    }

    Window_EventItemCancelButton.prototype = Object.create(
        Window_Command.prototype);
    Window_EventItemCancelButton.prototype.constructor =
        Window_EventItemCancelButton;
    Window_EventItemCancelButton.prototype.initialize = function(
            x, y) {
        Window_Command.prototype.initialize.call(this, x, y);
        this._margin = 0;
        this._refreshAllParts();
        this.refresh();
    }
    Window_EventItemCancelButton.prototype.makeCommandList = function() {
        this.addCommand(AdvancedMenus.cancelText, "cancel", true);
    }

    // Make the new "Cancel..." for Window_EventItem cancel the item choice:
    Window_EventItemCancelButton.prototype._activateWhenOutOfFocus =
            function() {
        var x = this.canvasToLocalX(TouchInput.x);
        var y = this.canvasToLocalY(TouchInput.y);
        var hitIndex = this.hitTest(x, y);
        if (hitIndex == 0) {
            var windows = AdvancedMenus.listOfWindows();
            for (var j = 0; j < windows.length; j++) {
                if (Window_EventItem.prototype.isPrototypeOf(windows[j]) &&
                        windows[j].active && windows[j].visible) {
                    windows[j].processCancel();
                    return true;
                }
            }
        }
    }

    // Helper function to adjust the placement of "Cancel..." according to the
    // Window_Message window
    var adjustEventItemCancelButtonPos = function(win) {
        if (typeof(win._eventItemCancelButtonWindow) == "undefined") {
            return;
        }
        var yPos = 0;
        if ((win._y || 0) <= 100) {
            yPos = Math.max(win._y || 0, 0) + Math.max(win._height || 0,
                200);
        }
        var evCancel = win._eventItemCancelButtonWindow;
        evCancel.move(0, yPos, evCancel._width, evCancel._height);
        evCancel._x = 0;
        evCancel._y = yPos;
        evCancel.refresh();
    }
    // When Window_Message moves, move the "Cancel..." too:
    Window_Message.prototype._preAdvancedMenus_move =
        Window_Message.prototype.move;
    Window_Message.prototype.move = function() {
        var retvalue = Window_Message.prototype.
            _preAdvancedMenus_move.apply(
            this, arguments);
        adjustEventItemCancelButtonPos(this);
        return retvalue;
    };
    // When Window_Message is hidden, hide the "Cancel...":
    Window_Message.prototype._preAdvancedMenus_hide =
        Window_Message.prototype.hide;
    Window_Message.prototype.hide = function() {
        var retvalue = Window_Message.prototype.
            _preAdvancedMenus_hide.apply(this, arguments);
        if (typeof(this._eventItemCancelButtonWindow) != "undefined") {
            this._eventItemCancelButtonWindow.deactivate();
            SceneManager._scene._windowLayer.removeChild(
                this._eventItemCancelButtonWindow);
            this._eventItemCancelButtonWindow = undefined;
        }
        return retvalue;
    };
    // When Window_Message is closed, hide the "Cancel...":
    Window_Message.prototype._preAdvancedMenus_close =
        Window_Message.prototype.close;
    Window_Message.prototype.close = function() {
        var retvalue = Window_Message.prototype.
            _preAdvancedMenus_close.apply(this, arguments);
        if (typeof(this._eventItemCancelButtonWindow) != "undefined") {
            this._eventItemCancelButtonWindow.deactivate();
            SceneManager._scene._windowLayer.removeChild(
                this._eventItemCancelButtonWindow);
            this._eventItemCancelButtonWindow = undefined;
        }
        return retvalue;
    };
    // Modify Window_Message's startInput code to show our "Cancel..." menu or
    // to hide it accordingly:
    Window_Message.prototype._preAdvancedMenus_startInput =
        Window_Message.prototype.startInput;
    Window_Message.prototype.startInput = function() {
        var retvalue = Window_Message.prototype.
            _preAdvancedMenus_startInput.apply(this, arguments);
        if (retvalue && !$gameMessage.isItemChoice() &&
                typeof(this._eventItemCancelButtonWindow) != "undefined") {
            this._eventItemCancelButtonWindow.destroy();
            this._eventItemCancelButtonWindow = undefined;
        }
        if (retvalue && $gameMessage.isItemChoice() &&
                typeof(this._eventItemCancelButtonWindow) == "undefined") {
            this._eventItemCancelButtonWindow =
                new Window_EventItemCancelButton(0, 0);
            this._eventItemCancelButtonWindow.show();
            this._eventItemCancelButtonWindow.select(-1);
            this._eventItemCancelButtonWindow.deactivate();
            this._eventItemCancelButtonWindow.refresh();
            SceneManager._scene.addWindow(
                this._eventItemCancelButtonWindow);
            adjustEventItemCancelButtonPos(this);
        }
        return retvalue;
    };
}

// ---- SOUND MANAGER ALTERATIONS TO MUTE TEMPORARILY ----
SoundManager._oldPreAdvancedMenus_playCursor = SoundManager.playCursor;
SoundManager.playCursor = function() {
    if (!AdvancedMenus.menuSoundsMuted) {
        SoundManager._oldPreAdvancedMenus_playCursor();
    }
};

SoundManager._oldPreAdvancedMenus_playOk = SoundManager.playOk;
SoundManager.playOk = function() {
    if (!AdvancedMenus.menuSoundsMuted) {
        SoundManager._oldPreAdvancedMenus_playOk();
    }
};

SoundManager._oldPreAdvancedMenus_playCancel = SoundManager.playCancel;
SoundManager.playCancel = function() {
    if (!AdvancedMenus.menuSoundsMuted) {
        SoundManager._oldPreAdvancedMenus_playCancel();
    }
};

// ---- WINDOW LIST HELPER FUNCTION ----
AdvancedMenus.listOfWindows = function() {
    var debugList = false;
    if (debugList) {
        console.log("");
        console.log("");
        console.log("--- window list ---");
    }
    var windows = [];
    var addChildren = function(win) {
        for (var j = 0; j < win.children.length; j++) {
            windows.push(win.children[j]);
            if (debugList) {
                console.log("Found window:");
                console.log(win.children[j]);
            }
            if (typeof(win.children[j].children) != "undefined") {
                addChildren(win.children[j]);
            }
        }
    }
    addChildren(SceneManager._scene._windowLayer);
    return windows;
}

// ---- SPECIFIC EXISTING MENUS CHANGED TO ALLOW INACTIVE INTERACTION ----

// Fix Scene_Equip sometimes not initializing Window_EquipItem to slot:
Scene_Equip.prototype._preAdvancedMenu_onSlotOk =
    Scene_Equip.prototype.onSlotOk;
Scene_Equip.prototype.onSlotOk = function() {
    this._slotWindow.update();
    return this._preAdvancedMenu_onSlotOk();
};

// Make sure there is no target enemy selection sticking around when leaving
// the targeting menu:
Window_ActorCommand.prototype._preAdvancedMenu_activate =
    Window_ActorCommand.prototype.activate;
Window_ActorCommand.prototype.activate = function() {
    var windows = AdvancedMenus.listOfWindows();
    for (var j = 0; j < windows.length; j++) {
        if (Window_BattleEnemy.prototype.isPrototypeOf(windows[j]) &&
                windows[j].active && windows[j].visible) {    
            windows[j].deactivate();
            windows[j].visible = false;
            break;
        }
    }
    return this._preAdvancedMenu_activate();
}

// Allow clicking ActorCommand while various sub menu popups are open:
Window_ActorCommand.prototype._activateWhenOutOfFocus = function() {
    var windows = AdvancedMenus.listOfWindows();
    // Submenu "Attack":
    for (var j = 0; j < windows.length; j++) {
        if (Window_BattleEnemy.prototype.isPrototypeOf(windows[j]) &&
                windows[j].active && windows[j].visible) {
            windows[j].processCancel();
            return true;
        }
    }
    // Submenu "Items":
    for (var j = 0; j < windows.length; j++) {
        if (Window_ItemList.prototype.isPrototypeOf(windows[j]) &&
                windows[j].active && windows[j].visible) {
            windows[j].processCancel();
            return true;
        }
    }
    // Submenu for any skill:
    for (var j = 0; j < windows.length; j++) {
        if (Window_SkillList.prototype.isPrototypeOf(windows[j]) &&
                windows[j].active && windows[j].visible) {
            windows[j].processCancel();
            return true;
        }
    }
    return false;
}

// Allow clicking specific equpiment slots while Window_EquipCommand (further
// outside) has focus or while Window_EquipSlot (deeper inside) has focus
Window_EquipSlot.prototype._activateWhenOutOfFocus = function() {
    var windows = AdvancedMenus.listOfWindows();
    // clicking when Window_EquipCommand active:
    for (var j = 0; j < windows.length; j++) {
        if (Window_EquipCommand.prototype.isPrototypeOf(windows[j]) &&
                windows[j].active && windows[j].visible) {
            // set the submenu Window_EquipSlot active:
            windows[j].deactivate();
            SceneManager._scene.commandEquip();
            SceneManager._scene.refreshActor();
            if (back_buttons == true) {
                windows[j].select(-1);
            } else {
                windows[j].select(0);
            }
            return true;
        }
    }
    // clicking when Window_EquipSlot active:
    for (var j = 0; j < windows.length; j++) {
        if (Window_EquipItem.prototype.isPrototypeOf(windows[j]) &&
                windows[j].active && windows[j].visible) {
            windows[j].processCancel(); 
            return true;
        }
    }
    return false;
}

// Allow clicking Window_EquipCommand while deeper inside the equip submenus
Window_EquipCommand.prototype._activateWhenOutOfFocus = function() {
    // Back out of item list:
    var windows = AdvancedMenus.listOfWindows();
    for (var j = 0; j < windows.length; j++) {
        if (Window_ItemList.prototype.isPrototypeOf(windows[j]) &&
                windows[j].active && windows[j].visible) {
            windows[j].processCancel();
            windows[j].select(-1);
            windows[j].deactivate();
        }
    }

    // Back out of having selected a specific equipment slot: 
    var windows = AdvancedMenus.listOfWindows();
    for (var j = 0; j < windows.length; j++) {
        if (Window_EquipSlot.prototype.isPrototypeOf(windows[j]) &&
                windows[j].active && windows[j].visible) {
            windows[j].processCancel();
            return true;
        }
    }
    return false;
}

// Allow changing from buy to sell or back, while somewhere in the submenus:
Window_ShopCommand.prototype._activateWhenOutOfFocus = function() {
    var windows = AdvancedMenus.listOfWindows();
    // SELL/BUY: exit number quantity screen for detail sell/buy if opened:
    for (var j = 0; j < windows.length; j++) {
        if (Window_ShopNumber.prototype.isPrototypeOf(windows[j]) &&
                windows[j].active && windows[j].visible) {
            windows[j].processCancel();
            break;
        }
    }
    // BUY: close buy list if opened:
    for (var j = 0; j < windows.length; j++) {
        if (Window_ShopBuy.prototype.isPrototypeOf(windows[j]) &&
                windows[j].active && windows[j].visible) {
            windows[j].processCancel();
            return true;
        }
    }
    // SELL: first, close inner item list window if found:
    for (var j = 0; j < windows.length; j++) {
        if (Window_ItemList.prototype.isPrototypeOf(windows[j]) &&
                windows[j].active && windows[j].visible) {
            windows[j].processCancel();
            break;
        }
    }
    // SELL: if we find an active item category menu, back out and done
    for (var j = 0; j < windows.length; j++) {
        if (Window_ItemCategory.prototype.isPrototypeOf(windows[j]) &&
                windows[j].active && windows[j].visible) {
            windows[j].processCancel();
            return true;
        }
    }
    return false;
}

// Allow changing skill category while in the skill details list:
Window_SkillType.prototype._activateWhenOutOfFocus = function() {
    // If skill list is open and Window_MenuActor is active, we are in the
    // item use target selection -> back out
    var windows = AdvancedMenus.listOfWindows();
    var inSkillList = false;
    for (var j = 0; j < windows.length; j++) {
        if (Window_SkillList.prototype.isPrototypeOf(windows[j]) &&
                windows[j].visible) {
            inSkillList = true;
        }
    }
    if (inSkillList) {
        for (var j = 0; j < windows.length; j++) {
            if (Window_MenuActor.prototype.isPrototypeOf(windows[j]) &&
                    windows[j].active && windows[j].visible) {
                windows[j].processCancel();
                windows[j].select(-1);
                windows[j].deactivate();
                break;
            }
        }
    }

    // Back out of SkillList when active:
    var windows = AdvancedMenus.listOfWindows();
    for (var j = 0; j < windows.length; j++) {
        if (Window_SkillList.prototype.isPrototypeOf(windows[j]) &&
                windows[j].active && windows[j].visible) {
            windows[j].processCancel();
            return true;
        }
    }
    return false;
}

// Allow changing game menu category while Window_MenuStatus selection active:
Window_MenuCommand.prototype._activateWhenOutOfFocus = function() {
    var windows = AdvancedMenus.listOfWindows();
    for (var j = 0; j < windows.length; j++) {
        if (Window_MenuStatus.prototype.isPrototypeOf(windows[j]) &&
                windows[j].visible && windows[j].active) {
            windows[j].processCancel();
            return true;
        }
    }
    return false;
}

// Allow changing ItemCategory while the ItemList is active:
Window_ItemCategory.prototype._activateWhenOutOfFocus = function() {
    // If item list is open and Window_MenuActor is active, we are in the
    // item use target selection -> back out, but only if clicking
    // at the left-most button.
    var x = this.canvasToLocalX(TouchInput.x);
    var y = this.canvasToLocalY(TouchInput.y);
    var hitIndex = this.hitTest(x, y);
    if (hitIndex == 0) {
        var windows = AdvancedMenus.listOfWindows();
        var inItemList = false;
        for (var j = 0; j < windows.length; j++) {
            if (Window_ItemList.prototype.isPrototypeOf(windows[j]) &&
                    windows[j].visible) {
                inItemList = true;
            }
        }
        if (inItemList) {
            for (var j = 0; j < windows.length; j++) {
                if (Window_MenuActor.prototype.isPrototypeOf(windows[j]) &&
                        windows[j].active && windows[j].visible) {
                    windows[j].processCancel();
                    windows[j].select(-1);
                    windows[j].deactivate();
                    break;
                }
            }
        }
    }

    // Make sure the item use target choice isn't open:
    var windows = AdvancedMenus.listOfWindows();
    for (var j = 0; j < windows.length; j++) {
        if (Window_MenuActor.prototype.isPrototypeOf(windows[j]) &&
                windows[j].visible) {
            return false;
        }
    }

    // Close item list so we can change category:
    for (var j = 0; j < windows.length; j++) {
        if (Window_ItemList.prototype.isPrototypeOf(windows[j])
                && windows[j].active && windows[j].visible) {
            windows[j].processCancel();
            return true;
        }
    }
    return false;
}

// Fix the displayed item help sometimes getting surprised by our changes:
Window_ItemCategory.prototype.processTouch = function() {
    Window_Selectable.prototype.processTouch.apply(this, []);
    // make sure the item help display follows our changes:
    var windows = AdvancedMenus.listOfWindows();
    for (var j = 0; j < windows.length; j++) {
        if (Window_ItemList.prototype.isPrototypeOf(windows[j])) {
            windows[j].updateHelp();
        }
    }
}

// Fix the displayed menu help sometimes getting surprised by our changes:
Window_SkillType.prototype.processTouch = function() {
    Window_Selectable.prototype.processTouch.apply(this, []);
    // make sure the item help display follows our changes:
    var windows = AdvancedMenus.listOfWindows();
    for (var j = 0; j < windows.length; j++) {
        if (Window_SkillList.prototype.isPrototypeOf(windows[j])
                && windows[j].visible && windows[j].active) {
            windows[j].updateHelp();
        }
    }
}

// ---- GENERAL CODE FOR ONE-CLICK NAVIGATION AND INACTIVE INTERACTION ----

// Allow activating menus that aren't active if this._activateWhenOutOfFocus
// is defined on them:
Window_Selectable.prototype.processTouch = function() {
    if (this.isOpenAndActive() ||
            typeof(this._activateWhenOutOfFocus) != "undefined") {
        if (TouchInput.isTriggered() && this.isTouchedInsideFrame()) {
            this._touching = true;
            this.onTouch(true);
        } else if (TouchInput.isCancelled()) {
            if (this.isCancelEnabled() && this.isOpenAndActive()) {
                this.processCancel();
            }
        }
        if (this._touching) {
            if (TouchInput.isPressed()) {
                this.onTouch(false);
            } else {
                this._touching = false;
            }
        }
    } else {
        this._touching = false;
    }
};

// Allow confirming menus with just one mouse click and possibly to click 
// when menu is inactive:
Window_Selectable.prototype.onTouch = function(triggered) {
    var lastIndex = this.index();
    var x = this.canvasToLocalX(TouchInput.x);
    var y = this.canvasToLocalY(TouchInput.y);
    var hitIndex = this.hitTest(x, y);
    var muteSelect = false;
    var self = this;
    var menuHasSelectInfo = function() {
        if (Window_EquipItem.prototype.isPrototypeOf(self)) {
            return true;
        }
        if (Window_SkillList.prototype.isPrototypeOf(self)) {
            return true;
        }
        if (Window_ItemList.prototype.isPrototypeOf(self)) {
            return true;
        }
        return false;
    }
    var tryActivate = function() {
        if (self.isOpenAndActive()) {
            // console.log("tryActivate: ALLOW IN FOCUS");
            return true;
        }
        AdvancedMenus.menuSoundsMuted = true;
        if (typeof(self._activateWhenOutOfFocus) != "undefined"
                && self._activateWhenOutOfFocus()) {
            AdvancedMenus.menuSoundsMuted = false;
            // console.log("tryActivate: ALLOW OUT OF FOCUS");
            return true;
        }
        AdvancedMenus.menuSoundsMuted = false;
        // console.log("tryActivate: DISALLOW");
        return false;
    }
    if (hitIndex >= 0) {
        if (hitIndex === this.index()) {
            if (triggered && this.isTouchOkEnabled()) {
                if (tryActivate()) {
                    this.processOk();
                    return;
                }
            }
        } else if (this.isCursorMovable() ||
                typeof(this._activateWhenOutOfFocus) != "undefined") {
            if (!tryActivate()) {
                return;
            }
            this.select(hitIndex);
            // Allow direct click unless it matches a few well-known menus
            // with per-selection descriptions:
            if (!menuHasSelectInfo()) {
                if (triggered && this.isTouchOkEnabled()) {
                    muteSelect = true;
                    this.processOk();
                }
            }
        }
    } else if (this._stayCount >= 10) {
        if (y < this.padding) {
            if (tryActivate()) {
                this.cursorUp();
            }
        } else if (y >= this.height - this.padding) {
            if (tryActivate()) {
                this.cursorDown();
            }
        }
    }
    if (this.index() !== lastIndex && !muteSelect) {
        SoundManager.playCursor();
    }
};

})();





Changelog:


1.0.0 - 12/6/2015 Initial release


1.0.1 - 12/19/2015 Added support for clicking "Back..." inside the use item/use skill on party member menus, and added a clickable "Cancel..." button for the item chooser dialog which can be triggered through a map event

1.0.3 - 25/03/2017 Incorporate changes by @BigTaro which allow Cancel.../Back... to have configurable texts (plugin options) and which moves them to the bottom. Fix "Choices" window positioning being broken by plugin. Fix selection & activation sound playing both when clicking unselected menu entries
 
Last edited:

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,600
Reaction score
2,360
First Language
French
Primarily Uses
it's nice :o but I would put that in a pastebin link lol!
 

orlando

Veteran
Veteran
Joined
May 24, 2014
Messages
177
Reaction score
84
I just fixed a tiny issue (purely visual) I hadn't noticed before: when back buttons are disabled in the plugin settings (default is true), the "Equip" button on the Equip screen will sometimes not be properly shown as selected when an equipment slot is clicked.


This is now fixed.


Since this plugin touches so many menus, there will probably be some other oddities. If you find any, please report them!
 
Last edited by a moderator:

djDarkX

Retro & Remastered Music Guru
Veteran
Joined
Jan 17, 2013
Messages
2,699
Reaction score
1,889
First Language
Music
Primarily Uses
RMMV
I agree with nio here, plus it's part of the forum rules for this board.  Please put the code either in a spoiler tag:

Content
Or post it to pastebin.  Or you could also just save it in a text editor to a .js file and upload it to either Mediafire or Dropbox.  Most people are turned off to that large block of code in a thread.
 

demonsword

Warper
Member
Joined
Jul 31, 2015
Messages
3
Reaction score
0
First Language
english
Primarily Uses
Thanks for this great plugin, Blubberblub. I love it and I'm currently using it in one of my projects because two finger tap is just effin' terrible.

However, I do have one question:

The "Back..." menu command doesn't seem to function (or even appear depending on other plugins) when using an Item or Skill from the menu screen (as opposed to in combat). Is there a way to extend this plugin's functionality to those two screens?

Thanks ahead either way.
 

orlando

Veteran
Veteran
Joined
May 24, 2014
Messages
177
Reaction score
84
You mean when selecting an Item or Skill category, then selecting an Item or Skill, and then being in the selection of the target party member to whom to apply the item/skill and wanting to abort?


Yea, that's an oversight. Will fix ASAP, give me half an hour :)


Edit: I released a new version now, 1.0.1. It makes "Back..." clickable inside the use item/use skill subdialogs in the inventory where you are supposed to pick a party member to use it on, and it adds a "Cancel..." button for the item chooser dialog which can be triggered from map events e.g. for locked doors and such (Window_EventItem).
 
Last edited by a moderator:

demonsword

Warper
Member
Joined
Jul 31, 2015
Messages
3
Reaction score
0
First Language
english
Primarily Uses
You are awesome!!!  TYVM for the fix.    :rock-left:   :D   :rock-right:
 

demonsword

Warper
Member
Joined
Jul 31, 2015
Messages
3
Reaction score
0
First Language
english
Primarily Uses
Hey Orlando, I've been playing with this plugin again and I've got a new question:
Any idea why it would frequently crash the game with the following error message whenever a Show Choices dialogue is called?


TypeError


Cannot read property 'destroy' of undefined


 


I've tried disabling all other plugins, but I still usually get this issue when choices try to load. 
 

NeoPGX

~ King of Cuteness ~
Veteran
Joined
May 15, 2014
Messages
785
Reaction score
89
First Language
English (US)
Primarily Uses
N/A
Please put this code in a JS file and upload it to pastebin or something.
 

EnMod

noelquiles.com
Veteran
Joined
Oct 28, 2015
Messages
24
Reaction score
3
First Language
English
Primarily Uses
Please put this code in a JS file and upload it to pastebin or something.


Agreed.  I can't update the 1.0.0 version as it is just too time-consuming to have to reformat the line of code that is in the OP.  Please paste to a pastebin.
 

NeoPGX

~ King of Cuteness ~
Veteran
Joined
May 15, 2014
Messages
785
Reaction score
89
First Language
English (US)
Primarily Uses
N/A
Agreed.  I can't update the 1.0.0 version as it is just too time-consuming to have to reformat the line of code that is in the OP.  Please paste to a pastebin.


Of course this wasn't an issue before the forum update. Oh well.

As useful as this plugin sounds, I doubt anyone is going to waste their time trying to reformat the code themselves. I personally have better things to do. 
 

kovak

Silverguard
Veteran
Joined
Apr 3, 2016
Messages
1,253
Reaction score
1,558
First Language
PT - EN
Primarily Uses
RMMV
I see no difference wile using this plugin and i've tested it on a new project.
What's wrong with what i'm doing?
 

NeoPGX

~ King of Cuteness ~
Veteran
Joined
May 15, 2014
Messages
785
Reaction score
89
First Language
English (US)
Primarily Uses
N/A
I see no difference wile using this plugin and i've tested it on a new project.
What's wrong with what i'm doing?

The plugin does not work in its current state due to how the code is formatted. This is due to how the updates to the forum changed everything.
 

orlando

Veteran
Veteran
Joined
May 24, 2014
Messages
177
Reaction score
84
Sorry folks, formatting is fixed now. Bad forum, bad! (on the other hand, the spoiler tag seems to be disfunctional now. Why is this forum so buggy?)

Hey Orlando, I've been playing with this plugin again and I've got a new question:
Any idea why it would frequently crash the game with the following error message whenever a Show Choices dialogue is called?


TypeError


Cannot read property 'destroy' of undefined


 


I've tried disabling all other plugins, but I still usually get this issue when choices try to load. 


Does this happen in a minimal test project without other plugins? I tested around myself, but I can't manage to make that error happen.
 

BigTaro

Villager
Member
Joined
Dec 22, 2012
Messages
12
Reaction score
6
First Language
English
Primarily Uses
Awesome script.  I modified the script a bit for my liking, and I am posting the changed version below.  I modified the following:


 - Back and Cancel buttons can now have user configurable text via plugin options.


 - Moved the back item to the end of each menu instead of the beginning.  It looks nicer in my opinion.


 - Bumped the version to 1.0.2

Code:
// Advanced Menus
// by orlando (rpgmakerweb.com forums)
// Date: 12/19/2015
// Modified on 6/1/2016 by BigTaro (rpgmakerweb.com forums)

var Imported = Imported || {};
Imported.AdvancedMenus = "1.0.2";

// LICENSE PLEASE READ:
// ====================
//
// Copyright (C) 2015 orlando (rpgmakerweb.com forums)
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
//    claim that you wrote the original software. If you use this software
//    in a product, an acknowledgement in the product documentation would be
//    appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
//    misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.

//===========================================================================


/*:
 * @plugindesc 1.0.2 Advanced Menus to fix countless details with mouse/touch navigation   id:AdvancedMenus
 *
 * @param Add back buttons
 * @desc Alter common menus to include back buttons. Disable if you use any plugin that does intrusive modifications to the ingame menu
 * @default true
 *
 * @param Back Text
 * @desc The text used for the back buttons
 * @default Back...
 *
 * @param Cancel Text
 * @desc The text used for the item change cancel button
 * @default Cancel...
 *
 * @author orlando (rpgmakerweb.com forums)
 */

(function() {

var parameters = $plugins.filter(function(p){return p.description.contains("id:AdvancedMenus")})[0].parameters;
var back_buttons = Boolean((parameters['Add back buttons'] === 'true') || false);
var back_text = String(parameters['Back Text']);
var cancel_text = String(parameters['Cancel Text']);

AdvancedMenus = function() {
    throw("this is a static class");
}

AdvancedMenus.menuSoundsMuted = false;
AdvancedMenus.backText = back_text;
AdvancedMenus.cancelText = cancel_text;

// ---- SPECIFIC MENUS EXPANDED TO HAVE A BACK BUTTON (IF ENABLED) ----

if (back_buttons) {
    // Window_ItemCategory "Back..." button:
    Window_ItemCategory.prototype._preAdvancedMenus_makeCommandList =
        Window_ItemCategory.prototype.makeCommandList;
    Window_ItemCategory.prototype.makeCommandList = function() {
        // Detect if we are inside a shop. If yes, don't add "Back...":
        var is_shop = false;
        var windows = AdvancedMenus.listOfWindows();
        for (var j = 0; j < windows.length; j++) {
            if (Window_ShopCommand.prototype.isPrototypeOf(windows[j])) {
                is_shop = true;
                break;
            }
        }

        this._preAdvancedMenus_makeCommandList();
		
        // Add if not a shop:
        if (!is_shop) {
            this.addCommand(AdvancedMenus.backText, 'cancel');
        }
		
    };

    // Make room for back button in Window_ItemCategory:
    Window_ItemCategory.prototype._preAdvancedMenus_maxCols =
        Window_ItemCategory.prototype.maxCols;
    Window_ItemCategory.prototype.maxCols = function() {
        // Detect if we are inside a shop. If yes, nothing needs to be added:
        var is_shop = false;
        var windows = AdvancedMenus.listOfWindows();
        for (var j = 0; j < windows.length; j++) {
            if (Window_ShopCommand.prototype.isPrototypeOf(windows[j])) {
                is_shop = true;
                break;
            }
        }
        if (is_shop) {
            return this._preAdvancedMenus_maxCols();
        } else {
            return this._preAdvancedMenus_maxCols() + 1;
        }
    };

    // Window_SkillType "Back..." button:
    Window_SkillType.prototype._preAdvancedMenus_makeCommandList =
        Window_SkillType.prototype.makeCommandList;
    Window_SkillType.prototype.makeCommandList = function() {

        this._preAdvancedMenus_makeCommandList();
		
        if (this._actor) {
            this.addCommand(AdvancedMenus.backText, 'cancel');
        }
		
    };

    // Main command list "Back..." button:
    Window_MenuCommand.prototype._preAdvancedMenus_makeCommandList =
        Window_MenuCommand.prototype.makeCommandList;
    Window_MenuCommand.prototype.makeCommandList = function() {

        this._preAdvancedMenus_makeCommandList();
		this.addCommand(AdvancedMenus.backText, 'cancel', true);
		
    };

    // Window_EquipCommand "Back..." button:
    Window_EquipCommand.prototype._preAdvancedMenus_makeCommandList =
        Window_EquipCommand.prototype.makeCommandList;
    Window_EquipCommand.prototype.makeCommandList = function() {
        this._preAdvancedMenus_makeCommandList();
        this.addCommand(AdvancedMenus.backText, 'cancel');
    };
    // Note: no need to make room for back button in Window_EquipCommand,
    // since we remove the "Equip" button later

    // Make down/up go from Window_EquipCommand to Window_EquipSlot
    Window_EquipCommand.prototype._preAdvancedMenus_cursorDown =
        Window_EquipCommand.prototype.cursorDown;
    Window_EquipCommand.prototype.cursorDown = function() {
        this.select(-1);
        SoundManager.playCursor();
        this.updateInputData();
        this.deactivate();
        SceneManager._scene.commandEquip();
    }
    Window_EquipCommand.prototype._preAdvancedMenus_cursorUp =
        Window_EquipCommand.prototype.cursorUp;
    Window_EquipCommand.prototype.cursorUp = function() {
        this.select(-1);
        SoundManager.playCursor();
        this.updateInputData();
        this.deactivate();
        SceneManager._scene.commandEquip();
        // make sure last item is selected in Window_EquipSlot:
        var windows = AdvancedMenus.listOfWindows();
        for (var j = 0; j < windows.length; j++) {
            if (Window_EquipSlot.prototype.isPrototypeOf(windows[j])) {
                windows[j].select(windows[j].maxItems() - 1);
                windows[j].refresh();
                break;
            }
        }
    }

    // Make down/up go from Window_EquipSlot to Window_EquipCommand if current
    // item is last/first:
    Window_EquipSlot.prototype._preAdvancedMenus_cursorDown =
        Window_EquipSlot.prototype.cursorDown;
    Window_EquipSlot.prototype.cursorDown = function(wrap) {
        if (this.index() >= this.maxItems() - 1 && wrap) {
            SoundManager.playCursor();
            this.updateInputData();
            this.deactivate();
            this.callCancelHandler();
            return;
        } else {
            return this._preAdvancedMenus_cursorDown(wrap);
        }
    }
    Window_EquipSlot.prototype._preAdvancedMenus_cursorUp =
        Window_EquipSlot.prototype.cursorUp;
    Window_EquipSlot.prototype.cursorUp = function(wrap) {
        if (this.index() <= 0 && wrap) {
            SoundManager.playCursor();
            this.updateInputData();
            this.deactivate();
            this.callCancelHandler();
            return;
        } else {
            return this._preAdvancedMenus_cursorUp(wrap);
        }
    }

    // Make sure leaving Window_EquipSlot will set a visible focus on the
    // menu Window_EquipCommand (instead of no selection):
    Window_EquipCommand.prototype._preAdvancedMenus_activate =
        Window_EquipCommand.prototype.activate;
    Window_EquipCommand.prototype.activate = function() {
        // make sure Window_ItemList is no longer active:
        var windows = AdvancedMenus.listOfWindows();
        for (var j = 0; j < windows.length; j++) {
            if (Window_ItemList.prototype.isPrototypeOf(windows[j]) &&
                    windows[j].active && windows[j].visible) {
                windows[j].select(-1);
                windows[j].deactivate();
                windows[j]._data = [];
                windows[j].refresh();
                break;
            }
        }

        // ensure visible selection:
        this._preAdvancedMenus_activate();
        if (this._index < 0) {
            this.select(0);
        }
    }

    // Remove "Equip" button from Window_EquipCommand:
    Window_EquipCommand.prototype._preAdvancedMenus_addCommand =
        Window_EquipCommand.prototype.addCommand;
    Window_EquipCommand.prototype.addCommand = function(name, symbol, enabled, ext) {
        if (name == "Equip") {
            return;
        }
        this._preAdvancedMenus_addCommand(name, symbol, enabled, ext);
    }
    // Note: no need to remove space from removal in Window_EquipCommand,
    // since we added the "Back..." button earlier

    // Options menu "Back..." button:
    Window_Options.prototype._preAdvancedMenus_makeCommandList =
        Window_Options.prototype.makeCommandList;
    Window_Options.prototype.makeCommandList = function() {
        this._preAdvancedMenus_makeCommandList();
        this.addCommand(AdvancedMenus.backText, 'cancel', true);
    };

    // Make sure no option value is drawn for the Options menu "Back" button:
    Window_Options.prototype._preAdvancedMenus_statusText =
        Window_Options.prototype.statusText;
    Window_Options.prototype.statusText = function(index) {
        if (this.commandName(index) != AdvancedMenus.backText) {
            return this._preAdvancedMenus_statusText(index);
        }
        return "";
    };

    // Make Options menu "Back" button trigger the escape:
    Window_Options.prototype._preAdvancedMenus_changeValue =
        Window_Options.prototype.changeValue;
    Window_Options.prototype.changeValue = function(symbol, value) {
        if (symbol != "cancel") {
            return this._preAdvancedMenus_changeValue(symbol, value);
        }
        this.playOkSound();
        this.callCancelHandler();
    };

    // Provide a new menu with "Back..." button for the Scene_Status screen:
    function Window_StatusBackButton() {
        this.initialize.apply(this, arguments);
    }

    Window_StatusBackButton.prototype = Object.create(Window_Command.prototype);
    Window_StatusBackButton.prototype.constructor = Window_StatusBackButton;
    Window_StatusBackButton.prototype.initialize = function(x, y) {
        Window_Command.prototype.initialize.call(this, x, y);
        this._margin = 0;
        this._refreshAllParts();
        this.refresh();
    }
    Window_StatusBackButton.prototype.makeCommandList = function() {
        this.addCommand(AdvancedMenus.backText, "cancel", true);
    }

    // Modify Scene_Status to show our "Back..." menu:
    Scene_Status.prototype._preAdvancedMenus_create =
        Scene_Status.prototype.create;
    Scene_Status.prototype.create = function() {
        this._preAdvancedMenus_create();
        // disable focus of actual status window:
        this._statusWindow.deactivate();
        this._statusWindow.refresh();

        // add "Back..." menu on top:
        this._statusWindowBackButton = new Window_StatusBackButton(
            Graphics.width - 240, 0);
        this._statusWindowBackButton.setHandler('cancel',
            this.popScene.bind(this));
        this.addWindow(this._statusWindowBackButton);
    }

    // Provide a new menu with "Cancel..." button for the Scene_EventItem
    // screen:
    function Window_EventItemCancelButton() {
        this.initialize.apply(this, arguments);
    }

    Window_EventItemCancelButton.prototype = Object.create(
        Window_Command.prototype);
    Window_EventItemCancelButton.prototype.constructor =
        Window_EventItemCancelButton;
    Window_EventItemCancelButton.prototype.initialize = function(
            x, y) {
        Window_Command.prototype.initialize.call(this, x, y);
        this._margin = 0;
        this._refreshAllParts();
        this.refresh();
    }
    Window_EventItemCancelButton.prototype.makeCommandList = function() {
        this.addCommand(AdvancedMenus.cancelText, "cancel", true);
    }

    // Make the new "Cancel..." for Window_EventItem cancel the item choice:
    Window_EventItemCancelButton.prototype._activateWhenOutOfFocus =
            function() {
        var x = this.canvasToLocalX(TouchInput.x);
        var y = this.canvasToLocalY(TouchInput.y);
        var hitIndex = this.hitTest(x, y);
        if (hitIndex == 0) {
            var windows = AdvancedMenus.listOfWindows();
            for (var j = 0; j < windows.length; j++) {
                if (Window_EventItem.prototype.isPrototypeOf(windows[j]) &&
                        windows[j].active && windows[j].visible) {
                    windows[j].processCancel();
                    return true;
                }
            }
        }
    }

    // Helper function to adjust the placement of "Cancel..." according to the
    // Window_Message window
    var adjustEventItemCancelButtonPos = function(win) {
        if (typeof(win._eventItemCancelButtonWindow) == "undefined") {
            return;
        }
        var yPos = 0;
        if ((win._y || 0) <= 100) {
            yPos = Math.max(win._y || 0, 0) + Math.max(win._height || 0,
                200);
        }
        var evCancel = win._eventItemCancelButtonWindow;
        evCancel.move(0, yPos, evCancel._width, evCancel._height);
        evCancel._x = 0;
        evCancel._y = yPos;
        evCancel.refresh();
    }
    // When Window_Message moves, move the "Cancel..." too:
    Window_Message.prototype._preAdvancedMenus_move =
        Window_Message.prototype.move;
    Window_Message.prototype.move = function(x, y) {
        var retval = this._preAdvancedMenus_move(x, y);
        adjustEventItemCancelButtonPos(this);
        return retval;
    }
    // When Window_Message is hidden, hide the "Cancel...":
    Window_Message.prototype._preAdvancedMenus_hide =
        Window_Message.prototype.hide;
    Window_Message.prototype.hide = function() {
        this._preAdvancedMenus_hide();
        if (typeof(this._eventItemCancelButtonWindow) != "undefined") {
            this._eventItemCancelButtonWindow.deactivate();
            SceneManager._scene._windowLayer.removeChild(
                this._eventItemCancelButtonWindow);
            this._eventItemCancelButtonWindow = undefined;
        }
    }
    // When Window_Message is closed, hide the "Cancel...":
    Window_Message.prototype._preAdvancedMenus_close =
        Window_Message.prototype.close;
    Window_Message.prototype.close = function() {
        this._preAdvancedMenus_close();
        if (typeof(this._eventItemCancelButtonWindow) != "undefined") {
            this._eventItemCancelButtonWindow.deactivate();
            SceneManager._scene._windowLayer.removeChild(
                this._eventItemCancelButtonWindow);
            this._eventItemCancelButtonWindow = undefined;
        }
    }
    // Modify Window_Message's startInput code to show our "Cancel..." menu or
    // to hide it accordingly:
    Window_Message.prototype._preAdvancedMenus_startInput =
        Window_Message.prototype.startInput;
    Window_Message.prototype.startInput = function() {
        var retvalue = this._preAdvancedMenus_startInput();
	if (retvalue && !$gameMessage.isItemChoice() &&
                typeof(this._eventItemCancelButtonWindow) != "undefined") {
            this._eventItemCancelButtonWindow.destroy();
            this._eventItemCancelButtonWindow = undefined;
        }
        if (retvalue && $gameMessage.isItemChoice() &&
                typeof(this._eventItemCancelButtonWindow) == "undefined") {
            this._eventItemCancelButtonWindow =
                new Window_EventItemCancelButton(0, 0);
            this._eventItemCancelButtonWindow.show();
            this._eventItemCancelButtonWindow.select(-1);
            this._eventItemCancelButtonWindow.deactivate();
            this._eventItemCancelButtonWindow.refresh();
            SceneManager._scene.addWindow(
                this._eventItemCancelButtonWindow);
            adjustEventItemCancelButtonPos(this);
        }
        return retvalue;
    };
}

// ---- SOUND MANAGER ALTERATIONS TO MUTE TEMPORARILY ----
SoundManager._oldPreAdvancedMenus_playCursor = SoundManager.playCursor;
SoundManager.playCursor = function() {
    if (!AdvancedMenus.menuSoundsMuted) {
        SoundManager._oldPreAdvancedMenus_playCursor();
    }
};

SoundManager._oldPreAdvancedMenus_playOk = SoundManager.playOk;
SoundManager.playOk = function() {
    if (!AdvancedMenus.menuSoundsMuted) {
        SoundManager._oldPreAdvancedMenus_playOk();
    }
};

SoundManager._oldPreAdvancedMenus_playCancel = SoundManager.playCancel;
SoundManager.playCancel = function() {
    if (!AdvancedMenus.menuSoundsMuted) {
        SoundManager._oldPreAdvancedMenus_playCancel();
    }
};

// ---- WINDOW LIST HELPER FUNCTION ----
AdvancedMenus.listOfWindows = function() {
    var debugList = false;
    if (debugList) {
        console.log("");
        console.log("");
        console.log("--- window list ---");
    }
    var windows = [];
    var addChildren = function(win) {
        for (var j = 0; j < win.children.length; j++) {
            windows.push(win.children[j]);
            if (debugList) {
                console.log("Found window:");
                console.log(win.children[j]);
            }
            if (typeof(win.children[j].children) != "undefined") {
                addChildren(win.children[j]);
            }
        }
    }
    addChildren(SceneManager._scene._windowLayer);
    return windows;
}

// ---- SPECIFIC EXISTING MENUS CHANGED TO ALLOW INACTIVE INTERACTION ----

// Fix Scene_Equip sometimes not initializing Window_EquipItem to slot:
Scene_Equip.prototype._preAdvancedMenu_onSlotOk =
    Scene_Equip.prototype.onSlotOk;
Scene_Equip.prototype.onSlotOk = function() {
    this._slotWindow.update();
    return this._preAdvancedMenu_onSlotOk();
};

// Make sure there is no target enemy selection sticking around when leaving
// the targeting menu:
Window_ActorCommand.prototype._preAdvancedMenu_activate =
    Window_ActorCommand.prototype.activate;
Window_ActorCommand.prototype.activate = function() {
    var windows = AdvancedMenus.listOfWindows();
    for (var j = 0; j < windows.length; j++) {
        if (Window_BattleEnemy.prototype.isPrototypeOf(windows[j]) &&
                windows[j].active && windows[j].visible) {    
            windows[j].deactivate();
            windows[j].visible = false;
            break;
        }
    }
    return this._preAdvancedMenu_activate();
}

// Allow clicking ActorCommand while various sub menu popups are open:
Window_ActorCommand.prototype._activateWhenOutOfFocus = function() {
    var windows = AdvancedMenus.listOfWindows();
    // Submenu "Attack":
    for (var j = 0; j < windows.length; j++) {
        if (Window_BattleEnemy.prototype.isPrototypeOf(windows[j]) &&
                windows[j].active && windows[j].visible) {
            windows[j].processCancel();
            return true;
        }
    }
    // Submenu "Items":
    for (var j = 0; j < windows.length; j++) {
        if (Window_ItemList.prototype.isPrototypeOf(windows[j]) &&
                windows[j].active && windows[j].visible) {
            windows[j].processCancel();
            return true;
        }
    }
    // Submenu for any skill:
    for (var j = 0; j < windows.length; j++) {
        if (Window_SkillList.prototype.isPrototypeOf(windows[j]) &&
                windows[j].active && windows[j].visible) {
            windows[j].processCancel();
            return true;
        }
    }
    return false;
}

// Allow clicking specific equpiment slots while Window_EquipCommand (further
// outside) has focus or while Window_EquipSlot (deeper inside) has focus
Window_EquipSlot.prototype._activateWhenOutOfFocus = function() {
    var windows = AdvancedMenus.listOfWindows();
    // clicking when Window_EquipCommand active:
    for (var j = 0; j < windows.length; j++) {
        if (Window_EquipCommand.prototype.isPrototypeOf(windows[j]) &&
                windows[j].active && windows[j].visible) {
            // set the submenu Window_EquipSlot active:
            windows[j].deactivate();
            SceneManager._scene.commandEquip();
            SceneManager._scene.refreshActor();
            if (back_buttons == true) {
                windows[j].select(-1);
            } else {
                windows[j].select(0);
            }
            return true;
        }
    }
    // clicking when Window_EquipSlot active:
    for (var j = 0; j < windows.length; j++) {
        if (Window_EquipItem.prototype.isPrototypeOf(windows[j]) &&
                windows[j].active && windows[j].visible) {
            windows[j].processCancel(); 
            return true;
        }
    }
    return false;
}

// Allow clicking Window_EquipCommand while deeper inside the equip submenus
Window_EquipCommand.prototype._activateWhenOutOfFocus = function() {
    // Back out of item list:
    var windows = AdvancedMenus.listOfWindows();
    for (var j = 0; j < windows.length; j++) {
        if (Window_ItemList.prototype.isPrototypeOf(windows[j]) &&
                windows[j].active && windows[j].visible) {
            windows[j].processCancel();
            windows[j].select(-1);
            windows[j].deactivate();
        }
    }

    // Back out of having selected a specific equipment slot: 
    var windows = AdvancedMenus.listOfWindows();
    for (var j = 0; j < windows.length; j++) {
        if (Window_EquipSlot.prototype.isPrototypeOf(windows[j]) &&
                windows[j].active && windows[j].visible) {
            windows[j].processCancel();
            return true;
        }
    }
    return false;
}

// Allow changing from buy to sell or back, while somewhere in the submenus:
Window_ShopCommand.prototype._activateWhenOutOfFocus = function() {
    var windows = AdvancedMenus.listOfWindows();
    // SELL/BUY: exit number quantity screen for detail sell/buy if opened:
    for (var j = 0; j < windows.length; j++) {
        if (Window_ShopNumber.prototype.isPrototypeOf(windows[j]) &&
                windows[j].active && windows[j].visible) {
            windows[j].processCancel();
            break;
        }
    }
    // BUY: close buy list if opened:
    for (var j = 0; j < windows.length; j++) {
        if (Window_ShopBuy.prototype.isPrototypeOf(windows[j]) &&
                windows[j].active && windows[j].visible) {
            windows[j].processCancel();
            return true;
        }
    }
    // SELL: first, close inner item list window if found:
    for (var j = 0; j < windows.length; j++) {
        if (Window_ItemList.prototype.isPrototypeOf(windows[j]) &&
                windows[j].active && windows[j].visible) {
            windows[j].processCancel();
            break;
        }
    }
    // SELL: if we find an active item category menu, back out and done
    for (var j = 0; j < windows.length; j++) {
        if (Window_ItemCategory.prototype.isPrototypeOf(windows[j]) &&
                windows[j].active && windows[j].visible) {
            windows[j].processCancel();
            return true;
        }
    }
    return false;
}

// Allow changing skill category while in the skill details list:
Window_SkillType.prototype._activateWhenOutOfFocus = function() {
    // If skill list is open and Window_MenuActor is active, we are in the
    // item use target selection -> back out
    var windows = AdvancedMenus.listOfWindows();
    var inSkillList = false;
    for (var j = 0; j < windows.length; j++) {
        if (Window_SkillList.prototype.isPrototypeOf(windows[j]) &&
                windows[j].visible) {
            inSkillList = true;
        }
    }
    if (inSkillList) {
        for (var j = 0; j < windows.length; j++) {
            if (Window_MenuActor.prototype.isPrototypeOf(windows[j]) &&
                    windows[j].active && windows[j].visible) {
                windows[j].processCancel();
                windows[j].select(-1);
                windows[j].deactivate();
                break;
            }
        }
    }

    // Back out of SkillList when active:
    var windows = AdvancedMenus.listOfWindows();
    for (var j = 0; j < windows.length; j++) {
        if (Window_SkillList.prototype.isPrototypeOf(windows[j]) &&
                windows[j].active && windows[j].visible) {
            windows[j].processCancel();
            return true;
        }
    }
    return false;
}

// Allow changing game menu category while Window_MenuStatus selection active:
Window_MenuCommand.prototype._activateWhenOutOfFocus = function() {
    var windows = AdvancedMenus.listOfWindows();
    for (var j = 0; j < windows.length; j++) {
        if (Window_MenuStatus.prototype.isPrototypeOf(windows[j]) &&
                windows[j].visible && windows[j].active) {
            windows[j].processCancel();
            return true;
        }
    }
    return false;
}

// Allow changing ItemCategory while the ItemList is active:
Window_ItemCategory.prototype._activateWhenOutOfFocus = function() {
    // If item list is open and Window_MenuActor is active, we are in the
    // item use target selection -> back out, but only if clicking
    // at the left-most button.
    var x = this.canvasToLocalX(TouchInput.x);
    var y = this.canvasToLocalY(TouchInput.y);
    var hitIndex = this.hitTest(x, y);
    if (hitIndex == 0) {
        var windows = AdvancedMenus.listOfWindows();
        var inItemList = false;
        for (var j = 0; j < windows.length; j++) {
            if (Window_ItemList.prototype.isPrototypeOf(windows[j]) &&
                    windows[j].visible) {
                inItemList = true;
            }
        }
        if (inItemList) {
            for (var j = 0; j < windows.length; j++) {
                if (Window_MenuActor.prototype.isPrototypeOf(windows[j]) &&
                        windows[j].active && windows[j].visible) {
                    windows[j].processCancel();
                    windows[j].select(-1);
                    windows[j].deactivate();
                    break;
                }
            }
        }
    }

    // Make sure the item use target choice isn't open:
    var windows = AdvancedMenus.listOfWindows();
    for (var j = 0; j < windows.length; j++) {
        if (Window_MenuActor.prototype.isPrototypeOf(windows[j]) &&
                windows[j].visible) {
            return false;
        }
    }

    // Close item list so we can change category:
    for (var j = 0; j < windows.length; j++) {
        if (Window_ItemList.prototype.isPrototypeOf(windows[j])
                && windows[j].active && windows[j].visible) {
            windows[j].processCancel();
            return true;
        }
    }
    return false;
}

// Fix the displayed item help sometimes getting surprised by our changes:
Window_ItemCategory.prototype.processTouch = function() {
    Window_Selectable.prototype.processTouch.apply(this, []);
    // make sure the item help display follows our changes:
    var windows = AdvancedMenus.listOfWindows();
    for (var j = 0; j < windows.length; j++) {
        if (Window_ItemList.prototype.isPrototypeOf(windows[j])) {
            windows[j].updateHelp();
        }
    }
}

// Fix the displayed menu help sometimes getting surprised by our changes:
Window_SkillType.prototype.processTouch = function() {
    Window_Selectable.prototype.processTouch.apply(this, []);
    // make sure the item help display follows our changes:
    var windows = AdvancedMenus.listOfWindows();
    for (var j = 0; j < windows.length; j++) {
        if (Window_SkillList.prototype.isPrototypeOf(windows[j])
                && windows[j].visible && windows[j].active) {
            windows[j].updateHelp();
        }
    }
}

// ---- GENERAL CODE FOR ONE-CLICK NAVIGATION AND INACTIVE INTERACTION ----

// Allow activating menus that aren't active if this._activateWhenOutOfFocus
// is defined on them:
Window_Selectable.prototype.processTouch = function() {
    if (this.isOpenAndActive() ||
            typeof(this._activateWhenOutOfFocus) != "undefined") {
        if (TouchInput.isTriggered() && this.isTouchedInsideFrame()) {
            this._touching = true;
            this.onTouch(true);
        } else if (TouchInput.isCancelled()) {
            if (this.isCancelEnabled() && this.isOpenAndActive()) {
                this.processCancel();
            }
        }
        if (this._touching) {
            if (TouchInput.isPressed()) {
                this.onTouch(false);
            } else {
                this._touching = false;
            }
        }
    } else {
        this._touching = false;
    }
};

// Allow confirming menus with just one mouse click and possibly to click 
// when menu is inactive:
Window_Selectable.prototype.onTouch = function(triggered) {
    var lastIndex = this.index();
    var x = this.canvasToLocalX(TouchInput.x);
    var y = this.canvasToLocalY(TouchInput.y);
    var hitIndex = this.hitTest(x, y);
    var self = this;
    var menuHasSelectInfo = function() {
        if (Window_EquipItem.prototype.isPrototypeOf(self)) {
            return true;
        }
        if (Window_SkillList.prototype.isPrototypeOf(self)) {
            return true;
        }
        if (Window_ItemList.prototype.isPrototypeOf(self)) {
            return true;
        }
        return false;
    }
    var tryActivate = function() {
        if (self.isOpenAndActive()) {
            // console.log("tryActivate: ALLOW IN FOCUS");
            return true;
        }
        AdvancedMenus.menuSoundsMuted = true;
        if (typeof(self._activateWhenOutOfFocus) != "undefined"
                && self._activateWhenOutOfFocus()) {
            AdvancedMenus.menuSoundsMuted = false;
            // console.log("tryActivate: ALLOW OUT OF FOCUS");
            return true;
        }
        AdvancedMenus.menuSoundsMuted = false;
        // console.log("tryActivate: DISALLOW");
        return false;
    }
    if (hitIndex >= 0) {
        if (hitIndex === this.index()) {
            if (triggered && this.isTouchOkEnabled()) {
                if (tryActivate()) {
                    this.processOk();
                    return;
                }
            }
        } else if (this.isCursorMovable() ||
                typeof(this._activateWhenOutOfFocus) != "undefined") {
            if (!tryActivate()) {
                return;
            }
            this.select(hitIndex);
            // Allow direct click unless it matches a few well-known menus
            // with per-selection descriptions:
            if (!menuHasSelectInfo()) {
                if (triggered && this.isTouchOkEnabled()) {
                    this.processOk();
                }
            }
        }
    } else if (this._stayCount >= 10) {
        if (y < this.padding) {
            if (tryActivate()) {
                this.cursorUp();
            }
        } else if (y >= this.height - this.padding) {
            if (tryActivate()) {
                this.cursorDown();
            }
        }
    }
    if (this.index() !== lastIndex) {
        SoundManager.playCursor();
    }
};

})();
 
Last edited by a moderator:

Linard

Veteran
Veteran
Joined
Jun 29, 2016
Messages
202
Reaction score
17
First Language
Filipino
Primarily Uses
RMMV
Hello @orlando this plugin is very helpful :)  I think there's a mini bug.


if i show a choices and set the position in Middle the Window Choices position is displaying at the bottom. Actually all of the position of the choices is affected. I turn off the plug-in and it works properly.


Here's the screenshot: 




here's the command: 



Spoiler











Thank you for your response very like this plugin :D
 
Last edited by a moderator:

yongilcool

Veteran
Veteran
Joined
Nov 7, 2014
Messages
60
Reaction score
10
First Language
English
thnx for the great plugin! i fixed the choice error.
 
Last edited by a moderator:

yongilcool

Veteran
Veteran
Joined
Nov 7, 2014
Messages
60
Reaction score
10
First Language
English
Hello @orlando this plugin is very helpful :)  I think there's a mini bug.


if i show a choices and set the position in Middle the Window Choices position is displaying at the bottom. Actually all of the position of the choices is affected. I turn off the plug-in and it works properly.


Here's the screenshot: 




here's the command: 



  Reveal hidden contents











Thank you for your response very like this plugin :D
 buddy i fixed this by deleting this part from the plugin. try it! :) :


    // When Window_Message moves, move the "Cancel..." too:
    Window_Message.prototype._preAdvancedMenus_move =
        Window_Message.prototype.move;
    Window_Message.prototype.move = function(x, y) {
        var retval = this._preAdvancedMenus_move(x, y);
        adjustEventItemCancelButtonPos(this);
        return retval;
    }
 

Users Who Are Viewing This Thread (Users: 0, Guests: 2)

Latest Threads

Latest Posts

Latest Profile Posts

I'm currently being attacked by the RPG Maker Hydra: fixing one problem only to have two more rise to take its place.
Hey you! Yeah YOU! Whatcha doin' not backing up your projects? You a masochist or sumthin'? GO BACK UP YOUR PROJECTS! Sheeesh... Didn't think I'd hafta spell it out for yas.
now I need to determine, how MV determines if an auto tile is complete or not.
Edit:From what I can tell it uses Autotile kinds to do that.
Edit 2: The editor determines it and packs picture data for the engine....
Finished with the ground work for my class system, using Ellye's Class Change Equipment and Yanfly's Class Change Core plugins to implement an equip based subclass feature!
Hi people! I was wondering... Here in Brazil, we have a whats app group for we talk about rpg maker and our projects. A more informal way for we meet each other. Is there any whats app group out there? :)

Forum statistics

Threads
94,281
Messages
919,638
Members
124,014
Latest member
AnnuRavi
Top