Exemplo n.º 1
0
        private UIElement SetUpMenu()
        {
            if (CircleMarker == null)
            {
                CircleMarker = PyDraw.getCircle(363, Color.White);
            }
            if (menuFont1 != "" && menuFont1 != null)
            {
                UIFontRenderer.LoadFont(Helper, Path.Combine("fonts", menuFont1 + ".fnt"), menuFont1);
            }

            if (menuFont2 != "" && menuFont2 != null && menuFont2 != menuFont1)
            {
                UIFontRenderer.LoadFont(Helper, Path.Combine("fonts", menuFont2 + ".fnt"), menuFont2);
            }

            UIElement menu = UIElement.GetContainer("WarpMenu", 0, UIHelper.GetCentered(0, 0, menuWidth, menuHeight), 1f);
            UIElement back = UIElement.GetImage(UIHelper.DarkTheme, Color.White * 0.9f, "Back", 1, -1).AsTiledBox(16, true);

            menu.Add(back);

            AddLeftMenu(menu);
            AddInfoMenu(menu);

            return(menu);
        }
Exemplo n.º 2
0
 private static Texture2D getMainColorPickerFromBase(int b, int witdh, int height)
 {
     return(PyDraw.getRectangle(witdh, height, (x, y, w, h) =>
     {
         return (ColorFromHSV(b, (((double)x) / w), 1d - ((double)y) / h));
     }));
 }
Exemplo n.º 3
0
        private void AddInfoMenu(UIElement menu)
        {
            InfoMenu = UIElement.GetContainer("InfoMenu", 0, UIHelper.GetTopRight(margins * -1, margins, (menuWidth / 2) - (2 * margins), menuHeight - (2 * margins)));
            InfoBack = UIElement.GetImage(PyDraw.getBorderedRectangle((menuWidth / 2) - (2 * margins), menuHeight - (2 * margins), Color.White * 0.2f, 1, Color.White), Color.MediumOrchid, positioner: UIHelper.GetCentered());
            InfoMenu.Add(InfoBack);

            menu.Add(InfoMenu);
        }
Exemplo n.º 4
0
        public static UIElement GetColorPicker(List <Color> oldColors, Action <int, Color> updateHandler = null, bool small = false)
        {
            int index = 0;

            int size = small ? 60 : 100;

            UIElement container = UIElement.GetContainer("MultiPicker", 0, UIHelper.GetCentered(0, 0, size * 8, size * 4));

            UIElement currentColorPicker = GetColorPicker(oldColors[index], (c) =>
            {
                updateHandler?.Invoke(index, c);
                container.GetElementById("ColorCircle>" + index).Color = c;
            }, small);

            var cpPositioner = UIHelper.GetTopRight(0, 0, currentColorPicker.Bounds.Width, currentColorPicker.Bounds.Height);

            currentColorPicker.Positioner = cpPositioner;
            currentColorPicker.Z          = 1;

            Texture2D circle = PyDraw.getCircle((int)(size * 2), Color.White, Color.Transparent);

            for (int i = 0; i < oldColors.Count; i++)
            {
                int       y = (-size / 5) + (i * ((int)(size * 1.1f)));
                UIElement colorContainer = UIElement.GetImage(UIHelper.DarkTheme, Color.White * 0.75f, "Color>" + i, 1f, i == index ? 3 : 0, UIHelper.GetTopLeft((int)(((100 - size) * 0.5f)), y, size, size)).WithTypes("ColorPick").AsTiledBox(size / 5, true).WithInteractivity(click: (point, right, release, hold, element) =>
                {
                    int idx = int.Parse(element.Id.Split('>')[1]);

                    if (index == idx)
                    {
                        return;
                    }

                    else if (!right && release)
                    {
                        foreach (UIElement e in container.GetElementsByType(true, "ColorPick"))
                        {
                            e.Z = 0;
                        }

                        index     = idx;
                        element.Z = 3;

                        currentColorPicker.Color = container.GetElementById("ColorCircle>" + idx).Color;
                        currentColorPicker.GetElementById("CPB_Old").Color = oldColors[idx];

                        container.UpdateBounds();
                    }
                });
                UIElement colorCircle = UIElement.GetImage(circle, oldColors[i], "ColorCircle>" + i, positioner: UIHelper.GetCentered(0, 0, 0.4f));
                colorContainer.Add(colorCircle);
                container.Add(colorContainer);
            }
            container.Add(currentColorPicker);

            return(container);
        }
