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:
As found in rpgcore.js:
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...
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 🙂
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();
}
}
};
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 🙂