Thread Tools Display Modes
02/17/23, 01:16 AM   #1
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
Question refresh UI and font without a reloadui?

Hey! I'm looking for a way to basically refresh the UI or something to update font settings. Im working on a feature in my addon that bumps up the nameplate font size a touch, but I cant seem to get it to update it right away without reloadui which I'd really like to avoid for a more pleasant user experience. Any ideas? Ive added a chat feedback and a 1sec delay so the user can see it was changed and then a reload to activate the larger font but ideally it would just activate instantly some other way.

Heres most of what im working with:

Code:
-- Nameplate Font Boost Toggle
function RidinDirty.NamePlatesToggle()
   local fontBoost = RidinDirty.savedVariables.fontBoost
   if fontBoost == nil or fontBoost == "" or fontBoost == "disabled" then
		fontBoost = "enabled"
		RidinDirty.savedVariables.fontBoost = fontBoost
		df("|c9900FF[RidinDirty]|r FontBoost: %s", fontBoost)
		zo_callLater(function() ReloadUI("ingame") end, 1000)
	else
		fontBoost = "disabled"
		RidinDirty.savedVariables.fontBoost = fontBoost
		df("|c9900FF[RidinDirty]|r FontBoost: %s", fontBoost)
		zo_callLater(function() ReloadUI("ingame") end, 1000)
	end
end

Last edited by sinnereso : 02/17/23 at 08:58 AM.
  Reply With Quote
02/18/23, 12:21 AM   #2
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
Anyone have any idea on this? Im just trying to get that code when executed to redraw or refresh the screen or whatever would cause the font to redraw or update..
  Reply With Quote
02/18/23, 03:59 AM   #3
FlatBadger
 
FlatBadger's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2021
Posts: 17
I'm not sure how you're setting the font for the nameplate, but font face and size changes do not require a ui refresh of any kind. They happen instantly when you use the :SetFont(...) function on the relevant control.

For example, if you type the following into the chat window:
Code:
/script ZO_ChatWindowTextEntryLabel:SetFont("ZoFontCallout")
The 'Say:' text will instantly change to something far too big. You can change it back with:

Code:
/script ZO_ChatWindowTextEntryLabel:SetFont("ZoFontChat")
  Reply With Quote
02/18/23, 08:37 AM   #4
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
Originally Posted by FlatBadger View Post
I'm not sure how you're setting the font for the nameplate, but font face and size changes do not require a ui refresh of any kind. They happen instantly when you use the :SetFont(...) function on the relevant control.

For example, if you type the following into the chat window:
Code:
/script ZO_ChatWindowTextEntryLabel:SetFont("ZoFontCallout")
The 'Say:' text will instantly change to something far too big. You can change it back with:

Code:
/script ZO_ChatWindowTextEntryLabel:SetFont("ZoFontChat")
I'd have to agree with you that I was expecting it to be instant. I've even peeked inside a couple big nameplate adds and tested them and they were instant with no apparent code making it instant BUT they had control panel controls and I'm wondering if thats why. Or maybe the callback?

Im setting it like this as its just an on/off function:

Code:
function RidinDirty.PlayerActivated()
	local fontBoost = RidinDirty.savedVariables.fontBoost
	if fontBoost == "enabled" then
		local fontString = string.format("%s|%d", "EsoUI/Common/Fonts/Univers67.otf", "26")
		SetNameplateKeyboardFont( fontString, 1)
		SetNameplateGamepadFont( fontString, 1)
	else
		local fontString = string.format("%s|%d", "EsoUI/Common/Fonts/Univers57.otf", "20")
		SetNameplateKeyboardFont( fontString, 1)
		SetNameplateGamepadFont( fontString, 1)
	end
  Reply With Quote
02/18/23, 09:29 AM   #5
FlatBadger
 
FlatBadger's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2021
Posts: 17
I just tried the following:


Code:
/script SetNameplateKeyboardFont(string.format("%s|%d", "EsoUI/Common/Fonts/Univers67.otf", "26"),FONT_STYLE_SHADOW)
and it took effect immediately.

Two things,
1) (not the problem but...) I think it's better practice to use named constants rather than their values, as I've done above (i.e. FONT_STYLE_SHADOW rather than 1)
2) Your code snippet implies that it only runs in response the to the Player Activated event - are you calling a similar function after you've set your new font?

Last edited by FlatBadger : 02/18/23 at 09:32 AM.
  Reply With Quote
02/18/23, 09:47 AM   #6
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
Originally Posted by FlatBadger View Post
I just tried the following:


Code:
/script SetNameplateKeyboardFont(string.format("%s|%d", "EsoUI/Common/Fonts/Univers67.otf", "26"),FONT_STYLE_SHADOW)
and it took effect immediately.

Two things,
1) (not the problem but...) I think it's better practice to use named constants rather than their values, as I've done above (i.e. FONT_STYLE_SHADOW rather than 1)
2) Your code snippet implies that it only runs in response the to the Player Activated event - are you calling a similar function after you've set your new font?
no thats basically it... its being called in the function RidinDirty.PlayerActivated(). Thats what Ive been looking to change so that its instant.. when in function RidinDirty.PlayerActivated() it requires some form of screen redraw like opening a door or a reloadui to activate the change. I cant seem to find a way for it to just be done instantly or at least its flying right over my head. I could really use some advice on this and maybe some best practices as im very new.
  Reply With Quote
02/18/23, 10:33 AM   #7
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
I had another question as well.. I read someplace in an old post from way back in 2014/15 directly from a DEV its no longer nessisary to "Unregister" events unless your specifically disabling the event..is this correct still? I had several unregister on addonload just to make sure they were i suppose "reset" on addon load. is this not nessisary for sure still?
  Reply With Quote
