LoadFile("DATA:GUI/Dialogs_Screen.lua")

-----------------------------------------------------
-- Collectibles
-----------------------------------------------------

--Template
CollectibleItem =
{
	name = "CollectibleItem",
	enabled = false,
	visible = true,
	width = 80,
	height = 100,
	anim_ext =
	{
		--no placeholder -> avoids stomping widget dimensions
		auto_hitregion = false,
		disable_collision_mask = true,
		do_not_animate = true,
	},
}

CollectiblesGroup = CreateGroup("CollectiblesGroup", {}, SCREEN_WIDTH, CollectibleItem.height, { SCREEN_WIDTH / 2, CollectibleItem.height / 2 })
CollectiblesGroup.enabled = false

-----------------------------------------------------
-- Game Menu Tab
-----------------------------------------------------
MenuButton = CreatePushButton("MenuButton", [[GUI/in_game_menu/menu_tab.anim]], { SCREEN_WIDTH - 145, -30 }, 1.1)
MenuButton.anim_ext.additional_scale = 1.1
MenuButton.button_ext.under_growth = 1

--------------------------------------------------------
-- Game Menu Dialog
--------------------------------------------------------

local buttonSpread = 86
local buttonX = -64
local buttonY = 43
local buttonOG = 1.1
local maxButtons = 5

local GameMenuChildren = {}

function AddGameMenuButton(name, anim, text)
	local button = CreatePushButton(name, anim, { buttonX, buttonY }, buttonOG)
	local txt = CreateClickableText(name.."Text", text, { buttonX + 27, buttonY }, "centy")
	txt.text_ext.font = "label"
	txt.text_ext.colour = WHITE
	txt.text_ext.hover_colour = WHITE
	txt.text_ext.offset = { 10, 0 }
	txt.button_ext.over_growth = 1
	txt.button_ext.under_growth = 1
	txt.width = 200
	txt.height = 50
	table.insert(GameMenuChildren, button)
	table.insert(GameMenuChildren, txt)
	buttonY = buttonY + buttonSpread
end

AddGameMenuButton("GameMenuOptions", [[GUI/in_game_menu/button_options.anim]], "$00497")
AddGameMenuButton("GameMenuPuzzleMap", [[GUI/in_game_menu/button_map.anim]], "$00496")

-- bottom align the buttons
buttonY = (maxButtons - math.floor(table.getn(GameMenuChildren) / 2)) * buttonSpread
for i, v in ipairs(GameMenuChildren) do
	v.position[2] = v.position[2] + buttonY
end

local GameMenuBackground = CreateImage("GameMenuBackground", [[GUI/in_game_menu/menu_panel.anim]], { 0, 250 })
GameMenuBackground.enabled = false
GameMenuBackground.anim_ext.do_not_animate = true
table.insert(GameMenuChildren, GameMenuBackground)

local GameMenuReturn = inherit(MenuButton)
{
	name = "GameMenuReturn",
	position = { 0, MenuButton.position[2] + 488 },
	button_ext =
	{
		under_growth = 0.8,
	},
}
table.insert(GameMenuChildren, GameMenuReturn)

GameMenuDialog = CreateModalDialog("GameMenuDialog", GameMenuChildren, nil, { SCREEN_WIDTH - 145, -buttonY })
-- override dimensions to force start position of opening transition
GameMenuDialog.width = 520
GameMenuDialog.height = 960
GameMenuDialog.modal_ext.fade_colour = { r = 0, g = 0, b = 0, alpha = 100 }

-----------------------------------------------------
-- Controls
-----------------------------------------------------
function SetUITooltip(widget, txt, offset)
	local tooltip = CreateStaticText(widget.name.."Tooltip", txt, { 0, 0 }, "unicode", "centre centy")
	tooltip.text_ext.colour = WHITE
	tooltip.text_ext.additional_scale = 0.8
	SetTooltip(widget, tooltip, offset, 0.5)
end

