Hi all,
I'm trying to get into the new scripting language by making minor changes to the menu. I've been through the beginner course over at Javascript Is Sexy, but I have basically no experience actually writing programs. As such, I'm hoping I can get some advice on what constitutes good practice from more experienced coders. I have two major issues that I'd really like some advice on, but I'm open to any constructive criticism you've got.
1) Since I'm altering the placement of items in the menu, there are times when I don't want the original code to execute at all, meaning I had to overwrite some original functions. I realize this is generally frowned upon - does a better way to do this exist, or is it reasonable in this situation? EDIT: I should probably mention that I was careful to overwrite in child classes rather than parent.
2) Every script I've examined uses the 'Imported' code at the beginning, but I'm not clear on what it does. Should I be doing this as well?
I've included my code below, if it helps. Thanks for looking!
I'm trying to get into the new scripting language by making minor changes to the menu. I've been through the beginner course over at Javascript Is Sexy, but I have basically no experience actually writing programs. As such, I'm hoping I can get some advice on what constitutes good practice from more experienced coders. I have two major issues that I'd really like some advice on, but I'm open to any constructive criticism you've got.
1) Since I'm altering the placement of items in the menu, there are times when I don't want the original code to execute at all, meaning I had to overwrite some original functions. I realize this is generally frowned upon - does a better way to do this exist, or is it reasonable in this situation? EDIT: I should probably mention that I was careful to overwrite in child classes rather than parent.
2) Every script I've examined uses the 'Imported' code at the beginning, but I'm not clear on what it does. Should I be doing this as well?
I've included my code below, if it helps. Thanks for looking!
Code:
/*Aluvien CMS *//*:*@plugindesc Makes minor changes to the main menu to give more information in a glance.*@author Aluvien*@help* -Replaces actor face with character graphic to make menu less visually "busy"* -Moves actor name and level* -Adds experience bar to level indicator* -Provides more room for status icons (in future update) *//*New functions: Window_MenuStatus: drawItemCharacter Window_Base: drawActorStatusLevel, drawActorAlteredStatusOverwritten functions: Window_MenuStatus: drawItem, drawItemStatus *///=========================================================//AFAIK there is no function to draw a character in Window_MenuStatus, so I add one here.//Basically just a straight copy of drawItemImage, with only line #5 altered.Window_MenuStatus.prototype.drawItemCharacter = function(index) { var actor = $gameParty.members()[index]; var rect = this.itemRect(index); this.changePaintOpacity(actor.isBattleMember()); this.drawActorCharacter(actor, rect.x + 60, rect.y + 120); this.changePaintOpacity(true);};//Then I alter Window_MenuStatus to use my new function instead of drawing the face.Window_MenuStatus.prototype.drawItem = function(index) { this.drawItemBackground(index); this.drawItemCharacter(index); this.drawItemStatus(index);};//I make a new function to add a gauge to actor level.//This function is a merger of drawActorLevel and drawActorHp, with a few minor additions.Window_Base.prototype.drawActorStatusLevel = function(actor, x, y, width) { width = width || 186; var color1 = this.tpGaugeColor1(); var color2 = this.tpGaugeColor2(); var expRate = actor.currentExp() / actor.nextRequiredExp(); this.drawGauge(x, y, width, expRate, color1, color2); this.changeTextColor(this.systemColor()); this.drawText(TextManager.levelA, x, y, 48); this.resetTextColor(); this.drawText(actor.level, x + 40, y, 36, 'right');};//Now I change the placement of actor name and level.//This is basically drawActorSimpleStatus with some X and Y values changed.Window_Base.prototype.drawActorAlteredStatus = function(actor, x, y, width) { var lineHeight = this.lineHeight(); var x2 = x + 180; var width2 = Math.min(200, width - 180 - this.textPadding()); this.drawActorName(actor, 0, y); this.drawActorStatusLevel(actor, x2, y + lineHeight * 0, width2); this.drawActorIcons(actor, x, y + lineHeight * 1); this.drawActorClass(actor, x, y); this.drawActorHp(actor, x2, y + lineHeight * 1, width2); this.drawActorMp(actor, x2, y + lineHeight * 2, width2);};//Then I change Window_MenuStatus to use my new placement.Window_MenuStatus.prototype.drawItemStatus = function(index) { var actor = $gameParty.members()[index]; var rect = this.itemRect(index); var x = rect.x + 162; var y = rect.y + rect.height / 2 - this.lineHeight() * 1.5; var width = rect.width - x - this.textPadding(); this.drawActorAlteredStatus(actor, x, y, width);};