Exemple #1
0
        private void UpdateWeaponGrid(WeaponGrid weaponGrid, CharacterSheet.WeaponItem item, int itemIndex)
        {
            var sheet = CharacterSheetStorage.Instance.selectedCharacter;

            if (sheet == null)
            {
                return;
            }
            MainPage.SetTapHandler(weaponGrid.container, (s, e) => Weapon_DoubleTap(item), 2);
#if EXPAND_SELECTED
#if EXPAND_CHECKBOX
            if (weaponGrid.selectedHandler != null)
            {
                weaponGrid.selected.CheckedChanged -= weaponGrid.selectedHandler;
            }
            weaponGrid.selectedHandler = (s, e) => Weapon_CheckedChanged(item, e.Value);
            UpdateValue(weaponGrid.selected, item.selected);
            weaponGrid.selected.CheckedChanged += weaponGrid.selectedHandler;
#if EXPAND_WITH_TAP
            MainPage.AddTapHandler(weaponGrid.container, (s, e) => Weapon_Tap(weaponGrid.selected), 1);
#endif
#else
#if EXPAND_WITH_TAP
            MainPage.AddTapHandler(weaponGrid.container, (s, e) => Weapon_Tap(item), 1);
#endif
#endif
#endif
            weaponGrid.name.FontAttributes = item.active ? FontAttributes.Bold : FontAttributes.None;
            UpdateValue(weaponGrid.name, item.AsString(sheet));
        }
Exemple #2
0
        private void CreateWeaponGrid(CharacterSheet.WeaponItem item, int itemIndex)
        {
            if (item == null)
            {
                return;
            }
            var sheet = CharacterSheetStorage.Instance.selectedCharacter;

            if (sheet == null)
            {
                return;
            }
            if (weaponGridsPool.Count > 0)
            {
                var weaponGrid = weaponGridsPool[0];
                weaponGridsPool.RemoveAt(0);
                UpdateWeaponGrid(weaponGrid, item, itemIndex);
                var pos =
#if EXPAND_SELECTED
                    selectedWeaponGrids.Count +
#endif
                    weaponGrids.Count;
                weaponGrids.Add(weaponGrid);
                Weapon.Children.Insert(pos, weaponGrid.container);
                return;
            }
#if USE_GRID
            var container = new Grid()
            {
                ColumnSpacing   = 5,
                RowSpacing      = 5,
                BackgroundColor = Color.LightGray,
            };
            container.ColumnDefinitions = new ColumnDefinitionCollection()
            {
                new ColumnDefinition()
                {
                    Width = GridLength.Auto
                },
                new ColumnDefinition()
                {
                    Width = GridLength.Star
                },
            };
            container.RowDefinitions = new RowDefinitionCollection()
            {
                new RowDefinition()
                {
                    Height = GridLength.Auto
                },
            };
#else
            var container = new StackLayout()
            {
                Orientation     = StackOrientation.Horizontal,
                BackgroundColor = Color.LightGray,
            };
#endif
            var weaponNameFrame = CreateFrame(item.AsString(sheet));
            weaponNameFrame.HorizontalOptions = LayoutOptions.FillAndExpand;
            var weaponName = weaponNameFrame.Content as Label;
            weaponName.FontAttributes = item.active ? FontAttributes.Bold : FontAttributes.None;
            MainPage.AddTapHandler(container, (s, e) => Weapon_DoubleTap(item), 2);
#if EXPAND_SELECTED
#if EXPAND_CHECKBOX
            var selectedcb = new CheckBox()
            {
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center,
                IsChecked         = item.selected,
            };
            EventHandler <CheckedChangedEventArgs> handler = (s, e) => Weapon_CheckedChanged(item, e.Value);
            selectedcb.CheckedChanged += handler;
#if EXPAND_WITH_TAP
            MainPage.AddTapHandler(container, (s, e) => Weapon_Tap(selectedcb), 1);
#endif
#if USE_GRID
            container.Children.Add(selectedcb, 0, 0);
#else
            container.Children.Add(selectedcb);
#endif
#else
#if EXPAND_WITH_TAP
            MainPage.AddTapHandler(container, (s, e) => Weapon_Tap(item), 1);
#endif
#endif
#endif
#if USE_GRID
            container.Children.Add(weaponNameFrame, 1, 0);
#else
            container.Children.Add(weaponNameFrame);
#endif

            var newWeaponGrid = new WeaponGrid()
            {
                container = container,
#if EXPAND_SELECTED && EXPAND_CHECKBOX
                selectedHandler = handler,
                selected        = selectedcb,
#endif
                name      = weaponName,
                nameFrame = weaponNameFrame,
            };

            var newpos =
#if EXPAND_SELECTED
                selectedWeaponGrids.Count +
#endif
                weaponGrids.Count;
            weaponGrids.Add(newWeaponGrid);
            Weapon.Children.Insert(newpos, newWeaponGrid.container);
        }