local buttonOG = 1.05
local buttonScale = 1.05
local buttonY = (CONTROL_PANEL_HEIGHT - CONTROL_PANEL_OFFSET) / 2
local playButtonTooltipOffset = { 8, -118 }
local speedButtonTooltipOffset = { 108, 0 }

local PlayButton = CreatePushButton("PlayButton", [[GUI/in_game/button_play_default.anim]], { 85, buttonY + 33 }, buttonOG)
PlayButton.button_ext.additional_scale = buttonScale
PlayButton.button_ext.wait_for_motion = true
PlayButton.anim_ext.disable_collision_mask = false
SetUITooltip(PlayButton, "$00201", playButtonTooltipOffset)

local StopButton = CreatePushButton("StopButton", [[GUI/in_game/button_stop_default.anim]], { 85, buttonY + 33 }, buttonOG)
StopButton.button_ext.additional_scale = buttonScale
StopButton.button_ext.wait_for_motion = true
StopButton.anim_ext.disable_collision_mask = false
SetUITooltip(StopButton, "$00202", playButtonTooltipOffset)

local SpeedFastButton = CreatePushButton("SpeedFastButton", [[GUI/in_game/button_speed_fast.anim]], { 160, buttonY - 30 }, buttonOG)
SpeedFastButton.button_ext.additional_scale = buttonScale
SpeedFastButton.anim_ext.disable_collision_mask = false
SetUITooltip(SpeedFastButton, "$00221", speedButtonTooltipOffset)

local SpeedMediumButton = CreatePushButton("SpeedMediumButton", [[GUI/in_game/button_speed_medium.anim]], { 165, buttonY + 16 }, buttonOG) 
SpeedMediumButton.button_ext.additional_scale = buttonScale
SpeedMediumButton.anim_ext.disable_collision_mask = false
SetUITooltip(SpeedMediumButton, "$00222", speedButtonTooltipOffset)

local SpeedSlowButton = CreatePushButton("SpeedSlowButton", [[GUI/in_game/button_speed_slow.anim]], { 160, buttonY + 62 }, buttonOG)
SpeedSlowButton.button_ext.additional_scale = buttonScale
SpeedSlowButton.anim_ext.disable_collision_mask = false
SetUITooltip(SpeedSlowButton, "$00223", speedButtonTooltipOffset)

--
local BottomBarVertical = CreatePushButton("BottomBarVertical", [[GUI/in_game/bottom_bar_vertical.anim]], { 100, 50 + CONTROL_PANEL_HEIGHT / 2 })
local BottomBar = CreateImage("BottomBar", [[GUI/in_game/panel.anim]], { SCREEN_WIDTH / 2, CONTROL_PANEL_HEIGHT / 2 })
local BottomBarBehind = CreateImage("BottomBarBehind", [[GUI/in_game/panel_behind.anim]], { SCREEN_WIDTH - 375, CONTROL_PANEL_HEIGHT - 10 })

-----------------------------------------------------
-- Conveyor
-----------------------------------------------------

local itemWidth = 100
local itemOffsetX = 20	--extra spacing at the left edge
						--not included in conveyorX because conveyorX already offset by itemWidth/2, and anymore will break clipping
local itemOffsetY = 36
local conveyorX = 196 --width of bottom left control buttons
local conveyorY = CONTROL_PANEL_HEIGHT + SCROLL_BAR_OFFSET - 100
local conveyorWidth = SCREEN_WIDTH - conveyorX
local conveyorHeight = 60
local scrollerWidth = 618
local scrollerHeight = 20
local scrollerX = conveyorX + itemOffsetX + (scrollerWidth + itemWidth) / 2
local scrollerY = conveyorY + 80

