-- Defining any locals we need before the program starts --

--[[
ok first we are going to find theight and width of the screen resolution
]]--

local resolHeight = GetScreenHeight () *.65
local resolWidth  = GetScreenWidth () *.65
--now calculate the ratio for a later time
local aspectRatio = (resolWidth/resolHeight)

--Here we welcome the player to the Project
print ("|cff00BFFF Welcome to Project Deranjata, Your input is Needed,") 
print ("|cff00BFFF Please be sure to visit us on www.wowinterface.com . all input is welcomed,") 

--and now we calculate and change the screen UI Scaling

local aspect = CreateFrame("frame", nil, UIParent)

aspect:RegisterEvent("PLAYER_ENTERING_WORLD")
aspect:SetScript("OnEvent", function(self, event)
	UIParent:SetScale(0.6)	-- you can change the scale here but you will break the entire add-on
	print ("|cff00BFFF Your Resolution Scale has been changed to 0.6") --Notify the player the screen scaling has been changed.
	aspect:UnregisterAllEvents()
	print (format("|cff00BFFF Your Screen Ratio is %.2f.", aspectRatio))--notify player of their resolution aspect
end)

--screen calculations done, now we hide all of blizzards main frames 

local FramesToHide = {
	MainMenuBar, 
	--MainMenuBarArtFrame, 
	MainMenuBarPageNumber,
	ActionBarDownButton,
	ActionBarUpButton,
	--OverrideActionBar,
	OverrideActionBarExpBar,
	OverrideActionBarHealthBar,
	OverrideActionBarPowerBar,
	OverrideActionBarPitchFrame,
	OverrideActionBarLeaveFrameLeaveButton,
	--BonusActionBarFrame, 
	--PossessBarFrame
	MainMenuBarBackpackButton,
	CharacterBag0Slot,
  CharacterBag1Slot,
  CharacterBag2Slot,
  CharacterBag3Slot,
	StanceBarLeft,
	StanceBarMiddle,
	StanceBarRight,
	SlidingActionBarTexture0,
	SlidingActionBarTexture1,
	PossessBackground1,
	PossessBackground2,
	MainMenuBarTexture0,
	MainMenuBarTexture1,
	MainMenuBarTexture2,
	MainMenuBarTexture3,
	MainMenuBarLeftEndCap,
	MainMenuBarRightEndCap,
	}
local frameHider = CreateFrame("Frame", nil)
frameHider:Hide()


for _, f in pairs(FramesToHide) do
    if f:GetObjectType() == "Texture" then
      --f:UnregisterAllEvents()
	  f:SetTexture(nil)
	else
	  f:SetParent(frameHider)
    end
end


local OverrideTexList =  {
	"_BG",
	"_MicroBGMid",
	"_Border",
	"EndCapL",
	"EndCapR",
	"Divider1",
	"Divider2",
	"Divider3",
	"ExitBG",
	"MicroBGL",
	"MicroBGR",
	"ButtonBGL",
	"ButtonBGR",
	"_ButtonBGMid",
	}
	
	
for _, t in pairs(OverrideTexList) do
	OverrideActionBar[t]:SetAlpha(1)
end

-- now that we have hidden the nessisary frames
-- now we start with the general layout

-- This is the Backdrop Variable
local backdrop = {
	bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
	edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
	tile = true,
	tileSize = 32,
	edgeSize = 20,
	insets = {
		left = 4,
		right = 4,
		top = 4,
		bottom = 4,
	}
}
local backdropClear = {
	edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
	tile = true,
	tileSize = 32,
	edgeSize = 20,
	insets = {
		left = 4,
		right = 4,
		top = 4,
		bottom = 4,
	}
}

-- This is Left Main Frame Chunk
local frame = CreateFrame("frame", "LeftChatBaseFrame", UIParent)
LeftChatBaseFrame:SetWidth(resolWidth*.34)
LeftChatBaseFrame:SetHeight(resolHeight*.33)
LeftChatBaseFrame:SetPoint("BOTTOMLEFT", UIParent,"BOTTOMLEFT", -6, -6)
LeftChatBaseFrame:SetFrameStrata("BACKGROUND")
LeftChatBaseFrame:SetFrameLevel(1)
LeftChatBaseFrame:SetAlpha(1)
LeftChatBaseFrame:SetBackdrop(backdrop)


