WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Set default text in a text box (https://www.wowinterface.com/forums/showthread.php?t=58820)

Walkerbo 07-02-21 12:04 AM

Set default text in a text box
 
Hi all

I have a frame that can be scaled via a text box.
When I reload I need the text box to be filled with the saved scale.

The frame does correctly scale based on the saved scale on reload however I have not been able to fill the text box with the saved scale value on login.

I get no errors and even when I try to hard-set a number in the text box it remains empty.

Here is my table of variables;
Lua Code:
  1. local NewbDevBoxOptionsTable = {
  2.     ButtonFrameScale = 1,
  3.     ButtonFrameOpacity = 1,
  4.     ButtonIsVisable = true
  5. }
My update frame scale;
Lua Code:
  1. local function updateButtonFrameScale(updateScaleNumber)
  2.     if updateScaleNumber >= 301 then -- if the entered number is too high
  3.         updateScaleNumber = 300
  4.     elseif updateScaleNumber <= 49 then -- if the entered number is too low
  5.         updateScaleNumber = 50
  6.     end
  7.     NewbDevBoxOptionsTable.ButtonFrameScale = updateScaleNumber / 100
  8.     NewbDevBoxButtonFrame:SetScale(NewbDevBoxOptionsTable.ButtonFrameScale)
  9.     NewbDevBoxInterfaceFrame.ScaleTextBox:SetNumber(updateScaleNumber)
  10. end
and setting the frame scale on player login
Lua Code:
  1. if event == "PLAYER_LOGIN" then
  2. NewbDevBoxButtonFrame:SetScale(NewbDevBoxOptionsTable.ButtonFrameScale)
  3. NewbDevBoxInterfaceFrame.ScaleTextBox:SetNumber(NewbDevBoxOptionsTable.ButtonFrameScale * 100)
and here is my textbox setup
Lua Code:
  1. NewbDevBoxInterfaceFrame.ScaleTextBox =
  2.     CreateFrame("EditBox", "NewbDevBoxInterfaceFrameScaleTextBox", NewbDevBoxInterfaceFrame, "OptionsBoxTemplate")
  3. NewbDevBoxInterfaceFrame.ScaleTextBox:SetPoint(
  4.     "TOPLEFT",
  5.     NewbDevBoxInterfaceFrameKeybindsButton,
  6.     "BOTTOMLEFT",
  7.     0,
  8.     NumberList.textBoxYGap
  9. )
  10. NewbDevBoxInterfaceFrame.ScaleTextBox:SetFontObject(TextDimensionList.checkBoxFont)
  11. NewbDevBoxInterfaceFrame.ScaleTextBox:SetNumeric(true)
  12. NewbDevBoxInterfaceFrame.ScaleTextBox:SetSize(NumberList.scaleTextBoxWidth, NumberList.scaleTextBoxHeight)
  13. NewbDevBoxInterfaceFrame.ScaleTextBox:SetMaxLetters(3)
  14. NewbDevBoxInterfaceFrame.ScaleTextBox:SetAutoFocus()
  15. NewbDevBoxInterfaceFrame.ScaleTextBox:SetJustifyH("CENTER")
  16. NewbDevBoxInterfaceFrame.ScaleTextBox:SetScript(
  17.     "OnEnterPressed",
  18.     function(self)
  19.         scaleNumber = tonumber(NewbDevBoxInterfaceFrame.ScaleTextBox:GetText())
  20.         self:ClearFocus()
  21.         updateButtonFrameScale(scaleNumber)
  22.     end
  23. )

I have not been able to work out why this is not working correctly, it is probably staring me in the face yet I cannot see where I have stuffed up.:confused:

Fizzlemizz 07-02-21 02:16 AM

In your setup you're not initialising the editbox with any text:
Code:

NewbDevBoxInterfaceFrame.ScaleTextBox:SetText(NewbDevBoxOptionsTable.ButtonFrameScale)
But then again, your NewbDevBoxOptionsTable is a local table so the information in it will not be saved between sessions.

I might be missing something...

Fizzlemizz 07-02-21 02:37 AM

One other possibility, if your addon is LOD (eg. a config. addon loaded via a slash command or some other) then it might never see the "PLAYER_LOGIN" event.

Walkerbo 07-02-21 06:58 PM

Hi Fizzlemizz

Sorry for the delayed reply.

I once again failed to link my full code.

My pastebin links to my lua, toc

The table of variables is a global table named in my toc.

The playerlogin event fires correctly as I have my setups within the event and they all seem to work correctly.

Now typing in the text box has stopped working due to my trying to fix, so I more than likely have broken the text boxes even more.

Fizzlemizz 07-02-21 11:05 PM

I had to change some fontobjects you created to use GameFontNormal so I'm not sure about the actual EditBox size but that's another thing this might hightlight.

In your PLAYER_LOGIN you can use.

Code:

NewbDevBoxInterfaceFrame.ScaleTextBox:SetNumber(NewbDevBoxOptionsTable.ButtonFrameScale * 100)
NewbDevBoxInterfaceFrame.ScaleTextBox:SetCursorPosition(1)
NewbDevBoxInterfaceFrame.OpacityTextBox:SetNumber(NewbDevBoxOptionsTable.ButtonFrameOpacity * 100)
NewbDevBoxInterfaceFrame.OpacityTextBox:SetCursorPosition(1)

Which should show some of the numbers at least.

Walkerbo 07-03-21 05:58 PM

Hi Fizzlemizz

Cracked it!

You provided the answer, I simply took it to the end.
Lua Code:
  1. NewbDevBoxInterfaceFrame.ScaleTextBox:SetCursorPosition(0)

Now it works perfectly, regardless of the font object, as long as the text box is big enough to accommodate the font size.

Thanks for your help :D


All times are GMT -6. The time now is 01:32 PM.

vBulletin © 2021, Jelsoft Enterprises Ltd
© 2004 - 2021 MMOUI