bishiba

Adept
Veteran
Joined
Apr 6, 2016
Messages
234
Reaction score
132
First Language
Swedish
Primarily Uses
N/A
Hello!

I need to add a handler to a window. I was thinking of using a simple target.addEventListener, but I realized I want to use this for the window.

I tried adding it as follows:
JavaScript:
    this._buyWindow.setHandler('control', this.onCompare.bind(this)); //Adding onCompare handler
    this._buyWindow.width = ww;
    this.addWindow(this._buyWindow);
};

Scene_Shop.prototype.onCompare = function() {
    console.log(this);
};

As found in rpgcore.js:
JavaScript:
Input.keyMapper = {
    9: 'tab',       // tab
    13: 'ok',       // enter
    16: 'shift',    // shift
    17: 'control',  // control
    18: 'control',  // alt

When it did not work, I looked into what the possible keys in Input.keyMapper was, I then noticed that there was no 'cancel'. And since some, or most, windows and such utilize the symbol 'cancel'. It became clear that this was not the place to look...

I then went into Window_Selectable. But sadly it is so much new information that I decided to just post and request some assistance! :) As always, I will keep going over the information available to me and update as I go.

So, how do I enable it so that when a player presses ctrl/alt the function onCompare triggers?

Best regards,

Update:
So I managed to get it working, sort of...
JavaScript:
Window_ShopBuy.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.cursorRight(Input.isTriggered('right'));
        }
        if (Input.isRepeated('left')) {
            this.cursorLeft(Input.isTriggered('left'));
        }
        if (!this.isHandled('pagedown') && Input.isTriggered('pagedown')) {
            this.cursorPagedown();
        }
        if (!this.isHandled('pageup') && Input.isTriggered('pageup')) {
            this.cursorPageup();
        }
        if (!this.isHandled('control') && Input.isTriggered('control')) {
            this.onCompare();
            SoundManager. playCursor();
        }
        if (this.index() !== lastIndex) {
            SoundManager. playCursor();
        }
    }
};
This way, I get the this part and it happens upon using ctrl/alt within the shopBuy window.
However, this is not dependent on an event handler for the Scene. So now this refers to the window rather than the scene. This could complicate certain aspects, but I am sure it should work.

I am still interested in understand how to add an event handler :)
 
Last edited:

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
2,978
Reaction score
2,302
First Language
EN
Primarily Uses
RMMZ
Yes: as you discovered, the handler symbol is not treated as a button name. setHandler simply stores the given callback under the given symbol. The isHandled and callHandler methods are then used to check whether a given symbol is handled, and if so then invoke the appropriate response.

For this, you would typically extend the window's processHandling method:
JavaScript:
Window_Selectable.prototype.processHandling = function() {
    if (this.isOpenAndActive()) {
        if (this.isOkEnabled() && this.isOkTriggered()) {
            this.processOk();
        } else if (this.isCancelEnabled() && this.isCancelTriggered()) {
            this.processCancel();
        } else if (this.isHandled('pagedown') && Input.isTriggered('pagedown')) {
            this.processPagedown();
        } else if (this.isHandled('pageup') && Input.isTriggered('pageup')) {
            this.processPageup();
        }
    }
};
E.g.
JavaScript:
(function(alias) {
  Window_ShopBuy.prototype.processHandling = function() {
    alias.apply(this, arguments);
    if (this.isOpenAndActive()) {
      if (this.isHandled('control') && Input.isTriggered('control')) {
        this.callHandler('control');
      }
    }
  };
})(Window_ShopBuy.prototype.processHandling);
processHandling is invoked as part of the update method of Window_Selectable. :kaohi:

[Some minor edits for clarity.]
 
Last edited:

Latest Threads

Latest Posts

Latest Profile Posts

"16. Do NOT contact other members by private message, on the forum or status feed, inviting them to put additional tools (such as leaderboards, ads, etc - whether yours or another person's) into their game."
Oh no. Necessity is the mother of invention. Do I want to know what happened?
Early WIP for my next entry. Since it's early you're going to need to wait a little longer than usual. What's that? You'll find out in my next update!
12.PNG
20 festive cards can now be unlocked in BiteMe!

The cards are permanent, but can only be unlocked in December!
Once the year is over, you won't be able to unlock the cards, or to upgrade it.
https://johndoenews.itch.io/biteme-storymodeCard141-160-Ad.png
Finally showing some updates again

Forum statistics

Threads
117,181
Messages
1,105,243
Members
153,306
Latest member
SuNWukng
Top