Exemple #1
0
        private void UpdateArmorGrid(SelectedArmorGrid armorGrid, CharacterSheet.ArmorClassItem item, int itemIndex)
        {
            var sheet = CharacterSheetStorage.Instance.selectedCharacter;

            if (sheet == null)
            {
                return;
            }

#if EXPAND_CHECKBOX
            if (armorGrid.selectedHandler != null)
            {
                armorGrid.selected.CheckedChanged -= armorGrid.selectedHandler;
            }
            armorGrid.selectedHandler = (s, e) => ArmorSelected_CheckedChanged(item, e.Value);
            UpdateValue(armorGrid.selected, item.selected);
            armorGrid.selected.IsChecked       = item.selected;
            armorGrid.selected.CheckedChanged += armorGrid.selectedHandler;
#endif

            if (armorGrid.activeHandler != null)
            {
                armorGrid.active.CheckedChanged -= armorGrid.activeHandler;
            }
            armorGrid.activeHandler = (s, e) => ArmorActive_CheckedChanged(item, e.Value);
            UpdateValue(armorGrid.active, item.active);
            armorGrid.active.IsChecked       = item.active;
            armorGrid.active.CheckedChanged += armorGrid.activeHandler;

            UpdateValue(armorGrid.name, item.name);
            UpdateValue(armorGrid.armorBonus, item.ArmorBonus(sheet));
            UpdateValue(armorGrid.armorType, item.armorType);
            UpdateValue(armorGrid.maxDexBonus, item.MaxDexBonus(sheet));
            UpdateValue(armorGrid.checkPenalty, item.CheckPenalty(sheet));
            UpdateValue(armorGrid.spellFailure, item.SpellFailure(sheet));
            UpdateValue(armorGrid.properties, item.properties);
            UpdateValue(armorGrid.weight, item.weight.GetTotal(sheet).ToString());
            UpdateValue(armorGrid.description, item.description);

            MainPage.SetTapHandler(armorGrid.container, (s, e) => Armor_DoubleTap(item), 2);
#if EXPAND_WITH_TAP
#if EXPAND_CHECKBOX
            MainPage.AddTapHandler(armorGrid.container, (s, e) => Armor_Tap(armorGrid.selected), 1);
#else
            MainPage.AddTapHandler(armorGrid.container, (s, e) => Armor_Tap(item), 1);
#endif
#endif
        }
Exemple #2
0
        private void CreateSelectedArmorGrid(CharacterSheet.ArmorClassItem item, int itemIndex)
        {
            if (item == null)
            {
                return;
            }
            var sheet = CharacterSheetStorage.Instance.selectedCharacter;

            if (sheet == null)
            {
                return;
            }
            if (selectedArmorGridsPool.Count > 0)
            {
                var armorGrid = selectedArmorGridsPool[0];
                selectedArmorGridsPool.RemoveAt(0);
                UpdateArmorGrid(armorGrid, item, itemIndex);
                var pos = selectedArmorGrids.Count;
                selectedArmorGrids.Add(armorGrid);
                Armor.Children.Insert(pos, armorGrid.container);
                return;
            }
            var grid = new Grid()
            {
                ColumnSpacing   = 5,
                RowSpacing      = 5,
                BackgroundColor = Color.LightGray,
            };

            grid.ColumnDefinitions = new ColumnDefinitionCollection()
            {
                new ColumnDefinition()
                {
                    Width = GridLength.Auto
                },
                new ColumnDefinition()
                {
                    Width = GridLength.Star
                },
            };
            const int count          = 14;
            var       rowDefinitions = new RowDefinitionCollection();

            for (var i = 0; i < count; i++)
            {
                rowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });
            }
            grid.RowDefinitions = rowDefinitions;
#if EXPAND_CHECKBOX
            var selectedcb = new CheckBox()
            {
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center,
                IsChecked         = item.selected,
            };
            EventHandler <CheckedChangedEventArgs> selectedHandler = (s, e) => ArmorSelected_CheckedChanged(item, e.Value);
            selectedcb.CheckedChanged += selectedHandler;
#endif
            var nameTitle = CreateLabel("Name:");
            var nameStack = new StackLayout()
            {
                Orientation       = StackOrientation.Horizontal,
                HorizontalOptions = LayoutOptions.Start,
                VerticalOptions   = LayoutOptions.Center,
            };
#if EXPAND_CHECKBOX
            nameStack.Children.Add(selectedcb);
