// standard menu definitions
// don't modify, add personal menus to autoexec.cfg instead

togglemainmenu = [
    if (! (cleargui 1)) [
        showgui main
    ]
]

bind ESCAPE [togglemainmenu]

newgui main [
    guilist [
        guitext "name: " (playermodelicon)
        newname = (getname)
        guifield newname 15 [name $newname]
    ]
    guibutton (concat "model:" (playermodelname)) [guirolloveraction = (playermodelbutton $playermodel); showgui playermodel] (playermodelicon)
    guilist [
        guibutton "crosshair: " [showgui crosshair] (playermodelicon)
        guiimage (getcrosshair) [showgui crosshair] 0.5
    ]
    guibar
    guibutton "server browser.."  "showgui servers"
    if (isconnected) [
        guibar
        if (|| $editing (m_edit (getmode))) [
            guibutton "editing.." "showgui editing"
        ]
        guibutton "vote game mode / map.." "showgui gamemode"
        // guibutton "lanconnect"
        // guibutton "connect localhost"
        guibutton "switch team" [if (strcmp (getteam) "good") [team evil] [team good]]
        guibutton "toggle spectator" [spectator (! (isspectator (getclientnum)))] "spectator"
        guibutton "master.." [showgui master]
        guibar
        guibutton "options.."  "showgui options"
        guibutton "disconnect" "disconnect"         "exit"
    ] [
        guibutton "bot match.."      "showgui botmatch"
        guibutton "campaign.."       "showgui campaign"
        guibar
        guibutton "options.."        "showgui options"
        guibutton "about.."          "showgui about"
        guibutton "quit"             "quit"                 "exit"
    ]
] 0

newgui about [
    guitext "Cube 2: Sauerbraten"
    guitext [by Wouter "Aardappel" van Oortmerssen, Lee "eihrul" Salzman,]
    guitext [Mike "Gilt" Dysart, Robert "baby-rabbit" Pointon,]
    guitext [John "geartrooper" Siar, Quinton "Quin" Reeves, and others]
    guitext "(for a full list of contributors see the readme)"
    guitext "http://sauerbraten.org/"
]

genmapitems = [
    looplist curmap $arg1 [
        guibutton $curmap (concat map $curmap) "cube"
    ]
]
//17

ffamaps1 = "aard3c academy akaritori alithia alloy aqueducts arbana bvdm_01 castle_trap collusion complex corruption curvedm curvy_castle darkdeath deathtek depot"
ffamaps2 = "dirtndust DM_BS1 dock douze duel7 duel8 dune elegy fanatic_quake force fragplaza frostbyte frozen fury guacamole gubo hades"
ffamaps3 = "hashi hog2 industry injustice island justice kalking1 katrez_d kffa killfactory kmap5 konkuri-to ksauer1 legazzo lostinspace masdm mbt10"
ffamaps4 = "mbt2 mbt9 memento metl2 metl3 metl4 moonlite neondevastation neonpanic nmp8 nucleus oasis oddworld ogrosupply orbe orion osiris"
ffamaps5 = "ot outpost paradigm park pgdm phosgene pitch_black powerplant refuge renegade rm5 roughinery ruby ruine sauerstruck sdm1 shadowed"
ffamaps6 = "shindou shinmei1 shiva simplicity skrdm1 stemple suburb tartech teahupoo tejen thetowers thor torment tumwalk turbine wake5 wdcd"
capturemaps1 = "abbey akroseum alithia arabic asgard asteroids c_egypt c_valley campo capture_night caribbean collusion core_refuge core_transfer corruption cwcastle damnation"
capturemaps2 = "dirtndust donya duomo dust2 eternal_valley evilness face-capture fb_capture fc3 fc4 fc5 forge frostbyte hades hallo haste hidden"
capturemaps3 = "infamy killcore3 kopenhagen lostinspace mbt12 mercury monastery nevil_c nitro nmp4 nmp8 nmp9 nucleus ogrosupply paradigm ph-capture reissen"
capturemaps4 = "relic river_c serenity snapper_rocks spcr subterra suburb tempest tortuga turbulence twinforts urban_c valhalla venice xenon"
ctfmaps1 = "abbey akroseum arbana asgard authentic autumn bad_moon berlin_wall bt_falls campo capture_night catch22 core_refuge core_transfer damnation desecration dust2"
ctfmaps2 = "eternal_valley europium evilness face-capture flagstone forge forgotten garden hallo haste hidden infamy kopenhagen l_ctf mach2 mbt1 mbt12"
ctfmaps3 = "mbt4 mercury mill nitro nucleus recovery redemption reissen sacrifice shipwreck siberia snapper_rocks spcr subterra suburb tejen tempest"
ctfmaps4 = "tortuga turbulence twinforts urban_c valhalla wdcd xenon"
conceptmaps = "ladder spiralz canyon secondevermap firstevermap door_demo box_demo platform_demo"
spmaps = "mpsp6a mpsp6b mpsp6c mpsp9a mpsp9b mpsp9c mpsp10 lost level9"
allmaps = (concat $ffamaps1 $ffamaps2 $ffamaps3 $ffamaps4 $ffamaps5 $ffamaps6 $capturemaps1 $capturemaps2 $capturemaps3 $capturemaps4 $ctfmaps1 $ctfmaps2 $ctfmaps3 $ctfmaps4 $conceptmaps $spmaps)

showmapshot = [ 
    guibar
    guiimage (concatword "packages/base/" (if (> $numargs 0) [result $arg1] [at $guirollovername 0]) ".jpg") $guirolloveraction 4 1 "data/cube.png"
]

newgui maps [
    guilist [
      guistrut 17 1
      guilist [ guistrut 15 1; genmapitems $ffamaps1 ]
      guilist [ guistrut 15 1; genmapitems $ffamaps2 ]
      showmapshot
    ]
    guitab 2
    guilist [
      guistrut 17 1
      guilist [ guistrut 15 1; genmapitems $ffamaps3 ]
      guilist [ guistrut 15 1; genmapitems $ffamaps4 ]
      showmapshot
    ]
    guitab 3
    guilist [
      guistrut 17 1
      guilist [ guistrut 15 1; genmapitems $ffamaps5 ]
      guilist [ guistrut 15 1; genmapitems $ffamaps6 ]
      showmapshot
    ]
    guitab capture
    guilist [
      guistrut 17 1
      guilist [ guistrut 15 1; genmapitems $capturemaps1 ]
      guilist [ guistrut 15 1; genmapitems $capturemaps2 ]
      showmapshot
    ]
    guitab 2
    guilist [
      guistrut 17 1
      guilist [ guistrut 15 1; genmapitems $capturemaps3 ]
      guilist [ guistrut 15 1; genmapitems $capturemaps4 ]
      showmapshot
    ]
    guitab ctf
    guilist [
        guistrut 17 1
        guilist [ guistrut 15 1; genmapitems $ctfmaps1 ]
        guilist [ guistrut 15 1; genmapitems $ctfmaps2 ]
        showmapshot
    ]
    guitab 2
    guilist [
        guistrut 17 1
        guilist [ guistrut 15 1; genmapitems $ctfmaps3 ]
        guilist [ guistrut 15 1; genmapitems $ctfmaps4 ]
        showmapshot
    ]

    guitab concept
    guilist [
        guistrut 17 1
        guilist [ guistrut 15 1; genmapitems $conceptmaps ]
        guilist [ guistrut 15 1 ]
        showmapshot
    ]
]

