PDA

View Full Version : How to change calendar days/months font color?



SirMotte
May 25th, 2020, 12:58
Please see post: #14 (https://www.fantasygrounds.com/forums/showthread.php?58354-How-to-change-calendar-days-months-font-color&p=514772&viewfull=1#post514772) for the solution :).

FGU latest public release
5E Ruleset
Gregorian Calendar

Hey there,
while working on a theme, I stumbled across a problem that I wasn't able to solve for 2 weeks now and searching the forum didn't provide any results related to this:

I absolutely can't figure out how to change the font color (to white or something else) for the days and months in the calendar.
36077
36089

I figured that the xml entries below should do the trick, but this didn't work. I found that at least some colors can be influenced by using the utility_calendar.xml,
but I'd like to avoid having too many xml files included in the theme.

Does anyone have a clue what I'm missing?
The fonts are correctly placed within the fonts folder and all paths are correct.

Here the fonts.xml entries I thought should work, but don't:

<!-- Calendar -->
<font name="calendarday">
<fgffile name="graphics/fonts/regular-10.fgf" />
<ttf file="graphics/fonts/Roboto-Regular.ttf" name="Roboto" size="16" />
<color value="#DDDDDD" />
</font>
<font name="calendarday-b">
<fgffile name="graphics/fonts/regular-10.fgf" />
<ttf file="graphics/fonts/Roboto-Regular.ttf" name="Roboto" size="16" />
<color value="#DDDDDD" />
</font>
<font name="calendarday-bi">
<fgffile name="graphics/fonts/regular-10.fgf" />
<ttf file="graphics/fonts/Roboto-Regular.ttf" name="Roboto" size="16" />
<color value="#DDDDDD" />
</font>
<font name="calendarbold">
<fgffile name="graphics/fonts/bold-10.fgf" />
<ttf file="graphics/fonts/Roboto-Bold.ttf" name="Roboto-Bold" size="16" />
<color value="#DDDDDD" />
</font>
<font name="calendarselecttitle">
<fgffile name="graphics/fonts/bold-10.fgf" />
<ttf file="graphics/fonts/Roboto-Bold.ttf" name="Roboto-Bold" size="16" />
<color value="#DDDDDD" />
</font>
<font name="calendarselectbody">
<fgffile name="graphics/fonts/regular-10.fgf" />
<ttf file="graphics/fonts/Roboto-Regular.ttf" name="Roboto" size="16" />
<color value="#DDDDDD" />
</font>
<font name="calendarmessage">
<fgffile name="graphics/fonts/italic-10.fgf" />
<ttf file="graphics/fonts/Roboto-Italic.ttf" name="Roboto-Italic" size="16" />
<color value="#DDDDDD" />
</font>

Thanks in advance!

SirMotte

damned
May 25th, 2020, 14:41
check corerpg
\utility\utility_calendar.xml


<stringcontrol name="viewdate">
<anchored to="dateframe" height="20">
<right anchor="center" offset="-80" />
<top offset="25" />
</anchored>
<color>5A1E33</color>
<font>calendarbold</font>
<nodrag />
<nodragselect />
<readonly />
</stringcontrol>
<label_fieldtop>
<anchored to="viewdate" />
<static textres="calendar_label_date" />
</label_fieldtop>
<basicnumber name="currentyear" source="current.year">
<anchored to="dateframe" width="40" height="20">
<left anchor="center" offset="-70" />
<top offset="25" />
</anchored>
<color>5A1E33</color>
<hideonvalue>0</hideonvalue>
<delaykeyupdate />
<script>
function onValueChanged()
window.onYearChanged();
end
</script>
</basicnumber>

You can see several colours being defined there - after the font has already been defined.

SirMotte
May 25th, 2020, 14:52
check corerpg
\utility\utility_calendar.xml


<stringcontrol name="viewdate">
<anchored to="dateframe" height="20">
<right anchor="center" offset="-80" />
<top offset="25" />
</anchored>
<color>5A1E33</color>
<font>calendarbold</font>
<nodrag />
<nodragselect />
<readonly />
</stringcontrol>
<label_fieldtop>
<anchored to="viewdate" />
<static textres="calendar_label_date" />
</label_fieldtop>
<basicnumber name="currentyear" source="current.year">
<anchored to="dateframe" width="40" height="20">
<left anchor="center" offset="-70" />
<top offset="25" />
</anchored>
<color>5A1E33</color>
<hideonvalue>0</hideonvalue>
<delaykeyupdate />
<script>
function onValueChanged()
window.onYearChanged();
end
</script>
</basicnumber>

You can see several colours being defined there - after the font has already been defined.

Hey damned thank you for the reply!

The core utility_calendar.xml is what I currently use to define the colors at the calendar top (see image above). Unfortunately the entries there do not seem to affect the day number columns in any way.
Also shouldn't the graphics_fonts.xml affect those aswell, as they change the parameters of eg. "calendarbold"?

Thanks
SirMotte

Edit: Okay, I just deleted the color entries in the utility_calendar.xml to see if the #DDDDDD color definition in my graphics_fonts.xml would work at all. And it does. That means I am missing the proper "font name =" definition for the calendar days font?
36080

damned
May 25th, 2020, 15:10
No.
The fonts are defined first.
The templates are defined next.
The file above is running last and it has a color code in it.
You will need to merge your changes into the calendar file Im pretty sure.

