@ATT_Turan is correct, I feel like it's a bit rude to post an entire thing like that and ask someone to go over it. I don't know why really, I wouldn't think it's rude if someone else would do it tbh
😛 It's commendable to ask for it though, so you're not rude at all, you're real nice for doing it
😀
It's your own code, right? And you're asking for help with it? Are you saying it's rude for us to ask to see the code? I don't get it.
😅
Anyway, I see the following sections in your code:
Scene setup
- Remember to remove the
createAllWindows override right at the top.
Window_EnemyStatus
- I'm not sure what you're trying to do with your
update code. It's like: if the user is hovering this window, then move this window to the cursor's location (typically game windows are anchored by their top-left corner). But if this window is some kind of tooltip etc for another window, then the repositioning code should be on the parent object, not the tooltip. 😴
Draw Enemy Status
- Try removing this section? Item drawing can be handled by
drawItem, as you've done later.
- I'm guessing this is what is messing things up, because:
- It conflicts with the existing
drawItem structure, and
- It draws the data without reference to the window's
topIndex.
(See Window_Selectable.prototype.drawAllItems for details.)
Draw Dark Rects
- Consider drawing the dark rectangles on a per-item basis, in the
drawItem method. This is particularly relevant for the inherited redrawItem method, otherwise a single-item redraw will erase that item's dark rect. RMMV's core scripts do not have a drawDarkRect method so I'm not sure of the specifics there...if it's drawing the dark rects on a separate background layer then it should be OK as-is.
- Like I said in my previous post, you can get the item rectangle using
this.itemRect(index), so you might not need a custom getRectPosition method? If that method is only for the background/dark rectangles then consider renaming it to getDarkRect or something so its purpose is clearer.
Items settup
Touch Input
- Remove this section as well? I'm guessing you just had it there for testing/logging because these methods should all be inherited from
Window_Selectable.
Thanks!
First off, thanks, I would've forgotten to remove the createAllWindows() function
🙂
So yes, I guess this is what I meant with cleanup :/
For example, draw enemy status and the dark rects aren't being used at all. They were from before I decided to make it into a selectable rather than a base window. I kept them, since I felt that perhaps, somehow, they would be interacting with the selectable. So it was mostly for safety, and I should have added a comment, clarifying that it is not being used at the moment.
This goes double for the marked part as it is just me playing around, trying to learn how to utilize the TouchInput. It's not really relevant
🙁
This window is not related to my previous topic about tooltip, it is relevant in such a way that I am just experimenting with the mouse input. But, this specific part only allows me to move the window by dragging it. It also changes the origin point to be the center of the window.
Secondly, this specific window won't be visible to a player, assuming I don't create some kind of "check enemy status" skill or item. It is currently there because I've added the Yanfly level plugin, and I want to have an easy way to see what stats enemies have. And since I am creating every single stat an enemy can have, around 40, I decided to use a selectable window.
So the problem I see, is that since my draw enemy status functions aren't being used, I assume the issue lies somewhere else. And rather than a mistake in my code, the problem comes from a potentially missing function that other selectable windows use?
I have now cleaned up the plugin, ensured that it works(With the same problem though), but it should be more clear what is actually a part of the plugin. I have added some comments. I have also, removed the part of the plugin that creates the parameter items to be displayed, as they should not be relevant to the actual list(?). It is, however, included under the spoiler after the code below.
JavaScript:
//Scene setup ######################################
(function(alias) {
Scene_Battle.prototype.createAllWindows = function() {
alias.apply(this, arguments);
try {
this.createEnemyStatusWindow();
console.log($gameTroop._enemies.length);
for (var i = 0; i < $gameTroop._enemies.length; i++) {
$gameTroop._enemies[i].setStatRegistry();
};
} catch(e) {console.error(e)};
}
}) (Scene_Battle.prototype.createAllWindows);
Scene_Battle.prototype.createEnemyStatusWindow = function() {
var wy = this._helpWindow.y + this._helpWindow.height;
var wh = this._statusWindow.y - wy;
var ww = this._actorCommandWindow._width * 1.5;
this._enemyStatusWindow = new Window_EnemyStatus(0, wy, ww, wh);
this.addWindow(this._enemyStatusWindow);
};
//Window_EnemyStatus ######################################
function Window_EnemyStatus() {
this.initialize.apply(this, arguments);
}
Window_EnemyStatus.prototype = Object.create(Window_Selectable.prototype);
Window_EnemyStatus.prototype.constructor = Window_EnemyStatus;
Window_EnemyStatus.prototype.initialize = function(x, y, width, height) {
Window_Selectable.prototype.initialize.call(this, x, y, width, height);
this._touching = false;
this._enemy = null;
};
Window_EnemyStatus.prototype.update = function() {
if (this.getScene()._enemyWindow.enemy() && this._enemy != this.getScene()._enemyWindow.enemy()) {
this._enemy = this.getScene()._enemyWindow.enemy();
if (this._enemy.isEnemy()) { //Ensures that the selected member is an enemy and not an actor.
//Get the amount of parameters of the enemy.
this._paramsLength = this._enemy.paramsName.length;
this.refresh();
}
}
Window_Selectable.prototype.update.call(this);
};
//Function is related to the draw dark rectangles.
//As far as I can understand, this should not interfere as it only parses the coordinates for item placement.
Window_EnemyStatus.prototype.getRectPosition = function(index) {
var rect = new Rectangle();
rect.width = Math.floor(this.contents.width);
rect.height = this.lineHeight();
rect.x = /*index % 2 === 0 ? 0 : rect.width;*/ 0; //Set it to 0, preserved original within the comment.
rect.y = index * this.lineHeight();
return rect;
};
//Items setup
Window_EnemyStatus.prototype.maxItems = function() { //Sets the max amount of items in the list.
if (this._enemy) {
return this._enemy.paramsName ? this._paramsLength : 1;
} else {return 1;}
};
Window_EnemyStatus.prototype.drawItem = function(index) {
var rect = this.getRectPosition(index); //Gets the position for where to place the text.
var statWidth = 96;
rect.width -= this.textPadding();
//Draws stat name.
this.drawText(this._enemy.paramsName[index], rect.x + 4, rect.y, rect.width - statWidth);
//Draws stat value.
this.drawText(this._enemy.paramsValue[index], rect.x + rect.width - statWidth, rect.y, statWidth, 'right');
this.changePaintOpacity(true);
};
The code for enemy stat setup. - It has dependencies on my superclass.
Spoiler: Enemy status code
JavaScript:
Game_Enemy.prototype.setStatRegistry = function() {
var i = 0;
var n = 0;
var code = 13;
var elementsName = $dataSystem.elements;
this.paramsName = [];
this.paramsValue = [];
this.paramsName[i] = "HP";
this.paramsValue[i] = this.paramBase(i++).toFixed(0);
this.paramsName[i] = "MP";
this.paramsValue[i] = this.paramBase(i++).toFixed(0);
this.paramsName[i] = "Attack";
this.paramsValue[i] = this.paramBase(i++).toFixed(0);
this.paramsName[i] = "Def";
this.paramsValue[i] = this.paramBase(i++).toFixed(0);
this.paramsName[i] = "M. Attack";
this.paramsValue[i] = this.paramBase(i++).toFixed(0);
this.paramsName[i] = "M. Def";
this.paramsValue[i] = this.paramBase(i++).toFixed(0);
this.paramsName[i] = "Agility";
this.paramsValue[i] = this.paramBase(i++).toFixed(0);
this.paramsName[i] = "Luck";
this.paramsValue[i] = this.paramBase(i++).toFixed(0);
n = 0;
code = 11;
for (let n = 0; n < this.traits(code).length; n++) {
dataIndex = this.traits(code)[n].dataId;
if (BISH.elementOrder.contains(dataIndex)) {
this.paramsName[i] = elementsName[dataIndex] + " Res %"; console.log(this.paramsName[i]);
this.setTrait(i++, this.traits(code)[n], true, "100-");
};
};
};
Game_Enemy.prototype.hasTrait = function() {
console.log(this.traits.length);
return this.traits.length > 0 ? true : false;
};
Game_Enemy.prototype.setTrait = function(index, trait, multiplier, modifier) {
value = trait.value;
if (multiplier) value *= 100;
if (modifier) modifier == "100-" ? value = 100 - value : value = value - 100;
this.paramsValue[index] = value.toFixed(0);
return false;
};
Game_Enemy.prototype.setAttackElement = function() {
for (var i = 0; i < item.traits.length; i++) {
if (item.traits[i].code == 31) {
var attackElement = $dataSystem.elements[item.traits[i].dataId];
return attackElement;
}
}
return 0;
};
Thanks!
🙂