Drawing new Window_Selectables in Scene (SOLVED)

Camkitsune

Veteran
Veteran
Joined
Mar 9, 2017
Messages
34
Reaction score
4
First Language
English
Primarily Uses
RMMV
I'm trying to create a window that functions similarly to the Items list, but for a set of objects that provide notes on characters and locations.

I've confirmed (to the best of my ability) that everything in the code is working as expected, right up until I actually try to open the new menu command.

The first spoiler contains all of the bits defining how the plugin itself and the Intel objects work; I've included it for the sake of completeness.
Code:
//Get the plugin parameters.
var intelParameters = PluginManager.parameters('IntelSystem');

 //Get the intel data from the json file.
DataManager.loadDataFile('$dataIntel', intelParameters.JsonFileName);
 
//Define getter for the DataManager.
DataManager.getIntelData = function(id) {
    return $dataIntel[id];
};

//Add the plugin commands.
Game_Interpreter.prototype.pluginCommand = (function (original) {
    "use strict";

    // Define the function that will replace the original.

    function pluginCommand(command, args) {
        original.call(this, command, args);
        if (command == "Intel") {
           
            var intelData = GetIntelItem(args);
            //If argument is 'add', run add function.
            if (args[0] = "add") {
                var result = $gameParty.IntelList.addIntel(intelData);
                //TODO: create popup window.
            } else if (args[0] = "check") {
                return $gameParty.IntelList.hasIntel(intelData);
            } else if (args[0] = "showAlerts") {
                intelParameters.ShowAlerts = args[1];
            } else { return;}
        } else { return;}
    }

    return pluginCommand;
}(Game_Interpreter.prototype.pluginCommand));

//Function fetches an intelItem for use by the above commands.
function GetIntelItem(args) {
    var idNum = Number(args[1]);
    var intelFromData = DataManager.getIntelData(idNum);
       
    var argsIndex = 2;
    var contents = [];
    if (args.length < 3  && args[0] != "check") {
        contents = intelFromData.contents;
    } else {
        while (argsIndex < args.length) {
            var contentsIndex = Number(args[argsIndex]);
            //If the number is within the contents array, AND the item hasn't already been added...
            if (contentsIndex < intelFromData.contents.length && contents.indexOf(intelFromData.contents[contentsIndex]) === -1) {
                    //...Add the contents item
                    contents.push(intelFromData.contents[contentsIndex]);
            }
            argsIndex++;
            }
    }
    return new IntelItem(idNum, intelFromData.topic, intelFromData.category, contents);
}

/*----------------------------------------------------------------------------*
 *        CORE FUNCTIONS                                                          *
 *----------------------------------------------------------------------------*/

//Object constructor for IntelItem.
function IntelItem(idnum, topic, category, contents) {
    //ID is used to simplify the lookup process.
    this.id = idnum;
    //Topics are what the specific informatoin will appear on: IE, the subject of the intel.
    this.topic = topic;
    //Categories are used for in-game filtering.
    this.category = category;
    //Array representing specific lines of information.
    this.contents = contents;
}
 
 //Function is used as part of evaluation of whether a new intel item's contents are already in the player's Intel inventory.
IntelItem.prototype.matches = function (intelFromList) {
    var index = 0;
    //isMatch first checks if the topics match; while loop won't even start if they don't.
    var isMatch = (this.id === intelFromList.id);    
    while (isMatch && index <  this.contents.length) {
        //Step through the contents of the calling IntelItem; if the IntelItem from the list is missing any of them, return false.
        isMatch = (intelFromList.contents.indexOf(this.contents[index]) > -1);
        index++;
    }
    return isMatch;
};

//Function adds contents FROM the calling function TO the item given as an argument; the intent is that the item passed as an argument accesses the info from IntelList.
IntelItem.prototype.addNewContents = function(intelFromList){
    var newContentsAdded = false;
    for (var index = 0; index < this.contents.length; index++) {
        if (intelFromList.contents.indexOf(this.contents[index]) === -1) {
            intelFromList.contents.push(this.contents[index]);
            newContentsAdded = true;
        }
    }
    return newContentsAdded;
};

//Function returns the IntelItem.contents array as a single formated string, ready to be written into the menu.
IntelItem.prototype.getContents = function(){
    var result = "";
    for (var x = 0; x < this.contents.length; x++) {
        result += "  " + this.contents[x];
    }
    return result;
};

//IntelList handles in-game inventory of IntelItems, provides sorting functionality.
function IntelList() {
    this.IntelItems = [];
    this.intelCategories = [];
}
 
//Function updates the intel listing with new items, new categories, and new contents for extant items.  Returns a string for use with alerts.  
IntelList.prototype.addIntel = function(targetIntel) {
    //Premature break if a null argument is added.
    if (!targetIntel) return;
   
    //Insert category if it isn't in the categories list.
    if (this.intelCategories.indexOf(targetIntel.category) === -1) {
        this.intelCategories.push(targetIntel.category);
        this.intelCategories.sort();
    }
   
    var result = null;
    var dexVal = this.findIndex(targetIntel);
    if (dexVal === this.IntelItems.length) {
        this.IntelItems.push(targetIntel);
        result = "New intelligence file: " + targetIntel.topic;
    } else {
        var intelAtIndex = this.IntelItems[dexVal];
        if (intelAtIndex.id != targetIntel.id) {
            this.IntelItems.splice(dexVal+ 1, 0, targetIntel);
            result = "New intelligence file: " + targetIntel.topic;
        } else {
            var contentsCheck = targetIntel.addNewContents(intelAtIndex);
            if (contentsCheck){
                result = "Information updated: " + targetIntel.topic;
            }
        }
    }
    if (intelParameters.ShowAlerts) {
        return result;
    } else {
        return null;
    }
};
 
//Helper function for addIntel function; makes sure new intel is inserted alphabetically.
IntelList.prototype.findIndex = function (targetIntel) {
    var index = 0;
    var resultVal = 1;
    while (index < this.IntelItems.length && resultVal < 0) {
        resultVal = targetIntel.topic.localeCompare(this.IntelItems[index].topic);
        if (resultVal > 0) { index++; }
    }
    return index;
};

//Function determines whether or not the specified intel is present in the player's intel inventory.
IntelList.prototype.hasIntel = function(targetIntel) {
    //searchFunction must be defined this way due to how Array.some handles the function.
    var searchFunction = function(intelFromList){
        //The IntelItem.matches function checks to see if the intel item taken from the list has the same ID as well as all of the contents it has.
        return targetIntel.matches(intelFromList);
    };
    return this.IntelItems.some(searchFunction);
};

//Returns an array of IntelItems with the specified topic.
IntelList.prototype.getIntelFromCategory = function(categoryName){
    var result = [];
    for (var index = 0; index < this.IntelItems.length; index++) {
        if (this.IntelItems[index].category === categoryName) {
            result.push(this.IntelItems[index]);
        }
    }
    return result;
};

//Add initialization of IntelList to $gameParty
Game_Party.prototype.initialize =  (function (original) {
    "use strict";
    function initialize() {
        original.call(this);
        this.IntelList = new IntelList();
    }
    return initialize;
}(Game_Party.prototype.initialize));

This is the section where I'm pretty sure I've messed up:
Code:
/*----------------------------------------------------------------------------*
 *        SCENE FUNCTIONS                                                          *
 *----------------------------------------------------------------------------*/
//Patch in the handler for the Intel command.
Scene_Menu.prototype.createCommandWindow = (function (original) {
    "use strict";
    function createCommandWindow() {
        original.call(this);

        this._commandWindow.setHandler("intel", function () {
            SceneManager.push(Scene_Intel);
        });
    }

    return createCommandWindow;
}(Scene_Menu.prototype.createCommandWindow));

//Patch the Intel command into the list of commands on the in-game menu.
Window_MenuCommand.prototype.addOriginalCommands = (function (original) {
    "use strict";
    function addOriginalCommands() {
        original.call(this);
        this.addCommand("Intel", "intel", ($gameParty.IntelList.IntelItems.length > 0));
    }

    return addOriginalCommands;
}(Window_MenuCommand.prototype.addOriginalCommands));

//Define initialization, prototype, and constructor.
function Scene_Intel() {this.initialize.apply(this, arguments);}
Scene_Intel.prototype = Object.create(Scene_MenuBase.prototype);
Scene_Intel.prototype.constructor = Scene_Intel;
Scene_Intel.prototype.initialize = function() {Scene_MenuBase.prototype.initialize.call(this);};

//Define creation and termination events.
Scene_Intel.prototype.create = function() {
    Scene_MenuBase.prototype.create.call(this);
    //TODO: Add Help Window.
    //TODO: Add Categories Window.
    this.createIntelWindow();
};

Scene_Intel.prototype.terminate = function() {
    Scene_MenuBase.prototype.terminate.call(this);
};

//Creates the windows that form the .
Scene_Intel.prototype.createIntelWindow = function() {
    this._intelWindow = new Window_IntelList();
    this._intelWindow.setHandler('cancel', this.popScene.bind(this));
    this.addWindow(this._intelWindow);
};
/*----------------------------------------------------------------------------*
* WINDOW FUNCTIONS *
*----------------------------------------------------------------------------*/


function Window_IntelList() {this.initialize.apply(this, arguments);}
Window_IntelList.prototype = Object.create(Window_Selectable.prototype);
Window_IntelList.prototype.constructor = Window_IntelList;

Window_IntelList.prototype.initialize = function(x, y, width, height) {
Window_Selectable.prototype.initialize.call(this, x, y, width, height);
    this._category = 'none';
    this._data = [];
};

Window_IntelList.prototype.windowWidth = function() {
    return Math.floor(Graphics.boxWidth * 0.4);
};

