/// <summary>
    /// Fires when checkbox selection is changed.
    /// </summary>
    void checkBoxWithDropDown_OnCheckBoxSelectionChanged(object sender, EventArgs e)
    {
        var checkBoxWithDropDown = sender as CheckBoxWithDropDown;

        if (checkBoxWithDropDown != null)
        {
            if (checkBoxWithDropDown.CheckboxChecked)
            {
                if (checkBoxWithDropDown.DropDownVisible)
                {
                    SelectedCategories.Add(checkBoxWithDropDown.Value, VariantOptionInfo.ExistingUnselectedOption);
                }
                else
                {
                    SelectedCategories.Add(checkBoxWithDropDown.Value, VariantOptionInfo.NewOption);
                }
            }
            else
            {
                SelectedCategories.Remove(checkBoxWithDropDown.Value);
            }

            // Raise the SelectionChanged event
            if (OnSelectionChanged != null)
            {
                OnSelectionChanged(this, e);
            }
        }
    }
예제 #2
0
        public CustomTileSelectorLogic(Widget widget, World world, WorldRenderer worldRenderer)
            : base(widget, world, worldRenderer, "TILETEMPLATE_LIST", "TILEPREVIEW_TEMPLATE")
        {
            terrainInfo = world.Map.Rules.TerrainInfo as ITemplatedTerrainInfo;
            if (terrainInfo == null)
            {
                throw new InvalidDataException("CustomTileSelectorLogic requires a template-based tileset.");
            }

            terrainRenderer = world.WorldActor.TraitOrDefault <ITiledTerrainRenderer>();
            if (terrainRenderer == null)
            {
                throw new InvalidDataException("TileSelectorLogic requires a tile-based terrain renderer.");
            }

            allTemplates = terrainInfo.Templates.Values.Select(t => new TileSelectorTemplate(t)).ToArray();
            editorCursor = world.WorldActor.Trait <EditorCursorLayer>();

            allCategories = allTemplates.SelectMany(t => t.Categories)
                            .Distinct()
                            .OrderBy(CategoryOrder)
                            .ToArray();

            foreach (var c in allCategories)
            {
                SelectedCategories.Add(c);
                FilteredCategories.Add(c);
            }

            SearchTextField.OnTextEdited = () =>
            {
                searchFilter = SearchTextField.Text.Trim();
                FilteredCategories.Clear();

                if (!string.IsNullOrEmpty(searchFilter))
                {
                    FilteredCategories.AddRange(
                        allTemplates.Where(t => t.SearchTerms.Any(
                                               s => s.IndexOf(searchFilter, StringComparison.OrdinalIgnoreCase) >= 0))
                        .SelectMany(t => t.Categories)
                        .Distinct()
                        .OrderBy(CategoryOrder));
                }
                else
                {
                    FilteredCategories.AddRange(allCategories);
                }

                InitializePreviews();
            };

            InitializePreviews();
        }
예제 #3
0
        /// <summary>
        /// Initializes the selected categories.
        /// </summary>
        /// <param name="categories">The categories.</param>
        private void InitSelectedCategories(IEnumerable <Category> categories)
        {
            // SelectedCategories is an ObservableCollection of checkboxes for the ItemsControl in DetailsView.xaml
            var categoryList = categories.ToList();

            foreach (var selectedCategory in categoryList.Select(c => new SelectListItem
            {
                Text = c.Name,
                Value = c.Id,
                Model = c,
                IsSelected = categoryList.Any(x => x.Id == c.Id)
            }).ToList())
            {
                // does this hospital currently have this category?
                SelectedCategories.Add(selectedCategory);
            }
        }
예제 #4
0
 private void collectCategories(TreeNode node)
 {
     foreach (TreeNode child in node.Nodes)
     {
         if (child.Tag is Category)
         {
             if (child.Checked)
             {
                 SelectedCategories.Add(child.Tag as Category);
             }
             else
             {
                 AllCategories = false;
             }
         }
         collectCategories(child);
     }
 }
