Esempio 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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
                }
            }
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        private void AddLeftMenu(UIElement menu)
        {
            menuItems.Clear();

            PopulateMenu();

            UIElement leftMenu = UIElement.GetContainer(z: 1, positioner: UIHelper.GetTopLeft(margins, margins, (optionWidth * 2) + 2, menuHeight - (2 * margins)));

            for (int i = 0; i < menuItems.Count; i++)
            {
                if (menuItems[i] is MenuItem item)
                {
                    AddLeftMenuOption(leftMenu, item, i);
                }
            }

            menu.Add(leftMenu);
        }
Esempio n. 6
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);
        }
Esempio n. 7
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;
                }
            });
        }
Esempio n. 8
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);
        }