public override void ProcessMouseEvent(Vector2 location, InputManager.LogicalButtonState buttons) { if (Math.Abs(buttons.WheelTick) > 0 && TextLabels.Count > 1) { SetSelectedIndex(SelectedIndex + buttons.WheelTick); } if (!buttons.PrimaryClick || ParentCanvas == null || ParentCanvas.PopupEnabled() || TextLabels.Count < 2) { return; } float width = Rect.GetPixelSize().X; float height = Rect.GetPixelSize().Y; Vector2 origin = Rect.GetPixelOrigin(); float availableDist = width - (height * 2); if (location.X < origin.X + height || location.X > origin.X + availableDist + height) { return; } Vector2 thisOrigin = GetScreenOrigin(); float thisCenterY = thisOrigin.Y + (height * 0.5f); float totalheight = (MenuCommon.ButtonSpacing.Paramater + (height * 1)) * TextLabels.Count; totalheight += MenuCommon.ButtonSpacing.Paramater * 1; float halfHeight = totalheight * 0.5f; float screenHeight = ParentCanvas.BoundWindow.Height; // see where the popup will land on the screen. OriginLocation originAllignment = OriginLocation.LowerLeft; if (totalheight > screenHeight) // it won't fit, center it { originAllignment = OriginLocation.MiddleLeft; } else { if (thisCenterY - halfHeight > 0 && thisCenterY + halfHeight <= screenHeight) { originAllignment = OriginLocation.MiddleLeft; // it'll fit centered, that looks better } else { // it won't fit centered, so put it on the other side of the screen from where the button is if (thisCenterY > halfHeight) { originAllignment = OriginLocation.UpperLeft; } else { originAllignment = OriginLocation.LowerLeft; } } } if (originAllignment == OriginLocation.UpperLeft) { thisOrigin.Y += height; } else if (originAllignment == OriginLocation.MiddleLeft) { thisOrigin.Y += height * 0.5f; } RelativeRect rect = new RelativeRect(new RelativeLoc(thisOrigin.X, RelativeLoc.Edge.Raw), new RelativeLoc(thisOrigin.Y, RelativeLoc.Edge.Raw), RelativeSize.FixedPixelSize(width), RelativeSize.FixedPixelSize(totalheight), originAllignment); var popup = new UIPanel(rect, ThemeManager.GetThemeAsset("ui/SelectorPopupBackground.png")); popup.FillMode = UIFillModes.SmartStprite; popup.IgnoreMouse = false; VerticalLayoutGroup vertgroup = MenuCommon.SetupCommonColumn(new RelativeRect(RelativeLoc.XCenter, RelativeLoc.YCenter, RelativeSize.ThreeQuarterWidth, rect.Height, OriginLocation.Center)); vertgroup.FirstElementHasSpacing = true; foreach (var label in TextLabels) { MenuButton button = new MenuButton(new RelativeRect(), label); button.Tag = label; button.Clicked += PopupButton_Clicked; if (label == GetText()) { button.Check(); } vertgroup.AddChild(button); } popup.AddChild(vertgroup); ParentCanvas.SetPopupElement(popup); }