////  Main > Editing  ////

newmenu editing
menuinit [ if (! $editing) [menuheader "" "\f3You are not in edit mode"] [menuheader] ]
menuitem "Mapmodels\i\3"                 [ showmenu Mapmodels ]
menuitem "Lighting\i\3"                  [ showmenu Lighting ]
menuitem "Entities\i\3"                  [ showmenu Entities ]
menuitem "Pickups\i\3"                   [ showmenu Pickups ]
menuitem "Textures\i\3"                  [ showmenu Textures ]
menuitem "Skymaps\i\3"                   [ showmenu Skymaps ]
menuitem "Ambient sounds\i\3"            [ showmenu [Ambient sounds] ]
menuitem "Arches, slopes and stairs\i\3" [ showmenu Arches ]
menuitem "Map operations\i\3"            [ showmenu [Map operations] ]
menuitem "Map settings\i\3"              [ showmenu [Map settings] ]
menuitem "Map config operations\i\3"     [ showmenu [Map config operations] ]
menuitem "Map checks and statistics\i\3" [ showmenu [Map checks and statistics] ]
menuitem "Bots\i\3"                      [ showmenu [Creating bot waypoints] ]
menuitem "Settings\i\3"                  [ showmenu [Editing settings] ]
menuitem "Misc\i\3"                      [ showmenu [Editing misc] ]
menuitem "Keys\i\3"                      [ showmenu [Editing keys] ]
menuitem "Deleted entities"              [ showmenu "Deleted entities" ]
menuitem "Help?" [ echo "\f2Please read the AssaultCube README which has a detailed guide on mapediting..." ]

////  Main > Editing > Mapmodels  ////

newmenu Mapmodels
menuinit __rebuildmapmodelmenus

tempalias __mapmodelcategories [
    platforms "Platforms"
    ladders "Ladders+Stairs"
    stairs "Ladders+Stairs"
    fencing "Fencing"
    plants "Plants"
    lamps "Lights+Lamps"
    street "Street"
    pipes "Pipes"
    office "Office"
    computers "Computers"
    home "Home"
    industrial "Industrial"
    military "Military"
    signs "Signs"
    litter "Other/Litter"
    misc "Other/Misc"
    unsoo "Unsorted/Official"
    unsoa "Unsorted/Akimbo"
    unsom "Unsorted/Map-Config"
    unsorted "Unsorted/Custom"
]

looplist $__mapmodelcategories [key menu] [tempalias (concatword __mm_key_ $key) $menu]

tempalias __menuitem_offlineeditonly [ menuitem "menu only available in offline edit mode" -1 ]
tempalias __mm_showmodel [concat alias __lastwatchedmapmodel $arg2 ";" menumdl (escape $arg1) (concatword mapmodels/ $arg2) all 40 3]
tempalias __mm_showmodel2 [concat menumdl (escape $arg1) (concatword mapmodels/ $arg2) all 40 3]
tempalias __mm_tempmenus ""

tempalias __rebuildmapmodelmenus [
    if $mapmodelchanged [
        push __mm_menus ""  // menus with content
        push __mm_done ""   // done map config slots
        push idxs ""
        push mpath ""
        looplist $__mapmodelcategories [key menu] [delmenu $menu]
        looplist (listallmapmodelattributes explodekeywords sortby: keywords sortby: desc usage defaults distribution) [path keyword desc usage dflts dist] [
            mpath = (concatword "mapmodels/" $path)
            dflts = (concat $dflts "0 0 0 0")
            dflts = (concat (at $dflts 0) (at $dflts 1) (at $dflts 2) (at $dflts 3))  // fix missing/incomplete default slot parameters
            idxs = (mapmodelslotbyname $mpath)
            if (|| (! (strlen $keyword)) (< (findlist $__mapmodelcategories $keyword) 0)) [
                keyword = unsorted
                if (strcmp $dist "official") [ keyword = unsoo ]       // unless someone writes the missing config files ;)
                if (strcmp $dist "autodownload") [ keyword = unsoa ]   // a.k.a "akimbo"
                if (strcmp $dist "akimbo") [ keyword = unsoa ]
                if (listlen $idxs) [ keyword = unsom ]                 // has slot in current map config
            ]
            keyword = (concatword __mm_key_ $keyword)
            newmenu $$keyword
            menurenderoffset -40 0
            concatuniq __mm_menus $$keyword
            if (strlen $desc) [] [desc = $mpath]
            if (listlen $idxs) [
                __mm_done = (concat $__mm_done $idxs)
                if (> (listlen $idxs) 1) [
                    looplist $idxs i [menuitem (concat $desc (concatword "#" $i)) (concat newent mapmodel $i) (__mm_showmodel $$keyword $path) $usage]  // several slots for the same mapmodel
                ][
                    menuitem $desc (concat newent mapmodel $idxs) (__mm_showmodel $$keyword $path) $usage // usual case: one slot per model
                ]
            ][
                menuitem (concatword "\f4" $desc) (concat newent mapmodel "(mapmodel" $dflts $path ") ; __enableautomapconfig") (__mm_showmodel $$keyword $path) $usage  // mapmodel has no slot assigned: assign one
            ]
        ]
        // add menus sorted by author and distribution
        push amenu ""
        push distmenus ""
        looplist $__mm_tempmenus menu [delmenu $menu]
        __mm_tempmenus = ""
        looplist (listallmapmodelattributes sortby: author desc usage defaults distribution) [path author desc usage dflts dist] [
            mpath = (concatword "mapmodels/" $path)
            dflts = (concat $dflts "0 0 0 0")
            dflts = (concat (at $dflts 0) (at $dflts 1) (at $dflts 2) (at $dflts 3))  // fix missing/incomplete default slot parameters
            if (strlen $author) [] [author = "*unknown*"]
            idxs = (mapmodelslotbyname $mpath)
            amenu = (concat "Map models by" $author)
            newmenu $amenu // menu sorted by author
            concatuniq __mm_tempmenus $amenu
            menurenderoffset -40 0
            if (listlen $idxs) [
                if (> (listlen $idxs) 1) [
                    looplist $idxs i [menuitem (concat $path (concatword "#" $i)) (concat newent mapmodel $i) (__mm_showmodel $amenu $path) $desc]  // several slots for the same mapmodel
                ][
                    menuitem $path (concat newent mapmodel $idxs) (__mm_showmodel $amenu $path) $desc // usual case: one slot per model
                ]
            ][
                menuitem (concatword "\f4" $path) (concat newent mapmodel "(mapmodel" $dflts $path ")") (__mm_showmodel $amenu $path) $desc  // mapmodel has no slot assigned: assign one
            ]
            if (strlen $dist) [] [dist = "*unknown*"]
            amenu = (concat "Map models of origin:" $dist)
            newmenu $amenu // menu sorted by distribution
            concatuniq distmenus $amenu
            menurenderoffset -40 0
            if (listlen $idxs) [
                if (> (listlen $idxs) 1) [
                    looplist $idxs i [menuitem (concat $path (concatword "#" $i)) (concat newent mapmodel $i) (__mm_showmodel $amenu $path) $desc]  // several slots for the same mapmodel
                ][
                    menuitem $path (concat newent mapmodel $idxs) (__mm_showmodel $amenu $path) $desc // usual case: one slot per model
                ]
            ][
                menuitem (concatword "\f4" $path) (concat newent mapmodel "(mapmodel" $dflts $path ")") (__mm_showmodel $amenu $path) $desc  // mapmodel has no slot assigned: assign one
            ]
        ]
        amenu = "Browse all map models"
        delmenu $amenu
        newmenu $amenu
        looplist $__mm_tempmenus m [menuitem $m (concat showmenu (escape $m))]
        menuitem "" -1
        looplist $distmenus m [menuitem $m (concat showmenu (escape $m))]
        __mm_tempmenus = (concat $__mm_tempmenus $distmenus)
        delmenu Mapmodels
        newmenu Mapmodels
        push __mm_sorted ""
        looplist $__mapmodelcategories [key menu] [if (>= (findlist $__mm_menus $menu) 0) [concatuniq __mm_sorted $menu]]  // create list of non-empty menus in order of list above
        looplist $__mm_sorted m [menuitem $m (concat showmenu $m)]   // only create non-empty menus
        if (strlen $__mm_tempmenus) [menuitem "" -1 ; menuitem $amenu (concat showmenu (escape $amenu))]
        delmenu [Delete unused mapmodel slot]
        delmenu [Edit mapmodel slots]
        if $editing_sp [
            newmenu [Delete unused mapmodel slot]
            loop i 256 [
                mpath = (mapmodelslotname $i)
                if (strlen $mpath) [
                    if (strcmp "" (mapmodelslotusage $i)) [
                        menuitem (concatword "delete slot #" $i ": " (editmapmodelslot $i)) (concat deletemapmodelslot $i) (__mm_showmodel [Delete unused mapmodel slot] $mpath)
                    ]
                ]
            ]
            newmenu [Edit mapmodel slots]
            menurenderoffset -40 0
            push origin ""
            loop i 256 [
                mpath = (mapmodelslotname $i)
                if (strlen $mpath) [
                    if $__showorigin [
                        origin = (getmapmodelattributes $mpath distribution)
                        if (! (strlen $origin)) [ origin = "custom/unsorted" ]
                        origin = (__colororigin $origin)
                    ]
                    menuitem (concatword "edit slot #" $i ": " (editmapmodelslot $i) $origin) (concat alias __mmslot $i ";" showmenu (escape "Edit mapmodel slot")) (__mm_showmodel2 [Edit mapmodel slots] $mpath)
                ] [
                  if (strlen (mapmodelslotusage $i)) [
                    menuitem (concatword "unassigned slot #" $i) (concat alias __mmslot $i ";" showmenu (escape "Edit mapmodel slot")) [menumdl [Edit mapmodel slots] ""]
                  ]
                ]
            ]
            pop origin
            mapmodelchanged 0
        ] [
            newmenu [Delete unused mapmodel slot]
            __menuitem_offlineeditonly // "menu only available in offline edit mode"
            newmenu [Edit mapmodel slots]
            __menuitem_offlineeditonly // "menu only available in offline edit mode"
        ]
        pop __mm_menus __mm_sorted __mm_done idxs mpath amenu distmenus
    ]
]


