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

exec "config/ui/lib.cfg"           // UI library
exec "config/ui/style.cfg"         // Styles
exec "config/ui/scoreboard.cfg"    // Scoreboard
exec "config/ui/edithud.cfg"       // Edit HUD
exec "config/ui/fkey.cfg"          // F# Key Menus
exec "config/ui/serverbrowser.cfg" // Server Browser
exec "config/ui/stats.cfg"         // Player Stats
exec "config/ui/options.cfg"       // Options Menu

reui = [
   exec "config/ui.cfg"
]

togglemainmenu = [|| hidetopui [toggleui main]]

bind ESCAPE [togglemainmenu]

///////////////////////////////////////////////////////////////////////////////
//  Main                                                                     //
///////////////////////////////////////////////////////////////////////////////
UImenu "main" [
   uieschide (! $mainmenu)
   uihlist 0 [
      uivlist 0 [
         UIbutton "hold2" [uitext "Server Browser" 0.65] 0.2 0.04 [hideui "main" ; showui "server_browser"]
         UIbutton "hold2" [uitext "Map Browser"    0.65] 0.2 0.04 [hideui "main" ; showui "map_browser"]
         uifill 0.2 0.02 [UIbar 1]
         UIbutton "hold2" [uitext "Player Setup"   0.65] 0.2 0.04 [hideui "main" ; showui "player_setup"]
         UIbutton "hold2" [uitext "Options"        0.65] 0.2 0.04 [hideui "main" ; showui "options"]
         if $mainmenu [
            UIbutton "hold2" [uitext "Credits"     0.65] 0.2 0.04 [hideui "main" ; showui "credits"]
         ]
         uifill 0.2 0.02 [UIbar 1]
         UIbutton "hold2" [uitext "Quit"           0.65] 0.2 0.04 [quit]
      ]
      if (! $mainmenu) [
         uifill 0.02 0.24 [UIbar 0 1]
         uivlist 0 [
            if (isspectator $getclientnum) [
               if $scoreboardmultiplayer [
                  if (ismaster $getclientnum) [
                     UIbutton "hold2" [uitext "Play" 0.65] 0.2 0.04 [hideui "main" ; spectator 0]
                  ] [
                     if (> $getmastermode 1) [
                        uifill 0 0.04 [uitext "^f4Play" 0.65]
                     ] [
                        UIbutton "hold2" [uitext "Play" 0.65] 0.2 0.04 [hideui "main" ; spectator 0]
                     ]
                  ]
               ] [
                  UIbutton "hold2" [uitext "Play" 0.65] 0.2 0.04 [hideui "main" ; spectator 0]
               ]
            ] [
               UIbutton "hold2" [uitext "Spectate" 0.65] 0.2 0.04 [hideui "main" ; spectator 1]
            ]
            case $getteam [
               0] [uifill 0 0.04] [
               1] [UIbutton "hold2" [uitext "Join ^f3Rojo" 0.65] 0.2 0.04 [team rojo]] [
               2] [UIbutton "hold2" [uitext "Join ^f1Azul" 0.65] 0.2 0.04 [team azul]]
            uifill 0.2 0.02 [UIbar 1]
            if $scoreboardmultiplayer [
               UIbutton "hold2" [uitext "Master" 0.65] 0.2 0.04 [hideui "main" ; showui "master"]
               if (ismaster $getclientnum) [
                  UIbutton "hold2" [uitext "Bots" 0.65] 0.2 0.04 [hideui "main" ; showui "bots"]
               ] [
                  uifill 0 0.04
               ]
            ] [
               uifill 0 0.04
               UIbutton "hold2" [uitext "Bots" 0.65] 0.2 0.04 [hideui "main" ; showui "bots"]
            ]
            uifill 0.2 0.02 [UIbar 1]
            UIbutton "hold2" [uitext "Disconnect" 0.65] 0.2 0.04 [disconnect]
         ]
      ]
   ]
]

///////////////////////////////////////////////////////////////////////////////
//  Player Setup                                                             //
///////////////////////////////////////////////////////////////////////////////
UI_pmodel  = 0
UI_pteam   = 0
UI_pweapon = 1

