This repository has been archived by the owner on Feb 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
CustomiFruit.cs
282 lines (247 loc) · 10 KB
/
CustomiFruit.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
using System.Drawing;
using GTA;
using GTA.Native;
namespace iFruitAddon2
{
//public delegate void ContactSelectedEvent(iFruitContactCollection sender, iFruitContact selectedItem);
public delegate void ContactAnsweredEvent(iFruitContact contact);
public class CustomiFruit
{
private static CustomiFruit _instance;
private bool _shouldDraw = true;
private PhoneImage _wallpaper;
private iFruitContactCollection _contacts;
private int _mScriptHash;
private int _timerClose = -1;
/// <summary>
/// Left Button Color
/// </summary>
public Color LeftButtonColor { get; set; } = Color.Empty;
/// <summary>
/// Center Button Color
/// </summary>
public Color CenterButtonColor { get; set; } = Color.Empty;
/// <summary>
/// Right Button Color
/// </summary>
public Color RightButtonColor { get; set; } = Color.Empty;
/// <summary>
/// Left Button Icon
/// </summary>
public SoftKeyIcon LeftButtonIcon { get; set; } = SoftKeyIcon.Blank;
/// <summary>
/// Center Button Icon
/// </summary>
public SoftKeyIcon CenterButtonIcon { get; set; } = SoftKeyIcon.Blank;
/// <summary>
/// Right Button Icon
/// </summary>
public SoftKeyIcon RightButtonIcon { get; set; } = SoftKeyIcon.Blank;
/// <summary>
/// List of custom contacts in the phone
/// </summary>
public iFruitContactCollection Contacts
{
get { return _contacts; }
set { _contacts = value; }
}
public CustomiFruit() : this(new iFruitContactCollection())
{ }
/// <summary>
/// Initialize the class.
/// </summary>
/// <param name="contacts"></param>
public CustomiFruit(iFruitContactCollection contacts)
{
_instance = this;
_contacts = contacts;
_mScriptHash = Game.GenerateHash("cellphone_flashhand");
}
/// <summary>
/// Handle of the current scaleform.
/// </summary>
public static CustomiFruit GetCurrentInstance() { return _instance; }
public int Handle
{
get
{
int h = 0;
switch ((uint)Game.Player.Character.Model.Hash)
{
case (uint)PedHash.Michael:
h = Function.Call<int>(Hash.REQUEST_SCALEFORM_MOVIE, "cellphone_ifruit");
while (!Function.Call<bool>(Hash.HAS_SCALEFORM_MOVIE_LOADED, h))
Script.Yield();
return h;
case (uint)PedHash.Franklin:
h = Function.Call<int>(Hash.REQUEST_SCALEFORM_MOVIE, "cellphone_badger");
while (!Function.Call<bool>(Hash.HAS_SCALEFORM_MOVIE_LOADED, h))
Script.Yield();
return h;
case (uint)PedHash.Trevor:
h = Function.Call<int>(Hash.REQUEST_SCALEFORM_MOVIE, "cellphone_facade");
while (!Function.Call<bool>(Hash.HAS_SCALEFORM_MOVIE_LOADED, h))
Script.Yield();
return h;
default:
h = Function.Call<int>(Hash.REQUEST_SCALEFORM_MOVIE, "cellphone_ifruit");
while (!Function.Call<bool>(Hash.HAS_SCALEFORM_MOVIE_LOADED, h))
Script.Yield();
return h;
}
}
}
/// <summary>
/// Set text displayed at the top of the phone interface. Must be called every update!
/// </summary>
/// <param name="text"></param>
public void SetTextHeader(string text)
{
Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION, Handle, "SET_HEADER");
Function.Call(Hash._BEGIN_TEXT_COMPONENT, "STRING");
Function.Call(Hash._0x761B77454205A61D, text, -1);
Function.Call(Hash._END_TEXT_COMPONENT);
Function.Call(Hash._POP_SCALEFORM_MOVIE_FUNCTION_VOID);
}
/// <summary>
/// Set icon of the soft key buttons directly.
/// </summary>
/// <param name="buttonID">The button index</param>
/// <param name="icon">Supplied icon</param>
public void SetSoftKeyIcon(int buttonID, SoftKeyIcon icon)
{
Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION, Handle, "SET_SOFT_KEYS");
Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_INT, buttonID);
Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_BOOL, true);
Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_INT, (int)icon);
Function.Call(Hash._POP_SCALEFORM_MOVIE_FUNCTION_VOID);
}
/// <summary>
/// Set the color of the soft key buttons directly.
/// </summary>
/// <param name="buttonID">The button index</param>
/// <param name="color">Supplied color</param>
public void SetSoftKeyColor(int buttonID, Color color)
{
Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION, Handle, "SET_SOFT_KEYS_COLOUR");
Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_INT, buttonID);
Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_INT, color.R);
Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_INT, color.G);
Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_INT, color.B);
Function.Call(Hash._POP_SCALEFORM_MOVIE_FUNCTION_VOID);
}
internal void SetWallpaperTXD(string textureDict)
{
Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION, Handle, "SET_BACKGROUND_CREW_IMAGE");
Function.Call(Hash._BEGIN_TEXT_COMPONENT, "CELL_2000");
Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, textureDict);
Function.Call(Hash._END_TEXT_COMPONENT);
Function.Call(Hash._POP_SCALEFORM_MOVIE_FUNCTION_VOID);
}
/// <summary>
/// Set the wallpaper of the phone.
/// </summary>
/// <param name="wallpaper"></param>
public void SetWallpaper(Wallpaper wallpaper)
{
_wallpaper = wallpaper;
}
public void SetWallpaper(ContactIcon icon)
{
_wallpaper = icon;
}
public void SetWallpaper(string textureDict)
{
_wallpaper = new Wallpaper(textureDict);
}
public void Update()
{
if (Function.Call<int>(Hash._GET_NUMBER_OF_INSTANCES_OF_STREAMED_SCRIPT, _mScriptHash) > 0)
{
if (_shouldDraw)
{
//Script.Wait(0);
if (LeftButtonColor != Color.Empty)
SetSoftKeyColor(1, LeftButtonColor);
if (CenterButtonColor != Color.Empty)
SetSoftKeyColor(2, CenterButtonColor);
if (RightButtonColor != Color.Empty)
SetSoftKeyColor(3, RightButtonColor);
//Script.Wait(0);
if (LeftButtonIcon != SoftKeyIcon.Blank)
SetSoftKeyIcon(1, LeftButtonIcon);
if (CenterButtonIcon != SoftKeyIcon.Blank)
SetSoftKeyIcon(2, CenterButtonIcon);
if (RightButtonIcon != SoftKeyIcon.Blank)
SetSoftKeyIcon(3, RightButtonIcon);
if (_wallpaper != null)
SetWallpaperTXD(_wallpaper.Name);
_shouldDraw = !_shouldDraw;
}
}
else
{
_shouldDraw = true;
}
if (_timerClose != -1)
{
if (_timerClose <= Game.GameTime)
{
Close();
_timerClose = -1;
}
}
_contacts.Update(Handle);
}
/// <summary>
/// Closes the phone.
/// </summary>
/// <param name="timer">Thread safe timer waiting before closing the phone. Time in ms.</param>
public void Close(int timer = 0)
{
if (timer == 0)
Close();
else
_timerClose = Game.GameTime + timer;
}
private void Close()
{
if (Function.Call<int>(Hash._GET_NUMBER_OF_INSTANCES_OF_STREAMED_SCRIPT, _mScriptHash) > 0)
{
Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION, Handle, "SHUTDOWN_MOVIE");
Function.Call(Hash._POP_SCALEFORM_MOVIE_FUNCTION_VOID);
Script.Yield();
//Function.Call(Hash.SET_SCALEFORM_MOVIE_AS_NO_LONGER_NEEDED, CustomiFruit.GetCurrentInstance().Handle);
Tools.Scripts.DestroyPhone(Handle);
Tools.Scripts.TerminateScript("cellphone_flashhand");
Tools.Scripts.TerminateScript("cellphone_controller");
Script.Yield();
Tools.Scripts.StartScript("cellphone_flashhand", 1424);
Tools.Scripts.StartScript("cellphone_controller", 1424);
}
}
}
public enum SoftKeyIcon
{
Blank = 1,
Select = 2,
Pages = 3,
Back = 4,
Call = 5,
Hangup = 6,
HangupHuman = 7,
Week = 8,
Keypad = 9,
Open = 10,
Reply = 11,
Delete = 12,
Yes = 13,
No = 14,
Sort = 15,
Website = 16,
Police = 17,
Ambulance = 18,
Fire = 19,
Pages2 = 20
}
}