Exemplo n.º 1
0
        public static UIElement GetElementForFolder(string folder)
        {
            if (folder == null)
            {
                folder = "Null";
            }

            bool active = TextureLoader.getFolderName() == folder;

            UIElement element = new UIElement(folder, UIHelper.Fill, 0, UIHelper.PlainTheme, Color.White, active ? 1f : 0.75f, false).AsSelectable("Folder", (s, e) =>
            {
                e.Opacity = s ? 1f : 0.7f;

                e.GetElementById(e.Id + "_BgName").Color = s ? Color.DarkCyan : Color.Black;

                if (s)
                {
                    Game1.playSound("coin");
                }

                if (e.Base != null)
                {
                    if (s)
                    {
                        foreach (UIElement selected in e.Base.GetSelected())
                        {
                            if (selected != e)
                            {
                                selected.Deselect();
                            }
                        }
                    }

                    if (!s)
                    {
                        if ((new List <UIElement>(e.Base.GetSelected())).Count == 0)
                        {
                            e.Select();
                        }
                    }
                }

                if (s)
                {
                    setFolder(e.Id);
                }
            }).WithInteractivity(hover: (point, hoverIn, e) =>
            {
                if (e.IsSelected)
                {
                    return;
                }

                if (hoverIn != e.WasHover)
                {
                    Game1.playSound("smallSelect");
                }

                if (hoverIn)
                {
                    e.Opacity = e.IsSelected ? 1f : 0.9f;
                }
                else
                {
                    e.Opacity = e.IsSelected ? 1f : 0.75f;
                }
            });

            element.IsSelected = active;
            element.Overflow   = true;
            int   LastX  = 0;
            float i      = 0;
            bool  scaled = false;

            if (folder == "Vanilla")
            {
                List <NPC> npcs = new List <NPC>();
                for (int c = 0; c < numPortraits; c++)
                {
                    NPC npc = null;
                    while (npc == null || npcs.Contains(npc))
                    {
                        npc = Utility.getRandomTownNPC();
                    }

                    npcs.Add(npc);

                    Texture2D p = Game1.content.Load <Texture2D>(@"Portraits/" + npc.Name);

                    if (p is Texture2D portrait)
                    {
                        Texture2D t  = portrait is ScaledTexture2D st ? st.STexture : portrait;
                        int       mx = Math.Max(t.Width / 2, 64);
                        Rectangle s  = new Rectangle(0, 0, mx, mx);
                        int       w  = listElementHeight - margin * 2;
                        int       x  = LastX + margin;
                        LastX = x + w;
                        i++;

                        UIElement pic = UIElement.GetImage(portrait, Color.White, folder + "_Portrait_" + npc.Name, 1f / (i + 1), 0, UIHelper.GetTopLeft(x, margin, w)).WithSourceRectangle(s);
                        element.Add(pic);
                    }
                }
            }
            else
            {
                foreach (var texture in TextureLoader.pTextures.Where(k => k.Key.StartsWith(folder)))
                {
                    if (texture.Value is Texture2D portrait)
                    {
                        if (i >= numPortraits)
                        {
                            i++;
                            continue;
                        }

                        if (portrait is ScaledTexture2D || scaled)
                        {
                            scaled = true;
                        }

                        Texture2D t  = portrait is ScaledTexture2D st ? st.STexture : portrait;
                        int       mx = Math.Max(t.Width / 2, 64);
                        Rectangle s  = new Rectangle(0, 0, mx, mx);
                        int       w  = listElementHeight - margin * 2;
                        int       x  = LastX + margin;
                        LastX = x + w;
                        i++;

                        UIElement pic = UIElement.GetImage(portrait, Color.White, folder + "_Portrait_" + texture.Key, 1f / (i + 1), 0, UIHelper.GetTopLeft(x, margin, w)).WithSourceRectangle(s);

                        element.Add(pic);
                    }
                }
            }

            UITextElement name = new UITextElement(folder, Game1.smallFont, Color.White, 0.5f, 1f, folder + "_Name", 2, UIHelper.GetTopLeft(margin, margin));
            UITextElement num  = new UITextElement(folder == "Vanilla" ? " " : i.ToString(), Game1.tinyFont, Color.Black, 1f, 1f, folder + "_Num", 2, UIHelper.GetBottomRight(-1 * margin, -1 * margin));


            var       size      = (Game1.smallFont.MeasureString(folder) * 0.5f).toPoint();
            var       scaleText = scaled ? "128+" : "64";
            var       scaleSize = (Game1.smallFont.MeasureString("XX") * 0.5f).toPoint();
            int       sIBSize   = Math.Max(scaleSize.X, scaleSize.Y) + margin * 2;
            Point     bgSize    = new Point(size.X + margin * 4, size.Y + margin * 2);
            Texture2D bgName    = PyTK.PyDraw.getFade(bgSize.X * 4, bgSize.Y * 4, Color.White * 0.8f, Color.Transparent);

            UIElement nameBg              = UIElement.GetImage(bgName, active ? Color.DarkCyan : Color.Black, folder + "_BgName", 1, 1, UIHelper.GetTopLeft(0, 0, bgSize.X));
            UIElement scaleInfoText       = new UITextElement(scaleText, Game1.smallFont, Color.White, 0.5f, 1, folder + "_Scale", 2, UIHelper.GetCentered());
            UIElement scaleInfoBackground = UIElement.GetImage(PyDraw.getCircle((int)(sIBSize * (scaled ? 4 : 1)), Color.White), Color.LightGray, folder + "_ScaleBG", 1, 1, UIHelper.GetTopRight(-1 * margin, margin, sIBSize));

            scaleInfoBackground.Add(scaleInfoText);
            element.Add(name);
            element.Add(num);
            element.Add(scaleInfoBackground);
            element.Add(nameBg);
            return(element);
        }