LoadFile("DATA:GUI/Creator_Screen.lua")
LoadFile("DATA:GUI/PlatformMap.lua")

-----------------------------------------------------
-- Editor Buttons
-----------------------------------------------------

local buttonSpread = 60
local buttonX = 0
local buttonY = 0
local buttonOG = 1.15

--Right aligned
function CreateEditorButton(name, anim, anim_disabled, tooltip)
	buttonX = buttonX - buttonSpread
	local button = CreatePushButton(name, anim, { buttonX, buttonY }, buttonOG)
	if anim_disabled then
		button.anim_ext.animation_disabled = anim_disabled
	end
	SetUITooltip(button, tooltip, { 0, -50 })
	return button
end

local EditorButtonsGroup = CreateGroup("EditorButtonsGroup",
{
	CreateEditorButton("PropertiesButton", [[GUI\editor\button_decor.anim]], nil, "$00267"),
	CreateEditorButton("UndoButton", [[GUI\editor\button_undo.anim]], [[GUI\editor\button_undo_disabled.anim]], "$00265"),
	CreateEditorButton("HelpButton", [[GUI\editor\button_help.anim]], nil, "$00275"),
},
-buttonX, EDITOR_BUTTONS_HEIGHT, { SCREEN_WIDTH - 75, SCREEN_HEIGHT - CONTROL_PANEL_HEIGHT / 2 - 50 })

--------------------------------------------------------
-- Level Properties Dialog
--------------------------------------------------------

local LevelPropertiesTitle = CreateStaticText("LevelPropertiesTitle", "$00267", { 0, -175 }, "header", "centre")
LevelPropertiesTitle.width = 300
LevelPropertiesTitle.height = 30
LevelPropertiesTitle.text_ext.colour = WHITE

local buttonSpread = 125
local buttonY = -20
local textY = buttonY + 65
local buttonOG = 1.1

local LevelPropertiesReturnButton = CreatePushButton("LevelPropertiesReturnButton", [[GUI\generic_dialogs\back.anim]], { -320, -150 }, buttonOG)

local LevelPropertiesBackgroundButton = CreatePushButton("LevelPropertiesBackgroundButton", [[GUI/editor/background.anim]], { -buttonSpread, buttonY }, buttonOG)
LevelPropertiesBackgroundButton.anim_ext.additional_scale = buttonOG

local LevelPropertiesBackgroundText = CreateStaticText("LevelPropertiesBackgroundText", "$00269", { -buttonSpread, textY }, "label", "centre centy")
LevelPropertiesBackgroundText.text_ext.colour = WHITE

local LevelPropertiesAmbientButton = CreatePushButton("LevelPropertiesAmbientButton", [[GUI/editor/ambient.anim]], { buttonSpread, buttonY }, buttonOG)
LevelPropertiesAmbientButton.anim_ext.additional_scale = buttonOG

local LevelPropertiesAmbientText = CreateStaticText("LevelPropertiesAmbientText", "$00270", { buttonSpread, textY }, "label", "centre centy")
LevelPropertiesAmbientText.text_ext.colour = WHITE

local LevelPropertiesDialog = CreateModalDialog("LevelPropertiesDialog",
{
	LevelPropertiesTitle,
	LevelPropertiesBackgroundButton,
	LevelPropertiesBackgroundText,
	LevelPropertiesAmbientButton,
	LevelPropertiesAmbientText,
	LevelPropertiesReturnButton,
},
[[GUI\game_dialogs\generic_dialog_wide.anim]], { SCREEN_WIDTH / 2, 320 })
LevelPropertiesDialog.modal_ext.fade_colour = { r = 0, g = 0, b = 0, alpha = 100 }

--------------------------------------------------------
-- Background/Foreground/Ambient Image Dialog
--------------------------------------------------------

local dialogX = SCREEN_WIDTH / 2
local dialogY = 370
local listboxWidth = 400
local listboxHeight = 388
local scrollerWidth = 20
local scrollerHeight = 300
local scrollerX = listboxWidth / 2 - 55
local scrollerY = -30
local listboxX = 0
local listboxY = scrollerY - listboxHeight / 2

local ImageSelectScroller = CreateScrollerButton("ImageSelectScroller", [[GUI\buttons\scrollbar_dot.anim]])
ImageSelectScroller.anim_ext.facing = { 0, 1 }
local ImageSelectScrollbar = CreateScrollBar("ImageSelectScrollbar", nil, nil, ImageSelectScroller, { scrollerX - listboxX, scrollerY - listboxY - scrollerHeight / 2 })
ImageSelectScrollbar.width = scrollerWidth
ImageSelectScrollbar.height = scrollerHeight
ImageSelectScrollbar.scrollbar_ext.start_point = { 0, 0 }
ImageSelectScrollbar.scrollbar_ext.end_point = { 0, 1 }
ImageSelectScrollbar.scrollbar_ext.is_modal = false
ImageSelectScrollbar.scrollbar_ext.scroller_offset = { 0, 0 }

