WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Setting fontsize for ChatFrame1 (https://www.wowinterface.com/forums/showthread.php?t=58797)

DarkruneDOTDK 06-16-21 11:07 AM

Setting fontsize for ChatFrame1
 
Hi.

I am trying to set the font size for ChatFrame1 (General), but it doesn't seem to update correctly... Doing a /reload will reset the font size to the size it had before the change. It starts by having a font size of 14 on a new character.

Code:
Code:

local name, fontSize, r, g, b, a, shown, locked = FCF_GetChatWindowInfo(1);
local fontFile, _, fontFlags = ChatFrame1:GetFont();
ChatFrame1:SetFont(fontFile, 12, fontFlags);

Is there something I need to do for it to be remembered? - The purpose is to make it easier to setup a new character, so you more or less write a slash command and it does all of it for you.

Fizzlemizz 06-16-21 11:20 AM

You've given no context as to the where, when and how this code is called. Makes it almost impossible to comment other than to say the first line doesn't seem to to have anything to do with the other two so maybe there is more code that is missing from your post?


Are you running any chat addons like Prat?

DarkruneDOTDK 06-16-21 11:50 AM

Quote:

Originally Posted by Fizzlemizz (Post 339404)
You've given no context as to the where, when and how this code is called. Makes it almost impossible to comment other than to say the first line doesn't seem to to have anything to do with the other two so maybe there is more code that is missing from your post?


Are you running any chat addons like Prat?

Ohh sorry...

The idea is that it is being run with a slash command after the addon has been loaded.
So I have added a SlashCmdHandler like this:
Code:

SLASH_DLU1 = "/dlu";
SlashCmdList.DLU = function(commandName)
        DLU:SlashCmdHandler(commandName);
end

The argument passed is then split like this:
Code:

function DLU:SlashCmdHandler(msg)
        local command, arg2, arg3 = strsplit(" ", msg);
        local arg = command:lower();
if (arg == "test") then
                Test();
        end
end

The Test method would then apply some settings (will be renamed at some point).
Right now I have just looked at the code here (line number 3209) and made a minor change (hard-coded the font size to 12).
I am however not able to call some of the methods in the file, like the ChatFrame_UpdateDefaultChatTarget(self), that I would believe would commit the update to the blizzard servers or something...

Currently I am not using any addon that would modify the chat window at all (actually not using anything that changes the original UI).

Probably also worth mentioning I am doing this in TBC Classic.

Fizzlemizz 06-16-21 12:24 PM

To save information between sessions you need to add a setting you your .toc file

for use by ALL characters (or set up a character specific mechanism here):
Code:

## SavedVariables: xxx
Information saved only usable by the current character:
Code:

## SavedVariablesPerCharacter: xxx
If your .toc had
Code:

## SavedVariablesPerCharacter: DarkruneDOTDK_DATA
To save/set the font size you could do something like:

Lua Code:
  1. local function SetFontSize()
  2.     local fontFile, _, fontFlags = ChatFrame1:GetFont();
  3.     ChatFrame1:SetFont(fontFile, DarkruneDOTDK_DATA.fontSize, fontFlags);
  4. end
  5.  
  6. local f = CreateFrame("Frame") -- a frame to handle events
  7. f:SetScript("OnEvent", function(self, event, ...) -- Event handler
  8.     DarkruneDOTDK_DATA = DarkruneDOTDK_DATA or { -- check if your SavedVariables table exists
  9.         fontSize = 12,              -- If not, create it and set some defaults
  10.         someOtherThing = 99,
  11.     }
  12.     SetFontSize() -- Then automatically set the saved font size each login
  13. end)
  14. f:RegisterEvent("PLAYER_LOGIN") -- Event to listen for. This event fires when you login after all addons have loaded
  15.  
  16.  
  17. function DLU:SlashCmdHandler(msg)
  18.     local command, arg2, arg3 = strsplit(" ", msg);
  19.     command = command:lower();
  20.     if command == "size" then -- We want to set a new font size
  21.         DarkruneDOTDK_DATA.fontSize = tonumber(arg2) -- New size, save it to your SavedVariables table
  22.         SetFontSize() -- Update the chat frame with the new size
  23.     end
  24. end
  25.  
  26. SLASH_DLU1 = "/dlu";
  27. SlashCmdList.DLU = function(commandName)
  28.     DLU:SlashCmdHandler(commandName);
  29. end

SavedVariables are global so the name you use for yours should be unique to your addon ie. something like DarkruneDOTDK_DATA

DarkruneDOTDK 06-16-21 02:07 PM

Thanks, seems to work the way I want :-)


All times are GMT -6. The time now is 03:54 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI