Skip to content
This repository was archived by the owner on Jan 30, 2024. It is now read-only.

Commit 5caf398

Browse files
committed
Added pause-styled menu.
1 parent 76679be commit 5caf398

8 files changed

Lines changed: 811 additions & 0 deletions

File tree

NativeUI.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@
5151
<ItemGroup>
5252
<Compile Include="InstructionalButton.cs" />
5353
<Compile Include="MenuPool.cs" />
54+
<Compile Include="PauseMenu\TabItem.cs" />
55+
<Compile Include="PauseMenu\TabItemSimpleList.cs" />
56+
<Compile Include="PauseMenu\TabMissionSelectItem.cs" />
57+
<Compile Include="PauseMenu\TabSubmenuItem.cs" />
58+
<Compile Include="PauseMenu\TabTextItem.cs" />
59+
<Compile Include="PauseMenu\TabView.cs" />
60+
<Compile Include="PointExtensions.cs" />
5461
<Compile Include="Properties\AssemblyInfo.cs" />
5562
<Compile Include="Sprite.cs" />
5663
<Compile Include="StringMeasurer.cs" />

PauseMenu/TabItem.cs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using System;
2+
using System.Drawing;
3+
4+
namespace NativeUI.PauseMenu
5+
{
6+
public class TabItem
7+
{
8+
public TabItem(string name)
9+
{
10+
RockstarTile = new Sprite("pause_menu_sp_content", "rockstartilebmp", new Point(), new Size(64, 64), 0f, Color.FromArgb(40, 255, 255, 255));
11+
Title = name;
12+
DrawBg = true;
13+
UseDynamicPositionment = true;
14+
}
15+
16+
public bool Visible { get; set; }
17+
public bool Focused { get; set; }
18+
public string Title { get; set; }
19+
public bool Active { get; set; }
20+
public bool JustOpened { get; set; }
21+
public bool CanBeFocused { get; set; }
22+
public Point TopLeft { get; set; }
23+
public Point BottomRight { get; set; }
24+
public Point SafeSize { get; set; }
25+
public bool UseDynamicPositionment { get; set; }
26+
27+
28+
public event EventHandler Activated;
29+
public bool DrawBg;
30+
public bool FadeInWhenFocused { get; set; }
31+
32+
protected Sprite RockstarTile;
33+
34+
public void OnActivated()
35+
{
36+
Activated?.Invoke(this, EventArgs.Empty);
37+
}
38+
39+
public virtual void Draw()
40+
{
41+
if (!Visible) return;
42+
43+
var res = UIMenu.GetScreenResolutionMantainRatio();
44+
45+
if (UseDynamicPositionment)
46+
{
47+
SafeSize = new Point(300, 240);
48+
49+
TopLeft = new Point(SafeSize.X, SafeSize.Y);
50+
BottomRight = new Point((int)res.Width - SafeSize.X, (int)res.Height - SafeSize.Y);
51+
}
52+
53+
var rectSize = new Size(BottomRight.SubtractPoints(TopLeft));
54+
55+
if (DrawBg)
56+
{
57+
new UIResRectangle(TopLeft, rectSize,
58+
Color.FromArgb((Focused || !FadeInWhenFocused) ? 200 : 120, 0, 0, 0)).Draw();
59+
60+
var tileSize = 100;
61+
RockstarTile.Size = new Size(tileSize, tileSize);
62+
63+
var cols = rectSize.Width / tileSize;
64+
var fils = 4;
65+
66+
for (int i = 0; i < cols * fils; i++)
67+
{
68+
RockstarTile.Position = TopLeft.AddPoints(new Point(tileSize * (i % cols), tileSize * (i / cols)));
69+
RockstarTile.Color = Color.FromArgb((int)MiscExtensions.LinearFloatLerp(40, 0, i / cols, fils), 255, 255, 255);
70+
RockstarTile.Draw();
71+
}
72+
}
73+
}
74+
}
75+
}