////  Main > Editing > Lighting  ////

newmenu Lighting
menuitem "Add white lights "    [ showmenu [White light] ]
menuitem "Add coloured lights " [ showmenu [Coloured light] ]
menuitem "" -1
menuitemcheckbox "Enable fullbright: " "$fullbright" [ fullbright $arg1 ]

////  Main > Editing > Lighting > White light  ////

newmenu [White light]
__wlight = 1; __wlight1 = 1
menuitemslider "Light radius: " 1 32 "$__wlight" 1 [ __wlight = $arg1 ] 1
menuitemslider "Brightness: " 1 255 "$__wlight1" 5 [ __wlight1 = $arg1 ] 1
menuitem "" -1
menuitem "\f2\t    [ OK ]\t\t" [ newent light $__wlight $__wlight1 ]

////  Main > Editing > Lighting > Coloured light  ////

newmenu [Coloured light]
__clight = 1; __clight1 = 1; __clight2 = 1; __clight3 = 1
menuitemslider "Light radius: " 1 32 "$__clight"  1 [ __clight = $arg1 ] 1
menuitem "" -1
menuitemslider "Red light: "   1 255 "$__clight1" 5 [ __clight1 = $arg1 ] 1
menuitemslider "Green light: " 1 255 "$__clight2" 5 [ __clight2 = $arg1 ] 1
menuitemslider "Blue light: "  1 255 "$__clight3" 5 [ __clight3 = $arg1 ] 1
menuitem "" -1
menuitem "\f2\t\t    [ OK ]" [ newent light $__clight $__clight1 $__clight2 $__clight3 ]


////  Main > Editing > Entities  ////

newmenu Entities
menuinit [
    resetcurmenu
    if $editing [
        menuitem "Place RVSF spawn point" [ newent playerstart 1 ]
        menuitem "Place CLA spawn point"  [ newent playerstart 0 ]
        menuitem "Place FFA spawn point"  [ newent playerstart 100 ]
        menuitemcheckbox  "Show all spawn points: " "$showplayerstarts" [ showplayerstarts $arg1 ]
        menuitem "" -1
        menuitem "Place RVSF CTF Flag"    [ newent ctf-flag 1 ]
        menuitem "Place CLA CTF Flag"     [ newent ctf-flag 0 ]
        menuitem "" -1
        menuitem "Place ladder entity"    "saycommand /newent ladder " [] "\f4The ladder entity lets players climb.\nPlease also place a ladder mapmodel.\n(found in the mapmodels menu)\i\3"
        menuitem "Place clip entity\i\3"  [ showmenu Clips ]
        menuitem "" -1
        push n (format2 "%1 %5 %6 %7 %8 %9 %010 %011" (editentity (getclosestent)))
        push d (switch (findlist "mapmodel sound" (at $n 0)) [mapmodelslotname (at $n 2)] [at (editmapsoundslot (at $n 1)) 0])
        menuitem "Copy closest entity" copyent [] (format "\fs\f4current closest entity:\n\fr%1\f4\n%2" (pop n) (pop d))
        menuitem "Paste entity\i\3" [ showmenu [Paste entity] ]
        menuitem "Paste last copied entity" pasteent
        menuitem "" -1
        menuitem "Show list of TODO entities\i\3"       [ showmenu "TODO entities" ]
        menuitem "Show list of deleted entities\i\3"    [ showmenu "Deleted entities" ]
    ][
        menuitem "menu only available in edit mode" -1
    ]
]
tempalias __resetpickedents [ delmenu [Paste entity]; newmenu [Paste entity]; menuitem "\f7[Clear the list of copied entities from this menu]" __resetpickedents ; menuitem "" -1 ]
__resetpickedents

////  Main > Editing > Entities > Clips  ////

newmenu Clips
alias _clip01 0 ; alias _clip02 1 ; alias _clip03 1 ; alias _clip04 1 ; alias _clip05 0 ; alias _clip06 0 ; alias _clip07 0
menuinit [
    resetcurmenu
    menusynctabstops 1
    if (! $editing) [ menuheader "" "\f3not in edit mode" ]
    menuitemslider "Elevation from ground: " 0 50 "$_clip01" 1 [ _clip01 = $arg1 ]
    menuitemslider "Length (X):  \t" 0 50 "$_clip02" 1 [ _clip02 = $arg1 ]
    menuitemslider "Width (Y):\t"  0 50 "$_clip03" 1 [ _clip03 = $arg1 ]
    menuitemslider "Height (Z):\t" 0 50 "$_clip04" 1 [ _clip04 = $arg1 ]
    menuitemslider "Slope:\t"      -4  4 "$_clip06" 1 [ _clip06 = $arg1 ]
    menuitemslider "Shape:\t" 0 3 "$_clip07" "regular sloped-x sloped-y rotated" [ _clip07 = $arg1 ] 1
    menuitem "" -1
    menuitem "\f2\t [ Place clip entity ]" [ newent7 clip $_clip01 $_clip02 $_clip03 $_clip04 _clip05 $_clip06 $_clip07 ]
    menuitem "\f2\t [ Place player clip entity]" [ newent7 plclip $_clip01 $_clip02 $_clip03 $_clip04 _clip05 $_clip06 $_clip07 ]
    if $editing [
        push x (editentity (getclosestent))
        if (|| (strcmp (at $x 0) clip) (strcmp (at $x 0) plclip)) [
            push n ""
            loop i 7 [ n = [@n ; _clip0@(+ $i 1) = @(at $x (+ $i 4)) ] ]
            menuitem "" -1
            menuitem (concat "Pick clip size from closest entity:" (at $x 4) (at $x 5) (at $x 6) (at $x 7) (at $x 9) (at $x 10)) [ @(pop n) ; refreshcurmenudelayed ]
        ]
        pop x
    ]
]

////  Main > Editing > Entities > TODO entities  ////

newmenu "TODO entities"
menuinit [
    resetcurmenu
    push h 1
    looplisti (enumtodoentities) [n desc] [
        if $editing [
            menuitem (concatword "Entity #" $n ": \fs\f4" (editentity $n) "\fr  " $desc) (concat gotoentity $n "; echo" (escape $desc))
        ][
            menuitem (concatword "Entity #" $n ":  " $desc) -1
        ]
        h = 0
    ]
    if (pop h) [
        menuitem "no TODO entities" -1
    ][
        menuitem "" -1
        menuitem "\f3Clear list of TODO entities" cleartodoentities
    ]
]


////  Main > Editing > Pickups  ////

newmenu Pickups
menuheader "" "\f4place pickup entities"
menuitem "Health"            [ newent health ]
menuitem "Pistol Magazine"   [ newent pistol ]
menuitem "Box of Ammo"       [ newent ammobox ]
menuitem "Kevlar Vest"       [ newent armour ]
menuitem "Helmet"            [ newent helmet ]
menuitem "Akimbo"            [ newent akimbo ]
menuitem "Grenades"          [ newent grenades ]


////  Main > Editing > Textures  ////

newmenu Textures
menuitem "Browse official textures"             [ showmenu "Official textures" ]
menuitem "Browse custom/downloaded textures"    [ showmenu "Custom textures" ]
menuitem "Edit texture slots of current map"    [ showmenu "Edit texture slots" ]
menuitem "Set notexture"                        [ showmenu "Set notexture" ]

tempalias __lastwatchedtexture "" ; tempalias __texslot ""
tempalias __rebuildtexturemenus [
    if $rereadtexturelists [
        delmenu "Official textures"
        delmenu "Custom textures"
        push fullname ""
        looplist (gettexturelist "" "kurt skymaps map_editor" "") [tpath tname] [
            fullname = (concatword $tpath "/" $tname)
            if (strcmp official (gettextureorigin $fullname)) [
                newmenu "Official textures"
            ] [
                newmenu "Custom textures"
            ]
            menuitem $fullname (concat _texmenu_exec (escape $fullname)) (concat _texmenu_hover (escape $fullname) (escape (curmenu)))
            menurenderoffset -20 0
        ]
        pop fullname
    ]
]

tempalias _texmenu_exec [
    __lastwatchedtexture = $arg1
    if $editing [ showmenu "Pick texture" ]
]

tempalias _texmenu_hover [
    __lastwatchedtexture = $arg1
    chmenutexture $arg2 $arg1
]

////  Main > Editing > Textures > Official textures  ////

newmenu "Official textures"
menuinit __rebuildtexturemenus

////  Main > Editing > Textures > Custom textures  ////

newmenu "Custom textures"
menuinit __rebuildtexturemenus

////  Main > Editing > Textures > Official|Custom textures > Pick texture  ////