Window_IntelList.prototype.windowHeight = function() {
    return Graphics.boxHeight;
};

Window_IntelList.prototype.maxCols = function() {return 1;};

Window_IntelList.prototype.maxItems = function() {return this._data ? this._data.length : 1; };

Window_IntelList.prototype.itemWidth = function() {return Math.floor(Graphics.boxWidth * 0.4) + this.textPadding; };

Window_IntelList.prototype.item = function() {
    var index = this.index();
    return this._data && index >= 0 ? this._data[index] : null;
};

Window_IntelList.prototype.makeIntelList = function() {
    //TODO: add category filtering.
    this._data = $gameParty.IntelList.IntelItems;
};


Window_IntelList.prototype.drawAllTopics = function() {
    for (var index = 0; index < this._data.length; index++) {
        this.drawTopic(index);
    };
   
};

Window_IntelList.prototype.drawTopic = function(index) {
    var intel = this._data[index];
    if (intel) {
        var rect = this.itemRect(index);
        rect.width -= this.textPadding();
        this.drawText(intel.topic, rect.x, rect.y, rect.width);
    }
};

I've confirmed that the initialization is working, and that the item is being successfully added to $gameParty.IntelList: after the corresponding event that calls the Plugin command to add the item from the json file, Intel becomes selectable.

However, no menu is actually drawn; all that happens is that the screen empties of the other menus (but stays blurred as if still in the menu system). Since the "cancel" event has been bound to the window it should allow me to back out, but does not. This means that I've either royally screwed up the window creation (probably because I've forgotten something critical), or the program is getting stuck in a loop somewhere.

EDIT: Fixed a typo that broke one of the SPOILER tags.
 
Last edited:

Clock Out

Veteran
Veteran
Joined
Jun 14, 2016
Messages
92
Reaction score
45
First Language
English
Primarily Uses
RMMV
The window is never passed coordinates nor width or height values. In the createIntelWindow() method, when Window_IntelList() is called, pass in the dimensions it needs.
Code:
//Creates the windows that form the .

Scene_Intel.prototype.createIntelWindow = function () {
    this._intelWindow = new Window_IntelList(0, 0,
        Math.floor(Graphics.boxWidth * 0.4), Graphics.boxHeight);
    this._intelWindow.setHandler("cancel", this.popScene.bind(this));
    this.addWindow(this._intelWindow);
};

