/// <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);
            }
        }
    }
Example #2
0
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            try {
                if (PublicParmValues.Any())
                {
                    this.ContentType = (SummaryContentType)Enum.Parse(typeof(SummaryContentType), GetParmValue("ContentType", "Blog"), true);

                    SelectedCategories = new List <Guid>();

                    List <string> lstCategories = GetParmValueList("SelectedCategories");
                    foreach (string sCat in lstCategories)
                    {
                        if (!String.IsNullOrEmpty(sCat))
                        {
                            SelectedCategories.Add(new Guid(sCat));
                        }
                    }
                }
                if (SelectedCategories.Any())
                {
                    this.ContentType = SummaryContentType.SpecifiedCategories;
                }
            } catch (Exception ex) {
            }
        }
 private IEnumerable <Category> GetSelectedCategories()
 {
     return(SelectedCategories.OrderBy(x => x.Name).Select((x, i) =>
     {
         x.Index = i;
         return x;
     }).ToList());
 }
Example #4
0
        /// <summary>
        /// Saves the current post edit model.
        /// </summary>
        /// <param name="api">The current api</param>
        public void Save(Api api)
        {
            var newModel = false;

            // Get or create post
            var post = Id.HasValue ? api.Posts.GetSingle(Id.Value) : null;

            if (post == null)
            {
                post     = new Piranha.Models.Post();
                newModel = true;
            }

            // Map values
            Mapper.Map <EditModel, Piranha.Models.Post>(this, post);

            // Check action
            if (Action == SubmitAction.Publish)
            {
                post.Published = DateTime.Now;
            }
            else if (Action == SubmitAction.Unpublish)
            {
                post.Published = null;
            }

            // Remove old categories
            post.Categories.Clear();

            // Map current categories
            if (!String.IsNullOrWhiteSpace(SelectedCategories))
            {
                foreach (var str in SelectedCategories.Split(new char[] { ',' }))
                {
                    var categoryName = str.Trim();

                    var cat = api.Categories.GetSingle(where : c => c.Title == categoryName);
                    if (cat == null)
                    {
                        cat = new Piranha.Models.Category()
                        {
                            Title = categoryName
                        };
                        api.Categories.Add(cat);
                    }
                    post.Categories.Add(cat);
                }
            }
            if (newModel)
            {
                api.Posts.Add(post);
            }
            api.SaveChanges();

            this.Id = post.Id;
        }
Example #5
0
        private void MultiSelectTreeView_OnSelectionChanged(object sender, EventArgs e)
        {
            if (DialogResult == true)
            {
                return;
            }
            var array = new CategoryVM[MultiSelectTreeView.SelectedItems.Count];

            MultiSelectTreeView.SelectedItems.CopyTo(array, 0);
            SelectedCategories = array.ToList();
            OK.IsEnabled       = SelectedCategories.Any();
        }
        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();
        }
        protected override void InitializePreviews()
        {
            Panel.RemoveChildren();
            if (!SelectedCategories.Any())
            {
                return;
            }

            foreach (var t in allTemplates)
            {
                if (!SelectedCategories.Overlaps(t.Categories))
                {
                    continue;
                }

                if (!string.IsNullOrEmpty(searchFilter) && !t.SearchTerms.Any(s => s.IndexOf(searchFilter, StringComparison.OrdinalIgnoreCase) >= 0))
                {
                    continue;
                }

                var tileId = t.Template.Id;
                var item   = ScrollItemWidget.Setup(ItemTemplate,
                                                    () => { var brush = Editor.CurrentBrush as EditorTileBrush; return(brush != null && brush.Template == tileId); },
                                                    () => Editor.SetBrush(new EditorTileBrush(Editor, tileId, WorldRenderer)));

                var preview  = item.Get <TerrainTemplatePreviewWidget>("TILE_PREVIEW");
                var template = tileset.Templates[tileId];
                var grid     = WorldRenderer.World.Map.Grid;
                var bounds   = WorldRenderer.Theater.TemplateBounds(template, grid.TileSize, grid.Type);

                // Scale templates to fit within the panel
                var scale = 1f;
                while (scale * bounds.Width > ItemTemplate.Bounds.Width)
                {
                    scale /= 2;
                }

                preview.Template      = template;
                preview.GetScale      = () => scale;
                preview.Bounds.Width  = (int)(scale * bounds.Width);
                preview.Bounds.Height = (int)(scale * bounds.Height);

                item.Bounds.Width   = preview.Bounds.Width + 2 * preview.Bounds.X;
                item.Bounds.Height  = preview.Bounds.Height + 2 * preview.Bounds.Y;
                item.IsVisible      = () => true;
                item.GetTooltipText = () => t.Tooltip;

                Panel.AddChild(item);
            }
        }