newmenu "Pick texture"
menuinit [
    resetcurmenu
    if (strlen $__lastwatchedtexture) [
        chmenutexture (curmenu) $__lastwatchedtexture
        push usedslots (textureslotbyname $__lastwatchedtexture)
        menuitem (concat "Texture:" $__lastwatchedtexture) -1
        menuitem (concat "Distribution:" (gettextureorigin $__lastwatchedtexture)) -1
        menuitem "" -1
        if (strlen $usedslots) [
            menuitem "Texture is already used in:" -1
            looplist $usedslots i [
                menuitem (concatword "   slot #" $i "  (scale " (at (edittextureslot $i) 0) ")") (concat "__texslot =" $i "; showmenu [Edit texture slot]")
            ]
            menuitem "" -1
            usedslots = "once more"
        ]
        if (! (strlen (edittextureslot 255))) [
            menuitem (concat "Add to map config" $usedslots) (concat texture 0 $__lastwatchedtexture ; __enableautomapconfig)
            menuitem "Add to map config and use as next wall texture" (concat "edittexturestack wall (texture 0" $__lastwatchedtexture ") ; __enableautomapconfig")
            menuitem "Add to map config and use as next floor texture" (concat "edittexturestack floor (texture 0" $__lastwatchedtexture ") ; __enableautomapconfig")
            menuitem "Add to map config and use as next ceiling texture" (concat "edittexturestack ceiling (texture 0" $__lastwatchedtexture ") ; __enableautomapconfig")
        ] [
            menuitem "\f4(no free texture slots available)" -1
        ]
        pop usedslots
    ][
        menuitem "no texture selected" -1
    ]
]

////  Main > Editing > Textures > Set notexture  ////

newmenu "Set notexture"
menuinit [
    resetcurmenu
    menurenderoffset -20 0
    push m (escape (curmenu))
    push t (concat chmenutexture $m "[]")
    if (strlen (getnotexture)) [
        menuitem (concat Current notexture: (getnotexture)) (concat loadnotexture (getnotexture)) (concat chmenutexture $m (getnotexture))
    ]
    menuitem "Reset notexture" loadnotexture $t  // no preview possible
    menuitem "" -1 $t
    menuitem "\f1Pick a notexture to highlight the areas" -1 $t
    looplist (gettexturelist "map_editor/marker" "" ".png") [tpath tname td] [
        fullname = (concatword $tpath "/" $tname)
        menuitem (concat Set notexture to $tname) (concat loadnotexture (escape $fullname)) (concat chmenutexture $m (escape $fullname))
    ]
    menuitem "" -1 $t
    menuitem "\f1Pick a notexture for actual use" -1 $t
    menuitem "\f4(as default texture, if custom texture downloads fail)" -1 $t
    looplist (concat makke/rock.jpg makke/concrete.jpg (at (edittextureslot 2) 1) (at (edittextureslot 3) 1) (at (edittextureslot 4) 1) $__lastwatchedtexture) fn [
        menuitem (concat Set notexture to $fn) (concat loadnotexture (escape $fn)) (concat chmenutexture $m (escape $fn))
    ]
    pop m t
]


////  Main > Editing > Skymaps  ////

newmenu Skymaps
menuinit [
    resetcurmenu
    if (&& $editing (! (getautomapconfig))) [
        menuitem [Enable automapconfig to make changes permanent] [automapconfig ; closemenu (curmenu)] (concat loadsky (escape $loadsky))
        menuitem "" -1 (concat loadsky (escape $loadsky))
    ]
    menuitem (concat "Current skymap:" $loadsky) (concat loadsky (escape $loadsky))
    menuitem "" -1 (concat loadsky (escape $loadsky))
    push offskies ""
    push userskies ""
    push skyname ""
    looplist (gettexturelist skymaps/ "" _ft.jpg) [c1 c2 c3 c4] [
        skyname = (escape (concatword $c3 "/" $c4))
        if (strcmp official (gettextureorigin (concatword $c1 "/" $c2))) [
            offskies = (concat $offskies $skyname)
        ] [
            userskies = (concat $userskies $skyname)
        ]
    ]
    menuitem "Official skymaps:" -1 (concat loadsky (escape $loadsky))
    looplist $offskies skyname [
        menuitem (concat "   " $skyname) (concat loadsky $skyname) (concat loadsky $skyname)
    ]
    if (strlen $userskies) [
        menuitem "" -1 (concat loadsky (escape $loadsky))
        menuitem "Custom/downloaded skymaps:" -1 (concat loadsky (escape $loadsky))
        looplist $userskies skyname [
            menuitem (concat "   " $skyname) (concat loadsky (escape $skyname)) (concat loadsky (escape $skyname))
        ]
    ]
    pop offskies userskies skyname
]


////  Main > Editing > Ambient sounds  ////

newmenu [Ambient sounds]
menuitem "Browse official mapsounds"             [ showmenu "Official mapsounds" ]
menuitem "Browse custom/downloaded mapsounds"    [ showmenu "Custom mapsounds" ]
menuitem "Edit mapsound slots of current map"    [ showmenu "Edit mapsound slots" ]

tempalias __mapsoundtitles [
    cavedrip.ogg        "Cave drip"
    distant_cars.ogg    "Cars driving in the distance"
    hum01.ogg           "Humm 1"
    hum02.ogg           "Humm 2"
    night_crickets.ogg  "Crickets at night"
    water.ogg           "Water 1"
    wind.ogg            "Wind"
    t_aircond.ogg       "Air conditioner"
    t_compressor.ogg    "Compressor"
    t_crow.ogg          "Crow"
    t_dogs01.ogg        "Dogs 1"
    t_helicopter.ogg    "Helicopter"
    t_hum01.ogg         "Humm 3"
    t_hum02.ogg         "Humm 4"
    t_hum03.ogg         "Humm 5"
    t_hum04.ogg         "Humm 6"
    t_night_dog.ogg     "Dogs 2"
    t_night01.ogg       "Night 1"
    t_night02.ogg       "Night 2"
    t_radio_comms.ogg   "Radio comms"
    t_radio_static.ogg  "Radio static"
    t_satcoms.ogg       "Sat-coms"
    t_sludge.ogg        "Sludge"
    t_static01.ogg      "Static 1"
    t_static02.ogg      "Static 2"
    t_vent01.ogg        "Vent 1"
    t_vent02.ogg        "Vent 2"
    t_water_owl.ogg     "Water owl"
    t_water01.ogg       "Water 2"
    t_waterdrip.ogg     "Water drip"
    t_wind.ogg          "Wind 2"
    t_waterpipe01.ogg   "Waterpipes 1"
    t_waterpipe02.ogg   "Waterpipes 2"
    warningalarm01.ogg  "Warning alarm"
    t_gastank.ogg       "Gastank"
    t_keyboard.ogg      "Keyboard"
    t_factory01.ogg     "Factory"
    t_vents.ogg         "Vent 3"
    t_waterfront.ogg    "Waterfront"
    t_generator.ogg     "Generator"
    t_electricbuzz.ogg  "Electric buzz"
    t_alarm01.ogg       "Alarm"
    flies.ogg           "Flies"
    deserthawk.ogg      "Desert hawk"
    owl.ogg             "Owl"
    citynoisebirds.ogg  "City birds"
]

tempalias __rebuildmapsoundmenus [
    if $rereadsoundlists [
        delmenu "Official mapsounds"
        delmenu "Custom mapsounds"
        looplist (getmapsoundlist) [sname] [
            if (strcmp official (getmapsoundorigin $sname)) [
                newmenu "Official mapsounds"
            ] [
                newmenu "Custom mapsounds"
            ]
            push idx (findlist $__mapsoundtitles $sname)
            if (< $idx 0) [
                menuitem $sname (concat _sndmenu_exec $sname)
            ] [
                menuitem (concatword (at $__mapsoundtitles (+ $idx 1)) " (" $sname ")") (concat _sndmenu_exec $sname)
            ]
            pop idx
            menurenderoffset -20 0
        ]
    ]
]

tempalias _sndmenu_exec [
    __lastwatchedmapsound = $arg1
    if $editing [ showmenu "Pick mapsound" ]
]

////  Main > Editing > Ambient sounds > Official mapsounds  ////

newmenu "Official mapsounds"
menuinit __rebuildmapsoundmenus

////  Main > Editing > Ambient sounds > Custom mapsounds  ////

newmenu "Custom mapsounds"
menuinit __rebuildmapsoundmenus

////  Main > Editing > Ambient sounds > Official|Custom mapsounds > Pick mapsound  ////

newmenu "Pick mapsound"
tempalias __lastwatchedmapsound "" ; tempalias __sndslot ""
menuinit [
    resetcurmenu
    if (strlen $__lastwatchedmapsound) [
        push usedslots (mapsoundslotbyname $__lastwatchedmapsound)
        menuitem (concat "Mapsound:" $__lastwatchedmapsound) -1
        menuitem (concat "Distribution:" (getmapsoundorigin $__lastwatchedmapsound)) -1
        menuitem "" -1
        if (strlen $usedslots) [
            menuitem "Mapsound is already used in" -1
            looplist $usedslots i [
                menuitem (concatword "   slot #" $i "  (maxuses: " (at (editmapsoundslot $i) 1) ")") (concat "__sndslot =" $i "; showmenu [Edit mapsound slot]")
            ]
            menuitem "" -1
            usedslots = "once more"
        ]
        if (! (strlen (editmapsoundslot 255))) [
            menuitem (concat "\f0Add to map config" $usedslots) (concat mapsound $__lastwatchedmapsound -1 ; __enableautomapconfig)
        ] [
            menuitem "\f4(no free mapsound slots available)" -1
        ]
        pop usedslots
    ][
        menuitem "no mapsound selected" -1
    ]
]


////  Main > Editing > Arches  ////

