--------------------------------------------------------
-- Platform selection layout
--------------------------------------------------------

--Each sub table corresponds to a hub
--Similar shaped platforms must be listed in the same order within each hub
--nil must be listed if a hub doesn't contain a matching shaped platform
--Example for defining PlatformMapPages entries (further below):
--  e.g. CreatePlatformMapItem(13, { 1, 2 }, { 3, 1 })
--       13: The thirteenth item for the current hub
--       { 1, 2 }: The item is 1 wide, 2 tall
--       { 3, 1 }: The item is placed starting at column 3, row 1 (NOTE: 0-based)
--  This means the thirteenth platform image listed for each hub must be shaped
--  to fit roughly 1 cell width and 2 cell heights.
--  See \\contentbase\UI\iPad Revamp\PNGs\LevelEditor\PlatformMap.fla
PlatformMapFilenames =
{
	{
		[[DATA:Animations\Platforms\forest_platform_01.png]],
		[[DATA:Animations\Platforms\forest_platform_02.png]],
		[[DATA:Animations\Platforms\forest_platform_03.png]],
		[[DATA:Animations\Platforms\forest_platform_04.png]],
		[[DATA:Animations\Platforms\forest_platform_05.png]],
		[[DATA:Animations\Platforms\forest_platform_06.png]],
		[[DATA:Animations\Platforms\forest_platform_07.png]],
		[[DATA:Animations\Platforms\forest_platform_08.png]],
		[[DATA:Animations\Platforms\forest_platform_09.png]],
		[[DATA:Animations\Platforms\forest_platform_10.png]],
		[[DATA:Animations\Platforms\forest_platform_11.png]],
		[[DATA:Animations\Platforms\forest_platform_12.png]],
		[[DATA:Animations\Platforms\forest_solid_01.png]],
		[[DATA:Animations\Platforms\forest_solid_02.png]],
		[[DATA:Animations\Platforms\forest_solid_03.png]],
		[[DATA:Animations\Platforms\forest_solid_04.png]],
		[[DATA:Animations\Platforms\forest_decor_01.png]],
		[[DATA:Animations\Platforms\forest_decor_02.png]],
		[[DATA:Animations\Platforms\forest_decor_03.png]],
	},
	{
		[[DATA:Animations\Platforms\kaboom_platform1.png]],
		[[DATA:Animations\Platforms\kaboom_platform2.png]],
		[[DATA:Animations\Platforms\kaboom_platform3.png]],
		[[DATA:Animations\Platforms\kaboom_platform4.png]],
		[[DATA:Animations\Platforms\kaboom_platform5.png]],
		[[DATA:Animations\Platforms\kaboom_platform6.png]],
		[[DATA:Animations\Platforms\kaboom_platform7.png]],
		[[DATA:Animations\Platforms\kaboom_platform8.png]],
		[[DATA:Animations\Platforms\kaboom_platform9.png]],
		[[DATA:Animations\Platforms\kaboom_platform10.png]],
		[[DATA:Animations\Platforms\kaboom_platform11.png]],
		[[DATA:Animations\Platforms\kaboom_platform12.png]],
		[[DATA:Animations\Platforms\kaboom_solid_01.png]],
		[[DATA:Animations\Platforms\kaboom_solid_02.png]],
		[[DATA:Animations\Platforms\kaboom_solid_03.png]],
		[[DATA:Animations\Platforms\kaboom_solid_04.png]],
		[[DATA:Animations\Platforms\kaboom_decor_01.png]],
		[[DATA:Animations\Platforms\kaboom_decor_02.png]],
		[[DATA:Animations\Platforms\kaboom_decor_03.png]],
	},
	{
		[[DATA:Animations\Platforms\caves_platform_01.png]],
		[[DATA:Animations\Platforms\caves_platform_02.png]],
		[[DATA:Animations\Platforms\caves_platform_03.png]],
		[[DATA:Animations\Platforms\caves_platform_04.png]],
		[[DATA:Animations\Platforms\caves_platform_05.png]],
		[[DATA:Animations\Platforms\caves_platform_06.png]],
		[[DATA:Animations\Platforms\caves_platform_07.png]],
		[[DATA:Animations\Platforms\caves_platform_09.png]],
		[[DATA:Animations\Platforms\caves_platform_08.png]],
		[[DATA:Animations\Platforms\caves_platform_10.png]],
		[[DATA:Animations\Platforms\caves_platform_11.png]],
		[[DATA:Animations\Platforms\caves_platform_12.png]],
		[[DATA:Animations\Platforms\caves_solid_01.png]],
		[[DATA:Animations\Platforms\caves_solid_02.png]],
		[[DATA:Animations\Platforms\caves_solid_03.png]],
		[[DATA:Animations\Platforms\caves_solid_04.png]],
		[[DATA:Animations\Platforms\caves_decor_01.png]],
		[[DATA:Animations\Platforms\caves_decor_02.png]],
		[[DATA:Animations\Platforms\caves_decor_03.png]],
	},
	{
		[[DATA:Animations\Platforms\peaks_platform_01.png]],
		[[DATA:Animations\Platforms\peaks_platform_02.png]],
		[[DATA:Animations\Platforms\peaks_platform_03.png]],
		[[DATA:Animations\Platforms\peaks_platform_04.png]],
		[[DATA:Animations\Platforms\peaks_platform_05.png]],
		[[DATA:Animations\Platforms\peaks_platform_06.png]],
		[[DATA:Animations\Platforms\peaks_platform_07.png]],
		[[DATA:Animations\Platforms\peaks_platform_08.png]],
		[[DATA:Animations\Platforms\peaks_platform_09.png]],
		[[DATA:Animations\Platforms\peaks_platform_10.png]],
		[[DATA:Animations\Platforms\peaks_platform_11.png]],
		[[DATA:Animations\Platforms\peaks_platform_12.png]],
		[[DATA:Animations\Platforms\peaks_solid_01.png]],
		[[DATA:Animations\Platforms\peaks_solid_02.png]],
		[[DATA:Animations\Platforms\peaks_solid_03.png]],
		[[DATA:Animations\Platforms\peaks_solid_04.png]],
		[[DATA:Animations\Platforms\peaks_decor_01.png]],
		[[DATA:Animations\Platforms\peaks_decor_02.png]],
		[[DATA:Animations\Platforms\peaks_decor_03.png]],
	},
}

