Changing Opacity for Unusable Items?

Discussion in 'Javascript/Plugin Support' started by fallenlorelei, Mar 7, 2019.

  1. fallenlorelei

    fallenlorelei Veteran Veteran

    Messages:
    295
    Likes Received:
    336
    First Language:
    English
    Hi everyone!

    I am using the default item UI and would like to figure out how to remove the grayed out/slightly transparent look for items that aren't usable (ideally, back to 255, or maybe even 230 or something - but not as low as it is now).

    I went into rpg_windows and found on line 243:
    Code:
    Window_Base.prototype.translucentOpacity = function() {
        return 160;
    };
    Then on line 251:
    Code:
    Window_Base.prototype.changePaintOpacity = function(enabled) {
        this.contents.paintOpacity = enabled ? 255 : this.translucentOpacity();
    };
    I could change the "160" in the first code to something, but I do like having unusable skills being translucent. I just want the items in the item scene to appear normal so it isn't a wash of gray.

    I'd also like a separate js plugin to pop in instead of editing rpg_windows directly.

    Now I'm not sure which code effects the actual item window. I saw what might have been relevant lines on 1407 and 1984, but I'm not entirely certain.

    1407:
    Code:
    Window_Command.prototype.drawItem = function(index) {
        var rect = this.itemRectForText(index);
        var align = this.itemTextAlign();
        this.resetTextColor();
        this.changePaintOpacity(this.isCommandEnabled(index));
        this.drawText(this.commandName(index), rect.x, rect.y, rect.width, align);
    };
    1984:
    Code:
    Window_ItemList.prototype.drawItem = function(index) {
        var item = this._data[index];
        if (item) {
            var numberWidth = this.numberWidth();
            var rect = this.itemRect(index);
            rect.width -= this.textPadding();
            this.changePaintOpacity(this.isEnabled(item));
            this.drawItemName(item, rect.x, rect.y, rect.width - numberWidth);
            this.drawItemNumber(item, rect.x, rect.y, rect.width);
            this.changePaintOpacity(1);
        }
    };
    
    Anyone think they can help out? :)

    Thanks!
     
    #1
  2. CaRa_CrAzY

    CaRa_CrAzY Undefined Custom Title Veteran

    Messages:
    37
    Likes Received:
    16
    Location:
    São Paulo - Brazil
    First Language:
    Portuguese
    Primarily Uses:
    Other
    I don't own MV, so I don't know if this will work for sure, but I think you can try this.

    Edit this line of code:
    Code:
    this.changePaintOpacity(this.isEnabled(item));
    For this:
    Code:
    this.contents.paintOpacity = this.isEnabled(item) ? 255 : 230;
     
    #2
  3. fallenlorelei

    fallenlorelei Veteran Veteran

    Messages:
    295
    Likes Received:
    336
    First Language:
    English
    @CaRa_CrAzY Yay, it worked!! Thank you :D So glad that was a simple enough solution.

    For anyone in the future, I decided to put the whole snippet into its own plugin without need to edit rpg_window:
    Code:
    Window_ItemList.prototype.drawItem = function(index) {
        var item = this._data[index];
        if (item) {
            var numberWidth = this.numberWidth();
            var rect = this.itemRect(index);
            rect.width -= this.textPadding();
            this.contents.paintOpacity = this.isEnabled(item) ? 255 : 230;
            this.drawItemName(item, rect.x, rect.y, rect.width - numberWidth);
            this.drawItemNumber(item, rect.x, rect.y, rect.width);
            this.changePaintOpacity(1);
        }
    };
    
     
    #3
  4. Magnus0808

    Magnus0808 Software Developer Veteran

    Messages:
    116
    Likes Received:
    109
    First Language:
    Danish
    Primarily Uses:
    RMMV
    @fallenlorelei Okay, what you did is not good practice at all. It will make your plugin incompatible with any plugin that changes how an item in the ItemList is drawn. However, you did identify the correct method to override:
    Code:
    Window_Base.prototype.translucentOpacity = function() {
        return 160;
    };
    But as you said you only want it to affect the item list and not e.g. the skills. What you should do is this:
    Code:
    Window_ItemList.prototype.translucentOpacity = function() {
        return 230;
    };
    Now it will only affect the item list instead. The way this works is that Window_ItemList actually inherits from Window_Selectable which inturn inherits from Window_Base. So using the code above will only overide the method of the Window_ItemList.

    Now if we want to be a bit fancy and add a plugin parameter so you can easily change the opacity from the editor instead of having to change in the code we can add this:
    Code:
     /*:
     * @param Item List Opacity
     * @type Number
     * @desc The translucent opacity of the Item List
     * @default 160
     */
    
    var ItemListOpacityChange = {};
    ItemListOpacityChange.opacity = Number(PluginManager.parameters('PLUGIN_NAME')['Item List Opacity']);
    Then put it all together and make a plugin like this:
    Code:
    //=============================================================================
    // Item List Opacity Change
    // MRP_ItemListOpacityChange.js
    // By Magnus0808 || Magnus Rubin Peterson
    //=============================================================================
    
    /*:
     * @plugindesc Change the translucent opacity of the item list.
     * @author Magnus0808
     *
     * @help Change the plugin parameter to the translucent opacity you want for
     * the item list.
     *
     * @param Item List Opacity
     * @type Number
     * @desc The translucent opacity of the Item List
     * @default 160
     */
     
     (function(){
        var MRP_ItemListOpacityChange = {};
        MRP_ItemListOpacityChange.opacity = Number(PluginManager.parameters('MRP_ItemListOpacityChange')['Item List Opacity']);
       
       
        Window_ItemList.prototype.translucentOpacity = function() {
            return MRP_ItemListOpacityChange.opacity;
        }
     })();
     
    #4
    Engr. Adiktuzmiko and CaRa_CrAzY like this.
  5. fallenlorelei

    fallenlorelei Veteran Veteran

    Messages:
    295
    Likes Received:
    336
    First Language:
    English
    #5

Share This Page