-- Advanced  Tools for Mission Editor

local thisModule



local F10DisplayCommand
F10DisplayCommand = function(args)      
    local player = args[1]
    
    local text = "Azimuth : " .. player:getAzimuth()
    text = text .. " - Alt MSL : " .. player:getMSLAltitude()

    if player:inAir() == true then
        player:display("In Air : " .. text, 5)
    else
        player:display("On floor : " .. text, 5)
    end
end

local F10DisplayNameCommand
F10DisplayNameCommand = function(args)      
    local player = args[1]
    
    player:display("Unit player name : " .. player:getName(), 5)
end

local F10DisplayPositionCommand
F10DisplayPositionCommand = function(args)      
    local player = args[1]
    
    local position = player:getPosition()
    local lat, lon, alt = ATME.convertPointToLL(position)
    
    local dirlat, dlat, mlat, slat  = ATME.convertToDMS(lat, false)
    local dirlon, dlon, mlon, slon  = ATME.convertToDMS(lon, false)
    
    local westEast = "E"
    if dirlat == -1 then
        westEast = "W"
    end
    
    local northSouth = "N"
    if dirlon == -1 then
        northSouth = "S"
    end
    
    local text = string.format("Lat : %s%d°%d'%d\"\n", westEast, dlat, mlat, slat)
    text = text .. string.format("Lon : %s%d°%d'%d\"\n", northSouth, dlon, mlon, slon)
    
    player:display(text, 5)
end

local function onCreatePlayer(player)
    player:display("Welcome in " .. ATME.getTheatre() .. " ... " .. player:getPseudo(), 10)
    
    local menu = player:getF10MenuRoot()
    menu:append(1, "Display informations", F10DisplayCommand , {player})
    menu:append(1, "Display unit player name", F10DisplayNameCommand , {player})
    
    if player:inAir() == false then
        menu:append(2, "Display position", F10DisplayPositionCommand , {player})
    end
end

local function onTakeOffPlayer(player)
    local menu = player:getF10MenuRoot()

    menu:remove(2)
end

local function onLandingPlayer(player)
    local menu = player:getF10MenuRoot()

    menu:append(2, "Display position", F10DisplayPositionCommand , {player})
end

-- MAIN
do
    local newHandlers = {
        onCreatePlayerHandler = onCreatePlayer,
        onDeletePlayerHandler = nil,
        onUpdatePlayerHandler = nil,
        onTakeoffPlayerHandler = onTakeOffPlayer,
        onLandingPlayerHandler = onLandingPlayer,
        onStartEnginePlayerHandler = nil,
        onStopEnginePlayerHandler = nil,
        
        onCreateAIUnitHandler = nil,
        onDeleteAIUnitHandler = nil,
        onDisableAIUnitHandler = nil,
        onTakeoffAIUnitHandler = nil,
        onLandingAIUnitHandler = nil,
        onStartEngineAIUnitHandler = nil,
        onStopEngineAIUnitHandler = nil,
        
        onCreateGroupHandler = nil,
        onDeleteGroupHandler = nil,
        onDisableGroupHandler = nil,
        
        onCreateStaticObjectHandler = nil,
        onDeleteStaticObjectHandler = nil,
    
        onTimerHandler = nil,
        onModuleStartHandler = nil,
    }
        
    thisModule = ATME.C_Module("Module1", newHandlers, true)
end
