///////////////////////////////////////////////////////////////////////////////
//  Scoreboard                                                               //
///////////////////////////////////////////////////////////////////////////////
newui "scoreboard" [
   if $mainmenu [hideui "scoreboard"]
   uiallowinput 0
   refreshscoreboard
   uicolor (? $sbtransparent $c_menu_a $c_menu) 0 0 [
      uivlist 0 [
         UI_sbheader
         uifill 0 0.005
         if (> $getmode 2) UI_playertableteam UI_playertablesolo
         UI_spectatorlist
      ]
   ]
] [if $mainmenu [hideui "scoreboard"]]

///////////////////////////////////////////////////////////////////////////////
UI_sbwsolo = 0.68
UI_sbwteam = 1.18
UI_sbheader = [
   uifill 0 0.005
   uifill (? (> $getmode 2) $UI_sbwteam $UI_sbwsolo) 0.05 [
      uifill (-f (? (> $getmode 2) $UI_sbwteam $UI_sbwsolo) (? (= $showip 1) 0.18 0)) 0 [
         uialign -1
         uiclip (-f (? (> $getmode 2) $UI_sbwteam $UI_sbwsolo) (? (= $showip 1) 0.18 0)) 0 [
            uialign -1
            uispace 0.01 0 [
               uivlist 0 [
                  if $scoreboardservinfo [
                     uitext $scoreboardservinfo 0.65
                  ] [
                     uitext "^f4Tesseract" 0.65
                  ]
                  uihlist 0.015 [
                     uifill
                     uihlist 0.003 [
                        uitext "^fs[" 0.52
                        uitext (concatword (at ["^f0" "^f0" "^f2" "^f3"] $getmastermode) (getmastermodename $getmastermode)) 0.52
                        uitext "^fS]" 0.52
                     ]
                     UItriangle 0x606060 0.01 0.01 270
                     uitext (getmodeprettyname $getmode) 0.52
                     UItriangle 0x606060 0.01 0.01 270
                     uitext $scoreboardmap 0.52
                     if (m_timed $getmode) [
                        UItriangle 0x606060 0.01 0.01 270
                        uitext (concatword (? (|| $intermission $paused) "^f3" "^f8") $scoreboardtime) 0.52
                     ]
                  ]
                  uialign* -1
               ]
            ]
         ]
      ]
      if $scoreboardmultiplayer [
         if $showip [
            uifill 0.18 0 [
               uialign 1
               UIbar 0 1; uialign- -1
               uiclip 0.18 0 [
                  uialign 1
                  uispace 0.01 0 [
                     uivlist 0.004 [
                        uicolortext $connectedip 0xA0A0A0 0.52
                        uicolortext $connectedport 0xA0A0A0 0.52
                        uialign* 1
                     ]
                  ]
                  uialign- 1
               ]
            ]
         ]
      ]
   ]
]
//-------------------------------------------------------------------------------------------------
UI_cw_s  = 0.042
UI_cw_k  = 0.054
UI_cw_d  = 0.054
UI_cw_pj = 0.050
UI_cw_p  = 0.050
UI_cw_cn = 0.040
UI_cw_n  = [-f (? (> $getmode 2) (*f $UI_sbwteam 0.5) $UI_sbwsolo) (? (> $getmode 2) (? $showscore $UI_cw_s)) (? $showkills $UI_cw_k) (? $showdeaths $UI_cw_d) (? $scoreboardmultiplayer (? $showpj $UI_cw_pj)) (? $scoreboardmultiplayer (? $showping $UI_cw_p)) (? $scoreboardmultiplayer (? $showclientnum $UI_cw_cn)) 0.03]
// ^ blarg

