#include "umf.lua"
local function bool(id, invert)
    id = "savegame.mod." .. id
    invert = not invert
    return function() return GetBool(id) == invert end
end

local warningtext = OptionsMenu.Text ( "Legacy flight is unsupported and will have more bugs.", { condition = bool("legacy"), align = "center top", pad_bottom = 10, pad_top = 10 } )
OptionsMenu {
    title = "Precision Flight",

    OptionsMenu.Spacer(50),

    OptionsMenu.Toggle {id = "legacy", name = "Legacy Flight", default = false},
	function()
		UiPush()
			UiColor(1, 0.3, 0.25, 1)
			local w, h = warningtext()
			if w > 0 then
				UiTranslate( 0, -2 )
				UiRectOutline(w + 10, math.floor(h - 15), 2)
			end
		UiPop()
		return w, h
	end,
    OptionsMenu.Toggle {
        id = "hybrid",
        name = "Hybrid Noclip",
        default = true,
        condition = bool("legacy")
    },
    OptionsMenu.Toggle {
        id = "noslowmo",
        name = "Ignore Slow-Mo",
        default = false,
        condition = bool("legacy", true)
    },
    OptionsMenu.Toggle {
        id = "clip",
        name = "Player Collision",
        default = false,
        condition = bool("legacy", true)
    },

    OptionsMenu.Spacer(50),

	OptionsMenu.Group {
		title = "Keybinds",

		OptionsMenu.Keybind { id = "key.fly", name = "Toggle Flight", default = "v" },
		OptionsMenu.Keybind { id = "key.forward", name = "Forward", default = "up" },
		OptionsMenu.Keybind { id = "key.backward", name = "Backward", default = "down" },
		OptionsMenu.Keybind { id = "key.left", name = "Left", default = "left" },
		OptionsMenu.Keybind { id = "key.right", name = "Right", default = "right" },
		OptionsMenu.Keybind { id = "key.up", name = "Up", default = "space" },
		OptionsMenu.Keybind { id = "key.down", name = "Down" },
		OptionsMenu.Keybind { id = "key.slow", name = "Slow Down", default = "ctrl" },
		OptionsMenu.Keybind { id = "key.fast", name = "Speed Up", default = "shift" },
	}
}

--[[function draw()
	UiFont( "regular.ttf", 26 )
	UiTranslate( UiCenter(), UiMiddle() )
	UiAlign( "center middle" )
	UiWindow( 600, 232 )
	UiAlign( "top left" )
	UiColor( .1, .1, .1, 0.6 )
	UiImageBox( "ui/common/box-solid-shadow-50.png", 600, 232, -50, -50 )

	UiColor( 1, 1, 1 )
	UiTranslate( 290, 80 )
	UiAlign( "right" )
	if SetCameraFov then
		UiPush()
		UiText( "Legacy Flight" )
		UiTranslate( 20, 0 )
		UiAlign( "left" )
		UiColor( 1, 1, 0.7 )
		local val = GetInt( "savegame.mod.legacy" )
		if val == 0 then
			if UiTextButton( "Disabled" ) then
				SetInt( "savegame.mod.legacy", 1 )
			end
		else
			if UiTextButton( "Enabled" ) then
				SetInt( "savegame.mod.legacy", 0 )
			end
		end
		UiPop()
		UiTranslate( 0, 32 )
	end
	if not SetCameraFov or GetInt( "savegame.mod.legacy" ) == 1 then
		UiPush()
		UiText( "Hybrid Noclip" )
		UiTranslate( 20, 0 )
		UiAlign( "left" )
		UiColor( 1, 1, 0.7 )
		local val = GetInt( "savegame.mod.hybrid" )
		if val == 1 then
			if UiTextButton( "Disabled" ) then
				SetInt( "savegame.mod.hybrid", 0 )
			end
		else
			if UiTextButton( "Enabled" ) then
				SetInt( "savegame.mod.hybrid", 1 )
			end
		end
		UiPop()
	else
		UiPush()
		UiText( "Ignore Slow-Mo" )
		UiTranslate( 20, 0 )
		UiAlign( "left" )
		UiColor( 1, 1, 0.7 )
		local val = GetInt( "savegame.mod.noslowmo" )
		if val == 0 then
			if UiTextButton( "Disabled" ) then
				SetInt( "savegame.mod.noslowmo", 1 )
			end
		else
			if UiTextButton( "Enabled" ) then
				SetInt( "savegame.mod.noslowmo", 0 )
			end
		end
		UiPop()
	end
	UiTranslate( 10, 80 )
	UiAlign( "center" )
	if UiTextButton( "Close" ) then
		Menu()
	end

end]]