Example #8
0
        public OldHrSearchOptions GetOldOptions()
        {
            var options = new OldHrSearchOptions();

            options.AllWords   = AllWords;
            options.QueryScope = QueryScope;

            options.WordsAll = AutocompleteAll.GetCHIOs().Where(x => x.HIO is Word).Select(x => x.HIO).Cast <Word>().ToList();

            options.MeasuresAll = AutocompleteAll.GetCHIOs().Where(x => x.HIO is MeasureOp).Select(x => x.HIO).Cast <MeasureOp>().ToList();

            options.Categories = SelectedCategories.Select(cat => cat.category).ToList();
            return(options);
        }
Example #9
0
        public Category GetCategoryFilter()
        {
            if (SelectedCategories.Count() == 0)
            {
                return(Category.Default);
            }

            Category res = SelectedCategories.First();

            for (int i = 1; i < SelectedCategories.Count(); i++)
            {
                res |= SelectedCategories.ElementAt(i);
            }
            return(res);
        }
        public override void Refresh()
        {
            base.Refresh();

            var categories = _categoryService.GetAll();

            SelectedCategories.Clear();
            Categories.Clear();

            foreach (Category category in categories)
            {
                _categoryService.Reload(category);
                Categories.Add(category);
            }
        }
        private void Delete(object obj)
        {
            foreach (Category selectedCategory in SelectedCategories)
            {
                var result = MessageBox.Show($"Are you sure you want to delete '{selectedCategory.Name}' category? All items in this category will be deleted.", "Confirm", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.No)
                {
                    continue;
                }
                _categoryService.Delete(selectedCategory.Id);
                OnRecordDeleted <Category>(selectedCategory.Name);
            }

            SelectedCategories.Clear();
            Refresh();
        }
Example #12
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);
            }
        }
Example #13
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);
     }
 }
Example #14
0
        private void FillToOptions(SearchOptions options)
        {
            AutocompleteAll.CompleteTypings();
            AutocompleteAny.CompleteTypings();
            AutocompleteNot.CompleteTypings();

            options.CWordsAll = AutocompleteAll.GetCWords().ToList();
            options.CWordsAny = AutocompleteAny.GetCWords().ToList();
            options.CWordsNot = AutocompleteNot.GetCWords().ToList();

            options.MeasuresAll = AutocompleteAll.GetCHIOs().Where(x => x.HIO is MeasureOp).Select(x => x.HIO).Cast <MeasureOp>().ToList();
            options.MeasuresAny = AutocompleteAny.GetCHIOs().Where(x => x.HIO is MeasureOp).Select(x => x.HIO).Cast <MeasureOp>().ToList();

            options.Categories    = SelectedCategories.Select(cat => cat.category).ToList();
            options.MinAny        = MinAny;
            options.WithConf      = WithConfidence;
            options.GroupOperator = GroupOperator;
            options.SearchScope   = SearchScope;
        }
        public void ExecuteSearch()
        {
            var crit = new EventLogQueryCriteria()
            {
                ProvidersName         = string.IsNullOrWhiteSpace(ProviderName) ? new List <string>() : ProviderName.Split(';').ToList(),
                DateFrom              = DateFrom,
                DateTo                = DateTo,
                EventLogEntryTypeList = SelectedEntryTypeList,
                DescriptionContains   = string.IsNullOrWhiteSpace(Contains) ? new List <string>() : Contains.Split(';').ToList()
            };

            List <string> serversList = new List <string>();

            if (SelectedCategories != null && SelectedCategories.Any())
            {
                serversList.AddRange(SelectedCategories.SelectMany(x => x.ServerList).Select(x => x.Name));
            }
            if (!string.IsNullOrEmpty(ManualServers))
            {
                serversList.AddRange(ManageManualServerList(ManualServers));
            }

            if (serversList.Any())
            {
                var logs = _eventLogReaderManager.ReadLogs(serversList, crit);

                if (logs != null && logs.Any())
                {
                    EventResultList = new ObservableCollection <Event>(logs.Select(x => new Event(x)).ToList());
                }
                else
                {
                    EventResultList = new ObservableCollection <Event>();
                    MessageBox.Show("No events found with the current criteria");
                }
                RaisePropertyChanged("EventResultList");
            }
            else
            {
                MessageBox.Show("No servers has been selected!");
            }
        }
