require( "scripts/style.lua" );


function QueueMakeDialog( t )
 f = function() MakeDialog(t) end; 
 QueueFunction(f);
end

function QueueDisplayDialog( t )
 f = function() DisplayDialog(t) end; 
 QueueFunction(f);
end 

function Tutorial()
		
	-- INITIALIZATION
	EnableTutorial(true);
	InitSpriteCursor();
	EnableCursor(false);
	Sleep(0);
	--SetCombiningState(2);
	-- INITIALIZATION - END
		
	-- START POPUP
	QueueDisplayDialog({"scripts/tutorialmodalh.lua", body="tutorial_combining_start"});
	Yield();
	-- START POPUP - END
	
	-- TEXT = Here's our blending machine. Once we turn it on, the grapes will start coming down to the squasher. Let's do a test run, first.
	--CreateWindow("scripts/tutorial_minigames/combining/window_a.lua");
	--Sleep(40);
	QueueDisplayDialog({"scripts/tutorial_minigames/combining/window_a.lua"});
	Yield();
	minigame_start3();
	Yield();
	-- TEXT END
	
	-- USER MOUSE DISABLED
	--SetMouseVisible(false);
	-- USER MOUSE DISABLED - END
	
	-- CREATE GRAPE LINE 1
	CreateGrapeLine("generic_grape","generic_grape","generic_grape",9);
	--SetCombiningState(0);
	Yield();
	-- CREATE GRAPE LINE 1 - END
	
	-- CREATE GRAPE LINE 2
	CreateGrapeLine("cabernet_sauvignon","generic_grape","generic_grape",8);
	--SetCombiningState(0);
	Yield();
	-- CREATE GRAPE LINE 2 - END
	
	-- CREATE GRAPE LINE 3
	CreateGrapeLine("generic_grape","generic_grape","generic_grape",7);
	--SetCombiningState(0);
	Yield();
	-- CREATE GRAPE LINE 3 - END
	
	-- CREATE GRAPE LINE 4
	CreateGrapeLine("cabernet_sauvignon","cabernet_sauvignon","cabernet_sauvignon", 6);
	--SetCombiningState(0);
	Yield();
	-- CREATE GRAPE LINE 4 - END
		
	-- CREATE GRAPE LINE 5
	CreateGrapeLine("generic_grape","cabernet_sauvignon","generic_grape", 5);
	--SetCombiningState(0);
	Yield();
	-- CREATE GRAPE LINE 5 - END
	
	-- CREATE GRAPE LINE 6
	CreateGrapeLine("cabernet_sauvignon","generic_grape","generic_grape", 4);
	--SetCombiningState(0);
	Yield();
	-- CREATE GRAPE LINE 6 - END
	
	-- CREATE GRAPE LINE 7
	--CreateGrapeLine("cabernet_sauvignon","generic_grape","cabernet_sauvignon");
	--SetCombiningState(0);
	--Yield();
	-- CREATE GRAPE LINE 7 - END
	
	-- CREATE GRAPE LINE 8
	--CreateGrapeLine("generic_grape","cabernet_sauvignon","cabernet_sauvignon");
	--SetCombiningState(0);
	--Yield();
	-- CREATE GRAPE LINE 8 - END

	-- CREATE GRAPE LINE 9
	--CreateGrapeLine("generic_grape","cabernet_sauvignon","cabernet_sauvignon");
	--SetCombiningState(0);
	--Yield();
	-- CREATE GRAPE LINE 9 - END

	-- TEXT = We need to make sure that each line of grapes that is squashed has the right amount of each grape. You can see the grapes needed in this blend here in the top left corner.
	DestroyWindow();
	CreateWindow("scripts/tutorial_minigames/combining/window_b.lua");
	Yield();
	-- TEXT - END
	
	-- WAIT
	Sleep(300);
	Yield();
	-- WAIT - END
	
	-- TEXT = You have to switch one grape with another by clicking on them.
	DestroyWindow();
	CreateWindow("scripts/tutorial_minigames/combining/window_b2.lua");
	Yield();
	-- TEXT - END
	
	-- WAIT
	Sleep(50);
	Yield();
	-- WAIT - END
	
	-- ENABLE TUTORIAL CURSOR
	EnableCursor(true);
	SetCursorPosition(2,6);
	Yield();
	-- ENABLE TUTORIAL CURSOR - END
		
	-- TUTORIAL CURSOR ACTION
	MouseMove(0,10);
	Yield();
	SelectGrape(0,9);
	Yield();
	MouseMove(0,9);
	Yield();
	SwapGrapes(0,8);
	Yield();
	-- TUTORIAL CURSOR ACTION - END
	
	--DISABLE TUTORIAL CURSOR
	EnableCursor(false);		
	Yield();
	-- DISABLE TUTORIAL CURSOR - END
		
	-- CREATE GRAPE LINE 10
	--CreateGrapeLine("generic_grape","cabernet_sauvignon","cabernet_sauvignon");
	SetCombiningState(3);
	Yield();
	-- CREATE GRAPE LINE 10 - END
	
	-- TEXT = If the machine detects that the quantities are wrong, it'll discard the grapes and throw them back.
	DestroyWindow();
	--CreateWindow("scripts/tutorial_minigames/combining/window_c.lua");
	--Yield();
	--QueueDisplayDialog({"scripts/tutorial_minigames/combining/window_c.lua"});
	Yield();
	-- TEXT - END
	
	-- WAIT
	--Sleep(200);
	--Yield();
	-- WAIT - END
	
	-- ROLL GRAPE LINE
	--SetCombiningState(0);
	Yield();
	-- ROLL GRAPE LINE - END
	
	-- TEXT = The machine only discards grapes when the quantites are wrong. We don't have to worry much about the order.
	--DestroyWindow();
	CreateWindow("scripts/tutorial_minigames/combining/window_d.lua");
	Sleep(120);
	Yield();
	SetCombiningState(0);
	Yield();
	
	DestroyWindow();
	-- TEXT - END
	
	-- WAIT
	--Sleep(100);
	--Yield();
	-- WAIT - END
	
	-- ENABLE TUTORIAL CURSOR
	EnableCursor(true);
	SetCursorPosition(2,6);
	Yield();
	-- ENABLE TUTORIAL CURSOR - END
	
	-- TUTORIAL CURSOR ACTION
	MouseMove(1,10);
	Yield();
	SelectGrape(1,9);
	Yield();
	MouseMove(2,8);
	Yield();
	SwapGrapes(2,7);
	Yield();
	-- TUTORIAL CURSOR ACTION - END
	
	-- WAIT
	--Sleep(100);
	--Yield();
	-- WAIT - END
	
	-- TEXT - The machine is more productive if we make all lines in the same order, though.
	DestroyWindow();
	CreateWindow("scripts/tutorial_minigames/combining/window_e.lua");
	Yield();
	-- TEXT - END
	
	-- WAIT
	--Sleep(100);
	--Yield();
	-- WAIT - END
	
	-- TUTORIAL CURSOR ACTION
	MouseMove(1,9);
	Yield();
	SelectGrape(1,8);
	Yield();
	MouseMove(0,8);
	Yield();
	SwapGrapes(0,7);
	Yield();
	MouseMove(1,6); --fix order of last line
	Yield();
	SelectGrape(1,5);
	Yield();
	MouseMove(0,6);
	Yield();
	SwapGrapes(0,5);
	Yield();
	-- TUTORIAL CURSOR ACTION - END
	
	--DISABLE TUTORIAL CURSOR
	EnableCursor(false);
	Yield();
	--DISABLE TUTORIAL CURSOR - END
	
	-- ROLL GRAPE LINE
	SetCombiningState(3);
	Yield();
	-- ROLL GRAPE LINE - END
	
	-- ROLL GRAPE LINE
	SetCombiningState(3);
	Yield();
	-- ROLL GRAPE LINE - END
	
	-- ROLL GRAPE LINE
	SetCombiningState(3);
	Yield();
	-- ROLL GRAPE LINE - END
	
	-- ROLL GRAPE LINE
	SetCombiningState(3);
	Yield();
	-- ROLL GRAPE LINE - END
	
	-- ROLL GRAPE LINE
	SetCombiningState(3);
	Yield();
	-- ROLL GRAPE LINE - END
	
	-- ROLL GRAPE LINE
	SetCombiningState(3);
	Yield();
	-- ROLL GRAPE LINE - END
	
	--WAIT
	--Sleep(100);
	--Yield();
	--WAIT - END
	
	-- TEXT = The machine can only run for a short time, and it will shut down automatically after that.
	--DestroyWindow();
	--CreateWindow("scripts/tutorial_minigames/combining/window_f.lua");
	--Yield();
	-- TEXT - END
	
	-- ROLL GRAPE LINE
	--SetCombiningState(0);
	--Yield();
	-- ROLL GRAPE LINE - END
	
	-- ROLL GRAPE LINE
	--SetCombiningState(0);
	--Yield();
	-- ROLL GRAPE LINE - END
	
	--WAIT
	--Sleep(100);
	--Yield();
	--WAIT - END

	-- FINALIZE
	--SetMouseVisible(true);
	DestroyWindow();
	QueueDisplayDialog({"scripts/tutorialmodalh.lua", body="tutorial_combining_finish"});
	EnableTutorial(false);
	--FINALIZE - END
end



return Tutorial;
