Fenix2222

Villager
Member
Joined
Jul 15, 2021
Messages
10
Reaction score
0
First Language
Italian
Primarily Uses
RMMZ
I found the code that creates the "cancel" button during the "select item" event.
My question is: what have I to change in this code in order to change the coordinates (x and y) of that button?
JavaScript:
The window used for the event command [Select Item].

function Window_EventItem() {
    this.initialize(...arguments);
}

Window_EventItem.prototype = Object.create(Window_ItemList.prototype);
Window_EventItem.prototype.constructor = Window_EventItem;

Window_EventItem.prototype.initialize = function(rect) {
    Window_ItemList.prototype.initialize.call(this, rect);
    this.createCancelButton();
    this.openness = 0;
    this.deactivate();
    this.setHandler("ok", this.onOk.bind(this));
    this.setHandler("cancel", this.onCancel.bind(this));
};

Window_EventItem.prototype.setMessageWindow = function(messageWindow) {
    this._messageWindow = messageWindow;
};

Window_EventItem.prototype.createCancelButton = function() {
    if (ConfigManager.touchUI) {
        this._cancelButton = new Sprite_Button("cancel");
        this._cancelButton.visible = false;
        this.addChild(this._cancelButton);
    }
};

Window_EventItem.prototype.start = function() {
    this.refresh();
    this.updatePlacement();
    this.placeCancelButton();
    this.forceSelect(0);
    this.open();
    this.activate();
};

Window_EventItem.prototype.update = function() {
    Window_Selectable.prototype.update.call(this);
    this.updateCancelButton();
};

Window_EventItem.prototype.updateCancelButton = function() {
    if (this._cancelButton) {
        this._cancelButton.visible = this.isOpen();
    }
};

Window_EventItem.prototype.updatePlacement = function() {
    if (this._messageWindow.y >= Graphics.boxHeight / 2) {
        this.y = 0;
    } else {
        this.y = Graphics.boxHeight - this.height;
    }
};

Window_EventItem.prototype.placeCancelButton = function() {
    if (this._cancelButton) {
        const spacing = 8;
        const button = this._cancelButton;
        if (this.y === 0) {
            button.y = this.height + spacing;
        } else if (this._messageWindow.y >= Graphics.boxHeight / 4) {
            const distance = this.y - this._messageWindow.y;
            button.y = -button.height - spacing - distance;
        } else {
            button.y = -button.height - spacing;
        }
        button.x = this.width - button.width - spacing;
    }
};

Window_EventItem.prototype.includes = function(item) {
    const itypeId = $gameMessage.itemChoiceItypeId();
    return DataManager.isItem(item) && item.itypeId === itypeId;
};

Window_EventItem.prototype.needsNumber = function() {
    const itypeId = $gameMessage.itemChoiceItypeId();
    if (itypeId === 2) {
        // Key Item
        return $dataSystem.optKeyItemsNumber;
    } else if (itypeId >= 3) {
        // Hidden Item
        return false;
    } else {
        // Normal Item
        return true;
    }
};

Window_EventItem.prototype.isEnabled = function(/*item*/) {
    return true;
};

Window_EventItem.prototype.onOk = function() {
    const item = this.item();
    const itemId = item ? item.id : 0;
    $gameVariables.setValue($gameMessage.itemChoiceVariableId(), itemId);
    this._messageWindow.terminateMessage();
    this.close();
};

Window_EventItem.prototype.onCancel = function() {
    $gameVariables.setValue($gameMessage.itemChoiceVariableId(), 0);
    this._messageWindow.terminateMessage();
    this.close();
};
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
2,759
Reaction score
2,108
First Language
EN
Primarily Uses
RMMZ
:kaohi: Just change the cancel button's x and/or y values.

By default this is done in the placeCancelButton method, called from its start method.

Example plugin code (untested):
JavaScript:
(alias => {
  Window_EventItem.prototype.placeCancelButton = function() {
    alias.apply(this, arguments);
    if (this._cancelButton) {
      this._cancelButton.x = this.x;
      this._cancelButton.y = this.y - this._cancelButton.height;
    }
  };
})(Window_EventItem.prototype.placeCancelButton);
 

Fenix2222

Villager
Member
Joined
Jul 15, 2021
Messages
10
Reaction score
0
First Language
Italian
Primarily Uses
RMMZ
:kaohi: Just change the cancel button's x and/or y values.

By default this is done in the placeCancelButton method, called from its start method.

Example plugin code (untested):
JavaScript:
(alias => {
  Window_EventItem.prototype.placeCancelButton = function() {
    alias.apply(this, arguments);
    if (this._cancelButton) {
      this._cancelButton.x = this.x;
      this._cancelButton.y = this.y - this._cancelButton.height;
    }
  };
})(Window_EventItem.prototype.placeCancelButton);
Thanks for the answer! So I just have to change "This.x" and "this.y" in your plugin right? :kaoswt:
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
2,759
Reaction score
2,108
First Language
EN
Primarily Uses
RMMZ
It depends where you want the button to be. You can use a number (e.g. 100) or a formula, whatever you like.

In this case, this.x is the x coordinate of the window.
 

Latest Threads

Latest Profile Posts

It makes sense that you try to focus on the squishy mages at the back of the party first, right? If the mage can out-DPS the enemy DPS before the latter can kill the tank in front, the fight becomes boring.
finally got footage of my main character running around the main hub world. I've fixed a few things tho even since this video unsurprisingly lol.
 …I think I might need to switch from standard ATK/DEF up/down buffs to parameter altering states. I just had an actor whose usual attack against an enemy does ~25 do a buffed attack against a debuffed enemy for ~600…
just saw that titan quest is free on steam until the 23rd

Forum statistics

Threads
115,228
Messages
1,088,245
Members
149,822
Latest member
ddkovi
Top