--Scrollbar button position and range.
local ConveyerScrollerButton = CreateScrollerButton("ConveyerScroller", [[GUI\buttons\scrollbar_dot.anim]])
ConveyerScrollerButton.anim_ext.additional_scale = 0.5
local ConveyerScrollbar = CreateScrollBar("ConveyerScrollbar", nil, nil, ConveyerScrollerButton, { scrollerX - conveyorX - scrollerWidth / 2, scrollerY - conveyorY })
ConveyerScrollbar.width = scrollerWidth
ConveyerScrollbar.height = scrollerHeight
ConveyerScrollbar.scrollbar_ext.start_point = { 0, 0 }
ConveyerScrollbar.scrollbar_ext.end_point = { 1, 0 }
ConveyerScrollbar.scrollbar_ext.is_modal = false
ConveyerScrollbar.scrollbar_ext.scroller_offset = { 0, 0 }

--List Box of items with scrollbar button attached
local ConveyerListBox = CreateListBox("ConveyerListBox", conveyorWidth, conveyorHeight, ConveyerScrollbar, { conveyorX, conveyorY })
ConveyerListBox.listbox_ext.horizontal = true
ConveyerListBox.listbox_ext.item_offset = { itemOffsetX, itemOffsetY }
ConveyerListBox.listbox_ext.item_width = itemWidth
ConveyerListBox.listbox_ext.drag_items_vector = { 0, -50 }

--Expand list box hit to the entire conveyor area for capturing drag and mouse wheel
--coords relative to BottomGroup
ConveyerListBox.hit_top_left = { 196 - conveyorX, -20 }
ConveyerListBox.hit_bottom_right = { SCREEN_WIDTH - conveyorX, CONTROL_PANEL_HEIGHT - conveyorY }

local ConveyerImage = nil
if GetVersion() == "IOS" then
	ConveyerScrollbar.scrollbar_ext.force_hidden = true
	ConveyerListBox.listbox_ext.auto_disable_drag = true
else
	--Scrollbar image drawn separately
	ConveyerImage = CreateImage("ScrollBar", [[GUI\buttons\scrollbar.anim]], { scrollerX, scrollerY })
	ConveyerListBox.listbox_ext.snap_back = false
end

---------------------------------------------------
-- Item Tooltips for Sim and Toolbar Objects
---------------------------------------------------

if GetVersion() ~= "IOS" then

	local ItemTTHeader = CreateStaticText("ItemTTHeader", "", { 0, 0 }, "unicode", "centre")
	ItemTTHeader.width = 1
	ItemTTHeader.height = 1
	ItemTTHeader.text_ext.colour = WHITE
	ItemTTHeader.text_ext.additional_scale = 0.9

	local ItemTTBody = CreateStaticText("ItemTTBody", "", { 0, 20 }, "unicode", "centre")
	ItemTTBody.width = 220
	ItemTTBody.height = 1
	ItemTTBody.text_ext.autowrap = true
	ItemTTBody.text_ext.colour = WHITE
	ItemTTBody.text_ext.additional_scale = 0.75

	local ItemTTGroup = CreateGroup("ItemTTGroup",
	{
		ItemTTHeader,
		ItemTTBody,
	},
	1, 1, { 0, 0 })

	ItemTooltipContainer =
	{
		name = "ItemTooltipContainer",
		width = 1,
		height = 1,
		enabled = false,
		visible = false,
	}
	SetTooltip(ItemTooltipContainer, ItemTTGroup, { 0, -30 }, 0.25)
	ItemTooltip = ItemTooltipContainer.tooltip_ext
	
end

-----------------------------------------------------
-- Bottom Group
-----------------------------------------------------

BottomGroup = CreateGroup("BottomGroup",
{
	PlayButton, 
	StopButton, 
	SpeedFastButton, 
	SpeedMediumButton, 
	SpeedSlowButton, 
	BottomBarVertical, 
	ConveyerListBox, 
	ConveyerImage, 
	BottomBar, 
	BottomBarBehind 
},
SCREEN_WIDTH, CONTROL_PANEL_HEIGHT, { 0, SCREEN_HEIGHT - CONTROL_PANEL_HEIGHT })
BottomGroup.thumbnail_renderable = true

