//-----------------------------------------------------------------------------
// Torque Game Engine
// 
// Copyright (c) 2001 GarageGames.Com
//-----------------------------------------------------------------------------

//--- OBJECT WRITE BEGIN ---
new GuiControl(PlayerListGui) {
   profile = "GuiModelessDialogProfile";
   horizSizing = "right";
   vertSizing = "bottom";
   position = "0 0";
   extent = "640 480";
   minExtent = "8 8";
   visible = "1";
   helpTag = "0";
      noCursor = "1";

   new GuiBitmapBorderCtrl() {
      profile = "GuiBitmapBorderProfile";
      horizSizing = "center";
      vertSizing = "center";
      position = "241 119";
      extent = "158 242";
      minExtent = "8 8";
      visible = "1";
      helpTag = "0";

      new GuiBitmapCtrl() {
         profile = "HudScrollProfile";
         horizSizing = "right";
         vertSizing = "bottom";
         position = "5 5";
         extent = "147 231";
         minExtent = "8 8";
         visible = "1";
         helpTag = "0";
         bitmap = "./hudfill";
         wrap = "0";

         new GuiTextCtrl() {
            profile = "HudTextProfile";
            horizSizing = "right";
            vertSizing = "bottom";
            position = "37 2";
            extent = "76 20";
            minExtent = "8 8";
            visible = "1";
            helpTag = "0";
            text = "Score Board";
            maxLength = "255";
         };
         new GuiScrollCtrl() {
            profile = "HudScrollProfile";
            horizSizing = "width";
            vertSizing = "height";
            position = "0 24";
            extent = "147 207";
            minExtent = "8 8";
            visible = "1";
            helpTag = "0";
            willFirstRespond = "1";
            hScrollBar = "alwaysOff";
            vScrollBar = "dynamic";
            constantThumbHeight = "0";
            childMargin = "0 0";
               defaultLineHeight = "15";

            new GuiTextListCtrl(PlayerListGuiList) {
               profile = "HudTextProfile";
               horizSizing = "width";
               vertSizing = "height";
               position = "1 1";
               extent = "145 16";
               minExtent = "8 8";
               visible = "1";
               helpTag = "0";
               enumerate = "0";
               resizeCell = "1";
               columns = "0 120";
               fitParentWidth = "1";
               clipColumnText = "0";
            };
         };
      };
   };
};
//--- OBJECT WRITE END ---

function PlayerListGui::update(%this,%clientId,%name,%isSuperAdmin,%isAdmin,%isAI,%score)
{
   // Build the row to display.  The name can have ML control tags,
   // including color and font.  Since we're not using and
   // ML control here, we need to strip them off.
   %tag = %isSuperAdmin? "[Super]":
          (%isAdmin? "[Admin]":
          (%isAI? "[Bot]":
          ""));
   %text = StripMLControlChars(%name) SPC %tag TAB %score;

   // Update or add the player to the control
   if (PlayerListGuiList.getRowNumById(%clientId) == -1)
      PlayerListGuiList.addRow(%clientId, %text);
   else
      PlayerListGuiList.setRowById(%clientId, %text);

   // Sorts by score
   PlayerListGuiList.sortNumerical(1,false);
   PlayerListGuiList.clearSelection();
}

function PlayerListGui::updateScore(%this,%clientId,%score)
{
   %text = PlayerListGuiList.getRowTextById(%clientId);
   %text = setField(%text,1,%score);
   PlayerListGuiList.setRowById(%clientId, %text);
   PlayerListGuiList.sortNumerical(1,false);
   PlayerListGuiList.clearSelection();
}

function PlayerListGui::remove(%this,%clientId)
{
   PlayerListGuiList.removeRowById(%clientId);
}

function PlayerListGui::toggle(%this)
{
   if (%this.isAwake())
      Canvas.popDialog(%this);
   else
      Canvas.pushDialog(%this);
}

function PlayerListGui::clear(%this)
{
   // Override to clear the list.
   PlayerListGuiList.clear();
}

function PlayerListGui::zeroScores(%this)
{
   for (%i = 0; %i < PlayerListGuiList.rowCount(); %i++) {
      %text = PlayerListGuiList.getRowText(%i);
      %text = setField(%text,1,"0");
      PlayerListGuiList.setRowById(PlayerListGuiList.getRowId(%i), %text);
   }
   PlayerListGuiList.clearSelection();
}