UI_playertablesolo = [
   uifill 0 0 [
      uitable 0 0 [
         uitableheader [
            uifill 0.015
            uifill (UI_cw_n) 0.022
            if $showkills        [uifill $UI_cw_k  0.022 [uicolortext "K"  0xBBCC8B 0.45 ; uialign-  1 1]]
            if $showdeaths       [uifill $UI_cw_d  0.022 [uicolortext "D"  0xE56767 0.45 ; uialign-  1 1]]
            if $scoreboardmultiplayer [
               if $showpj        [uifill $UI_cw_pj 0.022 [uicolortext "PJ" 0x77A1D9 0.45 ; uialign-  1 1]]
               if $showping      [uifill $UI_cw_p  0.022 [uicolortext "P"  0x77A1D9 0.45 ; uialign-  1 1]]
               if $showclientnum [uifill $UI_cw_cn 0.022 [uicolortext "#"  0xA0A0A0 0.45 ; uialign-  1 1]]
            ]
            uifill 0.015
         ] [uicolor 0x88161616 0 0 [uiclamp 1 1 1 1]]
         UI_sbtc = 0
         loopscoreboard cn 0 [
            UI_sbtc = (! $UI_sbtc)
            uitablerow [
               uifill 0.015
               uifill (UI_cw_n) 0.026 [uicolortext (getclientcolorname $cn) (scoreboardstatus $cn) 0.57 ; uialign- -1]
               if $showkills        [uifill $UI_cw_k  0.026 [uicolortext (getclientfrags  $cn)                      0xBBCC8B 0.52 ; uialign-  1]]
               if $showdeaths       [uifill $UI_cw_d  0.026 [uicolortext (getclientdeaths $cn)                      0xE56767 0.52 ; uialign-  1]]
               if $scoreboardmultiplayer [
                  if $showpj        [uifill $UI_cw_pj 0.026 [uicolortext (? (isai $cn) "^f4-" (scoreboardpj $cn))   0x77A1D9 0.52 ; uialign-  1]]
                  if $showping      [uifill $UI_cw_p  0.026 [uicolortext (? (isai $cn) "^f4-" (scoreboardping $cn)) 0x77A1D9 0.52 ; uialign-  1]]
                  if $showclientnum [uifill $UI_cw_cn 0.026 [uicolortext (? (isai $cn) "^f4-" $cn)                  0xA0A0A0 0.52 ; uialign-  1]]
               ]
               uifill 0.015
            ] [
               uicolor (? $UI_sbtc 0x99323232 0x99262626) 0 0 [uiclamp 1 1 1 1]
               pushif highlight (scoreboardhighlight $cn) [uioutline 0xA0A0A0 (-f $UI_sbwsolo 0.002) 0.024]
            ]
         ]
      ]
   ]
]
UI_playertableteam = [
   uifill 0 0 [
      uihlist 0 [
         uitable 0 0 [
            uialign 0 -1
            uitableheader [
               uifill 0.015
               if $scoreboardmultiplayer [
                  if $showclientnum [uifill $UI_cw_cn 0.042 [uicolortext "#"     0xA0A0A0 0.45 ; uialign- -1 1]]
                  if $showping      [uifill $UI_cw_p  0.042 [uicolortext "P"     0x77A1D9 0.45 ; uialign- -1 1]]
                  if $showpj        [uifill $UI_cw_pj 0.042 [uicolortext "PJ"    0x77A1D9 0.45 ; uialign- -1 1]]
               ]
               if $showdeaths       [uifill $UI_cw_d  0.042 [uicolortext "D"     0xE56767 0.45 ; uialign- -1 1]]
               if $showkills        [uifill $UI_cw_k  0.042 [uicolortext "K"     0xBBCC8B 0.45 ; uialign- -1 1]]
               if $showscore        [uifill $UI_cw_s  0.042 [uicolortext "Score" 0x62B370 0.45 ; uialign- -1 1]]
               uifill (UI_cw_n) 0.042 [uicolortext (getteamscore 1) 0x4060D0 1 ; uialign- 1]
               uifill 0.015
            ] [uicolor 0x99202860 0 0 [uiclamp 1 1 1 1]]
            UI_sbtc = 0
            loopscoreboard cn 1 [
               UI_sbtc = (! $UI_sbtc)
               uitablerow [
                  uifill 0.015
                  if $scoreboardmultiplayer [
                     if $showclientnum [uifill $UI_cw_cn 0.026 [uicolortext (? (isai $cn) "^f4-" $cn)                  0xA0A0A0 0.52 ; uialign- -1]]
                     if $showping      [uifill $UI_cw_p  0.026 [uicolortext (? (isai $cn) "^f4-" (scoreboardping $cn)) 0x77A1D9 0.52 ; uialign- -1]]
                     if $showpj        [uifill $UI_cw_pj 0.026 [uicolortext (? (isai $cn) "^f4-" (scoreboardpj $cn))   0x77A1D9 0.52 ; uialign- -1]]
                  ]
                  if $showdeaths       [uifill $UI_cw_d  0.026 [uicolortext (getclientdeaths $cn)                      0xE56767 0.52 ; uialign- -1]]
                  if $showkills        [uifill $UI_cw_k  0.026 [uicolortext (getclientfrags  $cn)                      0xBBCC8B 0.52 ; uialign- -1]]
                  if $showscore        [uifill $UI_cw_s  0.026 [uicolortext (getclientflags  $cn)                      0x62B370 0.52 ; uialign- -1]]
                  uifill (UI_cw_n) 0.026 [uicolortext (getclientcolorname $cn) (scoreboardstatus $cn) 0.57 ; uialign- 1]
                  uifill 0.015
               ] [
                  uicolor (? $UI_sbtc 0x99333b40 0x99262b33) 0 0 [uiclamp 1 1 1 1]
                  pushif highlight (scoreboardhighlight $cn) [uioutline 0xA0A0A0 (-f (*f $UI_sbwteam 0.5) 0.002) 0.024]
               ]
            ]
         ]
         uitable 0 0 [
            uialign 0 -1
            uitableheader [
               uifill 0.015
               uifill (UI_cw_n) 0.042 [uicolortext (getteamscore 2) 0xD04040 1 ; uialign- -1]
               if $showscore        [uifill $UI_cw_s  0.042 [uicolortext "Score" 0x62B370 0.45 ; uialign-  1 1]]
               if $showkills        [uifill $UI_cw_k  0.042 [uicolortext "K"     0xBBCC8B 0.45 ; uialign-  1 1]]
               if $showdeaths       [uifill $UI_cw_d  0.042 [uicolortext "D"     0xE56767 0.45 ; uialign-  1 1]]
               if $scoreboardmultiplayer [
                  if $showpj        [uifill $UI_cw_pj 0.042 [uicolortext "PJ"    0x77A1D9 0.45 ; uialign-  1 1]]
                  if $showping      [uifill $UI_cw_p  0.042 [uicolortext "P"     0x77A1D9 0.45 ; uialign-  1 1]]
                  if $showclientnum [uifill $UI_cw_cn 0.042 [uicolortext "#"     0xA0A0A0 0.45 ; uialign-  1 1]]
               ]
               uifill 0.015
            ] [uicolor 0x99602020 0 0 [uiclamp 1 1 1 1]]
            UI_sbtc = 0
            loopscoreboard cn 2 [
               UI_sbtc = (! $UI_sbtc)
               uitablerow [
                  uifill 0.015
                  uifill (UI_cw_n) 0.026 [uicolortext (getclientcolorname $cn) (scoreboardstatus $cn) 0.57 ; uialign- -1]
                  if $showscore        [uifill $UI_cw_s  0.026 [uicolortext (getclientflags  $cn)                      0x62B370 0.52 ; uialign-  1]]
                  if $showkills        [uifill $UI_cw_k  0.026 [uicolortext (getclientfrags  $cn)                      0xBBCC8B 0.52 ; uialign-  1]]
                  if $showdeaths       [uifill $UI_cw_d  0.026 [uicolortext (getclientdeaths $cn)                      0xE56767 0.52 ; uialign-  1]]
                  if $scoreboardmultiplayer [
                     if $showpj        [uifill $UI_cw_pj 0.026 [uicolortext (? (isai $cn) "^f4-" (scoreboardpj $cn))   0x77A1D9 0.52 ; uialign-  1]]
                     if $showping      [uifill $UI_cw_p  0.026 [uicolortext (? (isai $cn) "^f4-" (scoreboardping $cn)) 0x77A1D9 0.52 ; uialign-  1]]
                     if $showclientnum [uifill $UI_cw_cn 0.026 [uicolortext (? (isai $cn) "^f4-" $cn)                  0xA0A0A0 0.52 ; uialign-  1]]
                  ]
                  uifill 0.015
               ] [
                  uicolor (? $UI_sbtc 0x99403333 0x99332626) 0 0 [uiclamp 1 1 1 1]
                  pushif highlight (scoreboardhighlight $cn) [uioutline 0xA0A0A0 (-f (*f $UI_sbwteam 0.5) 0.002) 0.024]
               ]
            ]
         ]
      ]
   ]
]
//-------------------------------------------------------------------------------------------------
UI_spectatorlist = [
   uicolor 0x88161616 0 0.022 [
      uiclamp 1 1 1 1
      if $showspectators [
         uigrid (? (> $getmode 2) 3 2) 0 0 [
            loopscoreboard cn -1 [
               uispace 0.01 0.01 [
                  pushif sbhigh (scoreboardhighlight $cn) [
                     uioutline 0xA0A0A0 ; uiclamp- 1 1 1 1
                  ]
                  uihlist 0.01 [
                     uicolortext (getclientcolorname $cn) (scoreboardstatus $cn) 0.57
                     if $scoreboardmultiplayer [if $showclientnum [uitext $cn 0.57]]
                  ]
               ]
            ]
         ]
      ]
   ]
]
