Change color of MP/HP damage and add icon in front of it?

It's me again,thank you for answer this thread!😍

I have built up a battle system of Heart Rate(MP) and Sanity(HP).Players must always be aware of their heart rate to prevent falling into an inability to act.When sanity is 0, the battle comes to defeat.
1740985558032.png

Different types of state make different magnification on MP and HP.
For example,an actor under anxiety state may have 0.5 x HP variations and 2 x MP variation.

I have succeed in make magnification by elements.I made all the HP related skills into blue elements type and all the MP related skills into red elements.I use a plugin which can appear different color text with different elements.So that HP text can be blue when the MP text display in red.

But something wrong happened: It only link well to damage formula,but don't link to Formulas in the effects column.
So I wonder how can I Directly define the digital display color for all the HP and MP?(damage and heal)

Besides,in order to show more visualization of the difference between MP and HP,I hope to add icon in front of the text.
My plugins are not suitable for some complex plugins like visustella_battle core,are there any other way to add icon simply?

Hope for your reply!Thanks!😤

=====
Besides,it is the plugin i used to link the element color to the text.
It was written by other forum volunteers (not here).If it can help I would appericiate it!
=====

Sprite_Damage.prototype.damageColor = function() {
const id = BattleManager._action.item().damage.elementId;
switch (id) {
case 10: //element id
return "#82d6fc"; //color
case 11: //elemnet id
return "#ff4384"; //color
default:
return ColorManager.damageColor(this._colorType);
}
};
Why do you need to use element?
By default HP and MP damage numbers show different colors.
Why do you need to use element?
By default HP and MP damage numbers show different colors.
That combat system didn't used to be like that. It does only affect HP and MP now.Elements also play different magnification in battle. (2xHp or 0.5xMP) So I used to bind colors to elements.Some default setting may change color as well (show green style when hp heal)

Looks like I complicated things before. So that means now we can just change the display color of hp and mp in the default settings right?
This is the original damageColor function so maybe you can change the values there.
Maybe let hp damage and recover both display blue text?
JavaScript:
ColorManager.damageColor = function(colorType) {
    switch (colorType) {
        case 0: // HP damage
            return "#ffffff";
        case 1: // HP recover
            return "#b9ffb5";
        case 2: // MP damage
            return "#ffff90";
        case 3: // MP recover
            return "#80b0ff";
        default:
            return "#808080";
    }
};

As for your other question, I think it can be done by modifying this function.
Basically you need to draw icons and maybe show + or - to differentiate damage and heal.
JavaScript:
Sprite_Damage.prototype.createDigits = function(value) {
    const string = Math.abs(value).toString();
    const h = this.fontSize();
    const w = Math.floor(h * 0.75);
    for (let i = 0; i < string.length; i++) {
        const sprite = this.createChildSprite(w, h);
        sprite.bitmap.drawText(string[i], 0, 0, w, h, "center");
        sprite.x = (i - (string.length - 1) / 2) * w;
        sprite.dy = -i;
    }
};
Just a quick two cents here:
The color choice is cool, but those colors in your SS will be quite problematic for colorblind individuals.
Just be mindful of it as you go.

Good luck with your project!
The color choice is cool, but those colors in your SS will be quite problematic for colorblind individuals.
Just be mindful of it as you go.
might be true, but thats why the icon is there 🙂

if the icon in front in explained and the number, it would be good.
just color (numbers without icon) can be more problematic.
JavaScript:
Sprite_Damage.prototype.createDigits = function(value) {
    let string = Math.abs(value).toString();
    if(value>0){
      string = '-' + string;
    }else if(value<0){
      string = '+' + string;
    }
    const h = ImageManager.iconHeight;
    const iconSprite = this.createChildSprite(ImageManager.iconWidth, ImageManager.iconHeight);
    const iconIndex = this._colorType>1?13:12;
    const sx = (iconIndex % 16) * ImageManager.iconWidth;
    const sy = Math.floor(iconIndex / 16) * ImageManager.iconHeight;
    iconSprite.bitmap.blt(ImageManager.loadSystem("IconSet"), sx, sy, ImageManager.iconWidth, ImageManager.iconHeight, 0, 0);
    const totalW = iconSprite.bitmap.measureTextWidth(string) + string.length*2 + ImageManager.iconWidth;
    let x = -totalW/2;
    iconSprite.x = x;
    iconSprite.dy = 0;
    x += ImageManager.iconWidth;
    for (let i = 0; i < string.length; i++) {
      const w = iconSprite.bitmap.measureTextWidth(string[i]);
      const sprite = this.createChildSprite(w+2, h);
      sprite.bitmap.drawText(string[i], 0, 0, w+2, h);
      sprite.x = x;
      sprite.dy = -i - 1;
      x += w + 2;
    }
};
I found the idea icon (or maybe text) before damage number quite interesting.
Gave it a test, doesn't look too bad.
1741014831448.png


