Showing Custom Gauges

so.. I've figured out that in combination with ICF-SOFTPARAMS plugin, which creates new parameters and such... you can use certain said parameters as say a new form of mp. and SRDude's Battle Status Customizer can be configured to actually show these custom parameters. add Yanfly's skill core and you can even have custom requirements and executions based on the points in the new gauge. but I've had one consistently nagging issue with all of this. SRDude's plugin either needs to set to active updating (and I'm pretty sure that's what's causing a ton of lag in my battles), or no active update and changes aren't reflected as they happen...

so, does anyone know of any other way I can show custom parameters in a gauge visually? I feel if I knew how to simply use the draw Gauges stuff, and how to position it, I might be able to add the Gauges myself. any help would be greatly appreciated. thanks!
If you're looking to remove SRD's Battle Status Customizer I'm assuming your battle status window will be unaffected by other plugins. In which case you could write your own function for drawing the actors status's. This will allow you to set up whatever gauges you like.

So the functions to look at for drawing gauges within the battle status window are these two:

Code:
Window_BattleStatus.prototype.drawGaugeAreaWithTp = function(rect, actor) {
    this.drawActorHp(actor, rect.x + 0, rect.y, 108);
    this.drawActorMp(actor, rect.x + 123, rect.y, 96);
    this.drawActorTp(actor, rect.x + 234, rect.y, 96);
};

Window_BattleStatus.prototype.drawGaugeAreaWithoutTp = function(rect, actor) {
    this.drawActorHp(actor, rect.x + 0, rect.y, 201);
    this.drawActorMp(actor, rect.x + 216,  rect.y, 114);
};

Depending on whether you've set your game to use tp or now will decide which function you need to use. I'll assume you're not using tp for simplicity. The parameters on the functions drawActorHp and drawActorMp are as follows: actor, x, y, width - so to create space for more gauges we need to adjust the existing functions x and width parameters to fit in the new gauge. Lets for instance say I adjusted the existing gauges like so:

Code:
Window_BattleStatus.prototype.drawGaugeAreaWithoutTp = function(rect, actor) {
    this.drawActorHp(actor, rect.x + 0, rect.y, 151); //width dropped to 151
    this.drawActorMp(actor, rect.x + 166,  rect.y, 85); //x dropped to 166 (151+15), width dropped to 85
};

This now gives us some space for a new gauge on the right. For drawing the actual gauge we can just use the function drawGauge, the function uses the following parameters:

x = number, x coordinate, we'll use rect.x + 266 in this example (151+15+85+15 = 266) - this is the left of the invisible gauge area + 266.
y = number, y coordinate, we'll copy the above gauges and just use rect.y - this is just the top of the invisible gauge area.
width = number, width of the gauge, I'll use 64 (330 - 266 = 64). Note: 330 is the default width of the invisible gauge area [I think].
rate = number from 0 - 1, percentage of the gauge to be filled - I'm not familiar with the plugin you're using for parameters, but I assume you know how to access the parameters. You'll want to take current parameter value and divide it by the maximum.
color1 = hexadecimal, represent the colour of the gauge - I will leave this as color1, replace as necessary.
color2 = hexadecimal, represent the colour of the gauge - I will leave this as color2, replace as necessary.

Now that we have some values we can add the new gauge function into our "drawGaugeArea..." function.

Code:
Window_BattleStatus.prototype.drawGaugeAreaWithoutTp = function(rect, actor) {
    this.drawActorHp(actor, rect.x + 0, rect.y, 151);
    this.drawActorMp(actor, rect.x + 166,  rect.y, 85);
    //declare rate for ease, replace currentParam and maxParam with actual getters for custom parameters
    var rate = actor.currentParam/actor.maxParam;
    this.drawGauge(rect.x + 266, rect.y, 64, rate, color1, color2);
};

This will draw the gauge, no text. To draw the text we can use "drawText" and "drawCurrentAndMax", but only if the display name for the parameter is 2 characters eg "HP", "AP" and if the maximum value the parameter can be is 4 digits eg 1000-9999. I'll assume these conditions are true in your case for now (if they're not let me know, we can create a modified copy to remove these limitations).

The parameters for drawText are:

text = text to be drawn, I'll be using "CP".
x, y = same as for gauges
maxWidth = maximum width the text can be, if text is longer than maxWidth the text will appear squished.
align = alignment for text, this is optional so we will ignore it.

The parameters for drawCurrentAndMax are:

current = the current value of the parameter
max = the maximum value of the parameter (for the actor, not the global maximum)
x, y, width, color1, color2 = these are all the same as for the gauge.

Again, I'll assume you know how to retrieve the actor's current and max parameter values - I'll be using currentParam and maxParam, replace as necessary. With this in mind if we add the following to our function:

Code:
Window_BattleStatus.prototype.drawGaugeAreaWithoutTp = function(rect, actor) {
    this.drawActorHp(actor, rect.x + 0, rect.y, 151);
    this.drawActorMp(actor, rect.x + 166,  rect.y, 85);
    var rate = actor.currentParam/actor.maxParam;
    this.drawGauge(rect.x + 266, rect.y, 64, rate, color1, color2);
    this.drawText("CP", rect.x+266, rect.y, 64)
    this.drawCurrentAndMax(actor.currentParam, actor.maxParam, rect.x+266, rect.y, 64, color1, color2)
};

