bishiba

Adept
Veteran
Joined
Apr 6, 2016
Messages
233
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,976
Reaction score
2,299
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 Profile Posts

On another more gaming topic, I paid 20 bucks for a visual novel to emotionally destroy me. I may write an entry about that.
1638611395177.png
Reading about metaverses recently. I can totally imagine myself in the future, logging in with VR glasses to a virtual beach villa sitting in a virtual chair, with a virtual laptop facing the sea...coding 16-bit RM.
Mod name: "[Game name] Gameplay Overhaul"
What they actually mean: "Here is a mod that makes the game harder."
I decided to reinstall one of my most favourite game of all times, Gothic 2. Time to get back to Khorinis!
So much game make... I needs to rest. The foods call.

Forum statistics

Threads
117,171
Messages
1,105,127
Members
153,266
Latest member
ishagold
Top