persistidents 0

// Decides whether to open the admin or normal in-game menu.
const ingamemenu [ if (player1 role) [ showmenu [In-game admin] ] [ showmenu In-game ] ]

// "Join server" menu.
personalserverlist = []
const joinservermenu [
  searchlan 1
  showallservers 1
  showonlyfavourites 0
  updatefrommaster
  personalserverlist
  showmenu server
]

// Normal in-game menu that opens when pressing escape and connected to a game.
newmenu [In-game]

menuitemtextinput [Nickname:  ] "result $curname" [ name $arg1 ] [ __ingamemenu_showmodel [In-game] 0 ]
menuitem [Change weapon...] [ showmenu Weapons ] [ __ingamemenu_showmodel [In-game] 0 ]
menuitem [Change to the enemy team] changeteam [ __ingamemenu_showmodel [In-game] 0 ]
menuitemvar [result (concat [Change to] (if (> (player1 team) 1) [ result active ] [ result spectate]) mode)] spectate [ __ingamemenu_showmodel [In-game] 0 ]
menuitem [Change player skin...] [showmenu (at [CLA RVSF] (player1 team))]  [ __ingamemenu_showmodel [In-game] 1 ]
menuitem [] -1 [__ingamemenu_showmodel [In-game] 0]
menuitem [Set mode/map...]    [ showmenu Gamemode ]
// menuitem "Kick/ban player..." [ showmenu kick/ban ] // only noobish vote abusers use this, if you really want it, just uncomment
menuitem [Ignore/Unignore all...] [ if $ingall [ unignoreall ] [ ignoreall ] ]
menuitem [Adjust teams...]    [ showmenu [Team adjustment] ]
menuitem [Download a demo...] [ listdemos; showmenu [Download demo] ]
menuitem [Get additional server information] [ showmenu serverinfo ]
menuitem [] -1
menuitem "4Main menu..."           [ closemenu In-game; showmenu main ]
menuitem "4Browse servers..."      [ closemenu In-game; joinservermenu ]
menuitem "3Disconnect from server" disconnect
menuitem "3Quit AssaultCube"       savequit
menuinitselection 13

const __ingamemenu_showmodel [
  if (&& (< (player1 team) 4) $arg2) [
    chmenumdl $arg1 (concatword "playermodels/" (at [CLA RVSF CLA RVSF] (player1 team)) "/0" (+ 1 (player1 skin))) idle 15 3
  ] [
    chmenumdl $arg1
  ]
]

// In-game menu that opens if when you press escape if you're admin state and connected to a game.
newmenu [In-game admin]

menuitem [Set mode/map...]                  [ showmenu Gamemode ]
menuitem [Kick/ban player...]               [ showmenu kick/ban ]
menuitem [Adjust teams...]                  [ showmenu [Team adjustment] ]
menuitem [Change mastermode...]             [ showmenu Mastermode ]
menuitem [Change the server description...] [ saycommand "/serverdesc " ]
menuitem [Find a players IP address...]	    [ saycommand "/whois " ]
menuitem [Give admin...]                    [ showmenu [give admin] ]
menuitem [] -1
menuitemtextinput [Nickname: ] "result $curname" [ name $arg1 ]
menuitem [Change weapon...] [ showmenu Weapons ] [ __ingamemenu_showmodel [In-game admin] 0 ]
menuitem [Change to the enemy team] changeteam   [ __ingamemenu_showmodel [In-game admin] 1 ]
menuitemvar [result (concat [Change to] (if (> (player1 team) 1) [ result active ] [ result spectate ]) mode)] spectate [ __ingamemenu_showmodel [In-game admin] 1 ]
menuitem [Change player skin...]                 [ showmenu (at [CLA RVSF] (player1 team)) ] [ __ingamemenu_showmodel [In-game admin] 1 ]
menuitem [Demos...] [ showmenu Demo ]            [ __ingamemenu_showmodel "In-game admin" 0 ]
menuitem [] -1
menuitem "4Main menu..."           [ closemenu [In-game admin]; showmenu main ]
menuitem "4Browse servers..."      [ closemenu [In-game admin]; joinservermenu ]
menuitem "3Disconnect from server" disconnect
menuitem "3Quit AssaultCube"       savequit
menuinitselection 16

// Multiplayer menu only opens through the main menu (when disconnected).
newmenu multiplayer

menuitem [Join a server]     joinservermenu
menuitem [Join a LAN server] [ searchlan 2; showallservers 0; showmenu server ]
menuitem [Custom connect]    [ showmenu [Custom connect] ]
menuitem [Connect as Admin]  [ showmenu [Admin connect] ]
menuitem [] -1
menuitem [Force serverlist update] [ updatefrommaster 1; showmenu server ]

// Fancy custom connect menu.
newmenu [Custom connect]

menuinit [ cc1 = []; cc2 = []; cc3 = [] ]	// Resets the aliases
menuitemtextinput [Server IP/DNS: 		] []           [ cc1 = $arg1 ] [] 255
menuitemtextinput [Server port (optional): 	] []     [ cc2 = $arg1 ] [] 6
menuitemtextinput [Server password (optional): 	] [] [ cc3 = $arg1 ] [] 128 1
menuitem [] -1
menuitem "2		     [ Connect ]			" [ connect $cc1 $cc2 $cc3 ]

