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

NameButtonGraphics = 
{
	"buttons/choosenameover.png",
	"buttons/choosenamedown.png",
	"buttons/choosenameover.png",
	"buttons/choosenamedown.png"
};	

NameStyle= 
{
	type = kRadio,
	flags = kHAlignCenter + kVAlignCenter,
	font = StandardButtonFont,
	graphics = NameButtonGraphics,
	sound = kDefaultButtonSound
};

function AddQuestButtons()
	--local tQuests = GetQuestsToDisplay();
	local mQuests = SortQuest();
	local nbPrimaryQuests = mQuests[1]; -- nb primary quests
	local tQuests = mQuests[2]; -- quests
    local bcQuests = mQuests[3]; -- begun or completed quests ?
    local tTable;
    
    t = {};

    table.insert( t, BeginGroup() );
    table.insert( t, SetStyle(NameStyle) );
    
    local j = 1;
    local num = 0;
    -- Primary
    while ( num < nbPrimaryQuests ) do
        num = num + 1;
        if (bcQuests[num] == 0) then
            table.insert( t,
                Button
                {
                    name = tQuests[num],
                    x = 60,
                    y = 3 + 30 * j,
                    label = tQuests[num],
                    font = { corsivaFont, 18, BlackColor },
                    flags = kHAlignLeft + kVAlignCenter,
					command = 
                        function()
                          SwitchToQuestDescription();
                        end
                }
            );
			table.insert( t,
                Bitmap
				{
					name = "enQuete",
					x = 18,
                    y = 3 + 30 * j,
					image = "backgrounds/tome_sommaire/Quete_Neutre" ,
				}
            );
			
        end
        if (bcQuests[num] == 1) then
            table.insert( t,
                Button
                {
                    name = tQuests[num],
                    x = 60,
                    y = 3 + 30 * j,
                    label = tQuests[num],
                    font = { corsivaFont, 18, MordoreColor },
                    flags = kHAlignLeft + kVAlignCenter,
					command = 
                        function()
                            SwitchToQuestDescription();
                        end
                }
            );
			table.insert( t,
                Bitmap
				{
					name = "queteValide",
					x = 18,
                    y = 3 + 30 * j,
					image = "backgrounds/tome_sommaire/Quete_Valide" ,
				}
            );
        end
		
		 if (bcQuests[num] == 2) then
            table.insert( t,
                Button
                {
                    name = tQuests[num],
                    x = 60,
                    y = 3 + 30 * j,
                    label = tQuests[num],
                    font = { corsivaFont, 18, BlackColor },
                    flags = kHAlignLeft + kVAlignCenter,
					command = 
                        function()
                            SwitchToQuestDescription();
                        end
                }
            );
			table.insert( t,
                Bitmap
				{
					name = "queteInProgress",
					x = 18,
                    y = 3 + 30 * j,
					image = "backgrounds/tome_sommaire/En_Quete" ,
				}
            );
        end
		
        j = j + 1;
    end
    
    --Secondary
    local j = 1;
    while ( num < table.getn(tQuests) ) do
        num = num + 1;
        if (bcQuests[num] == 0) then
            table.insert( t,
                Button
                {
                    name = tQuests[num],
                    x = 465,
                    y = 3 + 30 * j,
                    label = tQuests[num],
                    font = { corsivaFont, 18, BlackColor },
                    flags = kHAlignLeft + kVAlignCenter,
					command = 
                        function()
                            SwitchToQuestDescription();
                        end
                }
            );
			table.insert( t,
                Bitmap
				{
					name = "enQuete",
					x = 423,
                    y = 3 + 30 * j,
					image = "backgrounds/tome_sommaire/Quete_Neutre" ,
				}
            );
			
        end
        if (bcQuests[num] == 1) then
            table.insert( t,
                Button
                  {
                    name = tQuests[num],
                    x = 465,
                    y = 3 + 30 * j,
                    label = tQuests[num],
                    font = { corsivaFont, 18, MordoreColor },
                    flags = kHAlignLeft + kVAlignCenter,
					command = 
                        function()
                            SwitchToQuestDescription();
                        end
                }
            );
			table.insert( t,
                Bitmap
				{
					name = "queteValide",
					x = 423,
                    y = 3 + 30 * j,
					image = "backgrounds/tome_sommaire/Quete_Valide" ,
				}
            );
        end
		if (bcQuests[num] == 2) then
            table.insert( t,
                Button
                  {
                    name = tQuests[num],
                    x = 465,
                    y = 3 + 30 * j,
                    label = tQuests[num],
                    font = { corsivaFont, 18, MordoreColor },
                    flags = kHAlignLeft + kVAlignCenter,
					command = 
                        function()
                            SwitchToQuestDescription();
                        end
                }
            );
			table.insert( t,
                Bitmap
				{
					name = "queteValide",
					x = 423,
                    y = 3 + 30 * j,
					image = "backgrounds/tome_sommaire/En_Quete" ,
				}
            );
        end
        j = j + 1;
    end
	
	return Group(t);
