

if wnd == nil then
    wmd = {}
end
if wmd.txlib == nil then
    wmd.txlib = {}
end
wmd.txlib.hud_toggle_on = gr.loadTexture('hudtoggle_on')
wmd.txlib.hud_toggle_off = gr.loadTexture('hudtoggle_off')

function WarmachineHudToggleDraw()
    if hu.HUDDrawn and (not hu.HUDDisabledExceptMessages)
            and not (RadarIcon == nil) then
        local c={}
        local r,g,b,a = hu.getHUDGaugeColorInMission(0)
        gr.setColor(r,g,b,a)
        local x1 = (1500/2560) * gr.getScreenWidth()
        local y1 = (1260/1440) * gr.getScreenHeight()
        local x2 = x1+128+32
        local y2 = y1+32+8
        WarmachineHudToggleLabel()

        if RadarIcon.Enabled then
            gr.drawImage(wmd.txlib.hud_toggle_on,
                x1,y1,x2,y2,
                0,0,1,1,1,true)
        else
            gr.drawImage(wmd.txlib.hud_toggle_off,
                x1,y1,x2,y2,
                0,0,1,1,1,true)
        end
    end
end

function WarmachineHudToggleLabel()
    local c={}
    local r,g,b,a = hu.getHUDGaugeColorInMission(0)
    gr.setColor(r,g,b,a)     
    local x1 = (1500/2560) * gr.getScreenWidth()
    local y1 = ((1260-(32+8))/1440) * gr.getScreenHeight()
    local x2 = x1+128+32
    local y2 = y1+32+8
    text = ba.replaceTokens("$ALT+Z$")
    gr.drawString(text,x1,y1,x2,y2)
end



function WarmachineHudToggleToggle(hv)
    keytext = ba.replaceTokens("$ALT+Z$")
    if hv.Key == keytext then
        if RadarIcon.Enabled then
            RadarIcon:Disable()
        elseif not RadarIcon.Enabled then
            RadarIcon.Teams["Friendly"] = true
            RadarIcon.Teams["Hostile"] = true
            RadarIcon.Teams["Neutral"] = true
            RadarIcon.Teams["Traitor"] = true
            RadarIcon.Teams["Unknown"] = true
            RadarIcon.Enabled = true
            RadarIcon:LoadShips()
        end
    end
end