newgui capturemaps [
    guilist [
      guistrut 17 1
      guilist [ guistrut 15 1; genmapitems $capturemaps1 ]
      guilist [ guistrut 15 1; genmapitems $capturemaps2 ]
      showmapshot
    ]
    guitab 2
    guilist [
      guistrut 17 1
      guilist [ guistrut 15 1; genmapitems $capturemaps3 ]
      guilist [ guistrut 15 1; genmapitems $capturemaps4 ]
      showmapshot
    ]
] "capture maps"

newgui ctfmaps [
    guilist [
        guistrut 17 1
        guilist [ guistrut 15 1; genmapitems $ctfmaps1 ]
        guilist [ guistrut 15 1; genmapitems $ctfmaps2 ]
        showmapshot
    ]
    guitab 2
    guilist [
        guistrut 17 1
        guilist [ guistrut 15 1; genmapitems $ctfmaps3 ]
        guilist [ guistrut 15 1; genmapitems $ctfmaps4 ]
        showmapshot
    ]
] "ctf maps"

custommaps = ""
newgui custommaps [
    looplist curmap $custommaps [
        guibutton $curmap (concat map $curmap) "cube"
    ]
] "custom maps"
showcustommaps = [
    custommaps = ""
    loopfiles curmap "packages/base" "ogz" [
        if (< (indexof $allmaps $curmap) 0) [
            custommaps = (concat $custommaps $curmap)
        ]
    ]
    custommaps = (sortlist $custommaps x y [<=s $x $y])
    showgui custommaps
]
macro playermodelbutton [cleargui 1; playermodel %1]

newgui playermodel [
    guilist [
        guilist [
            loop i $playermodelnum [
                guibutton (playermodelname $i) (playermodelbutton $i) (playermodelicon $i)
            ]
        ]
        guibar
        pmidx = (substr $guirolloveraction (strlen (playermodelbutton "")))
        pmidx = (max 0 (min (- $playermodelnum 1) $pmidx))
        guilist [
            guiplayerpreview $pmidx 0 6 $guirolloveraction 4 1
            guitextbox (playermodelstory $pmidx) 40 9
        ]
    ]
]

crosshairs = ["data/crosshair.png data/hit.png" 
"packages/crosshairs/x.png packages/crosshairs/x-hit.png"
"packages/crosshairs/x_dot.png packages/crosshairs/x_dot-hit.png"
"packages/crosshairs/o.png packages/crosshairs/o-hit.png"
"packages/crosshairs/o_x.png packages/crosshairs/o_x-hit.png"
"packages/crosshairs/o_dot.png packages/crosshairs/o_dot-hit.png"
"packages/crosshairs/dot.png packages/crosshairs/dot-hit.png"
"packages/crosshairs/dot_wide.png packages/crosshairs/dot_wide-hit.png"
"packages/crosshairs/star.png packages/crosshairs/star-hit.png"
"packages/crosshairs/wide.png packages/crosshairs/wide-hit.png"
"packages/crosshairs/circle_dot.png packages/crosshairs/circle_dot_hit.png"
"packages/crosshairs/cross_normal.png packages/crosshairs/cross_normal_hit.png"
"packages/crosshairs/cross_whole.png packages/crosshairs/cross_whole_hit.png"
"packages/crosshairs/dot_normal.png packages/crosshairs/dot_normal_hit.png"
"packages/crosshairs/dot_whole.png packages/crosshairs/dot_whole_hit.png"
]

newgui crosshair [
    guitext "crosshair size"
    guislider crosshairsize
    loop row (div (+ (listlen $crosshairs) 6) 7) [
        guilist [
            loop col 7 [
                ch = (at $crosshairs (+ (* $row 7) $col))
                if (!=s $ch "") [
                    guiimage (at $ch 0) [ 
                        cleargui 1
                        loadcrosshair @(at $ch 0) 0
                        loadcrosshair @(at $ch (if (> (listlen $ch) 1) 1 0)) 2
                    ] 0.5
                ]
            ]
        ]
    ]
]

newgui master [
  guistayopen [
    if (ismaster (getclientnum)) [
        guibutton "relinquish master" "setmaster 0"
    ] [
        guibutton "claim master" "setmaster 1"
    ]
    guilist [
        guitext "mastermode: "
        mm = (getmastermode)
        guiradio "open (0) " mm 0 "mastermode 0"
        guiradio "veto (1) " mm 1 "mastermode 1"
        guiradio "locked (2) " mm 2 "mastermode 2"
        guiradio "private (3) " mm 3 "mastermode 3"
    ]
    guibar
    looplist cn (listclients 0 0) [
        guilist [
            guitext (concatword (getclientname $cn) ": ") (getclienticon $cn)
            guibutton "kick " [kick @cn]
            guibutton "toggle spectator " [spectator @(= (isspectator $cn) 0) @cn]
            if (m_teammode (getmode)) [
                guibutton "switch team " [setteam @cn @(? (=s (getclientteam $cn) "good") "evil" "good")]
            ]
            if (ismaster $cn) [
                guibutton "take master" [setmaster 0 @cn]
            ] [
                guibutton "give master" [setmaster 1 @cn]
            ]
        ]
    ]
  ]
]

botmatchcount = 5
botmatchminskill = 50
botmatchmaxskill = 100

startbotmatch = [
    if (isconnected 0 0) [
        echo "You must disconnect from the current multiplayer game before starting a bot match."
    ] [
        loop i $botmatchcount [addbot (rnd (+ $botmatchmaxskill 1) $botmatchminskill)]
    ]
]

newgui botmatch [
    guitext "bot amount"
    guislider botmatchcount 0 32
    guitext "bot minimum skill"
    guislider botmatchminskill 50 101 [if (< $botmatchmaxskill $botmatchminskill) [botmatchmaxskill = $botmatchminskill]]
    guitext "bot maximum skill"
    guislider botmatchmaxskill 50 101 [if (> $botmatchminskill $botmatchmaxskill) [botmatchminskill = $botmatchmaxskill]]
    guibutton "start match.." [guionclear [startbotmatch]; showgui gamemode]
] "bot match"