Example #16
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();
        }
Example #17
0
        protected void PopulateModelSelectLists(List <Category> categories, List <Author> authors)
        {
            //Categories List
            CategoriesSelectList = categories
                                   .Select(x => new SelectListItem()
            {
                Value    = x.Id.ToString(),
                Text     = x.Name,
                Selected = SelectedCategories != null && SelectedCategories.Contains(x.Id)
            });

            //Authors list
            AuthorsSelectList = authors
                                .Select(x => new SelectListItem()
            {
                Text     = x.FirstName + " " + x.LastName,
                Value    = x.Id.ToString(),
                Selected = x.Id == AuthorId
            });
        }
Example #18
0
 public void UpdateSubcatgoriesVisible(int?changedCategoryId = null, bool?isSelected = null)
 {
     if (changedCategoryId != null && isSelected != null)
     {
     }
     else
     {
         var selected = SelectedCategories.ToList();
         foreach (var subCategory in PinSubCategories)
         {
             if (subCategory.ParentId != null && selected.Contains(subCategory.ParentId.Value))
             {
                 subCategory.IsVisible = true;
             }
             else
             {
                 subCategory.IsVisible = subCategory.ItemSelected = false;
             }
         }
     }
     UpdatePinsVisible();
 }
Example #19
0
        private List <AnimeSeriesVM> GetSeriesForGroup()
        {
            List <AnimeSeriesVM> serList = new List <AnimeSeriesVM>();

            try
            {
                if (LevelType != RandomSeriesEpisodeLevel.Group)
                {
                    return(serList);
                }
                AnimeGroupVM grp = LevelObject as AnimeGroupVM;
                if (grp == null)
                {
                    return(serList);
                }

                foreach (AnimeSeriesVM ser in grp.AllAnimeSeries)
                {
                    // categories
                    if (!string.IsNullOrEmpty(SelectedCategories))
                    {
                        string filterParm = SelectedCategories.Trim();

                        string[] cats = filterParm.Split(',');

                        bool foundCat = false;
                        if (cboCatFilter.SelectedIndex == 1)
                        {
                            foundCat = true;                                                          // all
                        }
                        int index = 0;
                        foreach (string cat in cats)
                        {
                            if (cat.Trim().Length == 0)
                            {
                                continue;
                            }
                            if (cat.Trim() == ",")
                            {
                                continue;
                            }

                            index = ser.CategoriesString.IndexOf(cat, 0, StringComparison.InvariantCultureIgnoreCase);

                            if (cboCatFilter.SelectedIndex == 0)                             // any
                            {
                                if (index > -1)
                                {
                                    foundCat = true;
                                    break;
                                }
                            }
                            else                             //all
                            {
                                if (index < 0)
                                {
                                    foundCat = false;
                                    break;
                                }
                            }
                        }
                        if (!foundCat)
                        {
                            continue;
                        }
                    }

                    serList.Add(ser);
                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }

            return(serList);
        }
    /// <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);
            }
        }
    }
