Skip to content

Commit

Permalink
Add mouseWheelControlEnabled
Browse files Browse the repository at this point in the history
  • Loading branch information
manups4e committed Sep 11, 2021
1 parent f824419 commit 288b6c9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 17 deletions.
2 changes: 2 additions & 0 deletions NativeUI/Controls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 44 additions & 17 deletions NativeUI/UIMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ public enum MenuState

public delegate void ProgressSliderChangedEvent(UIMenu menu, UIMenuSliderProgressItem item, int newIndex);



#endregion

Expand Down Expand Up @@ -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<MenuControls, Tuple<List<Keys>, List<Tuple<Control, int>>>> _keyDictionary =
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1156,9 +1173,9 @@ public void DisableInstructionalButtons(bool disable)
/// <param name="spriteBanner">Sprite object. The position and size does not matter.</param>
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);
}

/// <summary>
Expand All @@ -1167,7 +1184,7 @@ public void SetBannerType(Sprite spriteBanner)
/// <param name="rectangle">UIResRectangle object. Position and size does not matter.</param>
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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -1751,6 +1768,7 @@ public bool HasControlJustBeenReleaseed(MenuControls control, Keys key = Keys.No
}

private int _controlCounter;

/// <summary>
/// Check whether a menucontrol is being pressed.
/// </summary>
Expand Down Expand Up @@ -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);

Expand All @@ -1870,7 +1889,7 @@ public async Task Draw()

if (String.IsNullOrWhiteSpace(BannerTexture))
{
if (BannerSprite != null)
if (BannerSprite != null)
BannerSprite.Draw();
else
{
Expand Down Expand Up @@ -1985,13 +2004,20 @@ public async Task Draw()
/// </summary>
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);
Expand All @@ -2000,6 +2026,7 @@ public void ProcessMouse()
return;
}

var WindowHeight = CalculateWindowHeight();
PointF safezoneOffset = ScreenTools.SafezoneBounds;
API.ShowCursorThisFrame();
int limit = MenuItems.Count - 1;
Expand Down

0 comments on commit 288b6c9

Please sign in to comment.