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