Example #21
0
        private List <AnimeSeriesVM> GetSeriesForGroupFilter()
        {
            List <AnimeSeriesVM> serList = new List <AnimeSeriesVM>();

            try
            {
                if (LevelType != RandomSeriesEpisodeLevel.GroupFilter)
                {
                    return(serList);
                }
                GroupFilterVM gf = LevelObject as GroupFilterVM;
                if (gf == null)
                {
                    return(serList);
                }

                List <AnimeGroupVM> grps = new List <AnimeGroupVM>(MainListHelperVM.Instance.AllGroups);

                foreach (AnimeGroupVM grp in grps)
                {
                    // ignore sub groups
                    if (grp.AnimeGroupParentID.HasValue)
                    {
                        continue;
                    }

                    if (gf.EvaluateGroupFilter(grp))
                    {
                        foreach (AnimeSeriesVM ser in grp.AllAnimeSeries)
                        {
                            if (gf.EvaluateGroupFilter(ser))
                            {
                                // categories
                                if (!string.IsNullOrEmpty(SelectedCategories))
                                {
                                    string filterParm = SelectedCategories.Trim();

                                    string[] cats = filterParm.Split(',');

                                    bool foundCat = false;
                                    if (cboCatFilter.SelectedIndex == 1)
                                    {
                                        foundCat = true;                                                                      // all
                                    }
                                    int index = 0;
                                    foreach (string cat in cats)
                                    {
                                        if (cat.Trim().Length == 0)
                                        {
                                            continue;
                                        }
                                        if (cat.Trim() == ",")
                                        {
                                            continue;
                                        }

                                        index = ser.CategoriesString.IndexOf(cat, 0, StringComparison.InvariantCultureIgnoreCase);

                                        if (cboCatFilter.SelectedIndex == 0)                                         // any
                                        {
                                            if (index > -1)
                                            {
                                                foundCat = true;
                                                break;
                                            }
                                        }
                                        else                                         //all
                                        {
                                            if (index < 0)
                                            {
                                                foundCat = false;
                                                break;
                                            }
                                        }
                                    }
                                    if (!foundCat)
                                    {
                                        continue;
                                    }
                                }

                                if (!ser.IsComplete && chkComplete.IsChecked.Value)
                                {
                                    continue;
                                }

                                if (chkWatched.IsChecked.Value && ser.AllFilesWatched)
                                {
                                    serList.Add(ser);
                                    continue;
                                }

                                if (chkUnwatched.IsChecked.Value && !ser.AnyFilesWatched)
                                {
                                    serList.Add(ser);
                                    continue;
                                }


                                if (chkPartiallyWatched.IsChecked.Value && ser.AnyFilesWatched && !ser.AllFilesWatched)
                                {
                                    serList.Add(ser);
                                    continue;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }

            return(serList);
        }
        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();
        }
        protected override void InitializePreviews()
        {
            Panel.RemoveChildren();
            if (!SelectedCategories.Any())
            {
                return;
            }

            foreach (var a in allActors)
            {
                if (!SelectedCategories.Overlaps(a.Categories))
                {
                    continue;
                }

                if (!string.IsNullOrEmpty(searchFilter) && !a.SearchTerms.Any(s => s.IndexOf(searchFilter, StringComparison.OrdinalIgnoreCase) >= 0))
                {
                    continue;
                }

                var actor = a.Actor;
                var td    = new TypeDictionary();
                td.Add(new OwnerInit(selectedOwner.Name));
                td.Add(new FactionInit(selectedOwner.Faction));
                foreach (var api in actor.TraitInfos <IActorPreviewInitInfo>())
                {
                    foreach (var o in api.ActorPreviewInits(actor, ActorPreviewType.MapEditorSidebar))
                    {
                        td.Add(o);
                    }
                }

                try
                {
                    var item = ScrollItemWidget.Setup(ItemTemplate,
                                                      () => editorCursor.Type == EditorCursorType.Actor && editorCursor.Actor.Info == actor,
                                                      () => Editor.SetBrush(new EditorActorBrush(Editor, actor, selectedOwner, WorldRenderer)));

                    var preview = item.Get <ActorPreviewWidget>("ACTOR_PREVIEW");
                    preview.SetPreview(actor, td);

                    // Scale templates to fit within the panel
                    var scale = 1f;
                    if (scale * preview.IdealPreviewSize.X > ItemTemplate.Bounds.Width)
                    {
                        scale = (ItemTemplate.Bounds.Width - Panel.ItemSpacing) / (float)preview.IdealPreviewSize.X;
                    }

                    preview.GetScale      = () => scale;
                    preview.Bounds.Width  = (int)(scale * preview.IdealPreviewSize.X);
                    preview.Bounds.Height = (int)(scale * preview.IdealPreviewSize.Y);

                    item.Bounds.Width  = preview.Bounds.Width + 2 * preview.Bounds.X;
                    item.Bounds.Height = preview.Bounds.Height + 2 * preview.Bounds.Y;
                    item.IsVisible     = () => true;

                    item.GetTooltipText = () => a.Tooltip;

                    Panel.AddChild(item);
                }
                catch
                {
                    Log.Write("debug", "Map editor ignoring actor {0}, because of missing sprites for tileset {1}.",
                              actor.Name, World.Map.Rules.TerrainInfo.Id);
                    continue;
                }
            }
        }
Example #24
0
 public void DeselectCategory()
 {
     AvailableCategories.Add(SelectedUsedCategory);
     SelectedCategories.Remove(SelectedUsedCategory);
     SelectedUsedCategory = null;
 }
Example #25
0
 public void SelectCategory()
 {
     SelectedCategories.Add(SelectedAvailableCategory);
     AvailableCategories.Remove(SelectedAvailableCategory);
     SelectedAvailableCategory = null;
 }