Hello there! We are conducting a survey to better understand the user experience in making a first edit. If you have ever made an edit on Gamepedia, please fill out the survey. Thank you!

Softcoded tabs

From Wowpedia
Jump to: navigation, search

The below code is from my OpenRaid AddOn. Here you can see a different approach of the tabbed windows:

--@@USAGE
--OpenRaidTabs( <ParentFrame> [, <Childframe> [, nr of tab][,Forced]]) Childframe, nr of tab and Forced are OPTIONAL
--OpenRaidTabs(OpenRaidFrame) Opens OpenRaidFrame
--OpenRaidTabs(OpenRaidFrame, "CreateRaid") Opens OpenRaidFrameCreateRaid
--OpenRaidTabs(OpenRaidFrame, "CreateRaid", 1) Opens OpenRaidFrameCreateRaidTab1
local SaveChild, SaveTab;
function OpenRaidTabs(self, Child, Tab, Forced)
   if IsInTutorial and not Forced then --Are we in a tutorial and do we call it of the tutorial function or not? Forced is only used in tutorial functions.
      return
   end
   local F = self:GetName(); --Get the name of the frame
   if Child ~= "None" and not self.Close then --Do we want to close it or not?
       if self.CurrentTab then --If tab is displayed
           if Child == "Next" and self.NumTab then --If we want to go to the next tab
               _G[F .. self.CurrentTab .. "Tab" .. self.NumTab]:Hide(); --We hide the previous tab
           else
               _G[F .. self.CurrentTab]:Hide(); --We hide the previous childtab
           end
       end
       if Child == "Next" then --If we want to go to the next tab
           self.NumTab = (self.NumTab or 1) + 1; --We count the number of the next tab
           _G[F .. self.CurrentTab .. "Tab" .. self.NumTab]:Show(); --We show this Tab
           if self.NumTab == self[self.CurrentTab .. "Max"] then --If this is the last tab
               self.Close = true; --We can close it afterwards
               _G[F .. "Next"]:SetText("Close"); --Change the text of the "next" button to "close"
           end
       else --If it's not Next and is another child frame
           self.NumTab = nil; --We clear the tab variable
           _G[F]:Show(); --Show the parentframe
           _G[F .. "Next"]:Hide(); --No next button needed for this one
           if Child then
               _G[F .. Child]:Show(); --Show the childframe
               self.CurrentTab = Child; --We save this child frame for future use
               if Tab then --If we also want to show a tab
                   _G[F .. Child .. "Tab" .. Tab]:Show(); --Show the childframe tab
                   self.NumTab = Tab; --We save this tab frame for future use
                   _G[F .. "Next"]:Show(); --We show the next button
               end
           end
       end
   else --None = close window and reset Tabs
       if self.CurrentTab then --If we have a child frame
           if self.NumTab then --If we have a tab
               _G[F .. self.CurrentTab .. "Tab" .. self.NumTab]:Hide(); --We hide the tab
           end
           _G[F .. self.CurrentTab]:Hide(); --We hide the Child frame
       end
       --Reset variables
       self.CurrentTab = nil;
       self.NumTab = nil;
       self.Close = false;
       _G[F .. "Next"]:SetText("Next");
       _G[F]:Hide();
   end
end

This approach works for a frame with a lot of tabs, where hardcoding is not very efficient and bug heavy (if you forget to hide a childframe). There also need to be some initializing for the xml frame.

<Scripts>
    <OnLoad>
        self:Hide();
        self.NumTab = nil;
        self.CurrentTab = nil;
        self.CreateRaidMax = 4; --The amount of tabs for this child frame.
    </OnLoad>
</Scripts>