예제 #5
0
        public TileSelectorLogic(Widget widget, World world, WorldRenderer worldRenderer)
            : base(widget, world, worldRenderer, "TILETEMPLATE_LIST", "TILEPREVIEW_TEMPLATE")
        {
            tileset      = world.Map.Rules.TileSet;
            allTemplates = tileset.Templates.Values.Select(t => new TileSelectorTemplate(t)).ToArray();
            editorCursor = world.WorldActor.Trait <EditorCursorLayer>();

            allCategories = allTemplates.SelectMany(t => t.Categories)
                            .Distinct()
                            .OrderBy(CategoryOrder)
                            .ToArray();

            foreach (var c in allCategories)
            {
                SelectedCategories.Add(c);
                FilteredCategories.Add(c);
            }

            SearchTextField.OnTextEdited = () =>
            {
                searchFilter = SearchTextField.Text.Trim();
                FilteredCategories.Clear();

                if (!string.IsNullOrEmpty(searchFilter))
                {
                    FilteredCategories.AddRange(
                        allTemplates.Where(t => t.SearchTerms.Any(
                                               s => s.IndexOf(searchFilter, StringComparison.OrdinalIgnoreCase) >= 0))
                        .SelectMany(t => t.Categories)
                        .Distinct()
                        .OrderBy(CategoryOrder));
                }
                else
                {
                    FilteredCategories.AddRange(allCategories);
                }

                InitializePreviews();
            };

            InitializePreviews();
        }
    /// <summary>
    /// Loads control.
    /// </summary>
    private void LoadControl()
    {
        // Get all product categories with options which are already in variants
        if (VariantCategoriesOptions.Count == 0)
        {
            DataSet variantCategoriesDS = VariantHelper.GetProductVariantsCategories(ProductID);
            FillCategoriesOptionsDictionary(VariantCategoriesOptions, variantCategoriesDS);
        }

        // Get all product attribute categories with options
        if (AllCategoriesOptions.Count == 0)
        {
            DataSet allCategoriesDS = OptionCategoryInfoProvider.GetProductOptionCategories(ProductID, true, OptionCategoryTypeEnum.Attribute);
            FillCategoriesOptionsDictionary(AllCategoriesOptions, allCategoriesDS);
        }

        foreach (KeyValuePair <OptionCategoryInfo, List <SKUInfo> > keyValuePair in AllCategoriesOptions)
        {
            if (keyValuePair.Value.Count > 0)
            {
                OptionCategoryInfo optionCategory = keyValuePair.Key;

                // Create new instance of CheckBoxWithDropDown control and prefill all necessary values
                CheckBoxWithDropDown checkBoxWithDropDown = new CheckBoxWithDropDown();
                checkBoxWithDropDown.ID    = ValidationHelper.GetString(optionCategory.CategoryID, string.Empty);
                checkBoxWithDropDown.Value = optionCategory.CategoryID;
                // Use live site display name instead of category display name in case it is available
                checkBoxWithDropDown.CheckboxText = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(optionCategory.CategoryTitle));

                // Attach listeners
                checkBoxWithDropDown.OnCheckBoxSelectionChanged += checkBoxWithDropDown_OnCheckBoxSelectionChanged;
                checkBoxWithDropDown.OnDropDownSelectionChanged += checkBoxWithDropDown_OnDropDownSelectionChanged;

                // Option category is in variants too
                if (VariantCategoriesOptions.Keys.Any(c => ValidationHelper.GetInteger(c["categoryId"], 0) == optionCategory.CategoryID))
                {
                    // Check and disable checkbox
                    checkBoxWithDropDown.CheckboxChecked = true;
                    checkBoxWithDropDown.Enabled         = false;

                    // Already existing variants add to selected categories too
                    if (!SelectedCategories.ContainsKey(optionCategory.CategoryID))
                    {
                        SelectedCategories.Add(optionCategory.CategoryID, VariantOptionInfo.ExistingSelectedOption);
                    }
                }
                // Option category is not in variant, but some categories in variants already exists
                else if (VariantCategoriesOptions.Count > 0)
                {
                    // Set prompt message and visibility
                    checkBoxWithDropDown.DropDownPrompt  = GetString("general.pleaseselect");
                    checkBoxWithDropDown.DropDownLabel   = GetString("com.variants.dropdownlabel");
                    checkBoxWithDropDown.DropDownVisible = true;

                    // Get all product options and bind them to dropdownlist
                    var options       = SKUInfoProvider.GetSKUOptionsForProduct(ProductID, optionCategory.CategoryID, true).OrderBy("SKUOrder");
                    var dropDownItems = new ListItemCollection();

                    foreach (var option in options)
                    {
                        dropDownItems.Add(new ListItem(option.SKUName, option.SKUID.ToString()));
                    }

                    checkBoxWithDropDown.DropDownItems = dropDownItems;
                }

                // Finally bind this control to parent
                chboxPanel.Controls.Add(checkBoxWithDropDown);
            }
        }
    }