looplist [__slopeaxis 0 __slopeinc 4 __stairaxis 0 __stairwidth 1 __undoarch "" __archside 1] [n v] [tempalias $n $v]
tempalias __setundoarch [ __undoarch = (concat select (at (selx) 0) (at (sely) 0) (at (selxs) 0) (at (selys) 0) "; if (= (undolevel)" (+ (undolevel) 2) ") [ undolevel" (undolevel) "]") ]
newmenu Arches
menuinit [ chmenutexture (curmenu) map_editor/axes.png " " ]
menuitemslider "Arch sideways curve delta: " 0 5 "$__archside" 1 [ __archside = $arg1 ]
menuitem "\t[ Place arch ]" [ if $editing_sp __setundoarch ; heightfield 2; arch $__archside ]
menuitem "Edit arches\i\3" [ showmenu "Edit arches" ]
menuitem "" -1
menuitemradio "Slope axis: " 0 1 "$__slopeaxis" ["West to East (X)" "North to South (Y)"] [ __slopeaxis = $arg1 ]
menuitemslider "Slope increment: " 0 5 "$__slopeinc" ["downwards 3" "downwards 2" "downwards 1" "upwards 1" "upwards 2" "upwards 3"] [ __slopeinc = $arg1 ]
menuitem "\t[ Place slope ]" [ if $editing_sp __setundoarch ; heightfield 0; push i (at "3 2 1 -1 -2 -3" $__slopeinc) ; slope (if $__slopeaxis 0 $i) (if $__slopeaxis $i 0) ; pop i ; 0]
menuitem "" -1
menuitem "Clear heightfielding" [ solid 0; slope 0 0 ]
menuitem "Undo last placed arch or slope" [ __undoarch ; -1 ]
menuitemcheckbox  "Automatically enlarge selections after placing arches and slopes" "$enlargearchslopeselections" [ enlargearchslopeselections $arg1 ]
menuitem "Enlarge selections now" enlargevdeltaselections
menuitem "" -1
menuitemradio "Stairs axis: " 0 1 "$__stairaxis" ["West to East (X)" "North to South (Y)"] [ __stairaxis = $arg1 ]
menuitemslider "Step width: " 0 5 "$__stairwidth" ["downwards 3" "downwards 2" "downwards 1" "upwards 1" "upwards 2" "upwards 3"] [ __stairwidth = $arg1 ]
menuitem "\t[ Place stairs ]" [ push i (at "-3 -2 -1 1 2 3" $__stairwidth) ; stairs (if $__stairaxis 0 $i) (if $__stairaxis $i 0) ; pop i ; 0]

////  Main > Editing > Arches > Edit arches  ////

tempalias __pickarch 2
tempalias __listarch [ push ii "" ; loop i $arg1 [ if $i [ ii = (concat $ii (archvertex $arg1 $i)) ] ] ; result (pop ii) ]
newmenu "Edit arches"
menuinit [
    resetcurmenu
    loop i 50 [
        if (> $i 1) [
            menuitem (concatword "arch width " $i ": " (__listarch $i)) (concat __pickarch = $i "; showmenu [Edit arch]")
        ]
    ]
]

////  Main > Editing > Arches > Edit arches > Edit arch  ////

newmenu "Edit arch"
menuinit [
    resetcurmenu
    menuheader "" (concat "edit arch width" $__pickarch "(symmetrical)")
    push ii ""
    loop i (div $__pickarch 2) [
        ii = (+ $i 1)
        menuitemslider (concat vertex $ii "\t") 0 31 (archvertex $__pickarch $ii) 1 (concat archvertex $__pickarch $ii "$arg1 ; archvertex" $__pickarch (- $__pickarch $ii) "$arg1")
    ]
    pop ii
    menuitem "" -1
    menuitem (concat Measure selection for width $__pickarch arch) (concat av (- $__pickarch 1) "(av_measure)")
    menuitem "Edit full arch (non-symmetrical)\i\3" [ showmenu "Edit full arch" ]
    menuitem "Restore arch of different size (ymmv)\i\3" [ showmenu "Pick custom arch" ]
    menuitem "Delete saved custom arch\i\3" [ showmenu "Delete custom arch" ]
    menuitem "" -1
    tempalias __archname custom
    looplist (enumalias (concatword _arch_ $__pickarch _)) [fn sn] [
        if (= (+ (listlen $$fn) 1) $__pickarch) [
            __archname = $sn
            menuitem (concat Restore $sn "  " $$fn) (concat av (- $__pickarch 1) (escape $$fn))
        ]
    ]
    menuitemtextinput "Save arch as " "result $__archname" (concat __archname "= $arg1 ; (concatword _arch_"$__pickarch "_ $arg1) = (__listarch" $__pickarch ")" ) "" 250
]

////  Main > Editing > Arches > Edit arches > Edit arch > Edit full arch  ////

newmenu "Edit full arch"
menuinit [
    resetcurmenu
    menuheader "" (concat "edit arch width" $__pickarch "(non-symmetrical)")
    loop i $__pickarch [
        if $i [ menuitemslider (concat vertex $i "\t") 0 31 (archvertex $__pickarch $i) 1 (concat archvertex $__pickarch $i "$arg1") ]
    ]
]

////  Main > Editing > Arches > Edit arches > Edit arch > Pick custom arch  ////

newmenu "Pick custom arch"
menuinit [
    resetcurmenu
    menuheader "" (concat "pick custom arch for width" $__pickarch)
    looplist (enumalias _arch_) [fn sn] [ menuitem (concat Use "\fs\f2" $sn $$fn "\fr " as width $__pickarch arch) (concat av (- $__pickarch 1) (escape $$fn)) ]
]

////  Main > Editing > Arches > Edit arches > Edit arch > Delete custom arch  ////

newmenu "Delete custom arch"
menuinit [
    resetcurmenu
    looplist (enumalias _arch_) [fn sn] [ menuitem (concat Delete custom arch "\fs\f2" $sn "\fr" $$fn) (concat delalias (escape $fn)) ]
]


////  Main > Editing > Map operations  ////

newmenu [Map operations]
menuitem "Newmap (128x128 cubes - recommended)" [ newmap 7 ]
menuitem "Newmap (256x256 cubes)"               [ newmap 8 ]
menuitem "Increase mapsize (2x)"                [ mapenlarge; echo The map size has been increased by 2. However, the new space is solid. To utilize it, you will need to turn it into non-solid space, by selecting it and pressing G. ]
menuitem "Print entity stats"                   entstats
menuitem "Cycle through multiple closest entities" nextclosestent
menuitemslider "Select only entities of this type: " 0 -1 "(closestenttype -)" (concat all (listoptions ents)) [ if $arg1 [ closestenttype $arg1 ] [ closestenttype ] ] 1
menuitem "Hide entity sparklies\i\3"            [ showmenu [Hide entity sparklies] ]
menuitem "Multiple map buffers (xmaps)\i\3"     [ showmenu xmaps ]

////  Main > Editing > Map operations > Hide entity sparklies  ////

newmenu [Hide entity sparklies]
looplisti (listoptions ents) e [
    menuitemcheckbox  (concat Hide $e sparklies:) (concat "(&b $edithideentmask" (+ 0 (powf 2 $i)) ")") (concat "edithideentmask (^b $edithideentmask" (+ 0 (powf 2 $i)) ")")
]

////  Main > Editing > Map operations > xmaps  ////

newmenu xmaps
tempalias __curxmap ""
menuinit [
    resetcurmenu
    if $editing [
        push la (getxmaplist)
        push lb (getxmaplist bak)
        if (strlen $la) [
            menuitem "\f2Currently available xmaps:" -1
            looplist $la [n d] [
                menuitem $d (concat "__curxmap =" $n "; showmenu xmap")
            ]
            menuitem "" -1
        ]
        if (strlen $lb) [
            menuitem "\f2Currently stored backup xmap:" -1
            menuitem (at $lb 1) -1
            menuitem "Transfer backup xmap to new regular xmap" (concat inputcommand (at $lb 0) "[xmap_keep_backup $cmdbuf]" "\"\fs\f0[xmap_keep_backup]\f2 enter new nickname for backup xmap:\fr\""  1)
            menuitem "Delete backup xmap" [ saycommand "/xmap_delete_backup" ]
            if $editing_sp [
                if $unsavededits [
                    menuitem (concat "Restore backup xmap \f3(and lose" $unsavededits "currently unsaved edits)") xmap_restore
                ] [
                    menuitem "Restore backup xmap" xmap_restore
                ]
            ]
            menuitem "" -1
        ]
        menuitem "Store current map and edit state as xmap" [ inputcommand "" [xmap_store $cmdbuf] "\"\fs\f0[xmap_store]\f2 enter nickname for new xmap:\fr\"" ]
        menuitem "List all xmaps in console" [ saycommand "/xmap_list" ]
        pop la lb
    ] [
        menuitem "menu only available in edit mode" -1
    ]
]

////  Main > Editing > Map operations > xmaps > xmap ////

newmenu xmap
menuinit [
    resetcurmenu
    if $editing [
        push desc ""
        looplist (getxmaplist) [n d] [ if (strcmp $n $__curxmap) [ desc = $d ] ]
        if (strlen $desc) [
            menuitem (concatword  "\f2xmap " $__curxmap ":") -1
            menuitem $desc -1
            menuitem "" -1
            if $editing_sp [
                if (strlen (getxmaplist bak)) [
                    menuitem (concatword "Restore xmap \fs\f1" $__curxmap "\fr (store current state as new backup xmap \fs\f3and lose backup xmap \f1" (at (getxmaplist bak) 0) "\fr)") (concat xmap_restore $__curxmap)
                ] [
                    menuitem (concat "Restore xmap\fs\f1" $__curxmap "\fr(store current state as new backup xmap)") (concat xmap_restore $__curxmap)
                ]
            ]
            menuitem "" -1
            menuitem "Rename xmap" (concat inputcommand $__curxmap "[xmap_rename" $__curxmap "$cmdbuf]" "\"\fs\f0[xmap_rename]\f2 enter new nickname for xmap" $__curxmap ":\fr\"" 1)
            menuitem "Delete xmap" (concat saycommand "/xmap_delete" $__curxmap)
        ]
        menuselection (curmenu) 3
        pop desc
    ] [
        menuitem "menu only available in edit mode" -1
    ]
]