-- This is Right Main Frame Chunk
local frame = CreateFrame("frame", "RightChatBaseFrame", UIParent)
RightChatBaseFrame:SetWidth(resolWidth*.34)
RightChatBaseFrame:SetHeight(resolHeight*.33)
RightChatBaseFrame:SetPoint("BOTTOMRIGHT", UIParent,"BOTTOMRIGHT", 6, -6)
RightChatBaseFrame:SetFrameStrata("BACKGROUND")
RightChatBaseFrame:SetFrameLevel(1)
RightChatBaseFrame:SetAlpha(1)
RightChatBaseFrame:SetBackdrop(backdrop)
--set chat Frame to proper position
local DummyFrame = CreateFrame("Frame")
DummyFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
DummyFrame:SetScript("OnEvent", function(self, event, ...)
	ChatFrame1:ClearAllPoints() 
	ChatFrame2:ClearAllPoints()
	ChatFrame1:SetPoint("BOTTOMLEFT", LeftChatBaseFrame, "BOTTOMLEFT", 8, 0)
	ChatFrame1:SetPoint("TOPRIGHT", LeftChatBaseFrame, "BOTTOMLEFT", (resolWidth*.334), (resolHeight*.310))
	ChatFrame2:SetPoint("BOTTOMLEFT", RightChatBaseFrame, "BOTTOMLEFT", 8, 0)
	ChatFrame2:SetPoint("TOPRIGHT", RightChatBaseFrame, "BOTTOMLEFT", (resolWidth*.334), (resolHeight*.161))
	DummyFrame:UnregisterEvent("PLAYER_ENTERING_WORLD")
end)
--Right SubFrame a.k.a. XP frame
local frame = CreateFrame("frame", "XPFrame", RightChatBaseFrame)
	XPFrame:SetWidth(resolWidth*.34)
	XPFrame:SetHeight(resolHeight*.04)
	XPFrame:SetPoint("TOPRIGHT", RightChatBaseFrame,"TOPRIGHT", 0, 0)
	XPFrame:SetFrameStrata("BACKGROUND")
	XPFrame:SetFrameLevel(2)
	XPFrame:SetAlpha(1)
	XPFrame:SetBackdrop(backdropClear)
-- This is the Center Main Frame Chunk
local frame = CreateFrame("frame", "CenterBase", UIParent)
CenterBase:SetWidth(resolWidth*1.007)
CenterBase:SetHeight(resolHeight*.21)
CenterBase:SetPoint("BOTTOM", UIParent,"BOTTOM", 0, -6)
CenterBase:SetFrameStrata("BACKGROUND")
CenterBase:SetFrameLevel(2)
CenterBase:SetBackdrop(backdrop)
-- This is map frame chunk
local frame = CreateFrame("frame", "CenterMapBase", UIParent)
CenterMapBase:SetWidth(resolHeight*.21)
CenterMapBase:SetHeight(resolHeight*.21)
CenterMapBase:SetPoint("BOTTOM", UIParent,"BOTTOM", 0, -6)
CenterMapBase:SetFrameStrata("BACKGROUND")
CenterMapBase:SetFrameLevel(3)
CenterMapBase:SetBackdrop(backdropClear)
-- this is top frame chunk
local frame = CreateFrame("frame", "TopFrame", UIParent)
TopFrame:SetWidth(resolWidth*1.675)
TopFrame:SetHeight(resolHeight*.045)
TopFrame:SetPoint("TOPLEFT", UIParent,"TOPLEFT", -6, 6)
TopFrame:SetFrameStrata("BACKGROUND")
TopFrame:SetFrameLevel(1)
TopFrame:SetAlpha(1)
TopFrame:SetBackdrop(backdrop)

--to make it easier let us now make a reload button on the chat frame
--and place it at the very bottom right
local frame = CreateFrame("Button", "ExpandLeft", LeftChatBaseFrame, "UIPanelButtonTemplate")
frame:SetHeight(21)
frame:SetWidth(21)
frame:SetText("R")
frame:ClearAllPoints()
frame:SetPoint("BOTTOMRIGHT", -4, 4)
frame:SetFrameStrata("LOW")
ExpandLeft:SetScript("OnClick", ReloadUI)

-- from here we now go to the chat area, we need to nest it better into the visible frames that we just made
-- we will do this in other files, just noting here that it is happening for my own purpose


