Пример #1
0
        public static bool PromptConfirmReplayCompatibility(ReplayMetadata replayMeta, Action onCancel = null)
        {
            if (onCancel == null)
                onCancel = DoNothing;

            if (replayMeta == null)
                return IncompatibleReplayDialog("outdated engine", null, onCancel);

            var version = replayMeta.GameInfo.Version;
            if (version == null)
                return IncompatibleReplayDialog("unknown version", version, onCancel);

            var mod = replayMeta.GameInfo.Mod;
            if (mod == null)
                return IncompatibleReplayDialog("unknown mod", mod, onCancel);

            var allMods = ModMetadata.AllMods;
            if (!allMods.ContainsKey(mod))
                return IncompatibleReplayDialog("unavailable mod", mod, onCancel);
            else if (allMods[mod].Version != version)
                return IncompatibleReplayDialog("incompatible version", version, onCancel);

            if (replayMeta.GameInfo.MapPreview.Status != MapStatus.Available)
                return IncompatibleReplayDialog("unavailable map", replayMeta.GameInfo.MapUid,  onCancel);

            return true;
        }
Пример #2
0
        public static bool PromptConfirmReplayCompatibility(ReplayMetadata replayMeta, Action onCancel = null)
        {
            if (onCancel == null)
                onCancel = DoNothing;

            if (replayMeta == null)
            {
                ConfirmationDialogs.ButtonPrompt("Incompatible Replay", "Replay metadata could not be read.", onCancel: onCancel);
                return false;
            }

            var version = replayMeta.GameInfo.Version;
            if (version == null)
                return IncompatibleReplayDialog("unknown version", version, onCancel);

            var mod = replayMeta.GameInfo.Mod;
            if (mod == null)
                return IncompatibleReplayDialog("unknown mod", mod, onCancel);

            if (!Game.Mods.ContainsKey(mod))
                return IncompatibleReplayDialog("unavailable mod", mod, onCancel);

            if (Game.Mods[mod].Metadata.Version != version)
                return IncompatibleReplayDialog("incompatible version", version, onCancel);

            if (replayMeta.GameInfo.MapPreview.Status != MapStatus.Available)
                return IncompatibleReplayDialog("unavailable map", replayMeta.GameInfo.MapUid,  onCancel);

            return true;
        }
