Example #1
0
        void SetupFilters()
        {
            // Game type
            {
                var ddb = panel.GetOrNull<DropDownButtonWidget>("FLT_GAMETYPE_DROPDOWNBUTTON");
                if (ddb != null)
                {
                    // Using list to maintain the order
                    var options = new List<Pair<GameType, string>>
                    {
                        Pair.New(GameType.Any, ddb.GetText()),
                        Pair.New(GameType.Singleplayer, "Singleplayer"),
                        Pair.New(GameType.Multiplayer, "Multiplayer")
                    };
                    var lookup = options.ToDictionary(kvp => kvp.First, kvp => kvp.Second);

                    ddb.GetText = () => lookup[filter.Type];
                    ddb.OnMouseDown = _ =>
                    {
                        Func<Pair<GameType, string>, ScrollItemWidget, ScrollItemWidget> setupItem = (option, tpl) =>
                        {
                            var item = ScrollItemWidget.Setup(
                                tpl,
                                () => filter.Type == option.First,
                                () => { filter.Type = option.First; ApplyFilter(); });
                            item.Get<LabelWidget>("LABEL").GetText = () => option.Second;
                            return item;
                        };

                        ddb.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 330, options, setupItem);
                    };
                }
            }

            // Date type
            {
                var ddb = panel.GetOrNull<DropDownButtonWidget>("FLT_DATE_DROPDOWNBUTTON");
                if (ddb != null)
                {
                    // Using list to maintain the order
                    var options = new List<Pair<DateType, string>>
                    {
                        Pair.New(DateType.Any, ddb.GetText()),
                        Pair.New(DateType.Today, "Today"),
                        Pair.New(DateType.LastWeek, "Last 7 days"),
                        Pair.New(DateType.LastFortnight, "Last 14 days"),
                        Pair.New(DateType.LastMonth, "Last 30 days")
                    };
                    var lookup = options.ToDictionary(kvp => kvp.First, kvp => kvp.Second);

                    ddb.GetText = () => lookup[filter.Date];
                    ddb.OnMouseDown = _ =>
                    {
                        Func<Pair<DateType, string>, ScrollItemWidget, ScrollItemWidget> setupItem = (option, tpl) =>
                        {
                            var item = ScrollItemWidget.Setup(
                                tpl,
                                () => filter.Date == option.First,
                                () => { filter.Date = option.First; ApplyFilter(); });

                            item.Get<LabelWidget>("LABEL").GetText = () => option.Second;
                            return item;
                        };

                        ddb.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 330, options, setupItem);
                    };
                }
            }

            // Duration
            {
                var ddb = panel.GetOrNull<DropDownButtonWidget>("FLT_DURATION_DROPDOWNBUTTON");
                if (ddb != null)
                {
                    // Using list to maintain the order
                    var options = new List<Pair<DurationType, string>>
                    {
                        Pair.New(DurationType.Any, ddb.GetText()),
                        Pair.New(DurationType.VeryShort, "Under 5 min"),
                        Pair.New(DurationType.Short, "Short (10 min)"),
                        Pair.New(DurationType.Medium, "Medium (30 min)"),
                        Pair.New(DurationType.Long, "Long (60+ min)")
                    };
                    var lookup = options.ToDictionary(kvp => kvp.First, kvp => kvp.Second);

                    ddb.GetText = () => lookup[filter.Duration];
                    ddb.OnMouseDown = _ =>
                    {
                        Func<Pair<DurationType, string>, ScrollItemWidget, ScrollItemWidget> setupItem = (option, tpl) =>
                        {
                            var item = ScrollItemWidget.Setup(
                                tpl,
                                () => filter.Duration == option.First,
                                () => { filter.Duration = option.First; ApplyFilter(); });
                            item.Get<LabelWidget>("LABEL").GetText = () => option.Second;
                            return item;
                        };

                        ddb.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 330, options, setupItem);
                    };
                }
            }

            // Map
            {
                var ddb = panel.GetOrNull<DropDownButtonWidget>("FLT_MAPNAME_DROPDOWNBUTTON");
                if (ddb != null)
                {
                    var options = new HashSet<string>(replays.Select(r => r.GameInfo.MapTitle), StringComparer.OrdinalIgnoreCase).ToList();
                    options.Sort(StringComparer.OrdinalIgnoreCase);
                    options.Insert(0, null);	// no filter

                    var anyText = ddb.GetText();
                    ddb.GetText = () => string.IsNullOrEmpty(filter.MapName) ? anyText : filter.MapName;
                    ddb.OnMouseDown = _ =>
                    {
                        Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (option, tpl) =>
                        {
                            var item = ScrollItemWidget.Setup(
                                tpl,
                                () => string.Compare(filter.MapName, option, true) == 0,
                                () => { filter.MapName = option; ApplyFilter(); });
                            item.Get<LabelWidget>("LABEL").GetText = () => option ?? anyText;
                            return item;
                        };

                        ddb.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 330, options, setupItem);
                    };
                }
            }

            // Players
            {
                var ddb = panel.GetOrNull<DropDownButtonWidget>("FLT_PLAYER_DROPDOWNBUTTON");
                if (ddb != null)
                {
                    var options = new HashSet<string>(replays.SelectMany(r => r.GameInfo.Players.Select(p => p.Name)), StringComparer.OrdinalIgnoreCase).ToList();
                    options.Sort(StringComparer.OrdinalIgnoreCase);
                    options.Insert(0, null);	// no filter

                    var anyText = ddb.GetText();
                    ddb.GetText = () => string.IsNullOrEmpty(filter.PlayerName) ? anyText : filter.PlayerName;
                    ddb.OnMouseDown = _ =>
                    {
                        Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (option, tpl) =>
                        {
                            var item = ScrollItemWidget.Setup(
                                tpl,
                                () => string.Compare(filter.PlayerName, option, true) == 0,
                                () => { filter.PlayerName = option; ApplyFilter(); });
                            item.Get<LabelWidget>("LABEL").GetText = () => option ?? anyText;
                            return item;
                        };

                        ddb.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 330, options, setupItem);
                    };
                }
            }

            // Outcome (depends on Player)
            {
                var ddb = panel.GetOrNull<DropDownButtonWidget>("FLT_OUTCOME_DROPDOWNBUTTON");
                if (ddb != null)
                {
                    ddb.IsDisabled = () => string.IsNullOrEmpty(filter.PlayerName);

                    // Using list to maintain the order
                    var options = new List<Pair<WinState, string>>
                    {
                        Pair.New(WinState.Undefined, ddb.GetText()),
                        Pair.New(WinState.Lost, "Defeat"),
                        Pair.New(WinState.Won, "Victory")
                    };
                    var lookup = options.ToDictionary(kvp => kvp.First, kvp => kvp.Second);

                    ddb.GetText = () => lookup[filter.Outcome];
                    ddb.OnMouseDown = _ =>
                    {
                        Func<Pair<WinState, string>, ScrollItemWidget, ScrollItemWidget> setupItem = (option, tpl) =>
                        {
                            var item = ScrollItemWidget.Setup(
                                tpl,
                                () => filter.Outcome == option.First,
                                () => { filter.Outcome = option.First; ApplyFilter(); });
                            item.Get<LabelWidget>("LABEL").GetText = () => option.Second;
                            return item;
                        };

                        ddb.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 330, options, setupItem);
                    };
                }
            }

            // Faction (depends on Player)
            {
                var ddb = panel.GetOrNull<DropDownButtonWidget>("FLT_FACTION_DROPDOWNBUTTON");
                if (ddb != null)
                {
                    ddb.IsDisabled = () => string.IsNullOrEmpty(filter.PlayerName);

                    var options = new HashSet<string>(replays.SelectMany(r => r.GameInfo.Players.Select(p => p.FactionName).Where(n => !string.IsNullOrEmpty(n))), StringComparer.OrdinalIgnoreCase).ToList();
                    options.Sort(StringComparer.OrdinalIgnoreCase);
                    options.Insert(0, null);	// no filter

                    var anyText = ddb.GetText();
                    ddb.GetText = () => string.IsNullOrEmpty(filter.Faction) ? anyText : filter.Faction;
                    ddb.OnMouseDown = _ =>
                    {
                        Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (option, tpl) =>
                        {
                            var item = ScrollItemWidget.Setup(
                                tpl,
                                () => string.Compare(filter.Faction, option, true) == 0,
                                () => { filter.Faction = option; ApplyFilter(); });
                            item.Get<LabelWidget>("LABEL").GetText = () => option ?? anyText;
                            return item;
                        };

                        ddb.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 330, options, setupItem);
                    };
                }
            }

            // Reset button
            {
                var button = panel.Get<ButtonWidget>("FLT_RESET_BUTTON");
                button.IsDisabled = () => filter.IsEmpty;
                button.OnClick = () => { filter = new Filter(); ApplyFilter(); };
            }
        }
Example #2
0
        private List<string> GetPrefixList()
        {
            List<string> prefix = new List<string>();

            for (int i = 0; i < partnumber_grid.Rows.Count; i++)
            {
                prefix.Add(partnumber_grid.Rows[i].Cells["number"].Value.ToString ().Substring (0,3));
            }

            prefix = new HashSet<string>(prefix).ToList();

            prefix.Add("");

            prefix.Sort();

            return prefix.ToList();
        }