Skip to content

Commit

Permalink
Merge pull request #23 from manups4e/master
Browse files Browse the repository at this point in the history
New update
  • Loading branch information
manups4e authored Nov 22, 2020
2 parents 5cc13ef + 6da32e2 commit 9c66d8a
Show file tree
Hide file tree
Showing 22 changed files with 297 additions and 162 deletions.
76 changes: 76 additions & 0 deletions MenuExample/MenuExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using CitizenFX.Core;
using CitizenFX.Core.UI;
using NativeUI;
using NativeUI.PauseMenu;
using CitizenFX.Core.Native;

public class MenuExample : BaseScript
{
Expand Down Expand Up @@ -168,6 +170,14 @@ public void AddMenuCook(UIMenu menu)
menu.AddItem(listPanelItem4);
listPanelItem4.AddPanel(statistics);

UIMenuItem PauseMenu = new UIMenuItem("Open custom pauseMenu");
menu.AddItem(PauseMenu);
PauseMenu.Activated += (_submenu, item) =>
{
_menuPool.CloseAllMenus();
OpenCustomPauseMenu();
};

// THERE ARE NO EVENTS FOR PANELS.. WHEN YOU CHANGE WHAT IS CHANGABLE THE LISTITEM WILL DO WHATEVER YOU TELL HIM TO DO

menu.OnListChange += (sender, item, index) =>
Expand Down Expand Up @@ -215,4 +225,70 @@ public MenuExample()
mainMenu.Visible = !mainMenu.Visible;
};
}

public async void OpenCustomPauseMenu()
{
TabView MenuContainer = new TabView("This is the title");
_menuPool.AddPauseMenu(MenuContainer);

int mugshot = API.RegisterPedheadshot(API.PlayerPedId());
while (!API.IsPedheadshotReady(mugshot)) await BaseScript.Delay(1);
string Txd = API.GetPedheadshotTxdString(mugshot);

MenuContainer.Photo = new NativeUI.Sprite(Txd, Txd, PointF.Empty, SizeF.Empty); // Position and size can be empty.. they'll be handled by the TabView
//this will add our player smugshot to the pause menu
MenuContainer.Money = "1000"; // if money and moneySubtitle are empty or not used, the current datetime will be printed
MenuContainer.MoneySubtitle = "Bank = 10";

TabItem Item1 = new TabItem("simple TabItem");

TabTextItem Item2 = new TabTextItem("TabTextItem", "This is the Title inside", "With a cool text to be added where you can write whatever you want");

TabItemSimpleList Item3 = new TabItemSimpleList("TabItemSimpleList", new Dictionary<string, string>()
{
["Item 1"] = "subItem 1",
["Item 2"] = "subItem 2",
["Item 3"] = "subItem 3",
["Item 4"] = "subItem 4",
["Item 5"] = "subItem 5",
["Item 6"] = "subItem 6"
});


List<UIMenuItem> items = new List<UIMenuItem>()
{
new UIMenuItem("Item 1"),
new UIMenuCheckboxItem("Item 2", true),
new UIMenuListItem("Item 3", new List<dynamic>(){"Item1", 2, 3.0999 }, 0)
};

TabInteractiveListItem Item4 = new TabInteractiveListItem("TabInteractiveListItem", items);

TabSubmenuItem Item5 = new TabSubmenuItem("TabSubmenuItem", new List<TabItem>()
{
new TabItem("simple TabItem"),
new TabTextItem("TabTextItem", "This is the Title inside", "With a cool text to be added where you can write whatever you want"),
new TabItemSimpleList("TabItemSimpleList", new Dictionary<string, string>()
{
["Item 1"] = "subItem 1",
["Item 2"] = "subItem 2",
["Item 3"] = "subItem 3",
["Item 4"] = "subItem 4",
["Item 5"] = "subItem 5",
["Item 6"] = "subItem 6"
}),
new TabInteractiveListItem("TabInteractiveListItem", items)
});
MenuContainer.AddTab(Item1);
MenuContainer.AddTab(Item2);
MenuContainer.AddTab(Item3);
MenuContainer.AddTab(Item4);
MenuContainer.AddTab(Item5);
// this way we can choose which tab is the defualt one
Item1.Active = true;
Item1.Focused = true;
Item1.Visible = true;
MenuContainer.Visible = true;
// items have events exaclty the same as UIMenuItems and you can handle TabInteractiveListItem items just like that
}
}
2 changes: 1 addition & 1 deletion MenuExample/MenuExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="CitizenFX.Core.Client, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\CitizenFX.Core.Client.1.0.2207\lib\net45\CitizenFX.Core.Client.dll</HintPath>
<HintPath>..\packages\CitizenFX.Core.Client.1.0.3218\lib\net45\CitizenFX.Core.Client.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
2 changes: 1 addition & 1 deletion MenuExample/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CitizenFX.Core.Client" version="1.0.2207" targetFramework="net452" />
<package id="CitizenFX.Core.Client" version="1.0.3218" targetFramework="net452" />
</packages>
2 changes: 1 addition & 1 deletion NativeUI/Items/UIMenuItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class UIMenuItem
protected Sprite _badgeRight;

