Attract-Mode Support Forum

Attract-Mode Support => Scripting => Topic started by: jdye82 on October 09, 2017, 01:22:04 AM

Title: Text styling questions
Post by: jdye82 on October 09, 2017, 01:22:04 AM

I'm hoping someone can help me with a, hopefully, pretty simple newbie question.

I have the following string that I want to be able to style in two different colours:

Code: [Select]
local details = fe.add_text("[Title] - Plays: [PlayedCount]", flx*0.235, fly*0.02, flw*0.300, flh*0.500 );
For example, I want the title to be white but the play count to be blue. But I have to have the two grouped together so that the play count always follows on directly from the title - I don't them to be positioned independently.

Also, how can I make this string uppercase? I have tried using toupper, as below, but it doesn't work.

Code: [Select]
details.toupper();
thanks in advance for any help.
Title: Re: Text styling questions
Post by: keilmillerjr on October 09, 2017, 03:42:19 AM
A string is "A string". You must separate your parts to style them differently.

details.toupper() is not a declaration. Assign the result to your details variable as such: details = details.toupper();
Title: Re: Text styling questions
Post by: jdye82 on October 09, 2017, 05:31:54 AM
OK. So, to get my desired effect - of having the Title and Play Count coloured individually, but placed within / positioned with the same text object - presumably I need to define and colour each individually and then call them together within a text object? (as you can tell, I'm no programmer and so very likely not using the correct terms here).
If so, how would I go about doing this?
Title: Re: Text styling questions
Post by: qqplayer on October 09, 2017, 07:28:14 AM
I think the "easy way" to get uppercase text is set an "only uppercase" font on your layout  :)

Code: [Select]
fe.layout.font="New Athletic M54";
To get different text styles make something like this:

Code: [Select]
local tittletext = fe.add_text("[Title] , flx*0.235, fly*0.02, flw*0.300, flh*0.500 );
tittletext.charsize = 16;
tittletext.align = Align.Left;
tittletext.word_wrap = true;
tittletext.alpha = 255;
//tittletext.style = Style.Bold;

And then just change this part:

Code: [Select]
local tittletext = fe.add_text("[Title]
Code: [Select]
local manufacturertext = fe.add_text("[Manufacturer]
Download my theme here , you will see a bunch of text examples.

http://forum.attractmode.org/index.php?topic=1558.0
Title: Re: Text styling questions
Post by: jdye82 on October 10, 2017, 01:29:30 AM
Thanks for the responses.
So, it pretty much looks like I can't easily get the effect/layout I'm after and will have to compromise with text all the same colour and not uppercase.
Title: Re: Text styling questions
Post by: keilmillerjr on October 10, 2017, 03:38:35 AM
Thanks for the responses.
So, it pretty much looks like I can't easily get the effect/layout I'm after and will have to compromise with text all the same colour and not uppercase.

Make them two different objects like I said. If your worried about positioning with different aspect ratios, you could always duplicate the object with complete text, change text to the second text, and change color. This would only work with justify left or right, not center. Hopefully overlaying the object doesn't show artifacts.
Title: Re: Text styling questions
Post by: jdye82 on October 10, 2017, 04:31:11 AM
That wouldn't achieve the alignment I'm after - I want the two to flow together in one text object. Example below.
Title: Re: Text styling questions
Post by: keilmillerjr on October 10, 2017, 05:26:47 AM
That wouldn't achieve the alignment I'm after - I want the two to flow together in one text object. Example below.

Yes. Same result in two objects.

Create object with "the simpsons plays 13".
Style it blue.
Create object with "the simpsons" and same positioning as previous object.
Style it green.

Let me know how it looks.
Title: Re: Text styling questions
Post by: jdye82 on October 10, 2017, 06:08:16 AM
Ah, I get you now. Yeah, that sounds like it'd work fine. I'll give it a try this evening and will let you know how it turned out.
Thanks!
Title: Re: Text styling questions
Post by: jedione on October 10, 2017, 06:59:15 AM
here you are...


(http://i68.tinypic.com/vz78jr.png)

Code: [Select]
//game title1
local l = fe.add_text("[Title]   players:  [Players]", flx*0.185, fly*0.080, flw*0.300, flh*0.500 );
l.charsize = 47;
l.alpha = 255;
l.font="mad";
l.set_rgb( 66, 206, 244 );
l.align = Align.Left;
l.rotation = ( 90 );

//game title2
local l = fe.add_text("[Title]", flx*0.185, fly*0.080, flw*0.300, flh*0.500 );
l.charsize = 47;
l.alpha = 255;
l.font="mad";
l.set_rgb( 255, 0, 0 );
l.align = Align.Left;
l.rotation = ( 90 );
Title: Re: Text styling questions
Post by: jdye82 on October 11, 2017, 01:11:23 AM
Got the colours working now. Thanks all for the advice.
Now searching for a decent replacement font that's all caps. If only I could get .toupper could work!
Title: Re: Text styling questions
Post by: keilmillerjr on October 11, 2017, 03:24:36 AM
Got the colours working now. Thanks all for the advice.
Now searching for a decent replacement font that's all caps. If only I could get .toupper could work!

http://www.squirrel-lang.org/squirreldoc/reference/language/builtin_functions.html#string.toupper

string.toupper()
returns a uppercase copy of the string.

It works. Make sure you reasign string if you want to change it. Example: string = string.toupper();
Title: Re: Text styling questions
Post by: jedione on October 11, 2017, 06:35:21 AM
here is all i can see of the use on the site

http://forum.attractmode.org/index.php?topic=636.msg4503#msg4503 (http://forum.attractmode.org/index.php?topic=636.msg4503#msg4503)

with a working example that you made ,, but i cant get it to show anything.

i know your bizzy dude, but could you please make a working example from this..
Code: [Select]
local l = fe.add_text("[Title]", flx*0.185, fly*0.080, flw*0.300, flh*0.500 );
it,s pretty obvious that this is a bit over our heads...,, then we could all learn something from you.
thanks.

update to reply,,,thanks brother u rock...


Title: Re: Text styling questions
Post by: keilmillerjr on October 11, 2017, 07:03:46 AM
here is all i can see of the use on the site

http://forum.attractmode.org/index.php?topic=636.msg4503#msg4503 (http://forum.attractmode.org/index.php?topic=636.msg4503#msg4503)

with a working example that you made ,, but i cant get it to show anything.

i know your bizzy dude, but could you please make a working example from this..
Code: [Select]
local l = fe.add_text("[Title]", flx*0.185, fly*0.080, flw*0.300, flh*0.500 );
it,s pretty obvious that this is a bit over our heads...,, then we could all learn something from you.
thanks.

Will do when out of work tonight. Super simple. No worries.
Title: Re: Text styling questions
Post by: keilmillerjr on October 11, 2017, 03:52:50 PM
here is all i can see of the use on the site

http://forum.attractmode.org/index.php?topic=636.msg4503#msg4503 (http://forum.attractmode.org/index.php?topic=636.msg4503#msg4503)

with a working example that you made ,, but i cant get it to show anything.

i know your bizzy dude, but could you please make a working example from this..
Code: [Select]
local l = fe.add_text("[Title]", flx*0.185, fly*0.080, flw*0.300, flh*0.500 );
it,s pretty obvious that this is a bit over our heads...,, then we could all learn something from you.
thanks.

update to reply,,,thanks brother u rock...

Try this:

Code: [Select]
function title(){
  local text = fe.game_info(Info.Title);
  return text.toupper();
}
local title = fe.add_text(„[!title]", flx*0.185, fly*0.080, flw*0.300, flh*0.500 );
Title: Re: Text styling questions
Post by: jedione on October 11, 2017, 07:42:22 PM
ya this is working , for uppercase,
but.
it is dropping the magic tokin of  [!Players] at the end of it.

Code: [Select]
function title(){
  local text = fe.game_info(Info.Title );
  local text = fe.game_info(Info.Title );
  return text.toupper();
}
local title = fe.add_text("[!title] PLAYERS   [!Players] ", flx*0.185, fly*0.080, flw*0.300, flh*0.500 );
title.charsize = 47;
title.alpha = 255;
title.font="mad";
title.set_rgb( 255, 0, 0 );
title.align = Align.Left;
title.rotation = ( 90 );


//*********************************************************


function title(){
  local text = fe.game_info(Info.Title);
  return text.toupper();
}
local title = fe.add_text("[!title]", flx*0.185, fly*0.080, flw*0.300, flh*0.500 );
title.charsize = 47;
title.alpha = 255;
title.font="mad";
title.set_rgb( 255, 255, 0 );
title.align = Align.Left;
title.rotation = ( 90 );


pic
(http://i65.tinypic.com/29fxq86.png)

by the way thanks for your help!
Title: Re: Text styling questions
Post by: jedione on October 11, 2017, 08:22:43 PM
ok got it working..thanks for your code.....

final post and code.....

Code: [Select]
function title(){
  local text = fe.game_info(Info.Title ) ;
  local text = fe.game_info(Info.Title ) ;

  return text.toupper();
}
local title = fe.add_text("[!title] PLAYERS  [Players] ", flx*0.185, fly*0.080, flw*0.300, flh*0.500 );
title.charsize = 32;
title.alpha = 255;
title.font="mad";
title.set_rgb( 255, 0, 0 );
title.align = Align.Left;
title.rotation = ( 90 );

//*********************************************************

function title(){
  local text = fe.game_info(Info.Title);
  return text.toupper();
}
local title = fe.add_text("[!title]", flx*0.185, fly*0.080, flw*0.300, flh*0.500 );
title.charsize = 32;
title.alpha = 255;
title.font="mad";
title.set_rgb( 255, 255, 0 );
title.align = Align.Left;
title.rotation = ( 90 );

pic =
(http://i64.tinypic.com/zsldnl.png)

ALL UPPER CASE  GOOD TO GO THANK YOU.
Title: Re: Text styling questions
Post by: jdye82 on October 12, 2017, 01:21:27 AM
Brilliant.

Thank you keilmillerjr and jedione for your help and time on this. Will give it a go this evening (UK).
Title: Re: Text styling questions
Post by: jdye82 on October 13, 2017, 12:54:42 AM
OK, I have no idea where I'm going wrong, but I still can't get this to work.

Here's the code.

Code: [Select]
function title(){
  local text = fe.game_info(Info.Title);
  return text.toupper();
}

local title = fe.add_text("[!title]  PLAYS: [PlayedCount]", flx*0.235, fly*0.02, flw*0.600, flh*0.500 );

Using this, the text doesn't display at all, so something's off. As soon as I remove the function and stop trying to make the text uppercase, it's fine. So it's definitely the function causing the issues  :(

Any final thoughts? If not, I'll learn to live with it, or will find a suitable replacement uppercase font.
Title: Re: Text styling questions
Post by: kent79 on October 13, 2017, 01:51:44 AM
OK, I have no idea where I'm going wrong, but I still can't get this to work.

Here's the code.

Code: [Select]
function title(){
  local text = fe.game_info(Info.Title);
  return text.toupper();
}

local title = fe.add_text("[!title]  PLAYS: [PlayedCount]", flx*0.235, fly*0.02, flw*0.600, flh*0.500 );

Using this, the text doesn't display at all, so something's off. As soon as I remove the function and stop trying to make the text uppercase, it's fine. So it's definitely the function causing the issues  :(

Any final thoughts? If not, I'll learn to live with it, or will find a suitable replacement uppercase font.

Could you mind provide nut file to us for checking?
Title: Re: Text styling questions
Post by: jdye82 on October 13, 2017, 03:30:41 AM
Sure. Attached
Title: Re: Text styling questions
Post by: kent79 on October 13, 2017, 05:58:01 AM
Please update filtername fucntion as below  :)

function filtername(){
     local text = fe.filters[1];
     return text.name.toupper();
}
Title: Re: Text styling questions
Post by: jdye82 on October 13, 2017, 10:35:04 AM
Please update filtername fucntion as below  :)

function filtername(){
     local text = fe.filters[1];
     return text.name.toupper();
}

OK. So, the ROM name/title is now showing - and working in uppercase!!

BUT, The filer/list name is not showing now. So it looks like there's something wrong with fe.filters[1] ?
Title: Re: Text styling questions
Post by: kent79 on October 13, 2017, 04:26:43 PM
I think you set a incorrect x axis location (outside of screen)

local filter2 = fe.add_text("LIST:", flx*1.18, fly*0.02, flw*0.600, flh*0.500 );

Please try to change it to flx*0.1



Title: Re: Text styling questions
Post by: jdye82 on October 14, 2017, 01:25:39 AM
I think you set a incorrect x axis location (outside of screen)

local filter2 = fe.add_text("LIST:", flx*1.18, fly*0.02, flw*0.600, flh*0.500 );

Please try to change it to flx*0.1

Unfortunately that's not the issue. The text is being rotated 90 degrees, which is why it needs the odd positioning. The text "LIST:" is still visible, just not the filter/list name. So the problem definitely appears to be in the function?
Title: Re: Text styling questions
Post by: kent79 on October 14, 2017, 03:35:06 AM
local filter1 = fe.add_text("LIST: [!filtername]", flx*0.18, fly*0.02, flw*0.600, flh*0.500 );

Please change this line

Title: Re: Text styling questions
Post by: jdye82 on October 14, 2017, 07:03:17 AM
Honestly, that's not the problem.

If I swap [!filtername] with [FilterName] it works fine (but is obviously not in capitals). The issue I'm having is that the function isn't working.
Title: Re: Text styling questions
Post by: kent79 on October 14, 2017, 07:14:11 AM
Honestly, that's not the problem.

If I swap [!filtername] with [FilterName] it works fine (but is obviously not in capitals). The issue I'm having is that the function isn't working.

Actually, did you try to change ? What is your result?

local filter1 = fe.add_text("LIST: [!filtername]", flx*0.18, fly*0.02, flw*0.600, flh*0.500 );
Title: Re: Text styling questions
Post by: jedione on October 14, 2017, 07:33:39 AM
ya the magic tokins
[DisplayName][FilterName]
are not displayed,  all the others are like [Emulator], [Name], ext...are because your calling .info

this is because their is no scraped or add info for this category  [DisplayName] @t       romlists>snes.cfg
ie:#Name;Title;Emulator;CloneOf;Year;Manufacturer;Category;Players;Rotation;Control;Status;DisplayCount;DisplayType;AltRomname;AltTitle;Extra;Buttons

im sure this is were .info is pulled from

ill mess with it anf see what i can find out after work..peace
Title: Re: Text styling questions
Post by: jdye82 on October 14, 2017, 10:12:26 AM
Honestly, that's not the problem.

If I swap [!filtername] with [FilterName] it works fine (but is obviously not in capitals). The issue I'm having is that the function isn't working.

Actually, did you try to change ? What is your result?

local filter1 = fe.add_text("LIST: [!filtername]", flx*0.18, fly*0.02, flw*0.600, flh*0.500 );

This just moved the text ("LIST:") to the other side of the screen, but the filter name from the function is still not working.
Title: Re: Text styling questions
Post by: jdye82 on October 15, 2017, 03:11:55 AM
Problem solved: I renamed all of my lists/filters in all caps !  8)

Thanks everyone for their time and help. Sometimes there's a much simpler way to do it!