02/18/23, 11:50 AM   #8
FlatBadger
 
FlatBadger's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2021
Posts: 17
The way you have your code right now means that it will only change the font each time the Player Activated event is triggered, which only happens each time you zone in to somewhere.

If you want it to also change as soon as it's toggled, you need to refactor your code to something like this:
Code:
function RidinDirty.AdjustFont()
	local fontBoost = RidinDirty.savedVariables.fontBoost
	if fontBoost == "enabled" then
		local fontString = string.format("%s|%d", "EsoUI/Common/Fonts/Univers67.otf", "26")
		SetNameplateKeyboardFont( fontString, 1)
		SetNameplateGamepadFont( fontString, 1)
	else
		local fontString = string.format("%s|%d", "EsoUI/Common/Fonts/Univers57.otf", "20")
		SetNameplateKeyboardFont( fontString, 1)
		SetNameplateGamepadFont( fontString, 1)
	end
end

function RidinDirty.PlayerActivated()
	RidinDirty.AdjustFont()
end

-- Nameplate Font Boost Toggle
function RidinDirty.NamePlatesToggle()
   local fontBoost = RidinDirty.savedVariables.fontBoost
   
   if fontBoost == nil or fontBoost == "" or fontBoost == "disabled" then
		fontBoost = "enabled"
		RidinDirty.savedVariables.fontBoost = fontBoost
		df("|c9900FF[RidinDirty]|r FontBoost: %s", fontBoost)
	else
		fontBoost = "disabled"
		RidinDirty.savedVariables.fontBoost = fontBoost
		df("|c9900FF[RidinDirty]|r FontBoost: %s", fontBoost)
	end
	
	RidinDirty.AdjustFont()
end
As for the events, I only unregister the addonload event during the addonload - one of my addons uses many, many events, none of which I unregister at any point after that.

Code:
function BS.OnAddonLoaded(_, addonName)
    if (addonName ~= BS.Name) then
        return
    end

    EVENT_MANAGER:UnregisterForEvent(BS.Name, _G.EVENT_ADD_ON_LOADED)

    Initialise()
end
  Reply With Quote
02/18/23, 11:50 AM   #9
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
Oh got the font updating instantly finally.. somehow i completely missed putting the setkeybameplate... into the actual switch rather than just onplayeractivate().

I am still curious about the Uregistering events tho... ive removed them for the moment to see if i have any issues.
  Reply With Quote
02/20/23, 03:40 AM   #10
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
EVENT_MANAGER:UnregisterForEvent(BS.Name, _G.EVENT_ADD_ON_LOADED)

Should always be done unless you need to read other addons' EVENT_ADD_ON_LOADED too!
This event fires for each of your addons and libraries and as your's is found you can stop it by unregistering in 99%.

EVENT_PLAYER_ACTVATED fires after login the first time, as chat is ready.
You should register it at your EVENT_ADD_ON_LOADED and either keep it registered, because it also fires at a reloadUI, zone change with a loading screem (port into dungeon e.g., or port to someone in another zone ...).
Or you unregister it and it will only fire once after login then.
Depends on your usecase and needs.

Register, unregister, re-register is not needed each time an event fires! If you want events to be triggered each time it fires just keep it registered then. But Make sure the events are not registered before your EVENT_ADD_ON_LOADED was fired, as else you might run into issues where your event's callback function is executed but your code was not ready yet as it will be initialized at your EVENT_ADD_ON_LOADED first.
  Reply With Quote
02/20/23, 03:46 AM   #11
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
Originally Posted by Baertram View Post
EVENT_MANAGER:UnregisterForEvent(BS.Name, _G.EVENT_ADD_ON_LOADED)

Should always be done unless you need to read other addons' EVENT_ADD_ON_LOADED too!
This event fires for each of your addons and libraries and as your's is found you can stop it by unregistering in 99%.

EVENT_PLAYER_ACTVATED fires after login the first time, as chat is ready.
You should register it at your EVENT_ADD_ON_LOADED and either keep it registered, because it also fires at a reloadUI, zone change with a loading screem (port into dungeon e.g., or port to someone in another zone ...).
Or you unregister it and it will only fire once after login then.
Depends on your usecase and needs.

Register, unregister, re-register is not needed each time an event fires! If you want events to be triggered each time it fires just keep it registered then. But Make sure the events are not registered before your EVENT_ADD_ON_LOADED was fired, as else you might run into issues where your event's callback function is executed but your code was not ready yet as it will be initialized at your EVENT_ADD_ON_LOADED first.
Yes thank you.. event are about the one thing I do sorta understand. my only question was if it was still needed in anyway to un-register things like combat_stat etc etc onload incase of something carrying over from before a reloadui or similar to avoid bugs. I read someplace in a 2014 dev post it was no longer nessisary and im just looking for confirmation on that.

I think my addon is basically complete now except id like still to get an oroboros logo rotating onscreen possibly with a label as a sort of hourglass for one of my functions. Once i get that its everything and more id ever hoped for

Last edited by sinnereso : 02/20/23 at 03:49 AM.
  Reply With Quote
02/20/23, 03:52 AM   #12
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
A ReloadUI does clear stuff from before, you do not carry anything over.
All that could be carried over is saved in your addons SavedVariables as they are written to disk at the reloadui and read afterwards again.
So if you experience bugs you should check them (SVs) first

But the user interface and events etc. do not save old states unless there is something saved on server side outside of the addons.

If you reload the UI your addon will be loaded totally new -> EVENT_ADD_ON_LOADED -> other events and code etc.
  Reply With Quote
02/20/23, 03:53 AM   #13
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
ok perfect ty
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » refresh UI and font without a reloadui?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off