SirMotte
May 25th, 2020, 16:24
No.
The fonts are defined first.
The templates are defined next.
The file above is running last and it has a color code in it.
You will need to merge your changes into the calendar file Im pretty sure.

You are right in regard to loadorder. Please see attached picture on what I found out about what affects the colors in the calendar.
36082

As you can see I can influence some entries with the graphics_fonts.xml if I delete the corresponding color definition inside the utility_calendar.xml. Ultimately I prefer to use the fonts.xml, as I don't like to have things scattered around when changing colors. Other areas are defined directly inside the .lua files.
Yet I still wasn't able to find out how to change the day colums to another color as there doesn't seem to be an entry anywhere, at least I wasn't able to find it.

Thank you for your patience!

Cheers
SirMotte

damned
May 27th, 2020, 14:16
So... it would be nice if everything used a set entry in graphics_fonts.xml and nothing else.
For whatever reason some definitions are re-used but the color code is modified in the xml at the point where the font is used.
In those cases you will need to use merge="join" code to overwrite those settings.

Trenloe
May 27th, 2020, 14:34
Fonts all take up resources in the FG client. The more font definitions you have, the more resources you're using. This may not have a massive effect overall, but it is still better to define a resource like this once and then, if you don't want to use the default colour from the <font> resource definition, change the colour when it's used within a control.

SirMotte
May 27th, 2020, 14:44
Thanks for both your answers. Now this isn't really about where to define what, I simply cant figure out where to define the calendar day columns font at all. Please see the picture below.
36152

Please keep in mind, that I can't even be considered a novice in terms of any kind of programming language, so this might be a little over my head already?

mattekure
May 27th, 2020, 15:52
Thanks for both your answers. Now this isn't really about where to define what, I simply cant figure out where to define the calendar day columns font at all. Please see the picture below.
36152

Please keep in mind, that I can't even be considered a novice in terms of any kind of programming language, so this might be a little over my head already?

I think the script you are looking for is in utility\scripts\calendar_day.lua in the setState() function.



function setState(bCurrDay, bSelDay, bHoliday, nodeEvent)
if bCurrDay then
setBackColor("000000");
label_day.setColor("FFFFFF");
else
setBackColor();
if bHoliday then
label_day.setColor("333399");
else
label_day.setColor("000000");
end
end
if bSelDay then
setFrame("calendarhighlight");
else
setFrame(nil);
end
if bHoliday then
label_day.setFont("calendarday-bi");
label_day.setUnderline(true);
else
label_day.setFont("calendarday");
label_day.setUnderline(false);
end


The script seems to go through each day and determine its formatting based on if its the current day, if there are events, if its a holiday, etc.

SirMotte
May 27th, 2020, 15:57
I think the script you are looking for is in utility\scripts\calendar_day.lua in the setState() function.



label_day.setColor("333399");
else
label_day.setColor("000000");
end



I always thought that this only defined the current day only, but you're correct!

else
label_day.setColor("000000");

sounds promising.

I'll give it a try!

SirMotte
May 27th, 2020, 16:46
Okay, I seem to be too dumb to include a script file.

in the extension.xml I added:

<script file="scripts/calendar_day.lua" />

so far so good.
The calendar_day.lua is in place inside the correct folder and I changed the colors to my liking.
Inside FGU unfortunately nothing changes.

Do I need to add / change anything for the file to execute correctly?
Thanks for your help and patience everyone.

SirMotte
May 29th, 2020, 23:18
Bump. I'm sure this can be solved easily and it would enable me to finish up v 1.2 of my themes for publishing :). Sorry to nag, but I wasn't able to figure this one out myself :(.

StoryWeaver
May 30th, 2020, 18:42
To run code you've written in an extension there are a few steps you need.
The first thing you need to do is to first register the script file in extensions.xml as you've done.

Alternatively if you need to call the scripts functions somewhere you need to give the name a script, such as in the example below:


<script name="MenuItemRegister" file="scripts/menu_item_register.lua" />

If you want your new script to run on boot, then you need to add a function in the top of your script called onInit(), like below.:



function onInit()
registerMenuItems();
end

function registerMenuItems()
...
end

Alternatively you can call the function from any code section of any of your lua files in that extension if you gave it a name like above. Such as here:


function someFunctionFoo()
...
MenuItemRegister.registerMenuItems;
...
end

The final way to do this is more specific, in the cases you're overriding an already existing function. You then need to create an onInit() function, which includes the overriding. And then FG will call the override function when that event occurs, such as for when overriding mouse wheel scrolling over a Token. Token.onWheel is the inbuilt API function (https://www.fantasygrounds.com/refdoc/Token.xcp#onWheel), which I'm overriding here with my own onWheel function.:



function onInit()
Token.onWheel = onWheel;
end


function onWheel(token, notches)
if token == nil then
return;
end
...
end

SirMotte
May 30th, 2020, 20:03
[SOLVED]

Oookay.....it was a long road, but I got it....turned out I didn't need to do any additional coding! Your insight led me to the following discovery:

Within the utility_calendar.xml was an entry pointing the file directory of the calendar_day.lua to its default location. I simply had to change this to the correct folder...done -.-.
I had the idea because you told me how to define the script name, so I was wondering if the default name was mentioned anywhere else, overwriting my changes.

THANK YOU SO MUCH, I'll make sure to give your Themes extra care!

Thanks to everyone for your guidance, I feel like I have learned a lot through this.

StoryWeaver
May 30th, 2020, 20:34
Happy to help, glad it worked out!