newgui campaign [
    guibutton "start Private Stan Sauer"           "showgui privatestansauer"
    guibutton "start An Army Of One"               "showgui armyofone"
    guibutton "start Lost"                         "sp lost" "cube"
    guibutton "start Level 9"                      "sp level9" "cube"
    guibar
    guibutton "start DMSP map.."                   "mode -2; showgui maps"
    guicheckbox "slow motion"                      "slowmosp"
    guitext   "skill (default: 3)"
    guislider skill
]

newgui armyofone [
    guilist [
        guilist [
            guibutton "Part I" "sp mpsp6a" "cube"
            guibutton "Part II" "sp mpsp6b" "cube"
            guibutton "Part III" "sp mpsp6c" "cube"
        ]
        showmapshot (substr $guirolloveraction 3)
    ]
] "An Army Of One"

newgui privatestansauer [
    guilist [
        guilist [
            guibutton "Run N' Gun Part I" "sp mpsp9a" "cube"
            guibutton "Run N' Gun Part II" "sp mpsp9b" "cube"
            guibutton "Run N' Gun Part III" "sp mpsp9c" "cube"
            guibutton "THE SERIOUSLY BIG VALLEY" "sp mpsp10" "cube"
        ]
        showmapshot (substr $guirolloveraction 3)
    ]
] "Private Stan Sauer"

newgui servers [
    guistayopen [
        guiservers [
            guilist [
                guibutton "update from master server" "updatefrommaster"
                guibar
                guicheckbox "search LAN" searchlan
                guibar
                guicheckbox "auto-update" autoupdateservers
                guibar
                guicheckbox "auto-sort" autosortservers
                if (= $autosortservers 0) [
                    guibar
                    guibutton "sort" "sortservers"
                ]
            ]
            guibar
        ] 17
    ]
] "" [initservers]

newgui gamemode [
    guilist [
        guilist [
            guibutton "ffa"                "mode 0; showgui maps"
            guibutton "coop-edit"          "mode 1; showgui maps"
            guibutton "teamplay"           "mode 2; showgui maps"
            guibutton "instagib"           "mode 3; showgui maps"
            guibutton "instagib team"      "mode 4; showgui maps"
            guibutton "efficiency"         "mode 5; showgui maps"
            guibutton "efficiency team"    "mode 6; showgui maps"
            guibutton "tactics"            "mode 7; showgui maps"
            guibutton "tactics team"       "mode 8; showgui maps"
            guibutton "capture"            "mode 9; showgui capturemaps"
            guibutton "regen capture"      "mode 10; showgui capturemaps"
        ]
        guibar
        guilist [
            guibutton "ctf"                "mode 11; showgui ctfmaps"
            guibutton "insta ctf"          "mode 12; showgui ctfmaps"
            guibutton "efficiency ctf"     "mode 17; showgui ctfmaps"
            guibutton "protect"            "mode 13; showgui ctfmaps"
            guibutton "insta protect"      "mode 14; showgui ctfmaps"
            guibutton "efficiency protect" "mode 18; showgui ctfmaps"
            guibutton "hold"               "mode 15; showgui capturemaps"
            guibutton "insta hold"         "mode 16; showgui capturemaps"
            guibutton "efficiency hold"    "mode 19; showgui capturemaps"
            guibutton "collect"            "mode 20; showgui ctfmaps"
            guibutton "insta collect"      "mode 21; showgui ctfmaps"
            guibutton "efficiency collect" "mode 22; showgui ctfmaps"
        ]
    ]
]

showfileeditor = [
    guinoautotab [
        guieditor $arg1 $arg2 $arg3
        textinit $arg1 $arg1
        guistayopen [
            guilist [
                guibutton "load" [textfocus @arg1; textload @arg1]
                guibar
                guibutton "save" [textfocus @arg1; textsave @arg1]
                guibar
                guibutton "exec" [textfocus @arg1; textexec]
                guibar
                guibutton "copy" [textfocus @arg1; textcopy]
                guibar
                guibutton "paste" [textfocus @arg1; textpaste]
                guibar
                guibutton "select" [textfocus @arg1; textselectall]
                guibar
                guibutton "clear" [textfocus @arg1; textclear]
            ]
        ]
    ]
]

notepadfile = "untitled.txt"

newgui notepad [
    guifield notepadfile -30
    showfileeditor $notepadfile -80 20
]

notepad = [
    if (> $numargs 0) [notepadfile = $arg1]
    showgui notepad
]

newgui pastebuffer [
    guinoautotab [
        guieditor "#pastebuffer" -80 20
        guistayopen [
            guilist [
                guibutton "exec" [textfocus "#pastebuffer"; textexec]
                guibar
                guibutton "clear" [textfocus "#pastebuffer"; textclear]
            ]
        ]
    ]
]

pastebuffer = [showgui pastebuffer]

newgui scratchpad [
    guinoautotab [
        guieditor "#scratchpad" -80 20
        guistayopen [
            guilist [
                guibutton "exec" [textfocus "#scratchpad"; textexec]
                guibar
                guibutton "copy" [textfocus "#scratchpad"; textcopy]
                guibar
                guibutton "paste" [textfocus "#scratchpad"; textpaste]
                guibar
                guibutton "select" [textfocus "#scratchpad"; textselectall]
                guibar
                guibutton "clear" [textfocus "#scratchpad"; textclear]
            ]
        ]
    ]
]

scratchpad = [showgui scratchpad]

newmapsize = 12
savemap_name = temp