////  Main > Editing > Map settings  ////

newmenu [Map settings]
tempalias __enableautomapconfig [ if (&& $editing (! (getautomapconfig))) automapconfig ]
menuinit [
    resetcurmenu
    if $editing [
        menuheader "" (concat "   Settings for map" (curmap))
        menuitemtextinput (concatword "Water level (" (getvarrange min waterlevel) ".." (getvarrange max waterlevel) ", default " (getvarrange default waterlevel) "):\t") $waterlevel [waterlevel $arg1]
        looplisti "red 20 green 25 blue 20 alpha 178" [n v] [
            menuitemtextinput (concatword "Water colour (" $n ", default " $v "):\t") (at (getwatercolour) $i) (concat setwatercolour $n "$arg1")
        ]
        menuitem "Water colour sliders\i\3" [ showmenu [Water colour] ]
        menuitem "" -1
        menuitemtextinput (concatword "Shadow yaw (0..360, default " (getvarrange default shadowyaw) "):\t") $shadowyaw [__enableautomapconfig ; shadowyaw $arg1]
        menuitem "" -1
        menuitemtextinput (concatword "Fog distance (" (getvarrange min fog) ".." (getvarrange max fog) ", default " (getvarrange default fog) "):\t") $fog [__enableautomapconfig ; fog $arg1]
        menuitemtextinput (concatword "Fog colour (0xrrggbb, default 0x" (h0 6 (getvarrange default fogcolour)) "):\t") (concatword "0x" (h0 6 $fogcolour))  [__enableautomapconfig ; fogcolour $arg1]
        menuitem "Fog colour sliders\i\3" [ showmenu [Fog colour] ]
        menuitem "" -1
        menuitemtextinput (concatword "Ambient light (0..255 or 0xrrggbb, default 0):\t") (if (< $ambient 256) $ambient (concatword "0x" (h0 6 $ambient)))  [ambient $arg1]
        menuitem "" -1
        menuitemcheckbox  "Map override: Disable water reflection" "$mapoverride_nowaterreflect" [ mapoverride_nowaterreflect $arg1 ]
        menuitemcheckbox  "Map override: Limit water waveheight" "$mapoverride_limitwaveheight" [ mapoverride_limitwaveheight $arg1 ]
        menuitemcheckbox  "Map override: Disable stencil shadows" "$mapoverride_nostencilshadows" [ mapoverride_nostencilshadows $arg1 ]
        menuitem "" -1
        if (strlen (getvantagepoint)) [
            menuitem (format2 "Map vantage point is at x=%1, y=%2, z=%3, yaw=%4, pitch=%5" (getvantagepoint)) [ showmenu [Vantage point] ]
        ] [
            menuitem "Set map vantage point\i\3" [ showmenu [Vantage point] ]
        ]
        menuitem "" -1
        push n (getnotexture)
        if (! (strlen $n)) [n = <default>]
        menuitem (concatword "Notexture:\n" (pop n)) [showmenu "Set notexture"]
        menuitem (concatword "Skymap:\n" $loadsky) [showmenu Skymaps]
        menuitem "" -1
        if (strlen $mapmsg) [
            menuitem (concat "Map message:" $mapmsg) editmapmsg
        ] [
            menuitem "Edit map message..." editmapmsg
        ]
        if (strlen $mapinfo_license) [
            menuitem (concatword "Map license tag: \"" $mapinfo_license "\"") [ showmenu "Select map license" ]
            if (strlen $mapinfo_comment) [
                menuitem (concat "Map license comment:" $mapinfo_comment) [ editsvar mapinfo_comment ]
            ] [
                menuitem "Edit map license comment..." [ editsvar mapinfo_comment ]
            ]
        ] [
            menuitem "Select map license\i\3" [ showmenu "Select map license" ]
        ]
    ] [
        menuitem "menu only available in edit mode" -1
    ]
    menuitem "" -1
    menuitem "Show map info\i\3" [ showmenu "Show map info" ]
]

////  Main > Editing > Map settings > Water colour  ////

newmenu [Water colour]
looplisti [red green blue alpha] n [
    menuitemslider (concatword "Water colour (" $n "): ") 0 255 (concat "(at (getwatercolour)" $i ")") 5 (concat setwatercolour $i "$arg1") 1
]

////  Main > Editing > Map settings > Fog colour  ////

newmenu [Fog colour]
looplist [red 0xff0000 0x10000 green 0xff00 0x100 blue 0xff 1] [n m f] [
    menuitemslider (concatword "Fog colour (" $n "): ") 0 255 (concat "(div (&b $fogcolour " $m ")" $f ")") 5 (concat "__enableautomapconfig ; fogcolour (|b (&b $fogcolour" (^b 0xffffff $m) ") (* $arg1" $f "))") 1
]

////  Main > Editing > Map settings > Fog colour > Vantage point  ////

newmenu [Vantage point]
menuinit [
    resetcurmenu
    if (strlen (getvantagepoint)) [
        menuitem (format2 "Goto current map vantage point at x=%1, y=%2, z=%3, yaw=%4, pitch=%5" (getvantagepoint)) [ gotovantagepoint ]
        menuitem "" -1
        if $editing_sp [
            menuitem "\f3[ Delete vantage point ]" clearvantagepoint
            menuitem "" -1
        ]
    ]
    if(! $connected) [
        menuitem "\f0[ Set current position and viewing angle as map vantage point ]" setvantagepoint
    ]
]

////  Main > Editing > Map settings > Select map license  ////
////  Main > Editing > Map settings > Show map info  ////
// see menus_licenses.cfg


////  Main > Editing > Map config operations  ////

newmenu [Map config operations]
tempalias __showorigin 0 ; tempalias __colororigin [ result (concatword " \fs\f" (if (strcmp $arg1 official) 4 2) "<" $arg1 ">\fr") ]
menuinit [
    resetcurmenu
    if $editing_sp [
        menuitem "Edit mapmodel slot\i\3"           [ showmenu [Edit mapmodel slots] ]
        menuitem "Delete unused mapmodel slot\i\3"  [ showmenu [Delete unused mapmodel slot] ]
        menuitem "" -1
        menuitem "Edit texture slot\i\3"            [ showmenu [Edit texture slots] ]
        menuitem "" -1
        menuitem "Edit mapsound slot\i\3"           [ showmenu [Edit mapsound slots] ]
        menuitem "" -1
        menuitem "Delete ALL unused mapmodel slots" [loop ii 256 [ push i (- 255 $ii) ; if (&& (strlen (mapmodelslotname $i)) (strcmp "" (mapmodelslotusage $i))) [deletemapmodelslot $i] ; pop i]]
        menuitem "Delete ALL unused texture slots"  [loop ii 251 [ push i (- 255 $ii) ; if (&& (strlen (edittextureslot $i)) (strcmp "" (textureslotusage $i))) [deletetextureslot $i] ; pop i]]
        menuitem "Delete ALL unused mapsound slots" [loop ii 256 [ push i (- 255 $ii) ; if (&& (strlen (editmapsoundslot $i)) (strcmp "" (mapsoundslotusage $i))) [deletemapsoundslot $i] ; pop i]]
        menuitem "" -1
        menuitem "Sort mapmodel slots\i\3"          [ showmenu [Sort mapmodel slots] ]
        menuitem "Sort texture slots\i\3"           [ showmenu [Sort texture slots] ]
        menuitem "Sort mapsound slots\i\3"          [ showmenu [Sort mapsound slots] ]
        menuitem "" -1
        menuitem "Update mapmodel menus" "mapmodelchanged 1"
    ][
        menuitem "List mapmodel slots"              [ showmenu [List mapmodel slots] ]
        menuitem "List texture slots"               [ showmenu [List texture slots] ]
        menuitem "List mapsound slots"              [ showmenu [List mapsound slots] ]
        menuitem "\f4(offline edit mode required to make changes)" -1
        menuitem "" -1
    ]
    menuitemcheckbox "Show media file origin/distribution" "$__showorigin" [ __showorigin = $arg1 ; mapmodelchanged 1 ]
]

////  Main > Editing > Map config operations > Edit mapmodel slots  ////

newmenu [Edit mapmodel slots]
menuinit __rebuildmapmodelmenus

////  Main > Editing > Map config operations > Edit mapmodel slots > Edit mapmodel slot  ////