예제 #7
0
        public ActorSelectorLogic(Widget widget, World world, WorldRenderer worldRenderer)
            : base(widget, world, worldRenderer, "ACTORTEMPLATE_LIST", "ACTORPREVIEW_TEMPLATE")
        {
            mapRules       = world.Map.Rules;
            ownersDropDown = widget.Get <DropDownButtonWidget>("OWNERS_DROPDOWN");
            editorCursor   = world.WorldActor.Trait <EditorCursorLayer>();
            var editorLayer = world.WorldActor.Trait <EditorActorLayer>();

            selectedOwner = editorLayer.Players.Players.Values.First();
            Func <PlayerReference, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
            {
                var item = ScrollItemWidget.Setup(template, () => selectedOwner == option, () => SelectOwner(option));

                item.Get <LabelWidget>("LABEL").GetText = () => option.Name;
                item.GetColor = () => option.Color;

                return(item);
            };

            editorLayer.OnPlayerRemoved = () =>
            {
                if (editorLayer.Players.Players.Values.Any(p => p.Name == selectedOwner.Name))
                {
                    return;
                }
                SelectOwner(editorLayer.Players.Players.Values.First());
            };

            ownersDropDown.OnClick = () =>
            {
                var owners = editorLayer.Players.Players.Values.OrderBy(p => p.Name);
                ownersDropDown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 270, owners, setupItem);
            };

            ownersDropDown.Text      = selectedOwner.Name;
            ownersDropDown.TextColor = selectedOwner.Color;

            var tileSetId     = world.Map.Rules.TerrainInfo.Id;
            var allActorsTemp = new List <ActorSelectorActor>();

            foreach (var a in mapRules.Actors.Values)
            {
                // Partial templates are not allowed
                if (a.Name.Contains('^'))
                {
                    continue;
                }

                // Actor must have a preview associated with it
                if (!a.HasTraitInfo <IRenderActorPreviewInfo>())
                {
                    continue;
                }

                var editorData = a.TraitInfoOrDefault <MapEditorDataInfo>();

                // Actor must be included in at least one category
                if (editorData == null || editorData.Categories == null)
                {
                    continue;
                }

                // Excluded by tileset
                if (editorData.ExcludeTilesets != null && editorData.ExcludeTilesets.Contains(tileSetId))
                {
                    continue;
                }

                if (editorData.RequireTilesets != null && !editorData.RequireTilesets.Contains(tileSetId))
                {
                    continue;
                }

                var tooltip = a.TraitInfos <EditorOnlyTooltipInfo>().FirstOrDefault(ti => ti.EnabledByDefault) as TooltipInfoBase
                              ?? a.TraitInfos <TooltipInfo>().FirstOrDefault(ti => ti.EnabledByDefault);

                var searchTerms = new List <string>()
                {
                    a.Name
                };
                if (tooltip != null)
                {
                    searchTerms.Add(tooltip.Name);
                }

                var tooltipText = (tooltip == null ? "Type: " : tooltip.Name + "\nType: ") + a.Name;
                allActorsTemp.Add(new ActorSelectorActor(a, editorData.Categories, searchTerms.ToArray(), tooltipText));
            }

            allActors = allActorsTemp.ToArray();

            allCategories = allActors.SelectMany(ac => ac.Categories)
                            .Distinct()
                            .OrderBy(x => x)
                            .ToArray();

            foreach (var c in allCategories)
            {
                SelectedCategories.Add(c);
                FilteredCategories.Add(c);
            }

            SearchTextField.OnTextEdited = () =>
            {
                searchFilter = SearchTextField.Text.Trim();
                FilteredCategories.Clear();

                if (!string.IsNullOrEmpty(searchFilter))
                {
                    FilteredCategories.AddRange(
                        allActors.Where(t => t.SearchTerms.Any(
                                            s => s.IndexOf(searchFilter, StringComparison.OrdinalIgnoreCase) >= 0))
                        .SelectMany(t => t.Categories)
                        .Distinct()
                        .OrderBy(x => x));
                }
                else
                {
                    FilteredCategories.AddRange(allCategories);
                }

                InitializePreviews();
            };

            InitializePreviews();
        }
예제 #8
0
 public void SelectCategory()
 {
     SelectedCategories.Add(SelectedAvailableCategory);
     AvailableCategories.Remove(SelectedAvailableCategory);
     SelectedAvailableCategory = null;
 }