newgui editing [
    guibutton "materials.."                           "showgui materials"
    guibutton "toggle edit mode	(E)"              "edittoggle"
    guitext "toggle heightmap	(H)"
    guibutton "deselect			(SPACE)"                "cancelsel"
    guibutton "passthrough		(hold LCTRL)"               "passthrough"
    guitext "select			drag left mouse   "
    guitext "select corners		drag middle mouse "
    guitext "extend selection	right mouse"
    guitext "reorient			right mouse"
    guitext "move selection		drag right mouse"
    guibutton "copy				(C)"			                  "copy"
    guibutton "paste			(V)"			                "paste"

    guitab ents
    guilist [
      guilist [
        guibutton "drop entities.."              "showgui dropent"
        guibutton "mapmodels.."                  "showgui mapmodels"
        guibutton "light.."                      "resetlight;showgui newlight"

        guibutton "newent playerstart   "
        guibutton "newent shells"
        guibutton "newent bullets"
        guibutton "newent rockets"
        guibutton "newent riflerounds"
        guibutton "newent grenades"
      ]
      guilist [
        guibutton "teleport.."                   "showgui newteleport"
        guibutton "monster.."                    "showgui monsters"
        guibutton "trigger.."                    "showgui triggers"

        guibutton "newent cartridges"
        guibutton "newent health"
        guibutton "newent healthboost"
        guibutton "newent greenarmour"
        guibutton "newent yellowarmour"
        guibutton "newent quaddamage"
      ]
    ]

    guitab keys
    guibutton "flip / mirror cube		(X)"            "flip"
    guibutton "undo					(Z, U)"                     "undo"
    guibutton "redo					(I)"                        "redo"
    guibutton "delete				(BACKSPACE)"                  "editdel"
    guibutton "texture palette     	(F2)" "showtexgui"
    guibutton "edit entity gui			(F3)" "showentgui"
    guibutton "mapmodels list			(F4)" "showgui mapmodels"
    guibutton "select all in box		(keypad ENTER)" "entselect insel"
    guibutton "select all matching		(N)" "selentfindall"
    guibutton "center view on ent		(COMMA + scroll)" "entautoview"
    guibutton "edit entity console		(PERIOD)" "selentedit"
    guitext "toggle heightmap tex	(MMB in heightmapmode)"
    guicheckbox "toggle outline			(7)"        outline
    guicheckbox "toggle wireframe		(8)"    wireframe


    guitab scroll
    guitext "push/pull selection			scroll wheel only"
    guitext "push the face of a cube	hold F + scroll wheel"
    guitext "change gridsize			hold G + scroll wheel"
    guitext "change textures			hold Y + scroll wheel"
    guitext "rotate         			hold R + scroll wheel"
    guitext "push corner with cursor		hold Q + scroll wheel"
    guitext "push/pull heightmap			hold LALT + scroll wheel"
    guitext "change heightmap brush		hold B + scroll wheel"

    guitab lighting
    guibutton "calclight 1 (slow: 8xAA)" "calclight 1"
    guibutton "calclight -1 (quick: no AA, no model shadows)"   "calclight -1"
    guibutton "patchlight"                         "patchlight"

    guicheckbox "fullbright" fullbright

    guitext "lightprecision (default: 32)"
    guilistslider lightprecision "8 16 32 48 64 128 256"

    guitext "lighterror (default: 8)"
    guislider lighterror

    guitext "lightthreads (CPU threads/cores) (default: 0)"
    guislider lightthreads

    //guibutton "lightlod high (6)" "lightlod 6"
    //guibutton "lightlod low  (2)" "lightlod 2"
    //guibutton "lightlod off  (0)" "lightlod 0"


    guitab blend
    guitext "blend paint mode:"
	guiradio "off						(keypad 0)" blendpaintmode 0
	guiradio "replace					(keypad 1)" blendpaintmode 1
	guiradio "dig						(keypad 2)" blendpaintmode 2
	guiradio "fill						(keypad 3)" blendpaintmode 3
	guiradio "inverted dig				(keypad 4)" blendpaintmode 4
	guiradio "inverted fill				(keypad 5)" blendpaintmode 5
    guibar
    guitext "paint blendmap			(MOUSE1)"
	guibutton "change blend brush			scroll wheel" "nextblendbrush"
	guibutton "rotate blend brush			(MOUSE2)" "rotateblendbrush"
	guibutton "clear entire blendmap 		(^"clearblendmap^" command)" "clearblendmap"
	guibutton "clear blendmap in selection	(^"clearblendmapsel^" command)" "clearblendmapsel"

    guitab map
    guitext   "save map:"
    guifield  savemap_name 20 [ savemap $savemap_name ]
    guibutton [load @savemap_name map]             "map $savemap_name"
    guibutton "newmap (default size: 12)"          "newmap $newmapsize"
    guislider "newmapsize" 10 16
    guibutton "increase mapsize (2x)"              "mapenlarge"
    guitext   "max undo size (default: 5 MB)"
    guislider "undomegs" 1 10
    guibutton "optimize geometry"                  "remip"
    guibutton "set map title/author"               "saycommand [/maptitle ]"
    guibutton "show custom maps"                   "showcustommaps"

    guitab skybox
    guilist [
        guistayopen [
            guilist [ genskyitems $skies1 ]
            guilist [ genskyitems $skies2 ]
            showskyshot
        ]
    ]

    guitab cfg
    guitext (mapcfgname)
    showfileeditor (mapcfgname) -60 15
]


skies1 = [
aftas/sky/orbe
blindabuser/blindasky
blindabuser/blindasky2
darc/forge
dash/moon
hazel/green
humus/meadow
ik2k/env/iklake
jon/prarie
mayhem/duomo
mayhem/eclipse
meister/uzze
penguins/arid
penguins/harmony
penguins/wrath
penguins/yonder
ratboy/skyboxes/coward
]
skies2 = [
shmutzwurst/london
skyboxes/clearsky052
skyboxes/darkness
skyboxes/evilsky
skyboxes/morning
skyboxes/remus/sky01
skyboxes/turbulent
socksky/barren
socksky/desert
socksky/emerald
socksky/frozen
socksky/frozendusk
socksky/grave
socksky/mars
socksky/nightball
socksky/valley
staffy/staffy
]

genskyitems = [
    looplist cursky $arg1 [
        guibutton $cursky (concat skybox $cursky) //"cube"
    ]
]

alias showskyshot [ guibar; guiimage (concatword "<thumbnail:128>packages/" (if (> $numargs 0) [result $arg1] [result (at $guirollovername 0)]) "_ft.jpg") $guirolloveraction 4 1 "data/cube.png"]


newgui materials [
    guibutton "air"                        "editmat air"
    guibutton "water"                      "editmat water"
    guibutton "lava"                       "editmat lava"
    guibutton "clip"                       "editmat clip"
    guibutton "glass"                      "editmat glass"
    guibutton "noclip"                     "editmat noclip"
    guibutton "gameclip"                   "editmat gameclip"
    guibutton "death"                      "editmat death"
    guibutton "alpha"                      "editmat alpha"

    guicheckbox "show material volumes"    showmat

    //guibutton "waterlod very high		(3)"  "waterlod 3"
    //guibutton "waterlod high		(2)"          "waterlod 2"
    //guibutton "waterlod default		(1)"  "waterlod 1"
    //guibutton "waterlod low		(0)"          "waterlod 0"

    //guibutton "watersubdiv very fine	(0)"          "watersubdiv 0"
    //guibutton "watersubdiv fine		(1)"  "watersubdiv 1"
    //guibutton "watersubdiv default		(2)"  "watersubdiv 2"
    //guibutton "watersubdiv coarse		(3)"  "watersubdiv 3"

    //guibutton "water waves on"                     "waterwaves 1"
    //guibutton "water waves off"                    "waterwaves 0"
]

setting_entediting = 1

