//=============================================================================
// ItemChecker.js
//=============================================================================

/*:
* @plugindesc Displays which items in the database have given occasion/price settings.
* @author John Clifford (Trihan)
*
* @help
*
* Plugin Command:
* ItemChecker # Open the item checker screen
*/

(function() {
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
if (command === 'ItemChecker') {
SceneManager.push(Scene_ItemChecker);
}
};

function Scene_ItemChecker() {
this.initialize.apply(this, arguments);
}

Scene_ItemChecker.prototype = Object.create(Scene_MenuBase.prototype);
Scene_ItemChecker.prototype.constructor = Scene_ItemChecker;

Scene_ItemChecker.prototype.initialize = function() {
Scene_MenuBase.prototype.initialize.call(this);
};

Scene_ItemChecker.prototype.create = function() {
Scene_MenuBase.prototype.create.call(this);
this.createCategoryWindow();
this.createItemWindow();
};

Scene_ItemChecker.prototype.createCategoryWindow = function() {
this._categoryWindow = new Window_ItemCheckerCategory();
this._categoryWindow.setHandler('ok', this.onCategoryOk.bind(this));
this._categoryWindow.setHandler('cancel', this.popScene.bind(this));
this.addWindow(this._categoryWindow);
};

Scene_ItemChecker.prototype.createItemWindow = function() {
var wx = this._categoryWindow.x + this._categoryWindow.width;
var ww = Graphics.boxWidth - wx;
this._itemWindow = new Window_ItemCheckerList(wx, 0, ww, Graphics.boxHeight);
this._itemWindow.setHandler('cancel', this.onItemCancel.bind(this));
this.addWindow(this._itemWindow);
this._categoryWindow.setItemWindow(this._itemWindow);
};

Scene_ItemChecker.prototype.onCategoryOk = function() {
this._itemWindow.activate();
this._itemWindow.selectLast();
};

Scene_ItemChecker.prototype.onItemCancel = function() {
this._itemWindow.deselect();
this._categoryWindow.activate();
};

function Window_ItemCheckerCategory() {
this.initialize.apply(this, arguments);
}

Window_ItemCheckerCategory.prototype = Object.create(Window_Command.prototype);
Window_ItemCheckerCategory.prototype.constructor = Window_ItemCheckerCategory;

Window_ItemCheckerCategory.prototype.initialize = function() {
Window_Command.prototype.initialize.call(this, 0, 0);
};

Window_ItemCheckerCategory.prototype.windowWidth = function() {
return 240;
};

Window_ItemCheckerCategory.prototype.maxCols = function() {
return 1;
};

Window_ItemCheckerCategory.prototype.update = function() {
Window_Command.prototype.update.call(this);
if (this._itemWindow) {
this._itemWindow.setCategory(this.currentSymbol());
}
};

Window_ItemCheckerCategory.prototype.makeCommandList = function() {
this.addCommand("Occasion: Always", 'always');
this.addCommand("Occasion: Battle", 'battle');
this.addCommand("Occasion: Menu", 'menu');
this.addCommand("Occasion: Never", 'never');
this.addCommand("Price: 0", 'pricezero');
};

Window_ItemCheckerCategory.prototype.setItemWindow = function(itemWindow) {
this._itemWindow = itemWindow;
this.update();
};

function Window_ItemCheckerList() {
this.initialize.apply(this, arguments);
}

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

Window_ItemCheckerList.prototype.initialize = function(x, y, width, height) {
Window_ItemList.prototype.initialize.call(this, x, y, width, height);
};

Window_ItemCheckerList.prototype.includes = function(item) {
if (item) {
switch(this._category) {
case 'always':
return item.occasion === 0;
case 'battle':
return item.occasion === 1;
case 'menu':
return item.occasion === 2;
case 'pricezero':
return item.price === 0;
default:
return false;
}
}
};

Window_ItemCheckerList.prototype.isEnabled = function(item) {
return false;
};

Window_ItemCheckerList.prototype.makeItemList = function() {
this._data = $dataItems.filter(function(item) {
if (item) {
return this.includes(item);
}
}, this);
};

Window_ItemCheckerList.prototype.drawItem = function(index) {
var item = this._data;
if (item) {
var rect = this.itemRect(index);
rect.width -= this.textPadding();
this.drawItemName(item, rect.x, rect.y, rect.width);
}
};
})();