WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Can I make options dialog using code? (https://www.wowinterface.com/forums/showthread.php?t=52144)

Basil2 04-01-15 12:52 PM

Can I make options dialog by using code?
 
I need to create window with several checkboxes (like PowerAuras options dialog but simplier). I expected to do this using CreateFrame(), but the following code doesn't work at all:

Code:

function OpenSettingsFrame()
    local f = RecommendOptionsFrame -- this frame is defined in xml file
    f:Show()
   
    CreateFeatureLine(f, RcmSettings.Riptide)
    CreateFeatureLine(f, RcmSettings.Surge)
end

function CreateFeatureLine(parent, feature)
    f = CreateFrame("FontString ", nil, parent)
    f:Show()
    f:SetText(feature.Name)
    for k, v in pairs(feature.Values) do
        CreateCheckbox(f, v, UseTypeNames[k])
    end
end

function CreateCheckbox(parent, value, ttp)
    b = CreateFrame("CheckButton", nil, parent)
    b:Show()
    b:SetChecked(value)
    b.tooltip = ttp;
end

First of all, CreateFrame("FontString") fails - it writes "Unknown frame type 'FontString'". I am a bit surprised - I expected that every type of xml frame can be created via code.

Second, if I change "FontString" just to "Frame", the code generates no errors but doesn't work - checkboxes do not appear. At the same time, RecommendOptionsFrame is shown correctly (I see it on screen).

And third, I have questions :) :

1. How to make frame with text using code?
2. Why checkboxes don't appear?
3. Which addon does create its GUI using code? (that I can inspect).

Lombra 04-01-15 02:11 PM

Font strings are not "frames", but "regions", and they're created differently, using frame:CreateFontString().

Frames are essentially no more than anchor points as far as visuals go. You need to somehow use textures to get something visible.

jeffy162 04-01-15 02:17 PM

Why not check and see how "PowerAuras" does this? Actually, you can check quite a few addons that have an option screen. Many addons now use an option screen in the "AddOns" tab of Blizzard's default options.

Basil2 04-02-15 01:37 AM

Quote:

Originally Posted by jeffy162 (Post 307897)
Why not check and see how "PowerAuras" does this? Actually, you can check quite a few addons that have an option screen.

PowerAuras does this by using XML, which I am trying to avoid :) I watched several addons with dialog window but all of them used XML.

Basil2 04-02-15 02:11 AM

Quote:

Originally Posted by Lombra (Post 307896)
Font strings are not "frames", but "regions", and they're created differently, using frame:CreateFontString().

Frames are essentially no more than anchor points as far as visuals go. You need to somehow use textures to get something visible.

Thank you for guidance, I changed code to following:

Code:

f = RecommendOptionsFrame:CreateFontString("abc", "OVERLAY", "GameFontNormal")
f:Show()
f:SetText("12345555664dfgfdg")

However, text doesn't apear on frame :( Same XML code works perfectly

Code:

    <Layers>
      <Layer level="OVERLAY">
        <FontString name="OptionsString" inherits="GameFontNormal" text="Recommend options">
        </FontString>
      </Layer>
    </Layers>


odjur84 04-02-15 02:58 AM

Hi!

It seems that you haven't anchored the FontString-object to anything. Try something like

Code:

f:SetPoint("CENTER",nil,"CENTER",0,0)
Cheers,

Odjur

Seerah 04-02-15 08:15 PM

Also, you have to explicitly tell it to be shown. Frames/regions are shown by default when created.

Basil2 04-03-15 03:19 AM

Quote:

Originally Posted by odjur84 (Post 307911)
Hi!
It seems that you haven't anchored the FontString-object to anything. Try something like

It works after this, thank you much for help!

I also discovered why my checkboxes don't appear - I forgot to add 4-th function parameter: template.

Seerah 04-03-15 02:52 PM

If you don't want your objects to inherit from a pre-defined template, then you're going to have to do that work on your own. (Size, position, texture, font, etc.)


All times are GMT -6. The time now is 02:52 PM.

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