--[[Deranjata Config Screen]]

DeranjataDB = {};
DeranjataDB["HasBeenRun"] = 0;

SLASH_DERANJATA1 = "/der"
SLASH_DERANJATA2 = "/deranjata"
SlashCmdList["DERANJATA"] = function()
	MyAddon_ShowOptionFrame();
end


SlashCmdList['RELOAD'] = function() ReloadUI() end
SLASH_RELOAD1 = '/rl'

function AutoStart()
		local editbox=ChatEdit_ChooseBoxForSend(DEFAULT_CHAT_FRAME);--Get an editbox
		ChatEdit_ActivateChat(editbox);--  Show the editbox
		editbox:SetText("/der");--[[ Command goes here]]
		ChatEdit_OnEnterPressed(editbox);--[[ Process command and hide (runs ChatEdit_SendText() and ChatEdit_DeactivateChat() respectively)]]
end
function BarShow()
		local editbox=ChatEdit_ChooseBoxForSend(DEFAULT_CHAT_FRAME);--[[  Get an editbox]]
		ChatEdit_ActivateChat(editbox);--[[   Show the editbox]]
		editbox:SetText("/mab");--[[ Command goes here]]
		ChatEdit_OnEnterPressed(editbox); --[[Process command and hide (runs ChatEdit_SendText() and ChatEdit_DeactivateChat() respectively)]]
end

function ChatOps()
		local editbox=ChatEdit_ChooseBoxForSend(DEFAULT_CHAT_FRAME);--[[  Get an editbox]]
		ChatEdit_ActivateChat(editbox);--[[   Show the editbox]]
		editbox:SetText("/bcm");--[[ Command goes here]]
		ChatEdit_OnEnterPressed(editbox); --[[Process command and hide (runs ChatEdit_SendText() and ChatEdit_DeactivateChat() respectively)]]
end

function SETDB0_OnClick()
	DeranjataDB.HasBeenRun = 1
	ReloadUI()
end

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,
		}
	}


