[RMXP] How to middle-align name window to message window? (using CCOA's UMS script)

Hi everyone, and first of all, I apologise if I've posted in the wrong thread, this is my first time posting. Also I'm sorry if this has been asked before, but i've spent a lot of time with my good friend Google, and still have not found anything like this.

I'm using CCOA's UMS script, and using the FIT_WINDOW_TO_TEXT. How do you move name window to the center of message window, no matter how long or short the message is? With my very limited knowledge of scripts, I know (or at least, I think?) it's at Line 1480 - but while changing that number does move the name window to the middle, it doesn't take into account short messages, or long names (if this makes any sense?)

TLDR: Need some help making sure the name window appears in the middle of the message box constantly, no matter how short the message is or how long the character name is. Thank you in advance!

----

EDIT: Trihan has exactly what I need unfortunately it's not compatible with CCOA's ;_; or at least, i don't know how to combine them without losing the FIT_WINDOW_TO_TEXT from CCOA's... tqia!

(adding their screenshot for clarity)

----

EDIT #2: SOLVED! callmedan has very kindly and helpfully created a patch for this issue! Check out his thread right here!

ccoa's UMS name box position add-on

Please credit callmedan and BlackMage!
If you post a link to the script or thread where we can find CCOA's...
If you post a link to the script or thread where we can find CCOA's...
My apologies! I've edited my post with the link to her thread.
Hate to double post, but is there anybody who could help with this please? :blush:
First of all, at that point neither the script nor you know how wide the name window will ever be after printing the name inside that window. Setting any specific value in line 1480 to the X coordinate will definitely fail there.

The key point here is knowing WHEN and WHERE you need it to make the modification.

Your modification failed because it was not the best moment (meaning not the WHEN you're looking for) to alter its current location on screen.

If it fails there, then you should place it somewhere else. WHERE exactly? Well, just BELOW the set_name call. By then it should know the actual dimensions of that name window with total certainty.
Thanks for responding!

Ah, okay, so what I'm understanding is, I revert Line 1480 back to its original - and that Line 1482 is the one that needs editing, yes? (or is it Line 2481?) But what exactly do I need to write in order for it to be constantly middle-aligned?

Again, very limited knowledge of scripting >.< many thanks!
Well, you move the original line 1480's code right below line 1482:

Ruby:
@name_window.set_name($game_system.name)

So make sure to define the name window's X coordinate below that line.
I did what you suggested but the name still doesn't appear middle aligned, unfortunately.

1706424357247.png
image.png


was studying trihan's script to see if i could modify following their script, but didn't really understand how they made it middle align...
Because there's a logical flaw in your code.

What you did so far was displacing the window to the righthand side without considering how wide the name window itself actually is.

Ask yourself this simple question: do I need to shift it all the way to the right side of the screen?

Or this one: how do you know anything has been centered / justified on screen?
The answer is that you know that once you've measured the blank spaces on both sides and have confirmed they've got the same length.

Edit: Added Emphasis Here.

Go find out how wide both windows are and make the proper calculation of how wide each of those blank spaces should actually be.
?????????

You've completely misunderstood my last post.

do I need to shift it all the way to the right side of the screen?

Check out the code. I did not shift it to the right. It appears to look right-aligned because I am testing it with a long name. With a short name, it appears to look middle-aligned, but it's not, as you can see.

image.png


...without considering how wide the name window itself actually is

Well, that's the thing!! The tricky part is, it has to be middle aligned while applying the FIT_WINDOW_TO_TEXT function and also take into consideration long names and short names. So I tried doing @name_window.x = $game_system.window_width/2 while placing below the set_name call. Was hoping the /2 would mean middle of the message box, regardless of message length.

It's simple but so frustrating. I just want the name window to middle-align, no matter how long or short the name is, no matter how long or short the message is.

I've been trying to find a solution for this from the very beginning, and like I said, I have limited knowledge with scripting, hence I need help writing the line or whatever that needs to be done. If you know how, great! If not, then it's okay.

I know this might be a simple thing and a waste of your time, but please don't be condescending. I'm still learning.
Nope, the problem isn't really your knowledge of scripting. It's been a math issue from the very beginning. That's what I've pointed out in my previous post. It's not being condescending, it's been an attempt to make you understand that the solution depends on a very simple logic that has to be applied there.

Since you've been unable to fully understand the issue so far, even if you've grasped a couple of useful things already, an existing example seems to be badly needed here to demonstrate the principle behind this kind of alignment.

Don't worry! You're not to far from solving the issue. Seriously.

What's funny is that it has always been available to you since day 1. Not laughing at you at all. It just makes me remember my first months as a wannabe scripter.

Well, it's found in Scene_Title. Look for the @command_window and how it gets centered. Learn the principle shown there and you'll be able to apply it in any other situation.

Or perhaps you already did by reading it or my previous post. That would explain how you learned about dividing the width by 2. Good job. But you're still missing a critical component: there are 2 widths involved there.

I haven't checked out if that constant you mentioned could affect the alignment at all, but you're still doing a direct assignment AFTER the name window has been updated and shows the short / long name on screen. This means that such a constant should not be included in the calculation. Yeah, there's a chance that the name window could ignore the empty space to the lefthand side of the screen. You can add that at the beginning or the end of that calculation and it won't affect the final calculation if ever need it. You don't need to calculate it, just add the X coordinate of the main window by using the self.x internal variable.

Final clue here: parentheses do matter a lot in Ruby just as many other languages. You're not using them? Then you got a huge problem there...
To those facing the same problem, callmedan has very kindly and helpfully created a patch for this issue! Check out his thread right here! 😍

ccoa's UMS name box position add-on

Please credit callmedan and BlackMage!

@moderators, you may close this thread now! 😀 and delete the unnecessary replies above too, if you like!

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.

Original thread: https://forums.rpgmakerweb.com/threads/rmxp-how-to-middle-align-name-window-to-message-window-using-ccoas-ums-script.165154/