protected UIResText _labelText;

protected SizeF Resolution = ScreenTools.ResolutionMaintainRatio;
public Color MainColor { get; set; }
public Color HighlightColor { get; set; }

Expand Down
3 changes: 1 addition & 2 deletions NativeUI/Items/UIMenuProgressItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ public async void Functions()
while (API.IsDisabledControlPressed(0, 24) && ScreenTools.IsMouseInBounds(new PointF(_bar.Position.X, _bar.Position.Y - 7.5f), new SizeF(_max, _bar.Size.Height + 19)))
{
await BaseScript.Delay(0);
var ress = ScreenTools.ResolutionMaintainRatio;
float CursorX = API.GetDisabledControlNormal(0, 239) * ress.Width;
float CursorX = API.GetDisabledControlNormal(0, 239) * Resolution.Width;
CalculateProgress(CursorX);
Parent.ProgressChange(this, _index);
ProgressChanged(Parent, this, _index);
Expand Down
90 changes: 73 additions & 17 deletions NativeUI/Items/UIMenuSliderProgressItem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using CitizenFX.Core;
using CitizenFX.Core.Native;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
Expand All @@ -7,11 +9,12 @@

namespace NativeUI
{
public class UIMenuSliderProgressItem : UIMenuItem
public class UIMenuSliderProgressItem : UIMenuItem
{
protected Sprite _arrowLeft;
protected Sprite _arrowRight;

protected bool Pressed;
protected UIMenuGridAudio Audio;
protected UIResRectangle _rectangleBackground;
protected UIResRectangle _rectangleSlider;
protected UIResRectangle _rectangleDivider;
Expand All @@ -26,7 +29,7 @@ public UIMenuSliderProgressItem(string text, int maxCount, int startIndex, bool
_value = startIndex;
}

public UIMenuSliderProgressItem(string text, int maxCount, int startIndex, string description, bool divider = false) : this (text, maxCount, startIndex, description, Color.FromArgb(255, 57, 119, 200), Color.FromArgb(255, 4, 32, 57), divider)
public UIMenuSliderProgressItem(string text, int maxCount, int startIndex, string description, bool divider = false) : this(text, maxCount, startIndex, description, Color.FromArgb(255, 57, 119, 200), Color.FromArgb(255, 4, 32, 57), divider)
{
_max = maxCount;
_value = startIndex;
Expand All @@ -40,13 +43,13 @@ public UIMenuSliderProgressItem(string text, int maxCount, int startIndex, strin
_arrowRight = new Sprite("commonmenu", "arrowright", new PointF(0, 105), new SizeF(25, 25));
_rectangleBackground = new UIResRectangle(new PointF(0, 0), new SizeF(150, 10), backgroundSliderColor);
_rectangleSlider = new UIResRectangle(new PointF(0, 0), new SizeF(75, 10), sliderColor);
_value = startIndex;
if (divider)
_rectangleDivider = new UIResRectangle(new Point(0, 0), new Size(2, 20), Colors.WhiteSmoke);
else
_rectangleDivider = new UIResRectangle(new Point(0, 0), new Size(2, 20), Color.Transparent);
float offset = _rectangleBackground.Size.Width / _max * _value;
_rectangleSlider.Size = new SizeF(offset, _rectangleSlider.Size.Height);
Audio = new UIMenuGridAudio("CONTINUOUS_SLIDER", "HUD_FRONTEND_DEFAULT_SOUNDSET", 0);
}

public override void Position(int y)
Expand Down Expand Up @@ -79,16 +82,77 @@ public int Value
}
}

public int Multiplier
{
get
{
return _multiplier;
}
set
{
_multiplier = value;
}
}

/// <summary>
/// Triggered when the slider is changed.
/// </summary>
public event ItemSliderProgressEvent OnSliderChanged;

internal virtual void SliderProgressChanged()
protected virtual void SliderProgressChanged()
{
OnSliderChanged?.Invoke(this, Value);
Parent.SliderProgressChange(this, Value);
}

public async void Functions()
{
if (ScreenTools.IsMouseInBounds(new PointF(_rectangleBackground.Position.X, _rectangleBackground.Position.Y), new SizeF(150f, _rectangleBackground.Size.Height)))
{
if (API.IsDisabledControlPressed(0, 24))
{
if (!Pressed)
{
Pressed = true;
Audio.Id = API.GetSoundId();
API.PlaySoundFrontend(Audio.Id, Audio.Slider, Audio.Library, true);
}
await BaseScript.Delay(0);
float CursorX = API.GetDisabledControlNormal(0, 239) * Resolution.Width;
var Progress = CursorX - _rectangleSlider.Position.X;
Value = (int)Math.Round(_max * ((Progress >= 0f && Progress <= 150f) ? Progress : (Progress < 0) ? 0 : 150f) / 150f);
SliderProgressChanged();
}
else
{
API.StopSound(Audio.Id);
API.ReleaseSoundId(Audio.Id);
Pressed = false;
}
}
else if (ScreenTools.IsMouseInBounds(_arrowLeft.Position, _arrowLeft.Size))
{
if (API.IsDisabledControlPressed(0, 24))
{
Value -= Multiplier;
SliderProgressChanged();
}
}
else if (ScreenTools.IsMouseInBounds(_arrowRight.Position, _arrowRight.Size))
{
if (API.IsDisabledControlPressed(0, 24))
{
Value += Multiplier;
SliderProgressChanged();
}
}
else
{
API.StopSound(Audio.Id);
API.ReleaseSoundId(Audio.Id);
Pressed = false;
}
}

/// <summary>
/// Draw item.
Expand All @@ -98,20 +162,12 @@ public override async Task Draw()
base.Draw();
_arrowLeft.Color = Enabled ? Selected ? Colors.Black : Colors.WhiteSmoke : Color.FromArgb(163, 159, 148);
_arrowRight.Color = Enabled ? Selected ? Colors.Black : Colors.WhiteSmoke : Color.FromArgb(163, 159, 148);
if (Selected)
{
_arrowLeft.Draw();
_arrowRight.Draw();
}
else
{

}
_arrowLeft.Draw();
_arrowRight.Draw();
_rectangleBackground.Draw();
_rectangleSlider.Draw();
_rectangleDivider.Draw();
Functions();
}


}
}
16 changes: 14 additions & 2 deletions NativeUI/MenuPool.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using NativeUI.PauseMenu;
using Control = CitizenFX.Core.Control;

