if Option.Debug.GetInfo == true then UserInfo.AddVal("EditMenu", 1) end

local BG1 = Image.load("Game Resources/Backgrounds/CreateBG1.png")
local BG2 = Image.load("Game Resources/Backgrounds/CreateBG2.png")
--local Sel = Image.load("Game Resources/Cursors/Selector.png")

local mState = 1
local SCNIndex = 1
local ParamSelect = 1

Arial = Font.load("Font/Arial.TTF")
Arial:setPixelSizes(12,12)

local BTi = 5

-- information about deleting the scenario
local DeleteSucc = false
local DeleteTick = 0

local Selector = Image.createEmpty(85,10)
Selector:fillRect(0,0,78,10,Yellow)
Selector:fillRect(1,1,76,8,Color.new(200,200,0))
Selector:fillRect(6,0,78-6,10,Gray)
Selector:fillRect(6,1,78-6-1,8,DaGray)

while true do
	pad = Controls.read()
	screen:clear()
	
	BTi = BTi - 1
	
	screen:blit(0,0, BG1)
	screen:blit(0,0, BG2)
	
	if SCNIndex == 1 then
		screen:blit(42,41, Selector)
	elseif SCNIndex == 2 then
		screen:blit(42,61, Selector)
	elseif SCNIndex == 3 then
		screen:blit(42,81, Selector)
	elseif SCNIndex == 4 then
		screen:blit(42,101, Selector)
	elseif SCNIndex == 5 then
		screen:blit(42,121, Selector)
	elseif SCNIndex == 6 then
		screen:blit(42,141, Selector)
	end
	
	DrawShadowString(Arial, 50, 50, "Scenario #1", White)
	DrawShadowString(Arial, 50, 70, "Scenario #2", White)
	DrawShadowString(Arial, 50, 90, "Scenario #3", White)
	DrawShadowString(Arial, 50, 110, "Scenario #4", White)
	DrawShadowString(Arial, 50, 130, "Scenario #5", White)
	DrawShadowString(Arial, 50, 150, "Scenario #6", White)
	
	if mState == 1 then
		
		if pad:down() then
			if pressed.down == false then
				pressed.down = true
				SCNIndex = SCNIndex + 1
				if SCNIndex > 6 then SCNIndex = 1 end
			end
		else
			pressed.down = false
		end
		
		if pad:up() then
			if pressed.up == false then
				pressed.up = true
				SCNIndex = SCNIndex - 1
				if SCNIndex < 1 then SCNIndex = 6 end
			end
		else
			pressed.up = false
		end
	
		if pad:circle() then
			if pressed.circle == false then
				pressed.circle = true
				LoadMenuParts("MainMenu")
				dofile("MainMenu.lua")
			end
		else
			pressed.circle = false
		end
		
		if BTi == 0 then
			BTi = 5
			if pad:cross() then mState = 2 end
		end
		ParamSelect = 1
	end
	
	if mState == 2 then
	
		-- R.I.P. AdditionalPanel (28.08.2019)
		screen:fillRect(162, 35, 147, 114+15, Color.new(156, 62, 0))
		screen:fillRect(162+2, 35+2, 143, 110+15, Color.new(188, 75, 0))
		
		if DeleteSucc == true then
			DeleteTick = DeleteTick + 1
			if DeleteTick > 20 then
				DeleteTick = 0
				DeleteSucc = false
			end
			DrawShadowString(Arial, 180, 145, "Scenario Deleted", Green)
		end
		
		if ParamSelect == 1 then
			screen:blit(170,72, Selector)
		elseif ParamSelect == 2 then
			screen:blit(170,92, Selector)
		elseif ParamSelect == 3 then
			screen:blit(170,112, Selector)
		end
		
		DrawShadowString(Arial, 180, 55, "Scenario #"..SCNIndex, White)
		DrawShadowString(Arial, 180, 80, "Edit", White)
		DrawShadowString(Arial, 180, 100, "Play", White)
		DrawShadowString(Arial, 180, 120, "Delete Data", White)
		
		if pad:down() then
			if pressed.down == false then
				pressed.down = true
				ParamSelect = ParamSelect + 1
				if ParamSelect > 3 then ParamSelect = 1 end
			end
		else
			pressed.down = false
		end
		
		if pad:up() then
			if pressed.up == false then
				pressed.up = true
				ParamSelect = ParamSelect - 1
				if ParamSelect < 1 then ParamSelect = 3 end
			end
		else
			pressed.up = false
		end
		
	
		if BTi == 0 then
			BTi = 5
			if pad:cross() and ParamSelect == 1 then
				EditorParam(1, SCNIndex)
				dofile("MapEditor.lua")
			elseif pad:cross() and ParamSelect == 2 then
				EditorParam(2, SCNIndex)
				dofile("GameScript.lua")
			elseif pad:cross() and ParamSelect == 3 then
				DeleteSucc = true
				EditorParam(3, SCNIndex)
			end
		end
		
		if pad:circle() then
			if pressed.circle == false then
				pressed.circle = true
				mState = 1
			end
		else
			pressed.circle = false
		end
		
	end
	
	if BTi < 0 then BTi = 0 end
	
	screen.waitVblankStart(1)
	screen.flip()
end
