//-----------------------------------------------------------------------------
// Window_SkillList
//
// The window for selecting a skill on the skill screen.
/**
* The window for selecting a skill on the skill screen.
*
* @class
* @extends Window_Selectable
*/
function Window_SkillList() {
this.initialize(...arguments);
}
Window_SkillList.prototype = Object.create(Window_Selectable.prototype);
Window_SkillList.prototype.constructor = Window_SkillList;
Window_SkillList.prototype.initialize = function(rect) {
Window_Selectable.prototype.initialize.call(this, rect);
this._actor = null;
this._stypeId = 0;
this._data = [];
};
/**
* Sets the actor object for the window
*
* @param {Game_Actor} actor - The Game Actor object
*/
Window_SkillList.prototype.setActor = function(actor) {
if (this._actor !== actor) {
this._actor = actor;
this.refresh();
this.scrollTo(0, 0);
}
};
/**
* Sets the skill type Id for the window
*
* @param {number} stypeId - The skill type id
*/
Window_SkillList.prototype.setStypeId = function(stypeId) {
if (this._stypeId !== stypeId) {
this._stypeId = stypeId;
this.refresh();
this.scrollTo(0, 0);
}
};
/**
* Get the max amount of columns in the window
*
* @return {number} Max columns for the window
*/
Window_SkillList.prototype.maxCols = function() {
return 2;
};
/**
* Get the spacing between columns
*
* @return {number} Space between columns
*/
Window_SkillList.prototype.colSpacing = function() {
return 16;
};
/**
* Get the max amount of items to display in the window
*
* @return {number} Amount of items to display in the window
*/
Window_SkillList.prototype.maxItems = function() {
return this._data ? this._data.length : 1;
};
/**
* Get the currently selected item
*
* @return {Object} The skill object at the current index
*/
Window_SkillList.prototype.item = function() {
return this.itemAt(this.index());
};
/**
* Get the object at the given index
*
* @param {number} index - The index of the item
* @return {Object} The skill object at the current index
*/
Window_SkillList.prototype.itemAt = function(index) {
return this._data && index >= 0 ? this._data[index] : null;
};
/**
* Check if the currently selected skill is enabled
*
* @return {boolean} True if the skill is enabled
*/
Window_SkillList.prototype.isCurrentItemEnabled = function() {
return this.isEnabled(this._data[this.index()]);
};
/**
* Check if the skill should be included
*
* @param {Object} item - The skill object
* @return {boolean} True if the skill is included
*/
Window_SkillList.prototype.includes = function(item) {
return item && item.stypeId === this._stypeId;
};
/**
* Check if the skill should be enabled
*
* @param {Object} item - The skill object
* @return {boolean} True if the skill is enabled
*/
Window_SkillList.prototype.isEnabled = function(item) {
return this._actor && this._actor.canUse(item);
};
/**
* Makes the list of items to display in the window
*/
Window_SkillList.prototype.makeItemList = function() {
if (this._actor) {
this._data = this._actor.skills().filter(item => this.includes(item));
} else {
this._data = [];
}
};
/**
* Select the last skill, if remembered
*/
Window_SkillList.prototype.selectLast = function() {
const index = this._data.indexOf(this._actor.lastSkill());
this.forceSelect(index >= 0 ? index : 0);
};
/**
* Draws the item at the given index
*
* @param {number} index - The index of the item to draw
*/
Window_SkillList.prototype.drawItem = function(index) {
const skill = this.itemAt(index);
if (skill) {
const costWidth = this.costWidth();
const rect = this.itemLineRect(index);
this.changePaintOpacity(this.isEnabled(skill));
this.drawItemName(skill, rect.x, rect.y, rect.width - costWidth);
this.drawSkillCost(skill, rect.x, rect.y, rect.width);
this.changePaintOpacity(1);
}
};
/**
* Get the width of cost text
*
* @return {number} The width of cost text
*/
Window_SkillList.prototype.costWidth = function() {
return this.textWidth("000");
};
/**
* Draws the skill's cost
*
* @param {Object} skill - The skill object
* @param {number} x - The x coordinate to draw the cost
* @param {number} y - The y coordinate to draw the cost
* @param {number} width - The width available to draw the cost
*/
Window_SkillList.prototype.drawSkillCost = function(skill, x, y, width) {
if (this._actor.skillTpCost(skill) > 0) {
this.changeTextColor(ColorManager.tpCostColor());
this.drawText(this._actor.skillTpCost(skill), x, y, width, "right");
} else if (this._actor.skillMpCost(skill) > 0) {
this.changeTextColor(ColorManager.mpCostColor());
this.drawText(this._actor.skillMpCost(skill), x, y, width, "right");
}
};
/**
* Updates helper windows
*/
Window_SkillList.prototype.updateHelp = function() {
this.setHelpWindowItem(this.item());
};
Window_SkillList.prototype.refresh = function() {
this.makeItemList();
Window_Selectable.prototype.refresh.call(this);
};