-----------------------------------------------------
-- Creator Buttons
-----------------------------------------------------

local buttonSpread = 70
local buttonX = 0
local buttonY = 0
local buttonOG = 1.1
local buttonScale = 1.1

CreatorButtonsGroup = CreateGroup("CreatorButtonsGroup", {}, 1, 1, { SCREEN_WIDTH - 60, SCREEN_HEIGHT - CONTROL_PANEL_HEIGHT / 2 - 55 })

--Bottom aligned
function AddCreatorButton(name, anim, tooltip)
	local button = CreatePushButton(name, anim, { buttonX, buttonY }, buttonOG)
	button.anim_ext.additional_scale = buttonScale
	if tooltip then
		SetUITooltip(button, tooltip, { 0, -64 })
	end
	table.insert(CreatorButtonsGroup.parent_ext.children, button)
	buttonY = buttonY - buttonSpread
end

AddCreatorButton("TestButton", [[GUI\editor\button_test.anim]], "$00263")

-----------------------------------------------------
-- Radial Menu
-----------------------------------------------------

local buttonOG = 1.1
local radialTooltipOffset = { 0, -50 }

local rotatebutton = CreatePushButton("RadialRotateButton", [[GUI\in_game\radial_rotate.anim]], nil, buttonOG)
SetUITooltip(rotatebutton, "$00285", radialTooltipOffset)

local flipbutton = CreatePushButton("RadialFlipButton", [[GUI\in_game\radial_flip.anim]], nil, buttonOG)
SetUITooltip(flipbutton, "$00283", radialTooltipOffset)

local sendbackwardbutton = CreatePushButton("RadialSendBackwardButton", [[GUI\in_game\radial_backward.anim]], nil, buttonOG)
SetUITooltip(sendbackwardbutton, "$00279", radialTooltipOffset)

local sendforwardbutton = CreatePushButton("RadialBringForwardButton", [[GUI\in_game\radial_forward.anim]], nil, buttonOG)
SetUITooltip(sendforwardbutton, "$00281", radialTooltipOffset)

local lockbutton = CreatePushButton("RadialLockButton", [[GUI\in_game\radial_lock.anim]], nil, buttonOG)
SetUITooltip(lockbutton, "$00287", radialTooltipOffset)

local hintradialbutton = CreatePushButton("RadialSetHintableButton", [[GUI\in_game\radial_hint.anim]], nil, buttonOG)
SetUITooltip(hintradialbutton, "$00289", radialTooltipOffset)

local emotionradialbutton = CreatePushButton("RadialEmotionButton", [[GUI\in_game\radial_emotions.anim]], nil, buttonOG)
SetUITooltip(emotionradialbutton, "$00291", radialTooltipOffset)

local platformradialbutton = CreatePushButton("RadialPlatformPropertiesButton", [[GUI\in_game\radial_platforms.anim]], nil, buttonOG)
SetUITooltip(platformradialbutton, "$00293", radialTooltipOffset)

local copyradialbutton = CreatePushButton("RadialCopyButton", [[GUI\in_game\radial_copy.anim]], nil, buttonOG)
SetUITooltip(copyradialbutton, "$00295", radialTooltipOffset)

RadialMenu = CreateRadial("RadialMenu",
{
	sendbackwardbutton,
	sendforwardbutton,
	flipbutton,
	rotatebutton,
	lockbutton,
	hintradialbutton,
	emotionradialbutton,
	platformradialbutton,
	copyradialbutton,
},
nil, { 0, 0 })
RadialMenu.width = 1
RadialMenu.height = 1
for i, v in ipairs(RadialMenu.parent_ext.children) do
	v.anim_ext.disable_collision_mask = false
end

-----------------------------------------------------
-- Win Dialog
-----------------------------------------------------

-- globals
CollectibleScaleStart = 1.2
CollectibleScaleEnd = 1.0
CollectibleScaleTime = 0.08
CollectibleDelay = 0.35 --delay between collectibles
WinMusicDelay = 0.5 --delay before music plays

