public void ListSaves()
        {
            savedGames.Clear();
            lbSaveGameList.ClearItems();
            lbSaveGameList.SelectedIndex = -1;

            if (!Directory.Exists(ProgramConstants.GamePath + SAVED_GAMES_DIRECTORY))
            {
                Logger.Log("Saved Games directory not found!");
                return;
            }

            string[] files = Directory.GetFiles(ProgramConstants.GamePath +
                                                SAVED_GAMES_DIRECTORY + Path.DirectorySeparatorChar,
                                                "*.SAV", SearchOption.TopDirectoryOnly);

            foreach (string file in files)
            {
                ParseSaveGame(file);
            }

            savedGames = savedGames.OrderBy(sg => sg.LastModified.Ticks).ToList();
            savedGames.Reverse();

            foreach (SavedGame sg in savedGames)
            {
                string[] item = new string[] {
                    Renderer.GetSafeString(sg.GUIName, lbSaveGameList.FontIndex),
                    sg.LastModified.ToString()
                };
                lbSaveGameList.AddItem(item, true);
            }
        }
        void ListGames()
        {
            lbGameList.SelectedIndex = -1;
            lbGameList.SetTopIndex(0);

            lbGameStatistics.ClearItems();
            lbGameList.ClearItems();
            listedGameIndexes.Clear();

            switch (cmbGameClassFilter.SelectedIndex)
            {
            case 0:
                ListAllGames();
                break;

            case 1:
                ListOnlineGames();
                break;

            case 2:
                ListPvPGames();
                break;

            case 3:
                ListCoOpGames();
                break;

            case 4:
                ListSkirmishGames();
                break;
            }

            listedGameIndexes.Reverse();

            SetTotalStatistics();

            foreach (int gameIndex in listedGameIndexes)
            {
                MatchStatistics ms       = sm.GetMatchByIndex(gameIndex);
                string          dateTime = ms.DateAndTime.ToShortDateString() + " " + ms.DateAndTime.ToShortTimeString();
                List <string>   info     = new List <string>();
                info.Add(Renderer.GetSafeString(dateTime, lbGameList.FontIndex));
                info.Add(ms.MapName);
                info.Add(ms.GameMode);
                if (ms.AverageFPS == 0)
                {
                    info.Add("-");
                }
                else
                {
                    info.Add(ms.AverageFPS.ToString());
                }
                info.Add(Renderer.GetSafeString(TimeSpan.FromSeconds(ms.LengthInSeconds).ToString(), lbGameList.FontIndex));
                info.Add(Conversions.BooleanToString(ms.SawCompletion, BooleanStringStyle.YESNO));
                lbGameList.AddItem(info, true);
            }
        }
        public void ListSaves()
        {
            savedGames.Clear();
            lbSaveGameList.ClearItems();
            lbSaveGameList.SelectedIndex = -1;

            if (!Directory.Exists(ProgramConstants.GamePath + SAVED_GAMES_DIRECTORY))
            {
                Logger.Log("Saved Games directory not found!");
                return;
            }

            string[] files = Directory.GetFiles(ProgramConstants.GamePath +
                                                SAVED_GAMES_DIRECTORY + Path.DirectorySeparatorChar,
                                                "*.SAV", SearchOption.TopDirectoryOnly);

            string[] directories = Directory.GetDirectories(ProgramConstants.GamePath + SAVED_GAMES_DIRECTORY);

            foreach (string dirPath in directories)
            {
                string _dirPath = dirPath.Replace('\\', '/');
                int    lastDirectorySeparatorIndex = _dirPath.LastIndexOf('/');
                string dirName = _dirPath.Substring(lastDirectorySeparatorIndex + 1);

                long.TryParse(dirName, NumberStyles.None, CultureInfo.InvariantCulture, out long uniqueSessionId);

                string[] saveNames = Directory.GetFiles(dirPath, "*.SAV");
                foreach (string file in saveNames)
                {
                    ParseSaveGame(file, uniqueSessionId);
                }
            }

            savedGames = savedGames.OrderBy(sg => sg.LastModified.Ticks).ToList();
            savedGames.Reverse();

            foreach (SavedGame sg in savedGames)
            {
                string[] item = new string[] {
                    Renderer.GetSafeString(sg.GUIName, lbSaveGameList.FontIndex),
                    sg.LastModified.ToString()
                };
                lbSaveGameList.AddItem(item, true);
            }
        }
        private void LbGameList_SelectedIndexChanged(object sender, EventArgs e)
        {
            lbGameStatistics.ClearItems();

            if (lbGameList.SelectedIndex == -1)
            {
                return;
            }

            MatchStatistics ms = sm.GetMatchByIndex(listedGameIndexes[lbGameList.SelectedIndex]);

            List <PlayerStatistics> players = new List <PlayerStatistics>();

            for (int i = 0; i < ms.GetPlayerCount(); i++)
            {
                players.Add(ms.GetPlayer(i));
            }

            players = players.OrderBy(p => p.Score).Reverse().ToList();

            Color textColor = UISettings.AltColor;

            for (int i = 0; i < ms.GetPlayerCount(); i++)
            {
                PlayerStatistics ps = players[i];

                //List<string> items = new List<string>();
                List <XNAListBoxItem> items = new List <XNAListBoxItem>();

                if (ps.Color > -1 && ps.Color < mpColors.Count)
                {
                    textColor = mpColors[ps.Color].XnaColor;
                }

                if (ps.IsAI)
                {
                    items.Add(new XNAListBoxItem(AILevelToString(ps.AILevel), textColor));
                }
                else
                {
                    items.Add(new XNAListBoxItem(ps.Name, textColor));
                }

                if (ps.WasSpectator)
                {
                    // Player was a spectator
                    items.Add(new XNAListBoxItem("-", textColor));
                    items.Add(new XNAListBoxItem("-", textColor));
                    items.Add(new XNAListBoxItem("-", textColor));
                    items.Add(new XNAListBoxItem("-", textColor));
                    items.Add(new XNAListBoxItem("-", textColor));
                    XNAListBoxItem spectatorItem = new XNAListBoxItem();
                    spectatorItem.Text      = "Spectator";
                    spectatorItem.TextColor = textColor;
                    spectatorItem.Texture   = sideTextures[sideTextures.Length - 1];
                    items.Add(spectatorItem);
                    items.Add(new XNAListBoxItem("-", textColor));
                }
                else
                {
                    if (!ms.SawCompletion)
                    {
                        // The game wasn't completed - we don't know the stats
                        items.Add(new XNAListBoxItem("-", textColor));
                        items.Add(new XNAListBoxItem("-", textColor));
                        items.Add(new XNAListBoxItem("-", textColor));
                        items.Add(new XNAListBoxItem("-", textColor));
                        items.Add(new XNAListBoxItem("-", textColor));
                    }
                    else
                    {
                        // The game was completed and the player was actually playing
                        items.Add(new XNAListBoxItem(ps.Kills.ToString(), textColor));
                        items.Add(new XNAListBoxItem(ps.Losses.ToString(), textColor));
                        items.Add(new XNAListBoxItem(ps.Economy.ToString(), textColor));
                        items.Add(new XNAListBoxItem(ps.Score.ToString(), textColor));
                        items.Add(new XNAListBoxItem(
                                      Conversions.BooleanToString(ps.Won, BooleanStringStyle.YESNO), textColor));
                    }

                    if (ps.Side == 0 || ps.Side > sides.Length)
                    {
                        items.Add(new XNAListBoxItem("Unknown", textColor));
                    }
                    else
                    {
                        XNAListBoxItem sideItem = new XNAListBoxItem();
                        sideItem.Text      = sides[ps.Side - 1];
                        sideItem.TextColor = textColor;
                        sideItem.Texture   = sideTextures[ps.Side - 1];
                        items.Add(sideItem);
                    }

                    items.Add(new XNAListBoxItem(TeamIndexToString(ps.Team), textColor));
                }

                if (!ps.IsLocalPlayer)
                {
                    lbGameStatistics.AddItem(items);

                    items.ForEach(item => item.Selectable = false);
                }
                else
                {
                    lbGameStatistics.AddItem(items);
                    lbGameStatistics.SelectedIndex = i;
                }
            }
        }
