What is the name for the window that holds the status icons?

Discussion in 'Learning Javascript' started by Poppie360, Jan 12, 2019.

Thread Status:
Not open for further replies.
  1. Poppie360

    Poppie360 chocobo wrangler Veteran

    Messages:
    115
    Likes Received:
    32
    Location:
    NH, USA
    First Language:
    English
    Primarily Uses:
    RMMV
    I am trying to find the window that in the battle scene that holds the states that are inflicted onto the actors for my *map* based battle system, using this
    [​IMG]
    I can call any window to the map, but the problem is finding that window in particular (and no, that "window_status" thing is not the name of the window I am looking for, it was just what I was trying when I first started looking.)

    (alternatively, if anyone knows another way to show the statuses on the map screen i would be happy to be told how to do that as well.)
     
    #1
  2. Poryg

    Poryg Pixie of the Emvee kingdom, Ham of a Hamster Veteran

    Messages:
    3,209
    Likes Received:
    7,654
    Location:
    Czech Republic
    First Language:
    Czech
    Primarily Uses:
    RMMV
    Window_BattleStatus
     
    #2
    Zevia likes this.
  3. Poppie360

    Poppie360 chocobo wrangler Veteran

    Messages:
    115
    Likes Received:
    32
    Location:
    NH, USA
    First Language:
    English
    Primarily Uses:
    RMMV
    are you sure? because when i initialized the window it seems like nothing showed up...
     
    #3
  4. Poryg

    Poryg Pixie of the Emvee kingdom, Ham of a Hamster Veteran

    Messages:
    3,209
    Likes Received:
    7,654
    Location:
    Czech Republic
    First Language:
    Czech
    Primarily Uses:
    RMMV
    There's an easy way to verify. Go to mv's dlc/rpgmakerweb freebies/ plugins or how it is called/Yami folder.
    Inside that you'll find a Window identifier plugin. Copy it inside your project and follow its instructions.
     
    #4
  5. Zevia

    Zevia Veteran Veteran

    Messages:
    580
    Likes Received:
    273
    First Language:
    English
    Primarily Uses:
    RMMV
    To confirm Poryg's assertion, if you hit F8 to bring up the developer console, go into a battle (or use battle test), and execute:
    Code:
    SceneManager._scene._statusWindow
    You'll see that it's an instance of Window_BattleStatus.

    You can also quickly confirm it's the Window that shows state icons in a default project by executing the following in a battle test:
    Code:
    $gameParty.battleMembers()[0].addState(4); // Poisons the Actor, displays the animation, but the icon doesn't display yet
    SceneManager._scene._statusWindow.refresh(); // Now the poison state icon displays
    
     
    #5
  6. Poppie360

    Poppie360 chocobo wrangler Veteran

    Messages:
    115
    Likes Received:
    32
    Location:
    NH, USA
    First Language:
    English
    Primarily Uses:
    RMMV
    alright, how would i go about creating and instance of the window in the map? i am able to pull up most windows (just tried window_options) and it worked, but when i try doing it with that window it doesn't show anything.
     
    #6
  7. Poryg

    Poryg Pixie of the Emvee kingdom, Ham of a Hamster Veteran

    Messages:
    3,209
    Likes Received:
    7,654
    Location:
    Czech Republic
    First Language:
    Czech
    Primarily Uses:
    RMMV
    That's because windows need to be initialized, resized and drawn and not every window does it for you. Check the game code.
     
    #7
  8. Kes

    Kes Global Moderators Global Mod

    Messages:
    18,928
    Likes Received:
    9,713
    First Language:
    English
    Primarily Uses:
    RMVXA

    I've moved this thread to Learning Javascript. Please be sure to post your threads in the correct forum next time. Thank you.

     
    #8
  9. Zevia

    Zevia Veteran Veteran

    Messages:
    580
    Likes Received:
    273
    First Language:
    English
    Primarily Uses:
    RMMV
    You could try:
    Code:
    var statusWindow = new Window_BattleStatus();
    SceneManager._scene.addWindow(statusWindow); // edited from addChild on suggestion from Poryg
    SceneManager._scene._statusWindow = statusWindow; // optional step, but makes referencing the statusWindow later easier
    statusWindow.open(); // probably the important part here - it's closed on initialization
    
    [​IMG]
     
    Last edited: Jan 12, 2019
    #9
    Poryg likes this.
  10. Poryg

    Poryg Pixie of the Emvee kingdom, Ham of a Hamster Veteran

    Messages:
    3,209
    Likes Received:
    7,654
    Location:
    Czech Republic
    First Language:
    Czech
    Primarily Uses:
    RMMV
    That's a suicide to use addChild for windows :p The reason is simple, addChild automatically adds it above every layer, including error/fps meter layer. MV has a special addWindow method for adding windows to scenes:
    Code:
    SceneManager._scene._statusWindow = new Window_BattleStatus();
    SceneManager._scene.addWindow(SceneManager._scene._statusWindow);
     
    #10
    Zevia likes this.
  11. Poppie360

    Poppie360 chocobo wrangler Veteran

    Messages:
    115
    Likes Received:
    32
    Location:
    NH, USA
    First Language:
    English
    Primarily Uses:
    RMMV
    oh, that did work, but i see now that the whole window is dragged along, i just want this part of it however:
    [​IMG]
     
    #11
  12. Poryg

    Poryg Pixie of the Emvee kingdom, Ham of a Hamster Veteran

    Messages:
    3,209
    Likes Received:
    7,654
    Location:
    Czech Republic
    First Language:
    Czech
    Primarily Uses:
    RMMV
    Welp, for that you'd need a custom window.
     
    #12
    Zevia likes this.
  13. Zevia

    Zevia Veteran Veteran

    Messages:
    580
    Likes Received:
    273
    First Language:
    English
    Primarily Uses:
    RMMV
    Duly noted - and good to know. I'm still picking up what methods are already available. I looked for a "hasState" method on Game_BattlerBase, Game_Actor and Game_Enemy the other day, implemented my own, then later discovered what I wanted is "isStateAffected".

    I guess you could also just do SceneManager._scene._windowLayer.addChild, but that's what addWindow does, anyhow.

    Do you literally just want the icons displayed in a column, or would you want the names next to them, too?
     
    Last edited: Jan 12, 2019
    #13
  14. Poppie360

    Poppie360 chocobo wrangler Veteran

    Messages:
    115
    Likes Received:
    32
    Location:
    NH, USA
    First Language:
    English
    Primarily Uses:
    RMMV
    well, at least i know where to start looking now, any suggestions on how i can do that? what i want is this:
    [​IMG]

    since i have the names all set up and whatnot, yes i do want just the icons
     
    Last edited: Jan 12, 2019
    #14
  15. gstv87

    gstv87 Veteran Veteran

    Messages:
    1,405
    Likes Received:
    496
    First Language:
    Spanish
    Primarily Uses:
    RMVXA
    rpg_windows, line 5504
    Code:
    Window_BattleStatus.prototype.drawBasicArea = function(rect, actor) {
        this.drawActorName(actor, rect.x + 0, rect.y, 150);
        this.drawActorIcons(actor, rect.x + 156, rect.y, rect.width - 156);
    };
    
     
    #15
  16. Zevia

    Zevia Veteran Veteran

    Messages:
    580
    Likes Received:
    273
    First Language:
    English
    Primarily Uses:
    RMMV
    Here's a plugin that provides you with a Window_StatusIconList. It'll work for both Enemies and Actors and is configurable in terms of icon sizes, number of rows of icons to display, window padding, and whether or not to show the base window skin. You'll still have to pass a battler in and specify the x and y coordinates as well as the window width.

    Make sure it's saved as "StateIconWindow.js". You can also download it from this post.
    Code:
    /*:
    * @plugindesc This is a tool that can be used by developers to create a window that just
    * contains state icons for a given battler (Actors or Enemies).
    * @author Zevia
    *
    * @help Create a new Zevia.Window_StatusIconList, passing in the battler whose state
    * icons you want to display, the x-coordinate of the window, the y-coordinate, and
    * the width of the window.
    *
    * For the number of rows specified in configuration, an icon will be drawn as long
    * as it will fit on the row. If it won't, it will go to the next row, until the
    * number of rows has been filled. At that point, no more icons will be drawn.
    *
    * Example:
    * var harold = $gameParty.battleMembers()[0];
    * var haroldIcons = new Zevia.Window_StatusIconList(harold, 0, 0, 150);
    * SceneManager._scene.addWindow(haroldIcons);
    *
    * To refresh the window, call the refresh() method.
    
    * @param iconWidth
    * @text Icon width
    * @type number
    * @desc The width of the icons you want to display, in pixels.
    * @default 28
    *
    * @param iconHeight
    * @text Icon height
    * @type number
    * @desc The height of the icons you want to display, in pixels.
    * @default 28
    
    * @param maxRows
    * @text Number of rows
    * @type number
    * @desc The number of rows of icons you want to display.
    * @default 1
    *
    * @param padding
    * @text Window padding
    * @type number
    * @desc The amount of extra space you want from the edges of the window to where the icons are drawn
    * @default 0
    *
    * @param hasBackground
    * @text Show Windowskin
    * @type boolean
    * @desc Whether or not the icons should use the base Windowskin or be transparent
    * @default false
    */
    
    (function(module) {
        'use strict';
    
        // Polyfill for older versions of RPG Maker MV
        Array.prototype.find = Array.prototype.find || function(finderFunction) {
            for (var i = 0; i < this.length; i++) {
                var element = this[i];
                if (finderFunction(element, i, this)) { return element; }
            }
        };
    
        module.Zevia = module.Zevia || {};
        var parameters = PluginManager.parameters('StateIconWindow');
        var iconWidth = parseInt(parameters.iconWidth);
        var iconHeight = parseInt(parameters.iconHeight);
        var maxRows = parseInt(parameters.maxRows);
        var padding = parseInt(parameters.padding);
        var hasBackground = !!parameters.hasBackground.match(/true/i);
    
        if (isNaN(iconWidth)) { iconWidth = 28; }
        if (isNaN(iconHeight)) { iconHeight = 28; }
        if (isNaN(maxRows)) { maxRows = 1; }
        if (isNaN(padding)) { padding = 8; }
    
        var Window_StatusIconList = module.Zevia.Window_StatusIconList = function() {
            this.initialize.apply(this, arguments);
        };
    
        Window_StatusIconList.prototype = Object.create(Window_Base.prototype);
        Window_StatusIconList.prototype.constructor = Window_StatusIconList;
    
        Window_StatusIconList.prototype.initialize = function(battler, x, y, width) {
            var height = (this.lineHeight() * maxRows) + (this.standardPadding() * 2);
            Window_Base.prototype.initialize.call(this, x, y, width, height);
            this._battler = battler;
            this.opacity = hasBackground ? 255 : 0;
            this.deactivate();
            this.refresh();
        };
    
        Window_StatusIconList.prototype.standardPadding = function() {
            return padding;
        };
    
        Window_StatusIconList.prototype.canFitIcon = function(row) {
            return ((row.length + 1) * iconWidth) < this.contentsWidth();
        };
    
        Window_StatusIconList.prototype.setDisplayedIcons = function() {
            this._displayedIcons = this._battler.allIcons().reduce(function(iconRows, icon) {
                var availableRow = iconRows.find(function(row) {
                    return this.canFitIcon(row);
                }.bind(this));
                if (availableRow) { availableRow.push(icon); }
                else {
                    if (iconRows.length === maxRows) { return iconRows; }
                    iconRows.push([icon]);
                }
                return iconRows;
            }.bind(this), []);
        };
    
        Window_StatusIconList.prototype.drawStateIcon = function(iconIndex, x, y, width, height) {
            this.contents.blt(
                ImageManager.loadSystem('IconSet'),
                iconIndex % 16 * Window_Base._iconWidth,
                Math.floor(iconIndex / 16) * Window_Base._iconHeight,
                Window_Base._iconWidth,
                Window_Base._iconHeight,
                x,
                y,
                width,
                height
            );
        };
    
        Window_StatusIconList.prototype.drawStateIcons = function() {
            this._displayedIcons.forEach(function(iconRow, row) {
                iconRow.forEach(function(icon, column) {
                    this.drawStateIcon(
                        icon,
                        iconWidth * column,
                        iconHeight * row,
                        iconWidth,
                        iconHeight
                    );
                }.bind(this));
            }.bind(this));
        };
    
        Window_StatusIconList.prototype.refresh = function() {
            this.setDisplayedIcons();
            this.contents.clear();
            this.drawStateIcons();
        };
    })(window);
    
    [​IMG]
     

    Attached Files:

    Last edited: Jan 12, 2019
    #16
  17. Poppie360

    Poppie360 chocobo wrangler Veteran

    Messages:
    115
    Likes Received:
    32
    Location:
    NH, USA
    First Language:
    English
    Primarily Uses:
    RMMV
    i have an error, do you know what to do with it?
    "TypeError: undefined is not a function↵ at null.<anonymous> (file:///C:/Users/Poppie/Desktop/Project1/js/plugins/StateIconWindow.js:94:41)↵ at Array.reduce (native)↵ at Window_StatusIconList.setDisplayedIcons (file:///C:/Users/Poppie/Desktop/Project1/js/plugins/StateIconWindow.js:93:57)↵ at Window_StatusIconList.refresh (file:///C:/Users/Poppie/Desktop/Project1/js/plugins/StateIconWindow.js:135:14)↵ at Window_StatusIconList.initialize (file:///C:/Users/Poppie/Desktop/Project1/js/plugins/StateIconWindow.js:81:14)↵ at new module.Zevia.Window_StatusIconList (file:///C:/Users/Poppie/Desktop/Project1/js/plugins/StateIconWindow.js:69:25)↵ at Game_Interpreter.eval (eval at <anonymous> (file:///C:/Users/Poppie/Desktop/Project1/js/plugins/YEP_CoreEngine.js:1740:10), <anonymous>:2:19)↵ at Game_Interpreter.command355 (file:///C:/Users/Poppie/Desktop/Project1/js/plugins/YEP_CoreEngine.js:1740:5)↵ at Game_Interpreter.executeCommand (file:///C:/Users/Poppie/Desktop/Project1/js/rpg_objects.js:8930:34)↵ at Game_Interpreter.update (file:///C:/Users/Poppie/Desktop/Project1/js/rpg_objects.js:8838:19)↵ at Game_Map.updateInterpreter (file:///C:/Users/Poppie/Desktop/Project1/js/rpg_objects.js:6115:27)↵ at Game_Map.update (file:///C:/Users/Poppie/Desktop/Project1/js/rpg_objects.js:6022:14)"
     
    #17
  18. Zevia

    Zevia Veteran Veteran

    Messages:
    580
    Likes Received:
    273
    First Language:
    English
    Primarily Uses:
    RMMV
    @Poppie360 Can you show me the event/script call/code you're using to create the window?
     
    Last edited: Jan 12, 2019
    #18
  19. Poppie360

    Poppie360 chocobo wrangler Veteran

    Messages:
    115
    Likes Received:
    32
    Location:
    NH, USA
    First Language:
    English
    Primarily Uses:
    RMMV
    [​IMG]
     
    #19
  20. Zevia

    Zevia Veteran Veteran

    Messages:
    580
    Likes Received:
    273
    First Language:
    English
    Primarily Uses:
    RMMV
    I just copied your event into my own project and it works fine, so I suspect it's a conflict with another plugin.

    Can you try creating a new project with no plugins in it, installing the plugin there, then copy-pasting that same script call into an event and running it there?

    If you get any errors, let me know - if they're the same as what you've already posted, you don't have to paste screenshots again. If you continue getting errors, can you try opening up the dev console with F8, running the following bit of code, then posting the results?

    Code:
    var harold = $gameParty.battleMembers()[0];
    console.log(harold, harold.allIcons, harold.allIcons());
    var haroldIcons = new Zevia.Window_StatusIconList(harold, 0, 0, 150);
    SceneManager._scene.addWindow(haroldIcons);
    
    I'm wondering if battleMembers() is returning an empty array or something.
     
    #20
Thread Status:
Not open for further replies.

Share This Page