require( "scripts/style.lua" );
require( "scripts/tome_footer.lua" );
require( "package/typedef.lua" );

function knowledge_tree_button_action( level, competence_type, iOffsetX, iOffsetY )
  local try = TryKnowledgeTreeNode( level, competence_type );
  if (try == TKTN_ok) then
    DisplayDialog { 
      "scripts/yesno.lua",
	  yes = function()
              ReachKnowledgeTreeNode( level, competence_type );
              PlayKnowledgeTreeFX( "fx/fx_boutique_fee_vert.lua", iOffsetX, iOffsetY );
              if( AreAllKnowledgeTreeNodeReached() == true ) then
                gTempFunction = 
                  function() 
                    DisplayDialog {	
                    "scripts/okbox.lua",
                    body = "TIP_faerie_over",
                    title = "buyleveltitle",
                    Dialogname = "tomebuy",
                    };
                  end;
                  table.insert( gCommandQueue,gTempFunction );
              end
            end,
      body ="buylevelconfirm",
      title = "buyleveltitle",
      Dialogname = "tomebuy",
	};
  elseif( try == TKTN_not_enough_feerie ) then
    DisplayDialog { 
      "scripts/okbox.lua",
      body ="buylevel_lowfairy",
      title = "buyleveltitle",
      Dialogname = "tomebuy",
    };  
  elseif( try == TKTN_previous_node_not_reached ) then
    DisplayDialog { 
      "scripts/okbox.lua",
      body ="buylevel_skiplevel",
      title = "buyleveltitle",
      Dialogname = "tomebuy",
    };  
  end
end

