public PlayersSelectViewModel(string label, IEnumerable <int> humans, RangeViewModel minMax)
        {
            Label  = label;
            Humans = new OptionInputViewModel <int>(humans.ToArray());
            MinMax = minMax;

            RefreshForHumanPlayers = ReactiveCommand.Create((OptionInputItem <int> item) =>
            {
                OptionInputViewModel <int> minInput = MinMax.MinInput;
                foreach (var minItem in minInput.Items)
                {
                    minItem.IsEnabled = minItem.Item >= item.Item;
                }
                if (!minInput.SelectedItem.IsEnabled)
                {
                    minInput.SelectedItem = minInput.Items.Where(x => x.IsEnabled).First();
                }
            });

            RefreshForRaces = ReactiveCommand.Create((IEnumerable <DowRace> races) =>
            {
                Races = new ProportionalOptionsViewModel <DowRace>("Races", race => race.Name, races.ToArray());
            });

            this.WhenAnyValue(x => x.Humans.SelectedItem)
            .DistinctUntilChanged()
            .InvokeCommand(RefreshForHumanPlayers);
        }
示例#2
0
        public RangeViewModel(int min, int max)
        {
            int count = max - min + 1;

            MinInput = new OptionInputViewModel <int>(Enumerable.Range(min, count).ToArray());
            MaxInput = new OptionInputViewModel <int>(Enumerable.Range(min, count).ToArray());
            MaxInput.SelectedItem = MaxInput.Items.Last();

            RefreshForMin = ReactiveCommand.Create((OptionInputItem <int> item) =>
            {
                foreach (var maxItem in MaxInput.Items)
                {
                    maxItem.IsEnabled = maxItem.Item >= item.Item;
                }
                if (!MaxInput.SelectedItem.IsEnabled)
                {
                    MaxInput.SelectedItem = MaxInput.Items.Where(x => x.IsEnabled).First();
                }
            });

            this.WhenAnyValue(x => x.MinInput.SelectedItem)
            .DistinctUntilChanged()
            .InvokeCommand(RefreshForMin);
        }
        public TeamTabViewModel()
        {
            GlobalPlayerOptions = new PlayersSelectViewModel("Players",
                                                             Enumerable.Range(1, 8), new RangeViewModel(2, 8));

            TeamNum = new OptionInputViewModel <int>(Enumerable.Range(2, 7).ToArray());

            RefreshForMin = ReactiveCommand.Create((OptionInputItem <int> min) =>
            {
                foreach (var teamItem in TeamNum.Items)
                {
                    teamItem.IsEnabled = teamItem.Item <= min.Item;
                }
                if (!TeamNum.SelectedItem.IsEnabled)
                {
                    TeamNum.SelectedItem = TeamNum.Items.Last(x => x.IsEnabled);
                }
            });

            RefreshTeamList = ReactiveCommand.Create((int teams) =>
            {
                if (TeamPlayerOptions.Count < teams)
                {
                    for (int i = TeamPlayerOptions.Count; i < teams; ++i)
                    {
                        var teamOptions = new PlayersSelectViewModel($"Team {i + 1}",
                                                                     Enumerable.Range(0, 7).ToArray(), new RangeViewModel(1, 7));

                        TeamPlayerOptions.Add(teamOptions);
                    }
                }
                else
                {
                    for (int i = TeamPlayerOptions.Count - 1; i >= teams; --i)
                    {
                        TeamPlayerOptions.RemoveAt(i);
                    }
                }
            });

            //RefreshForMod = ReactiveCommand.CreateFromTask(async (int id) =>
            //{
            //    Races.Clear();
            //    var (races, maps, rules) = await Observable.Start(() =>
            //    {
            //        using var store = new ModsDataStore();
            //        return (store.GetRaces(id).ToList(), store.GetMaps(id).ToList(), store.GetRules(id).ToList());
            //    }, RxApp.TaskpoolScheduler);

            //    maps.Sort((a, b) => a.Players - b.Players);

            //    Races.AddRange(races);

            //    await GlobalPlayerOptions.RefreshForRaces.Execute(races);

            //    foreach (var team in TeamPlayerOptions)
            //    {
            //        await team.RefreshForRaces.Execute(races);
            //    }

            //    Maps = new ToggleItemListViewModel<DowMap>("Maps", maps.Select(map => new ToggleItemViewModel<DowMap>(true) { Label = $"{map.Name}", Item = map }));
            //    Rules = new ToggleItemListViewModel<GameRule>("Win Conditions", rules.Where(rule => rule.IsWinCondition)
            //            .Select(rule => new ToggleItemViewModel<GameRule>(true) { Label = rule.Name, Item = rule }));
            //});

            //RefreshMapsForRange = ReactiveCommand.Create(((OptionInputItem<int> min, OptionInputItem<int> max) minMax) =>
            //{
            //    for (int i = 0; i < MapTypes.Count; ++i)
            //    {
            //        ToggleItemViewModel<int> mapType = MapTypes[i];
            //        int mapPlayers = i + 2;
            //        bool wasDisabled = !mapType.IsEnabled;
            //        mapType.IsEnabled = mapPlayers >= minMax.min.Item && mapPlayers <= minMax.max.Item;
            //        if (!mapType.IsEnabled)
            //        {
            //            mapType.IsToggled = false;
            //        }
            //        else if (wasDisabled)
            //        {
            //            mapType.IsToggled = true;
            //        }
            //    }
            //});

            //this.WhenAnyValue(x => x.GlobalPlayerOptions.MinMax.MinInput.SelectedItem,
            //        x => x.GlobalPlayerOptions.MinMax.MaxInput.SelectedItem)
            //    .DistinctUntilChanged()
            //    .InvokeCommand(RefreshMapsForRange);

            this.WhenAnyValue(x => x.TeamNum.SelectedItem)
            .DistinctUntilChanged()
            .Select(item => item.Item)
            .InvokeCommand(RefreshTeamList);

            this.WhenAnyValue(x => x.GlobalPlayerOptions.MinMax.MinInput.SelectedItem)
            .DistinctUntilChanged()
            .InvokeCommand(RefreshForMin);

            //this.WhenAnyValue(x => x.Mod)
            //    .Where(mod => mod != null)
            //    .Select(mod => mod.Id)
            //    .DistinctUntilChanged()
            //    .InvokeCommand(RefreshForMod);
        }