local WinDialogChildren = {}

-- Buttons
local buttonSpread = 140
local buttonX = 0
local buttonY = 90
local buttonOG = 1.1

function AddWinDialogButton(name, anim)
	table.insert(WinDialogChildren, CreatePushButton(name, anim, { buttonX, buttonY }, buttonOG))
	buttonX = buttonX + buttonSpread
end

AddWinDialogButton("WinDialogMenuButton", [[GUI\level_complete\menu_button.anim]])
AddWinDialogButton("WinDialogRestartButton", [[GUI\level_complete\restart_button.anim]])
AddWinDialogButton("WinDialogNextButton", [[GUI\level_complete\next_button.anim]])

-- center align the buttons
buttonX = (table.getn(WinDialogChildren) - 1) / 2 * buttonSpread
for i, v in ipairs(WinDialogChildren) do
	v.position[1] = v.position[1] - buttonX
end

-- Collectibles
local collectibleSpread = 150
local collectibleY = -40
local collectibleOffsetY = -20
local collectibleWidth = 250
local collectibleHeight = 250

function AddWinDialogCollectible(name, pos, fac)
	local anim = CreateImage(name, [[world/blank.anim]], pos, fac)
	anim.enabled = false
	anim.width = collectibleWidth
	anim.height = collectibleHeight
	anim.anim_ext.auto_hitregion = false
	anim.anim_ext.do_not_animate = true
	table.insert(WinDialogChildren, 1, inherit(anim){ name = name.."Outline" })
	table.insert(WinDialogChildren, 1, anim)
end

AddWinDialogCollectible("Collectible1", { -collectibleSpread, collectibleY }, { 1, -0.5 })
AddWinDialogCollectible("Collectible2", { 0, collectibleY + collectibleOffsetY })
AddWinDialogCollectible("Collectible3", { collectibleSpread, collectibleY }, { 1, 0.5 })

local UnlockText = CreateStaticText("WinDialogUnlockText", "", { -250, -230 }, "label", "")
UnlockText.text_ext.colour = WHITE
UnlockText.width = 1
UnlockText.height = 1
table.insert(WinDialogChildren, UnlockText);

WinDialog = CreateModalDialog("WinDialog", WinDialogChildren, [[GUI\generic_dialogs\generic_dialog_medium.anim]], { SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 })
WinDialog.modal_ext.fade_colour = { r = 0, g = 0, b = 0, alpha = 100 }
  
---------------------------------------------------
-- Eets Dead Dialog
---------------------------------------------------

local FailEetsStars = CreateImage("FailEetsStars", [[GUI/level_complete/fail_eets_stars.anim]], { 0, 0 })
local FailEetsEyes = CreateImage("FailEetsEyes", [[GUI/level_complete/fail_eets_eyes.anim]], { 0, 0})
local FailEets = CreateImage("FailEets", [[GUI/level_complete/fail_eets.anim]], { 0, 0 })
local FailOops = CreateImage("FailOops", [[GUI/level_complete/fail_oops.anim]], { 0, 0 })

local EetsDeadDialogTryAgain = CreatePushButton("EetsDeadDialogTryAgain", [[GUI\level_complete\restart_button.anim]], { 95, 68 }, 1.1)
EetsDeadDialogTryAgain.button_ext.additional_scale = 1.35
	
EetsDeadDialog = CreateModalDialog("EetsDeadDialog",
{
	EetsDeadDialogTryAgain,
	FailEetsStars,
	FailEetsEyes,
	FailEets,
	FailOops,
},
[[GUI\generic_dialogs\generic_dialog_medium.anim]], { SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2 })
EetsDeadDialog.modal_ext.fade_colour = { r = 0, g = 0, b = 0, alpha = 100 }
EetsDeadDialog.modal_ext.start_sound = "eets2/Items/Goal/Fail"
EetsDeadDialog.modal_ext.fade_music = false
EetsDeadDialog.modal_ext.stop_music = true
