I am working on my next plugin and have run into another weird issue I have not encountered before. For some reason, at a certain point in the scene structure, a window is not being hidden properly. I tried calling the window earlier in the scene and it works fine from there, but the same code does not work if I create the window and open it from its proper location.
At first I thought that maybe something was capturing the ok and cancel commands but they are correctly going to the handler functions where the above mentioned function calls proceed to not hide the window. The problem window in question is Window_Refine. It will create, display, and work just fine but once the code tried to hide it, it just stays and covers up the Window_ActionPane() although that becomes the active window.
Below are my window definitions and my entire scene code plus the code for the Window_Refine. If you need more let me know.
I am probably missing or overlooking something simple.
At first I thought that maybe something was capturing the ok and cancel commands but they are correctly going to the handler functions where the above mentioned function calls proceed to not hide the window. The problem window in question is Window_Refine. It will create, display, and work just fine but once the code tried to hide it, it just stays and covers up the Window_ActionPane() although that becomes the active window.
Below are my window definitions and my entire scene code plus the code for the Window_Refine. If you need more let me know.
Code:
function Scene_Blacksmith() { this.initialize.apply(this,arguments); };
function Window_WeaponList() { this.initialize.apply(this,arguments); };
function Window_WeapStatus() { this.initialize.apply(this,arguments); };
function Window_ActionPane() { this.initialize.apply(this,arguments); };
function Window_LevelUp() { this.initialize.apply(this,arguments); };
function Window_Refine() { this.initialize.apply(this,arguments); };
function Window_Synthesize() { this.initialize.apply(this,arguments); };
function Window_Repair() { this.initialize.apply(this,arguments); };
function Window_CommandPane() { this.initialize.apply(this,arguments); };
function Window_PartyGold() { this.initialize.apply(this,arguments); };
Scene_Blacksmith.prototype = Object.create(Scene_MenuBase.prototype);
Scene_Blacksmith.prototype.constructor = Scene_Blacksmith;
Scene_Blacksmith.prototype.initialize = function(){
Scene_MenuBase.prototype.initialize.call(this);
};
Scene_Blacksmith.prototype.create = function(){
Scene_MenuBase.prototype.create.call(this);
this.createHelpWindow();
this.createWeaponStatusWindow();
this.createWeaponList();
this._wepListWnd.show();
this._wepListWnd.activate();
this._helpWindow.show();
this._wepListWnd.selectFirst();
this._wepStatWnd.show();
this._wepStatWnd.refresh(false,false,false,false,false);
}
Scene_Blacksmith.prototype.createWeaponList = function(){
var w = 255;
var h = 250;
var x = 0;
var y = this._helpWindow.height + 10;
this._wepListWnd = new Window_WeaponList(w,h,x,y,this._wepStatWnd);
this._wepListWnd.setHandler('ok',this.onWepSelect.bind(this));
this._wepListWnd.setHandler('cancel',this.onWepSelectCancel.bind(this));
this._wepListWnd.refresh();
this.addWindow(this._wepListWnd);
};
Scene_Blacksmith.prototype.onWepSelect = function(){
this._wepListWnd.hide();
this._wepListWnd.deactivate();
this.createWeaponActionWindow();
this._wepActWnd.show();
this._wepActWnd.activate();
this._wepActWnd.select();
this.updateWepStatWnd(false);
this._wepActWnd.refresh();
}
Scene_Blacksmith.prototype.onWepSelectCancel = function(){
SceneManager.pop();
}
Scene_Blacksmith.prototype.createWeaponStatusWindow = function(){
var h = 250;
var x = 255 + 10;
var y = this._helpWindow.height + 10;
var w = Graphics.width - x;
this._wepStatWnd = new Window_WeapStatus(w,h,x,y);
this.addWindow(this._wepStatWnd);
}
Scene_Blacksmith.prototype.updateWepStatWnd = function(bReturnToWepSel){
if (!bReturnToWepSel){
var h = Graphics.height - (this._helpWindow.height + 10);
var x = this._wepActWnd.getWidth() + 10;
var y = this._helpWindow.height + 10;
var w = Graphics.width - x;
this._wepStatWnd.move(x,y,w,h);
this._wepStatWnd.createContents();
this._wepStatWnd.refresh(true,false,false,false,false);
} else{
var h = 250;
var x = 255 + 10;
var y = this._helpWindow.height + 10;
var w = Graphics.width - x;
this._wepStatWnd.move(x,y,w,h);
this._wepStatWnd.createContents();
this._wepStatWnd.refresh(false,false,false,false,false);
}
}
Scene_Blacksmith.prototype.createWeaponActionWindow = function(){
var w = 145;
var h = 215;
var x = 0;
var y = this._helpWindow.height + 10;
this._wepActWnd = new Window_ActionPane(w,h,x,y,this._wepStatWnd.getWeapon());
this._wepActWnd.setHandler('ok',this.onWepActSelect.bind(this));
this._wepActWnd.setHandler('cancel',this.onWepActSelectCancel.bind(this));
this._wepActWnd.setHelpWindow(this._helpWindow);
this.addWindow(this._wepActWnd);
};
Scene_Blacksmith.prototype.onWepActSelect = function(){
var selection = this._wepActWnd.getSelection();
this.createGoldWindow();
if (selection == "Level Up"){
this.createLevelUpWindow();
this._wepActWnd.hide();
this._wepActWnd.deactivate();
this._wepStatWnd.refresh(false,true,false,false,false)
this._lvlUpWnd.show();
this._lvlUpWnd.activate();
this._lvlUpWnd.select();
this._lvlUpWnd.refresh();
this._gldWnd.show();
this._gldWnd.refresh();
} else if (selection == "Refine"){
this.createRefineWindow();
this._wepActWnd.hide();
this._wepActWnd.deactivate();
this._wepStatWnd.refresh(false,false,true,false,false)
this._refWnd.show();
this._refWnd.activate();
this._refWnd.select();
this._refWnd.refresh();
this._gldWnd.show();
this._gldWnd.refresh();
} else if (selection == "Synthesize"){
/*
existing params and triats carry over 15% of value from donor weapon
new params and traits carry over 30% of value from donor weapon
*/
} else if (selection == "Repair"){
} else if (selection == "Cancel"){
}
}
Scene_Blacksmith.prototype.createGoldWindow = function(){
var w = this._wepActWnd.getWidth();
var h = 78;
var x = 0;
var y = Graphics.height - h;
this._gldWnd = new Window_PartyGold(w,h,x,y,$gameParty.gold());
this.addWindow(this._gldWnd);
}
Scene_Blacksmith.prototype.onWepActSelectCancel = function(){
this._wepActWnd.hide();
this._wepActWnd.deactivate();
this._wepListWnd.show();
this._wepListWnd.activate();
this._wepListWnd.select();
this._wepListWnd.refresh();
this.updateWepStatWnd(true);
}
Scene_Blacksmith.prototype.createLevelUpWindow = function(){
var w = 145;
var h = Graphics.height/2;
var x = 0;
var y = this._helpWindow.height + 10;
this._lvlUpWnd = new Window_LevelUp(w,h,x,y,this._wepStatWnd.getWeapon()); //Pass through currently selected Game_InstanceWeapon
this._lvlUpWnd.setHandler('ok',this.onWepLvlUpOk.bind(this));
this._lvlUpWnd.setHandler('cancel',this.onWepLvlUpCancel.bind(this));
this.addWindow(this._lvlUpWnd);
}
Scene_Blacksmith.prototype.onWepLvlUpOk = function(){
this._lvlUpWnd.hide();
this._lvlUpWnd.deactivate();
this._wepActWnd.show();
this._wepActWnd.activate();
this._wepActWnd.select();
this._wepActWnd.refresh();
this._wepStatWnd.setWeapon(this._lvlUpWnd.getWeapon());
this._wepStatWnd.refresh(true,false,false,false,false);
this._gldWnd.hide();
}
Scene_Blacksmith.prototype.onWepLvlUpCancel = function(){
this._lvlUpWnd.hide();
this._lvlUpWnd.deactivate();
this._wepActWnd.show();
this._wepActWnd.activate();
this._wepActWnd.select();
this._wepActWnd.refresh();
this._wepStatWnd.refresh(true,false,false,false,false);
this._gldWnd.hide();
}
Scene_Blacksmith.prototype.createRefineWindow = function(){
var w = 145;
var h = Graphics.height/2;
var x = 0;
var y = this._helpWindow.height + 10;
this._refWnd = new Window_Refine(w,h,x,y,this._wepStatWnd.getWeapon());
this._refWnd.setHandler('ok',this.onRefOk.bind(this));
this._refWnd.setHandler('cancel',this.onRefCancel.bind(this));
this.addWindow(this._refWnd);
}
Scene_Blacksmith.prototype.onRefOk = function(){
this._refWnd.hide();
this._refWnd.deactivate();
this._wepActWnd.show();
this._wepActWnd.activate();
this._wepStatWnd.refresh(true,false,false,false,false);
}
Scene_Blacksmith.prototype.onRefCancel = function(){
this._refWnd.hide();
this._refWnd.deactivate();
this._wepActWnd.show();
this._wepActWnd.activate();
this._wepStatWnd.refresh(true,false,false,false,false);
}
Window_Refine.prototype = Object.create(Window_Selectable.prototype);
Window_Refine.prototype.constructor = Window_Refine;
Window_Refine.prototype.initialize = function(w,h,x,y,wep){
this._wep = wep;
this._goldCost = 0;
this._h = h;
this._lineHeight = this.lineHeight();
this._rects = {};
Window_Selectable.prototype.initialize.call(this,x,y,w,h);
this.setupCosts();
this.setupCommands();
this.setupRects();
}
Window_Refine.prototype.setupCosts = function(){
this._goldCost = ~~eval(this._wep._goldForm);
if (this._wep._reLevel != 0) { this._goldCost = Math.round(((this._goldCost/2) + (this._goldCost*((this._wep._refBonus * this._wep._level) * (this._wep._refLevel/1.5))))/this._wep._refBonus); }
else { this._goldCost = Math.round(((this._goldCost/2) + (this._goldCost*(this._wep._refBonus * this._wep._level)))/this._wep._refBonus); }
}
Window_Refine.prototype.setupCommands = function(){
this._comList = ["OK","Cancel"];
}
Window_Refine.prototype.setupRects = function(){
for (var i1 = 0; i1 < this._comList.length; i1++) { this.itemRectForText(i1); }
}
Window_Refine.prototype.getWeapon = function(){
return this._wep;
}
Window_Refine.prototype.maxCols = function() { return 1; };
Window_Refine.prototype.maxItems = function() { return this._comList ? this._comList.length : 1; };
Window_Refine.prototype.itemHeight = function() { return 35; };
Window_Refine.prototype.numVisibleRows = function() { return 2; };
Window_Refine.prototype.spacing = function() { return 8; };
Window_Refine.prototype.drawItem = function(index) {
this.drawReqs();
this.drawActionItem(index);
};
Window_Refine.prototype.drawReqs = function(){
this.contents.fontSize = 18;
var x = 0;
var y = 0;
var gLabel = "G: " + this._goldCost;
if ($gameParty.gold() < this._goldCost) { this.changeTextColor("#CF0C0C"); }
this.drawText(gLabel,x,y+(this._lineHeight),this.textWidth(gLabel),'left');
this.resetTextColor();
}
Window_Refine.prototype.drawActionItem = function(index){
this.contents.fontSize = 20;
var rect = this.getRect(index);
var x = rect.x;
var y = 0;
if (index == 0) { y = this._h - (rect.y+rect.height*3); }
else { y = this._h - (rect.y+rect.height); }
var w = rect.width -x - this.textPadding();
rect.y = y;
this.updateRect(rect, index);
if (index == 0 && ($gameParty.gold() < this._goldCost)){
this.contents.paintOpacity = 125;
}
this.drawText(this._comList[index],rect.x,y,rect.width,'left');
this.contents.paintOpacity = 255;
};
Window_Refine.prototype.updateCursor = function() {
if (this._cursorAll) {
var allRowsHeight = this.maxRows() * this.itemHeight();
this.setCursorRect(0, 0, this.contents.width, allRowsHeight);
this.setTopRow(0);
} else if (this.isCursorVisible()) {
var rect = this.getRect(this.index());
this.setCursorRect(rect.x, rect.y, rect.width, rect.height);
} else {
this.setCursorRect(0, 0, 0, 0);
}
};
Window_Refine.prototype.hitTest = function(x, y) {
if (this.isContentsArea(x, y)) {
var cx = x - this.padding;
var cy = y - this.padding;
var topIndex = this.topIndex();
for (var i = 0; i < this.maxPageItems(); i++) {
var index = topIndex + i;
if (index < this.maxItems()) {
var rect = this.getRect(index);
var right = rect.x + rect.width;
var bottom = rect.y + rect.height;
if (cx >= rect.x && cy >= rect.y && cx < right && cy < bottom) {
return index;
}
}
}
}
return -1;
};
Window_Refine.prototype.itemRect = function(index) {
var rect = new Rectangle();
var maxCols = this.maxCols();
rect.width = this.itemWidth();
rect.height = this.itemHeight();
rect.x = index % maxCols * (rect.width + this.spacing()) - this._scrollX;
rect.y = Math.floor(index / maxCols) * rect.height - this._scrollY;
return rect;
};
Window_Refine.prototype.itemRectForText = function(index) {
var rect = this.itemRect(index);
rect.x += this.textPadding();
rect.width -= this.textPadding() * 2;
this._rects[index] = rect;
};
Window_Refine.prototype.getRect = function(index){
return this._rects[index];
}
Window_Refine.prototype.updateRect = function(rect,index){
this._rects[index] = rect;
}
Window_Refine.prototype.processOk = function(){
if (this._index == 0 && ($gameParty.gold() < this._goldCost)){
SoundManager.playCancel();
} else{
$gameParty.loseGold(this._goldCost);
var traits = {};
var parm = {};
for (var i1 = 0; i1 < this._wep._traits.length; i1++){
traits[i1] = this._wep._traits[i1];
}
//For Base Parms
for (var pId in this._wep._baseParams){
if (this._wep._baseParams[pId] != 0){
if (this._wep._refLevel != 0) { this._wep._baseParams[pId] += Math.round(this._wep._baseParams[pId]*(this._wep._refBonus*this._wep._refLevel)); }
else { this._wep._baseParams[pId] += Math.round(this._wep._baseParams[pId]*this._wep._refBonus); }
}
}
//For Ex Parms
for (var pId in this._wep._exParams){
if (this._wep._exParams[pId] != 0){
if (this._wep._refLevel != 0) { this._wep._exParams[pId] += Math.round(this._wep._exParams[pId]*(this._wep._refBonus*this._wep._refLevel)); }
else { this._wep._exParams[pId] += Math.round(this._wep._exParams[pId]*this._wep._refBonus); }
}
}
//For SP Parms
for (var pId in this._wep._spParams){
if (this._wep._spParams[pId] != 0){
if (this._wep._refLevel != 0) { this._wep._spParams[pId] += Math.round(this._wep._spParams[pId]*(this._wep._refBonus*this._wep._refLevel)); }
else { this._wep._spParams[pId] += Math.round(this._wep._spParams[pId]*this._wep._refBonus); }
}
}
for (var tId in traits){
if (this._wep._traits[tId].code == 13){
this._wep._traits[tId].value += this._wep._traits[tId].value*this._wep._refBonus;
if (this._wep._refLevel != 0) { this._wep._traits[tId].value += this._wep._traits[tId].value*(this._wep._refBonus*this._wep._refLevel); }
else { this._wep._traits[tId].value += this._wep._traits[tId].value*this._wep._refBonus; }
}
}
if (this._wep._refLevel != 0) { this._wep._maxDur += Math.round(this._wep._maxDur*(this._wep._refBonus*this._wep._refLevel)); }
else { this._wep._maxDur += Math.round(this._wep._maxDur*this._wep._refBonus); }
this._wep._durability = this._wep._maxDur;
this._wep.processFinalParams();
//Reset weapon values
this._wep.changeExp(-1*this._wep._exp);
this._wep._level = 1;
this._wep._refLevel++;
$gameParty.updateWeapon(this._wep,this._wep._id);
Window_Selectable.prototype.processOk.call(this);
}
}
I am probably missing or overlooking something simple.