namespace NativeUI
Expand Down Expand Up @@ -39,7 +40,7 @@ public class MenuPool
public bool OffsetInheritance = true;

private readonly List<UIMenu> _menuList = new List<UIMenu>();

private readonly List<TabView> _pauseMenus = new List<TabView>();

/// <summary>
/// Add your menu to the menu pool.
Expand All @@ -50,6 +51,15 @@ public void Add(UIMenu menu)
_menuList.Add(menu);
}

/// <summary>
/// Add your pause menu to the menu pool.
/// </summary>
/// <param name="menu"></param>
public void AddPauseMenu(TabView menu)
{
_pauseMenus.Add(menu);
}

/// <summary>
/// Create and add a submenu to the menu pool.
/// Adds an item with the given text to the menu, creates a corresponding submenu, and binds the submenu to the item.
Expand Down Expand Up @@ -224,7 +234,7 @@ public void Draw()
/// <returns>true if at least one menu is visible, false if not.</returns>
public bool IsAnyMenuOpen()
{
return _menuList.Any(menu => menu.Visible);
return _menuList.Any(menu => menu.Visible) || _pauseMenus.Any(x => x.Visible);
}


Expand All @@ -234,6 +244,8 @@ public bool IsAnyMenuOpen()
public void ProcessMenus()
{
ProcessControl();
if (_pauseMenus.Count > 0)
_pauseMenus.ForEach(x => { x.ProcessControls(); x.Draw(); });
ProcessMouse();
Draw();
}
Expand Down
2 changes: 1 addition & 1 deletion NativeUI/NativeUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="CitizenFX.Core.Client, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\CitizenFX.Core.Client.1.0.2207\lib\net45\CitizenFX.Core.Client.dll</HintPath>
<HintPath>..\packages\CitizenFX.Core.Client.1.0.3218\lib\net45\CitizenFX.Core.Client.dll</HintPath>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Xml.Linq" />
Expand Down
Loading

0 comments on commit 9c66d8a

Please sign in to comment.