I also noticed mistakes in the pluginCommand function. The if statements have assignments instead of comparisons.
Code:
if (args[0] = "add") { // ... }
Should be:
Code:
if (args[0] === "add") { // ... }
I recommend using only the strict comparison operators in JS.

Consider using a "guard" if statement and a switch statement for evaluating the args array. Looks a little cleaner without all the braces and drops us down a level of indentation which is nice.
Code:
//Add the plugin commands.

Game_Interpreter.prototype.pluginCommand = (function (original) {
    "use strict";

    // Define the function that will replace the original.

    function pluginCommand(command, args) {
        var result;

        original.call(this, command, args);

        if (command !== "Intel") {
            return;
        }

        switch(args[0]) {
        case "add":
            result = $gameParty.IntelList.addIntel(GetIntelItem(args));

            // TODO: Create popup window.

            break;
        case "check":
            $gameParty.IntelList.hasIntel(GetIntelItem(args));
            break;
        case "showAlerts":
            intelParameters.ShowAlerts = args[1];
            break;
        }
    }

    return pluginCommand;
})(Game_Interpreter.prototype.pluginCommand);

The cancel event handler was setup properly it's just that the window wasn't set to active so it's event handlers won't be called. Call the window's activate() method after it's been created.
Code:
Scene_Intel.prototype.createIntelWindow = function () {
    this._intelWindow = new Window_IntelList(0, 0,
        Math.floor(Graphics.boxWidth * 0.4), Graphics.boxHeight);
    this._intelWindow.setHandler("cancel", this.popScene.bind(this));
    this._intelWindow.activate();
    this.addWindow(this._intelWindow);
};
 
Last edited:

Camkitsune

Veteran
Veteran
Joined
Mar 9, 2017
Messages
34
Reaction score
4
First Language
English
Primarily Uses
RMMV
The specified changes made the window appear as expected; cancelling back to the main menu is also working properly now.

However, none of the Topics are appearing as expected.

I went ahead and wrote in a window to sort by categories, since that seemed to work differently; the topics appear as expected, but with no Topics in the Topic list. The cursor also starts in the Categories list, possibly because the Topics list is empty.

I also ran into problems with 'undefined is not a function' when attempting to assign the Category window to the Topics window.

Code:
/*----------------------------------------------------------------------------*
 *        PLUGIN SETUP                                                          *
 *----------------------------------------------------------------------------*/
//Get the plugin parameters.
var intelParameters = PluginManager.parameters('IntelSystem');

 //Get the intel data from the json file.
DataManager.loadDataFile('$dataIntel', intelParameters.JsonFileName);
 
//Define getter for the IntelData.
DataManager.getIntelData = function(id) {
    return $dataIntel[Number(id)];
};

//Add the plugin commands.
Game_Interpreter.prototype.pluginCommand = (function (original) {
    "use strict";

    // Define the function that will replace the original.

    function pluginCommand(command, args) {
        original.call(this, command, args);
        if (command !== "Intel") {
            return;
        }
        var intelData = DataManager.getIntelData(args[1]);
        //Necessary for preventing data from being manipulated.
        var newIntel = new IntelItem(intelData.id, intelData.topic, intelData.category, intelData.contents);
        //use slice so that only the arguments relating to contents are passed.
        newIntel.pruneContents(args.slice(2, args.length));
       
        switch (args[0]) {
            case "add":
                //intelData is also passed in to reduce calls to the DataManager.
                var result = $gameParty.IntelList.addIntel(newIntel, intelData);
                //TODO: create popup window.
                break;
            case "check":
                return $gameParty.IntelList.hasIntel(newIntel);
            case "showAlerts":
                intelParameters.ShowAlerts = args[1];
                break;
            case "debug":
                for (var index = 1; index < args.length; index++) {
                    var debugIntel = DataManager.getIntelData(args[index]);
                    $gameParty.IntelList.addIntel(new IntelItem(debugIntel.id, debugIntel.topic, debugIntel.category, debugIntel.contents), debugIntel);
                }
                break;
            default:
                break;
        }
    }

    return pluginCommand;
}(Game_Interpreter.prototype.pluginCommand));

//Add initialization of IntelList to $gameParty
Game_Party.prototype.initialize =  (function (original) {
    "use strict";
    function initialize() {
        original.call(this);
        this.IntelList = new IntelList();
    }
    return initialize;
}(Game_Party.prototype.initialize));
/*----------------------------------------------------------------------------*
 *        CORE FUNCTIONS                                                          *
 *----------------------------------------------------------------------------*/

//Object constructor for IntelItem.
function IntelItem(idnum, topic, category, contents) {
    //ID is used to simplify the lookup process.
    this.id = idnum;
    //Topics are what the specific informatoin will appear on: IE, the subject of the intel.
    this.topic = topic;
    //Categories are used for in-game filtering.
    this.category = category;
    //Array representing specific lines of information.
    this.contents = contents;
}
 
 //Function is used as part of evaluation of whether a new intel item's contents are already in the player's Intel inventory.
IntelItem.prototype.matches = function (intelFromList) {
    var index = 0;
    //isMatch first checks if the topics match; while loop won't even start if they don't.
    var isMatch = (this.id === intelFromList.id);    
    while (isMatch && index <  this.contents.length) {
        //Step through the contents of the calling IntelItem; if the IntelItem from the list is missing any of them, return false.
        isMatch = (intelFromList.contents.indexOf(this.contents[index]) > -1);
        index++;
    }
    return isMatch;
};

//Function adds contents FROM the calling function TO the item given as an argument; the intent is that the item passed as an argument accesses the info from IntelList.
IntelItem.prototype.addNewContents = function(intelFromList, intelData){
    var newContentsAdded = false;
    for (var index = 0; index < this.contents.length; index++) {
        var newContents = this.contents[index]
        var contentsIndex = intelFromList.contents.indexOf(newContents);
        if (contentsIndex === -1) {
            newContentsAdded = true;
           
            //Get the index of the contents from the data.
            var dataIndexOfNewContents = intelData.contents.indexOf(this.contents[index]);
           
            var dataIndexOfOldContents = 0;
           
            //This will cycle through the list item's contents until it finds the last one that comes before the new item.
            while (dataIndexOfOldContents < intelFromList.contents.length
                    && dataIndexOfNewContents > intelData.contents.indexOf(intelFromList.contents[dataIndexOfOldContents])) {
                dataIndexOfOldContents++;
            }
            intelFromList.contents.splice(dataIndexOfOldContents, 0, this.contents[index]);
           
        }
    }
    return newContentsAdded;
};

//Function returns the IntelItem.contents array as a single formated string, ready to be written into the menu.
IntelItem.prototype.getContents = function(){
    var result = "";
    for (var x = 0; x < this.contents.length; x++) {
        result += "  " + this.contents[x];
    }
    return result;
};

//Function is used to remove contents.
IntelItem.prototype.pruneContents = function(args){
    var index = this.contents.length;
    while (index > 0) {
        //If an index number is not in args, remove the contents at that number.
        if (args.indexOf(index) === -1) {
            this.contents.splice(index, 1);
        }
        index--;
    }
};
   
//IntelList handles in-game inventory of IntelItems, provides sorting functionality.
function IntelList() {
    this.IntelItems = [];
    this.IntelCategories = [];
}
 
//Function updates the intel listing with new items, new categories, and new contents for extant items.  Returns a string for use with alerts.  
IntelList.prototype.addIntel = function(targetIntel, intelData) {
    //Premature break if a null argument is added.
    if (!targetIntel) return;
   
    //Insert category if it isn't in the categories list.
    if (this.IntelCategories.indexOf(targetIntel.category) === -1) {
        this.IntelCategories.push(targetIntel.category);
        this.IntelCategories.sort();
    }
   
    var result = null;
    var dexVal = this.findIndex(targetIntel);
    if (dexVal === this.IntelItems.length) {
        this.IntelItems.push(targetIntel);
        result = "New intelligence file: " + targetIntel.topic;
    } else {
        var intelAtIndex = this.IntelItems[dexVal];
        if (intelAtIndex.id != targetIntel.id) {
            this.IntelItems.splice(dexVal+ 1, 0, targetIntel);
            result = "New intelligence file: " + targetIntel.topic;
        } else {
            var contentsCheck = targetIntel.addNewContents(intelAtIndex, intelData);
            if (contentsCheck){
                result = "Information updated: " + targetIntel.topic;
            }
        }
    }
    if (intelParameters.ShowAlerts) {
        return result;
    } else {
        return null;
    }
};
 
//Helper function for addIntel function; makes sure new intel is inserted alphabetically.
IntelList.prototype.findIndex = function (targetIntel) {
    var index = 0;
    var resultVal = 1;
    while (index < this.IntelItems.length && resultVal < 0) {
        resultVal = targetIntel.topic.localeCompare(this.IntelItems[index].topic);
        if (resultVal > 0) { index++; }
    }
    return index;
};

//Function determines whether or not the specified intel is present in the player's intel inventory.
IntelList.prototype.hasIntel = function(targetIntel) {
    //searchFunction must be defined this way due to how Array.some handles the function.
    var searchFunction = function(intelFromList){
        //The IntelItem.matches function checks to see if the intel item taken from the list has the same ID as well as all of the contents it has.
        return targetIntel.matches(intelFromList);
    };
    return this.IntelItems.some(searchFunction);
};

//Returns an array of IntelItems with the specified topic.
IntelList.prototype.getIntelFromCategory = function(categoryName){
    var result = [];
    for (var index = 0; index < this.IntelItems.length; index++) {
        if (this.IntelItems[index].category === categoryName) {
            result.push(this.IntelItems[index]);
        }
    }
    return result;
};
Code:
/*----------------------------------------------------------------------------*
 *        SCENE FUNCTIONS                                                          *
 *----------------------------------------------------------------------------*/
//Patch in the handler for the Intel command.
Scene_Menu.prototype.createCommandWindow = (function (original) {
    "use strict";
    function createCommandWindow() {
        original.call(this);

        this._commandWindow.setHandler("intel", function () {
            SceneManager.push(Scene_Intel);
        });
    }

    return createCommandWindow;
}(Scene_Menu.prototype.createCommandWindow));

//Patch the Intel command into the list of commands on the in-game menu.
Window_MenuCommand.prototype.addOriginalCommands = (function (original) {
    "use strict";
    function addOriginalCommands() {
        original.call(this);
        this.addCommand("Intel", "intel", ($gameParty.IntelList.IntelItems.length > 0));
    }

    return addOriginalCommands;
}(Window_MenuCommand.prototype.addOriginalCommands));

//Define initialization, prototype, and constructor.
function Scene_Intel() {this.initialize.apply(this, arguments);}
Scene_Intel.prototype = Object.create(Scene_MenuBase.prototype);
Scene_Intel.prototype.constructor = Scene_Intel;
Scene_Intel.prototype.initialize = function() {Scene_MenuBase.prototype.initialize.call(this);};

//Define creation and termination events.
Scene_Intel.prototype.create = function() {
    Scene_MenuBase.prototype.create.call(this);
    //this.createHelpWindow();
    this.createIntelCatsWindow();
    this.createIntelWindow();
};

Scene_Intel.prototype.terminate = function() {
    Scene_MenuBase.prototype.terminate.call(this);
};

//Creates the category list.
Scene_Intel.prototype.createIntelCatsWindow = function() {
    this._categoryWindow = new Window_IntelCategory();
    this._categoryWindow.makeCommandList();
    this.addWindow(this._categoryWindow);
};

//Creates the list of intel items.
Scene_Intel.prototype.createIntelWindow = function() {
    this._topicWindow = new Window_IntelList(0, this._categoryWindow.height, Math.floor(Graphics.boxWidth * 0.3), Graphics.boxHeight - this._categoryWindow.windowHeight());
    this._topicWindow.setHandler('cancel', this.popScene.bind(this));
    this._topicWindow.drawAllTopics();
    this.addWindow(this._topicWindow);
    //this._categoryWindow.setIntelWindow(this._topicWindow);
    this._topicWindow.activate();
};

/*----------------------------------------------------------------------------*
* WINDOW FUNCTIONS *
*----------------------------------------------------------------------------*/

//Window for the list of categories
function Window_IntelCategory() {this.initialize.apply(this, arguments);}
Window_IntelCategory.prototype = Object.create(Window_HorzCommand.prototype);
Window_IntelCategory.prototype.constructor = Window_IntelCategory;

Window_IntelCategory.prototype.initialize = function() {
    Window_HorzCommand.prototype.initialize.call(this, 0, 0);
};

Window_IntelCategory.prototype.windowWidth = function() {
    return Graphics.boxWidth;
};

Window_IntelCategory.prototype.maxCols = function() {
    return 5;
};

Window_IntelCategory.prototype.setIntelWindow = function(topicWindow) {
    this._topicWindow = topicWindow;
};

Window_IntelCategory.prototype.update = function() {
    Window_HorzCommand.prototype.update.call(this);
    if (this._topicWindow) {
        this._topicWindow.setCategory(this.currentSymbol());
    }
};
   
Window_IntelCategory.prototype.makeCommandList = function() {
    for (var index = 0; index < $gameParty.IntelList.IntelCategories.length; index++) {
        this.addCommand($gameParty.IntelList.IntelCategories[index], $gameParty.IntelList.IntelCategories[index]);
    }
};
   
   
//Window for the list of topics.

function Window_IntelList() {this.initialize.apply(this, arguments);}
Window_IntelList.prototype = Object.create(Window_Selectable.prototype);
Window_IntelList.prototype.constructor = Window_IntelList;

Window_IntelList.prototype.initialize = function(x, y, width, height) {
Window_Selectable.prototype.initialize.call(this, x, y, width, height);
    this._category = 'none';
    this._data = [];
};

Window_IntelList.prototype.windowWidth = function() {
    return Math.floor(Graphics.boxWidth * 0.3);
};

Window_IntelList.prototype.windowHeight = function() {
    return Graphics.boxHeight;
};

Window_IntelList.prototype.maxCols = function() {return 1;};

Window_IntelList.prototype.maxItems = function() {return this._data ? this._data.length : 1; };

Window_IntelList.prototype.itemWidth = function() {return Math.floor(Graphics.boxWidth * 0.4) + this.textPadding; };

Window_IntelList.prototype.item = function() {
    var index = this.index();
    return this._data && index >= 0 ? this._data[index] : null;
};

Window_IntelList.prototype.makeIntelList = function() {
    if (this._category && this._category !== 'none') {
        this._data = $gameParty.IntelList.IntelItems.getIntelFromCategory(this._category);
    } else {
        this._data = $gameParty.IntelList.IntelItems;
    }
};

Window_IntelList.prototype.drawAllTopics = function() {
    this.makeIntelList();
    for (var index = 0; index < this._data.length; index++) {
        this.drawTopic(index);
    }
   
};

Window_IntelList.prototype.drawTopic = function(index) {
    var intel = this._data[index];
    if (intel) {
        var rect = this.itemRect(index);
        rect.width -= this.textPadding();
        this.drawText(intel.topic, rect.x, rect.y, rect.width);
    }
};

Window_IntelList.prototype.setCategory = function(category) {
    if (this._category !== category) {
        this._category = category;
        this.refresh();
        this.resetScroll();
    }
};

Window_IntelList.prototype.refresh = function() {
    this.makeIntelList();
    this.createContents();
    this.drawAllTopics();
};

I've been using the various 'Window_Item's as an example; with that in mind, would I be better off just opting for adding Commands?
If I were to do it that way, would it be possible to only require moving the cursor over a command to have it execute, instead of having to select it?
If not, what do I need to do to get the Topics to actually show up?
 

Clock Out

Veteran
Veteran
Joined
Jun 14, 2016
Messages
92
Reaction score
45
First Language
English
Primarily Uses
RMMV
Code:
Window_IntelList.prototype.itemWidth = function () {
    return Math.floor(Graphics.boxWidth * 0.4) + this.textPadding;
};
The topics will appear when the parens are added to this.textPadding().
 

Camkitsune

Veteran
Veteran
Joined
Mar 9, 2017
Messages
34
Reaction score
4
First Language
English
Primarily Uses
RMMV
That did the trick.

What would the best approach be to attach a function that executes as soon as the cursor hovers over the item?

I'm guessing it would be to do something like this:
Code:
Window_IntelTopics.prototype.drawTopic = function(index) {
    var intel = this._data[index];
    if (intel) {
        var rect = this.itemRect(index);
        rect.width -= this.textPadding();
        this.drawText(intel.topic, rect.x, rect.y, rect.width);
        rect.bind('handlerForCursorHover', myFunction(intel.contents))
    }
};
The main problem is that I have no clue what handler I'd use for the RPGMaker Menu cursor.

EDIT: I'm also having problems with the Scene_Intel methods not properly 'linking' windows together; this is why the 'SetIntelWindow' call is commented out.
EDIT2: Fixed the issue with SetIntel window by setting the relationships in the prototype.initialize functions.
 
Last edited:

Clock Out

Veteran
Veteran
Joined
Jun 14, 2016
Messages
92
Reaction score
45
First Language
English
Primarily Uses
RMMV
The Window_Selectable.prototype.select method is called when an list item is selected. I guess monkey patch the select method and do what you need. Here's an example.
Code:
function aWin() {
    "use strict";

    var win = Object.create(Window_HorzCommand.prototype);

    win.select = (function (original) {
        return function (index) {
            original.call(win, index);

            if (win.index() > -1) {

                // Do the stuff you need here when an list item is selected.

                console.log(win._list[win.index()].name);
            }
        };
    }(win.select));

    win.makeCommandList = function () {
        win.addCommand("a", "a");
        win.addCommand("b", "b");
        win.addCommand("c", "c");
        win.addCommand("d", "d");
    };

    win.initialize(0, 0);

    return win;
}

function aScene() {
    "use strict";

    var scene = Object.create(Scene_MenuBase.prototype);

    scene.create = (function (original) {
        return function () {
            original.call(scene);

            scene.addWindow(aWin());
        };
    }(scene.create));

    scene.initialize();

    return scene;
}
 
Last edited:

Camkitsune

Veteran
Veteran
Joined
Mar 9, 2017
Messages
34
Reaction score
4
First Language
English
Primarily Uses
RMMV
I wound up doing something similar using ProcessCursorMove:
Code:
Window_IntelTopics.prototype.processCursorMove = function() {
    Window_Selectable.prototype.processCursorMove.call(this);
    var index = this.index();
    var intel = this._data[index];
    if (intel  && this._contentsWindow) {
        this._contentsWindow.drawContents(intel.getContents());
    }
}

function Window_IntelContents() {this.initialize.apply(this, arguments);};
Window_IntelContents.prototype = Object.create(Window_Base.prototype);
Window_IntelContents.prototype.constructor = Window_IntelContents;

Window_IntelContents.prototype.initialize = function(x, y, width, height) {
    Window_Base.prototype.initialize.call(this, x, y, width, height);
};

Window_IntelContents.prototype.drawContents = function(contentsText) {
    this.contents.clear();
    var linesAbove = 0;
    while (contentsText.length > 0) {
        var index = contentsText.length;
        while (this.contents.measureTextWidth(contentsText.slice(0, index)) > this.contentsWidth()) {
            index = contentsText.slice(0, index).lastIndexOf(" ");
        }  
        this.contents.drawText(contentsText.slice(0, index), 0, linesAbove *this.lineHeight(), this.width, this.height, 'left');
    contentsText = contentsText.slice(index);
    linesAbove++;
    }
};

There are two problems I've run into:
The first is that the text only appears in the bottom half of the Contents window.
The second is that the behavior of the windows is, for lack of a better word, weird. Both the windows are able to be controlled simultaneously, and for some reason the horizontal window wants to scroll vertically until you hit 'up' the first time. This was happening before I patched in the Contents window.
EDIT: the first problem was fixed by changing the 'x' argument for drawText to linesAbove * this.lineHeight - this.contentsHeight()/2
 
Last edited:

Clock Out

Veteran
Veteran
Joined
Jun 14, 2016
Messages
92
Reaction score
45
First Language
English
Primarily Uses
RMMV
Move the cancel handler that pops the scene to the categories window. Then remove the activate method in the createIntelWindow method for the topics window.

I noticed the scrolling issue but I'm not sure what's causing it.
 
Last edited:

Camkitsune

Veteran
Veteran
Joined
Mar 9, 2017
Messages
34
Reaction score
4
First Language
English
Primarily Uses
RMMV
I tried doing as you suggested; this fixed the issue of the cursor being in two places at once, but made it impossible to actually select any topics.

I also tried binding a sorting method to 'OK' on the categories window, but that isn't working either:
Code:
/*----------------------------------------------------------------------------*
 *        SCENE FUNCTIONS                                                          *
 *----------------------------------------------------------------------------*/
//Patch in the handler for the Intel command.
Scene_Menu.prototype.createCommandWindow = (function (original) {
    "use strict";
    function createCommandWindow() {
        original.call(this);

        this._commandWindow.setHandler("intel", function () {
            SceneManager.push(Scene_Intel);
        });
    }

    return createCommandWindow;
}(Scene_Menu.prototype.createCommandWindow));

//Patch the Intel command into the list of commands on the in-game menu.
Window_MenuCommand.prototype.addOriginalCommands = (function (original) {
    "use strict";
    function addOriginalCommands() {
        original.call(this);
        this.addCommand("Intel", "intel", ($gameParty.IntelList.IntelItems.length > 0));
    }

    return addOriginalCommands;
}(Window_MenuCommand.prototype.addOriginalCommands));

//Define initialization, prototype, and constructor.
function Scene_Intel() {this.initialize.apply(this, arguments);}
Scene_Intel.prototype = Object.create(Scene_MenuBase.prototype);
Scene_Intel.prototype.constructor = Scene_Intel;
Scene_Intel.prototype.initialize = function() {Scene_MenuBase.prototype.initialize.call(this);};

//Define creation and termination events.
Scene_Intel.prototype.create = function() {
    Scene_MenuBase.prototype.create.call(this);
    //this.createHelpWindow();
    this.createIntelCatsWindow();
    this.createIntelContentsWindow();
    this.createIntelTopicsWindow();
    this.setBindings();
};

Scene_Intel.prototype.terminate = function() {
    Scene_MenuBase.prototype.terminate.call(this);
};

//Creates the category list.
Scene_Intel.prototype.createIntelCatsWindow = function() {
    this._categoryWindow = new Window_IntelCategory(0,0);
    this._categoryWindow.makeCommandList();
    this.addWindow(this._categoryWindow);
};

//Creates the window in which the contents will appear.
Scene_Intel.prototype.createIntelContentsWindow = function() {
    this._contentsWindow = new Window_IntelContents(Math.floor(Graphics.boxWidth*0.3), this._categoryWindow.height, Math.ceil(Graphics.boxWidth * 0.7), Graphics.boxHeight - this._categoryWindow.windowHeight());
    this.addWindow(this._contentsWindow);
};


//Creates the list of intel items.
Scene_Intel.prototype.createIntelTopicsWindow = function() {
    var catWindow = this._categoryWindow;
    this._topicWindow = new Window_IntelTopics(0, catWindow.height, Math.floor(Graphics.boxWidth * 0.3), Graphics.boxHeight - catWindow.windowHeight(), this._contentsWindow);
 
    this._topicWindow.drawAllTopics();
    this.addWindow(this._topicWindow);
    catWindow.topicWindow = this._topicWindow;
 
};

Scene_Intel.prototype.setBindings = function(){
    this._categoryWindow.setHandler('ok', this._topicWindow.setCategory(this._categoryWindow.currentSymbol()));
    this._categoryWindow.setHandler('cancel', this.popScene.bind(this));
 
};

Code:
/*----------------------------------------------------------------------------*
* WINDOW FUNCTIONS *
/*----------------------------------------------------------------------------*/
//Window for the list of categories
function Window_IntelCategory() {this.initialize.apply(this, arguments);}
Window_IntelCategory.prototype = Object.create(Window_HorzCommand.prototype);
Window_IntelCategory.prototype.constructor = Window_IntelCategory;

Window_IntelCategory.prototype.initialize = function(x, y) {
    Window_HorzCommand.prototype.initialize.call(this, x, y);
    this.topicWindow = null;
    this._data = [];
};

Window_IntelCategory.prototype.windowWidth = function() {
    return Graphics.boxWidth;
};

Window_IntelCategory.prototype.maxCols = function() {
    return 5;
};

Window_IntelCategory.prototype.update = function() {
    Window_HorzCommand.prototype.update.call(this);
    if (this._topicWindow) {
        this._topicWindow.setCategory(this.currentSymbol());
    }
};
 
Window_IntelCategory.prototype.makeCommandList = function() {
    this.addCommand("All", 'all');
    this._data = ['all'];
    for (var index = 0; index < $gameParty.IntelList.IntelCategories.length; index++) {
        var result = $gameParty.IntelList.IntelCategories[index];
        this.addCommand(result, result);
        this._data.push(result);
    }
};

/*----------------------------------------------------------------------------*/
//Window for the list of topics.
function Window_IntelTopics() {this.initialize.apply(this, arguments);}
Window_IntelTopics.prototype = Object.create(Window_Selectable.prototype);
Window_IntelTopics.prototype.constructor = Window_IntelTopics;

Window_IntelTopics.prototype.initialize = function(x, y, width, height, contentsWindow) {
Window_Selectable.prototype.initialize.call(this, x, y, width, height);
    this._category = 'all';
    this._data = [];
    this._contentsWindow = contentsWindow;
};

Window_IntelTopics.prototype.windowWidth = function() {
    return Math.floor(Graphics.boxWidth * 0.3);
};

Window_IntelTopics.prototype.windowHeight = function() {
    return Graphics.boxHeight;
};

Window_IntelTopics.prototype.maxCols = function() {return 1;};
Window_IntelTopics.prototype.maxItems = function() {return this._data ? this._data.length : 1; };
Window_IntelTopics.prototype.itemWidth = function() {return Math.floor(Graphics.boxWidth * 0.4) + this.textPadding(); };

Window_IntelTopics.prototype.item = function() {
    var index = this.index();
    return this._data && index >= 0 ? this._data[index] : null;
};

Window_IntelTopics.prototype.makeIntelList = function() {
    if (this._category && this._category !== 'all') {
        this._data = $gameParty.IntelList.IntelItems.getIntelFromCategory(this._category);
    } else {
        this._data = $gameParty.IntelList.IntelItems;
    }
};

Window_IntelTopics.prototype.drawAllTopics = function() {
    this.makeIntelList();
    for (var index = 0; index < this._data.length; index++) {
        var intel = this._data[index];
        if (intel && this.maxItems() > index) {
            var rect = this.itemRect(index);
            rect.width -= this.textPadding();
            this.drawText(intel.topic, rect.x, rect.y, rect.width);
        }
    }
};

Window_IntelTopics.prototype.setCategory = function(category) {
    if (this._category !== category) {
        this._category = category;
        this.refresh();
        this.resetScroll();
    }
};

Window_IntelTopics.prototype.refresh = function() {
    this.makeIntelList();
    this.createContents();
    this.drawAllTopics();
};

Window_IntelTopics.prototype.item = function() {
    var index = this.index();
    return this._data && index >= 0 ? this._data[index] : null;
};

Window_IntelTopics.prototype.processCursorMove = function() {
    Window_Selectable.prototype.processCursorMove.call(this);
    var index = this.index();
    var intel = this._data[index];
    if (intel  && this._contentsWindow) {
        this._contentsWindow.drawContents(intel.contents);
    }
}
/*----------------------------------------------------------------------------*/
//Window to display the contents.
function Window_IntelContents() {this.initialize.apply(this, arguments);};
Window_IntelContents.prototype = Object.create(Window_Base.prototype);
Window_IntelContents.prototype.constructor = Window_IntelContents;

Window_IntelContents.prototype.initialize = function(x, y, width, height) {
    Window_Base.prototype.initialize.call(this, x, y, width, height);
};

Window_IntelContents.prototype.drawContents = function(contentsArray) {
    this.contents.clear();
    var linesAbove = 0;
    for (var x = 0; x < contentsArray.length; x++) {
        var contentsText = contentsArray[x];
        while (contentsText.length > 0) {
            var index = contentsText.length;
            while (this.contents.measureTextWidth(contentsText.slice(0, index)) > this.contentsWidth()) {
                index = contentsText.slice(0, index).lastIndexOf(" ");
            }
            this.contents.drawText(contentsText.slice(0, index), 0, linesAbove *this.lineHeight() - this.contentsHeight()/2, this.width, this.height, 'left');
            contentsText = contentsText.slice(index);
            linesAbove++;
        }
    }
};

In basic terms, what is the activate() method actually doing?

Also, I added in a function that should handle sorting based on the symbol of the current category, but it doesn't appear to work as-written...

Looking through how some of the other Scene_ objects handle things, part of the problem may be the absence of the .deselect() method. Will report back with results shortly.

EDIT: The reason for the peculiar column behavior in the categories menu was because I didn't have a maxItems method on the prototype; creating one resolved the issue. There's still quite a bit of weirdness with handling moving around the window, though.

EDIT 2: I've managed to get the menu cursor to behave the way I want it to, even if it's horrifically kludged together:
Code:
/*----------------------------------------------------------------------------*
 *        SCENE FUNCTIONS                                                          *
 *----------------------------------------------------------------------------*/
//Patch in the handler for the Intel command.
Scene_Menu.prototype.createCommandWindow = (function (original) {
    "use strict";
    function createCommandWindow() {
        original.call(this);

        this._commandWindow.setHandler("intel", function () {
            SceneManager.push(Scene_Intel);
        });
    }

    return createCommandWindow;
}(Scene_Menu.prototype.createCommandWindow));

//Patch the Intel command into the list of commands on the in-game menu.
Window_MenuCommand.prototype.addOriginalCommands = (function (original) {
    "use strict";
    function addOriginalCommands() {
        original.call(this);
        this.addCommand("Intel", "intel", ($gameParty.IntelList.IntelItems.length > 0));
    }

    return addOriginalCommands;
}(Window_MenuCommand.prototype.addOriginalCommands));

//Define initialization, prototype, and constructor.
function Scene_Intel() {this.initialize.apply(this, arguments);}
Scene_Intel.prototype = Object.create(Scene_MenuBase.prototype);
Scene_Intel.prototype.constructor = Scene_Intel;
Scene_Intel.prototype.initialize = function() {Scene_MenuBase.prototype.initialize.call(this);};

//Define creation and termination events.
Scene_Intel.prototype.create = function() {
    Scene_MenuBase.prototype.create.call(this);
    //this.createHelpWindow();
    this.createIntelCatsWindow();
    this.createIntelContentsWindow();
    this.createIntelTopicsWindow();
    this.setBindings();
    this._topicWindow.activate();
};

Scene_Intel.prototype.terminate = function() {
    Scene_MenuBase.prototype.terminate.call(this);
};

//Creates the category list.
Scene_Intel.prototype.createIntelCatsWindow = function() {
    this._categoryWindow = new Window_IntelCategory(0,0);
    this._categoryWindow.makeCommandList();
    this.addWindow(this._categoryWindow);
};

//Creates the window in which the contents will appear.
Scene_Intel.prototype.createIntelContentsWindow = function() {
    this._contentsWindow = new Window_IntelContents(Math.floor(Graphics.boxWidth*0.3), this._categoryWindow.height, Math.ceil(Graphics.boxWidth * 0.7), Graphics.boxHeight - this._categoryWindow.windowHeight());
    this.addWindow(this._contentsWindow);
};


//Creates the list of intel items.
Scene_Intel.prototype.createIntelTopicsWindow = function() {
    var catWindow = this._categoryWindow;
    this._topicWindow = new Window_IntelTopics(0, catWindow.height, Math.floor(Graphics.boxWidth * 0.3), Graphics.boxHeight - catWindow.windowHeight(), this._contentsWindow, catWindow); 
    this._topicWindow.drawAllTopics();
    this.addWindow(this._topicWindow);
    catWindow.topicWindow = this._topicWindow;
    
};

Scene_Intel.prototype.setBindings = function(){
    this._categoryWindow.setHandler('ok', this.onCategoryOK.bind(this));
    this._categoryWindow.setHandler('cancel', this.popScene.bind(this));
    
};

Scene_Intel.prototype.onCategoryOK = function() {
    this._categoryWindow.update();
    this._categoryWindow.deselect();
    this._topicWindow.activate();
    
}

/*----------------------------------------------------------------------------*
* WINDOW FUNCTIONS *
/*----------------------------------------------------------------------------*/
//Window for the list of categories
function Window_IntelCategory() {this.initialize.apply(this, arguments);}
Window_IntelCategory.prototype = Object.create(Window_HorzCommand.prototype);
Window_IntelCategory.prototype.constructor = Window_IntelCategory;

Window_IntelCategory.prototype.initialize = function(x, y) {
    Window_HorzCommand.prototype.initialize.call(this, x, y);
    this.topicWindow = null;
};

Window_IntelCategory.prototype.windowWidth = function() {return Graphics.boxWidth;};
Window_IntelCategory.prototype.maxCols = function() {return 5;};
Window_IntelCategory.prototype.maxItems = function() {return $gameParty.IntelList.IntelCategories.length + 1;};

Window_IntelCategory.prototype.update = function() {
    Window_HorzCommand.prototype.update.call(this);
    if (this._topicWindow) {
        this._topicWindow.setCategory(this.currentSymbol());
    }
};
  
Window_IntelCategory.prototype.makeCommandList = function() {
    this.addCommand("All", 'all');
    for (var index = 0; index < $gameParty.IntelList.IntelCategories.length; index++) {
        var result = $gameParty.IntelList.IntelCategories[index];
        this.addCommand(result, result);
    }
};
 
Window_IntelCategory.prototype.processCursorMove = function() {
    if (this.isCursorMovable()) {
        var lastIndex = this.index();
        if (Input.isRepeated('down')) {
            this.deselect();
        }
        if (Input.isRepeated('up')) {
            this.deselect();
        }
        if (Input.isRepeated('right')) {
            this.cursorRight(Input.isTriggered('right'));
        }
        if (Input.isRepeated('left')) {
            this.cursorLeft(Input.isTriggered('left'));
        }
        if (!this.isHandled('pagedown') && Input.isTriggered('pagedown')) {
            this.deselect();
        }
        if (!this.isHandled('pageup') && Input.isTriggered('pageup')) {
            this.deselect();
        }
        if (this.index() !== lastIndex) {
            SoundManager.playCursor();
        }
    }
};
 
/*----------------------------------------------------------------------------*/   
//Window for the list of topics.
function Window_IntelTopics() {this.initialize.apply(this, arguments);}
Window_IntelTopics.prototype = Object.create(Window_Selectable.prototype);
Window_IntelTopics.prototype.constructor = Window_IntelTopics;

Window_IntelTopics.prototype.initialize = function(x, y, width, height, contentsWindow, categoryWindow) {
Window_Selectable.prototype.initialize.call(this, x, y, width, height);
    this._category = 'all';
    this._data = [];
    this._contentsWindow = contentsWindow;
    this._categoryWindow = categoryWindow;
};

Window_IntelTopics.prototype.windowWidth = function() {
    return Math.floor(Graphics.boxWidth * 0.3);
};

Window_IntelTopics.prototype.windowHeight = function() {
    return Graphics.boxHeight;
};

Window_IntelTopics.prototype.maxCols = function() {return 1;};
Window_IntelTopics.prototype.maxItems = function() {return this._data ? this._data.length : 1; };
Window_IntelTopics.prototype.itemWidth = function() {return Math.floor(Graphics.boxWidth * 0.4) + this.textPadding(); };

Window_IntelTopics.prototype.item = function() {
    var index = this.index();
    return this._data && index >= 0 ? this._data[index] : null;
};

Window_IntelTopics.prototype.setCategory = function(category) {
    if (this._category !== category) {
        this._category = category;
        this.refresh();
        this.resetScroll();
    }
};

Window_IntelTopics.prototype.refresh = function() {
    this.makeIntelList();
    this.createContents();
    this.drawAllTopics();
};

Window_IntelTopics.prototype.makeIntelList = function() {
    if (this._category && this._category !== 'all') {
        this._data = $gameParty.IntelList.IntelItems.getIntelFromCategory(this._category);
    } else {
        this._data = $gameParty.IntelList.IntelItems;
    }
};

Window_IntelTopics.prototype.drawAllTopics = function() {
    this.makeIntelList();
    for (var index = 0; index < this._data.length; index++) {
        var intel = this._data[index];
        if (intel && this.maxItems() > index) {
            var rect = this.itemRect(index);
            rect.width -= this.textPadding();
            this.drawText(intel.topic, rect.x, rect.y, rect.width);
        }
    }
};

Window_IntelTopics.prototype.processCursorMove = function() {
        if (this.isCursorMovable()) {
        var lastIndex = this.index();
        if (Input.isRepeated('down')) {
            this.cursorDown(Input.isTriggered('down'));
        }
        if (Input.isRepeated('up')) {
            this.cursorUp(Input.isTriggered('up'));
        }
        if (Input.isRepeated('right')) {
            this.deselect();
            if (!this._categoryWindow.active) {
                this._categoryWindow.activate();
                this._categoryWindow.select(0);
            }
        }
        if (Input.isRepeated('left')) {
            this.deselect();
            if (!this._categoryWindow.active) {
                this._categoryWindow.activate();
                this._categoryWindow.select(0);
            }
        }
        if (!this.isHandled('pagedown') && Input.isTriggered('pagedown')) {
            this.cursorPagedown();
        }
        if (!this.isHandled('pageup') && Input.isTriggered('pageup')) {
            this.cursorPageup();
        }
        if (this.index() !== lastIndex) {
            SoundManager.playCursor();
        }
    }
    var index = this.index();
    var intel = this._data[index];
    if (intel  && this._contentsWindow) {
        this._contentsWindow.drawContents(intel.contents);
    }
};

Window_IntelTopics.prototype.activate = function() {
    this.active = true;
    this.select(0);
};
/*----------------------------------------------------------------------------*/
//Window to display the contents.
function Window_IntelContents() {this.initialize.apply(this, arguments);};
Window_IntelContents.prototype = Object.create(Window_Base.prototype);
Window_IntelContents.prototype.constructor = Window_IntelContents;

Window_IntelContents.prototype.initialize = function(x, y, width, height) {
    Window_Base.prototype.initialize.call(this, x, y, width, height);
};

Window_IntelContents.prototype.drawContents = function(contentsArray) {
    this.contents.clear();
    var linesAbove = 0;
    for (var x = 0; x < contentsArray.length; x++) {
        var contentsText = contentsArray[x];
        while (contentsText.length > 0) {
            var index = contentsText.length;
            while (this.contents.measureTextWidth(contentsText.slice(0, index)) > this.contentsWidth()) {
                index = contentsText.slice(0, index).lastIndexOf(" ");
            }   
            this.contents.drawText(contentsText.slice(0, index), 0, linesAbove *this.lineHeight() - this.contentsHeight()/2, this.width, this.height, 'left');
            contentsText = contentsText.slice(index);
            linesAbove++;
        }
    }
};

If there's a more elegant way to do this I'd desperately like to know it; I'm also still unable to get the Category sorting function to work.
 
Last edited:

Clock Out

Veteran
Veteran
Joined
Jun 14, 2016
Messages
92
Reaction score
45
First Language
English
Primarily Uses
RMMV
Yeah, I wouldn't try using processCursorMove() it's too painful. As far as wiring up the event handlers, I recommend doing it all in one spot like in the scene create() method where the code can get a reference to all the windows after they're initialized. That makes monkey patching the select() methods for category and topics windows easy, too.
Code:
/*:
 * @plugindesc Adds Intel-Gathering funcionality: itemized intel, checks for
 * event handling, and a menu for viewing collected Intel.
 * @author Camkitsune
 *
 * @param JsonFileName
 * @desc Filename for the JSON file containing the intel data.
 * @default Intel.json
 *
 * @param ShowAlerts
 * @desc Boolean toggles whether or not alert messages appear on intel gain/
 * update; functionality currently not implemeneted.
 * @default false
 */

/*----------------------------------------------------------------------------*
 *        PLUGIN SETUP                                                        *
 *----------------------------------------------------------------------------*/
// Get the plugin parameters.

var intelParameters = PluginManager.parameters("IntelSystem");

// Get the intel data from the json file.

DataManager.loadDataFile("$dataIntel", intelParameters.JsonFileName);

// Define getter for the IntelData.

DataManager.getIntelData = function (id) {
    return $dataIntel[Number(id)];
};

// Add the plugin commands.

Game_Interpreter.prototype.pluginCommand = (function (original) {
    "use strict";

    // Define the function that will replace the original.

    function pluginCommand(command, args) {
        original.call(this, command, args);

        if (command !== "Intel") {
            return;
        }

        var intelData = DataManager.getIntelData(args[1]);

        // Necessary for preventing data from being manipulated.

        var newIntel = new IntelItem(
            intelData.id,
            intelData.topic,
            intelData.category,
            intelData.contents
        );

        // Use slice so that only the arguments relating to contents are passed.

        newIntel.pruneContents(args.slice(2, args.length));

        switch (args[0]) {
        case "add":

            // intelData is also passed in to reduce calls to the DataManager.

            var result = $gameParty.IntelList.addIntel(newIntel, intelData);

            // TODO: create popup window.

            break;
        case "check":
            return $gameParty.IntelList.hasIntel(newIntel);
        case "showAlerts":
            intelParameters.ShowAlerts = args[1];
            break;
        case "debug":
            for (var index = 1; index < args.length; index++) {
                var debugIntel = DataManager.getIntelData(args[index]);

                $gameParty.IntelList.addIntel(
                    new IntelItem(
                        debugIntel.id,
                        debugIntel.topic,
                        debugIntel.category,
                        debugIntel.contents
                    ),
                    debugIntel
                );
            }

            break;
        default:
            break;
        }
    }

    return pluginCommand;
}(Game_Interpreter.prototype.pluginCommand));

// Add initialization of IntelList to $gameParty

Game_Party.prototype.initialize = (function (original) {
    "use strict";

    function initialize() {
        original.call(this);
        this.IntelList = new IntelList();
    }

    return initialize;
}(Game_Party.prototype.initialize));

/*----------------------------------------------------------------------------*
 *        CORE FUNCTIONS                                                      *
 *----------------------------------------------------------------------------*/

// Object constructor for IntelItem.

function IntelItem(idnum, topic, category, contents) {

    // ID is used to simplify the lookup process.

    this.id = idnum;

    // Topics are what the specific informatoin will appear on:
    // IE, the subject of the intel.

    this.topic = topic;

    // Categories are used for in-game filtering.

    this.category = category;

    // Array representing specific lines of information.

    this.contents = contents;
}

// Function is used as part of evaluation of whether a new intel item's contents
// are already in the player's Intel inventory.

IntelItem.prototype.matches = function (intelFromList) {
    var index = 0;

    // isMatch first checks if the topics match; while loop won't even start
    // if they don't.

    var isMatch = this.id === intelFromList.id;

    while (isMatch && index < this.contents.length) {

        // Step through the contents of the calling IntelItem; if the IntelItem
        // from the list is missing any of them, return false.

        isMatch = intelFromList.contents.indexOf(this.contents[index]) > -1;
        index++;
    }

    return isMatch;
};

// Function adds contents FROM the calling function TO the item given as an
// argument; the intent is that the item passed as an argument accesses
// the info from IntelList.

IntelItem.prototype.addNewContents = function (intelFromList, intelData) {
    var newContentsAdded = false;

    for (var index = 0; index < this.contents.length; index++) {
        var newContents = this.contents[index];
        var contentsIndex = intelFromList.contents.indexOf(newContents);

        if (contentsIndex === -1) {
            newContentsAdded = true;

            // Get the index of the contents from the data.

            var dataIndexOfNewContents = intelData.contents.indexOf(
                this.contents[index]
            );

            var dataIndexOfOldContents = 0;

            // This will cycle through the list item's contents until it finds
            // the last one that comes before the new item.

            while (
                dataIndexOfOldContents < intelFromList.contents.length &&
                dataIndexOfNewContents >
                    intelData.contents.indexOf(
                        intelFromList.contents[dataIndexOfOldContents]
                    )
            ) {
                dataIndexOfOldContents++;
            }

            intelFromList.contents.splice(
                dataIndexOfOldContents,
                0,
                this.contents[index]
            );
        }
    }

    return newContentsAdded;
};

// Function returns the IntelItem.contents array as a single formated string,
// ready to be written into the menu.

IntelItem.prototype.getContents = function () {
    var result = "";

    for (var x = 0; x < this.contents.length; x++) {
        result += "  " + this.contents[x];
    }

    return result;
};

// Function is used to remove contents.

IntelItem.prototype.pruneContents = function (args) {
    var index = this.contents.length;

    while (index > 0) {

        // If an index number is not in args, remove the contents at
        // that number.

        if (args.indexOf(index) === -1) {
            this.contents.splice(index, 1);
        }

        index--;
    }
};

// IntelList handles in-game inventory of IntelItems, provides
// sorting functionality.

function IntelList() {
    this.IntelItems = [];
    this.IntelCategories = [];
}

// Function updates the intel listing with new items, new categories, and
// new contents for extant items.  Returns a string for use with alerts.

IntelList.prototype.addIntel = function (targetIntel, intelData) {

    // Premature break if a null argument is added.

    if (!targetIntel) {
        return;
    }

    // Insert category if it isn't in the categories list.

    if (this.IntelCategories.indexOf(targetIntel.category) === -1) {
        this.IntelCategories.push(targetIntel.category);
        this.IntelCategories.sort();
    }

    var result = null;
    var dexVal = this.findIndex(targetIntel);

    if (dexVal === this.IntelItems.length) {
        this.IntelItems.push(targetIntel);
        result = "New intelligence file: " + targetIntel.topic;
    } else {
        var intelAtIndex = this.IntelItems[dexVal];

        if (intelAtIndex.id != targetIntel.id) {
            this.IntelItems.splice(dexVal + 1, 0, targetIntel);
            result = "New intelligence file: " + targetIntel.topic;
        } else {
            var contentsCheck = targetIntel.addNewContents(
                intelAtIndex,
                intelData
            );

            if (contentsCheck) {
                result = "Information updated: " + targetIntel.topic;
            }
        }
    }

    if (intelParameters.ShowAlerts) {
        return result;
    } else {
        return null;
    }
};

// Helper function for addIntel function; makes sure new intel is inserted
// alphabetically.

IntelList.prototype.findIndex = function (targetIntel) {
    var index = 0;
    var resultVal = 1;

    while (index < this.IntelItems.length && resultVal < 0) {
        resultVal = targetIntel.topic.localeCompare(
            this.IntelItems[index].topic
        );

        if (resultVal > 0) {
            index++;
        }
    }

    return index;
};

// Function determines whether or not the specified intel is present in the
// player's intel inventory.

IntelList.prototype.hasIntel = function (targetIntel) {

    //searchFunction must be defined this way due to how Array.some handles
    // the function.

    var searchFunction = function (intelFromList) {

        // The IntelItem.matches function checks to see if the intel item taken
        // from the list has the same ID as well as all of the contents it has.

        return targetIntel.matches(intelFromList);
    };

    return this.IntelItems.some(searchFunction);
};

// Returns an array of IntelItems with the specified topic.

IntelList.prototype.getIntelFromCategory = function (categoryName) {
    var result = [];

    for (var index = 0; index < this.IntelItems.length; index++) {
        if (this.IntelItems[index].category === categoryName) {
            result.push(this.IntelItems[index]);
        }
    }

    return result;
};

/*----------------------------------------------------------------------------*
 *        SCENE FUNCTIONS                                                     *
 *----------------------------------------------------------------------------*/
// Patch in the handler for the Intel command.

Scene_Menu.prototype.createCommandWindow = (function (original) {
    "use strict";

    function createCommandWindow() {
        original.call(this);

        this._commandWindow.setHandler("intel", function () {
            SceneManager.push(Scene_Intel);
        });
    }

    return createCommandWindow;
}(Scene_Menu.prototype.createCommandWindow));

// Patch the Intel command into the list of commands on the in-game menu.

Window_MenuCommand.prototype.addOriginalCommands = (function (original) {
    "use strict";

    function addOriginalCommands() {
        original.call(this);
        this.addCommand(
            "Intel",
            "intel",
            $gameParty.IntelList.IntelItems.length > 0
        );
    }

    return addOriginalCommands;
}(Window_MenuCommand.prototype.addOriginalCommands));

// Define initialization, prototype, and constructor.

function Scene_Intel() {
    this.initialize.apply(this, arguments);
}

Scene_Intel.prototype = Object.create(Scene_MenuBase.prototype);
Scene_Intel.prototype.constructor = Scene_Intel;

Scene_Intel.prototype.initialize = function () {
    Scene_MenuBase.prototype.initialize.call(this);
};

Scene_Intel.prototype.create = function () {
    var categories;
    var topics;
    var contents;

    Scene_MenuBase.prototype.create.call(this);
    this.createIntelCatsWindow();
    this.createIntelContentsWindow();
    this.createIntelTopicsWindow();

    categories = this._categoryWindow;
    topics = this._topicWindow;
    contents = this._contentsWindow;

    categories.select = (function (original) {
        var previousIndex = -1;

        return function (index) {
            original.call(categories, index);

            if (index === previousIndex) {
                return;
            }

            previousIndex = index;
            topics.refresh();
        };
    }(categories.select));

    topics.select = (function (original) {
        var previousIndex = -1;

        return function (index) {
            original.call(topics, index);

            if (index === previousIndex) {
                return;
            }

            previousIndex = index;

            if (this._data[index] !== undefined) {
                contents.drawContents(this._data[index].contents);
            }
        };
    }(topics.select));

    categories.setHandler("cancel", function () {
        this.popScene();
    }.bind(this));

    categories.setHandler("ok", function () {
        categories.deactivate();
        topics.select(0);
        topics.activate();
    });

    topics.setHandler("cancel", function () {
        topics.select(-1);
        topics.deactivate();
        contents.contents.clear();
        categories.activate();
    });

    topics.setHandler("ok", function () {
        topics.activate();
    });
};

// Creates the category list.

Scene_Intel.prototype.createIntelCatsWindow = function () {
    this._categoryWindow = new Window_IntelCategory(0, 0);
    this._categoryWindow.makeCommandList();
    this.addWindow(this._categoryWindow);
};

// Creates the window in which the contents will appear.

Scene_Intel.prototype.createIntelContentsWindow = function () {
    this._contentsWindow = new Window_IntelContents(
        Math.floor(Graphics.boxWidth * 0.3),
        this._categoryWindow.height,
        Math.ceil(Graphics.boxWidth * 0.7),
        Graphics.boxHeight - this._categoryWindow.windowHeight()
    );
    this.addWindow(this._contentsWindow);
};

// Creates the list of intel items.

Scene_Intel.prototype.createIntelTopicsWindow = function () {
    var catWindow = this._categoryWindow;

    this._topicWindow = new Window_IntelTopics(
        0,
        catWindow.height,
        Math.floor(Graphics.boxWidth * 0.3),
        Graphics.boxHeight - catWindow.windowHeight(),
        this._contentsWindow,
        catWindow
    );
    this._topicWindow.refresh();
    this.addWindow(this._topicWindow);
    catWindow.topicWindow = this._topicWindow;
};

/*----------------------------------------------------------------------------*
 * WINDOW FUNCTIONS                                                           *
 *----------------------------------------------------------------------------*/
// Window for the list of categories

function Window_IntelCategory() {
    this.initialize.apply(this, arguments);
}

Window_IntelCategory.prototype = Object.create(Window_HorzCommand.prototype);
Window_IntelCategory.prototype.constructor = Window_IntelCategory;

Window_IntelCategory.prototype.windowWidth = function () {
    return Graphics.boxWidth;
};

Window_IntelCategory.prototype.maxCols = function () {
    return 5;
};

Window_IntelCategory.prototype.maxItems = function () {
    return $gameParty.IntelList.IntelCategories.length + 1;
};

Window_IntelCategory.prototype.makeCommandList = function () {
    var categories = $gameParty.IntelList.IntelCategories;

    this.addCommand("All", "all");

    categories.forEach(function (command) {
        this.addCommand(command, command);
    }, this);
};

/*----------------------------------------------------------------------------*/
// Window for the list of topics.

function Window_IntelTopics() {
    this.initialize.apply(this, arguments);
}

Window_IntelTopics.prototype = Object.create(Window_Selectable.prototype);
Window_IntelTopics.prototype.constructor = Window_IntelTopics;

Window_IntelTopics.prototype.initialize = function (
    x,
    y,
    width,
    height,
    contentsWindow,
    categoryWindow
) {
    Window_Selectable.prototype.initialize.call(this, x, y, width, height);
    this._category = "all";
    this._data = [];
    this._contentsWindow = contentsWindow;
    this._categoryWindow = categoryWindow;
};

Window_IntelTopics.prototype.windowWidth = function () {
    return Math.floor(Graphics.boxWidth * 0.3);
};

Window_IntelTopics.prototype.windowHeight = function () {
    return Graphics.boxHeight;
};

Window_IntelTopics.prototype.maxCols = function () {
    return 1;
};

Window_IntelTopics.prototype.maxItems = function () {
    return this._data ? this._data.length : 1;
};

Window_IntelTopics.prototype.itemWidth = function () {
    return Math.floor(Graphics.boxWidth * 0.4) + this.textPadding();
};

Window_IntelTopics.prototype.item = function () {
    var index = this.index();

    return this._data && index >= 0 ? this._data[index] : null;
};

Window_IntelTopics.prototype.refresh = function () {
    this.makeIntelList();
    this.drawAllTopics();
};

Window_IntelTopics.prototype.makeIntelList = function () {
    var category = this._categoryWindow.currentSymbol();
    var intelList = $gameParty.IntelList;

    if (category !== "all") {
        this._data = intelList.getIntelFromCategory(category);
    } else {
        this._data = intelList.IntelItems;
    }
};

Window_IntelTopics.prototype.drawAllTopics = function () {
    this.contents.clear();

    this._data.forEach(function (intel, index) {
        var rect = this.itemRect(index);

        rect.width -= this.textPadding();
        this.drawText(intel.topic, rect.x, rect.y, rect.width);
    }, this);
};

/*----------------------------------------------------------------------------*/
//Window to display the contents.

function Window_IntelContents() {
    this.initialize.apply(this, arguments);
}

Window_IntelContents.prototype = Object.create(Window_Base.prototype);
Window_IntelContents.prototype.constructor = Window_IntelContents;

Window_IntelContents.prototype.initialize = function (x, y, width, height) {
    Window_Base.prototype.initialize.call(this, x, y, width, height);
};

Window_IntelContents.prototype.drawContents = function (contentsArray) {
    var linesAbove = 0;

    this.contents.clear();

    for (var x = 0; x < contentsArray.length; x++) {
        var contentsText = contentsArray[x];

        while (contentsText.length > 0) {
            var index = contentsText.length;

            while (
                this.contents.measureTextWidth(contentsText.slice(0, index)) >
                this.contentsWidth()
            ) {
                index = contentsText.slice(0, index).lastIndexOf(" ");
            }

            this.contents.drawText(
                contentsText.slice(0, index),
                0,
                linesAbove * this.lineHeight() - this.contentsHeight() / 2,
                this.width,
                this.height,
                "left"
            );
            contentsText = contentsText.slice(index);
            linesAbove += 1;
        }
    }
};

I made some changes to other functions as well but I kinda forget which ones. Some were changed just because I like replacing loops with array methods.
 

Camkitsune

Veteran
Veteran
Joined
Mar 9, 2017
Messages
34
Reaction score
4
First Language
English
Primarily Uses
RMMV
I only replaced the 'onCursorMove' patch for the Categories window, since I want the topic information to appear without the need of an additional button press.
I integrated the code as shown below:
Code:
function Scene_Intel() {this.initialize.apply(this, arguments);}
Scene_Intel.prototype = Object.create(Scene_MenuBase.prototype);
Scene_Intel.prototype.constructor = Scene_Intel;
Scene_Intel.prototype.initialize = function() {Scene_MenuBase.prototype.initialize.call(this);};

//Define creation and termination events.
Scene_Intel.prototype.create = function() {
    Scene_MenuBase.prototype.create.call(this);
    this.createIntelCatsWindow();
    this.createIntelContentsWindow();
    this.createIntelTopicsWindow();
    var categories = this._categoryWindow;
    var topics = this._topicWindow;
    var contents = this._contentsWindow;
    
    categories.select = (function (original){
        var prevIndex = -1;
        return function (index) {
            original.call(categories, index);
            if (index === prevIndex) {return;}
            prevIndex = index;
            topics.refresh();
        };
    }(categories.select));
    
    categories.setHandler("cancel", function () {this.popScene();}.bind(this));
    
    categories.setHandler("ok", function () {
        categories.deactivate();
        topics.select(0);
        topics.activate();
    });

    topics.setHandler("cancel", function () {
        topics.select(-1);
        topics.deactivate();
        contents.contents.clear();
        categories.activate();
    });

    topics.setHandler("ok", function () {topics.activate();});
};

Scene_Intel.prototype.terminate = function() {
    Scene_MenuBase.prototype.terminate.call(this);
};

//Creates the category list.
Scene_Intel.prototype.createIntelCatsWindow = function() {
    this._categoryWindow = new Window_IntelCategory(0,0);
    this._categoryWindow.makeCommandList();
    this.addWindow(this._categoryWindow);
};

//Creates the window in which the contents will appear.
Scene_Intel.prototype.createIntelContentsWindow = function() {
    this._contentsWindow = new Window_IntelContents(Math.floor(Graphics.boxWidth*0.25), this._categoryWindow.height, Math.ceil(Graphics.boxWidth * 0.75), Graphics.boxHeight - this._categoryWindow.windowHeight());
    this.addWindow(this._contentsWindow);
};


//Creates the list of intel items.
Scene_Intel.prototype.createIntelTopicsWindow = function() {
    var catWindow = this._categoryWindow;
    this._topicWindow = new Window_IntelTopics(0, catWindow.height, Math.floor(Graphics.boxWidth * 0.25), Graphics.boxHeight - catWindow.windowHeight(), this._contentsWindow, catWindow); 
    this._topicWindow.refresh();
    this.addWindow(this._topicWindow);
    catWindow.topicWindow = this._topicWindow;
    
};

/*----------------------------------------------------------------------------*
* WINDOW FUNCTIONS *
/*----------------------------------------------------------------------------*/
//Window for the list of categories
function Window_IntelCategory() {this.initialize.apply(this, arguments);}
Window_IntelCategory.prototype = Object.create(Window_HorzCommand.prototype);
Window_IntelCategory.prototype.constructor = Window_IntelCategory;

Window_IntelCategory.prototype.initialize = function(x, y) {
    Window_HorzCommand.prototype.initialize.call(this, x, y);
    this.topicWindow = null;
};

Window_IntelCategory.prototype.windowWidth = function() {return Graphics.boxWidth;};
Window_IntelCategory.prototype.maxCols = function() {return 5;};
Window_IntelCategory.prototype.maxRows = function() {return 1;};
Window_IntelCategory.prototype.maxItems = function() {return $gameParty.IntelList.IntelCategories.length + 1;};

Window_IntelCategory.prototype.update = function() {
    Window_HorzCommand.prototype.update.call(this);
    if (this._topicWindow) {
        var index = this.index();
        this._topicWindow.setCategory("Places");
    }
};
  
Window_IntelCategory.prototype.makeCommandList = function() {
    this.addCommand("All", 'all');
    for (var index = 0; index < $gameParty.IntelList.IntelCategories.length; index++) {
        var result = $gameParty.IntelList.IntelCategories[index];
        this.addCommand(result, result);
    }
};
 
 
/*----------------------------------------------------------------------------*/   
//Window for the list of topics.
function Window_IntelTopics() {this.initialize.apply(this, arguments);}
Window_IntelTopics.prototype = Object.create(Window_Selectable.prototype);
Window_IntelTopics.prototype.constructor = Window_IntelTopics;

Window_IntelTopics.prototype.initialize = function(x, y, width, height, contentsWindow, categoryWindow) {
Window_Selectable.prototype.initialize.call(this, x, y, width, height);
    this._category = 'all';
    this._data = [];
    this._contentsWindow = contentsWindow;
    this._categoryWindow = categoryWindow;
};

Window_IntelTopics.prototype.windowWidth = function() {
    return Math.floor(Graphics.boxWidth * 0.25);
};

Window_IntelTopics.prototype.windowHeight = function() {
    return Graphics.boxHeight;
};

Window_IntelTopics.prototype.maxCols = function() {return 1;};
Window_IntelTopics.prototype.maxItems = function() {return this._data ? this._data.length : 1; };
Window_IntelTopics.prototype.itemWidth = function() {return Math.floor(Graphics.boxWidth * 0.25) - this.textPadding() *2; };

Window_IntelTopics.prototype.item = function() {
    var index = this.index();
    return this._data && index >= 0 ? this._data[index] : null;
};

Window_IntelTopics.prototype.setCategory = function(category) {
    if (this._category !== category) {
        this._category = category;
        this.refresh();
        this.resetScroll();
    }
};

Window_IntelTopics.prototype.refresh = function() {
    this.makeIntelList();
    this.createContents();
    this.drawAllTopics();
};

Window_IntelTopics.prototype.makeIntelList = function() {
    if (this._category && this._category !== 'all') {
        this._data = $gameParty.IntelList.IntelItems.getIntelFromCategory(this._category);
    } else {
        this._data = $gameParty.IntelList.IntelItems;
    }
};

Window_IntelTopics.prototype.drawAllTopics = function() {
    this.makeIntelList();
    for (var index = 0; index < this._data.length; index++) {
        var intel = this._data[index];
        if (intel && this.maxItems() > index) {
            var rect = this.itemRect(index);
            rect.width -= this.textPadding();
            this.drawText(intel.topic, rect.x, rect.y, rect.width);
        }
    }
};

Window_IntelTopics.prototype.processCursorMove = function() {
    Window_Selectable.prototype.processCursorMove.call(this);
    var index = this.index();
    var intel = this._data[index];
    if (intel  && this._contentsWindow) {
        this._contentsWindow.drawContents(intel.contents, intel.pic);
    }
};

Window_IntelTopics.prototype.activate = function() {
    this.active = true;
    this.select(0);
};
/*----------------------------------------------------------------------------*/
//Window to display the contents.
function Window_IntelContents() {this.initialize.apply(this, arguments);}
Window_IntelContents.prototype = Object.create(Window_Base.prototype);
Window_IntelContents.prototype.constructor = Window_IntelContents;

Window_IntelContents.prototype.initialize = function(x, y, width, height) {
    Window_Base.prototype.initialize.call(this, x, y, width, height);
};

Window_IntelContents.prototype.standardFontSize = function() { return 20;};
Window_IntelContents.prototype.lineHeight = function() { return 28;};
Window_IntelContents.prototype.textPadding = function() {return 4;};

Window_IntelContents.prototype.drawContents = function(contentsArray, picLoc) {
    this.contents.clear();
    var linesAbove = 0;
    var indent = 0;
    if (picLoc) { indent = Window_Base._faceWidth; };
    for (var x = 0; x < contentsArray.length; x++) {
        var contentsText = "    " + contentsArray[x];
        while (contentsText && contentsText.length > 0) {
            if (linesAbove * this.lineHeight() > Window_Base._faceHeight) {
                indent = 0;
            }
            var index = contentsText.length;
            while (this.contents.measureTextWidth(contentsText.slice(0, index)) + indent > this.contentsWidth()) {
                index = contentsText.slice(0, index).lastIndexOf(" ");
            }   
            this.contents.drawText(contentsText.slice(0, index), indent, linesAbove *this.lineHeight() - this.contentsHeight()/2, this.contentsWidth() - indent, this.height, 'left');
            contentsText = contentsText.slice(index);
            linesAbove++;
        }
    }
};

This got the cursor moving through the menus as I wanted. Thanks for the help!
 

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

Latest Threads

Latest Posts

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,085
Members
137,583
Latest member
write2dgray
Top