Exemplo n.º 5
0
        private void AddLeftMenuOption(UIElement leftMenu, MenuItem item, int index, int row = 0)
        {
            int    maxT      = 11;
            int    placeRow  = row + (index / options);
            string placeText = item.Name;

            if (placeText.Length > maxT + 3)
            {
                placeText = placeText.Substring(0, maxT) + "...";
            }

            index = index % options;
            UIElement button    = UIElement.GetImage(PyDraw.getBorderedRectangle(optionWidth, optionHeight - 1, Color.White * 0.2f, 1, Color.White), row == 0 ? Color.CornflowerBlue : Color.LightGreen, item.Id, 1, 0, UIHelper.GetTopLeft(placeRow * (optionWidth + 1), index * (optionHeight + 1), optionWidth, optionHeight - 1)).WithInteractivity(update: UpdateItem, click: ClickItem);
            float     textScale = Math.Min(0.5f * menuScale, 0.7f);

            if (LocalizedContentManager.CurrentLanguageLatin && menuFont1 != "" && menuFont1 != null)
            {
                textScale *= cFontAdjust;
            }

            UITextElement text = new UITextElement(placeText, Game1.smallFont, Color.White, textScale, 1, positioner: UIHelper.GetCentered());

            if (LocalizedContentManager.CurrentLanguageLatin && menuFont1 != "" && menuFont1 != null)
            {
                text.WithFont(menuFont1);
            }

            button.Z = row;
            button.Add(text);
            leftMenu.Add(button);

            if (item.Special)
            {
                PyTK.PyUtils.setDelayedAction(100, () => button.ClickAction(Point.Zero, false, true, false, button));
            }

            if (row > 0)
            {
                button.Disable();
                button.Visible = false;
                text.Visible   = false;
            }
            for (int i = 0; i < item.Children.Count; i++)
            {
                if (item.Children[i] is MenuItem child)
                {
                    AddLeftMenuOption(leftMenu, child, i, row + 1);
                }
            }
        }
Exemplo n.º 6
0
        internal void setupBoard()
        {
            calculateSizes();

            Texture2D whiteTile = PyDraw.getRectangle(tileTextureSize, tileTextureSize, WhiteTileColor);
            Texture2D blackTile = PyDraw.getRectangle(tileTextureSize, tileTextureSize, BlackTileColor);

            BoardImage  = PyDraw.getPattern(boardTextureSize, boardTextureSize, whiteTile, blackTile);
            BoardBounds = new Rectangle(Position.X, Position.Y, BoardSize, BoardSize);
            Structure   = PyDraw.getPattern(boardTextureSize, boardTextureSize, Game1.content.Load <Texture2D>(@"LooseSprites//Cursors").getArea(new Rectangle(527, 0, 100, 96)));
            Color[] bgColors = new[] { Color.LightGray, Color.White };
            BackgroundShade  = PyDraw.getPattern(backGroundTileSize * 8, backGroundTileSize * 8, PyDraw.getRectangle(backGroundTileSize, backGroundTileSize, bgColors[0]), PyDraw.getRectangle(backGroundTileSize, backGroundTileSize, bgColors[1]));
            BackgroundBorder = PyDraw.getRectangle(BoardBounds.Width + 20, BoardBounds.Height + 20, Color.White);
            HoverTileImage   = PyDraw.getRectangle(TilesSize, TilesSize, Color.White);
        }
