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,748
Reaction score
2,100
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,748
Reaction score
2,100
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 Posts

Latest Profile Posts

Changed my avatar, goodbye Alan Sugar, hello George Carlin (one of my favorite human beings ever)
If you still don't subscribe our Polish channel please consider it :)
1.png
Who wants to see my review of the worst star wars movie? This movie has all the excitement of being on Jury Duty of the most boring case ever about trade negotiations.
A lot to learn to make a game. Can I handle it?
I've been working on status effects since last thursday, and today I finished the core mechanic of Zombie, Teleport, Curse and Recall. Zombie and Curse are lacking a few things to make them complete atm. Teleport though is the "HAHA" spell for some of my mobs, but can "NOPE" at them with Recall.

Forum statistics

Threads
115,171
Messages
1,087,797
Members
149,719
Latest member
NanYuan
Top