local cellWidth = 200
local cellHeight = 180

--combine two pages into one for iOS scrolling
local mergePages = false--(GetVersion() == "IOS")

--Scale everything down so pages fit into screen width
PlatformMapScale = SCREEN_WIDTH / cellWidth / 6
cellWidth = cellWidth * PlatformMapScale
cellHeight = cellHeight * PlatformMapScale

PlatformMapPageWidth = cellWidth * 3
PlatformMapPageHeight = cellHeight * 3
if mergePages then
	PlatformMapPageWidth = PlatformMapPageWidth * 2
end

local PlatformMapItemTemplate =
{
	object_ext =
	{
		object = "platform",
	},
	button_ext =
	{
		over_growth = 1,
		under_growth = 1,
		activate_on_up = (GetVersion() == "IOS"),
	},
	sound_ext =
	{
		enter = { patch = "eets2/GUI/mouseOver" },
		click = { patch = "eets2/GUI/click" },
	},
}

local PlatformMapPageTemplate =
{
	width = PlatformMapPageWidth,
	height = PlatformMapPageHeight,
	hit_top_left = { -PlatformMapPageWidth / 2, -PlatformMapPageHeight / 2 },
	hit_bottom_right = { PlatformMapPageWidth / 2, PlatformMapPageHeight / 2 },
}

function CreatePlatformItem(n, grid_dimensions, grid_placement)
	local w = grid_dimensions[1] * cellWidth
	local h = grid_dimensions[2] * cellHeight
	local x = grid_placement[1] * cellWidth + (w - PlatformMapPageWidth) / 2
	local y = grid_placement[2] * cellHeight + (h - PlatformMapPageHeight) / 2
	local item = inherit(PlatformMapItemTemplate)
	{
		name = tostring(n),
		width = w,
		height = h,
		position = { x, y },
	}
	return item
end

PlatformMapPages = {}

local curPage = 0
local mergeNextPage = false
function AddPlatformMapPage(items)
	if mergeNextPage then
		local page = PlatformMapPages[curPage]
		local offset = PlatformMapPageWidth / 2
		for i,v in ipairs(items) do
			v.position[1] = v.position[1] + offset
			table.insert(page.parent_ext.children, v)
		end
	else
		curPage = curPage + 1
		local page = inherit(PlatformMapPageTemplate)
		{
			name = "PlatformMapPage"..tostring(curPage),
			parent_ext =
			{
				children = items,
			}
		}
		table.insert(PlatformMapPages, page)
	end
	mergeNextPage = mergePages and not mergeNextPage
end

AddPlatformMapPage({
	CreatePlatformItem(8, { 2, 1 }, { 0, 0 }),
	CreatePlatformItem(9, { 2, 1 }, { 0, 1 }),
	CreatePlatformItem(10, { 2, 1 }, { 0, 2 }),
	CreatePlatformItem(12, { 1, 1 }, { 2, 0 }),
	CreatePlatformItem(4, { 1, 1 }, { 2, 1 }),
	CreatePlatformItem(6, { 1, 1 }, { 2, 2 }),
})
AddPlatformMapPage({
	CreatePlatformItem(5, { 1, 1 }, { 0, 1 }),
	CreatePlatformItem(7, { 1, 1 }, { 0, 2 }),
	CreatePlatformItem(11, { 1, 1 }, { 0, 0 }),
	CreatePlatformItem(3, { 2, 1 }, { 1, 0 }),
	CreatePlatformItem(2, { 2, 1 }, { 1, 1 }),
	CreatePlatformItem(1, { 2, 1 }, { 1, 2 }),
})
AddPlatformMapPage({
	CreatePlatformItem(14, { 1, 1 }, { 0, 0 }),
	CreatePlatformItem(16, { 1, 1 }, { 0, 1 }),
	CreatePlatformItem(15, { 1, 1 }, { 0, 2 }),
	CreatePlatformItem(19, { 1, 2 }, { 1, 0 }),
	CreatePlatformItem(18, { 1, 2 }, { 2, 0 }),
	CreatePlatformItem(13, { 1, 1 }, { 1, 1.8 }),
	CreatePlatformItem(17, { 1, 1 }, { 2, 1.8 }),
})