#endif
            nameStack.Children.Add(nameTitle);

            var row       = 0;
            var nameValue = CreateFrame(item.name);
            grid.Children.Add(nameStack, 0, row);
            grid.Children.Add(nameValue, 1, row);
            row += 1;

            var activeTitle = CreateLabel("Active:");
            var activecb    = new CheckBox()
            {
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center,
                IsChecked         = item.active,
                IsEnabled         = false,
            };
            EventHandler <CheckedChangedEventArgs> activeHandler = (s, e) => ArmorActive_CheckedChanged(item, e.Value);
            activecb.CheckedChanged += activeHandler;
            grid.Children.Add(activeTitle, 0, row);
            grid.Children.Add(activecb, 1, row);
            row += 1;

            var armorBonusTitle = CreateLabel("Armor Bonus:");
            var armorBonusValue = CreateFrame(item.ArmorBonus(sheet));
            grid.Children.Add(armorBonusTitle, 0, row);
            grid.Children.Add(armorBonusValue, 1, row);
            row += 1;

            var armorTypeTitle = CreateLabel("Armor Type:");
            var armorTypeValue = CreateFrame(item.ArmorType.ToString());
            grid.Children.Add(armorTypeTitle, 0, row);
            grid.Children.Add(armorTypeValue, 1, row);
            row += 1;

            var maxDexBonusTitle = CreateLabel("Max Dex Bonus:");
            var maxDexBonusValue = CreateFrame(item.MaxDexBonus(sheet));
            grid.Children.Add(maxDexBonusTitle, 0, row);
            grid.Children.Add(maxDexBonusValue, 1, row);
            row += 1;

            var checkPenaltyTitle = CreateLabel("Check Penalty:");
            var checkPenaltyValue = CreateFrame(item.CheckPenalty(sheet));
            grid.Children.Add(checkPenaltyTitle, 0, row);
            grid.Children.Add(checkPenaltyValue, 1, row);
            row += 1;

            var spellFailureTitle = CreateLabel("Spell Failure:");
            var spellFailureValue = CreateFrame(item.SpellFailure(sheet));
            grid.Children.Add(spellFailureTitle, 0, row);
            grid.Children.Add(spellFailureValue, 1, row);
            row += 1;

            var propertiesTitle = CreateLabel("Properties:");
            var propertiesValue = CreateFrame(item.properties);
            grid.Children.Add(propertiesTitle, 0, row);
            grid.Children.Add(propertiesValue, 1, row);
            row += 1;

            var weightTitle = CreateLabel("Weight:");
            var weightValue = CreateFrame(item.weight.GetTotal(sheet).ToString());
            grid.Children.Add(weightTitle, 0, row);
            grid.Children.Add(weightValue, 1, row);
            row += 1;

            var descriptionTitle = CreateLabel("Description:");
            grid.Children.Add(descriptionTitle, 0, 2, row, row + 1);
            row += 1;

            var descriptionValue = CreateFrame(item.description);
            grid.Children.Add(descriptionValue, 0, 2, row, row + 1);
            row += 1;

            MainPage.AddTapHandler(grid, (s, e) => Armor_DoubleTap(item), 2);
#if EXPAND_WITH_TAP
#if EXPAND_CHECKBOX
            MainPage.AddTapHandler(grid, (s, e) => Armor_Tap(selectedcb), 1);
#else
            MainPage.AddTapHandler(grid, (s, e) => Armor_Tap(item), 1);
#endif
#endif

            var newArmorGrid = new SelectedArmorGrid()
            {
                container = grid,
#if EXPAND_CHECKBOX
                selectedHandler = selectedHandler,
                selected        = selectedcb,
#endif
                activeHandler     = activeHandler,
                active            = activecb,
                nameTitle         = nameTitle,
                name              = nameValue.Content as Label,
                armorBonusTitle   = armorBonusTitle,
                armorBonus        = armorBonusValue.Content as Label,
                armorTypeTitle    = armorTypeTitle,
                armorType         = armorTypeValue.Content as Label,
                maxDexBonusTitle  = maxDexBonusTitle,
                maxDexBonus       = maxDexBonusValue.Content as Label,
                checkPenaltyTitle = checkPenaltyTitle,
                checkPenalty      = checkPenaltyValue.Content as Label,
                spellFailureTitle = spellFailureTitle,
                spellFailure      = spellFailureValue.Content as Label,
                propertiesTitle   = propertiesTitle,
                properties        = propertiesValue.Content as Label,
                weightTitle       = weightTitle,
                weight            = weightValue.Content as Label,
                descriptionTitle  = descriptionTitle,
                description       = descriptionValue.Content as Label,
            };

            var newpos = selectedArmorGrids.Count;
            selectedArmorGrids.Add(newArmorGrid);
            Armor.Children.Insert(newpos, newArmorGrid.container);
        }