Exemplo n.º 7
0
        private UIElement SetUpMenu()
        {
            if (CircleMarker == null)
            {
                CircleMarker = PyDraw.getCircle(363, Color.White);
            }

            UIElement menu = UIElement.GetContainer("WarpMenu", 0, UIHelper.GetCentered(0, 0, menuWidth, menuHeight), 1f);
            UIElement back = UIElement.GetImage(UIHelper.DarkTheme, Color.White * 0.9f, "Back", 1, -1).AsTiledBox(16, true);

            menu.Add(back);

            AddLeftMenu(menu);
            AddInfoMenu(menu);

            return(menu);
        }
Exemplo n.º 8
0
        private static UIElement getColorPickerMenu(int oldH = 0, double oldS = 0, double oldV = 0, float oldAlpha = 1f, Action <Color> handler = null, int size = 100)
        {
            int   previewWidth      = size;
            int   margin            = previewWidth / 10;
            int   pickerWidth       = margin * 4;
            int   pickerHeight      = previewWidth * 3;
            int   mainPickerWidth   = previewWidth * 5;
            int   baseValue         = oldH;
            float currentAlpha      = oldAlpha;
            int   pickPosition      = (int)((baseValue / 360f) * pickerHeight);
            int   pickAlphaPosition = (int)((1f - oldAlpha) * (mainPickerWidth - pickerWidth));
            int   lastBaseValue     = baseValue;

            Vector2 colorChoiceMade = new Vector2((float)(oldS * mainPickerWidth), (float)((1d - oldV) * (pickerHeight - margin - pickerWidth) - 1f));

            Color[] baseColors = new Color[mainPickerWidth * (pickerHeight - margin - pickerWidth)];

            Color     old          = (ColorFromHSV(oldH, oldS, oldV)) * oldAlpha;
            Color     currentColor = old;
            Color     lastColor    = old;
            Texture2D cp           = PyDraw.getRectangle(1, 361, (i, w, h) =>
            {
                return(ColorFromHSV(i, 1d, 1d));
            });

            UIElement colorChoice  = null;
            UIElement colorPreview = UIElement.GetImage(UIHelper.PlainTheme, old, "CPB_Preview", positioner: UIHelper.GetBottomLeft(0, 0, previewWidth, pickerHeight / 2 - margin / 2));
            UIElement colorOld     = UIElement.GetImage(UIHelper.PlainTheme, old, "CPB_Old", positioner: UIHelper.GetTopLeft(0, 0, previewWidth, pickerHeight / 2 - margin / 2)).WithInteractivity(click: (p, r, rls, hld, e) =>
            {
                if (r)
                {
                    baseValue         = oldH;
                    pickPosition      = (int)((baseValue / 360f) * pickerHeight);
                    pickAlphaPosition = (int)((1f - oldAlpha) * (mainPickerWidth - (pickerWidth)));
                    currentAlpha      = oldAlpha;
                    colorChoiceMade   = new Vector2((float)(oldS * mainPickerWidth), (float)((1d - oldV) * (pickerHeight - margin - pickerWidth) - 1f));
                }
            });;

            Texture2D ap = PyDraw.getRectangle(pickerHeight, 1, (x, y, w, h) =>
            {
                return(Color.White * (1f - ((float)x / w)));
            });


            UIElement container = UIElement.GetContainer("ColorPickerContainer", positioner: UIHelper.GetCentered(0, 0, pickerWidth + margin + mainPickerWidth + margin + previewWidth + margin * 6, pickerHeight + margin * 6));

            container.Color = Color.Transparent;
            UIElement box = UIElement.GetImage(UIHelper.DarkTheme, Color.White * 0.75f, "CPB_Box").AsTiledBox(size / 5, true);

            UIElement canvas = UIElement.GetImage(UIHelper.PlainTheme, Color.Transparent, "ColorPicker", positioner: UIHelper.GetCentered(0, 0, pickerWidth + margin + mainPickerWidth + margin + previewWidth, pickerHeight));

            UIElement colorPickerBasePick = UIElement.GetImage(UIHelper.ArrowLeft, Color.Wheat, "CPB_Pick", positioner: (t, p) =>
            {
                int w   = p.Bounds.Width;
                float s = ((float)w) / t.Theme.Width;
                int h   = (int)(s * t.Theme.Width);
                return(new Rectangle((p.Bounds.Right - w / 3), (p.Bounds.Y + pickPosition) - (h / 2), w, h));
            });

            UIElement colorPickPointer = UIElement.GetImage(PyDraw.getBorderedRectangle(8, 8, Color.Transparent, 1, Color.White), Color.White, "CPB_Pointer", positioner: (t, p) => {
                return(new Rectangle((int)colorChoiceMade.X + p.Bounds.X - t.Theme.Width / 2, (int)colorChoiceMade.Y + p.Bounds.Y - t.Theme.Height / 2, t.Theme.Width, t.Theme.Height));
            });


            var first = getMainColorPickerFromBase(baseValue, mainPickerWidth, pickerHeight - margin - pickerWidth);

            first.GetData(baseColors);

            colorChoice = UIElement.GetImage(first, Color.White, "CPB_MainPicker", positioner: UIHelper.GetTopLeft(previewWidth + margin, 0, mainPickerWidth, pickerHeight - margin - pickerWidth)).WithInteractivity(click: (point, right, release, hold, element) =>
            {
                colorChoiceMade = new Vector2(Game1.getMouseX() - element.Bounds.X, Game1.getMouseY() - element.Bounds.Y);
                colorPickPointer.UpdateBounds();
            });

            UIElement colorPickerBase = UIElement.GetImage(cp, Color.White, "CPB_BasePicker", 1, 2, UIHelper.GetTopRight(0, 0, pickerWidth, 1f)).WithInteractivity(click: (point, right, release, hold, element) =>
            {
                pickPosition = Game1.getMouseY() - element.Bounds.Y;
                colorPickerBasePick.UpdateBounds();
                baseValue = (int)((((float)pickPosition) / element.Bounds.Height) * (360f));
            });


            UIElement colorPickerAlphaPick = UIElement.GetImage(UIHelper.ArrowUp, Color.Wheat, "CPB_Pick", positioner: (t, p) =>
            {
                int h   = p.Bounds.Height;
                float s = ((float)h) / t.Theme.Height;
                int w   = (int)(s * t.Theme.Height);
                return(new Rectangle((p.Bounds.X - w / 2) + pickAlphaPosition, p.Bounds.Bottom - (h / 3), w, h));
            });

            UIElement colorPickerAlpha = UIElement.GetImage(ap, Color.White, "CPB_AlphaPicker", 1, 2, UIHelper.GetBottomLeft(previewWidth + margin + pickerWidth, 0, mainPickerWidth - pickerWidth, pickerWidth)).WithInteractivity(click: (point, right, release, hold, element) =>
            {
                pickAlphaPosition = Game1.getMouseX() - element.Bounds.X;
                colorPickerAlphaPick.UpdateBounds();
                currentAlpha = 1f - (pickAlphaPosition / (float)element.Bounds.Width);
            });

            UIElement alphaReset = UIElement.GetImage(UIHelper.PlainTheme, Color.LightGray, "ResetAlpha", 1, 1, UIHelper.GetBottomLeft(previewWidth + margin, 0, pickerWidth, pickerWidth)).WithInteractivity(click: (point, right, release, hold, element) =>
            {
                colorPreview.Color = new Color(colorPreview.Color.R, colorPreview.Color.G, colorPreview.Color.B);
                pickAlphaPosition  = 0;
                currentAlpha       = 1f;
                colorPickerAlphaPick.UpdateBounds();
            });

            colorPickerBase.Add(colorPickerBasePick);
            colorPickerAlpha.Add(colorPickerAlphaPick);
            colorChoice.Add(colorPickPointer);
            canvas.Add(alphaReset);
            canvas.Add(colorPickerBase);
            canvas.Add(colorPickerAlpha);

            canvas.Add(colorPreview);
            canvas.Add(colorOld);
            canvas.Add(colorChoice);
            box.Add(canvas);
            container.Add(box);


            box.WithInteractivity(draw: (b, e) =>
            {
                currentColor       = (ColorFromHSV(baseValue, (((double)colorChoiceMade.X) / colorChoice.Bounds.Width), 1d - ((double)colorChoiceMade.Y) / colorChoice.Bounds.Height));
                currentColor.A     = (byte)(int)(255f * currentAlpha);
                colorPreview.Color = currentColor;

                if (baseValue != lastBaseValue && Microsoft.Xna.Framework.Input.Mouse.GetState().LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Released)
                {
                    lastBaseValue     = baseValue;
                    colorChoice.Theme = getMainColorPickerFromBase(baseValue, mainPickerWidth, pickerHeight - margin - pickerWidth);
                    colorChoice.Theme.GetData(baseColors);
                }

                if (container.Color != Color.Transparent)
                {
                    double newH = 0;
                    double newS = 0;
                    double newV = 0;
                    float newA  = container.Color.A / 255f;

                    ColorToHSV(container.Color, out newH, out newS, out newV);
                    container.Color = Color.Transparent;

                    baseValue         = (int)newH;
                    pickPosition      = (int)((baseValue / 360f) * pickerHeight);
                    pickAlphaPosition = (int)((1f - newA) * (mainPickerWidth - pickerWidth));
                    currentAlpha      = newA;
                    colorChoiceMade   = new Vector2((float)(newS * mainPickerWidth), (float)((1d - newV) * (pickerHeight - margin - pickerWidth) - 1f));
                }

                if (currentColor != lastColor)
                {
                    lastColor = currentColor;
                    handler?.Invoke(colorPreview.Color);
                }
            });

            return(container);
        }