UImenu "player_setup" [
   uihlist 0.01 [
      uivlist 0 [
         uiplayerpreview $UI_pmodel (case $UI_pteam 0 $playercolor 1 $playercolorazul 2 $playercolorrojo) $UI_pteam $UI_pweapon 0.4 0.5 [
            style_generic_default
            uiclamp* 1 1 1 1
         ]
         uihlist 0 [
            uiclamp 1 1
            UIbutton "" [
               UIradio [= $UI_pweapon 0] 0.016
               uitext "Railgun" 0.6
            ] 0 0.032 [UI_pweapon = 0] -1
            UIbutton "" [
               UIradio [= $UI_pweapon 1] 0.016
               uitext "Pulse Rifle" 0.6
            ] 0 0.032 [UI_pweapon = 1] -1
            uiclamp* 1 1
         ]
      ]
      uivlist 0.01 [
         uialign -2 -1
         uivlist 0.0037 [
            uitext "Name" 0.7
            uifield name 15 [] 0.7 [uioutline (uifocus? $c_focus $c_line); uiclamp- 1 1 1 1]
         ]
         looplist3 v t l [
            "playercolor"     0 9
            "playercolorazul" 1 4
            "playercolorrojo" 2 4
         ] [
            uivlist 0.0037 [
               case $t 1 [
                  uitext "^f8Azul" 0.7
               ] 2 [
                  uitext "^f3Rojo" 0.7
               ] () [uitext "Solo" 0.7]
               uigrid (? (< $t 1) 3 2) 0.005 0.005 [
                  local color
                  uihover [UI_pteam = $t]
                  loop i $l [
                     color = (getplayercolor $i $t)
                     uicolor $color 0.0458 0.0458 [
                        uioutline (? (= $$v $i) $c_fill $color)
                        uiclamp- 1 1 1 1
                        uipress [$v $i]
                     ]
                  ]
               ]
            ]
         ]
      ]
   ]
] [] [] [] "Player Setup"

