Game Development Community

Favorites Problems

by Ronald J Nelson · in Torque Game Engine · 08/15/2007 (10:21 am) · 0 replies

I have not been able to find a resource that fully covered what I wanted my favorites system to do. BAsically I am going for more a system that looks like that found in Half-Life 2 or other Steam based games. I am running into some problems however with my delete favorite code. I also realize that there is some problem with the idex and ID numbers not matching properly. For instance for favorites numbers from top to bottom 1 to 3 the id will be numbered in reverse order.

Could someone have a look to tell me where I am going wrong?

If you decide you want to use this stuff, knock yourselves out. Its just GUI stuff after all.

function multiplayerGui::selectFavorites(%this)
{
   if($ConnectionType == 1)
   {
      %this.setPane(Favorites);
      $lastMultiPane = 2;
      OptFavoritesPane.query();
   }
   else
   {
      //Check if they want to connect
      Canvas.pushDialog(accountLogin);
   }
}

function OptFavoritesPane::query(%this)
{
   $prevFav = "";

   JF_serverList.clear();
   if($favorite::ServerFavoriteCount == 0)
   {
      FavoritesServerSort.setText("Servers (" @ JF_serverList.rowCount() @ ")");
      return;
   }
   %sc = $favorite::ServerFavoriteCount;
   for (%i = 0; %i < %sc; %i++) 
   {
      %firstSub = strchr( $favorite::ServerFavorite[%i] , "DTSS" );
      %serverName = Strreplace($favorite::ServerFavorite[%i], %firstSub, "");
      %serverAddress = Strreplace(%firstSub, "DTSSIP:", "");

      querySingleServer( %serverAddress, 0 );
   }
}

function OptFavoritesPane::update(%this)
{
   // Copy the servers into the server list.
   %i = JF_serverList.rowCount();
   echo("This is update %i: " @ %i);

   %sc = $favorite::ServerFavoriteCount;
   setServerInfo(%i);
   %badCheck = 1;

   // Double check things first
   if($ServerInfo::Address $= $prevFav)
   {
      return;
   }


   for (%d = 0; %d < %sc; %d++) 
   {
      %firstSub = strchr( $favorite::ServerFavorite[%d] , "DTSS" );
      %serverName = Strreplace($favorite::ServerFavorite[%d], %firstSub, "");
      %serverAddress = Strreplace(%firstSub, "DTSS", "");
      echo("%firstSub: " @ %firstSub);
      echo("%serverName: " @ %serverName);
      echo("Server Address: " @ $ServerInfo::Address);
      echo("Favorite Address: " @ %serverAddress);

      if($ServerInfo::Address $= %serverAddress)
      {
         echo("At least one of our favorites matched");
         %badCheck = 0;
      }
   }
   if(%badCheck == 1)
   {
      return;
   }

    $prevFav = $ServerInfo::Address;

   // All good, proceed
   JF_serverList.addRow(%i,
      $ServerInfo::Dedicated TAB
      $ServerInfo::Name TAB
      $ServerInfo::Ping TAB
      $ServerInfo::PlayerCount @ "/" @ $ServerInfo::MaxPlayers @ "(" @ $ServerInfo::BotCount @ ")" TAB
      $ServerInfo::MissionType TAB
      $ServerInfo::MissionName TAB
      %i);  // ServerInfo index stored also

   FavoritesServerSort.setText("Servers (" @ JF_serverList.rowCount() @ ")");

   JF_serverList.sort(0);
   JF_serverList.setSelectedRow(0);
   JF_serverList.scrollVisible(0);

   JF_joinInt.setActive(JF_serverList.rowCount() > 0);
} 

function addServerToList()
{
   %id = JI_serverList.getSelectedId();

   // The server info index is stored in the row along with the
   // rest of displayed info.
   %index = getField(JI_serverList.getRowTextById(%id),6);
   if (setServerInfo(%index)) 
   {  
         %sc = $favorite::ServerFavoriteCount;
         for (%i = 0; %i < %sc; %i++) 
         {
            %firstSub = strchr( $favorite::ServerFavorite[%i] , "DTSS" );
            %serverName = Strreplace($favorite::ServerFavorite[%i], %firstSub, "");
            %serverAddress = Strreplace(%firstSub, "DTSS", "");
            if($ServerInfo::Address $= %serverAddress)
            {
               echo("Already present");
               return;
            }
         }
         $favorite::ServerFavorite[$favorite::ServerFavoriteCount] = $ServerInfo::Name @ "DTSS" @ $ServerInfo::Address;
         $favorite::ServerFavoriteCount++;
   }
}
function removeServerFromList()
{
   if($favorite::ServerFavoriteCount == 0)
   {
      echo("No Favorites");
      return;
   }
   else if($favorite::ServerFavoriteCount == 1)
   {
      echo("Only 1 Favorite");
      deleteVariables("$favorite::ServerFavorite0");
      $favorite::ServerFavoriteCount = 0;
   }
   else
   {
      %id = JF_serverList.getSelectedId();
      %row = JF_serverList.getSelectedRow();
      echo("More than 1 Favorite");
      echo("This is the selected ID: " @ %id);
      echo("This is the selected Row Index: " @ %row);
      // The server info index is stored in the row along with the
      // rest of displayed info.
      %index = getField(JF_serverList.getRowTextById(%id),6);
      setServerInfo(%index);
      %sc = $favorite::ServerFavoriteCount;
      %match = "";
 
      for (%i = 0; %i < %sc; %i++) 
      {
         %firstSub = strchr( $favorite::ServerFavorite[%i] , "DTSS" );
         %serverName = Strreplace($favorite::ServerFavorite[%i], %firstSub, "");
         %serverAddress = Strreplace(%firstSub, "DTSS", "");
         %temp[%i] = $favorite::ServerFavorite[%i];
 
         if($ServerInfo::Address $= %serverAddress)
         {
            echo("Match found");
            %match = $favorite::ServerFavorite[%i];
         }
      }
      if(%match !$= "")
      {
         %sc = $favorite::ServerFavoriteCount;
         %d = 0;
         for (%i = 0; %i < %sc; %i++) 
         {
            echo("This is the temp: " @ %temp[%i]);
            echo("This is the original: " @ $favorite::ServerFavorite[%i]);
         
            if(%temp[%i] $= %match)
            {
               echo("Its the match so don't renumber it");
            }
            else
            {
               echo("Its not the match so renumber it");
               $favorite::ServerFavorite[%d] = %temp[%i];
               %d++;
            }
         }
         $favorite::ServerFavoriteCount = %sc - 1;
         deleteVariables("$favorite::ServerFavorite" @ $favorite::ServerFavoriteCount);
      }
   }
   export("$favorite::*", "main/client/favorites.cs", False);

   exec("main/client/favorites.cs");
   OptFavoritesPane.query();

   JF_serverList.setSelectedRow(0);
}

Thank you in advance.

The only code changes to this so far is renaming the $pref::Client favoritites to $favorites in serverQuery.cc so I could set up my favorites to export in a separate file from the prefs.cs which is named favorites.

Thanks in advance.