// Connect to a menu as admin.
newmenu [Admin connect]

menuinit [ acc1 = []; acc2 = []; acc3 = []; echo (red)To use this menu to connect as administrator, you will need to know the admin password for the server. ] // Resets the aliases
menuitemtextinput [Server IP/DNS: 		] []       [ acc1 = $arg1 ] [] 255
menuitemtextinput [Server port (optional):	] [] [ acc2 = $arg1 ] [] 6
menuitemtextinput [Server admin password: 	] [] [ acc3 = $arg1 ] [] 128 1
menuitem [] -1
menuitem "2		  [ Admin connect ]		" [ connectadmin $acc1 $acc2 $acc3 ]

_kickbanaction = kick
newmenu reason
menuinit [ _kickbanreason = None; if (! (strcmp $_kickbanaction kick)) [ if (! (strcmp $_kickbanaction ban)) [ _kickbanaction = ban ] ] ]
menuitem [intentional TK]    [ _kickbanreason = [intentional TK]; showmenu (concat $_kickbanaction player) ]
menuitem [abusive behaviour] [ _kickbanreason = [abusive behaviour]; showmenu (concat $_kickbanaction player) ]
menuitem [bad language]      [ _kickbanreason = [bad language]; showmenu (concat $_kickbanaction player) ]
// TODO: more reasons
//menuitem "" [ _kickbanreason = ""; showmenu (concat $_kickbanaction player) ]
menuitemtextinput [Reason: ] [] [ _kickbanreason = $arg1 ] [] 255
menuitem $_kickbanaction [ showmenu (concat $_kickbanaction player) ]
menuinitselection 2

newmenu kick/ban
menuitem [Kick a player] [ _kickbanaction = kick; showmenu reason ]
menuitem [Ban a player]  [ _kickbanaction = ban; showmenu reason ]
//menuitem "Kick a player" [ showmenu "kick player" ]
//menuitem "Ban a player"  [ showmenu "ban player" ]
menuitem [Remove all bans] removebans

newmenu [Team adjustment]

menuitem [Initiate shuffleteams] shuffleteams
menuitem [Force a team change]   [ showmenu [force team] ]
menuitem [Force yourself to enemy team] forceme
menuitem [Initiate autoteam]		 [ showmenu Auto-team ]

newmenu Gamemode

menuitem [Team Deathmatch]          [ mode 0; showmenu maps ]
menuitem [Deathmatch]               [ mode 2; showmenu maps ]
menuitem [Team Survivor]            [ mode 4; showmenu maps ]
menuitem [Survivor]                 [ mode 3; showmenu maps ]
menuitem [Capture the Flag]         [ mode 5; showmenu maps_flags ]
menuitem [Hunt the Flag]            [ mode 13; showmenu maps ]
menuitem [Keep the Flag]            [ mode 15; showmenu maps_flags ]
menuitem [Team Keep the Flag]       [ mode 14; showmenu maps_flags ]
menuitem [Team Pistol Frenzy]       [ mode 16; showmenu maps ]
menuitem [Pistol Frenzy]            [ mode 6; showmenu maps ]
menuitem [Team Last Swiss Standing] [ mode 17; showmenu maps ]
menuitem [Last Swiss Standing]      [ mode 9; showmenu maps ]
menuitem [One Shot, One Kill]       [ mode 10; showmenu maps ]
menuitem [Team One Shot, One Kill]  [ mode 11; showmenu maps ]

newmenu Mastermode

menuitem [Unlock the server (open)]     [ mastermode 0 ]
menuitem [Lock the server (private)]    [ mastermode 1 ]
menuitem [Lock the server (match mode)] [ mastermode 2 ]

newmenu Auto-team

menuitem [Turn auto-team on]	[ autoteam 1 ]
menuitem [Turn auto-team off]	[ autoteam 0 ]

newmenu [serverbrowser help]

menuitem [F1: Display this help menu] -1
menuitem [F3: Search for players by nickname...]           [ showmenu [search player] ]
menuitem [F4: Edit favourites...]                          [ showmenu [edit favourites] ]
menuitem [F5: Update the serverlist from the masterserver] [ updatefrommaster 1; closemenu [serverbrowser help] ]
menuitem [F9: Get additional server information]           [ showmenu serverinfo ]
menuitem [] -1
menuitem [Options:] -1
menuitemcheckbox [F6: Reverse the sort order:] "$serversortdir"          [ serversortdir $arg1 ]
menuitemcheckbox [F7: Only show good servers:] "$showonlygoodservers"    [ showonlygoodservers $arg1 ]
menuitemcheckbox [F8: Show minutes remaining:] "$showminremain"          [ showminremain $arg1 ]
menuitemcheckbox [Sort official maps ontop:] "$serversortpreferofficial" [ serversortpreferofficial $arg1 ]
menuitemcheckbox [Use gamemode acronyms:] "$modeacronyms"                [ modeacronyms $arg1 ]
menuitemslider [Favourites tag column:	] 0 2 "$serverbrowserhidefavtag" 1 ["Show always" "Show when used" "Hide always"] [ serverbrowserhidefavtag $arg1 ]
menuitemslider [Server IP & port:		] 0 2 "$serverbrowserhideip" 1 [Show "Show in grey" Hide] [ serverbrowserhideip $arg1 ]
menuitemslider [Sort servers by:		] 0 7 "$serversort" 1 [Ping "Number of players" "Max players" "Minutes remaining" "Map name" Gamemode "IP address" "Server description"] [ serversort $arg1 ]
menuinitselection 1