MakeDialog
{
	name = "knowledge_tree",
	
	KnowledgeTomeWindow
	{
		x = 0,
		y = 0,
		w = GetScreenWidth(),
		h = GetScreenHeight(),	
		
		KnowledgeTreeImage
		{
		    name = "bgimage",
			image="backgrounds/options",
			x = kCenter,
			y = kCenter - 84,
			
			
		  --- Background des images metiers ---
			Bitmap
			{
				image="backgrounds/work/background_collection_nature",
				x = kCenter - 210,
				y = kCenter - 105,
			},
			
			Bitmap
			{
				image="backgrounds/work/background_collection_exploration",
				x = kCenter - 210,
				y = kCenter + 118,
			},
			
			Bitmap
			{
				image="backgrounds/work/background_collection_savoir",
				x = kCenter + 213,
				y = kCenter - 105,
			},
			
			Bitmap
			{
				image="backgrounds/work/background_collection_musique",
				x = kCenter + 213,
				y = kCenter + 118,
			},
			--- fin du background des images metier ---
			
			----------- Image nature----------
			
			Bitmap
			{
				image="backgrounds/work/nature_on_1",
				x = kCenter - 303,
				y = kCenter - 105,
				name = "nature_on_1";
				
				
			},
			
			ClickableImage
			{
        Text
				{
					name = "nature1_cost_label",
					x = 0,
					y = kCenter,
					w = 40,
					h = 25,
                    font = ButtonKnowledgeTreeCostFont,
					flags = kHAlignCenter + kVAlignCenter,
				},
           
        image="backgrounds/work/nature_off_1",
        x = kCenter - 303,
        y = kCenter - 105,
        name = "nature_off_1";
        
        command =
          function()
            knowledge_tree_button_action("nature1", 1, -303, -105);
          end
			},
			
			Bitmap
			{
				image="backgrounds/work/nature_on_2",
				x = kCenter - 241,
				y = kCenter - 105,
				name = "nature_on_2";
			},
		
			ClickableImage
			{
        Text
				{
					name = "nature2_cost_label",
					x = 0,
					y = kCenter,
					w = 40,
					h = 25,
                    font = ButtonKnowledgeTreeCostFont,
					flags = kHAlignCenter + kVAlignCenter,
				},
       
				image="backgrounds/work/nature_off_2",
				x = kCenter - 241,
				y = kCenter - 105,
				name = "nature_off_2";
				
				command =
					function()
						knowledge_tree_button_action("nature2", 1, -241, -105);
					end
			},
			
			Bitmap
			{
				image="backgrounds/work/nature_on_3",
				x = kCenter - 179,
				y = kCenter - 105,
				name = "nature_on_3";
			},
			
			ClickableImage
			{
         Text
				{
					name = "nature3_cost_label",
					x = 0,
					y = kCenter,
					w = 40,
					h = 25,
                    font = ButtonKnowledgeTreeCostFont,
					flags = kHAlignCenter + kVAlignCenter,
				},
                
				image="backgrounds/work/nature_off_3",
				x = kCenter - 179,
				y = kCenter - 105,
				name = "nature_off_3";
				
				command =
					function()
						knowledge_tree_button_action("nature3", 1, -179, -105);
					end
			},
			
			Bitmap
			{
				image="backgrounds/work/nature_on_4",
				x = kCenter - 117,
				y = kCenter - 105,
				name = "nature_on_4";
			},
			
			ClickableImage
			{
        Text
				{
					name = "nature4_cost_label",
					x = 0,
					y = kCenter,
					w = 40,
					h = 25,
                    font = ButtonKnowledgeTreeCostFont,
					flags = kHAlignCenter + kVAlignCenter,
				},                
          
				image="backgrounds/work/nature_off_4",
				x = kCenter - 117,
				y = kCenter - 105,
				name = "nature_off_4";
				
				command =
					function()
						knowledge_tree_button_action("nature4", 1, -117, -105);
					end
			},
			
			----------- Image exploration----------
			
			Bitmap
			{
				image="backgrounds/work/exploration_on_1",
				x = kCenter - 303,
				y = kCenter + 118,
				name = "exploration_on_1";
			},
			
			ClickableImage
			{
        Text
				{
					name = "exploration1_cost_label",
					x = 0,
					y = kCenter,
					w = 40,
					h = 25,
                    font = ButtonKnowledgeTreeCostFont,
					flags = kHAlignCenter + kVAlignCenter,
				},
        
				image="backgrounds/work/exploration_off_1",
				x = kCenter - 303,
				y = kCenter + 118,
				name = "exploration_off_1";
				
				command =
					function()
						knowledge_tree_button_action("exploration1", 2, -303, 118);
					end
			},
			
			Bitmap
			{
				image="backgrounds/work/exploration_on_2",
				x = kCenter - 241,
				y = kCenter + 118,
				name = "exploration_on_2";
			},
			
			ClickableImage
			{
        Text
				{
					name = "exploration2_cost_label",
					x = 0,
					y = kCenter,
					w = 40,
					h = 25,
                    font = ButtonKnowledgeTreeCostFont,
					flags = kHAlignCenter + kVAlignCenter,
				},
        
				image="backgrounds/work/exploration_off_2",
				x = kCenter - 241,
				y = kCenter + 118,
				name = "exploration_off_2";
				
				command =
					function()
						knowledge_tree_button_action("exploration2", 2, -241, 118);
					end
			},
			
			Bitmap
			{
				image="backgrounds/work/exploration_on_3",
				x = kCenter - 179,
				y = kCenter + 118,
				name = "exploration_on_3";
			},
			
			ClickableImage
			{
        Text
				{
					name = "exploration3_cost_label",
					x = 0,
					y = kCenter,
					w = 40,
					h = 25,
                    font = ButtonKnowledgeTreeCostFont,
					flags = kHAlignCenter + kVAlignCenter,
				},
                
				image="backgrounds/work/exploration_off_3",
				x = kCenter - 179,
				y = kCenter + 118,
				name = "exploration_off_3";
				
				command =
					function()
						knowledge_tree_button_action("exploration3", 2, -179, 118);
					end
			},
			
			Bitmap
			{
				image="backgrounds/work/exploration_on_4",
				x = kCenter - 117,
				y = kCenter + 118,
				name = "exploration_on_4";
			},
			
			ClickableImage
			{
        Text
				{
					name = "exploration4_cost_label",
					x = 0,
					y = kCenter,
					w = 40,
					h = 25,
                    font = ButtonKnowledgeTreeCostFont,
					flags = kHAlignCenter + kVAlignCenter,
				},
                
				image="backgrounds/work/exploration_off_4",
				x = kCenter - 117,
				y = kCenter + 118,
				name = "exploration_off_4";
				
				command =
					function()
						knowledge_tree_button_action("exploration4", 2, -117, 118);
					end
			},
			
			--------- Image du savoir ------------
			
			Bitmap
			{
				image="backgrounds/work/savoir_on_1",
				x = kCenter + 120,
				y = kCenter - 105,
				name = "savoir_on_1";
			},
			
			ClickableImage
			{
        Text
				{
					name = "savoir1_cost_label",
					x = 0,
					y = kCenter,
					w = 40,
					h = 25,
                    font = ButtonKnowledgeTreeCostFont,
					flags = kHAlignCenter + kVAlignCenter,
				},
        
				image="backgrounds/work/savoir_off_1",
				x = kCenter + 120,
				y = kCenter - 105,
				name = "savoir_off_1";
				
				command =
					function()
						knowledge_tree_button_action("savoir1", 3, 120, -105);
					end
			},
			
			Bitmap
			{
				image="backgrounds/work/savoir_on_2",
				x = kCenter + 181,
				y = kCenter - 105,
				name = "savoir_on_2";
			},
			
			ClickableImage
			{
        Text
				{
					name = "savoir2_cost_label",
					x = 0,
					y = kCenter,
					w = 40,
					h = 25,
                    font = ButtonKnowledgeTreeCostFont,
					flags = kHAlignCenter + kVAlignCenter,
				},
   
				image="backgrounds/work/savoir_off_2",
				x = kCenter + 181,
				y = kCenter - 105,
				name = "savoir_off_2";
				
				command =
					function()
						knowledge_tree_button_action("savoir2", 3, 181, -105);
					end
			},
			
			Bitmap
			{
				image="backgrounds/work/savoir_on_3",
				x = kCenter + 244,
				y = kCenter - 105,
				name = "savoir_on_3";
			},
			
			ClickableImage
			{
        Text
				{
					name = "savoir3_cost_label",
					x = 0,
					y = kCenter,
					w = 40,
					h = 25,
                    font = ButtonKnowledgeTreeCostFont,
					flags = kHAlignCenter + kVAlignCenter,
				},
                
				image="backgrounds/work/savoir_off_3",
				x = kCenter + 244,
				y = kCenter - 105,
				name = "savoir_off_3";
				
				command =
					function()
						knowledge_tree_button_action("savoir3", 3, 244, -105);
					end
			},
			
			Bitmap
			{
				image="backgrounds/work/savoir_on_4",
				x = kCenter + 306,
				y = kCenter - 105,
				name = "savoir_on_4";
			},
			
			ClickableImage
			{
        Text
				{
					name = "savoir4_cost_label",
					x = 0,
					y = kCenter,
					w = 40,
					h = 25,
                    font = ButtonKnowledgeTreeCostFont,
					flags = kHAlignCenter + kVAlignCenter,
				},
                
				image="backgrounds/work/savoir_off_4",
				x = kCenter + 306,
				y = kCenter - 105,
				name = "savoir_off_4";
				
				command =
					function()
						knowledge_tree_button_action("savoir4", 3, 306, -105);
					end
			},
			
			------ Image musique --------
			
			Bitmap
			{
				image="backgrounds/work/musique_on_1",
				x = kCenter + 120,
				y = kCenter + 118,
				name = "musique_on_1";
			},
			
			ClickableImage
			{
        Text
				{
					name = "musique1_cost_label",
					x = 0,
					y = kCenter,
					w = 40,
					h = 25,
                    font = ButtonKnowledgeTreeCostFont,
					flags = kHAlignCenter + kVAlignCenter,
				},
                
				image="backgrounds/work/musique_off_1",
				x = kCenter + 120,
				y = kCenter + 118,
				name = "musique_off_1";
				
				command =
					function()
						knowledge_tree_button_action("musique1", 4, 120, 118);
					end
			},
			
			Bitmap
			{
				image="backgrounds/work/musique_on_2",
				x = kCenter + 181,
				y = kCenter + 118,
				name = "musique_on_2";
			},
			
			ClickableImage
			{
        Text
				{
					name = "musique2_cost_label",
					x = 0,
					y = kCenter,
					w = 40,
					h = 25,
                    font = ButtonKnowledgeTreeCostFont,
					flags = kHAlignCenter + kVAlignCenter,
				},
    
				image="backgrounds/work/musique_off_2",
				x = kCenter + 181,
				y = kCenter + 118,
				name = "musique_off_2";
				
				command =
					function()
						knowledge_tree_button_action("musique2", 4, 181, 118);
					end
			},
			
			Bitmap
			{
				image="backgrounds/work/musique_on_3",
				x = kCenter + 244,
				y = kCenter + 118,
				name = "musique_on_3";
			},
			
			ClickableImage
			{
        Text
				{
					name = "musique3_cost_label",
					x = 0,
					y = kCenter,
					w = 40,
					h = 25,
                    font = ButtonKnowledgeTreeCostFont,
					flags = kHAlignCenter + kVAlignCenter,
				},
                
				image="backgrounds/work/musique_off_3",
				x = kCenter + 244,
				y = kCenter + 118,
				name = "musique_off_3";
				
				command =
					function()
						knowledge_tree_button_action("musique3", 4, 244, 118);
					end
			},
			
			Bitmap
			{
				image="backgrounds/work/musique_on_4",
				x = kCenter + 306,
				y = kCenter + 118,
				name = "musique_on_4";
			},
			
			ClickableImage
			{
        Text
				{
					name = "musique4_cost_label",
					x = 0,
					y = kCenter,
					w = 40,
					h = 25,
                    font = ButtonKnowledgeTreeCostFont,
					flags = kHAlignCenter + kVAlignCenter,
				},
     
				image="backgrounds/work/musique_off_4",
				x = kCenter + 306,
				y = kCenter + 118,
				name = "musique_off_4";
				
				command =
					function()
						knowledge_tree_button_action("musique4", 4, 306, 118);
					end
			},
			
			--------------------------------Fin des images metiers -----------
			Bitmap
			{
				name = "icone_nature",
				image = "backgrounds/collection/icone_tome_nature.png",
				x=kCenter - 342,
    			y=kCenter - 212,				
			},
            Text
            {
    			font = PapyrusLegendFont,
    			name = "nature",
    			x=kCenter - 222,
    			y=kCenter - 212,
    			flags = kHAlignLeft + kVAlignCenter,
    			w=200,
    			h=70,
    			label="nature",
            },
           
            Button
            {
                x=kCenter  - 90,
    			y=kCenter  - 212,
    			graphics = HelpToLButtonGraphics,
    			name="naturehelp",
    			command=
    				function()
    					DisplayDialog { "scripts/okbox.lua", body = "tooltip_nature", title = "nature" };
    				end
            },
		   
		    Bitmap
			{
				name = "icone_exploration",
				image = "backgrounds/collection/icone_tome_exploration.png",
				x=kCenter - 342,
    			y=kCenter + 11,			
			},
            Text
            {
    			font = PapyrusLegendFont,
    			name = "exploration",
    			x=kCenter - 222,
    			y=kCenter + 11,
    			flags = kHAlignLeft + kVAlignCenter,
    			w=200,
    			h=70,
    			label="exploration",
            },
           
            Button
            {
                x=kCenter  - 90,
    			y=kCenter  + 11,
    			graphics = HelpToLButtonGraphics,
    			name="explorationhelp",
    			command=
    				function()
    					DisplayDialog { "scripts/okbox.lua", body = "tooltip_exploration", title = "exploration" };
    				end
            },
		   
		    Bitmap
			{
				name = "icone_exploration",
				image = "backgrounds/collection/icone_tome_savoir.png",
				x=kCenter + 78,
    			y=kCenter - 212,		
			},
            Text
            {
    			font = PapyrusLegendFont,
    			name = "science",
    			x=kCenter + 198,
    			y=kCenter - 212,
    			flags = kHAlignLeft + kVAlignCenter,
    			w=200,
    			h=70,
    			label="science",
            },
          
            Button
            {
                x=kCenter  + 335,
    			y=kCenter  - 212,
    			graphics = HelpToLButtonGraphics,
    			name="sciencehelp",
    			command=
    				function()
    					DisplayDialog { "scripts/okbox.lua", body = "tooltip_savoir", title = "science" };
    				end
            },
		    
			Bitmap
			{
				name = "icone_exploration",
				image = "backgrounds/collection/icone_tome_musique.png",
				x=kCenter + 78,
    			y=kCenter + 11,	
			},
		    Text
            {
    			font = PapyrusLegendFont,
    			name = "musique",
    			x=kCenter + 198,
    			y=kCenter + 11,
    			flags = kHAlignLeft + kVAlignCenter,
    			w=200,
    			h=70,
    			label="musique",
            },
           
            Button
            {
                x=kCenter  + 335,
    			y=kCenter  + 11,
    			graphics = HelpToLButtonGraphics,
    			name="musiquehelp",
    			command=
    				function()
    					DisplayDialog { "scripts/okbox.lua", body = "tooltip_musique", title = "musique" };
    				end
            },
			
			tab_placement( 2 ),			
			tome_footer(),
		},
	},
	
	
}