local ImageSelectListBox = CreateListBox("ImageSelectListBox", listboxWidth, listboxHeight, ImageSelectScrollbar, { listboxX, listboxY })
ImageSelectListBox.listbox_ext.horizontal = false
ImageSelectListBox.listbox_ext.page_align_always = false
ImageSelectListBox.listbox_ext.item_repeat_offset = 8
ImageSelectListBox.listbox_ext.item_offset = { 0, 4 }
ImageSelectListBox.listbox_ext.font = "label"
ImageSelectListBox.listbox_ext.hover_colour = { r = 180, g = 180, b = 180, alpha = 255 }

AddListBoxMask(ImageSelectListBox, CreateImage("ImageSelectListBoxMaskTop", [[GUI\editor\list_mask_top.anim]], { -listboxX, -listboxY }))
AddListBoxMask(ImageSelectListBox, CreateImage("ImageSelectListBoxMaskBottom", [[GUI\editor\list_mask_bottom.anim]], { -listboxX, -listboxY }))

--Platform dependent overrides
if GetVersion() == "IOS" then
	ImageSelectScrollbar.scrollbar_ext.force_hidden = true
	--Expand list box hit region to dialog window only for capturing drag
	ImageSelectListBox.hit_top_left = { -listboxWidth / 2, 0 }
	ImageSelectListBox.hit_bottom_right = { listboxWidth / 2, listboxHeight }
else
	--Expand list box hit region to full screen for capturing drag and mouse wheel
	ImageSelectListBox.hit_top_left = { -listboxX - dialogX, -listboxY - dialogY }
	ImageSelectListBox.hit_bottom_right = { SCREEN_WIDTH - listboxX - dialogX, SCREEN_HEIGHT - listboxY - dialogY }
end

local buttonSpread = 110
local buttonOG = 1.1
local buttonScale = 0.8

local AcceptImageSelectButton = CreatePushButton("AcceptImageSelectButton", [[GUI\generic_dialogs\generic_textbutton.anim]], { -buttonSpread, 215 }, buttonOG)
AcceptImageSelectButton.button_ext.additional_scale = buttonScale
SetButtonText(AcceptImageSelectButton, "$00408")

local CancelImageSelectButton = CreatePushButton("CancelImageSelectButton", [[GUI\generic_dialogs\generic_textbutton.anim]], { buttonSpread, 215 }, buttonOG)
CancelImageSelectButton.button_ext.additional_scale = buttonScale
SetButtonText(CancelImageSelectButton, "$00409")

local ImageSelectDialog = CreateModalDialog("ImageSelectDialog",
{
	AcceptImageSelectButton,
	CancelImageSelectButton,
	ImageSelectListBox,
},
[[GUI\generic_dialogs\generic_dialog_tall.anim]], { dialogX, dialogY })
ImageSelectDialog.modal_ext.fade_colour = { r = 0, g = 0, b = 0, alpha = 100 }

if GetVersion() ~= "IOS" then
	local ScrollbarImage = CreateImage("ImageSelectScrollbarImage", [[GUI\buttons\scrollbar_600.anim]], { scrollerX, scrollerY })
	ScrollbarImage.anim_ext.facing = { 0, 1 }
	table.insert(ImageSelectDialog.parent_ext.children, ScrollbarImage)
end

--------------------------------------------------------
-- Platform Image Dialog
--------------------------------------------------------

--Global
PlatformPropertiesTabSpacing = 10
PlatformPropertiesTabScale = 0.7
PlatformPropertiesTabSelectedScale = 1

--Radio buttons will be spread out and scaled automatically by the dialog class
local PlatformPropertiesHubRadioGroup = CreateRadioGroup("PlatformPropertiesHubRadioGroup",
{
	CreatePushButton("PlatformPropertiesHubTabButton1", [[GUI\editor\tab1.anim]]),
	CreatePushButton("PlatformPropertiesHubTabButton2", [[GUI\editor\tab2.anim]]),
	CreatePushButton("PlatformPropertiesHubTabButton3", [[GUI\editor\tab3.anim]]),
	CreatePushButton("PlatformPropertiesHubTabButton4", [[GUI\editor\tab4.anim]]),
},
{ 145 - SCREEN_WIDTH / 2, -260 })
PlatformPropertiesHubRadioGroup.width = 1
PlatformPropertiesHubRadioGroup.height = 1

