Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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;
                }
            }
        }