public EditSpellListPageViewModel(IViewServices viewSvc, ISpellList spellList) : base(spellList) { _title = spellList.Title; _class = spellList.Class; _level = spellList.Level; PickSpellListCommand = new Command(() => { spellList.Title = _title; spellList.Class = _class; spellList.Level = _level; Services.MockDataStore.Instance.Save(spellList); viewSvc.Navigation.PushAsync(new Views.PickSpellListPage(spellList)); }); DeleteSpellListCommand = new Command(async() => { if (await viewSvc.DisplayAlert("Delete Spell List", $"Are you sure you want to delete \"{Title}\"?", "Yes", "No")) { Services.MockDataStore.Instance.Delete(SpellList); await viewSvc.Navigation.PopToRootAsync(); } }); CloneSpellListCommand = new Command(() => viewSvc.Navigation.PushAsync(new Views.EditSpellListPage(SpellList.Clone()))); }
public IEnumerable <IClassSpell> LoadSpellsForSpellList(ISpellList spellList) { var classSpells = Spells.ByClass(spellList.Class); return(classSpells .Where(_ => _.Level <= spellList.Level) .OrderBy(_ => _.Level) .ThenBy(_ => _.Name)); }
public void Delete(ISpellList spellList) { var index = spellLists.FindIndex(_ => _.ID == spellList.ID); if (index != -1) { spellLists.RemoveAt(index); } }
public ViewSpellListPageViewModel(IViewServices viewSvc, ISpellList spellList) : base(spellList) { EditSpellListCommand = new Command(() => viewSvc.Navigation.PushAsync(new Views.EditSpellListPage(spellList))); var spells = Services.MockDataStore.Instance.LoadSpellsForSpellList(spellList); Spells = spells.Select(_ => new SpellListEntryViewModel(_)).ToList(); }
public CastSpell(IWriteToClient writer, ISpellTargetCharacter spellTargetCharacter, ICache cache, IDamage damage, IUpdateClientUI updateClientUi, IDice dice, ISpellList spellList) { _writer = writer; _spellTargetCharacter = spellTargetCharacter; _cache = cache; _damage = damage; _updateClientUi = updateClientUi; _dice = dice; _spellList = spellList; }
public PickSpellListPageViewModel(IViewServices viewSvc, ISpellList spellList) : base(spellList) { SaveSpellListCommand = new Command(() => { Services.MockDataStore.Instance.Save(spellList); viewSvc.Navigation.PopToRootAsync(false); viewSvc.Navigation.PushAsync(new Views.ViewSpellListPage(spellList)); }); BuySpellCommand = new Command(obj => { var vm = (SpellListEntryViewModel)obj; vm.Bought = Math.Min(vm.Max, vm.Bought + 1); }); SellSpellCommand = new Command(obj => { var vm = (SpellListEntryViewModel)obj; vm.Bought = Math.Max(0, vm.Bought - 1); }); Spells = Services.MockDataStore.Instance.LoadSpellsForSpellList(spellList) .Select(_ => new SpellListEntryViewModel(_)) .OrderByDescending(_ => _.Level) .ThenBy(_ => _.Name) .ToList(); foreach (var spells in Spells) { spells.PropertyChanged += Spells_PropertyChanged; } GroupHeaders = new PickSpellGroupHeaderViewModel[] { new PickSpellGroupHeaderViewModel(1), new PickSpellGroupHeaderViewModel(2), new PickSpellGroupHeaderViewModel(3), new PickSpellGroupHeaderViewModel(4), new PickSpellGroupHeaderViewModel(5), new PickSpellGroupHeaderViewModel(6) }; }
public GameLoop(IWriteToClient writeToClient, ICache cache, ICommands commands, ICombat combat, IDataBase database, IDice dice, IUpdateClientUI client, ITime time, ICore core, ISpellList spelllist, IWeather weather) { _writeToClient = writeToClient; _cache = cache; _commands = commands; _combat = combat; _db = database; _dice = dice; _client = client; _time = time; _core = core; _spellList = spelllist; _weather = weather; if (_hints == null) { _hints = _core.Hints(); } }
public PickSpellListPage(ISpellList spellList) { Title = $"{spellList.Title} (L{spellList.Level})"; var vm = new PickSpellListPageViewModel(this, spellList); BindingContext = vm; ToolbarItems.Add(new ToolbarItem { Text = "Save" } .AndBind(_ => _.SetBinding(ToolbarItem.CommandProperty, nameof(PickSpellListPageViewModel.SaveSpellListCommand)))); var list = new SfListView { AutoFitMode = AutoFitMode.Height, SelectionMode = SelectionMode.None, ItemSpacing = new Thickness(5), IsStickyGroupHeader = true, GroupHeaderSize = 100, GroupHeaderTemplate = new DataTemplate(() => new ViewCell { View = new StackLayout { BackgroundColor = Color.Gray, Orientation = StackOrientation.Horizontal, Children = { new Label { FontAttributes = FontAttributes.Bold, TextColor = Color.Black, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), Margin = new Thickness(0) }.AndBind(Label.TextProperty, "Key.LevelText"), new Label { FontAttributes = FontAttributes.Bold, TextColor = Color.Black, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), Margin = new Thickness(0) }.AndBind(Label.TextProperty, "Key.PointsRemaining") } } }), ItemTemplate = new DataTemplate(() => new Grid { Margin = new Thickness(0), Padding = new Thickness(0), RowDefinitions = { new RowDefinition { Height = GridLength.Star }, new RowDefinition { Height = GridLength.Auto } }, ColumnDefinitions = { new ColumnDefinition { Width = GridLength.Star }, new ColumnDefinition { Width = GridLength.Auto }, new ColumnDefinition { Width = GridLength.Auto }, } }.AndBind(Grid.IsVisibleProperty, nameof(SpellListEntryViewModel.IsVisible)) .AddCells( new GridCell(0, 0, new StackLayout { Orientation = StackOrientation.Horizontal, Children = { new Label { Margin = new Thickness(0), FontAttributes = FontAttributes.Bold, VerticalTextAlignment = TextAlignment.Center, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), TextColor = Color.Black, }.AndBind(Label.TextProperty, nameof(SpellListEntryViewModel.Name)), new Label { Margin = new Thickness(10, 0, 0, 0), VerticalTextAlignment = TextAlignment.Center, FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)), TextColor = Color.Black, }.AndBind(Label.TextProperty, nameof(SpellListEntryViewModel.Uses)) } }), new GridCell(0, 1, new StackLayout { Orientation = StackOrientation.Horizontal, Children = { new Label { Margin = new Thickness(30, 0, 0, 0), FontAttributes = FontAttributes.Bold, VerticalTextAlignment = TextAlignment.Center, FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)), TextColor = Color.Black, Text = "C:" }, new Label { Margin = new Thickness(0), VerticalTextAlignment = TextAlignment.Center, FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)), TextColor = Color.Black, }.AndBind(Label.TextProperty, nameof(SpellListEntryViewModel.Cost)), new Label { Margin = new Thickness(5, 0, 0, 0), FontAttributes = FontAttributes.Bold, VerticalTextAlignment = TextAlignment.Center, FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)), TextColor = Color.Black, Text = "M:" }, new Label { VerticalTextAlignment = TextAlignment.Center, Margin = new Thickness(0), FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)), TextColor = Color.Black, }.AndBind(Label.TextProperty, nameof(SpellListEntryViewModel.MaxText)), new Label { Margin = new Thickness(5, 0, 0, 0), FontAttributes = FontAttributes.Bold, VerticalTextAlignment = TextAlignment.Center, FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)), TextColor = Color.Black, Text = "P:" }, new Label { Margin = new Thickness(0), VerticalTextAlignment = TextAlignment.Center, FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)), TextColor = Color.Black, }.AndBind(Label.TextProperty, nameof(SpellListEntryViewModel.Bought)), } }), new GridCell(1, 0, 1, 2, new StackLayout { Orientation = StackOrientation.Horizontal, Children = { new Button { Text = "-", WidthRequest = 50 } .AndBind(Button.IsVisibleProperty, nameof(SpellListEntryViewModel.CanSell)) .AndBind(Button.CommandProperty, nameof(PickSpellListPageViewModel.SellSpellCommand), BindingContext) .AndBind(Button.CommandParameterProperty, "."), new Button { Text = "+", WidthRequest = 50 } .AndBind(Button.IsVisibleProperty, nameof(SpellListEntryViewModel.CanBuy)) .AndBind(Button.CommandProperty, nameof(PickSpellListPageViewModel.BuySpellCommand), BindingContext) .AndBind(Button.CommandParameterProperty, ".") } }) )) }.AndBind(SfListView.ItemsSourceProperty, nameof(PickSpellListPageViewModel.Spells)); list.DataSource.GroupDescriptors.Add(new Syncfusion.DataSource.GroupDescriptor() { PropertyName = "Level", KeySelector = _ => vm.GroupHeaders[((SpellListEntryViewModel)_).Level - 1] }); Content = new StackLayout { Children = { list } }; }
public void SaveSpellsForSpellList(ISpellList spellList, IEnumerable <IClassSpell> classSpells) { throw new NotImplementedException(); }
public void Save(ISpellList spellList) { Delete(spellList); spellLists.Add((SpellList)spellList); }
public ViewSpellListPage(ISpellList spellList) { Title = spellList.Title; BindingContext = new ViewSpellListPageViewModel(this, spellList); ToolbarItems.Add(new ToolbarItem { Text = "Edit" } .AndBind(_ => _.SetBinding(ToolbarItem.CommandProperty, nameof(ViewSpellListPageViewModel.EditSpellListCommand)))); var listView = new SfListView { AutoFitMode = AutoFitMode.Height, SelectionMode = SelectionMode.None, ItemSpacing = new Thickness(5), IsStickyGroupHeader = true, GroupHeaderSize = 100, GroupHeaderTemplate = new DataTemplate(() => new ViewCell { View = new Label { FontAttributes = FontAttributes.Bold, TextColor = Color.Black, BackgroundColor = Color.Green, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), Margin = new Thickness(0) }.AndBind(Label.TextProperty, "Key") }), ItemTemplate = new DataTemplate(() => new Grid { Margin = new Thickness(0), Padding = new Thickness(0), RowDefinitions = { new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Star } }, ColumnDefinitions = { new ColumnDefinition { Width = GridLength.Star }, new ColumnDefinition { Width = GridLength.Auto }, } }.AddCells( new GridCell(0, 0, new Label { FontAttributes = FontAttributes.Bold, TextColor = Color.Black, FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)), Margin = new Thickness(0) }.AndBind(Label.TextProperty, nameof(SpellListEntryViewModel.Name))), new GridCell(1, 0, new Label { FontAttributes = FontAttributes.Bold, TextColor = Color.Black, FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)), Margin = new Thickness(0) }.AndBind(Label.TextProperty, nameof(SpellListEntryViewModel.Uses))))) }.AndBind(SfListView.ItemsSourceProperty, nameof(PickSpellListPageViewModel.Spells)); listView.DataSource.GroupDescriptors.Add(new Syncfusion.DataSource.GroupDescriptor() { PropertyName = "Level" }); Content = new StackLayout { Children = { new Label().AndBind(_ => _.SetBinding(Label.TextProperty, nameof(SpellListViewModel.Title))), new Label().AndBind(_ => _.SetBinding(Label.TextProperty, nameof(SpellListViewModel.Subtitle))), listView } }; }