// connecting from the serverbrowser to a password-protected server
// called by sbconnect
newmenu [password required]

menuinit [ sbpwd = [] ]	// Resets the aliases
menuitemvar [result $sbmsg]
menuitem [You need a password to join it.] -1
menuitem [] -1
menuitemtextinput [Password: 	] [] [ sbpwd = $arg1 ] [] 128 1
menuitem [] -1
menuitem "2		  [ Connect ]		" [ echo connecting to $sbdesc ; connect $sbdns $sbport $sbpwd ]
menuitem "2		  [ Connect without password ]		" [ echo connecting to $sbdesc ; connect $sbdns $sbport ]
menuinitselection 3

const addfavcatmenu [
  i = (+ 1 (findlist (listfavcats) $arg1))
  newmenu [edit favourites]
  if (< $i 11) [
    menuitemvar (concatword "concat " (mod $i 10) ":  $" sbfavourite_ $arg1 _desc " (concatword <s $" sbfavourite_ $arg1 _tag " r>)") (concatword "showmenu [favourites " $i "]")
    newmenu [serverbrowser help]
    menuitemvar (concatword "concat " $i ":  Toggle category $" sbfavourite_ $arg1 _desc " (concatword <s $" sbfavourite_ $arg1 _tag " r>)") -1
  ] [
    menuitemvar (concatword "result $" sbfavourite_ $arg1 _desc " (concatword <s $" sbfavourite_ $arg1 _tag " r>)") (concatword "showmenu [favourites " $i "]")
  ]
  newmenu (concat favourites $i)
  menuitemtextinput [Tag:  ] (concatword "result $" sbfavourite_ $arg1 _tag) (concatword sbfavourite_ $arg1 _tag " = $arg1") [] 15
  menuitemtextinput [Description:  ] (concatword "result $" sbfavourite_ $arg1 _desc) (concatword sbfavourite_ $arg1 _desc " = $arg1") [] 45
  menuitem [] -1
  menuitemslider [Background red:	] 0 100 (concatword "$" sbfavourite_ $arg1 _red) 10 [] (concatword sbfavourite_ $arg1 _red " = $arg1")
  menuitemslider [Background green:	] 0 100 (concatword "$" sbfavourite_ $arg1 _green) 10 [] (concatword sbfavourite_ $arg1 _green " = $arg1")
  menuitemslider [Background blue:	] 0 100 (concatword "$" sbfavourite_ $arg1 _blue) 10 [] (concatword sbfavourite_ $arg1 _blue " = $arg1")
  menuitemslider [Background alpha:	] 0 100 (concatword "$" sbfavourite_ $arg1 _alpha) 10 [] (concatword sbfavourite_ $arg1 _alpha " = $arg1")
  menuitem [] -1
  menuitemtextinput [Keyword list:  ] (concatword "result $" sbfavourite_ $arg1 _keys) (concatword sbfavourite_ $arg1 _keys " = $arg1") [] 255
  menuitem [] -1
  menuitemtextinput [Weight:  ] (concatword "result $" sbfavourite_ $arg1 _weight) (concatword sbfavourite_ $arg1 _weight " = $arg1") [] 10
  menuitem [] -1
  menuitemslider [] 0 1 (concatword "result $" sbfavourite_ $arg1 _ignore) 1 ["Enable this category" "Ignore this category"] (concatword sbfavourite_ $arg1 _ignore " = $arg1")
  menuitem [] -1
  menuitem [Show servers of this category] (concat showonlyfavourites $i ";showmenu server") [ showonlyfavourites 0 ]
]

const addallfavcatmenus [
	newmenu [serverbrowser help]
	menuitem [] -1
	menuitem [Keys to add/remove servers from categories:] -1
	loop ii (listlen (listfavcats)) [ addfavcatmenu (at (listfavcats) $ii) ]
]

lastsearchname = []
newmenu [search player]

menuitemtextinput [Search servers for a player: ] "result $lastsearchname" [ lastsearchname = $arg1 ]
menuitem "2		       [ Search ]" [ closemenu [Search for a player]; searchnickname $lastsearchname]
menuinitselection 1

newmenu getmap
menuitem [      This server is using a different version of this map...] -1
menuitem [] -1
menuitemvar "result $__getmaprevisions"
menuitem [] -1
menuitem "2    [ Download the servers map version and join the game ]"     [ getmap ]
menuitem "3 [ Keep the local map version and disconnect from the server ]" [ showmenu ""; disconnect ]
menuinitselection 4

persistidents 1
