Changing text color in YEP_ShopMenuCore

Status
Not open for further replies.

TSR

The Northern Frog
Veteran
Joined
Nov 14, 2019
Messages
279
Reaction score
244
First Language
French
Primarily Uses
RMMV
Hi everybody!
I'm new here and it's my firts post; I hope it's the right place to post this...

I'm currently trying to edit Yanfly ShopMenuCore so that it show elements/states rates with icons.
This is the main function I added:

Code:
Window_ShopStatus.prototype.drawAttributes = function() {
    let item = this._item
    let rateList = [1, 1, 1, 1]
    let iconList = [78, 76, 31, 92];
    let iconPos = [4, 69, 132, 196];
    let attributes = ''
    let p = 0;
    let i;
    for (i in item.traits) {
      if (item.traits[i].code === 11) {
        var id = item.traits[i].dataId - 1;
        rateList[id] *= item.traits[i].value;
      }
    }
    for (i = 0; i < 4; i++) {
      if (rateList[i] !== 1) {
        rateList[i] = Math.floor(-1 * (100 - rateList[i] * 100));
        if (rateList[i] >= 200) {
          this.changeTextColor(this.textColor(10));
        } else if (rateList[i] >= 100) {
          this.changeTextColor(this.textColor(2))
        } else if (rateList[i] >= 1) {
          this.changeTextColor(this.textColor(14))
        } else if (rateList[i] >= -25) {
          this.changeTextColor(this.textColor(5))
        } else if (rateList[i] >= -50) {
          this.changeTextColor(this.textColor(13))
        } else if (rateList[i] > -75) {
          this.changeTextColor(this.textColor(31))
        } else if (rateList[i] <= -75) {
          rateList[i] = 'Immune'
          this.changeTextColor(this.textColor(27))
        } else if (rateList[i] < -100) {
          rateList[i] = 'Regen'
          this.changeTextColor(this.textColor(24))
         }
        var iconIndex = iconList[i];
        var bitmap = ImageManager.loadSystem('IconSet');
        var pw = Window_Base._iconWidth;
        var ph = Window_Base._iconHeight;
        var sx = iconIndex % 16 * pw;
        var sy = Math.floor(iconIndex / 16) * ph;
        var dw = 24;
        var dh = 24;
        var dx = iconPos[p];
        var dy = 180;
        this.contents._context.imageSmoothingEnabled = false;
        this.contents.blt(bitmap, sx, sy, pw, ph, dx, dy, dw, dh)
        this.contents._context.imageSmoothingEnabled = true;
        attributes += rateList[i] + '%' + '    ';
        p += 1;
      }
    }
    var rect = this.getBigRectPos(0);
    this.drawText(attributes, rect.x + 30, rect.y - 3, rect.width);
};
And this how it looks:
screen2.png

So it work fine except for the color changes...
I would like it to look like this:

screen1.png

A different color depending on the rate value.
This was scripted in the Yanfly ItemCore <Info Eval> notetag where text codes are accepted.
Since text codes can't be used inside the plugin js files I tried to use the function:
this.changeTextColor(this.textColor(id));
But it change the color of the whole text according to the last entry that was checked in the loop...
I think this is because the this keyword represent the whole function, but I can't figure out how to apply the function to a specific entry;
rateList[id].changeTextColor... makes the game crash.

So I was wondering if someone can point me toward some solutions?
Thanks in advance to anyone who will take the time to reply.
TSR
 

TSR

The Northern Frog
Veteran
Joined
Nov 14, 2019
Messages
279
Reaction score
244
First Language
French
Primarily Uses
RMMV
I solved my problem last night!
I splited the function in 3 functions for the sake of clarity and the solution just appeared to me...
This is the finale 3 functions:

Code:
Window_ShopStatus.prototype.drawAttributes = function() {
    let item = this._item
    let attributes = ''
    let rateList = [1, 1, 1, 1];
    let textPos = [30, 95, 158, 222];
    var p = 0;
    var i;
    var rect = this.getBigRectPos(0);
    for (i in item.traits) {
      if (item.traits[i].code === 11) {
        var id = item.traits[i].dataId - 1;
        rateList[id] *= item.traits[i].value;
      }
    }
    for (i = 0; i < 4; i++) {
      if (rateList[i] !== 1) {
        rateList[i] = Math.floor(-1 * (100 - rateList[i] * 100));
        var text = rateList[i]
        var Text = this.getTextColor(text)
        attributes =  Text + '%' + '    ';
        this.drawText(attributes, textPos[p], rect.y - 3, rect.width);
        this.getIcon(i, p);
        p += 1;
      } 
    }   
};

Window_ShopStatus.prototype.getIcon = function(i, p) {
        let iconList = [78, 76, 31, 92];
        let iconPos = [4, 69, 132, 196];
        let iconIndex = iconList[i];
        let bitmap = ImageManager.loadSystem('IconSet');
        let pw = Window_Base._iconWidth;
        let ph = Window_Base._iconHeight;
        let sx = iconIndex % 16 * pw;
        let sy = Math.floor(iconIndex / 16) * ph;
        let dw = 24;
        let dh = 24;
        let dx = iconPos[p];
        let dy = 180;
        this.contents._context.imageSmoothingEnabled = false;
        this.contents.blt(bitmap, sx, sy, pw, ph, dx, dy, dw, dh)
        this.contents._context.imageSmoothingEnabled = true;
}

Window_ShopStatus.prototype.getTextColor = function(text) {
       if (text >= 200) {
          this.changeTextColor(this.textColor(10));
          text = '+'.concat(text);
        } else if (text >= 100) {
          this.changeTextColor(this.textColor(2));
          text = '+'.concat(text);
        } else if (text >= 1) {
          this.changeTextColor(this.textColor(14));
          text = '+'.concat(text);
        } else if (text >= -25) {
          this.changeTextColor(this.textColor(5));
        } else if (text >= -50) {
          this.changeTextColor(this.textColor(13));
        } else if (text > -75) {
          this.changeTextColor(this.textColor(31));
        } else if (text <= -75) {
          text = 'Immune'
          this.changeTextColor(this.textColor(27));
        } else if (rateList[i] < -100) {
          text = 'Regen'
          this.changeTextColor(this.textColor(24));
        }
      return text
};
This Thread can be close, thanks.
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
7,842
Reaction score
5,225
First Language
Dutch
Primarily Uses
RMXP

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,085
Members
137,584
Latest member
Faustus2501
Top