newmenu [Edit mapmodel slot]
tempalias __lastwatchedmapmodel "" ; tempalias __mmslot ""
menuinit [
    resetcurmenu
    if (strlen $__mmslot) [
        push info (editmapmodelslot $__mmslot)
        menuheader "" (concatword "edit mapmodel slot #" $__mmslot ":\n" (mapmodelslotname $__mmslot))
        if (strlen $info) [
            menuitemtextinput "Clipping radius" (at $info 0) [editmapmodelslot $__mmslot $arg1]
            menuitemtextinput "Clipping height       " (at $info 1) [editmapmodelslot $__mmslot "" $arg1]
            menuitemtextinput "z-Offset              " (at $info 2) [editmapmodelslot $__mmslot "" "" $arg1]
            menuitemtextinput "Scale [0.25 - 4.0]    " (at $info 3) [editmapmodelslot $__mmslot "" "" "" $arg1]
            push __distribution (getmapmodelattributes (mapmodelslotname $__mmslot) distribution)
            if (! (strlen $__distribution)) [ __distribution = "custom/unsorted" ]
            menuitem (concat "Distribution:" (pop __distribution)) -1
            looplist [defaults "Defaults:" usage "Usage:" license "License:" version "Version:" requires "Requires:"] [attr hd] [ // also possible: desc "Desc:" author "Author:"
                attr = (getmapmodelattributes (mapmodelslotname $__mmslot) $attr)
                if (strlen $attr) [
                    menuitem (concat $hd $attr) -1
                ]
            ]
            menuitem "" -1
            menuitemtextinput "Mapmodel path         " (concat result (at $info 4)) [editmapmodelslot $__mmslot "" "" "" "" $arg1] "" 250
            if (&& (strlen $__lastwatchedmapmodel) (! (strcmp $__lastwatchedmapmodel (at $info 4)))) [
                menuitem (concat "   change to" (escape $__lastwatchedmapmodel)) [editmapmodelslot $__mmslot "" "" "" "" $__lastwatchedmapmodel]
            ]
            menuitem "" -1
            menuitem "Duplicate slot" (concat mapmodel $info)
        ] [
            menuitem "\f3Unassigned slot" -1
        ]
        if (strlen (mapmodelslotusage $__mmslot)) [
            menuitem "" -1 (concat gotoposition (gotoposition))
            looplist (mapmodelslotusage $__mmslot) ii [
                menuitem (concatword "slot used by map entity #" $ii) (concat gotoentity $ii) (concat gotoentity $ii)
            ]
            if (strcmp " " (mapmodelslotusage $__mmslot)) [
                menuitem "(this model is required by another model)" -1
            ]
            menuitem "" -1 (concat gotoposition (gotoposition))
        ][
            menuitem "" -1
            menuitem "\f3Delete unused slot" (concat deletemapmodelslot $__mmslot)
        ]
        pop info
    ][
        menuitem "no slot selected" -1
    ]
]

////  Main > Editing > Map config operations > Delete unused mapmodel slot  ////

newmenu [Delete unused mapmodel slot]
menuinit __rebuildmapmodelmenus

////  Main > Editing > Map config operations > Edit texture slots  ////

newmenu [Edit texture slots]
menuinit [
    resetcurmenu
    menurenderoffset -20 0
    if $editing_sp [
        push ecurmenu (escape (curmenu))
        push info ""
        push origin ""
        looplisti (textureslotusagelist) [cnt used] [
            info = (edittextureslot $i)
            if $__showorigin [ origin = (__colororigin (gettextureorigin (at $info 1))) ]
            if (|| $cnt (strlen $info)) [
                if (! (strlen $info)) [ info = "  \fs\f3<unassigned>\fr" ; origin = "" ]
                menuitem (concatword "edit texture slot #" $i ": " $info " (" $cnt " uses, " $used " visible)" $origin) (concat __texslot = $i "; showmenu [Edit texture slot]") (concat chmenutexture $ecurmenu (at $info 1))
            ]
        ]
        pop info ecurmenu origin
    ] [
        __menuitem_offlineeditonly // "menu only available in offline edit mode"
    ]
]

////  Main > Editing > Map config operations > Edit texture slots > Edit texture slot  ////

newmenu [Edit texture slot]
tempalias __defaultskymapdummy kurt/klite1.jpg
menuinit [
    resetcurmenu
    if (strlen $__texslot) [
        push info (edittextureslot $__texslot)   // "<scale> <path>"
        chmenutexture (curmenu) (at $info 1)
        menurenderoffset -20 0
        menuheader "" (concatword "edit texture slot #" $__texslot ":\n" (at $info 1))
        menuitemtextinput "Scaling factor [0..4]    " (at $info 0) [edittextureslot $__texslot $arg1]
        menuitem "\f4factor 0 means default (1.0)" -1
        menuitem "" -1
        menuitem (concat "Distribution:" (gettextureorigin (at $info 1))) -1
        menuitem "" -1
        menuitemtextinput "Texture path         " (concat result (at $info 1)) [edittextureslot $__texslot "" $arg1] "" 250
        if (&& (strlen $__lastwatchedtexture) (! (strcmp $__lastwatchedtexture (at $info 1)))) [
            menuitem (concat "   change to" (escape $__lastwatchedtexture)) [edittextureslot $__texslot "" $__lastwatchedtexture]
        ]
        if (&& (! $__texslot) (! (strcmp $__defaultskymapdummy (at $info 1)))) [
            menuitem (concat "   change to skymap default" (escape $__defaultskymapdummy)) [edittextureslot $__texslot 0 $__defaultskymapdummy]
        ]
        menuitem "" -1
        menuitem "use as next (upper-)wall texture" [edittexturestack wall $__texslot]
        menuitem "use as next floor texture" [edittexturestack floor $__texslot]
        menuitem "use as next ceiling texture" [edittexturestack ceiling $__texslot]
        push __usage (textureslotusage $__texslot)
        if (&& $__texslot (listlen $__usage)) [
            menuitem "" -1 (concat gotoposition (gotoposition))
            looplist $__usage ii [
                menuitem (concatword "slot used by map entity #" $ii) (concat gotoentity $ii) (concat gotoentity $ii)
            ]
            menuitem "" -1 (concat gotoposition (gotoposition))
        ]
        if (strlen (pop __usage)) [
            if (> (listlen (textureslotbyname (at $info 1))) 1) [
                menuitem "" -1
                menuitem "Merge multiple slots using same texture" [showmenu "Texture slot merge"]
            ]
        ] [
            menuitem "" -1
            menuitem "\f3Delete unused slot" (concat deletetextureslot $__texslot)
        ]
        if (! (strcmp $__lastwatchedtexture (at $info 1))) [
            menuitem "" -1
            menuitem (concat "Pick texture name" (at $info 1)) (concat __lastwatchedtexture = (escape (at $info 1)))
        ]
        if (! $__texslot) [
            menuitem "" -1
            menuitem (concat "Slot #0 is hardcoded as skymap, please use" $__defaultskymapdummy) -1
        ] [
            if (< $__texslot 5) [
                menuitem "" -1
                menuitem (concatword "Slot #" $__texslot " is the default " (at ["" "cube 1 water" "wall" "floor" "ceiling"] $__texslot) " texture") -1
            ]
        ]
        pop info
    ][
        menuitem "no slot selected" -1
    ]
]

////  Main > Editing > Map config operations > Edit texture slots > Edit texture slot > Texture slot merge  ////

newmenu "Texture slot merge"
tempalias __tex_joined "" ; tempalias __tex_togo ""
menuinit [
    resetcurmenu
    if (strlen $__texslot) [
        push info (edittextureslot $__texslot)   // "<scale> <path>"
        chmenutexture (curmenu) (at $info 1)
        menurenderoffset -20 0
        menuheader "" (concatword "merge texture slots using\n" (at $info 1))
        menuitem (concat "Slots using texture" (at $info 1)) -1
        push slots (textureslotbyname (at $info 1))
        push usemap (textureslotusagelist)
        menuitem "" -1
        push last (- (listlen $slots) 1)
        __tex_togo = (at $slots 0)
        __tex_joined = (at $slots $last)
        looplist $slots ii [
            menuitem (concatword "  #" $ii ": " (edittextureslot $ii) " (" (at $usemap (* $ii 2)) " uses, " (at $usemap (+ (* $ii 2) 1)) " visible)") (concat alias __texslot $ii "; showmenu [Edit texture slot]")
        ]
        menuitem "" -1
        menuitem "Merge" -1
        menuitemslider "    slot #" 0 $last 0 $slots (concat "__tex_togo = (at" (escape $slots) "$arg1)")
        menuitem "into" -1
        menuitemslider "    slot #" 0 $last $last $slots (concat "__tex_joined = (at" (escape $slots) "$arg1)")
        menuitem "                  \f0[OK]" [if (!= $__tex_joined $__tex_togo) [deletetextureslot $__tex_togo purge $__tex_joined]]
        pop info slots usemap last
    ][
        menuitem "no slot selected" -1
    ]
]

////  Main > Editing > Map config operations > Edit mapsound slots  ////

// Edit mapsound slots
newmenu [Edit mapsound slots]
menuinit [
    resetcurmenu
    if $editing_sp [
        push info ""
        push origin ""
        loop i 256 [
            info = (editmapsoundslot $i)
            if (strlen $info) [
                if $__showorigin [ origin = (__colororigin (getmapsoundorigin (at $info 0))) ]
                menuitem (concatword "edit mapsound slot #" $i ": " $info $origin) (concat alias __sndslot $i ";" showmenu (escape "Edit mapsound slot"))
            ] [
                if (strlen (mapsoundslotusage $i)) [
                    menuitem (concatword "unassigned mapsound slot #" $i) (concat alias __sndslot $i ";" showmenu (escape "Edit mapsound slot"))
                ]
            ]
        ]
        pop info origin
    ] [
        __menuitem_offlineeditonly // "menu only available in offline edit mode"
    ]
]

////  Main > Editing > Map config operations > Edit mapsound slots > Edit mapsound slot  ////