Пример #3
0
        void SelectReplay(ReplayMetadata replay)
        {
            selectedReplay = replay;
            selectedSpawns = (selectedReplay != null)
                ? LobbyUtils.GetSpawnOccupants(selectedReplay.GameInfo.Players, selectedReplay.GameInfo.MapPreview)
                : new Dictionary<CPos, SpawnOccupant>();

            if (replay == null)
                return;

            try
            {
                var players = replay.GameInfo.Players
                    .GroupBy(p => p.Team)
                    .OrderBy(g => g.Key);

                var teams = new Dictionary<string, IEnumerable<GameInformation.Player>>();
                var noTeams = players.Count() == 1;
                foreach (var p in players)
                {
                    var label = noTeams ? "Players" : p.Key == 0 ? "No Team" : "Team {0}".F(p.Key);
                    teams.Add(label, p);
                }

                playerList.RemoveChildren();

                foreach (var kv in teams)
                {
                    var group = kv.Key;
                    if (group.Length > 0)
                    {
                        var header = ScrollItemWidget.Setup(playerHeader, () => true, () => { });
                        header.Get<LabelWidget>("LABEL").GetText = () => group;
                        playerList.AddChild(header);
                    }

                    foreach (var option in kv.Value)
                    {
                        var o = option;

                        var color = o.Color.RGB;

                        var item = ScrollItemWidget.Setup(playerTemplate, () => false, () => { });

                        var label = item.Get<LabelWidget>("LABEL");
                        label.GetText = () => o.Name;
                        label.GetColor = () => color;

                        var flag = item.Get<ImageWidget>("FLAG");
                        flag.GetImageCollection = () => "flags";
                        flag.GetImageName = () => o.FactionId;

                        playerList.AddChild(item);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Write("debug", "Exception while parsing replay: {0}", e);
                SelectReplay(null);
            }
        }
Пример #4
0
 void RenameReplay(ReplayMetadata replay, string newFilenameWithoutExtension)
 {
     try
     {
         replay.RenameFile(newFilenameWithoutExtension);
         replayState[replay].Item.Text = newFilenameWithoutExtension;
     }
     catch (Exception ex)
     {
         Log.Write("debug", ex.ToString());
         return;
     }
 }
Пример #5
0
        bool EvaluateReplayVisibility(ReplayMetadata replay)
        {
            // Game type
            if ((filter.Type == GameType.Multiplayer && replay.GameInfo.IsSinglePlayer) || (filter.Type == GameType.Singleplayer && !replay.GameInfo.IsSinglePlayer))
                return false;

            // Date type
            if (filter.Date != DateType.Any)
            {
                TimeSpan t;
                switch (filter.Date)
                {
                    case DateType.Today:
                        t = TimeSpan.FromDays(1d);
                        break;

                    case DateType.LastWeek:
                        t = TimeSpan.FromDays(7d);
                        break;

                    case DateType.LastFortnight:
                        t = TimeSpan.FromDays(14d);
                        break;

                    case DateType.LastMonth:
                    default:
                        t = TimeSpan.FromDays(30d);
                        break;
                }

                if (replay.GameInfo.StartTimeUtc < DateTime.UtcNow - t)
                    return false;
            }

            // Duration
            if (filter.Duration != DurationType.Any)
            {
                var minutes = replay.GameInfo.Duration.TotalMinutes;
                switch (filter.Duration)
                {
                    case DurationType.VeryShort:
                        if (minutes >= 5)
                            return false;
                        break;

                    case DurationType.Short:
                        if (minutes < 5 || minutes >= 20)
                            return false;
                        break;

                    case DurationType.Medium:
                        if (minutes < 20 || minutes >= 60)
                            return false;
                        break;

                    case DurationType.Long:
                        if (minutes < 60)
                            return false;
                        break;
                }
            }

            // Map
            if (!string.IsNullOrEmpty(filter.MapName) && string.Compare(filter.MapName, replay.GameInfo.MapTitle, true) != 0)
                return false;

            // Player
            if (!string.IsNullOrEmpty(filter.PlayerName))
            {
                var player = replay.GameInfo.Players.FirstOrDefault(p => string.Compare(filter.PlayerName, p.Name, true) == 0);
                if (player == null)
                    return false;

                // Outcome
                if (filter.Outcome != WinState.Undefined && filter.Outcome != player.Outcome)
                    return false;

                // Faction
                if (!string.IsNullOrEmpty(filter.Faction) && string.Compare(filter.Faction, player.FactionName, true) != 0)
                    return false;
            }

            return true;
        }
Пример #6
0
        void DeleteReplay(ReplayMetadata replay)
        {
            try
            {
                File.Delete(replay.FilePath);
            }
            catch (Exception ex)
            {
                Game.Debug("Failed to delete replay file '{0}'. See the logs for details.", replay.FilePath);
                Log.Write("debug", ex.ToString());
                return;
            }

            if (replay == selectedReplay)
                SelectReplay(null);

            replayList.RemoveChild(replayState[replay].Item);
            replays.Remove(replay);
            replayState.Remove(replay);
        }
Пример #7
0
        void AddReplay(ReplayMetadata replay, ScrollItemWidget template)
        {
            var item = ScrollItemWidget.Setup(template,
                () => selectedReplay == replay,
                () => SelectReplay(replay),
                () => WatchReplay());

            replayState[replay] = new ReplayState
            {
                Item = item,
                Visible = true
            };

            item.Text = Path.GetFileNameWithoutExtension(replay.FilePath);
            item.Get<LabelWidget>("TITLE").GetText = () => item.Text;
            item.IsVisible = () => replayState[replay].Visible;
            replayList.AddChild(item);
        }