--[[
	EXECUTABLE_PATH/Joseph/8.lua
	Joseph | STEAM_0:0:69348930 <2.26.87.183:27005> | [19-10-13 05:31:12PM]
	===BadFile===
]]

--[[
	lua/autorun/client/OubHack/vgui/oh_DSwitchPanel.lua
	Oubliette | (STEAM_0:1:34029133)
	===DStream===
]]

/******************************************************************************
 .d88888b.  888     888 888888b.   888    888        d8888  .d8888b.  888    d8P  
d88P" "Y88b 888     888 888  "88b  888    888       d88888 d88P  Y88b 888   d8P   
888     888 888     888 888  .88P  888    888      d88P888 888    888 888  d8P    
888     888 888     888 8888888K.  8888888888     d88P 888 888        888d88K     
888     888 888     888 888  "Y88b 888    888    d88P  888 888        8888888b    
888     888 888     888 888    888 888    888   d88P   888 888    888 888  Y88b   
Y88b. .d88P Y88b. .d88P 888   d88P 888    888  d8888888888 Y88b  d88P 888   Y88b  
 "Y88888P"   "Y88888P"  8888888P"  888    888 d88P     888  "Y8888P"  888    Y88b 
 By Oubliete and UnknownAlias
*******************************************************************************/

-- The panel opened from the main menu.

local PANEL = {}

function PANEL:Init()
	self.ActivePanel = false;
	self.ExpandingPanel = false;
	self.ContractingPanel = false;
	self.MovingPanel = false;
end

function PANEL:Paint()

	if self.ContractingPanel then
		self.MovingPanel = true
		local cp = self.ContractingPanel;
		local cp_width = math.Approach(cp:GetWide(),0,65)
		local cp_height = math.Approach(cp:GetTall(),0,65)
		cp:SetSize(cp_width,cp_height)
		if cp_width == 0 and cp_height == 0 then 
			self.ContractingPanel:SetVisible(false) 
			self.ContractingPanel = nil
			self.MovingPanel = false
		end
	end

	if self.ExpandingPanel then
		self.MovingPanel = true
		local ep = self.ExpandingPanel;
		local ep_width = math.Approach(ep:GetWide(),self:GetWide(),65)
		local ep_height = math.Approach(ep:GetTall(),self:GetTall(),65)
		ep:SetSize(ep_width,ep_height)	
		if ep_width == self:GetWide() and ep_height == self:GetTall() then 
			self.ExpandingPanel = nil;
			self.ActivePanel = ep;
			self.MovingPanel = false
		end
	end
end

function PANEL:ChangePanel(panel)
	if self.ExpandingPanel then
		self.ExpandingPanel:SetVisible(false)
	end
	if self.ContractingPanel then	
		self.ContractingPanel:SetVisible(false)
	end
	self:ContractPanel()
	self:ExpandPanel(panel)
end

function PANEL:SetPanel(panel)
	self:CloseActivePanel()
	panel:SetParent(self)
	panel:SetPos(0,0)
	panel:SetSize(self:GetWide(),self:GetTall())
	panel:SetVisible(true);
	self.ActivePanel = panel;
end

function PANEL:CloseActivePanel()
	if self.ActivePanel then self.ActivePanel:SetVisible(false) end 
end



function PANEL:ExpandPanel(panel)
	panel:SetParent(self)
	panel:SetPos(0,0)
	panel:SetSize(1,1) -- So it's still draws, aka a valid panel.
	panel:SetVisible(true);
	panel:MoveToFront()
	self.ExpandingPanel = panel;
end

function PANEL:ContractPanel(panel)
	-- Presuming it's parent is this panel and it's in the right position.
	self.ContractingPanel = panel or self.ActivePanel;
end

oubhack:RegisterVgui("oh_DSwitchPanel",PANEL,"DPanel")