Exemplo n.º 9
0
        private UIElement GetMenuForLocation(GameLocation location, NPC npc = null, bool artifacts = false, bool structure = false)
        {
            var   lmenu     = UIElement.GetContainer("Location Menu " + location.Name, positioner: UIHelper.GetCentered(0, 0, 1f, 1f));
            float textScale = 1.4f;

            if (LocalizedContentManager.CurrentLanguageLatin && menuFont2 != "" && menuFont2 != null)
            {
                textScale *= cFontAdjust;
            }
            var lname = !structure ? location.Name : location.uniqueName.Value;

            if (i18n.GetTranslations().ToList().Exists(t => t.Key == "location." + lname))
            {
                lname = i18n.Get("location." + lname);
            }

            var lmenuHead = new UITextElement(lname, Game1.dialogueFont, Color.White, textScale, positioner: UIHelper.GetTopCenter(0, 5));


            var back = location.Map.GetLayer("Back");

            double w = back.LayerWidth;
            double h = back.LayerHeight;
            double s = (h / w);

            int tw = (menuWidth / 2) - (4 * margins);
            int th = (int)(tw * s);

            if (th > menuHeight * 0.75f)
            {
                s  = (w / h);
                th = (int)(menuHeight * 0.75f);
                tw = (int)(th * s);
            }

            var lmenuViewer = UIElement.GetImage(PyDraw.getWhitePixel(), Color.Green, positioner: UIHelper.GetTopCenter(0, 50, tw, th));

            var lmenuWarp    = new UITextElement($"{i18n.Get("menu.locations.warp")} (X:0 Y:0)", Game1.dialogueFont, Color.White, textScale, positioner: UIHelper.GetTopCenter(0, th + 60));
            var lmenuLoading = new UITextElement(i18n.Get("menu.locations.loading"), Game1.dialogueFont, Color.White, textScale, positioner: UIHelper.GetCentered());

            lmenuViewer.Add(lmenuLoading);

            if (LocalizedContentManager.CurrentLanguageLatin && menuFont2 != "" && menuFont2 != null)
            {
                lmenuHead.WithFont(menuFont2);
                lmenuWarp.WithFont(menuFont2);
                lmenuLoading.WithFont(menuFont2);
            }

            lmenu.Add(lmenuViewer);

            Point tPoint = new Point(0, 0);

            lmenuViewer.WithInteractivity(update: (t, el) =>
            {
                PlatoWarpMenuMod.GetLocationShot(location, () =>
                {
                    Texture2D screen = PlatoWarpMenuMod.LastScreen;
                    if (PlatoWarpMenuMod.instance.config.UseTempFolder)
                    {
                        screen = Helper.Content.Load <Texture2D>(Path.Combine("Temp", (location.isStructure.Value ? location.uniqueName.Value : location.Name) + ".png"));
                    }
                    var image = UIElement.GetImage(screen, Color.White, positioner: el.Positioner);
                    image.WithInteractivity(click: (point, right, released, hold, imageContainer) =>
                    {
                        if (released && !right)
                        {
                            if (!location.isTileLocationTotallyClearAndPlaceableIgnoreFloors(new Vector2(tPoint.X, tPoint.Y)))
                            {
                                return;
                            }
                            Game1.activeClickableMenu = null;
                            Game1.player.warpFarmer(new Warp(0, 0, structure ? location.uniqueName.Value : location.Name, tPoint.X, tPoint.Y, false));
                        }
                    }, hover: (point, drag, imageContainer) =>
                    {
                        var rect = imageContainer.Bounds;
                        int x    = (int)(((point.X - rect.X) / (double)rect.Width) * location.Map.GetLayer("Back").LayerWidth);
                        int y    = (int)(((point.Y - rect.Y) / (double)rect.Height) * location.Map.GetLayer("Back").LayerHeight);
                        tPoint   = new Point(x, y);

                        lmenuWarp.Text = $"{i18n.Get("menu.locations.warp")} (X:{ (int)x} Y:{(int)y})";

                        if (!location.isTileLocationTotallyClearAndPlaceableIgnoreFloors(new Vector2(x, y)))
                        {
                            lmenuWarp.TextColor = Color.Red;
                        }
                        else
                        {
                            lmenuWarp.TextColor = Color.White;
                        }
                    });

                    lmenu.Add(image);
                    lmenu.Remove(lmenuViewer);
                    lmenu.UpdateBounds();

                    if (npc != null)
                    {
                        var rect        = image.Bounds;
                        int mx          = (int)((npc.getTileX() / (double)location.Map.GetLayer("Back").LayerWidth) * rect.Width);
                        int my          = (int)((npc.getTileY() / (double)location.Map.GetLayer("Back").LayerHeight) * rect.Height);
                        var lmenuMarker = UIElement.GetImage(CircleMarker, Color.Magenta * 0.6f, positioner: UIHelper.GetTopLeft(mx - 12, my - 12, 33, 33));
                        image.Add(lmenuMarker);
                    }

                    if (artifacts)
                    {
                        foreach (var spot in location.Objects.Keys.Where(o => location.Objects[o].ParentSheetIndex == 590))
                        {
                            var rect        = image.Bounds;
                            int mx          = (int)((spot.X / (double)location.Map.GetLayer("Back").LayerWidth) * rect.Width);
                            int my          = (int)((spot.Y / (double)location.Map.GetLayer("Back").LayerHeight) * rect.Height);
                            var lmenuMarker = UIElement.GetImage(CircleMarker, Color.Red, positioner: UIHelper.GetTopLeft(mx - 5, my - 5, 11, 11));
                            image.Add(lmenuMarker);
                        }
                    }
                });
                el.WithoutInteractivity(true);
            });


            lmenu.Add(lmenuHead);
            lmenu.Add(lmenuWarp);
            return(lmenu);
        }