PauseMenu/TabItemSimpleList.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System.Collections.Generic;
2+
using System.Drawing;
3+
using System.Linq;
4+
using Font = GTA.Font;
5+
6+
namespace NativeUI.PauseMenu
7+
{
8+
public class TabItemSimpleList : TabItem
9+
{
10+
public TabItemSimpleList(string title, Dictionary<string, string> dict) : base(title)
11+
{
12+
Dictionary = dict;
13+
DrawBg = false;
14+
}
15+
16+
public Dictionary<string, string> Dictionary { get; set; }
17+
18+
public override void Draw()
19+
{
20+
base.Draw();
21+
22+
var res = UIMenu.GetScreenResolutionMantainRatio();
23+
24+
var alpha = (Focused || !CanBeFocused) ? 180 : 60;
25+
var blackAlpha = (Focused || !CanBeFocused) ? 200 : 90;
26+
var fullAlpha = (Focused || !CanBeFocused) ? 255 : 150;
27+
28+
var rectSize = (int)(BottomRight.X - TopLeft.X);
29+
30+
for (int i = 0; i < Dictionary.Count; i++)
31+
{
32+
new UIResRectangle(new Point(TopLeft.X, TopLeft.Y + (40 * i)),
33+
new Size(rectSize, 40), i % 2 == 0 ? Color.FromArgb(alpha, 0, 0, 0) : Color.FromArgb(blackAlpha, 0, 0, 0)).Draw();
34+
35+
var item = Dictionary.ElementAt(i);
36+
37+
new UIResText(item.Key, new Point(TopLeft.X + 6, TopLeft.Y + 5 + (40 * i)), 0.35f, Color.FromArgb(fullAlpha, Color.White)).Draw();
38+
new UIResText(item.Value, new Point(BottomRight.X - 6, TopLeft.Y + 5 + (40 * i)), 0.35f, Color.FromArgb(fullAlpha, Color.White), Font.ChaletLondon, UIResText.Alignment.Right).Draw();
39+
}
40+
}
41+
}
42+
}