示例#4
0
        public GenerationViewModel(IScreen screen) : base(screen, "generation")
        {
            GameTab = new GameTabViewModel();
            TeamTab = new TeamTabViewModel();

            using var store = new ModsDataStore();

            DowMod[] mods = store.GetPlayableMods().ToArray();

            IEnumerable <DowMod> addonMods = mods.Where(mod => !mod.IsVanilla && DowConstants.IsVanilla(mod.ModFolder));
            IEnumerable <DowMod> baseMods  = mods.Where(mod => mod.IsVanilla || !DowConstants.IsVanilla(mod.ModFolder));

            GeneralTab = new GeneralTabViewModel(addonMods.SelectMany(mod => mod.Maps).ToList());

            Mod = new OptionInputViewModel <DowMod>(mod => mod.Name, baseMods.ToArray());

            RefreshMod = ReactiveCommand.Create((DowMod mod) =>
            {
                GeneralTab.Mod = mod;
            });

            GenerateMatchupAction = ReactiveCommand.CreateFromObservable(() =>
            {
                var settings = new GenerationSettings()
                {
                    Mod  = Mod.SelectedItem.Item,
                    Maps = GeneralTab.Maps.Items.Concat(GeneralTab.AddonMaps.Items)
                           .Where(map => map.IsEnabled && map.IsToggled)
                           .Select(map => map.Item).ToList(),
                    Rules = GeneralTab.Rules.Items
                            .Where(rule => rule.IsToggled)
                            .Select(rule => rule.Item).ToList()
                };

                foreach (var diff in GameTab.DiffOption.Items)
                {
                    settings.GameDifficultyTickets[(int)diff.Item] = diff.Input;
                }

                foreach (var speed in GameTab.SpeedOption.Items)
                {
                    settings.GameSpeedTickets[(int)speed.Item] = speed.Input;
                }

                foreach (var rate in GameTab.RateOption.Items)
                {
                    settings.ResourceRateTickets[(int)rate.Item] = rate.Input;
                }

                foreach (var start in GameTab.StartingOption.Items)
                {
                    settings.StartResourceTickets[(int)start.Item] = start.Input;
                }

                return(HostScreen.Router.Navigate.Execute(new MatchupViewModel(HostScreen, settings)));
            });

            this.WhenAnyValue(x => x.Mod.SelectedItem)
            .DistinctUntilChanged()
            .Select(mod => mod.Item)
            .InvokeCommand(RefreshMod);
        }