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); }
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); } } }
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); }