MV How to make a Window appear while hovering an object?

1636913251656.png

So, this is something I've made for my self programmed game. So when your mouse is hovering over an item, the box there appears at the bottom left point of the item. And the reason I don't know how to implement something similar is that it's all made with DOM elements, so I don't know how to get this and/or create this type of data on a canvas.

I'd like to know how to make a window do the same. And I believe the only thing I need to know is how to make a function that runs upon hovering. I should be able to figure out the rest 😀

Best regards,
Bishiba

Edit:
I don't know if I was unclear, if the question is unclear, please tell me. I also changed the title.
@caethyril I know you're great at Windows, so do you have any thoughts?
I'll use "tooltip" to refer to the box with extra information, and "parent" to refer to the window/scene containing the reference that the tooltip is explaining.

This can be split into parts:
  1. Define the tooltip object, e.g. a custom sprite or game window.
    • Unless you really want it to use the windowskin, I suggest defining the tooltip as a new Sprite subclass rather than a game window. This is because game windows all render in one layer by default, making them poorly-suited to layered elements like this.

    • If the tooltip may need to display outside the bounds of the parent, it should generally be a child of the scene or something, not that game window.

    • Alternatively, it's all HTML so I'm pretty sure you could use a DOM element if you want. You'd just need to make sure the element displays on top of the canvas.

  2. Determine when/where to show the tooltip (triggers).
    • If the parent inherits from Window_Selectable, you could hook into its select method and update the tooltip through there. Selectable windows also have an itemRect method that can be referenced for positioning.

    • Otherwise, consider hooking into the parent's update method to check the current screen touch coordinates (TouchInput.x, TouchInput.y) vs the parent's contents each frame, then update the tooltip as needed.
Actually updating the tooltip should be fairly simple: change its position and refresh its contents. 😮‍💨
I'll use "tooltip" to refer to the box with extra information, and "parent" to refer to the window/scene containing the reference that the tooltip is explaining.

This can be split into parts:
  1. Define the tooltip object, e.g. a custom sprite or game window.
    • Unless you really want it to use the windowskin, I suggest defining the tooltip as a new Sprite subclass rather than a game window. This is because game windows all render in one layer by default, making them poorly-suited to layered elements like this.

    • If the tooltip may need to display outside the bounds of the parent, it should generally be a child of the scene or something, not that game window.

    • Alternatively, it's all HTML so I'm pretty sure you could use a DOM element if you want. You'd just need to make sure the element displays on top of the canvas.

  2. Determine when/where to show the tooltip (triggers).
    • If the parent inherits from Window_Selectable, you could hook into its select method and update the tooltip through there. Selectable windows also have an itemRect method that can be referenced for positioning.

    • Otherwise, consider hooking into the parent's update method to check the current screen touch coordinates (TouchInput.x, TouchInput.y) vs the parent's contents each frame, then update the tooltip as needed.
Actually updating the tooltip should be fairly simple: change its position and refresh its contents. 😮‍💨
Thanks, well I would prefer to use the window skin 😛

For clarity, the tooltip should appear when putting the mouse over the red-circled state.
1637093388071.png


The reason I can't use DOM elements the way I did with my other game is that each of the icons are a <div>(I think it was div at least), and then I am just using the default onmouseover and onmouoseout functions that are native to the DOM element. But since in RPG maker it's drawn on the canvas I can't access that, since it doesn't exist 😛


**********************************************************************************

I think I will do it something like below, unless I get some objections:
Create a new Window_Tooltip class.
It will appear when hovering any object defined with a showTooltip() function.

The showTooltip function will be added to Scene.prototype.showTooltip(). This way it can always be called from any scene.

If the active Scene uses Window_Tooltip and is active. Then the TouchInput.isMoved() will trigger and parse the x and y coordinates to BISH.checkMouse(). This will check if the x and y coordinates exist in the array function BISH.tooltip["x, y"].

The x and y coordinates will be compared in BISH.checkMouse(), it will be compared to any value that contains a tooltip area.

The Window_Tooltip will fade in over 0.5(or so) seconds. This will be achieved by modifying the .show() function. The .hide() function will be changed accordingly.

I will try and get the corresponding coordinates from the TouchInput.isMoved() function.
JavaScript:
TouchInput.isMoved = function() {
    if (BISH.windowTooltipActive) { //This bool value is set to true upon creating the Window_Tooltip. It is set to false when closing the parent Scene.
        BISH.actScene.checkMousePos(TouchInput._mouseOverX, TouchInput._mouseOverY); //Parses the mouse position.
    }
    return this._moved;
};

BISH.tooltip = [];

BISH.checkMousePos(x, y) {
    if (BISH.isTooltip[coord(x,y))) actScene.showTooltip(x, y); //coord(x, y) returns a string: "x, y".
}
};

As it is constantly updating, this might cause some lag issues or some other issues. So far I've not noticed anything, when logging the x and y values. But it remains to be seen whilst it is actively used.

**********************************************************************************
Remember that the above is essentially just a mock up. All the code I've written for this is actually in the code spoiler. This is primarily due to this being more of a side project than a primary project 😛 I am aware that the code is very clunky and that it is doing some redundant stuff. But try to see what concept I am after rather than the exact code 🙂 I am also quite sure I can easily avoid using my own class BISH, that's something I tend to strive for.

@caethyril I am unsure if something you wrote could be utilized for the above. I did use the touchinput, but there might be more things that could be used. Like perhaps the itemRect you mentioned, but it was tied to the selectable, so I do not know actually.
@bishiba: yes, by default Window_BattleStatus paints the icons to its canvas: there is no representative object/sprite to check other than the coordinates where the icon has been drawn. (This may vary depending on what plugins you're using.)

Remember that the TouchInput coordinates are relative to the screen, but the icon's position will be relative to:
  • The current screen position of the Window_BattleStatus instance; and
  • The coordinates of the relevant actor's itemRect within that game window.
You can use this.itemRect(index) in a Window_BattleStatus context to get the rectangle for that index (window coordinates). You should be able to find the icon offset(s) somewhere in your project's plugins and/or the core scripts.

Also, TouchInput.isMoved may be checked multiple times per frame! Instead, as I mentioned in my previous post, I'd recommend that you update the tooltip via the update method of the relevant game window(s), especially if the tooltip is only for Window_BattleStatus or should update differently for different window classes.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-make-a-window-appear-while-hovering-an-object.142126/