PauseMenu/TabMissionSelectItem.cs

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Drawing;
4+
using GTA;
5+
using GTA.Native;
6+
using Font = GTA.Font;
7+
8+
namespace NativeUI.PauseMenu
9+
{
10+
public delegate void OnItemSelect(MissionInformation selectedItem);
11+
12+
public class MissionInformation
13+
{
14+
public MissionInformation(string name, IEnumerable<Tuple<string, string>> info)
15+
{
16+
Name = name;
17+
ValueList = new List<Tuple<string, string>>(info);
18+
}
19+
20+
public MissionInformation(string name, string description, IEnumerable<Tuple<string, string>> info)
21+
{
22+
Name = name;
23+
Description = description;
24+
ValueList = new List<Tuple<string, string>>(info);
25+
}
26+
27+
public string Name { get; set; }
28+
public string Description { get; set; }
29+
public MissionLogo Logo { get; set; }
30+
public List<Tuple<string, string>> ValueList { get; set; }
31+
}
32+
33+
public class MissionLogo
34+
{
35+
/// <summary>
36+
/// Create a logo from an external picture.
37+
/// </summary>
38+
/// <param name="filepath">Path to the picture</param>
39+
public MissionLogo(string filepath)
40+
{
41+
FileName = filepath;
42+
IsGameTexture = false;
43+
}
44+
45+
/// <summary>
46+
/// Create a mission logo from a game texture.
47+
/// </summary>
48+
/// <param name="textureDict">Name of the texture dictionary</param>
49+
/// <param name="textureName">Name of the texture.</param>
50+
public MissionLogo(string textureDict, string textureName)
51+
{
52+
FileName = textureName;
53+
DictionaryName = textureDict;
54+
IsGameTexture = true;
55+
}
56+
57+
internal bool IsGameTexture;
58+
internal string FileName { get; set; }
59+
internal string DictionaryName { get; set; }
60+
}
61+
62+
public class TabMissionSelectItem : TabItem
63+
{
64+
public TabMissionSelectItem(string name, IEnumerable<MissionInformation> list) : base(name)
65+
{
66+
base.FadeInWhenFocused = true;
67+
base.DrawBg = false;
68+
69+
_noLogo = new Sprite("gtav_online", "rockstarlogo256", new Point(), new Size(512, 256));
70+
_maxItem = MaxItemsPerView;
71+
_minItem = 0;
72+
73+
CanBeFocused = true;
74+
75+
Heists = new List<MissionInformation>(list);
76+
}
77+
78+
public event OnItemSelect OnItemSelect;
79+
80+
public List<MissionInformation> Heists { get; set; }
81+
public int Index { get; set; }
82+
83+
protected const int MaxItemsPerView = 15;
84+
protected int _minItem;
85+
protected int _maxItem;
86+
protected Sprite _noLogo { get; set; }
87+
88+
public void ProcessControls()
89+
{
90+
if (!Focused) return;
91+
if (JustOpened)
92+
{
93+
JustOpened = false;
94+
return;
95+
}
96+
97+
if (Game.IsControlJustPressed(0, Control.PhoneSelect))
98+
{
99+
Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1);
100+
OnItemSelect?.Invoke(Heists[Index]);
101+
}
102+
103+
if (Game.IsControlJustPressed(0, Control.FrontendUp) || Game.IsControlJustPressed(0, Control.MoveUpOnly))
104+
{
105+
Index = (1000 - (1000 % Heists.Count) + Index - 1) % Heists.Count;
106+
Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1);
107+
108+
if (Heists.Count <= MaxItemsPerView) return;
109+
110+
if (Index < _minItem)
111+
{
112+
_minItem--;
113+
_maxItem--;
114+
}
115+
116+
if (Index == Heists.Count - 1)
117+
{
118+
_minItem = Heists.Count - MaxItemsPerView;
119+
_maxItem = Heists.Count;
120+
}
121+
}
122+
123+
else if (Game.IsControlJustPressed(0, Control.FrontendDown) || Game.IsControlJustPressed(0, Control.MoveDownOnly))
124+
{
125+
Index = (1000 - (1000 % Heists.Count) + Index + 1) % Heists.Count;
126+
Function.Call(Hash.PLAY_SOUND_FRONTEND, -1, "NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET", 1);
127+
128+
if (Heists.Count <= MaxItemsPerView) return;
129+
130+
if (Index >= _maxItem)
131+
{
132+
_maxItem++;
133+
_minItem++;
134+
}
135+
136+
if (Index == 0)
137+
{
138+
_minItem = 0;
139+
_maxItem = MaxItemsPerView;
140+
}
141+
}
142+
}
143+
144+
public override void Draw()
145+
{
146+
base.Draw();
147+
if (Heists.Count == 0) return;
148+
149+
ProcessControls();
150+
151+
var res = UIMenu.GetScreenResolutionMantainRatio();
152+
153+
var activeWidth = res.Width - SafeSize.X * 2;
154+
var itemSize = new Size((int)activeWidth - 515, 40);
155+
156+
var alpha = Focused ? 120 : 30;
157+
var blackAlpha = Focused ? 200 : 100;
158+
var fullAlpha = Focused ? 255 : 150;
159+
160+
var counter = 0;
161+
for (int i = _minItem; i < Math.Min(Heists.Count, _maxItem); i++)
162+
{
163+
new UIResRectangle(SafeSize.AddPoints(new Point(0, (itemSize.Height + 3) * counter)), itemSize, (Index == i && Focused) ? Color.FromArgb(fullAlpha, Color.White) : Color.FromArgb(blackAlpha, Color.Black)).Draw();
164+
new UIResText(Heists[i].Name, SafeSize.AddPoints(new Point(6, 5 + (itemSize.Height + 3) * counter)), 0.35f, Color.FromArgb(fullAlpha, (Index == i && Focused) ? Color.Black : Color.White)).Draw();
165+
counter++;
166+
}
167+
168+
if (Heists[Index].Logo == null || string.IsNullOrEmpty(Heists[Index].Logo.FileName))
169+
{
170+
_noLogo.Position = new Point((int)res.Width - SafeSize.X - 512, SafeSize.Y);
171+
_noLogo.Color = Color.FromArgb(blackAlpha, 0, 0, 0);
172+
_noLogo.Draw();
173+
}
174+
else if (Heists[Index].Logo != null && Heists[Index].Logo.FileName != null && !Heists[Index].Logo.IsGameTexture)
175+
{
176+
var target = Heists[Index].Logo.FileName;
177+
Sprite.DrawTexture(target, new Point((int)res.Width - SafeSize.X - 512, SafeSize.Y), new Size(512, 256));
178+
}
179+
else if (Heists[Index].Logo != null && Heists[Index].Logo.FileName != null &&
180+
Heists[Index].Logo.IsGameTexture)
181+
{
182+
var newLogo = new Sprite(Heists[Index].Logo.DictionaryName, Heists[Index].Logo.FileName, new Point(), new Size(512, 256));
183+
newLogo.Position = new Point((int)res.Width - SafeSize.X - 512, SafeSize.Y);
184+
newLogo.Color = Color.FromArgb(blackAlpha, 0, 0, 0);
185+
newLogo.Draw();
186+
}
187+
188+
new UIResRectangle(new Point((int)res.Width - SafeSize.X - 512, SafeSize.Y + 256), new Size(512, 40), Color.FromArgb(fullAlpha, Color.Black)).Draw();
189+
new UIResText(Heists[Index].Name, new Point((int)res.Width - SafeSize.X - 4, SafeSize.Y + 260), 0.5f, Color.FromArgb(fullAlpha, Color.White),
190+
Font.HouseScript, UIResText.Alignment.Right).Draw();
191+
192+
for (int i = 0; i < Heists[Index].ValueList.Count; i++)
193+
{
194+
new UIResRectangle(new Point((int)res.Width - SafeSize.X - 512, SafeSize.Y + 256 + 40 + (40 * i)),
195+
new Size(512, 40), i % 2 == 0 ? Color.FromArgb(alpha, 0, 0, 0) : Color.FromArgb(blackAlpha, 0, 0, 0)).Draw();
196+
var text = Heists[Index].ValueList[i].Item1;
197+
var label = Heists[Index].ValueList[i].Item2;
198+
199+
200+
new UIResText(text, new Point((int)res.Width - SafeSize.X - 506, SafeSize.Y + 260 + 42 + (40 * i)), 0.35f, Color.FromArgb(fullAlpha, Color.White)).Draw();
201+
new UIResText(label, new Point((int)res.Width - SafeSize.X - 6, SafeSize.Y + 260 + 42 + (40 * i)), 0.35f, Color.FromArgb(fullAlpha, Color.White), Font.ChaletLondon, UIResText.Alignment.Right).Draw();
202+
}
203+
204+
if (!string.IsNullOrEmpty(Heists[Index].Description))
205+
{
206+
var propLen = Heists[Index].ValueList.Count;
207+
new UIResRectangle(new Point((int) res.Width - SafeSize.X - 512, SafeSize.Y + 256 + 42 + 40*propLen),
208+
new Size(512, 2), Color.FromArgb(fullAlpha, Color.White)).Draw();
209+
new UIResText(Heists[Index].Description,
210+
new Point((int) res.Width - SafeSize.X - 508, SafeSize.Y + 256 + 45 + 40*propLen + 4), 0.35f,
211+
Color.FromArgb(fullAlpha, Color.White))
212+
{
213+
WordWrap = new Size(508, 0),
214+
}.Draw();
215+
216+
new UIResRectangle(new Point((int) res.Width - SafeSize.X - 512, SafeSize.Y + 256 + 44 + 40*propLen),
217+
new Size(512, 45*(StringMeasurer.MeasureString(Heists[Index].Description)/500)),
218+
Color.FromArgb(blackAlpha, 0, 0, 0)).Draw();
219+
}
220+
}
221+
}
222+
}

0 commit comments

Comments
 (0)