newmenu [Edit mapsound slot]
tempalias __snd_rad "1" ; tempalias __snd_size "0" ; tempalias __snd_vol "255"
menuinit [
    resetcurmenu
    if (strlen $__sndslot) [
        push info (editmapsoundslot $__sndslot)   // "<path> <maxuses>"
        menuheader "" (concatword "edit mapsound slot #" $__sndslot ":\n" (at $info 0))
        if (strlen $info) [
            menuitemtextinput "Max simultaneous uses    " (at $info 1) [editmapsoundslot $__sndslot "" $arg1]
            menuitem "            (\f4-1: unlimited)" -1
            menuitem "" -1
            menuitem (concat "Distribution:" (getmapsoundorigin (at $info 0))) -1
            menuitem "" -1
            menuitemtextinput "Mapsound path         " (concat result (at $info 0)) [editmapsoundslot $__sndslot $arg1] "" 250
            if (&& (strlen $__lastwatchedmapsound) (! (strcmp $__lastwatchedmapsound (at $info 0)))) [
                menuitem (concat "   change to" (escape $__lastwatchedmapsound)) [editmapsoundslot $__sndslot $__lastwatchedmapsound]
            ]
            menuitem "" -1
            menuitem "\f2Create map entity:" -1
            menuitemslider [Sound radius: ] 1 25 "$__snd_rad"  1 [ __snd_rad = $arg1 ]
            menuitemslider [Sound size: ]   0 25 "$__snd_size" 1 [ __snd_size = $arg1 ]
            menuitemslider [Sound volume: ] 1 255 "$__snd_vol" 5 [ __snd_vol = $arg1 ]
            menuitem "\f0          Place new entity now" (concat newent sound $__sndslot $__snd_rad $__snd_size $__snd_vol)
        ] [
            menuitem "\f3Unassigned slot" -1
        ]
        if (strlen (mapsoundslotusage $__sndslot)) [
            menuitem "" -1 (concat gotoposition (gotoposition))
            looplist (mapsoundslotusage $__sndslot) ii [
                menuitem (concatword "slot used by map entity #" $ii) (concat gotoentity $ii) (concat gotoentity $ii)
            ]
            menuitem "" -1 (concat gotoposition (gotoposition))
        ][
            menuitem "" -1
            menuitem "\f3Delete unused slot" (concat deletemapsoundslot $__sndslot)
        ]
        pop info
    ][
        menuitem "no slot selected" -1
    ]
]

////  Main > Editing > Map config operations > Sort mapmodel slots  ////

looplist [__mmsort __mmmerge __texsort __texmerge __sndsort __sndmerge] i [tempalias $i 1]

newmenu [Sort mapmodel slots]
menuitemcheckbox  "Sort slots alphabetically" "$__mmsort" [ __mmsort = $arg1 ]
menuitemslider "Merge " 0 2 "$__mmmerge" ["no slots" "unused identical slots" "all identical slots"] [ __mmmerge = $arg1 ] 1
menuitem "" -1
menuitem "\t\t\f0[Start]" [sortmapmodelslots (at [nosort ""] $__mmsort) (at [nomerge "" mergeused] $__mmmerge)]

////  Main > Editing > Map config operations > Sort texture slots  ////

newmenu [Sort texture slots]
menuitemcheckbox  "Sort slots alphabetically" "$__texsort" [ __texsort = $arg1 ]
menuitemslider "Merge " 0 2 "$__texmerge" ["no slots" "unused identical slots" "all identical slots"] [ __texmerge = $arg1 ]
menuitem "" -1
menuitem "\t\t\f0[Start]" [sorttextureslots (at [nosort ""] $__texsort) (at [nomerge "" mergeused] $__texmerge)]

////  Main > Editing > Map config operations > Sort mapsound slots  ////

newmenu [Sort mapsound slots]
menuitemcheckbox  "Sort slots alphabetically" "$__sndsort" [ __sndsort = $arg1 ]
menuitemslider "Merge " 0 2 "$__sndmerge" ["no slots" "unused identical slots" "all identical slots"] [ __sndmerge = $arg1 ] 1
menuitem "" -1
menuitem "\t\t\f0[Start]" [sortmapsoundslots (at [nosort ""] $__sndsort) (at [nomerge "" mergeused] $__sndmerge)]

////  Main > Editing > Map config operations > List mapmodel slots  ////