newgui dropent [
    guitext "drop entities:"
    guiradio "to the floor"                 entdrop 1
    guiradio "on selection"                 entdrop 2
    guiradio "to the floor at selection"    entdrop 3
    guiradio "at current position"          entdrop 0
    guibar
    guicheckbox "entity snap-to-grid"       entselsnap
    guicheckbox "entity selection"          setting_entediting 1 0 [ entediting $setting_entediting ]
]

newgui triggers [
    guibutton [invisible]               [BTmm = -1; showgui trigger2]
    guibutton [a carrot]                [BTmm = 23; showgui trigger2]
    guibutton [switch #1]               [BTmm = 24; showgui trigger2]
    guibutton [switch #2]               [BTmm = 25; showgui trigger2]
    guibutton [door #1]                 [BTmm = 26; showgui trigger2]
    guibutton [door #2]                 [BTmm = 27; showgui trigger2]
    guibutton [door #3]                 [BTmm = 28; showgui trigger2]
]

newgui trigger2 [
    guibutton [animation loop]                      [BTtt = 0; showgui trigger3]
    guibutton [trigger once (popback)]              [BTtt = 1; showgui trigger3]
    guibutton [trigger once (popback & rumble)]     [BTtt = 2; showgui trigger3]
    guibutton [trigger once]                            [BTtt = 3; showgui trigger3]
    guibutton [trigger once (rumble)]               [BTtt = 4; showgui trigger3]
    guibutton [trigger multiple (popback)]          [BTtt = 5; showgui trigger3]
    guibutton [trigger multiple (popback & rumble)] [BTtt = 6; showgui trigger3]
    guibutton [trigger multiple]                        [BTtt = 7; showgui trigger3]
    guibutton [trigger multiple (rumble)]           [BTtt = 8; showgui trigger3]
    guibutton [door (open once)]                        [BTtt = 9; showgui trigger3]
    guibutton [door (auto close)]                   [BTtt = 10; showgui trigger3]
    guibutton [door (locked)]                       [BTtt = 11; showgui trigger3]
    guibutton [vanishing trigger]                   [BTtt = 12; showgui trigger3]
    guibutton [vanishing trigger (rumble)]          [BTtt = 13; showgui trigger3]
    guibutton [End Of Level Trigger]                    [BTtt = 29; showgui trigger3]
]

build_trigger = [newent mapmodel $BTmm $BTtt $BTti]

newgui trigger3 [
    loop i 9 [
        tjt = (concat tag (concatword # $i))
        tjc = (concat BTti "=" $i ";" "build_trigger")
        guibutton $tjt $tjc
    ]
]


resetlight = [
    lightcolour = 0
    lightbright = 1
    lightset 255 255 255
    lightradius = 128
]

lightset = [
    lightr = $arg1
    lightg = $arg2
    lightb = $arg3
    if (= $lightbright 0) lightscale
]

lightscale = [
    if (= $lightbright 0) [
        lightr = (div $lightr 2); lightg = (div $lightg 2); lightb = (div $lightb 2)
    ] [
        lightr = (min 255 (* $lightr 2)); lightg = (min 255 (* $lightg 2)); lightb = (min 255 (* $lightb 2))
    ]
]

lightcmd = [
    result (concat newent light $lightradius $lightr $lightg $lightb)
]

newgui newlight [
    guibutton "sunlight"    "newent light 0 255 255 255"
    guibutton (lightcmd)
    guibar
    guitext "color:"
    guicolor (+ (* (+ (* $lightr 256) $lightg) 256) $lightb)
    guislider lightr 0 255
    guislider lightg 0 255
    guislider lightb 0 255
    guilist [
        guicheckbox "bright"    lightbright 1 0 [lightscale]
        guibar
        guiradio "white"        lightcolour 0 [lightset 255 255 255]
        guiradio "blue"         lightcolour 1 [lightset 192 192 255]
        guiradio "red"          lightcolour 2 [lightset 255 192 192]
        guiradio "green"        lightcolour 3 [lightset 192 255 192]
        guiradio "yellow"       lightcolour 4 [lightset 255 255 192]
        guiradio "purple"       lightcolour 5 [lightset 255 192 255]
        guiradio "turquoise"    lightcolour 6 [lightset 192 255 255]
    ]
    guitext "radius:"
    guislider lightradius 0 512
]

newgui newteleport [
    guibutton "newent teleport 1"
    guibutton "newent teledest 1"
    guibutton "newent teleport 2"
    guibutton "newent teledest 2"
    guibutton "newent teleport 3"
    guibutton "newent teledest 3"
    guibutton "newent teleport 4"
    guibutton "newent teledest 4"
]

newgui mapmodels [
    loop i (div (+ (nummapmodels) (- 17 1)) 17) [
        if (> $i 0) [
            guitab (+ $i 1)
        ]
        guilist [
            guilist [
                loop j (min (- (nummapmodels) (* $i 17)) 17) [
                    mmidx = (+ (* $i 17) $j)
                    mmname = (mapmodelname $mmidx) 
                    if (= (strstr $mmname "mapmodels") 0) [
                        mmname = (substr $mmname 10)
                    ]
                    guibutton $mmname [newent mapmodel @mmidx]
                ]
            ]
            guispring
            guibar
            guimodelpreview (mapmodelname (at $guirolloveraction 2)) "mapmodel" $guirolloveraction 4 1
        ]
    ]
]

newgui monsters [
    guibutton "ogro / fireball"      "newent monster 0"
    guibutton "rhino / chaingun"      "newent monster 1"
    guibutton "ratamahatta / shotgun"      "newent monster 2"
    guibutton "slith / rifle" "newent monster 3"
    guibutton "bauul / RL"     "newent monster 4"
    guibutton "hellpig / bite"       "newent monster 5"
    guibutton "knight / iceball" "newent monster 6"
    guibutton "goblin / slimeball"   "newent monster 7"
    guibutton "spider / grenade"    "newent monster 8"
]

newgui postfx [
    guibutton "(effect OFF)"          "clearpostfx"
    guibutton "bloom (subtle: 30%)"    "bloom 0.3"
    guibutton "bloom (bright: 55%)"    "bloom 0.55"
    guibutton "bloom (intense: 80%)"  "bloom 0.8"
    guibutton "rotoscope" "rotoscope 1"
    guibutton "rotoscope + blur3" "rotoscope 1 1"
    guibutton "rotoscope + blur5" "rotoscope 1 2"
    guibutton "sobel"  "setpostfx sobel"
    guibutton "invert" "setpostfx invert"
    guibutton "gbr"    "setpostfx gbr"
    guibutton "bw"     "setpostfx bw"
    guibutton "blur3"  "setpostfx hblur3; addpostfx vblur3"
    guibutton "blur5"  "setpostfx hblur5; addpostfx vblur5"
]

macro resbutton [
    guibutton "%1x%2" "screenres %1 %2" (if (&& (= $scr_w %1) (= $scr_h %2)) [result "radio_on"] [result "radio_off"])
]

newgui options [
    guicheckbox "show FPS" showfps
    guilist [
        guicheckbox "wall clock" wallclock
        if $wallclock [
            guibar
            guicheckbox "24 hour" wallclock24
            guibar
            guicheckbox "seconds" wallclocksecs
        ]
    ]
    guicheckbox "2D menus" gui2d
    guicheckbox "show scoreboard at death" deathscore
    guilist [
        guicheckbox "damage screen"     damagescreen
        guibar
        guicheckbox "damage compass"    damagecompass
    ]
	guilist [
    	guicheckbox "hudguns"       hudgun
		if $hudgun [
			guibar
			guicheckbox "sway"		hudgunsway
            guibar
            guicheckbox "muzzle flash" muzzleflash
            guibar
            guicheckbox "muzzle light" muzzlelight
		]
	]
    guicheckbox "blood"             blood
    guilist [
        guicheckbox "ragdoll deaths"    ragdoll
        if $ragdoll [
            guibar
            guicheckbox "keep after respawn" ragdollmillis 10000
        ]
        guibar
        guicheckbox "hide dead players" hidedead
    ]
    guitext "ragdoll velocity multiplier"
    guislider deadpush
    guilist [
        guicheckbox "fullbright player models" fullbrightmodels 60 0
        if $fullbrightmodels [
            guibar
            guiradio "subtle" fullbrightmodels 60
            guibar
            guiradio "bright" fullbrightmodels 100
            guibar
            guiradio "overbright" fullbrightmodels 150
            guibar
            guiradio "max" fullbrightmodels 200
        ]
    ]
    guilist [
        guicheckbox "force matching player models" forceplayermodels
        guibar
        guicheckbox "always use team skins" teamskins
    ]
    guilist [
        guicheckbox "outline capture meters" outlinemeters
        guibar
        guicheckbox "numbered capture bases" basenumbers
        guibar
        guicheckbox "show teammates" radarteammates 1
    ]
    guicheckbox "hit sound" hitsound
    guilist [
        guicheckbox "crosshair color effects" crosshairfx
        if $crosshairfx [
            guibar
            guicheckbox "teammates" teamcrosshair
            guibar
            guicheckbox "hits" hitcrosshair 425
        ]
    ]

    guibar
    guibutton "restore defaults (clears ALL settings)" "exec restore.cfg"

    guitab    "gfx"
    guitext "performance key: ^f0fast^f~, ^f2moderate^f~, ^f3slow and pretty^f~"
    guibar
    if (&& (< $shaders 0) (= $renderpath 0)) [
        guicheckbox "^f2shaders		"			shaders 1 -1
    ] [
		guilist [
        	guicheckbox "^f2shaders		"           shaders
	    	if $shaders [
            	guibar
            	guiradio "^f0low detail" shaderdetail 1
            	guibar
            	guiradio "^f2high detail" shaderdetail 3
                //if $hasglsl [
                //    guibar
                //    guicheckbox "^f3GLSL only" forceglsl
                //]
	    	]
		]
    ]
    guilist [
        guitext "water		"
        guibar
        guicheckbox "^f2refraction"  waterrefract
        guibar
        guicheckbox "^f3reflection"  waterreflect
        guibar
        guicheckbox "^f0caustics"    caustics
        guibar
        guicheckbox "^f0animation" vertwater
    ]
	if (> $renderpath 0) [
		guilist [
			guitext "waterfalls		"
			guibar
			guicheckbox "^f2refraction" waterfallrefract
			guibar
			guicheckbox "^f0reflection" waterfallenv
		]
	]
    if (= $renderpath 0) [
        guilist [
            guicheckbox "^f3shadow maps	"  shadowmap
            if $shadowmap [
                guibar
                guiradio "^f2medium quality" shadowmapsize 9 [blurshadowmap 1]
                guibar
                guiradio "^f3high quality" shadowmapsize 10 [blurshadowmap 2]
            ] [
                guibar
                guicheckbox "^f0blob shadows" blobs
            ]
        ]
        if (>= $maxtmus 3) [
            guicheckbox "^f2dynamic lights  "    ffdynlights 5 0
        ]
    ] [
		guilist [
        	guicheckbox "^f3soft shadows	"  shadowmap
			if $shadowmap [
                guibar
        	    guiradio "^f2medium quality" shadowmapsize 9 [blurshadowmap 1]
    	        guibar
	            guiradio "^f3high quality" shadowmapsize 10 [blurshadowmap 2]
			] [
				guibar
				guicheckbox "^f0blob shadows" blobs
			]
    	]
    	if $glare [
        	glarepreset = 0
        	if (= $glarescale 1) [
            	if (= $blurglare 4) [glarepreset = 1]
            	if (= $blurglare 7) [glarepreset = 3]
        	]
        	if (= $glarescale 2) [
            	if (= $blurglare 3) [glarepreset = 2]
            	if (= $blurglare 7) [glarepreset = 4]
        	]
        	guilist [
            	guicheckbox "^f3glare			"       glare
            	guibar
            	guiradio "^f2subtle" glarepreset 1 [blurglare 4; glarescale 1]
            	guibar
            	guiradio "^f2glowy" glarepreset 2 [blurglare 3; glarescale 2]
            	guibar
            	guiradio "^f3soft" glarepreset 3 [blurglare 7; glarescale 1]
            	guibar
            	guiradio "^f3intense" glarepreset 4 [blurglare 7; glarescale 2]
        	]
    	] [
        	guicheckbox "^f3glare"         glare
    	]
    ]
    if $usetexrect [
        guilist [
            guicheckbox "^f3motion blur	" motionblur
            if $motionblur [
                guibar
                guiradio "^f3subtle" motionblurscale 0.5
                guibar
                guiradio "^f3moderate" motionblurscale 0.65
                guibar
                guiradio "^f3intense" motionblurscale 0.8
            ]
        ]
    ]
    guilist [
        guicheckbox "^f3grass			" grass
		if $grass [
			guibar
			guiradio "^f2quick fade" grassdist 128
			guibar
			guiradio "^f2moderate fade" grassdist 256
			guibar
			guiradio "^f3slow fade" grassdist 512
		]
	]
    if (> $renderpath 0) [
        guilist [
            guicheckbox "^f0dynamic lights	"    maxdynlights 3 0
            if $maxdynlights [
                guibar
                guiradio "^f0medium quality" maxdynlights 3
                guibar
                guiradio "^f2high quality" maxdynlights 5
            ]
        ]
        guilist [
            guicheckbox "^f0soft particles	" depthfx
            if $depthfx [
                guibar
                guiradio "^f0low quality" depthfxsize 7 [depthfxrect 0; depthfxfilter 1; blurdepthfx 1]
                guibar
                guiradio "^f2medium quality" depthfxsize 10 [depthfxrect 1; depthfxfilter 0; blurdepthfx 0]
                guibar
                guiradio "^f3high quality" depthfxsize 12 [depthfxrect 1; depthfxfilter 0; blurdepthfx 0]
            ]
        ]
	]
    guicheckbox "^f0glass reflection"  glassenv
    guilist [
        guicheckbox "^f0decals		" decals
        if $decals [
            guibar
            guiradio "^f0quick fade" decalfade 10000 [maxdecaltris 1024]
            guibar
            guiradio "^f2slow fade" decalfade 60000 [maxdecaltris 4096]
        ]
    ]
    guicheckbox "^f0fix t-joints (world sparklies)" filltjoints
    guilist [
        guitext "textures		"
        guibar
        guiradio "^f0low quality" maxtexsize 256
        guibar
        guiradio "^f0medium quality" maxtexsize 512
        guibar
        guiradio "^f2high quality" maxtexsize 0
    ]
    guilist [
        guitext "models		"
        guibar
        guicheckbox "^f0lighting"    lightmodels
        guibar
        guicheckbox "^f0reflection"  envmapmodels
        guibar
        guicheckbox "^f0glow"        glowmodels
        if (> $renderpath 0) [
            guibar
            guicheckbox "^f2bumpmap" bumpmodels
        ]
    ]
    guilist [
        guitext "animation		"
        guibar
        guiradio "^f0medium quality" matskel 1
        guibar
        guiradio "^f0high quality" matskel 0
    ]

    guitab    "display"
    guicheckbox "v-sync"            vsync 1 0
    guicheckbox "fullscreen"        fullscreen
    guitext "gamma (default: 100)"
    guislider gamma
    guitext "full-scene anti-aliasing (default: -1)"
    guilistslider fsaa "-1 0 2 4 8 16"
    guitext "color depth (default: 0)"
    guilistslider colorbits "0 16 24 32"
    guitext "z-buffer depth (default: 0)"
    guilistslider depthbits "0 16 24 32"
    guitext "stencil bits (default: 0)"
    guislider stencilbits
    guitext "anisotropic filtering (default: 0)"
    guilistslider aniso "0 2 4 8 16"
	guilist [
    	guicheckbox "bilinear filtering" bilinear
		guibar
		guicheckbox "trilinear filtering (mipmaps)" trilinear
	]

    guitab   "res"
    guitext "field of view (default: 100)"
    guislider fov
    guistayopen [
      guilist [
        guilist [
            guitext "4:3"
            @@@@(resbutton 320 240)
            @@@@(resbutton 640 480)
            @@@@(resbutton 800 600)
            @@@@(resbutton 1024 768)
            @@@@(resbutton 1152 864)
            @@@@(resbutton 1280 960)
            @@@@(resbutton 1400 1050)
            @@@@(resbutton 1600 1200)
            @@@@(resbutton 1792 1344)
            @@@@(resbutton 1856 1392)
            @@@@(resbutton 1920 1440)
            @@@@(resbutton 2048 1536)
            @@@@(resbutton 2800 2100)
            @@@@(resbutton 3200 2400)
        ]
        guibar
        guilist [
            guitext "16:10"
            @@@@(resbutton 320 200)
            @@@@(resbutton 640 400)
            @@@@(resbutton 1024 640)
            @@@@(resbutton 1280 800)
            @@@@(resbutton 1440 900)
            @@@@(resbutton 1600 1000)
            @@@@(resbutton 1680 1050)
            @@@@(resbutton 1920 1200)
            @@@@(resbutton 2048 1280)
            @@@@(resbutton 2560 1600)
            @@@@(resbutton 3840 2400)
        ]
        guibar
        guilist [
            guitext "16:9"
            @@@@(resbutton 1024 600)
            @@@@(resbutton 1280 720)
            @@@@(resbutton 1366 768)
            @@@@(resbutton 1600 900)
            @@@@(resbutton 1920 1080)
            @@@@(resbutton 2048 1152)
            @@@@(resbutton 3840 2160)
        ]
        guibar
        guilist [
            guitext "5:4"
            @@@@(resbutton 600 480)
            @@@@(resbutton 1280 1024)
            @@@@(resbutton 1600 1280)
            @@@@(resbutton 2560 2048)
        ]
        guibar
        guilist [
            guitext "5:3"
            @@@@(resbutton 800 480)
            @@@@(resbutton 1280 768)

            guibar
            guitext "Custom"
            guilist [
                customw = $scr_w
                customh = $scr_h
                guifield customw 4 [scr_w $customw]
                guifield customh 4 [scr_h $customh]
            ]
        ]
      ]
    ]

    guitab   "sound"
    guitext "sound volume"
    guislider soundvol
    guitext "music volume"
    guislider musicvol
    guitext "sound channels"
    guislider soundchans
    guitext "sound frequency"
    guilistslider soundfreq "11025 22050 44100"
    guitext "sound buffer length"
    guislider soundbufferlen
    guicheckbox "Mumble positional audio" mumble

    guitab  "mouse"
    guicheckbox "invert mouse"      invmouse

    guilist [
        guitext "mouse sensitivity: "
        newsens = $sensitivity
        guifield newsens 8 [sensitivity $newsens]
    ]

    guilist [
        guitext "mouse UI sensitivity: "
        newguisens = $guisens
        guifield newguisens 8 [guisens $newguisens]
    ]

    guilist [
        guibutton "crosshair: " [showgui crosshair]
        guiimage (getcrosshair) [showgui crosshair] 0.5
    ]
    guitext "crosshair size"
    guislider crosshairsize

    guitab "keys"
    guitext "(basic keybinds, for anything more use the 'bind' command)"
    guitext "select action to bind and press desired keys (ESC when done):"

    guilistsplit n 2 $bindactions [
        guilist [
            guitext (tabify (concatword $n ": ") 4)
            [newbinds@i] = (searchbinds $n)
            guikeyfield [newbinds@i] -9 [
                oldbinds = (searchbinds [@@n])
                looplist j $oldbinds [bind $j ""]
                looplist j $[newbinds@@i] [bind $j [@@@n]]
            ]
        ]
    ] [guibar]

    guitab "console"
    guicheckbox "chat console" miniconfilter 0x300 0
    guitext "console size (lines)"
    guislider consize
    guitext "console filter:"
    guilist [
        guilist [
            guibitfield "important information" confilter 0x01
            guibitfield "warnings" confilter 0x02
            guibitfield "errors" confilter 0x04
            guibitfield "init messages" confilter 0x10
            guibitfield "script messages" confilter 0x20
	    ]
        guibar
        guilist [
            guibitfield "chat" confilter 0x100
            guibitfield "team chat" confilter 0x200
            guibitfield "game events" confilter 0x400
            guibitfield "self frags" confilter 0x800
            guibitfield "other player frags" confilter 0x1000
        ]
        guibar
        guilist [
            guibitfield "team kills" confilter 0x2000
        ]
    ]
    guitext "full console size (percent of screen)"
    guislider fullconsize
    guitext "full console filter:"
    guilist [
        guilist [
            guibitfield "important information" fullconfilter 0x01
            guibitfield "warnings" fullconfilter 0x02
            guibitfield "errors" fullconfilter 0x04
            guibitfield "init messages" fullconfilter 0x10
            guibitfield "script messages" fullconfilter 0x20
        ]
        guibar
        guilist [
            guibitfield "chat" fullconfilter 0x100
            guibitfield "team chat" fullconfilter 0x200
            guibitfield "game events" fullconfilter 0x400
            guibitfield "self frags" fullconfilter 0x800
            guibitfield "other player frags" fullconfilter 0x1000
        ]
        guibar
        guilist [
            guibitfield "team kills" fullconfilter 0x2000
        ]
    ]

    guitab "autoexec.cfg"
    guitext "autoexec.cfg"
    showfileeditor "autoexec.cfg" -60 15
] "game"

bindactions = [forward backward left right jump attack togglezoom saycommand sayteamcommand showscores toggleconsole screenshot edittoggle "setweapon FI" "setweapon SG" "setweapon CG" "setweapon RL" "setweapon RI" "setweapon GL" "setweapon PI" "weapon" "universaldelta 1" "universaldelta -1" dropflag addbot delbot]

entupdate = [ entset $entguitype $entguiattr0 $entguiattr1 $entguiattr2 $entguiattr3 $entguiattr4 ]

initentgui = [
  entguitype = (enttype)
  @(loopconcat i 5 [result [
    entguiattr@i = (entattr @i)
  ]])
]

genentattributes = [
    entattributes = (loopconcat i (listlen $arg2) [
        entattribname = (at $arg2 $i)
        entattriblimits = (at $arg3 (* 2 $i))
        entattriblimits2 = (at $arg3 (+ 1 (* 2 $i)))
        if (=s (at $entattriblimits 0) $entattriblimits) [
            result [
                guitext @entattribname
                guislider entguiattr@i @entattriblimits @entattriblimits2 entupdate
            ]
        ] [
            result [
                guitext @entattribname
                guinameslider entguiattr@i [@@entattriblimits] [@@entattriblimits2] entupdate
            ]
        ]
    ])
]

guilistsplit = [
  guilist [
    i = 0
    l = (listlen $arg3)
    z = (div (+ $l (- $arg2 1)) $arg2)
    loop a $arg2 [
      guilist [
        t = (min (+ $i $z) $l)
        while [< $i $t] [
          $arg1 = (at $arg3 $i)
          arg4
          i = (+ $i 1)
        ]
      ]
      if (&& (>= $numargs 5) (< (+ $a 1) $arg2)) [arg5]
    ]
  ]
]

quickeditmenu = [
  guitext "Quick Commands:"
  guibar
  guifield  savemap_name 10 [ savemap $savemap_name ]
  guibutton "quick light"       "calclight -1"
  guibutton "optimize map"      "remip"
  guibutton "new entity"        "newent shells"
  guibar
  guibutton newmap
  guibar
  guibutton help "showgui editing"
]

matmenu = [
    guibutton "air"                        "editmat air"
    guibutton "water"                      "editmat water"
    guibutton "lava"                       "editmat lava"
    guibutton "clip"                       "editmat clip"
    guibutton "glass"                      "editmat glass"
    guibutton "noclip"                     "editmat noclip"
    guibutton "gameclip"                   "editmat gameclip"
    guibutton "death"                      "editmat death"
    guibutton "alpha"                      "editmat alpha"
    guicheckbox "show material volumes"    showmat
]

brushmenu = [
  guilist [ // diamonds
  guiimage "packages/icons/brush_1c.png" brush_0
  guiimage "packages/icons/brush_21c.png" brush_1
  guiimage "packages/icons/brush_421c.png" brush_2
  ]
  guilist [ // squares
  guiimage "packages/icons/brush_3s.png" brush_3
  guiimage "packages/icons/brush_5s.png" brush_4
  guiimage "packages/icons/brush_7s.png" brush_5
  ]
  guititle smooth
  guilist [ // smooth
  guiimage "packages/icons/brush_3s.png" brush_6
  guiimage "packages/icons/brush_5s.png" brush_7
  guiimage "packages/icons/brush_7s.png" brush_8
  ]
]

newentgui = [
  genentattributes $arg1 $arg2 $arg3
  newgui $arg1 [
    guitext $entguitype
    guibar
    @entattributes
    guitab type
    guilistsplit n 2 $enttypelist [
        guibutton $n [ entset @n ]
    ]
    guitab misc
    @quickeditmenu
  ] "" [initentgui]
]

looplist i $enttypelist [
  newentgui $i "" ""
]

newgui materials [
  @matmenu
  guitab misc
  @quickeditmenu
]

newgui brushes [
  @brushmenu
  guitab misc
  @quickeditmenu
]

newgui quickedit [
  @quickeditmenu
  guitab materials
  @matmenu
]

newentgui light "radius red green blue" "0 400 0 255 0 255 0 255"
newentgui spotlight "radius" "0 200"
newentgui playerstart "direction" "0 360"
newentgui teleport "tag" "0 20"
newentgui teledest "direction tag" "0 360 0 20"
newentgui monster "direction type" "0 360 0 7"
newentgui mapmodel "direction model" "0 360 0 100"
newentgui envmap "radius" "0 400"
newentgui jumppad "Z Y X" "0 200 0 200 0 200"
newentgui sound "type radius size" "0 20 0 500 0 500"
newentgui particles "type" "0 3"

contexteditgui = [
    if $hmapedit [showgui brushes] [
        if (enthavesel) [
            showgui (enttype)
        ] [showgui (? (havesel) materials quickedit)]
    ]
]

showentgui = [ contexteditgui ] // legacy bind

newgui seltexinfo [
    guitext (concatword "Slot: " (getseltex))
    guilist [ loop x 5 [
        texname = (gettexname (getseltex) $x)
        texname = (substr $texname (+ (strstr $texname ">") 1)) // chop off any leading commands
        guiimage (concatword "packages/" $texname) "" 1 1
    ]]
    loop x 5 [ tex = (gettexname (getseltex) $x); if (strcmp $tex "") [] [guitext $tex]]
]
