bishiba

Adept
Veteran
Joined
Apr 6, 2016
Messages
238
Reaction score
135
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,979
Reaction score
2,303
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

DavidUchina wrote on caethyril's profile.
You chad, thanks a lot for your plugins. You helped me costumize the buttons in my game.
I created the first teaser for my game! I decided to make an animation of Cabaret Helen advertising the Pizza Time Theater, set to an actual radio commercial. But this is no ordinary advertisement...
"Somber melody and stunning visuals takes one through the bittersweet tale of False Rebirth" ~ Marmalade
https://rpgmaker.net/games/12069/reviews/7576/

Got a first review on my game, on RPG Maker dot net. :kaothx:
Nightmare... Dreamt I posted a GFX resource post. With a work in progress glove icon that tinted to different colors. In the wrong forum. And I was in such a panic. I saw people writing posts in response, those "..." you see in discord and such. So I frantically tried to report my post as wrong forum, editing to say it's the wrong forum and that I "accidentally" posted it too early... Very odd dream to be honest...
The youngest photo of you is also the oldest photo of you.

Forum statistics

Threads
117,214
Messages
1,105,525
Members
153,357
Latest member
gabriel1777
Top