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,764
Reaction score
2,114
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,764
Reaction score
2,114
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

Another comic with Backstage Malak...
If you want to ask him anything, you can ask on my DeviantArt page! I'm not sure if you're allowed to do it here.
Forum tip of the day ...
If you get a temporary suspension for being a jerk to people who are trying to help you, and arguing with mods and admins, don't go making new accounts. Chances are, if you p**s us off enough to suspend you for a week, we're not going to hesitate giving you a permanent ban when you give us a reason.
E_6fAErVkAQILXu.png
I'm so close to releasing my game on steam! :blush::blush::blush:
Us:
"This game is awesome! I wish there are more games like this in the future."
Also us:
"I hate how games stopped being original and start copying other successful games."
Should've done this a few days ago but...
PRI_200136808.jpg
Rest in Peace, Sir Clive Sinclair
1940 - 2021
Entrepreneur, Technologist, Father of the Modern British Computing Industry, and protagonist of Legend of ZUN.

Without you, England's games and tech industry wouldn't be where it is.

Forum statistics

Threads
115,291
Messages
1,088,682
Members
149,923
Latest member
R1ck_Str1k3r
Top