WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Show and Hide frames on button click (https://www.wowinterface.com/forums/showthread.php?t=57177)

twin_tania 06-01-19 10:21 PM

Show and Hide frames on button click
 
I recently started to learn LUA and have been slowly picking a few stuff up and currently am stuck trying to progress further with what I want to do. So far I've learned to create a frame, add a button, and a couple widgets to it. I've also been able to turn the button into something like a macro using SetAttribute("macrotext1", "/wave") but I have been unsuccessful trying to figure out how to press a button that shows a new frame while hiding the current frame. Basically like almost turning a page.

I have managed to create a new frame by pressing the button but this creates a new frame outside of the existing one by doing something like this.

Code:

frame.sBtn:SetScript("OnClick", function()
                local newFrames = CreateFrame("Frame", "DragFrame", UIParent, "TranslucentFrameTemplate")
                newFrames:SetWidth(150)
                newFrames:SetHeight(320)
                newFrames:SetFrameStrata("MEDIUM")
                newFrames:SetPoint("CENTER",  UIParent, "CENTER",0,-20)                       
end)

But as mentioned this only created a brand new frame. I would appreciate any help or if there is somewhere I can get this info that is easy to digest. I tried looking at other addons but the amount of code inside those folders is very overwhelming since I am not quite sure what I need to be looking for.

twin_tania 06-01-19 11:04 PM

Ok, after finally taking a break my mind was finally able to make a bit more progress but it is still incomplete from what I am trying to do. I managed to show and hide on demand by pressing the button a secondary frame I created within the file doing the following.

Code:

local newFrameHidden = false
frame.sBtn:SetScript("OnClick", function(self)
                               
        if newFrameHidden == false then
                newFrame:Hide()
                newFrameHidden = true
        else
                newFrame:Show()
                newFrameHidden = false
        end
       
end)

Now this is probably an ugly approach to someone who is experienced but so far is what I was able to think off at the moment.

Fizzlemizz 06-01-19 11:28 PM

Lua Code:
  1. frame.sBtn:SetScript("OnClick", function(self)
  2.     newFrame:SetShown(not newFrame:IsShown())  
  3. end)

Essentially, change the frame's shown state to what it is not now.

If you wanted to hide frame at the same time, add
Code:

self:GetParent():SetShown(not self:GetParent()IsShown())
to the above script. This assumes you have created the button (sBtn) with "frame" as its parent.

If you have a button on newFrame to toggle back, use the same script in its OnClick handler only replace newFrame with frame


All times are GMT -6. The time now is 11:55 AM.

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