Example #5
0
        private void TunnelHandler_TunnelsRefreshed(object sender, EventArgs e)
        {
            lbTunnelList.ClearItems();

            int tunnelIndex = 0;

            foreach (CnCNetTunnel tunnel in tunnelHandler.Tunnels)
            {
                List <string> info = new List <string>();

                info.Add(tunnel.Name);
                info.Add(Conversions.BooleanToString(tunnel.Official, BooleanStringStyle.YESNO));
                if (tunnel.PingInMs == -1)
                {
                    info.Add("Unknown");
                }
                else
                {
                    info.Add(tunnel.PingInMs + " ms");
                }
                info.Add(tunnel.Clients + " / " + tunnel.MaxClients);

                lbTunnelList.AddItem(info, true);

                if ((tunnel.Official || tunnel.Recommended) && tunnel.PingInMs > -1)
                {
                    int rating = GetTunnelRating(tunnel);
                    if (rating < lowestTunnelRating)
                    {
                        bestTunnelIndex    = tunnelIndex;
                        lowestTunnelRating = rating;
                    }
                }

                tunnelIndex++;
            }

            if (tunnelHandler.Tunnels.Count > 0)
            {
                if (!isManuallySelectedTunnel)
                {
                    lbTunnelList.SelectedIndex = bestTunnelIndex;
                    isManuallySelectedTunnel   = false;
                }
                else
                {
                    int manuallySelectedIndex = tunnelHandler.Tunnels.FindIndex(t => t.Address == manuallySelectedTunnelAddress);

                    if (manuallySelectedIndex == -1)
                    {
                        lbTunnelList.SelectedIndex = bestTunnelIndex;
                        isManuallySelectedTunnel   = false;
                    }
                    else
                    {
                        lbTunnelList.SelectedIndex = manuallySelectedIndex;
                    }
                }

                btnCreateGame.AllowClick = true;
                btnLoadMPGame.AllowClick = AllowLoadingGame();
            }
            else
            {
                btnLoadMPGame.AllowClick = false;
                btnCreateGame.AllowClick = false;
            }
        }