///////////////////////////////////////////////////////////////////////////////
//  Credits                                                                  //
///////////////////////////////////////////////////////////////////////////////
UI_creditlist = [
   UItitle [
      uispace 0.015 0 [
         uialign -1 -2
         uihlist 0.01 [
            uiimage "media/interface/cube.png" 0.03 0.03
            uitext [@@@@arg1] 0.7
         ]
      ]
   ] 0 0.032
   uispace 0.03 0 [
      uifill 0 0 [
         uiclamp 1 1
         uimodhgradient 0xC0C0C0 0xFFFFFF
         uiclamp- 1 1 1 1
         uispace 0.02 0.01 [
            uialign -1 -2
            uivlist 0 [
               looplist i $arg2 [
                  uiwraptext (strreplace (strreplace $i "^"" "^fs^f8^"" "^"^fr") ": " "^f4: ") 0.69 0.6
               ]
               uialign* -1 -2
            ]
         ]
      ]
   ]
   uifill 0 0.02
]

UImenu "credits" [
   uihlist 0.01 [
      uiscroll 0.8 0.8 [
         uifill 0.77
         uivlist 0.0008 [
            uiclamp 1 1
            uialign -2 -1
            // Alphabetized by alias
            UI_creditlist "Project" [
               [Lee "eihrul" Salzman : Code Gatekeeper]
               [Shane "Nieb" Nieb : Media Gatekeeper]
            ]
            UI_creditlist "Code" [
               [Lee "eihrul" Salzman]
               [Benjamin Segovia]
               [Kevin "Hirato Kirata" Meyer]
            ]
            UI_creditlist "Art" [
               [Shane "Nieb" Nieb : Playermodel, Mapmodels, Textures]
            ]
            UI_creditlist "Sound" [
               [Dylan "Dacker" Ackerly]
               [Shane "Nieb" Nieb]
               [Sławomir "Q009" Błauciak]
               [Jannic "Uphys" Böhme]
            ]
            UI_creditlist "Cartography" [
               [Dylan "Dacker" Ackerly : complex]
               [Shane "Nieb" Nieb : complex, test_ctf]
               [Sławomir "Q009" Błauciak : steelribs]
               [Jack "Pritchard" Viney : alphacorp]
               [Kurt Kessler : waterworks]
               [James 'Skur' Rucks : reflection]
               [Yannick 'Snowy' Weber : reflection]
            ]
            UI_creditlist "Miscellaneous" [
               [Kevin "Hirato Kirata" Meyer : CubeScript Documentation]
               [Shane "Nieb" Nieb : UI Design, Tesseract Website]
               [Daniel "q66" Kolesa : Build-system Improvements]
               ["RaZgRiZ" : UI Documentation, UI Design]
            ]
            UI_creditlist "Cube Engine 2" [
               [Wouter "Aardappel" van Oortmerssen]
               [Lee "eihrul" Salzman]
               [Mike "Gilt" Dysart]
               [Robert "baby-rabbit" Pointon]
               [Quinton "Quin" Reeves]
               [John "geartrooper" Siar]
               [and others...]
               "http://sauerbraten.org/"
            ]
            uiclamp* 1 1
         ]
      ]
      UIvscroll 0.02 0.8 2.0
   ]
] [] [] [] "Tesseract Contributors"

///////////////////////////////////////////////////////////////////////////////
//  Master                                                                   //
///////////////////////////////////////////////////////////////////////////////
menu_master = [if $isconnected [if $scoreboardmultiplayer [toggleui "master"]]]

UImenu "master" [
   uifill 0 0 [
      uivlist 0 [
         uihlist 0.01 [
            if (ismaster $getclientnum) [
               UIbutton "" [uitext "Relinquish Master" 0.65] 0.24 0.06 [setmaster 0]
            ] [
               if (issomeoneelsemaster) [
                  UIbutton "" [uitext "^f4Claim Master" 0.65] 0.24 0.06 []
               ] [
                  UIbutton "" [uitext "Claim Master" 0.65] 0.24 0.06 [setmaster 1]
               ]
            ]
            if (ismaster $getclientnum) [
               uigrid 2 0 0 [
                  looplist2 n i [
                     "^f0open ^f4(0)"   0 "^f0veto ^f4(1)"    1
                     "^f2locked ^f4(2)" 2 "^f3private ^f4(3)" 3
                  ] [
                     UIbutton "" [
                        UIradio [= $getmastermode $i] 0.016
                        uitext $n 0.6
                     ] 0.16 0.03 [mastermode $i] -1
                  ]
               ]
               uivlist 0 [
                  UIbutton "" [uitext "Clearbans" 0.65] 0.16 0.03 [clearbans]
                  UIbutton "" [uitext "Bots" 0.65] 0.16 0.03 [hideui "main" ; showui "bots"]
               ]
            ] [
               uifill 0.49
            ]
         ]
         uifill 0 0.02 [UIbar 1 ; uiclamp 1 1 1 1]
         if (ismaster $getclientnum) [
            if (> $getmode 2) [UI_clientlistteam] [UI_clientlistsolo]
         ] [
            if (> $getmode 2) [uifill 1.43 0.312] [uifill 0 0.624]
         ]
      ]
   ]
] [] [] [] "Master"

UI_clientlistsolo = [
   uihlist 0 [
      uiscroll 0.71 0.624 [
         uifill 0.71 0.624 [
            uitable 0 0 [
               UI_mlc = 0
               looplist cn (listclients 1 0) [
                  uitablerow [
                     uifill 0.078 0.026 [
                        uicolortext (concatword $cn " : ") (scoreboardstatus $cn) 0.57
                        uialign- 1
                     ]
                     uifill 0.362 0.026 [
                        uicolortext (getclientcolorname $cn) (scoreboardstatus $cn) 0.57
                        uialign- -1
                     ]
                     if (= $cn $getclientnum)[
                        uifill 0.077 0.026
                     ] [
                        UIbutton "hold2" [
                           UItriangle 0xCCCCCC 0.01 0.01 270
                           uitext "Kick" 0.57
                        ] 0.077 0.026 [kick @cn] -1
                     ]
                     UIbutton "hold2" [
                        UIradio [= (isspectator $cn) 1] 0.016
                        uitext "Spec" 0.57
                     ] 0.087 0.026 [spectator @(= (isspectator $cn) 0) @cn] -1
                     UIbutton "hold2" [
                        UIradio [= (ismaster $cn) 1] 0.016
                        uitext (concatword (? (isadmin $cn) "Admin" (? (isauth $cn) "Auth" "Master"))) 0.57
                     ] 0.105 0.026 [setmaster (? (ismaster $cn) 0 1) @cn] -1
                  ] [
                     UI_mlc = (! $UI_mlc)
                     uicolor (? $UI_mlc 0x99323232 0x99262626) 0 0 [
                        uiclamp 1 1 1 1
                        pushif highlight (scoreboardhighlight $cn) [
                           uioutline 0xA0A0A0 ; uiclamp- 1 1 1 1
                        ]
                     ]
                  ]
               ]
            ]
            uialign* -1 -1
         ]
      ]
      uifill 0.01
      UIvscroll 0.02 0.624 1.56
   ]
]

UI_clientlistteam = [
   uihlist 0 [
      uiscroll 1.4 0.312 [
         uifill 1.4 0.312 [
            uihlist 0 [
               uialign 0 -1
               uitable 0 0 [
                  uifill 0.695
                  UI_mlc = 0
                  looplist cn (listclients 1 0) [
                     if (= (getclientteam $cn) 1) [
                        uitablerow [
                           uifill 0.078 0.026 [
                              uicolortext (concatword $cn " : ") (scoreboardstatus $cn) 0.57
                              uialign- 1
                           ]
                           uifill 0.26 0.026 [
                              uicolortext (getclientcolorname $cn) (scoreboardstatus $cn) 0.57
                              uialign- -1
                           ]
                           if (= $cn $getclientnum)[
                              uifill 0.077 0.026
                           ] [
                              UIbutton "hold2" [
                                 UItriangle 0xCCCCCC 0.01 0.01 270
                                 uitext "Kick" 0.57
                              ] 0.077 0.026 [kick @cn] -1
                           ]
                           UIbutton "hold2" [
                              UItriangle 0xCCCCCC 0.01 0.01 270
                              uitext "Team" 0.57
                           ] 0.0875 0.026 [setteam @cn @(? (=s (getclientteam $cn) "1") "2" "1")] -1
                           UIbutton "hold2" [
                              UIradio [= (isspectator $cn) 1] 0.016
                              uitext "Spec" 0.57
                           ] 0.087 0.026 [spectator @(= (isspectator $cn) 0) @cn] -1
                           UIbutton "hold2" [
                              UIradio [= (ismaster $cn) 1] 0.016
                              uitext (concatword (? (isadmin $cn) "Admin" (? (isauth $cn) "Auth" "Master"))) 0.57
                           ] 0.105 0.026 [setmaster (? (ismaster $cn) 0 1) @cn] -1
                        ] [
                           UI_mlc = (! $UI_mlc)
                           uicolor (? $UI_mlc 0x99333b40 0x99262b33) 0 0 [
                              uiclamp 1 1 1 1
                              pushif highlight (scoreboardhighlight $cn) [
                                 uioutline 0xA0A0A0 ; uiclamp- 1 1 1 1
                              ]
                           ]
                        ]
                     ]
                  ]
               ]
               uifill 0.01
               uitable 0 0 [
                  uifill 0.695
                  UI_mlc = 0
                  looplist cn (listclients 1 0) [
                     if (= (getclientteam $cn) 2) [
                        uitablerow [
                           uifill 0.078 0.026 [
                              uicolortext (concatword $cn " : ") (scoreboardstatus $cn) 0.57
                              uialign- 1
                           ]
                           uifill 0.26 0.026 [
                              uicolortext (getclientcolorname $cn) (scoreboardstatus $cn) 0.57
                              uialign- -1
                           ]
                           if (= $cn $getclientnum)[
                              uifill 0.077 0.026
                           ] [
                              UIbutton "hold2" [
                                 UItriangle 0 0.01 0.01 270
                                 uitext "Kick" 0.57
                              ] 0.077 0.026 [kick @cn] -1
                           ]
                           UIbutton "hold2" [
                              UItriangle 0 0.01 0.01 270
                              uitext "Team" 0.57
                           ] 0.0875 0.026 [setteam @cn @(? (=s (getclientteam $cn) "1") "2" "1")] -1
                           UIbutton "hold2" [
                              UIradio [= (isspectator $cn) 1] 0.016
                              uitext "Spec" 0.57
                           ] 0.087 0.026 [spectator @(= (isspectator $cn) 0) @cn] -1
                           UIbutton "hold2" [
                              UIradio [= (ismaster $cn) 1] 0.016
                              uitext (concatword (? (isadmin $cn) "Admin" (? (isauth $cn) "Auth" "Master"))) 0.57
                           ] 0.105 0.026 [setmaster (? (ismaster $cn) 0 1) @cn] -1
                        ] [
                           UI_mlc = (! $UI_mlc)
                           uicolor (? $UI_mlc 0x99403333 0x99332626) 0 0 [
                              uiclamp 1 1 1 1
                              pushif highlight (scoreboardhighlight $cn) [
                                 uioutline 0xA0A0A0 ; uiclamp- 1 1 1 1
                              ]
                           ]
                        ]
                     ]
                  ]
               ]
               uialign* 0 -1
            ]
         ]
      ]
      uifill 0.01
      UIvscroll 0.02 0.312 1.56
   ]
]

///////////////////////////////////////////////////////////////////////////////
//  Bots                                                                     //
///////////////////////////////////////////////////////////////////////////////
UI_botskill = 87
UI_botaddnum = 9

UImenu "bots" [
   uifill 0.65 0.27 [
      uivlist 0.01 [
         uitext (concatword "Bots: " (numbots)) 0.6
         uifill 0 0.01
         uihlist 0.01 [
            uialign 1 ; uitext "Skill Level" 0.6 ; UIhslider UI_botskill 1 100 1 0.5 0.032 [uitext $UI_botskill 0.6]
         ]
         uihlist 0.01 [
            uialign 1 ; uitext "#" 0.6 ; UIhslider UI_botaddnum 2 32 1 0.5 0.032 [uitext $UI_botaddnum 0.6]
         ]
         uifill 0 0.015
         uihlist 0.05 [
            uivlist 0.01 [
               UIbutton "" [uitext "Add Bot" 0.65 ; UI_keyref 1 0.027 0.027 "Ins" "" 0.4] 0.2 0.04 [addbot $UI_botskill]
               UIbutton "" [uitext (concatword "Add " $UI_botaddnum " Bots") 0.65] 0.2 0.04 [loop a (UI_botaddnum) [addbot $UI_botskill]]
            ]
            uivlist 0.01 [
               UIbutton "" [uitext "Delete Bot" 0.65 ; UI_keyref 1 0.027 0.027 "Del" "" 0.4] 0.2 0.04 [delbot]
               UIbutton "" [uitext "Clear Bots" 0.65] 0.2 0.04 [clearbots]
            ]
         ]
      ]
   ]
] [] [] [] "Bots"

///////////////////////////////////////////////////////////////////////////////
//  Display Changes                                                          //
///////////////////////////////////////////////////////////////////////////////
UImenu "changes" [
   uivlist 0.02 [
      uiclamp 1 1
      UItitle [uitext "Apply changes for:" 0.6] 0 0.03
      uiclamp- 1 1
      uivlist 0.01 [
         loop i $pendingchanges [
            uitext (concatword "^f8" (pendingchanges $i)) 0.6
         ]
      ]
      uihlist 0 [
         UIbutton "hold2" [uitext "Yes" 0.6] 0.18 0.032 [applychanges]
         UIbutton "hold2" [uitext "No"  0.6] 0.18 0.032 [hideui "changes"]
      ]
   ]
] [if (= $pendingchanges 0) [hideui "changes"]]


///////////////////////////////////////////////////////////////////////////////
//  Notepad                                                                  //
///////////////////////////////////////////////////////////////////////////////
UI_notepadfile = "untitled.txt"
UI_cmc_from   = ""
UI_cmc_to     = ""

UImenu "notepad" [
   uivlist 0.01 [
      uihlist 0.01 [
         uialign -1 -2
         uifield UI_notepadfile -35 [] 0.6 [
            uioutline (uifocus? 0xFF0000 $c_line)
            uiclamp- 1 1 1 1
         ]
         UIbutton "hold2" [uitext "Load"       0.6] 0.04 0.032 [textfocus $UI_notepadfile ; textload $UI_notepadfile]
         UIbutton "hold2" [uitext "Save"       0.6] 0.04 0.032 [textfocus $UI_notepadfile ; textsave $UI_notepadfile]
         UIbutton "hold2" [uitext "Exec"       0.6] 0.04 0.032 [textfocus $UI_notepadfile ; textexec]
         uispace 0.01 0 [UIbar 0 1]
         UIbutton "hold2" [uitext "Copy"       0.6] 0.04 0.032 [textfocus $UI_notepadfile ; textcopy]
         UIbutton "hold2" [uitext "Paste"      0.6] 0.04 0.032 [textfocus $UI_notepadfile ; textpaste]
         UIbutton "hold2" [uitext "Select All" 0.6] 0.04 0.032 [textfocus $UI_notepadfile ; textselectall]
         uispace 0.01 0 [UIbar 0 1]
         UIbutton "hold2" [uitext "Clear All"  0.6] 0.04 0.032 [textfocus $UI_notepadfile ; textclear]
      ]
      uitexteditor $UI_notepadfile -80 20 1 "" 0 [
         uioutline (uifocus? 0xFF0000 $c_line)
         uiclamp- 1 1 1 1
      ]
      textinit $UI_notepadfile $UI_notepadfile
   ]
] [] [] [] "Notepad"

notepad = [
   if $numargs [UI_notepadfile = $arg1]
   showui "notepad"
]

mapnotepad = [
   UI_notepadfile = (concatword "media/map/" (? $numargs $arg1 $mapname) ".cfg")
   showui "notepad"
]

copymapcfg = [
   if $numargs [
      UI_cmc_from = $arg1
      UI_cmc_to   = (? (= $numargs 2) $arg2 $mapname)
      if (findfile (concatword "media/map/" $UI_cmc_from ".cfg")) [
         if (findfile (concatword "media/map/" $UI_cmc_to ".cfg")) [showui "cmc_confirm"] [
            textfocus "#copymapcfg"
            textload (concatword "media/map/" $UI_cmc_from ".cfg")
            textsave (concatword "media/map/" $UI_cmc_to   ".cfg")
         ]
      ] [
         echo (concatword "^f7Map config "^f8^" $UI_cmc_from "^f7^" does not exist!")
         UI_cmc_from = "" ; UI_cmc_to = ""
      ]
   ]
]

UImenu "cmc_confirm" [
   uivlist 0.02 [
      uiclamp 1 1
      UItitle [uitext "Copy map config:" 0.6] 0 0.03
      uiclamp- 1 1
      uivlist 0.01 [
         uitext (concatword "^f2" $UI_cmc_from) 0.6
         UItriangle 0 0.01 0.01 180
         uitext (concatword "^f2" $UI_cmc_to) 0.6
      ]
      uihlist 0 [
         UIbutton "hold2" [uitext "Proceed" 0.6] 0.18 0.032 [
            textfocus "#copymapcfg"
            textload (concatword "media/map/" $UI_cmc_from ".cfg")
            textsave (concatword "media/map/" $UI_cmc_to   ".cfg")
            hideui "cmc_confirm"
         ]
         UIbutton "hold2" [uitext "Cancel"  0.6] 0.18 0.032 [hideui "cmc_confirm"]
      ]
   ]
] [
   if (|| [=s $UI_cmc_from ""] [=s $UI_cmc_to ""]) [hideui "cmc_confirm"]
] [UI_cmc_from = "" ; UI_cmc_to = ""]