We Should if all goes well and I haven't missed anything, have a battle status window that has a new gauge for each actor with overlaid text showing the parameter name and current/max values. Note: You may end up with just the current value being drawn, this means our gauge is too small to fit both the current and the max, you can adjust the x and width values accordingly to increase the size of the new gauge.

What I would advise is, rather than overwrite the actual code in rpg_windows is that you add the modified function to a text editor and save it as a .js file and load it to your game like a plugin - this means if anything goes wrong you can just remove the new plugin
wow thank you so much for all of that information! that's actually all really helpful to know in general. and it yes, it works too by the way! I had one question if that's the case tho, how would I go about having more than two letters for the name of the gauge. I feel with this information tho, I should be able to piece anything else I might need to know together myself. again tho, thanks a ton, this is an extreme help.
No problem. 🙂

You'll need to create a modified version of drawCurrentAndMax and use that instead. So the original function looks like this:

Code:
Window_Base.prototype.drawCurrentAndMax = function(current, max, x, y,
                                                   width, color1, color2) {
    var labelWidth = this.textWidth('HP');  // this is the line that restricts us to 2 character names.
    var valueWidth = this.textWidth('0000');
    var slashWidth = this.textWidth('/');
    var x1 = x + width - valueWidth;
    var x2 = x1 - slashWidth;
    var x3 = x2 - valueWidth;
    if (x3 >= x + labelWidth) {
        this.changeTextColor(color1);
        this.drawText(current, x3, y, valueWidth, 'right');
        this.changeTextColor(color2);
        this.drawText('/', x2, y, slashWidth, 'right');
        this.drawText(max, x1, y, valueWidth, 'right');
    } else {
        this.changeTextColor(color1);
        this.drawText(current, x1, y, valueWidth, 'right');
    }
};

So we need to create a new function that does pretty much the same thing but slightly different. Depending on if you plan to use this function in different windows or exclusively in the battle status window we can either add this method to Window_Base (so we can use it in all windows) or Window_BattleStatus (so we can only use it in battle status). I'll show you adding it to Window_Base.

Code:
//we change the name of the function so that we don't overwrite the original
Window_Base.prototype.drawCurrentAndMaxCustom = function(current, max, x, y,
                                                   width, color1, color2) {
    var labelWidth = this.textWidth('SCP');  //we add more characters into the textWidth function
    var valueWidth = this.textWidth('0000');
    var slashWidth = this.textWidth('/');
    var x1 = x + width - valueWidth;
    var x2 = x1 - slashWidth;
    var x3 = x2 - valueWidth;
    if (x3 >= x + labelWidth) {
        this.changeTextColor(color1);
        this.drawText(current, x3, y, valueWidth, 'right');
        this.changeTextColor(color2);
        this.drawText('/', x2, y, slashWidth, 'right');
        this.drawText(max, x1, y, valueWidth, 'right');
    } else {
        this.changeTextColor(color1);
        this.drawText(current, x1, y, valueWidth, 'right');
    }
};

Now in your original function instead of using

Code:
this.drawCurrentAndMax(actor.currentParam, actor.maxParam, rect.x+266, rect.y, 64, color1, color2)

We can use

Code:
this.drawCurrentAndMaxCustom(actor.currentParam, actor.maxParam, rect.x+266, rect.y, 64, color1, color2)


As a side note, if you want to have a few different labels all with different character lengths you could add a new parameter to the custom function like so:

Code:
//add parameter label after color2
Window_Base.prototype.drawCurrentAndMaxCustom = function(current, max, x, y,
                                                   width, color1, color2, label) {
    var labelWidth = this.textWidth(label);  //use the value of label to get the labelWidth
    var valueWidth = this.textWidth('0000');
    var slashWidth = this.textWidth('/');
    var x1 = x + width - valueWidth;
    var x2 = x1 - slashWidth;
    var x3 = x2 - valueWidth;
    if (x3 >= x + labelWidth) {
        this.changeTextColor(color1);
        this.drawText(current, x3, y, valueWidth, 'right');
        this.changeTextColor(color2);
        this.drawText('/', x2, y, slashWidth, 'right');
        this.drawText(max, x1, y, valueWidth, 'right');
    } else {
        this.changeTextColor(color1);
        this.drawText(current, x1, y, valueWidth, 'right');
    }
};

This time we would use:

Code:
this.drawCurrentAndMaxCustom(actor.currentParam, actor.maxParam, rect.x+266, rect.y, 64, color1, color2, "SCP")
// notice "SCP" is added as the final parameter, this can now be any number of characters
ok thanks! I got everything working as I was hoping to! I can't thank you enough honestly. I was having a lot of issues with lag before, so this is a much better option.

Original thread: https://forums.rpgmakerweb.com/threads/showing-custom-gauges.116205/