Icons 12 and 13 are hp and mp.
1741015066917.png


Edit* Gave digit text more spacing.
JavaScript:
Sprite_Damage.prototype.createDigits = function(value) {
    let string = Math.abs(value).toString();
    if(value>0){
      string = '-' + string;
    }else if(value<0){
      string = '+' + string;
    }
    const h = ImageManager.iconHeight;
    const iconSprite = this.createChildSprite(ImageManager.iconWidth, ImageManager.iconHeight);
    const iconIndex = this._colorType>1?13:12;
    const sx = (iconIndex % 16) * ImageManager.iconWidth;
    const sy = Math.floor(iconIndex / 16) * ImageManager.iconHeight;
    iconSprite.bitmap.blt(ImageManager.loadSystem("IconSet"), sx, sy, ImageManager.iconWidth, ImageManager.iconHeight, 0, 0);
    const totalW = iconSprite.bitmap.measureTextWidth(string) + string.length*2 + ImageManager.iconWidth;
    let x = -totalW/2;
    iconSprite.x = x;
    iconSprite.dy = 0;
    x += ImageManager.iconWidth;
    for (let i = 0; i < string.length; i++) {
      const w = iconSprite.bitmap.measureTextWidth(string[i]);
      const sprite = this.createChildSprite(w+2, h);
      sprite.bitmap.drawText(string[i], 0, 0, w+2, h);
      sprite.x = x;
      sprite.dy = -i - 1;
      x += w + 2;
    }
};
I found the idea icon (or maybe text) before damage number quite interesting.
Gave it a test, doesn't look too bad.
View attachment 333230

Icons 12 and 13 are hp and mp.
View attachment 333231

Edit* Gave digit text more spacing.
Thanks!I would try it tomorrow.It seems quite good.
JavaScript:
Sprite_Damage.prototype.createDigits = function(value) {
    let string = Math.abs(value).toString();
    if(value>0){
      string = '-' + string;
    }else if(value<0){
      string = '+' + string;
    }
    const h = ImageManager.iconHeight;
    const iconSprite = this.createChildSprite(ImageManager.iconWidth, ImageManager.iconHeight);
    const iconIndex = this._colorType>1?13:12;
    const sx = (iconIndex % 16) * ImageManager.iconWidth;
    const sy = Math.floor(iconIndex / 16) * ImageManager.iconHeight;
    iconSprite.bitmap.blt(ImageManager.loadSystem("IconSet"), sx, sy, ImageManager.iconWidth, ImageManager.iconHeight, 0, 0);
    const totalW = iconSprite.bitmap.measureTextWidth(string) + string.length*2 + ImageManager.iconWidth;
    let x = -totalW/2;
    iconSprite.x = x;
    iconSprite.dy = 0;
    x += ImageManager.iconWidth;
    for (let i = 0; i < string.length; i++) {
      const w = iconSprite.bitmap.measureTextWidth(string[i]);
      const sprite = this.createChildSprite(w+2, h);
      sprite.bitmap.drawText(string[i], 0, 0, w+2, h);
      sprite.x = x;
      sprite.dy = -i - 1;
      x += w + 2;
    }
};
I found the idea icon (or maybe text) before damage number quite interesting.
Gave it a test, doesn't look too bad.
View attachment 333230

Icons 12 and 13 are hp and mp.
View attachment 333231

