Skip to content

Commit

Permalink
Merge pull request #29 from manups4e/master
Browse files Browse the repository at this point in the history
Updated Pause Menu (see details)
  • Loading branch information
manups4e authored Nov 26, 2020
2 parents ac20baa + 3593af7 commit 4b6ae0e
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 36 deletions.
14 changes: 5 additions & 9 deletions MenuExample/MenuExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,13 @@ public MenuExample()

public async void OpenCustomPauseMenu()
{
TabView MenuContainer = new TabView("This is the title");
TabView MenuContainer = new TabView("This is the title", "Subtitle");
MenuContainer.SideStringTop = "Player_Name";
MenuContainer.SideStringMiddle = "Middle_String";
MenuContainer.SideStringBottom = "Bottom_string";
MenuContainer.DisplayHeader = true;
_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");

Expand Down
6 changes: 3 additions & 3 deletions NativeUI/PauseMenu/TabItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public virtual void Draw()

if (UseDynamicPositionment)
{
SafeSize = new PointF(300, 240);
SafeSize = new PointF(300, Parent.SubTitle != null && Parent.SubTitle != "" ? 255 : 245);

TopLeft = new PointF(SafeSize.X, SafeSize.Y);
BottomRight = new PointF((int)Resolution.Width - SafeSize.X, (int)Resolution.Height - SafeSize.Y);
Expand All @@ -74,8 +74,8 @@ public virtual void Draw()

for (int i = 0; i < cols * fils; i++)
{
RockstarTile.Position = TopLeft.AddPoints(new PointF(titleSize * (i % cols), titleSize * (i / cols)));
RockstarTile.Color = Color.FromArgb((int)MiscExtensions.LinearFloatLerp(40, 0, i / (int)cols, fils), 255, 255, 255);
RockstarTile.Position = TopLeft.AddPoints(new PointF(titleSize * (i % (int)cols), titleSize * i / (int)cols));
RockstarTile.Color = Color.FromArgb((int)MiscExtensions.LinearFloatLerp(20, 0, i / (int)cols, fils), 255, 255, 255);
RockstarTile.Draw();
}
}
Expand Down
112 changes: 88 additions & 24 deletions NativeUI/PauseMenu/TabView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,23 @@ public class TabView
public TabView(string title)
{
Title = title;
SubTitle = "";
SideStringTop = "";
SideStringMiddle = "";
SideStringBottom = "";
Tabs = new List<TabItem>();
Index = 0;
Name = Game.Player.Name;
TemporarilyHidden = false;
CanLeave = true;
}
public TabView(string title, string subtitle)
{
Title = title;
SubTitle = subtitle;
SideStringTop = "";
SideStringMiddle = "";
SideStringBottom = "";
Tabs = new List<TabItem>();
Index = 0;
Name = Game.Player.Name;
Expand All @@ -21,6 +38,11 @@ public TabView(string title)
}

public string Title { get; set; }
public string SubTitle { get; set; }
public string SideStringTop { get; set; }
public string SideStringMiddle { get; set; }
public string SideStringBottom { get; set; }
public Tuple<string, string> HeaderPicture { internal get; set; }
public Sprite Photo { get; set; }
public string Name { get; set; }
public string Money { get; set; }
Expand All @@ -30,9 +52,10 @@ public TabView(string title)
public bool TemporarilyHidden { get; set; }
public bool CanLeave { get; set; }
public bool HideTabs { get; set; }

public bool DisplayHeader = true;

protected readonly SizeF Resolution = ScreenTools.ResolutionMaintainRatio;

internal bool _loaded;
internal readonly static string _browseTextLocalized = Game.GetGXTEntry("HUD_INPUT1C");

public event EventHandler OnMenuClose;
Expand Down Expand Up @@ -67,6 +90,7 @@ public void AddTab(TabItem item)
private bool _visible;

private Scaleform _sc;
private Scaleform _header;
public void ShowInstructionalButtons()
{
if (_sc == null)
Expand All @@ -86,6 +110,37 @@ public void ShowInstructionalButtons()
_sc.CallFunction("SET_DATA_SLOT", 3, API.GetControlInstructionalButton(2, (int)Control.FrontendLb, 0), _browseTextLocalized);
}

public async void ShowHeader()
{
if (_header == null)
_header = new Scaleform("pause_menu_header");
while (!_header.IsLoaded) await BaseScript.Delay(0);
if (String.IsNullOrEmpty(SubTitle) || String.IsNullOrWhiteSpace(SubTitle))
_header.CallFunction("SET_HEADER_TITLE", Title);
else
{
_header.CallFunction("SET_HEADER_TITLE", Title, false, SubTitle);
_header.CallFunction("SHIFT_CORONA_DESC", true);
}
if (HeaderPicture != null)
_header.CallFunction("SET_CHAR_IMG", HeaderPicture.Item1, HeaderPicture.Item2, true);
else
{
int mugshot = API.RegisterPedheadshot(API.PlayerPedId());
while (!API.IsPedheadshotReady(mugshot)) await BaseScript.Delay(1);
string Txd = API.GetPedheadshotTxdString(mugshot);
HeaderPicture = new Tuple<string, string>(Txd, Txd);
API.ReleasePedheadshotImgUpload(mugshot);
_header.CallFunction("SET_CHAR_IMG", HeaderPicture.Item1, HeaderPicture.Item2, true);
}
_header.CallFunction("SET_HEADING_DETAILS", SideStringTop, SideStringMiddle, SideStringBottom, false);
_header.CallFunction("BUILD_MENU");
_header.CallFunction("adjustHeaderPositions");
_header.CallFunction("SHOW_HEADING_DETAILS", true);
_header.CallFunction("SHOW_MENU", true);
_loaded = true;
}

public void DrawInstructionalButton(int slot, Control control, string text)
{
_sc.CallFunction("SET_DATA_SLOT", slot, API.GetControlInstructionalButton(2, (int)control, 0), text);
Expand All @@ -96,7 +151,7 @@ public void ProcessControls()
if (!Visible || TemporarilyHidden) return;
API.DisableAllControlActions(0);

if (Game.IsControlJustPressed(0, Control.PhoneLeft) && FocusLevel == 0)
if (Game.IsControlJustPressed(2, Control.PhoneLeft) && FocusLevel == 0)
{
Tabs[Index].Active = false;
Tabs[Index].Focused = false;
Expand All @@ -109,7 +164,7 @@ public void ProcessControls()
Game.PlaySound("NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET");
}

else if (Game.IsControlJustPressed(0, Control.PhoneRight) && FocusLevel == 0)
else if (Game.IsControlJustPressed(2, Control.PhoneRight) && FocusLevel == 0)
{
Tabs[Index].Active = false;
Tabs[Index].Focused = false;
Expand All @@ -122,7 +177,7 @@ public void ProcessControls()
Game.PlaySound("NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET");
}

else if (Game.IsControlJustPressed(0, Control.FrontendAccept) && FocusLevel == 0)
else if (Game.IsControlJustPressed(2, Control.FrontendAccept) && FocusLevel == 0)
{
if (Tabs[Index].CanBeFocused)
{
Expand All @@ -140,25 +195,28 @@ public void ProcessControls()

}

else if (Game.IsControlJustPressed(0, Control.PhoneCancel) && FocusLevel == 1)
else if (Game.IsControlJustPressed(2, Control.PhoneCancel))
{
Tabs[Index].Focused = false;
FocusLevel = 0;

Game.PlaySound("BACK", "HUD_FRONTEND_DEFAULT_SOUNDSET");
}

else if (Game.IsControlJustPressed(0, Control.PhoneCancel) && FocusLevel == 0 && CanLeave)
{
Visible = false;
Game.PlaySound("BACK", "HUD_FRONTEND_DEFAULT_SOUNDSET");

OnMenuClose?.Invoke(this, EventArgs.Empty);
if (FocusLevel == 1)
{
Tabs[Index].Focused = false;
FocusLevel = 0;
Game.PlaySound("BACK", "HUD_FRONTEND_DEFAULT_SOUNDSET");
}
else if (FocusLevel == 0 && CanLeave)
{
Visible = false;
Game.PlaySound("BACK", "HUD_FRONTEND_DEFAULT_SOUNDSET");
OnMenuClose?.Invoke(this, EventArgs.Empty);
_loaded = false;
_header.CallFunction("REMOVE_MENU", true);
_header.Dispose();
_header = null;
}
}

if (!HideTabs)
{

if (Game.IsControlJustPressed(0, Control.FrontendLb))
{
Tabs[Index].Active = false;
Expand Down Expand Up @@ -217,9 +275,10 @@ public void Draw()
API.ShowCursorThisFrame();


var safe = new PointF(300, 180);
var safe = new PointF(300, SubTitle != null && SubTitle != ""? 205 : 195);
if (!HideTabs)
{
/*
new UIResText(Title, new PointF(safe.X, safe.Y - 80), 1f, Colors.White, Font.ChaletComprimeCologne, Alignment.Left)
{
Shadow = true,
Expand Down Expand Up @@ -263,12 +322,12 @@ public void Draw()
{
Shadow = true,
}.Draw();

*/
for (int i = 0; i < Tabs.Count; i++)
{
var activeSize = Resolution.Width - 2 * safe.X;
activeSize -= 5;
int tabWidth = (int)activeSize / Tabs.Count;
float tabWidth = ((int)activeSize / Tabs.Count) - 1.95f;
Game.EnableControlThisFrame(0, Control.CursorX);
Game.EnableControlThisFrame(0, Control.CursorY);

Expand All @@ -280,7 +339,7 @@ public void Draw()
if (Tabs[i].Active)
new UIResRectangle(safe.SubtractPoints(new PointF(-((tabWidth + 5) * i), 10)), new SizeF(tabWidth, 10), Colors.DodgerBlue).Draw();

new UIResText(Tabs[i].Title.ToUpper(), safe.AddPoints(new PointF((tabWidth / 2) + (tabWidth + 5) * i, 5)), 0.35f, Tabs[i].Active ? Colors.Black : Colors.White, Font.ChaletLondon, Alignment.Center).Draw();
new UIResText(Tabs[i].Title.ToUpper(), safe.AddPoints(new PointF((tabWidth / 2) + (tabWidth + 5) * i, 5)), 0.3f, Tabs[i].Active ? Colors.Black : Colors.White, Font.ChaletLondon, Alignment.Center).Draw();

if (hovering && Game.IsControlJustPressed(0, Control.CursorAccept) && !Tabs[i].Active)
{
Expand All @@ -305,8 +364,13 @@ public void Draw()
Tabs[Index].Draw();

_sc.CallFunction("DRAW_INSTRUCTIONAL_BUTTONS", -1);

_sc.Render2D();
if (DisplayHeader)
{
if(!_loaded)
ShowHeader();
API.DrawScaleformMovie(_header.Handle, 0.501f, 0.162f, 0.6782f, 0.145f, 255, 255, 255, 255, 0);
}
}
}

Expand Down

0 comments on commit 4b6ae0e

Please sign in to comment.