require "StandardMouseButton"
require "CDialog"

-- reserve constructor
Book_CrisisWonDialog = 
{
	name = "Book_CrisisWonDialog"
}

function Book_CrisisWonDialog:Create(  )
	
	-- The main screen container
	local instance = root.dialogs[ self.name ];
	instance:SetPosition( 0, 0 )
	CDialog:Attach( instance )

	-- The buttons
	local ra1 = instance.rightArrow1
	local ra2 = instance.rightArrow2
	local ra3 = instance.rightArrow3
	local la1 = instance.leftArrow1
	local la2 = instance.leftArrow2
	local la3 = instance.leftArrow3

	local b1 = instance.button1
	local b2 = instance.button2
	local b3 = instance.button3
	
	local preview = instance.preview;

	local btnDone = instance.btnDone
	
	-- The main init function
	function instance:Init( )
			
--		instance.crisisTitle:SetText("|1|Crisis|Great job!|");
		instance.crisisTitle:SetText("Wedding Crisis Averted!");
			
		-- C1
		if ( instance.tileset == 0 ) then
			instance.crisisText:SetText("You did it - now it's up to you to create a new wedding cake for Rachel and Nate!");
			--instance.crisisText:SetText("|2|Crisis|It's time to pick out some new cabinets and return the kitchen to normal! Select your favorite finish...|");
		-- C2
		elseif ( instance.tileset == 1 ) then
			instance.crisisText:SetText("You obviously know what you're doing... so you're the perfect person to build a new bouquet for Rachel's Dream Day!");
			--instance.crisisText:SetText("|3|Crisis|You've restored peace to the back yard...now select one special item to add the finishing touch!|");
		-- C3
		elseif ( instance.tileset == 2 ) then
			instance.crisisText:SetText("Congratulations! Now it's time to design a new gown for Rachel...what will look best?");
			--instance.crisisText:SetText("|4|Crisis|Your seek and find skills are rock solid! Now choose your favorite color scheme to make this house a home!|");
		-- V1
		elseif ( instance.tileset == 4 ) then
			instance.crisisText:SetText("Great work - now you can choose a new bouquet for Emily!");
			--instance.crisisText:SetText("|5|Crisis|You've done it again...now that things have dried out, it's time to pick some new tile!|");
		-- V2
		elseif ( instance.tileset == 3 ) then
			instance.crisisText:SetText("You did it - now it's time to create a brand-new wedding cake for the happy couple!");
			--instance.crisisText:SetText("|6|Crisis|Now that the dining room is safe again...choose a new floor to complete the look!|");
		-- V3
		elseif ( instance.tileset == 5 ) then
			instance.crisisText:SetText("Thank goodness you're cool under pressure... now all that's left to do is create a new gown for the bride!");
			--instance.crisisText:SetText("|7|Crisis|You've got an eagle eye, all right! Now choose the color scheme that will make this house shine!|");
		-- default
		else
			instance.crisisText:SetText("|8|Crisis|Crisis Completed?|");
		end

		b1:SetFrame( instance.tileset )
		b2:SetFrame( instance.tileset )
		b3:SetFrame( instance.tileset )

		preview:SetFrame(instance.tileset)

		anyInit(ra1, b1, 1)
		anyInit(ra2, b2, 1)
		anyInit(ra3, b3, 1)
		anyInit(la1, b1, -1)
		anyInit(la2, b2, -1)
		anyInit(la3, b3, -1)
		
	end

	-- init done button
	StandardMouseButton( btnDone )
	function btnDone:Pressed( )
		instance:ScreenEvent( "btnDone", "" )
--		instance:CloseAndSave( )
	end
	
	function instance:OnUpdate( )
		self:OnUpdateDialog()
	end

	-- Handle keyboard input for the dialog
--	function instance:CharDown( i_Key )
--		log( "On Key Down" .. i_Key )
--	end

	-- selection buttons
	function anyInit(abc, inst, dir)
		abc.fading = (instance.tileset == 2)
		
		StandardMouseButton( abc )
		
		function abc:Pressed( )
			local inst1 = inst.choose
			local fr = (inst1:GetNumFrames() + inst1:GetFrame() + dir) % inst1:GetNumFrames()
			inst1:SetFrame( fr )
			
			local curPreview = preview.inst    --:GetChildren()[1]
			
			if( curPreview.top ~= nil ) then curPreview.top:SetFrame( b1.choose:GetFrame() ) end
			if( curPreview.middle ~= nil ) then curPreview.middle:SetFrame( b2.choose:GetFrame() ) end
			if( curPreview.bottom ~= nil ) then curPreview.bottom:SetFrame( b3.choose:GetFrame() ) end
			if( curPreview.bottom ~= nil ) then 
				curPreview.bottom:SetFrame( b3.choose:GetFrame() )
			else
				if( curPreview.top ~= nil and curPreview.top.bottom ~= nil ) then curPreview.top.bottom:SetFrame( b3.choose:GetFrame() ) end
			end
			if( inst:GetFrame() == 2 or inst:GetFrame() == 5 ) then
				instance:ScreenEvent( "color", "" )
			elseif ( inst:GetFrame() == 0 or inst:GetFrame() == 3 ) then
				instance:ScreenEvent( "colorCake", "" )
			end
		end
		
--		function abc:OnMouseEnter()
--			abc.chooseGlow:SetVisible( true );
--		end
		
--		function abc:OnMouseLeave()
--			abc.chooseGlow:SetVisible( false );
--		end	
	end

end

Book_CrisisWonDialog:Create( )