function MyAddon_ShowOptionFrame()
	--[[ Does the frame already exist?]]
	if not Config_BaseFrame then
		--[[ Nope. Create it now:]]
		CreateFrame("frame", "Config_BaseFrame", UIParent)
		Config_BaseFrame:SetWidth(1024)
		Config_BaseFrame:SetHeight(512)
		Config_BaseFrame:SetPoint("CENTER", UIParent,"CENTER")
		Config_BaseFrame:SetFrameStrata("HIGH")
		--[[	MAKE THE FRAME MOVEABLE ON LEFT CLICK]]
		Config_BaseFrame:SetMovable(true)
		Config_BaseFrame:EnableMouse(true)
		Config_BaseFrame:SetScript("OnMouseDown", function(self, button)
			if button == "RightButton"
				and not self.isMoving
				then
					self:StartMoving()
					self.isMoving = true
				end
			end)
			Config_BaseFrame:SetScript("OnMouseUp", function(self, button)
				if button == "RightButton"
					and self.isMoving
					then
						self:StopMovingOrSizing()
						self.isMoving = false
					end
				end)
				Config_BaseFrame:SetScript("OnHide", function(self)
					if ( self.isMoving )
						then
							self:StopMovingOrSizing()
							self.isMoving = false
						end
					end)

					--[[ 	Setting The Background Image For Config_BaseFrame for left side]]
					Config_BaseFrame.portrait = Config_BaseFrame:CreateTexture("Config_BaseFrame_Portrait", "BACKGROUND")
					Config_BaseFrame.portrait:SetWidth(512)
					Config_BaseFrame.portrait:SetHeight(512)
					Config_BaseFrame.portrait:SetPoint("TOPLEFT", 0, 0)
					Config_BaseFrame.portrait:SetTexture("Interface\\Addons\\_Deranjata\\Media\\UI-GuildBankFrame-Left.tga")

					--[[	Setting the background for Config_BaseFrame for Right side]]
					Config_BaseFrame.portrait = Config_BaseFrame:CreateTexture("Config_BaseFrame_Portrait", "BACKGROUND")
					Config_BaseFrame.portrait:SetWidth(512)
					Config_BaseFrame.portrait:SetHeight(512)
					Config_BaseFrame.portrait:SetPoint("TOPRIGHT", 0, 0)
					Config_BaseFrame.portrait:SetTexture("Interface\\Addons\\_Deranjata\\Media\\UI-GuildBankFrame-Right.tga")

					--[[ Setting up the Frame to list options when the option buttons are pushed within config screen]]
					CreateFrame("frame", "ConfigSubOptionFrame", Config_BaseFrame)
					ConfigSubOptionFrame:SetWidth(820)
					ConfigSubOptionFrame:SetHeight(300)
					ConfigSubOptionFrame:SetPoint("CENTER", 0, 30)
					ConfigSubOptionFrame.portrait = ConfigSubOptionFrame:CreateTexture("ConfigSubOptionFrame_Portrait", "BACKGROUND")
					ConfigSubOptionFrame.portrait:SetWidth(600)
					ConfigSubOptionFrame.portrait:SetHeight(400)
					ConfigSubOptionFrame.portrait:SetPoint("CENTER", 0, 0)
					ConfigSubOptionFrame:SetBackdrop(backdrop)
					local Welcome = ConfigSubOptionFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
						Welcome:SetPoint("TOP",0,-10)
						Welcome:SetText("Welcome to Project Deranjata, \n CREDITS:")
					local credBCM = ConfigSubOptionFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
						credBCM:SetPoint("TOP", 0, -40)
						credBCM:SetText("RIGHT CLICK AND HOLD THEN DRAG TO MOVE THIS WINDOW \n \n Thanks go out to Funkydude \n for allowing us to integrate BCM(BasicChatMod) into Project Deranjata, \n without doing so i would have had +100 hours of work to do.")
					local credAnotherAdd = ConfigSubOptionFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
						credAnotherAdd:SetPoint("CENTER", 0, -45)
						credAnotherAdd:SetText()
					--[[all button outputs should steer to ConfigSubOptionFrame]]
					--[[Button1]]
					local frame = CreateFrame("Button", "Options1", Config_BaseFrame, "UIPanelButtonTemplate")
					frame:SetHeight(36)
					frame:SetWidth(67)
					frame:SetText("BarZone")
					frame:ClearAllPoints()
					frame:SetPoint("CENTER", -451, 160)
					Options1:SetScript("OnClick", function() BarShow() end) 
							
					--[[Button7]]
					local frame = CreateFrame("Button", "Options7", Config_BaseFrame, "UIPanelButtonTemplate")
					frame:SetHeight(36)
					frame:SetWidth(67)
					frame:SetText("Chat")
					frame:ClearAllPoints()
					frame:SetPoint("CENTER", 451, 160)
					Options7:SetScript("OnClick", function() ChatOps() end)
					--[[Button2]]
					local frame = CreateFrame("Button", "Options2", Config_BaseFrame, "UIPanelButtonTemplate")
					frame:SetHeight(36)
					frame:SetWidth(67)
					frame:SetText("Opt2")
					frame:ClearAllPoints()
					frame:SetPoint("CENTER", -451, 110)
					Options2:SetScript("OnClick", ReloadUI)
					--[[Button8]]
					local frame = CreateFrame("Button", "Options8", Config_BaseFrame, "UIPanelButtonTemplate")
					frame:SetHeight(36)
					frame:SetWidth(67)
					frame:SetText("Opt8")
					frame:ClearAllPoints()
					frame:SetPoint("CENTER", 451, 110)
					Options8:SetScript("OnClick", ReloadUI)
					--[[Button3]]
					local frame = CreateFrame("Button", "Options3", Config_BaseFrame, "UIPanelButtonTemplate")
					frame:SetHeight(36)
					frame:SetWidth(67)
					frame:SetText("Opt3")
					frame:ClearAllPoints()
					frame:SetPoint("CENTER", -451, 60)
					Options3:SetScript("OnClick", ReloadUI)
					--[[Button9]]
					local frame = CreateFrame("Button", "Options9", Config_BaseFrame, "UIPanelButtonTemplate")
					frame:SetHeight(36)
					frame:SetWidth(67)
					frame:SetText("Opt9")
					frame:ClearAllPoints()
					frame:SetPoint("CENTER", 451, 60)
					Options9:SetScript("OnClick", ReloadUI)
					--[[Button4]]
					local frame = CreateFrame("Button", "Options4", Config_BaseFrame, "UIPanelButtonTemplate")
					frame:SetHeight(36)
					frame:SetWidth(67)
					frame:SetText("Opt4")
					frame:ClearAllPoints()
					frame:SetPoint("CENTER", -451, 10)
					Options4:SetScript("OnClick", ReloadUI)
					--[[Button10]]
					local frame = CreateFrame("Button", "Options10", Config_BaseFrame, "UIPanelButtonTemplate")
					frame:SetHeight(36)
					frame:SetWidth(67)
					frame:SetText("Opt10")
					frame:ClearAllPoints()
					frame:SetPoint("CENTER", 451, 10)
					Options10:SetScript("OnClick", ReloadUI)
					--[[Button5]]
					local frame = CreateFrame("Button", "Options5", Config_BaseFrame, "UIPanelButtonTemplate")
					frame:SetHeight(36)
					frame:SetWidth(67)
					frame:SetText("Opt5")
					frame:ClearAllPoints()
					frame:SetPoint("CENTER", -451, -40)
					Options5:SetScript("OnClick", ReloadUI)
					--[[Button11]]
					local frame = CreateFrame("Button", "Options11", Config_BaseFrame, "UIPanelButtonTemplate")
					frame:SetHeight(36)
					frame:SetWidth(67)
					frame:SetText("Opt11")
					frame:ClearAllPoints()
					frame:SetPoint("CENTER", 451, -40)
					Options11:SetScript("OnClick", ReloadUI)
					--[[Button6]]
					local frame = CreateFrame("Button", "Options6", Config_BaseFrame, "UIPanelButtonTemplate")
					frame:SetHeight(36)
					frame:SetWidth(67)
					frame:SetText("Opt6")
					frame:ClearAllPoints()
					frame:SetPoint("CENTER", -451, -90)
					Options6:SetScript("OnClick", ReloadUI)

					--[[Button12]]
					local frame = CreateFrame("Button", "Options12", Config_BaseFrame, "UIPanelButtonTemplate")
					frame:SetHeight(36)
					frame:SetWidth(67)
					frame:SetText("Opt12")
					frame:ClearAllPoints()
					frame:SetPoint("CENTER", 451, -90)
					Options12:SetScript("OnClick", ReloadUI)
					
					--[[Config Panel Buttons]]
					--[[ Exit Button]]
					local frame = CreateFrame("Button", "ExitSetup", Config_BaseFrame, "UIPanelCloseButton")
					frame:ClearAllPoints()
					frame:SetPoint("TOPRIGHT", -74, -8)
					--[[Exit Button]]
					local frame = CreateFrame("Button", "SaveAndReload", Config_BaseFrame, "UIPanelButtonTemplate")
					frame:SetHeight(20)
					frame:SetWidth(100)
					frame:SetText("Reload UI")
					frame:ClearAllPoints()
					frame:SetPoint("CENTER", 380, -165)
					SaveAndReload:SetScript("OnClick", ReloadUI)
					--[[Alignment Button]]
					local frame = CreateFrame("Button", "AlignGrid", Config_BaseFrame, "UIPanelButtonTemplate")
					frame:SetHeight(20)
					frame:SetWidth(100)
					frame:SetText("Alignment")
					frame:ClearAllPoints()
					frame:SetPoint("CENTER", -380, -165)
					frame:SetScript("OnClick", function() Allignment() end)
					
					--[[ Here we Set up the function to Run our Allignment tool, No real Purpose accept to help line up other addons to our UI]]
					function Allignment()
						local editbox=ChatEdit_ChooseBoxForSend(DEFAULT_CHAT_FRAME);--  Get an editbox
						ChatEdit_ActivateChat(editbox);--   Show the editbox
						editbox:SetText("/align 64");-- Command goes here
						ChatEdit_OnEnterPressed(editbox);-- Process command and hide (runs ChatEdit_SendText() and ChatEdit_DeactivateChat() respectively)
					end


				else
					--[[ frame already exists, so toggle it.]]
					Config_BaseFrame:SetShown(not Config_BaseFrame:IsShown())
				end


			
	end


-- Here we have our Options Toggle Button (MAY BE REMOVED AT A LATER DATE)
frame = CreateFrame("Button", "OptionsFrame", TopFrame, "UIPanelButtonTemplate")
frame:SetHeight(21)
frame:SetWidth(80)
frame:SetText("Options")
frame:ClearAllPoints()
frame:SetPoint("CENTER", 400, 0)
frame:SetFrameStrata ("TOOLTIP")
OptionsFrame:SetScript("OnClick", function() MyAddon_ShowOptionFrame() end)

local btn = CreateFrame("Button", "myButton", UIParent, "SecureActionButtonTemplate");
btn:SetAttribute("spell", "action");
btn:SetAttribute("action", 1);

