
require "CDialog"

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

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

	-- The buttons
	local a = instance.button1
	local b = instance.button2
	local c = instance.button3
	
	-- The main init function
	function instance:Init( )
			
		-- C1
		if ( instance.tileset == 0 ) then
			instance.crisisTitle:SetText("Craftsman Crisis 1");
			instance.crisisText:SetText("Craftsman Crisis 1 Completed!");
		-- C2
		elseif ( instance.tileset == 1 ) then
			instance.crisisTitle:SetText("Craftsman Crisis 2");
			instance.crisisText:SetText("Craftsman Crisis 2 Completed!");
		-- C3
		elseif ( instance.tileset == 2 ) then
			instance.crisisTitle:SetText("Craftsman Crisis 3");
			instance.crisisText:SetText("Craftsman Crisis 3 Completed!");
		-- V1
		elseif ( instance.tileset == 3 ) then
			instance.crisisTitle:SetText("Victorian Crisis 1");
			instance.crisisText:SetText("Victorian Crisis 1 Completed!");
		-- V2
		elseif ( instance.tileset == 4 ) then
			instance.crisisTitle:SetText("Victorian Crisis 2");
			instance.crisisText:SetText("Victorian Crisis 2 Completed!");
		-- V3
		elseif ( instance.tileset == 5 ) then
			instance.crisisTitle:SetText("Victorian Crisis 3");
			instance.crisisText:SetText("Victorian Crisis 3 Completed!");
		-- default
		else
			instance.crisisTitle:SetText("Craftsman Crisis 1");
			instance.crisisText:SetText("Craftsman Crisis 1 Completed?");
		end
		
		a:Init( )
		b:Init( )
		c:Init( )		
		
	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 a:Init( )
		a.chooseGlow:SetVisible( false );
		a:SetFrame( instance.tileset );
		a.timer = 120
		a.fading = (instance.tileset == 2)
		a.waiting = false
		
		a:SetOnUpdateEnabled( true );
		
		function a:OnLeftMouseUp( )
			PlaySound( "MatchWild" )
			self.waiting = true
		end
		
		function a:OnUpdate( )
			if ( self.waiting == true ) then
				self.timer = self.timer - 1
				
				instance:ScreenEvent( "button1", "" )
				instance:CloseAndSave( )
			end
		end
		
		function a:OnMouseEnter()
			a.chooseGlow:SetVisible( true );
		end
		
		function a:OnMouseLeave()
			a.chooseGlow:SetVisible( false );
		end
	end
	
	function b:Init( )
		b.chooseGlow:SetVisible( false );
		b:SetFrame( instance.tileset );
		b.timer = 120
		b.waiting = false
		
		b:SetOnUpdateEnabled( true );
		
		function b:OnLeftMouseUp( )
			PlaySound( "MatchWild" )
			self.waiting = true
		end
		
		function b:OnUpdate( )
			if ( self.waiting == true ) then
				self.timer = self.timer - 1
			
				instance:ScreenEvent( "button2", "" )
				instance:CloseAndSave( )
			end
		end
		
		function b:OnMouseEnter()
			b.chooseGlow:SetVisible( true );
		end
		
		function b:OnMouseLeave()
			b.chooseGlow:SetVisible( false );
		end
	end
	
	function c:Init( )
		c.chooseGlow:SetVisible( false );
		c:SetFrame( instance.tileset );
		c.timer = 120
		c.waiting = false
		
		c:SetOnUpdateEnabled( true );
		
		function c:OnLeftMouseUp( )
			PlaySound( "MatchWild" )
			self.waiting = true
		end
		
		function c:OnUpdate( )
			if ( self.waiting == true ) then
				self.timer = self.timer - 1
				
				instance:ScreenEvent( "button3", "" )
				instance:CloseAndSave( )
			end
		end
		
		function c:OnMouseEnter()
			c.chooseGlow:SetVisible( true );
		end
		
		function c:OnMouseLeave()
			c.chooseGlow:SetVisible( false );
		end
	end

end

Book_CrisisWonDialog:Create( )



