(function() {
var _Scene_Equip_createItemWindow = Scene_Equip.prototype.createItemWindow;
Scene_Equip.prototype.createItemWindow = function() {
_Scene_Equip_createItemWindow.call(this);
this._itemWindow.setHandler('ok', this.onItemOk.bind(this));
};
//Cursed meta
var _Scene_Equip_onItemOk = Scene_Equip.prototype.onItemOk;
Scene_Equip.prototype.onItemOk = function() {
var item = this._itemWindow.item();
if (item && item.meta.Cursed) {
this.createConfirmWindow(item);
this.createConfirmMessageWindow(item);
this.toggleItemDescriptionWindow(false);
} else {
_Scene_Equip_onItemOk.call(this);
}
};
//----------------------------------------------------------
//This is the conformation window for the cursed item Yes | No.
Scene_Equip.prototype.createConfirmWindow = function() {
// Create a semi-transparent black background
this._confirmWindowBackground = new Sprite(new Bitmap(Graphics.width, Graphics.height));
this._confirmWindowBackground.bitmap.fillRect(0, 0, Graphics.width, Graphics.height, '#000000');
this._confirmWindowBackground.opacity = 200;
this.addChild(this._confirmWindowBackground);
// Create the confirm window
this._confirmWindow = new Window_Confirm();
this._confirmWindow.setHandler('ok', this.onConfirmOk.bind(this));
this._confirmWindow.setHandler('cancel', this.onConfirmCancel.bind(this));
this.addChild(this._confirmWindow);
};
//This is the conformation message window for the cursed item that asks a question.
Scene_Equip.prototype.createConfirmMessageWindow = function(item) {
// Create the confirm message window
this._confirmMessageWindow = new Window_ConfirmMessage(item);
this.addChild(this._confirmMessageWindow);
};
Scene_Equip.prototype.onConfirmOk = function() {
_Scene_Equip_onItemOk.call(this);
this.removeChild(this._confirmWindow);
this._confirmWindow = null;
this.removeChild(this._confirmMessageWindow);
this._confirmMessageWindow = null;
this.removeChild(this._confirmWindowBackground);
this.toggleItemDescriptionWindow(true);
};
Scene_Equip.prototype.onConfirmCancel = function() {
this._itemWindow.activate();
this.removeChild(this._confirmWindow);
this._confirmWindow = null;
this.removeChild(this._confirmMessageWindow);
this._confirmMessageWindow = null;
this.removeChild(this._confirmWindowBackground);
this.toggleItemDescriptionWindow(true);
};
Scene_Equip.prototype.toggleItemDescriptionWindow = function(visible) {
this._itemWindow._helpWindow.visible = visible;
};
//------------------------------------------------------------------------
function Window_Confirm(item) {
this.initialize.apply(this, arguments);
}
Window_Confirm.prototype = Object.create(Window_Command.prototype);
Window_Confirm.prototype.constructor = Window_Confirm;
Window_Confirm.prototype.initialize = function() {
Window_Command.prototype.initialize.call(this, 0, 0);
this.updatePlacement();
this.select(0);
this.open();
};
Window_Confirm.prototype.windowWidth = function() {
return Graphics.boxWidth / 2;
};
Window_Confirm.prototype.numVisibleRows = function() {
return 2;
};
Window_Confirm.prototype.windowHeight = function() {
return this.fittingHeight(this.numVisibleRows() + 3) + 11;
};
Window_Confirm.prototype.makeCommandList = function() {
this.addCommand('Yes', 'ok');
this.addCommand('No', 'cancel');
};
Window_Confirm.prototype.itemTextAlign = function() {
return 'center'; // Center the command text
};
Window_Confirm.prototype.updatePlacement = function() {
this.width = this.windowWidth();
this.height = this.windowHeight();
this.x = (Graphics.boxWidth - this.width);
this.y = (Graphics.boxHeight - this.height);
};
Window_Confirm.prototype.itemRect = function(index) {
var rect = Window_Command.prototype.itemRect.call(this, index);
rect.x = (this.contentsWidth() / 2) - 120;
rect.y = (this.contentsHeight() - this.lineHeight() * 3 + 22) / 2 + index * this.lineHeight();
rect.width = 240;
return rect;
};
//------------------------------------------------------------------------
function Window_ConfirmMessage(item) {
this._item = item;
this.initialize.apply(this, arguments);
}
Window_ConfirmMessage.prototype = Object.create(Window_Base.prototype);
Window_ConfirmMessage.prototype.constructor = Window_ConfirmMessage;
Window_ConfirmMessage.prototype.initialize = function() {
var x = 0;
var y = 0;
var width = Graphics.boxWidth;
var height = this.fittingHeight(2);
Window_Base.prototype.initialize.call(this, x, y, width, height);
this.refresh();
};
Window_ConfirmMessage.prototype.refresh = function() {
this.contents.clear();
var text = "Are you sure you want to equip " + this._item.name + "?\nIt's a cursed item!";
this.drawTextEx(text, 0, 0);
};
})();