Exemplo n.º 10
0
        public static void OpenMenu(IClickableMenu prioMenu = null)
        {
            PlatoUIMenu      menu    = null;
            List <UIElement> folders = new List <UIElement>();

            foreach (string folder in TextureLoader.folders)
            {
                folders.AddOrReplace(GetElementForFolder(folder));
            }

            int f = folders.Count;

            Texture2D circle = PyDraw.getCircle(margin * 9, Color.White);

            UIElement     container = UIElement.GetContainer("PortraitureMenu", 0, UIHelper.GetCentered(0, 0, listElementWidth + margin * 2, listElementHeight * elementsPerPage + margin * 3), 1);
            UIElement     listbox   = new UIElement("ListBox", UIHelper.GetCentered(0, 0, listElementWidth + margin * 2, listElementHeight * elementsPerPage + margin * 3), 0, UIHelper.PlainTheme, Color.Black * 0.5f, 1, false);
            UIElementList list      = new UIElementList("PortraitFolders", true, 0, 1, 5, 0, true, UIHelper.GetCentered(0, 0, listElementWidth, listElementHeight * elementsPerPage + margin), UIHelper.GetFixed(0, 0, listElementWidth, listElementHeight), folders.ToArray());
            UIElement     closeBtn  = UIElement.GetImage(circle, Color.White, "CloseBtn", 0.8f, 99, UIHelper.GetAttachedDiagonal(listbox, false, true, margin, -1 * margin, margin * 3, margin * 3)).WithInteractivity(click: (point, right, release, hold, element) =>
            {
                if (release)
                {
                    menu?.exitThisMenu();
                }
            }, hover: (point, hoverIn, element) =>
            {
                if (hoverIn != element.WasHover)
                {
                    Game1.playSound("smallSelect");
                }

                if (hoverIn)
                {
                    element.Opacity = 1f;
                }
                else
                {
                    element.Opacity = 0.8f;
                }
            });

            closeBtn.Add(UIElement.GetImage(circle, Color.DarkCyan, "CloseBtn_Inner", 1, 0, UIHelper.GetCentered(0, 0, margin, margin)));
            container.Add(closeBtn);
            listbox.Add(list);
            container.Add(listbox);

            UIElement scrollBar   = UIElement.GetContainer("ScrollBarContainer", 0, UIHelper.GetAttachedHorizontal(listbox, false, 1, margin, 0, margin * 2, listElementHeight * 2));
            UIElement up          = UIElement.GetImage(PyDraw.getFade(margin * 2, margin * 2, Color.White, Color.Gray, false), Color.DarkCyan, "ScrollUp", 1, 0, UIHelper.GetTopCenter());
            UIElement down        = UIElement.GetImage(PyDraw.getFade(margin * 2, margin * 2, Color.White, Color.Gray, false), Color.DarkCyan, "ScrollDown", 1, 0, UIHelper.GetBottomCenter());
            UIElement bar         = UIElement.GetImage(PyDraw.getFade(margin * 2, listElementHeight * 2 - margin * 4, Color.White, Color.Gray, false), Color.White, "ScrollBar", 1, 0, UIHelper.GetCentered());
            UIElement scrollPoint = UIElement.GetImage(circle, Color.DarkCyan, "ScrollPoint", 1, 0, (t, p) =>
            {
                int w = p.Bounds.Width;
                int h = p.Bounds.Height / (f - 2);
                int x = 0;
                int y = list.Position * h;
                return(new Rectangle(p.Bounds.X + x, p.Bounds.Y + y, w, h));
            });

            if (f > 3)
            {
                bar.Add(scrollPoint.WithBase(list));
                scrollBar.Add(up.WithBase(list).WithInteractivity(click: clickScrollBar, hover: hoverScrollBar));
                scrollBar.Add(down.WithBase(list).WithInteractivity(click: clickScrollBar, hover: hoverScrollBar));
                scrollBar.Add(bar.WithBase(list).WithInteractivity(click: clickScrollBar));
                listbox.Add(scrollBar);
            }
            menu = UIHelper.OpenMenu("PortraitureMenu", container);
            menu.exitFunction = new IClickableMenu.onExit(() =>
            {
                if (prioMenu != null)
                {
                    Game1.activeClickableMenu = prioMenu;
                }
            });
        }
Exemplo n.º 11
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);
        }