Skip to content

Commit

Permalink
Merge pull request #37 from manups4e/master
Browse files Browse the repository at this point in the history
Various fixes for new 3.1 version
  • Loading branch information
manups4e authored Jan 9, 2022
2 parents 10d4392 + 7284297 commit e1ca149
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 25 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
13 changes: 11 additions & 2 deletions NativeUI/Hud/Markers/Marker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class Marker
public bool FaceCamera { get; set; }
public bool IsInMarker { get; private set; }
public bool IsInRange { get => MenuPool.PlayerPed.IsInRangeOf(Position, Distance); }
public bool CheckZ { get; set; }
/// <summary>
/// It doesn't work on water and under the map!
/// </summary>
Expand Down Expand Up @@ -96,8 +97,16 @@ public void Draw()
Position = new Vector3(Position.X, Position.Y, _height + 0.03f);
}
World.DrawMarker(MarkerType, Position, Direction, Rotation, Scale, Color, BobUpDown, FaceCamera, Rotate);
float distanceSquared = (Position - MenuPool.PlayerPed.Position).LengthSquared();
IsInMarker = distanceSquared < Math.Pow(Scale.X, 2) || distanceSquared < Math.Pow(Scale.Y, 2) || distanceSquared < Math.Pow(Scale.Z, 2);
if (CheckZ)
{
float distanceSquared = Position.DistanceToSquared(MenuPool.PlayerPed.Position);
IsInMarker = (distanceSquared < Math.Pow(Scale.X / 2, 2) || distanceSquared < Math.Pow(Scale.Y / 2, 2)) || distanceSquared < Math.Pow(Scale.Z / 2, 2);
}
else
{
var distanceSquared = Position.DistanceToSquared2D(MenuPool.PlayerPed.Position);
IsInMarker = distanceSquared <= Math.Pow(Scale.X / 2, 2) || distanceSquared <= Math.Pow(Scale.Y / 2, 2);
}
}
}
}
2 changes: 2 additions & 0 deletions NativeUI/NativeUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -36,6 +37,7 @@
<Reference Include="CitizenFX.Core.Client, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\CitizenFX.Core.Client.1.0.4207\lib\net45\CitizenFX.Core.Client.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml.Linq" />
<Reference Include="Microsoft.CSharp" />
Expand Down
3 changes: 2 additions & 1 deletion NativeUI/Panels/UIMenuGridPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ public UIMenuGridPanel(string TopText, string LeftText, string RightText, string

internal override void Position(float y)
{
var Y = y + 35f;
float ParentOffsetX = ParentItem.Offset.X;
int ParentOffsetWidth = ParentItem.Parent.WidthOffset;
Background.Position = new PointF(ParentOffsetX, y + 35);
Background.Position = new PointF(ParentOffsetX, Y);
Grid.Position = new PointF(ParentOffsetX + 115.5f + (ParentOffsetWidth / 2), 72.5f + y);
Top.Position = new PointF(ParentOffsetX + 215.5f + (ParentOffsetWidth / 2), 40f + y);
Left.Position = new PointF(ParentOffsetX + 57.75f + (ParentOffsetWidth / 2), 155f + y);
Expand Down
2 changes: 1 addition & 1 deletion NativeUI/Panels/UIMenuHorizontalOneLineGridPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public UIMenuHorizontalOneLineGridPanel(string LeftText, string RightText, float

internal override void Position(float y)
{
float Y = y;
var Y = y + 35f;
float ParentOffsetX = ParentItem.Offset.X;
int ParentOffsetWidth = ParentItem.Parent.WidthOffset;
Background.Position = new PointF(ParentOffsetX, Y);
Expand Down
78 changes: 75 additions & 3 deletions NativeUI/Scaleforms/Instructional_Buttons/InstructionalButtons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,50 @@

namespace NativeUI
{
[Flags]
public enum PadCheck
{
Any = 0,
Keyboard = 1,
Controller = 2
}

public enum InputGroup
{
UNUSED = -1,
INPUTGROUP_MOVE = 0,
INPUTGROUP_LOOK = 1,
INPUTGROUP_WHEEL = 2,
INPUTGROUP_CELLPHONE_NAVIGATE = 3,
INPUTGROUP_CELLPHONE_NAVIGATE_UD = 4,
INPUTGROUP_CELLPHONE_NAVIGATE_LR = 5,
INPUTGROUP_FRONTEND_DPAD_ALL = 6,
INPUTGROUP_FRONTEND_DPAD_UD = 7,
INPUTGROUP_FRONTEND_DPAD_LR = 8,
INPUTGROUP_FRONTEND_LSTICK_ALL = 9,
INPUTGROUP_FRONTEND_RSTICK_ALL = 10,
INPUTGROUP_FRONTEND_GENERIC_UD = 11,
INPUTGROUP_FRONTEND_GENERIC_LR = 12,
INPUTGROUP_FRONTEND_GENERIC_ALL = 13,
INPUTGROUP_FRONTEND_BUMPERS = 14,
INPUTGROUP_FRONTEND_TRIGGERS = 15,
INPUTGROUP_FRONTEND_STICKS = 16,
INPUTGROUP_SCRIPT_DPAD_ALL = 17,
INPUTGROUP_SCRIPT_DPAD_UD = 18,
INPUTGROUP_SCRIPT_DPAD_LR = 19,
INPUTGROUP_SCRIPT_LSTICK_ALL = 20,
INPUTGROUP_SCRIPT_RSTICK_ALL = 21,
INPUTGROUP_SCRIPT_BUMPERS = 22,
INPUTGROUP_SCRIPT_TRIGGERS = 23,
INPUTGROUP_WEAPON_WHEEL_CYCLE = 24,
INPUTGROUP_FLY = 25,
INPUTGROUP_SUB = 26,
INPUTGROUP_VEH_MOVE_ALL = 27,
INPUTGROUP_CURSOR = 28,
INPUTGROUP_CURSOR_SCROLL = 29,
INPUTGROUP_SNIPER_ZOOM_SECONDARY = 30,
INPUTGROUP_VEH_HYDRAULICS_CONTROL = 31,
};

public delegate void OnInstructionControlSelected(Control control);
public class InstructionalButton
{
Expand All @@ -28,6 +64,7 @@ public class InstructionalButton

public Control GamepadButton { get; private set; }
public Control KeyboardButton { get; private set; }
public InputGroup InputButton { get; private set; } = InputGroup.UNUSED;
public List<Control> GamepadButtons { get; private set; }
public List<Control> KeyboardButtons { get; private set; }
public PadCheck PadCheck { get; private set; }
Expand Down Expand Up @@ -103,6 +140,13 @@ public InstructionalButton(List<Control> gamepadControls, List<Control> keyboard
PadCheck = PadCheck.Any;
}

public InstructionalButton(InputGroup control, string text, PadCheck padFilter = PadCheck.Any)
{
InputButton = control;
Text = text;
PadCheck = padFilter;
}

/// <summary>
/// Bind this button to an item, so it's only shown when that item is selected.
/// </summary>
Expand Down Expand Up @@ -139,6 +183,8 @@ public string GetButtonId()
}
return retVal;
}
else if(InputButton != InputGroup.UNUSED) return $"~{InputButton}~";

return IsUsingController ? API.GetControlInstructionalButton(2, (int)GamepadButton, 1) : API.GetControlInstructionalButton(2, (int)KeyboardButton, 1);
}

Expand Down Expand Up @@ -235,6 +281,20 @@ public void RemoveInstructionalButton(InstructionalButton button)
_changed = true;
}

/// <summary>
/// Removes a List of <see cref="InstructionalButton"/>
/// </summary>
/// <param name="buttons">The List of <see cref="InstructionalButton"/> to remove.</param>
public void RemoveInstructionalButtons(List<InstructionalButton> buttons)
{
foreach (var button in buttons)
{
if(ControlButtons.Contains(button))
ControlButtons.Remove(button);
}
_changed = true;
}

/// <summary>
/// Removes an <see cref="InstructionalButton"/>
/// </summary>
Expand All @@ -245,6 +305,17 @@ public void RemoveInstructionalButton(int button)
_changed = true;
}

/// <summary>
/// Clears all the buttons
/// </summary>
/// <param name="button">The index to remove.</param>
public void ClearButtonList()
{
ControlButtons.Clear();
_changed = true;
}


/// <summary>
/// Shows the Saving / Loading Button
/// </summary>
Expand All @@ -265,10 +336,11 @@ public async void AddSavingText(LoadingSpinnerType spinnerType, string text, int
internal void UpdateButtons()
{
if (!_changed) return;
_sc.CallFunction("SET_DATA_SLOT_EMPTY");
_sc.CallFunction("TOGGLE_MOUSE_BUTTONS", _useMouseButtons);
int count = 0;

foreach (InstructionalButton button in ControlButtons)
foreach (InstructionalButton button in ControlButtons.ToList())
{
if (button.IsUsingController)
{
Expand Down Expand Up @@ -340,7 +412,7 @@ internal void HandleScaleform()

if (!PopupWarningThread.Warning.IsShowing) Draw();

foreach (InstructionalButton button in ControlButtons)
foreach (InstructionalButton button in ControlButtons.Where(x => x.InputButton == null))
{
if (IsControlJustPressed(button.GamepadButton, button.PadCheck) || (button.GamepadButtons != null && button.GamepadButtons.Any(x => IsControlJustPressed(x, button.PadCheck))))
button.InvokeEvent(button.GamepadButton);
Expand Down
63 changes: 45 additions & 18 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 @@ -1313,9 +1330,9 @@ private float CalculateItemHeight()
/// </summary>
private float CalculatePanelsPosition(bool hasDescription)
{
float Height = CalculateWindowHeight() + 126 + _mainMenu.Position.Y;
float Height = CalculateWindowHeight() + 40 + _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 e1ca149

Please sign in to comment.