From 288b6c924b6ccee533ba64b0ba8753da111139d0 Mon Sep 17 00:00:00 2001 From: manups4e Date: Sat, 11 Sep 2021 22:59:09 +0200 Subject: [PATCH] Add mouseWheelControlEnabled --- NativeUI/Controls.cs | 2 ++ NativeUI/UIMenu.cs | 61 ++++++++++++++++++++++++++++++++------------ 2 files changed, 46 insertions(+), 17 deletions(-) diff --git a/NativeUI/Controls.cs b/NativeUI/Controls.cs index 197a8f0..5189fcf 100644 --- a/NativeUI/Controls.cs +++ b/NativeUI/Controls.cs @@ -65,6 +65,8 @@ public static void Toggle(bool toggle) if (toggle) { // Enable all of them + Game.EnableAllControlsThisFrame(0); + Game.EnableAllControlsThisFrame(1); Game.EnableAllControlsThisFrame(2); } // If we don't need them diff --git a/NativeUI/UIMenu.cs b/NativeUI/UIMenu.cs index 39def33..f18e7f0 100644 --- a/NativeUI/UIMenu.cs +++ b/NativeUI/UIMenu.cs @@ -830,7 +830,7 @@ public enum MenuState public delegate void ProgressSliderChangedEvent(UIMenu menu, UIMenuSliderProgressItem item, int newIndex); - + #endregion @@ -859,6 +859,7 @@ public class UIMenu private const int MaxItemsOnScreen = 9; private int _minItem; private int _maxItem = MaxItemsOnScreen; + private bool mouseWheelControlEnabled; //Keys private readonly Dictionary, List>>> _keyDictionary = @@ -905,6 +906,25 @@ public class UIMenu public bool MouseEdgeEnabled = true; public bool ControlDisablingEnabled = true; + public bool MouseWheelControlEnabled + { + get => mouseWheelControlEnabled; set + { + mouseWheelControlEnabled = value; + if (value) + { + SetKey(MenuControls.Up, Control.CursorScrollUp); + SetKey(MenuControls.Down, Control.CursorScrollDown); + } + else + { + ResetKey(MenuControls.Up); + ResetKey(MenuControls.Down); + SetKey(MenuControls.Up, Control.PhoneUp); + SetKey(MenuControls.Down, Control.PhoneDown); + } + } + } public bool ResetCursorOnOpen = true; [Obsolete("The description is now formated automatically by the game.")] public bool FormatDescriptions = true; @@ -1064,10 +1084,7 @@ public UIMenu(string title, string subtitle, PointF offset, string spriteLibrary SetKey(MenuControls.Up, Control.PhoneUp); - SetKey(MenuControls.Up, Control.CursorScrollUp); - SetKey(MenuControls.Down, Control.PhoneDown); - SetKey(MenuControls.Down, Control.CursorScrollDown); SetKey(MenuControls.Left, Control.PhoneLeft); SetKey(MenuControls.Right, Control.PhoneRight); @@ -1127,7 +1144,7 @@ public UIMenu(string title, string subtitle, PointF offset, string spriteLibrary public void SetMenuWidthOffset(int widthOffset) { WidthOffset = widthOffset; - BannerSprite .Size = new SizeF(431 + WidthOffset, 100); + BannerSprite.Size = new SizeF(431 + WidthOffset, 100); _mainMenu.Items[0].Position = new PointF((WidthOffset + Offset.X + 431) / 2, 20 + Offset.Y); // Title _counterText.Position = new PointF(425 + Offset.X + widthOffset, 110 + Offset.Y); if (_mainMenu.Items.Count >= 1) @@ -1156,9 +1173,9 @@ public void DisableInstructionalButtons(bool disable) /// Sprite object. The position and size does not matter. public void SetBannerType(Sprite spriteBanner) { - BannerSprite = spriteBanner; - BannerSprite .Size = new SizeF(431 + WidthOffset, 100); - BannerSprite .Position = new PointF(Offset.X, Offset.Y); + BannerSprite = spriteBanner; + BannerSprite.Size = new SizeF(431 + WidthOffset, 100); + BannerSprite.Position = new PointF(Offset.X, Offset.Y); } /// @@ -1167,7 +1184,7 @@ public void SetBannerType(Sprite spriteBanner) /// UIResRectangle object. Position and size does not matter. public void SetBannerType(UIResRectangle rectangle) { - BannerSprite = null; + BannerSprite = null; BannerRectangle = rectangle; BannerRectangle.Position = new PointF(Offset.X, Offset.Y); BannerRectangle.Size = new SizeF(431 + WidthOffset, 100); @@ -1315,7 +1332,7 @@ private float CalculatePanelsPosition(bool hasDescription) { float Height = CalculateWindowHeight() + 126 + _mainMenu.Position.Y; if (hasDescription) - Height += _descriptionRectangle.Size.Height + 5; + Height += _descriptionRectangle.Size.Height + 5; return CalculateItemHeight() + Height; } @@ -1533,7 +1550,7 @@ public void GoRight() else if (MenuItems[CurrentSelection] is UIMenuSliderProgressItem) { UIMenuSliderProgressItem it = (UIMenuSliderProgressItem)MenuItems[CurrentSelection]; - it.Value ++; + it.Value++; Game.PlaySound(AUDIO_LEFTRIGHT, AUDIO_LIBRARY); SliderProgressChange(it, it.Value); } @@ -1751,6 +1768,7 @@ public bool HasControlJustBeenReleaseed(MenuControls control, Keys key = Keys.No } private int _controlCounter; + /// /// Check whether a menucontrol is being pressed. /// @@ -1857,6 +1875,7 @@ private int IsMouseInListItemArrows(UIMenuItem item, PointF topLeft, PointF safe public async Task Draw() { if (!Visible || PopupWarningThread.Warning.IsShowing) return; + if (ControlDisablingEnabled) Controls.Toggle(false); @@ -1870,7 +1889,7 @@ public async Task Draw() if (String.IsNullOrWhiteSpace(BannerTexture)) { - if (BannerSprite != null) + if (BannerSprite != null) BannerSprite.Draw(); else { @@ -1985,13 +2004,20 @@ public async Task Draw() /// public void ProcessMouse() { - var WindowHeight = CalculateWindowHeight(); if (!Visible || _justOpened || MenuItems.Count == 0 || IsUsingController || !MouseControlsEnabled) { - API.EnableControlAction(2, (int)Control.LookUpDown, true); - API.EnableControlAction(2, (int)Control.LookLeftRight, true); - API.EnableControlAction(2, (int)Control.Aim, true); - API.EnableControlAction(2, (int)Control.Attack, true); + Game.EnableControlThisFrame(0, Control.LookUpDown); + Game.EnableControlThisFrame(0, Control.LookLeftRight); + Game.EnableControlThisFrame(0, Control.Aim); + Game.EnableControlThisFrame(0, Control.Attack); + Game.EnableControlThisFrame(1, Control.LookUpDown); + Game.EnableControlThisFrame(1, Control.LookLeftRight); + Game.EnableControlThisFrame(1, Control.Aim); + Game.EnableControlThisFrame(1, Control.Attack); + Game.EnableControlThisFrame(2, Control.LookUpDown); + Game.EnableControlThisFrame(2, Control.LookLeftRight); + Game.EnableControlThisFrame(2, Control.Aim); + Game.EnableControlThisFrame(2, Control.Attack); if (_itemsDirty) { MenuItems.Where(i => i.Hovered).ToList().ForEach(i => i.Hovered = false); @@ -2000,6 +2026,7 @@ public void ProcessMouse() return; } + var WindowHeight = CalculateWindowHeight(); PointF safezoneOffset = ScreenTools.SafezoneBounds; API.ShowCursorThisFrame(); int limit = MenuItems.Count - 1;