Edit* Gave digit text more spacing.
Sorry to bother you again. This is really helpful.My battle system has been updated recently, and I would like to know if this JS code can also be added to the TP judgment function? Like HP and MP, it has different colors and icons. Is this possible?
I'm not sure. Does TP also has digits pop ups?
I'm not sure. Does TP also has digits pop ups?
No.Would setting up a TP popup be difficult for the code?
It shouldn't be difficult. But I haven't tested the code.
I think you need to modify the 3 methods in which color type is involved.

JavaScript:
Sprite_Damage.prototype.setup = function(target) {
    const result = target.result();
    if (result.missed || result.evaded) {
        this._colorType = 0;
        this.createMiss();
    } else if (result.hpAffected) {
        this._colorType = result.hpDamage >= 0 ? 0 : 1;
        this.createDigits(result.hpDamage);
    } else if (target.isAlive() && result.mpDamage !== 0) {
        this._colorType = result.mpDamage >= 0 ? 2 : 3;
        this.createDigits(result.mpDamage);
    } else if (target.isAlive() && result.tpDamage !== 0) {
        this._colorType = result.tpDamage >= 0 ? 4 : 5;
        this.createDigits(result.tpDamage);
    }
    if (result.critical) {
        this.setupCriticalEffect();
    }
};

JavaScript:
ColorManager.damageColor = function(colorType) {
    switch (colorType) {
        case 0: // HP damage
            return "#ffffff";
        case 1: // HP recover
            return "#b9ffb5";
        case 2: // MP damage
            return "#ffff90";
        case 3: // MP recover
            return "#80b0ff";
        case 4: // TP damage
            return "#FD8F4D";
        case 5: // TP recover
            return "#6D2DAF";
        default:
            return "#808080";
    }
};

JavaScript:
Sprite_Damage.prototype.createDigits = function(value) {
    let string = Math.abs(value).toString();
    if(value>0){
      string = '-' + string;
    }else if(value<0){
      string = '+' + string;
    }
    const h = ImageManager.iconHeight;
    const iconSprite = this.createChildSprite(ImageManager.iconWidth, ImageManager.iconHeight);
    const iconIndex = Math.floor(this._colorType / 2 + 12);
    const sx = (iconIndex % 16) * ImageManager.iconWidth;
    const sy = Math.floor(iconIndex / 16) * ImageManager.iconHeight;
    iconSprite.bitmap.blt(ImageManager.loadSystem("IconSet"), sx, sy, ImageManager.iconWidth, ImageManager.iconHeight, 0, 0);
    const totalW = iconSprite.bitmap.measureTextWidth(string) + string.length*2 + ImageManager.iconWidth;
    let x = -totalW/2;
    iconSprite.x = x;
    iconSprite.dy = 0;
    x += ImageManager.iconWidth;
    for (let i = 0; i < string.length; i++) {
      const w = iconSprite.bitmap.measureTextWidth(string[i]);
      const sprite = this.createChildSprite(w+2, h);
      sprite.bitmap.drawText(string[i], 0, 0, w+2, h);
      sprite.x = x;
      sprite.dy = -i - 1;
      x += w + 2;
    }
};
It shouldn't be difficult. But I haven't tested the code.
I think you need to modify the 3 methods in which color type is involved.
I tried the code, and hp and mp display normally as before, but tp still does not seem to display. Whether I turn off all other plugins or only turn on tp-related plugins, it seems to have no effect.
I just checked the code, this part also needs to be changed.
JavaScript:
Game_Battler.prototype.shouldPopupDamage = function() {
    const result = this._result;
    return (
        result.missed ||
        result.evaded ||
        result.hpAffected ||
        result.mpDamage !== 0 ||
        result.tpDamage !== 0
    );
};
I just checked the code, this part also needs to be changed.
JavaScript:
Game_Battler.prototype.shouldPopupDamage = function() {
    const result = this._result;
    return (
        result.missed ||
        result.evaded ||
        result.hpAffected ||
        result.mpDamage !== 0 ||
        result.tpDamage !== 0
    );
};
It works! However, it seems that pop-ups only appear when the TP of our actors is changed. When I tried to change the TP of the enemies, no pop-ups appeared.
I tested the code and it worked without other plugins.

Original thread: https://forums.rpgmakerweb.com/threads/change-color-of-mp-hp-damage-and-add-icon-in-front-of-it.175963/