newmenu [List mapmodel slots]
menuinit [
    resetcurmenu
    menurenderoffset -40 0
    push mpath ""
    push origin ""
    loop i 256 [
        mpath = (mapmodelslotname $i)
        if (strlen $mpath) [
            if $__showorigin [
                origin = (getmapmodelattributes $mpath distribution)
                if (! (strlen $origin)) [ origin = "custom/unsorted" ]
                origin = (__colororigin $origin)
            ]
            menuitem [slot #@[i]: @(editmapmodelslot $i)@origin] -1 (__mm_showmodel2 [List mapmodel slots] $mpath)
        ]
    ]
    pop origin mpath
]

////  Main > Editing > Map config operations > List texture slots  ////

newmenu [List texture slots]
menuinit [
    resetcurmenu
    menurenderoffset -20 0
    push info ""
    push origin ""
    looplisti (textureslotusagelist) [cnt used] [
        info = (edittextureslot $i)
        if $__showorigin [ origin = (__colororigin (gettextureorigin (at $info 1))) ]
        if (strlen $info) [
            menuitem [texture slot #@[i]: @info @"("@cnt uses, @used visible@")"@origin] -1 [chmenutexture [List texture slots] @(at $info 1)]
        ]
    ]
    pop info origin
]

////  Main > Editing > Map config operations > List mapsound slots  ////

newmenu [List mapsound slots]
menuinit [
    resetcurmenu
    push info ""
    push origin ""
    loop i 256 [
        info = (editmapsoundslot $i)
        if (strlen $info) [
            if $__showorigin [ origin = (__colororigin (getmapsoundorigin (at $info 0))) ]
            menuitem (concatword "mapsound slot #" $i ": " $info $origin) -1
        ]
    ]
    pop info origin
]


////  Main > Editing > Map checks and statistics  ////

newmenu [Map checks and statistics]
menuinit [
    resetcurmenu
    if $editing [
        menuitem "Map area checks\i\3"            [ showmenu [Map area checks] ]
        menuitem "Entity statistics"             [ showmenu [Entity statistics] ]
        menuitem "Check mapmodels with unconfigured custom textures" [ showmenu [Walk mapmodel entities with unconfigured custom textures] ]
        menuitem "Show most visible textures"    [ showmenu [Most visible textures] ]
        menuitem "Cycle through spawn points"    [ gotonextplayerstart ]
    ] [
        menuitem "menu only available in edit mode" -1
    ]
]

tempalias __showslopes [
    push i 0
    looplist (mapareacheck vdelta) n [
        if $n [ echo $n cubes with slopes $i .. (+ $i 2) ]
        i = (+ $i 2)
    ]
    pop i
]

tempalias __clearprobepointdummies [ clearents dummy ]

tempalias __placeprobepointdummies [
    __clearprobepointdummies
    looplist (mapareacheck pp) [x y z area vol avgh] [
        if (> $vol 32767) [ vol = 32767 ]
        editentity (addentity dummy) $x $y (+ $z 5) $area "" "" "" $vol "" $avgh
    ]
]

////  Main > Editing > Map checks and statistics > Map area checks  ////

newmenu [Map area checks]
menuinit [
    resetcurmenu
    menuitem "Heightfield slope stats" __showslopes
    menuitem "Goto steepest heightfield position" [ push p (mapareacheck steepest) ; gotoposition (at $p 0) (at $p 1) (at (pop p) 2)]
    if $editing_sp [
        menuitem "Place probe point dummies" __placeprobepointdummies
        menuitem "Walk probe point dummies\i\3" [ showmenu [Walk probe point dummies] ]
        menuitem "Clear probe point dummies" __clearprobepointdummies
    ]
]

////  Main > Editing > Map checks and statistics > Map area checks > Walk probe point dummies  ////

newmenu [Walk probe point dummies]
menuinit [
    resetcurmenu
    __placeprobepointdummies
    menuitem "\f4(return to previous position)" (concat gotoposition (gotoposition)) (concat gotoposition (gotoposition))
    push ents (enumentities dummy)
    looplisti (mapareacheck pp) [x y z area vol avgh] [
        menuitem (concatword "#" $i " area: " $area " volume: " $vol " avg height: " $avgh "  (" $x "|" $y ")") (concat gotoentity (at $ents $i)) (concat gotoentity (at $ents $i))
    ]
    pop ents
]

////  Main > Editing > Map checks and statistics > Entity statistics  ////

newmenu [Entity statistics]
menuinit [
    resetcurmenu
    push s 1
    looplist (listoptions ents) e [
        push n (listlen (enumentities $e))
        if $n [
            menuitem (concatword $n " entities of type " $e) (concat showmenu "[Walk" $e "entities]")
            s = 0
        ]
        pop n
    ]
    if (pop s) [
        menuitem "No entities" -1
    ]
]

////  Main > Editing > Map checks and statistics > Entity statistics > Walk ... entities  ////

push __a "resetcurmenu ; menuitem [\f4(return to previous position)] (concat gotoposition (gotoposition)) (concat gotoposition (gotoposition)) ;"
push __b "looplist $ents i [ menuitem (concatword # $i [ ] (editentity $i)) (concat gotoentity $i) (concat gotoentity $i) ] ; pop ents"
looplist (listoptions ents) e [
    newmenu (concat Walk $e entities)
    menuinit (concat $__a "push ents (enumentities" $e ") ;" $__b)
]

////  Main > Editing > Map checks and statistics > Walk mapmodel entities with unconfigured custom textures  ////

newmenu [Walk mapmodel entities with unconfigured custom textures]
menuinit (concat $__a "looplist (enumentities mapmodel) i [if (! (strlen (edittextureslot (at (editentity $i) 7)))) [menuitem (concatword # $i [ ] (editentity $i)) (concat gotoentity $i) (concat gotoentity $i)]]")
pop __a __b

////  Main > Editing > Map checks and statistics > Most visible textures  ////

newmenu [Most visible textures]
menuinit [
    resetcurmenu
    menurenderoffset -20 0
    if $editing [
        push ec (escape (curmenu))
        push mvis (textureslotusagelist onlymostvisible)
        push info ""
        looplist $mvis [d i] [
            info = (edittextureslot $i)
            menuitem (concatword "most visible " $d " texture: " (if $i (escape $info) [result <skymap>]) " (slot #" $i ")") (concat __texslot = $i "; showmenu [Edit texture slot]") (concat chmenutexture $ec (at $info 1))
        ]
        if $editing_sp [
            menuitem "" -1 (concat chmenutexture $ec [])
            menuitem "Sort the most visible textures to the default slot positions" (concat sorttextureslots nomerge nosort 1 (at $mvis 1) (at $mvis 3) (at $mvis 5) (at $mvis 7)) (concat chmenutexture $ec [])
        ]
        pop mvis ec info
    ] [
        menuitem "menu only available in edit mode" -1
    ]
]


////  Main > Editing > Creating bot waypoints  ////
// see menus_bot.cfg


////  Main > Editing > Editing settings  ////

newmenu [Editing settings]
menuitemslider    "Grid/Selection style: " 0 1 "$oldselstyle" [triangles "squares (default)"] [ oldselstyle $arg1 ] 1
menuitemcheckbox  "Show mapmodel clippings: " "$showmodelclipping" [ showmodelclipping $arg1 ]
menuitemcheckbox  "Show ladder entities: " "$showladderentities" [ showladderentities $arg1 ]
menuitemcheckbox  "Show all playerstarts (spawn points): " "$showplayerstarts" [ showplayerstarts $arg1 ]
menuitemslider    "Show closest ent slot info: " 0 2 "$hideeditslotinfo" [ always "if unassigned" never ][ hideeditslotinfo $arg1 ] 1
menuitemcheckbox  "Show edit info panel: " "(! $hideeditinfopanel)" [ hideeditinfopanel (! $arg1) ]
menuitemslider    "Fly speeds multiplier: " 1 5 "$flyspeed" 1 [ flyspeed $arg1 ]
menuitemcheckbox  "Write xmaps to disk on quit: " "$persistentxmaps" [ persistentxmaps $arg1 ]
// opt/autosave.cfg may add some entries


////  Main > Editing > Editing misc  ////

newmenu [Editing misc]
menuitem "Load batch map conversion tools" load_convmap [] "\f4(checking and editing of entire map collections)"
menuitem "Load extra map editing scripts" load_mapeditscripts [] "\f4(expert tools for hardcore map optimisations)"
menuitem "Rebuild list of mapmodels" [ echo "\f1This will take a few seconds..." ; sleep 99 [ mapmodelregistryclear ; loadallmapmodels ; echo "\f1Done." ] ] [] "\f2Use this after manually adding or removing mapmodels\nfrom your profile directory. May throw some errors."


////  Main > Editing > Editing keys  ////

newmenu [Editing keys]
menuitem "Select an action and press ENTER to bind a new key:" -1
menuitem "" -1
menuitem "\f2Mousewheel editing:" -1
menuitemeditkeyinput [Move entity: ]                     editkey_scroll_moveent
menuitemeditkeyinput [Change vdelta: ]                   editkey_scroll_vdelta
menuitemeditkeyinput [Change wall/upper wall texture: ]  editkey_scroll_walluppertex
menuitemeditkeyinput [Change floor/ceiling texture: ]    editkey_scroll_floorceiltex
menuitem "\f4(Keys '1' thru '7' edit entity attributes)" -1
menuitem "" -1
menuitem "\f2Edit all selected cubes:" -1
menuitemeditkeyinput [Make cubes 'solid': ]       editkey_cubes_solid
menuitemeditkeyinput [Make cubes 'space': ]       editkey_cubes_space
menuitemeditkeyinput [Make cubes 'floor heightfield': ]    editkey_cubes_hf_floor
menuitemeditkeyinput [Make cubes 'ceiling heightfield': ]  editkey_cubes_hf_ceiling
menuitemeditkeyinput [Make cubes 'corner': ]      corner
menuitem "" -1
menuitemeditkeyinput [Move floor down: ]          editkey_move_floor_down
menuitemeditkeyinput [Move floor up: ]            editkey_move_floor_up
menuitemeditkeyinput [Move ceiling down: ]        editkey_move_ceiling_down
menuitemeditkeyinput [Move ceiling up: ]          editkey_move_ceiling_up
menuitemeditkeyinput [Decrease vdelta: ]          editkey_vdelta_down
menuitemeditkeyinput [Increase vdelta: ]          editkey_vdelta_up
menuitemeditkeyinput [Equalize floor: ]           editkey_equalize_floor
menuitemeditkeyinput [Equalize ceiling: ]         editkey_equalize_ceiling
menuitem "" -1
menuitemeditkeyinput [Texture on floor forward: ]       editkey_floortex_up
menuitemeditkeyinput [Texture on floor previous: ]      editkey_floortex_dn
menuitemeditkeyinput [Texture on wall forward: ]        editkey_walltex_up
menuitemeditkeyinput [Texture on wall previous: ]       editkey_walltex_dn
menuitemeditkeyinput [Texture on ceiling forward: ]     editkey_ceiltex_up
menuitemeditkeyinput [Texture on floor previous: ]      editkey_ceiltex_dn
menuitemeditkeyinput [Texture on upper wall forward: ]  editkey_uppertex_dn
menuitemeditkeyinput [Texture on upper wall previous: ] editkey_uppertex_up
menuitem "" -1
menuitem "\f2Misc editing keys:" -1
menuitemkeyinput     [Enter edit mode: ]          edittoggle
menuitemeditkeyinput [Exit edit mode: ]           edittoggle
menuitemeditkeyinput [Show editing menu: ]        editkey_show_menu
menuitemeditkeyinput [Show lighting menu: ]       editkey_show_menu_light
menuitem "" -1
menuitemeditkeyinput [1st meta key: ]             editmeta
menuitemeditkeyinput [2nd meta key: ]             editkey_editmeta2
menuitem "" -1
menuitemeditkeyinput [Occlusion culling on/off: ] toggleocull
menuitemeditkeyinput [Mip display on/off: ]       showmip
menuitemeditkeyinput [Fullbright on/off: ]        editkey_fullbright
menuitemeditkeyinput [Show cube details on/off: ] showfocuscubedetails
menuitem "" -1
menuitemeditkeyinput [Copy selected cubes: ]      copy
menuitemeditkeyinput [Paste cubes: ]              paste
menuitemeditkeyinput [Undo geometry changes: ]    undo
menuitemeditkeyinput [Redo: ]                     redo
menuitem "" -1
menuitemeditkeyinput [Pin/unpin closest entity: ] toggleclosestentpin
menuitemeditkeyinput [Point to select entity: ]   editkey_pointatents
menuitemeditkeyinput [Cycle through closest entities: ] nextclosestent
menuitemeditkeyinput [Delete entity: ]            editkey_delete_entity
menuitemeditkeyinput [Copy entity: ]              copyent
menuitemeditkeyinput [Paste entity: ]             pasteent
menuitemeditkeyinput [Edit entity: ]              editent
menuitemeditkeyinput [Cycle through TODO entities: ] editkey_scroll_todoents
menuitemeditkeyinput [Cycle through spawns: ]     editkey_scroll_spawns
menuitem "" -1
menuitem "\f2Tag clips:" -1
menuitemeditkeyinput [Show tag clip volume: ]     showtagclipfocus
menuitemeditkeyinput [Remove tag clip: ]          editkey_tagclip_none
menuitemeditkeyinput [Create tag 'playerclip': ]  editkey_tagclip_plclip
menuitemeditkeyinput [Create tag 'clip': ]        editkey_tagclip_clip
menuitem "" -1
menuitemtextinput [Lookup a keyeditbind: ] [] [
    if (strlen $arg1) [
        echo (concatword "\f9Contents of keyeditbind " (addpunct $arg1) :)
        if (strcmp (result (keyeditbind $arg1)) "") [
            echo (addpunct $arg1) is not bound
        ][
            echo (keyeditbind $arg1)
        ]
     ]
] [] 256
menuitem [] -1
menuitem "Alternate edit binds\i\3" [ showmenu [Alternate edit binds] ]

////  Main > Editing > Editing keys > Alternate edit binds  ////

newmenu [Alternate edit binds]
menuitem "\f2Back" [ closecurmenu ]
menuitem [Click to use alternate edit binds] [ exec config/opt/alternateeditbinds.cfg; closecurmenu ] [ echo "\f3See config/opt/alternateeditbinds.cfg first" ]


////  Main > Editing > Deleted entities  ////

newmenu "Deleted entities"
menuinit [
    resetcurmenu
    if (unlistdeletedentity) [
        looplisti (getdeletedentities) [type x y z a1 a2 a3 a4 a5 a6 a7] [
            push desc (concat $type (concatword "[" $x "|" $y "|" $z "]") (concatword "(" $a1 ", " $a2 ", " $a3 ", " $a4 ", " $a5 ", " $a6 ", " $a7 ")"))
            if (strcmp $type mapmodel) [desc = (concat $desc (mapmodelslotname $a2))]
            if (&& $editing (strcmp $type sound)) [desc = (concat $desc (at (editmapsoundslot $a1) 0))]
            if $editing [
                menuitem  (pop desc) (concat gotoposition $x $y $z $a1 0 ";" undelent $i)
            ][
                menuitem  (pop desc) -1
            ]
        ]
        menuitem "\f3clear this list" "unlistdeletedentity all"
    ] [
        menuitem "no deleted entities" -1
    ]
]
