function ToggleGameMenu()
if ( not UIParent:IsShown() ) then
UIParent:Show();
SetUIVisibility(true);
elseif ( C_Commentator.IsSpectating() and IsFrameLockActive("COMMENTATOR_SPECTATING_MODE") ) then
PvPCommentator:SetFrameLock(false);
elseif ( ModelPreviewFrame:IsShown() ) then
ModelPreviewFrame:Hide();
elseif ( StoreFrame_EscapePressed and StoreFrame_EscapePressed() ) then
elseif ( WowTokenRedemptionFrame_EscapePressed and WowTokenRedemptionFrame_EscapePressed() ) then
elseif ( securecall("StaticPopup_EscapePressed") ) then
elseif ( GameMenuFrame:IsShown() ) then
PlaySound(SOUNDKIT.IG_MAINMENU_QUIT);
HideUIPanel(GameMenuFrame);
elseif ( HelpFrame:IsShown() ) then
ToggleHelpFrame();
elseif ( VideoOptionsFrame:IsShown() ) then
VideoOptionsFrameCancel:Click();
elseif ( AudioOptionsFrame:IsShown() ) then
AudioOptionsFrameCancel:Click();
elseif ( SocialBrowserFrame and SocialBrowserFrame:IsShown() ) then
SocialBrowserFrame:Hide();
elseif ( InterfaceOptionsFrame:IsShown() ) then
InterfaceOptionsFrameCancel:Click();
elseif ( SocialPostFrame and Social_IsShown() ) then
Social_SetShown(false);
elseif ( TimeManagerFrame and TimeManagerFrame:IsShown() ) then
TimeManagerFrameCloseButton:Click();
elseif ( MultiCastFlyoutFrame:IsShown() ) then
MultiCastFlyoutFrame_Hide(MultiCastFlyoutFrame, true);
elseif (SpellFlyout:IsShown() ) then
SpellFlyout:Hide();
elseif ( securecall("FCFDockOverflow_CloseLists") ) then
elseif ( securecall("CloseMenus") ) then
elseif ( CloseCalendarMenus and securecall("CloseCalendarMenus") ) then
elseif ( CloseGuildMenus and securecall("CloseGuildMenus") ) then
elseif ( GarrisonMissionFrame_ClearMouse and securecall("GarrisonMissionFrame_ClearMouse") ) then
elseif ( GarrisonMissionFrame and GarrisonMissionFrame.MissionTab and GarrisonMissionFrame.MissionTab.MissionPage and GarrisonMissionFrame.MissionTab.MissionPage:IsVisible() ) then
GarrisonMissionFrame.MissionTab.MissionPage.CloseButton:Click();
elseif ( GarrisonShipyardFrame_ClearMouse and securecall("GarrisonShipyardFrame_ClearMouse") ) then
elseif ( GarrisonShipyardFrame and GarrisonShipyardFrame.MissionTab and GarrisonShipyardFrame.MissionTab.MissionPage and GarrisonShipyardFrame.MissionTab.MissionPage:IsVisible() ) then
GarrisonShipyardFrame.MissionTab.MissionPage.CloseButton:Click();
elseif ( securecall("OrderHallMissionFrame_EscapePressed") ) then
elseif ( securecall("OrderHallTalentFrame_EscapePressed") ) then
elseif ( securecall("BFAMissionFrame_EscapePressed") ) then
elseif ( SpellStopCasting() ) then
elseif ( SpellStopTargeting() ) then
elseif ( securecall("CloseAllWindows") ) then
elseif ( LootFrame:IsShown() ) then
-- if we're here, LootFrame was opened under the mouse (cvar "lootUnderMouse") so it didn't get closed by CloseAllWindows
LootFrame:Hide();
elseif ( ClearTarget() and (not UnitIsCharmed("player")) ) then
elseif ( OpacityFrame:IsShown() ) then
OpacityFrame:Hide();
elseif ( SplashFrame:IsShown() ) then
SplashFrame_Close();
elseif ( ChallengesKeystoneFrame and ChallengesKeystoneFrame:IsShown() ) then
ChallengesKeystoneFrame:Hide();
else
PlaySound(SOUNDKIT.IG_MAINMENU_OPEN);
ShowUIPanel(GameMenuFrame);
end
end