local PlatformPropertiesCancelButton = CreatePushButton("PlatformPropertiesCancelButton", [[GUI\generic_dialogs\back.anim]], { -440, -365 }, 1.1)

--Scroller
local listboxWidth = SCREEN_WIDTH
local listboxHeight = 570
local listboxX = -listboxWidth / 2
local listboxY = -10
local scrollerWidth = 618
local scrollerHeight = 20
local scrollerX = 0
local scrollerY = listboxHeight / 2 - 35

--Scrollbar button position and range.
local PlatformPropertiesScrollerButton = CreateScrollerButton("PlatformPropertiesScrollerButton", [[GUI\buttons\scrollbar_dot.anim]])
local PlatformPropertiesScrollbar = CreateScrollBar("PlatformPropertiesScrollbar", nil, nil, PlatformPropertiesScrollerButton, { scrollerX - listboxX - scrollerWidth / 2, scrollerY - listboxY })
PlatformPropertiesScrollbar.width = scrollerWidth
PlatformPropertiesScrollbar.height = scrollerHeight
PlatformPropertiesScrollbar.scrollbar_ext.start_point = { 0, 0 }
PlatformPropertiesScrollbar.scrollbar_ext.end_point = { 1, 0 }
PlatformPropertiesScrollbar.scrollbar_ext.is_modal = false
PlatformPropertiesScrollbar.scrollbar_ext.scroller_offset = { 0, 0 }

--List Box of items with scrollbar button attached
local PlatformPropertiesListBox = CreateListBox("PlatformPropertiesListBox", listboxWidth, listboxHeight, PlatformPropertiesScrollbar, { listboxX, listboxY })
PlatformPropertiesListBox.listbox_ext.horizontal = true

--Expand list box hit region to full panel for capturing drag and mouse wheel
PlatformPropertiesListBox.hit_top_left = { -SCREEN_WIDTH / 2 - listboxX, -listboxHeight / 2 - listboxY }
PlatformPropertiesListBox.hit_bottom_right = { SCREEN_WIDTH / 2 - listboxX, listboxHeight / 2 - listboxY }

--Platform dependent overrides
local PlatformPropertiesScrollbarImage = nil
if GetVersion() == "IOS" then
	PlatformPropertiesScrollbar.scrollbar_ext.pip_anim = [[GUI\buttons\scrollbar_notch.anim]]
	PlatformPropertiesScrollbar.scrollbar_ext.pip_spacing = 40
	PlatformPropertiesScrollbar.scrollbar_ext.force_hidden = true
else
	PlatformPropertiesScrollbarImage = CreateImage("PlatformPropertiesScrollbarImage", [[GUI\buttons\scrollbar.anim]], { scrollerX, scrollerY })
	PlatformPropertiesListBox.listbox_ext.snap_back = false
end

--Load pre-arranged platform map items
tconcat(PlatformPropertiesListBox.parent_ext.children, PlatformMapPages)

local PlatformPropertiesDialog = CreateModalDialog("PlatformPropertiesDialog", 
{
	PlatformPropertiesHubRadioGroup,
	PlatformPropertiesCancelButton,
	PlatformPropertiesListBox,
	PlatformPropertiesScrollbarImage,
},
[[GUI\game_dialogs\generic_panel_wide.anim]], { SCREEN_WIDTH / 2, 440 })
PlatformPropertiesDialog.modal_ext.fade_colour = { r = 0, g = 0, b = 0, alpha = 150 }

--------------------------------------------------------
-- Level Editor Help Box
--------------------------------------------------------

local buttonOG = 1.1

local LevelEditorHelpTitle = CreateStaticText("HeaderText", "$01901", { 0, -222 }, "header", "centre")
LevelEditorHelpTitle.width = 400
LevelEditorHelpTitle.height = 30
LevelEditorHelpTitle.text_ext.colour = WHITE
LevelEditorHelpTitle.text_ext.hover_colour = WHITE

local textWidth = 640

local LevelEditorHelpText2 = CreateStaticText("LevelEditorHelpText2", "$01902", { -textWidth / 2, -122 }, "unicode")
LevelEditorHelpText2.width = textWidth
LevelEditorHelpText2.height = 70;
LevelEditorHelpText2.text_ext.colour = WHITE
LevelEditorHelpText2.text_ext.autowrap = true

