require "scripts/style"

function setNeededResources( )
    local numWidth      = 40; -- width of number labels
-- offsets for the items   
    local offsetXStart  = 0;
    local offsetX       = 0; 
    local numOffsetX    = 40;
    local offsetIconY   = 405;--373;
    local offsetNumY    = offsetIconY + 10;
    -- 4
    local offset4XStart = 71;--50;
    local offset4X      = 80;
    -- 3
    local offset3XStart = 111;--90;
    local offset3X      = 80;
    -- 2
    local offset2XStart = 151;--130;
    local offset2X      = 80;
    -- 1
    local offset1XStart = 196;--175;
    local offset1X      = 80;

	t = { SetStyle(QuickTaskStyle), BeginGroup() };
    local count = 0;
    local offsets = {};
    offsets[0] = 0; -- food
    offsets[1] = 0; -- money
    offsets[2] = 0; -- stone
    offsets[3] = 0; -- wood
    currItem = 0; -- used in the for cycle to get the nbr where we are
    
-- check which resources are not zero
    if ( gFoodNbr > 0 )  then count = count + 1; offsets[0] = 1; end
    if ( gMoneyNbr > 0 ) then count = count + 1; offsets[1] = 1; end
    if ( gStoneNbr > 0 ) then count = count + 1; offsets[2] = 1; end
    if ( gWoodNbr > 0 )  then count = count + 1; offsets[3] = 1; end

    if ( count == 0 ) then return; end
    
    if     ( count == 4 ) then
        offsetXStart = offset4XStart;
        offsetX = offset4X;
    elseif ( count == 3 ) then
        offsetXStart = offset3XStart;
        offsetX = offset3X;
    elseif ( count == 2 ) then
        offsetXStart = offset2XStart;
        offsetX = offset2X;
    elseif ( count == 1 ) then
        offsetXStart = offset1XStart;
        offsetX = offset1X;
    end            
    
    
    for i = 0,3 do 
        if ( offsets[i] == 1 ) then
            offsets[i] = offsetXStart + (offsetX*currItem);
            currItem = currItem + 1;
        end
    end
    
-- Food
    if ( gFoodNbr > 0 ) then
		table.insert(t,
            Bitmap
            {
                name = "res_foodPic",
                image = "pics/food_lvl1",
                x = offsets[0],
                y = offsetIconY,
                scale = 1.00
            }
        );
		table.insert(t,
            Text
            {
                font = QuickTaskButtonFont,--StandardButtonFont,
                name = "res_foodNum",
                x=offsets[0] + numOffsetX,
                y=offsetNumY, 
                w=numWidth,
                h=25,
                flags = kHAlignLeft,
                label = gFoodNbr
            }
        );
    end
-- Money
    if ( gMoneyNbr > 0 ) then
		table.insert(t,
            Bitmap
            {
                name = "res_moneyPic",
                image = "pics/money_lvl1",
                x = offsets[1],
                y = offsetIconY,
                scale = 1.00
            }
        );
		table.insert(t,
            Text
            {
                font = QuickTaskButtonFont,--StandardButtonFont,
                name = "res_moneyNum",
                x=offsets[1] + numOffsetX,
                y=offsetNumY,
                w=numWidth,
                h=25,
                flags = kHAlignLeft,
                label = gMoneyNbr
            }
        ); 
    end
-- Stone
    if ( gStoneNbr > 0 ) then
		table.insert(t,
            Bitmap
            {
                name = "res_stonePic",
                image = "pics/stone_lvl1",
                x = offsets[2],
                y = offsetIconY,
                scale = 1.00
            }
        );
		table.insert(t,
            Text
            {
                font = QuickTaskButtonFont,--StandardButtonFont,
                name = "res_stoneNum",
                x=offsets[2] + numOffsetX,
                y=offsetNumY,
                w=numWidth,
                h=25,
                flags = kHAlignLeft,
                label = gStoneNbr
            }
        ); 
    end        
-- Wood
    if ( gWoodNbr > 0 ) then
		table.insert(t,
            Bitmap
            {
                name = "res_woodPic",
                image = "pics/wood_lvl1",
                x = offsets[3],
                y = offsetIconY,
                scale = 1.00
            }
        );
		table.insert(t,
            Text
            {
                font = QuickTaskButtonFont,--StandardButtonFont,
                name = "res_woodNum",
                x=offsets[3] + numOffsetX,
                y=offsetNumY,
                w=numWidth,
                h=25,
                flags = kHAlignLeft,
                label = gWoodNbr
            }
        );         
	end        
   
    return Group(t);
end

MakeDialog
{
	-- Name the modal dialog
	name="nextStationDialog",
	Bitmap
	{
		image="backgrounds/largedialog",
		x = kCenter,
		y = kCenter,
        
-- station pic backgrounds
			Bitmap
			{
				name="nextStationStationPicBackground",
				image="buildings/station_unlock_background",
				x=kCenter,
				y=85,--70,
                alpha=true,
			}, 
-- Station picture
			Bitmap
			{
				name="nextStationStationPic",
				image=gNextStationImage,
				x=kCenter,
				y=96,--81,
			},   
-- Building Name            
			Text
			{
				align=kHAlignLeft,
				font = StandardButtonFontHuge,
				name = "nextStationBuildingName",
				x=kCenter,
                y=218,--193,
                w=335, h=30,
				flags = kHAlignCenter + kVAlignCenter,
				label = gNextBuildingName
			};              
-- Congratulation            
			Text
			{
				font = StandardButtonFont,
				name = "nextStationCongratulation",
				x=kCenter,
                y=45,--35,
                w=335,h=30,
				flags = kHAlignCenter + kVAlignCenter,
				label = "weaponUnlockCongratulation"
			};
-- Description            
			Text
			{
				font = StandardButtonFontSmall,
				name = "nextStationDescription",
				x=kCenter,
                y=260,--230,
                w=335,h=180,
				flags = kHAlignCenter,-- + kVAlignCenter,
				label = gNextStationDescription
			};        
           
            SetStyle(SmallEmptyRoundButtonStyle),
			Button
			{
				x = kCenter,
				y = kMax-90, --84,
				name="nextStationOK",
				label="ok",
				close=true,
				default=true,
				type = kPush,
                command=
                    function()
                        gNextStationDialogClosed = 1;
						nextStationDialogClosed();
                    end	                    
			},
            setNeededResources( );            
--		},
	},
}


