Icon Captions

● ARCHIVED · READ-ONLY
Started by Astfgl66 55 posts Page 3 of 3 View original ↗
  1. You can't do this.lineHeight() = 28 because you can't assign a value to the return value of a function.

    What you can do is overwrite lineHeight so that it returns a different value.

    You're thinking of this somewhat backwards; aliasing a function doesn't mean you then have to replace every reference to it in the code with your new name for it. Let me think how best to explain this...

    Let's say I want to add a new property to Game_System, called _bestiaryEnabled or something, to determine whether or not to display an option for it in the menu. Although I COULD do:

    Code:
    Game_System.prototype.initialize = function() {
        this._saveEnabled = true;
        this._menuEnabled = true;
        this._encounterEnabled = true;
        this._formationEnabled = true;
        this._battleCount = 0;
        this._winCount = 0;
        this._escapeCount = 0;
        this._saveCount = 0;
        this._versionId = 0;
        this._framesOnSave = 0;
        this._bgmOnSave = null;
        this._bgsOnSave = null;
        this._windowTone = null;
        this._battleBgm = null;
        this._victoryMe = null;
        this._defeatMe = null;
        this._savedBgm = null;
        this._walkingBgm = null;
       this._bestiaryEnabled = null;
    };

    it means I have to copy the entirety of the function I'm rewriting, even though I'm *adding* something to it. And if other plugins also rewrote this function, I'd be undoing those changes if my plugin comes afterwards. It's much better to alias the function instead:

    Code:
    Trihan.TLB_Game_System_Initialize = Game_System.prototype.initialize;
    Game_System.prototype.initialize = function() {
       Trihan.TLB_Game_System.Initialize.call(this);
       this._bestiaryEnabled = null;
    }

    The point is that I've rewritten the initialize function, but I stored the original function in a variable *before* doing that so that the original is still callable in code, meaning I can have it do whatever the original did before my additions without having to replicate the whole thing.

    That doesn't mean I have to replace every reference to the function with my new name for it, because the whole point of rewriting the function is that other places in code that call it use my new version instead of the old one.
  2. Astfgl66 said:
    lineHeight is a function of window base, thus is extended to all its instances. This is why there is no defined lineHeight function for the iconCaption window. It's in the parent class window base. Change the lineheight by changing the window icon caption lineHeight function.

    You can just add this snippet to the plugin file.
    Code:
    Window_IconCaption.prototype.lineHeight = function() {
        return 36; //or whatever number you want it to be
    };

    It's the same thing for font size. Look into window base, find the fontsize function and change it for window iconCaption.

    Also look at trihan's post for an explanation as to why you're getting an error message.
    Now this is odd, I did as you suggested and was able to get font size to change, but line height remained the same for some reason... I added this before the closing bracket of the plugin's function:
    JavaScript:
        Window_IconCaption.prototype.standardFontSize = function() {
            return 21; //or whatever number you want it to be
        };
      
        Window_IconCaption.prototype.lineHeight = function() {
            return 28; //or whatever number you want it to be
        };
    The fact that font size successfully changed leads me to believe there's something wrong w/ the line-height portion of this addition, and not due to placement. Hmm, what else could it be?...
  3. Frostorm said:
    Now this is odd, I did as you suggested and was able to get font size to change, but line height remained the same for some reason... I added this before the closing brack of the plugin's function:
    JavaScript:
        Window_IconCaption.prototype.lineHeight = function() {
            return 28; //or whatever number you want it to be
        };
    
        Window_IconCaption.prototype.standardFontSize = function() {
            return 21; //or whatever number you want it to be
        };
    The fact that font size successfully changed leads me to believe there's something wrong w/ the line-height portion of this addition, and not due to placement. Hmm, what else could it be?...

    In the parts of the window that call lineHeight, how exactly are they doing so?
  4. Trihan said:
    In the parts of the window that call lineHeight, how exactly are they doing so?
    Like so:
    JavaScript:
         Window_Base.prototype.updateCaptions = function() {
             if (!$gameSwitches.value(Number(showCaptions))) {return}
             if (!this.visible) {return}
             if (this._iconCaptions) {
                 var x = this.x + this._padding;
                 var y = this.y + this._padding;;
                 var win = this;
                 this._iconCaptions.forEach(function(caption){
                    if (IconCaptions[caption[2]] && IconCaptions["cond"+caption[2]] !== undefined && !eval(IconCaptions["cond"+caption[2]])) {return}
                    if (TouchInput._mouseX >= (caption[0][0] + x) && TouchInput._mouseX <= (caption[1][0] + x) && TouchInput._mouseY >= (caption[0][1] + y) && TouchInput._mouseY <= (caption[1][1] + y)) {
                        if (!SceneManager._scene._captionWindow) {
                            var captionWindow = new Window_IconCaption(caption[0][0] + x, caption[1][0] + y + win.lineHeight(),800,600)
                            captionWindow.height = win.lineHeight() + win._padding * 2
                            captionWindow.width = 100;
                            captionWindow.hide();
                            SceneManager._scene._captionWindow = captionWindow
                            SceneManager._scene.addChild(SceneManager._scene._captionWindow);
                        } else {
                            if (win instanceof Window_Gold && $gameParty.inBattle()) {return}
                            if (win instanceof Window_Gold && SceneManager._scene instanceof Scene_Map) {return}
                            if (!win.visible) {return}
                            var captionWindow = SceneManager._scene._captionWindow;
                            captionWindow._index = caption[2];
                            captionWindow.isHovered = true;
                            captionWindow.x = caption[0][0] + x;
                            captionWindow.y = caption[0][1] + y + win.lineHeight();
                            var lineNum = 1;
                            if (IconCaptions[caption[2]]) {
                                lineNum = IconCaptions[caption[2]].split(/\r\n|\r|\n/).length
                            }
                            if (captionWindow.y + captionWindow.height > Graphics.boxHeight) {
                                captionWindow.y = caption[0][1] + y - win.lineHeight() * (1+ lineNum);
                            }
                            if (captionWindow.x + captionWindow.width > Graphics.boxWidth) {
                                captionWindow.x -= captionWindow.width
                            }
                            if (captionWindow.x < 0) {
                                captionWindow.x = 0
                            }
                            captionWindow.height = win.lineHeight() * lineNum + win._padding *2;
                        }
                    }
                 })
             }
         }
    That chunk is repeated 3 times throughout the plugin or at least in a similar fashion, so lineHeight is used a total of 15 times.

    Btw, Yanfly's Core plugin uses the same method for changing lineHeight:
    JavaScript:
    Window_Base.prototype.lineHeight = function() {
      return Yanfly.Param.LineHeight;
    };
    So maybe it's not an issue with syntax, but something else?
  5. You have "var win = this" meaning win will be a Window_Base, not a Window_IconCaption. It'll therefore use the lineHeight function of Window_Base even though a later class rewrote it.

    Change "win.lineHeight()" to "captionWindow.lineHeight()".

    That SHOULD work, though I'm a bit iffy on the idea of a base class creating instances of its child classes in one of its own functions.
  6. Trihan said:
    You have "var win = this" meaning win will be a Window_Base, not a Window_IconCaption. It'll therefore use the lineHeight function of Window_Base even though a later class rewrote it.

    Change "win.lineHeight()" to "captionWindow.lineHeight()".

    That SHOULD work, though I'm a bit iffy on the idea of a base class creating instances of its child classes in one of its own functions.
    Yea I noticed that too, idk why the plugin was written like that but I didn't question it. I'll try your suggestion rn, thx.

    Edit: Nope, it threw a "Cannot read property 'lineHeight' of undefined"
    it's probably because changing var captionWindow = new Window_IconCaption(caption[0][0] + x, caption[1][0] + y + win.lineHeight(),800,600) to use captionWindow instead of win for win.lineHeight() means it's trying to define itself? Or some kind of circular logic I don't know how to explain lol.
  7. I mean if I were writing that I'd have made updateCaptions a function of Window_IconCaption, but maybe that's just me. :p I like having my functions as parts of the classes they belong to.
  8. I just changed every instance of win.lineHeight() to (win.lineHeight() - 8) lol. Not as elegant, but it gets the job done!
  9. Ah yes, it's been a while since I've looked at my code.
    Window iconCaption is just used to display the captions. Each window detects if you're hovering over an icon that has a caption within its frame. I made it like this because each icon when drawn is registered in an array in the window.
    Window_IconCaption could have checked all active windows to see if an icon in their arrays was being hovered I guess that would have worked too.
    I figured with different windows updating at different times and frequency having it update per window was better.

    I could probably save myself a bit of an headache and have caption priority be in function of their order in the children array of the scene instead of coding it manually for skill list and item list. I guess I'll keep that in mind if I make this again for MZ.
  10. It's still a pretty cool plugin regardless. :)
  11. Omg, thank you, guys!:kaoluv:
  12. Oh, thank you for this! Does this work if the icon is also added to say, just a text window and not in a menu or battle?
  13. I have been made aware via PM that the plugin did not work on new projects due to an improper variable declaration.

    I don't know why this just pops up now 3 years after my last update, and a quick check assured me it is still working without issue in my projects from 2019, but anyway, the plugin has been updated and should now work on new projects for those that are considering using it.

    As before, REMEMBER TO SAVE YOUR CAPTIONS BEFORE UPDATING, if you overwrite your captions when copying the new file they'll be lost.
  14. Well I am glad that you updated the plugin simply because that's how I became aware of it :rswt
    It looks to be exactly what I was looking for when I was googling for "tooltip" plugins. Will give it a try later :rhappy:
  15. hello there, i'd like to ask but is it possible to have this icon caption work on transparent background or a dim one ?