local LevelEditorHelpText3 = CreateStaticText("LevelEditorHelpText3", "$01903", { -textWidth / 2, LevelEditorHelpText2.position[2] + LevelEditorHelpText2.height }, "unicode")
LevelEditorHelpText3.width = textWidth
LevelEditorHelpText3.height = 50;
LevelEditorHelpText3.text_ext.colour = WHITE
LevelEditorHelpText3.text_ext.autowrap = true

textWidth = 560

local LevelEditorHelpText4 = CreateStaticText("LevelEditorHelpText4", "$01904", { 20 - textWidth / 2, LevelEditorHelpText3.position[2] + LevelEditorHelpText3.height }, "unicode")
LevelEditorHelpText4.width = textWidth
LevelEditorHelpText4.height = 70;
LevelEditorHelpText4.text_ext.colour = WHITE
LevelEditorHelpText4.text_ext.autowrap = true

local LevelEditorHelpText5 = CreateStaticText("LevelEditorHelpText5", "$01905", { 20 - textWidth / 2, LevelEditorHelpText4.position[2] + LevelEditorHelpText4.height }, "unicode")
LevelEditorHelpText5.width = textWidth
LevelEditorHelpText5.height = 70;
LevelEditorHelpText5.text_ext.colour = WHITE
LevelEditorHelpText5.text_ext.autowrap = true

local LevelEditorHelpText6 = CreateStaticText("LevelEditorHelpText6", "$01906", { 20 - textWidth / 2, LevelEditorHelpText5.position[2] + LevelEditorHelpText5.height }, "unicode")
LevelEditorHelpText6.width = textWidth
LevelEditorHelpText6.height = 70;
LevelEditorHelpText6.text_ext.colour = WHITE
LevelEditorHelpText6.text_ext.autowrap = true

local LevelEditorHelpBoxCloseButton = CreatePushButton("LevelEditorHelpBoxCloseButton", [[GUI\generic_dialogs\generic_textbutton.anim]], { 0, 245 }, buttonOG)
SetButtonText(LevelEditorHelpBoxCloseButton, "$00408")

--icons
local iconOffsetX = -40
local iconOffsetY = 22

local LevelEditorHelpUnlockButton = CreateImage("LevelEditorHelpUnlockButton", [[GUI/in_game/radial_unlock.anim]], { LevelEditorHelpText4.position[1] + iconOffsetX, LevelEditorHelpText4.position[2] + iconOffsetY })
LevelEditorHelpUnlockButton.anim_ext.additional_scale = 0.85

local LevelEditorHelpHintButton = CreateImage("LevelEditorHelpHintButton", [[GUI/in_game/radial_hint.anim]], { LevelEditorHelpText5.position[1] + iconOffsetX, LevelEditorHelpText5.position[2] + iconOffsetY })
LevelEditorHelpHintButton.anim_ext.additional_scale = 0.85

local LevelEditorHelpBoxTestMode = CreateImage("LevelEditorHelpBoxTestMode", [[GUI/editor/button_test.anim]], { LevelEditorHelpText6.position[1] + iconOffsetX, LevelEditorHelpText6.position[2] + iconOffsetY })
LevelEditorHelpBoxTestMode.anim_ext.additional_scale = 0.64

local LevelEditorHelpBox = CreateModalDialog("LevelEditorHelpBox",
{
	LevelEditorHelpTitle,
	LevelEditorHelpText2,
	LevelEditorHelpText3,
	LevelEditorHelpText4,
	LevelEditorHelpText5,
	LevelEditorHelpText6,
	LevelEditorHelpBoxCloseButton,
	LevelEditorHelpBoxTestMode,
	LevelEditorHelpUnlockButton,
	LevelEditorHelpHintButton,
},
[[GUI\generic_dialogs\generic_dialog_large.anim]], { 512, 344 })
LevelEditorHelpBox.modal_ext.fade_colour = { r = 0, g = 0, b = 0, alpha = 100 }

------------------------------------------------------
-- Widgets
--------------------------------------------------------

widgets =
{
	-- Hud
	RadialMenu,
	CreatorButtonsGroup,
	EditorButtonsGroup,
	BottomGroup,
	CollectiblesGroup,
	
	-- Menu
	MenuButtonBadge,
	MenuButton,
	GameMenuDialog,
	OptionsDialog,
	CreditsDialog,

	-- Gameplay dialogs
	MessageBox,
	WinDialog,
	EetsDeadDialog,
	
	-- Editor dialogs
	LevelEditorHelpBox,
	LevelPropertiesDialog,
	ImageSelectDialog,
	PlatformPropertiesDialog,
}

if GetVersion() ~= "IOS" then
	table.insert(widgets, ItemTooltipContainer)
end