Text Alignment (YEP_JobPoints) - SOLVED!

Status
Not open for further replies.

Frostorm

[]D[][]V[][]D aka "Staf00"
Veteran
Joined
Feb 22, 2016
Messages
1,116
Reaction score
808
First Language
English
Primarily Uses
RMMV
So I'm using @SomeFire's skill tree plugin in addition to Yanfly's Job Points plugin so that I have both JP & SP as a resource for the player. I was able to get the SP to show up on another line underneath JP on the character menu but SP isn't aligned to the right edge like JP is. For JP, the text and icon ill always hug the right side with a certain amount of padding so when the number in front of the icon changes, the position of the icon stays the same. However, this doesn't happen with SP. When the number in front of the SP icon changes, the position of the icon also changes depending on the width of the text (numbers in front of the icon).
Screenshot:
1594513157265.png

Notice how the position of the JP icon remains the same whether the number in front is "11" or "15". However, this is not the case for SP. From what I can tell, the code is using the width of the text for JP as a basis for its position. (i.e. wx += ww - this.textWidthEx(text);)
JavaScript:
Window_Base.prototype.drawActorJp = function(actor, id, wx, wy, ww, align) {
    var jp = actor.jp(id);
    var icon = '\\i[' + Yanfly.Icon.Jp + ']';
    var fmt = Yanfly.Param.JpMenuFormat;
    var sp = actor.getTreesPoints(skillTree); //Gets actor's available Skill Points
    var text = fmt.format(Yanfly.Util.toGroup(jp), Yanfly.Param.Jp, icon);
    if (align === 'left') {
      wx = 0;
    } else if (align === 'center') {
      wx += (ww - this.textWidthEx(text)) / 2;
    } else {
      wx += ww - this.textWidthEx(text);
    }
    this.drawTextEx(text, wx, wy);
    this.drawTextEx(sp + '\\i[157]', ww - this.textWidthEx(text), wy + 32); //Shows Skill Points
};
The issue lies in here: ww - this.textWidthEx(text) which I used in the last line of code. The "text" inside the parenthesis refers to fmt.format(Yanfly.Util.toGroup(jp), Yanfly.Param.Jp, icon); which returns a string if I'm not mistaken. It contains both the JP icon as well as the number representing the quantity that goes in front of it.

Perhaps I need to create something similar for SP, but I don't know how to. Instead, I created a var sp that returns the number of Skill Points. Then I had it draw the icon separately.

I tried using this.drawTextEx(sp + '\\i[157]', ww - this.textWidthEx(sp), wy + 32); instead, but it threw an error...

Substituting ww - this.textWidthEx(text) with wx also doesn't align it correctly since that references the text width of JP instead of SP as well.

Basically, I need it to use the text width of SP instead of JP as a basis for its position. Any solutions? Thx in advance!

Note: My use of Galv_BustMenu should have no effect on this since the issue is present with the default menu setup as well.

Edit: I'm guessing the reason for the error when I tried this.textWidthEx(text)->this.textWidthEx(sp) was because the contents inside the parenthesis has to be a string?

I did just try making it into a string but the result was both lines becoming blank (nothing gets drawn)...
 
Last edited:

Frostorm

[]D[][]V[][]D aka "Staf00"
Veteran
Joined
Feb 22, 2016
Messages
1,116
Reaction score
808
First Language
English
Primarily Uses
RMMV
Woohoo! I did it!
1594522393859.png

If anyone's curious, this is how I fixed it:
JavaScript:
Window_Base.prototype.drawActorJp = function(actor, id, wx, wy, ww, align) {
    var jp = actor.jp(id);
    var icon = '\\i[' + Yanfly.Icon.Jp + ']';
    var fmt = Yanfly.Param.JpMenuFormat;
    var sp = String(actor.getTreesPoints(skillTree) + '\\i[157]'); //Shows actor's available Skill Points
    var text = fmt.format(Yanfly.Util.toGroup(jp), Yanfly.Param.Jp, icon);
    if (align === 'left') {
      wx = 0;
    } else if (align === 'center') {
      wx += (ww - this.textWidthEx(text)) / 2;
    } else {
      wx += ww - this.textWidthEx(text);
    }
    this.drawTextEx(text, wx, wy);
    this.drawTextEx(sp, ww - this.textWidthEx(sp) + 5, wy + 32); //Skill Points
};
The key was indeed turning var sp into a string, as I had assumed.:kaopride:
 
Last edited:

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
3,419
Reaction score
4,480
First Language
English
Primarily Uses
RMMV

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

ESAMarathon on Twitch, now streaming "Eat Girl". Yep, that's the title of a game... Apparently it's a Pacman knockoff.... Which is of course the only logical conclusion one would get from a name like "Eat Girl". :kaopride: I can't believe anybody would think anything else! :kaoback:
Super stoked i just finished my first town in my project, by finished i mean i can always add more decorative aesthetics and the NPCs don't talk yet but the mapping is complete and all the important chess pieces are present!
My brain: Hey, I have an idea how to make the transition to the main story quest in The Wastes more natural!
Me: Good!
My brain: You need to remake the hotel you start out in, it's not realistic enough.
Me: Ok... This was unexpected, but I can do it.
My brain: Now make each hotel floor 5 times as large to match the main part. Oh, you also need to make a bunch of new npcs to fill in the space on these maps.
Me: Crap.
Should be able to release Haxe MV/MZ next weekend.
It look that somehow MZ tracks are messed up (for example battle4 is obviously a theme, castle2 is a ship, ship1 is a scene and so on..). Maybe they just named them after with some ambiguity.

Forum statistics

Threads
100,609
Messages
977,802
Members
132,225
Latest member
nallovint
Top