end


MakeDialog
{
	name = "quest_report",
	
	KnowledgeTomeWindow
	{
		x = 0,
		y = 0,
		w = GetScreenWidth(),
		h = GetScreenHeight(),	
		
				
		Bitmap
		{
			image="backgrounds/options",
			x = kCenter,
			y = kCenter - 84,
            
            SetStyle( OptionsCancelButtonStyle );
            Button
            {
                name = "back",
                label = "back",
                x = 707,
                y = 450,
                command = 
                    function()
                        SwitchToQuests();
                    end
            },
			
			Text
			{
                font = { papyrusFont, 26, MordoreColor },
				name = "quest_finished",
				x = 90,
				y = 85,
				w = 350,
				h = 50,
				
				label = "completed",
				
				flags = kHAlignCenter + kVAlignTop,
			},
			
			QuestContainer
			{
				x = 90,
				y = 50,
				w = 700,
				h = 450,
				
				name = "quest_container",
				
                font_done = { corsivaFont, 20, MordoreColor },
                font_undone = { corsivaFont, 20, BlackColor },
				
				image_up = "buttons/choosenameover.png",
				image_down = "buttons/choosenamedown.png",
				image_rollover_up = "buttons/choosenamedown.png",
				image_rollover_down = "buttons/choosenamedown.png",
                
				AddQuestButtons(),
				
			},
      
			
				
            --Gauche
            Text
			{
				font = PapyrusLegendFont,
				name = "q_primary_book",
				x = 90,y = 50,w=350,h=50,
				flags = kHAlignCenter + kVAlignTop,
				label = "q_primary_book"
			},
            
            
            Text
			{
                font = PapyrusLegendFont,
				name = "quest_name",
				x = 90,
				y = 50,
				w = 350,
				h = 50,
				
				flags = kHAlignCenter + kVAlignTop,
			},
            
            Text
			{
			    font = { papyrusFont, 26, BlackColor },
				name = "quest_objective",
				x = 90,
				y = 100,
				w = 350,
				h = 60,
				
				flags = kHAlignCenter + kVAlignCenter,
			},
            
            Text
			{
				name = "quests_elements_description",
				x = 90,
				y = 150,
				w = 350,
				h = 350,
				
				flags = kHAlignLeft + kVAlignCenter,
			},
            
			Text
			{
				name = "quests_description_image",
				x = 50,
				y = 145,
				w = 350,
				h = 350,
			},
				
            --Droite
            Text
			{
				font = PapyrusLegendFont,
				name = "q_secondary_book",
				x = 500,y = 50,w=350,h=50,
				flags = kHAlignCenter + kVAlignTop,
				label = "q_secondary_book"
			},
                
            
            Text
			{
				font = { corsivaFont, 19, BlackColor },
				name = "quest_description",
				x = 500,
				y = 60,
				w = 350,
				h = 70,
				
				flags = kHAlignLeft + kVAlignTop,
			},
            
            Text
			{
				font = { corsivaFont, 19, BlackColor },
				name = "quests_elements_done",
				x = 500,
				y = 130,
				w = 350,
				h = 330,
				
				flags = kHAlignLeft + kVAlignTop,
			},
			
			tab_placement( 4 ),
			tome_footer(),
		},

	},
	
	
}
