Skip to content

Commit 6050ae6

Browse files
committed
New options for setting wallpaper and contact icons. Updated to 2.1
Fixed an issue where the contact icons were not appearing. Added wallpaper and contact icon manipulation options. Exposed some more methods for the user and hid some other ones that were left by mistake. Various fixes and code changes
1 parent 3a29b79 commit 6050ae6

File tree

10 files changed

+421
-85
lines changed

10 files changed

+421
-85
lines changed

CustomiFruit.cs

Lines changed: 134 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,41 @@
44

55
namespace iFruitAddon
66
{
7+
public delegate void ContactSelectedEvent(iFruitContactCollection sender, iFruitContact selectedItem);
8+
9+
public delegate void ContactAnsweredEvent(iFruitContact contact);
10+
711
public class CustomiFruit
812
{
913
/// <summary>
10-
/// Keypad Button Color
14+
/// Left Button Color
15+
/// </summary>
16+
public Color LeftButtonColor { get; set; } = Color.Empty;
17+
18+
/// <summary>
19+
/// Center Button Color
20+
/// </summary>
21+
public Color CenterButtonColor { get; set; } = Color.Empty;
22+
23+
/// <summary>
24+
/// Right Button Color
1125
/// </summary>
12-
public Color KeypadButtonColor { get; set; } = Color.Empty;
26+
public Color RightButtonColor { get; set; } = Color.Empty;
1327

1428
/// <summary>
15-
/// Select Button Color
29+
/// Left Button Icon
1630
/// </summary>
17-
public Color SelectButtonColor { get; set; } = Color.Empty;
31+
public SoftKeyIcon LeftButtonIcon { get; set; } = SoftKeyIcon.Blank;
1832

1933
/// <summary>
20-
/// Return Button Color
34+
/// Center Button Icon
2135
/// </summary>
22-
public Color ReturnButtonColor { get; set; } = Color.Empty;
36+
public SoftKeyIcon CenterButtonIcon { get; set; } = SoftKeyIcon.Blank;
2337

2438
/// <summary>
25-
/// Header text shown in phone UI
39+
/// Right Button Icon
2640
/// </summary>
27-
public string HeaderText { get; set; } = string.Empty;
41+
public SoftKeyIcon RightButtonIcon { get; set; } = SoftKeyIcon.Blank;
2842

2943
/// <summary>
3044
/// List of custom contacts in the phone
@@ -35,6 +49,22 @@ public iFruitContactCollection Contacts
3549
set { _contacts = value; }
3650
}
3751

52+
public CustomiFruit() : this(new iFruitContactCollection())
53+
{ }
54+
55+
/// <summary>
56+
/// Initialize the class.
57+
/// </summary>
58+
/// <param name="contacts"></param>
59+
public CustomiFruit(iFruitContactCollection contacts)
60+
{
61+
_contacts = contacts;
62+
_mHash = Function.Call<int>(Hash.GET_HASH_KEY, "cellphone_flashhand");
63+
}
64+
65+
/// <summary>
66+
/// Handle of the current scaleform.
67+
/// </summary>
3868
public int Handle
3969
{
4070
get
@@ -53,36 +83,74 @@ public int Handle
5383
}
5484
}
5585

56-
public CustomiFruit() : this(new iFruitContactCollection())
57-
{ }
86+
/// <summary>
87+
/// Set text displayed at the top of the phone interface. Must be called every update!
88+
/// </summary>
89+
/// <param name="text"></param>
90+
public void SetTextHeader(string text)
91+
{
92+
Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION, Handle, "SET_HEADER");
93+
Function.Call(Hash._BEGIN_TEXT_COMPONENT, "STRING");
94+
Function.Call(Hash._0x761B77454205A61D, text, -1);
95+
Function.Call(Hash._END_TEXT_COMPONENT);
96+
Function.Call(Hash._POP_SCALEFORM_MOVIE_FUNCTION_VOID);
97+
}
5898

59-
public CustomiFruit(iFruitContactCollection contacts)
99+
/// <summary>
100+
/// Set icon of the soft key buttons directly.
101+
/// </summary>
102+
/// <param name="buttonID">The button index</param>
103+
/// <param name="icon">Supplied icon</param>
104+
public void SetSoftKeyIcon(int buttonID, SoftKeyIcon icon)
60105
{
61-
_contacts = contacts;
62-
_mHash = Function.Call<int>(Hash.GET_HASH_KEY, "cellphone_flashhand");
106+
Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION, Handle, "SET_SOFT_KEYS");
107+
Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_INT, buttonID);
108+
Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_BOOL, true);
109+
Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_INT, (int)icon);
110+
Function.Call(Hash._POP_SCALEFORM_MOVIE_FUNCTION_VOID);
63111
}
64112

65-
private void SetSoftKeyColor(int key, Color color)
113+
/// <summary>
114+
/// Set the color of the soft key buttons directly.
115+
/// </summary>
116+
/// <param name="buttonID">The button index</param>
117+
/// <param name="color">Supplied color</param>
118+
public void SetSoftKeyColor(int buttonID, Color color)
66119
{
67120
Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION, Handle, "SET_SOFT_KEYS_COLOUR");
68-
Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_INT, key);
121+
Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_INT, buttonID);
69122
Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_INT, color.R);
70123
Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_INT, color.G);
71124
Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_INT, color.B);
72-
Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION_PARAMETER_INT, -1);
73125
Function.Call(Hash._POP_SCALEFORM_MOVIE_FUNCTION_VOID);
74126
}
75127

76-
private void SetHeaderString(string text)
128+
private void SetWallpaperTXD(string textureDict)
77129
{
78-
Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION, Handle, "SET_HEADER");
79-
Function.Call(Hash._BEGIN_TEXT_COMPONENT, "STRING");
80-
Function.Call(Hash._0x761B77454205A61D, text, -1);
130+
Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION, Handle, "SET_BACKGROUND_CREW_IMAGE");
131+
Function.Call(Hash._BEGIN_TEXT_COMPONENT, "CELL_2000");
132+
Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, textureDict);
81133
Function.Call(Hash._END_TEXT_COMPONENT);
82134
Function.Call(Hash._POP_SCALEFORM_MOVIE_FUNCTION_VOID);
83135
}
84136

85-
private bool _shouldDraw = true;
137+
public void SetWallpaper(Wallpaper wallpaper)
138+
{
139+
_wallpaper = wallpaper;
140+
}
141+
142+
public void SetWallpaper(ContactIcon icon)
143+
{
144+
_wallpaper = icon;
145+
}
146+
147+
public void SetWallpaper(string textureDict)
148+
{
149+
_wallpaper = new Wallpaper(textureDict);
150+
}
151+
152+
private bool _shouldDraw = true;
153+
private PhoneImage _wallpaper;
86154
private iFruitContactCollection _contacts;
87155
private int _mHash;
88156

@@ -92,19 +160,29 @@ public void Update()
92160
{
93161
if (_shouldDraw)
94162
{
95-
Script.Wait(10);
96-
if (KeypadButtonColor != Color.Empty)
97-
SetSoftKeyColor(1, KeypadButtonColor);
98-
if (SelectButtonColor != Color.Empty)
99-
SetSoftKeyColor(2, SelectButtonColor);
100-
if (ReturnButtonColor != Color.Empty)
101-
SetSoftKeyColor(3, ReturnButtonColor);
163+
Script.Wait(0);
102164

103-
_shouldDraw = !_shouldDraw;
104-
}
165+
if (LeftButtonColor != Color.Empty)
166+
SetSoftKeyColor(1, LeftButtonColor);
167+
if (CenterButtonColor != Color.Empty)
168+
SetSoftKeyColor(2, CenterButtonColor);
169+
if (RightButtonColor != Color.Empty)
170+
SetSoftKeyColor(3, RightButtonColor);
105171

106-
if (HeaderText != string.Empty)
107-
SetHeaderString(HeaderText);
172+
Script.Wait(0);
173+
174+
if (LeftButtonIcon != SoftKeyIcon.Blank)
175+
SetSoftKeyIcon(1, LeftButtonIcon);
176+
if (CenterButtonIcon != SoftKeyIcon.Blank)
177+
SetSoftKeyIcon(2, CenterButtonIcon);
178+
if (RightButtonIcon != SoftKeyIcon.Blank)
179+
SetSoftKeyIcon(3, RightButtonIcon);
180+
181+
if (_wallpaper != null)
182+
SetWallpaperTXD(_wallpaper.Name);
183+
184+
_shouldDraw = !_shouldDraw;
185+
}
108186
}
109187

110188
else
@@ -115,4 +193,28 @@ public void Update()
115193
_contacts.Update(Handle);
116194
}
117195
}
196+
197+
public enum SoftKeyIcon
198+
{
199+
Blank = 1,
200+
Select = 2,
201+
Pages = 3,
202+
Back = 4,
203+
Call = 5,
204+
Hangup = 6,
205+
HangupHuman = 7,
206+
Week = 8,
207+
Keypad = 9,
208+
Open = 10,
209+
Reply = 11,
210+
Delete = 12,
211+
Yes = 13,
212+
No = 14,
213+
Sort = 15,
214+
Website = 16,
215+
Police = 17,
216+
Ambulance = 18,
217+
Fire = 19,
218+
Pages2 = 20
219+
}
118220
}

ExampleScript.cs

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,49 @@ public class ExampleScript : Script
1212

1313
public ExampleScript()
1414
{
15-
ifruit = new CustomiFruit() {
16-
SelectButtonColor = System.Drawing.Color.Orange,
17-
ReturnButtonColor = System.Drawing.Color.LimeGreen,
18-
KeypadButtonColor = System.Drawing.Color.Purple
15+
ifruit = new CustomiFruit()
16+
{
17+
CenterButtonColor = System.Drawing.Color.Orange,
18+
LeftButtonColor = System.Drawing.Color.LimeGreen,
19+
RightButtonColor = System.Drawing.Color.Purple,
20+
CenterButtonIcon = SoftKeyIcon.Fire,
21+
LeftButtonIcon = SoftKeyIcon.Police,
22+
RightButtonIcon = SoftKeyIcon.Website
1923
};
2024

21-
var contact = new iFruitContact("Spawn Adder", 10);
22-
contact.Selected += (sender, args) => Scripts.SpawnVehicle("ADDER", Game.Player.Character.Position);
25+
ifruit.SetWallpaper(new Wallpaper("char_facebook"));
26+
//or..
27+
ifruit.SetWallpaper(Wallpaper.BadgerDefault);
28+
29+
var contact = new iFruitContact("Spawn Adder", 19);
30+
contact.Answered += Contact_Answered;
31+
contact.DialTimeout = 8000;
32+
33+
//set custom icons by instantiating the ContactIcon class
34+
contact.Icon = new ContactIcon("char_sasquatch");
35+
2336
ifruit.Contacts.Add(contact);
24-
contact = new iFruitContact("Teleport to Waypoint", 11);
25-
contact.Selected += (sender, args) => Scripts.TeleportToWaypoint();
37+
38+
contact = new iFruitContact("Teleport to Waypoint", 20);
39+
contact.Selected += (s, a) => Scripts.TeleportToWaypoint();
40+
contact.DialTimeout = 0;
41+
contact.Icon = ContactIcon.Target;
42+
2643
ifruit.Contacts.Add(contact);
27-
this.Tick += OnTick;
2844

45+
Tick += OnTick;
46+
}
47+
48+
private void Contact_Answered(iFruitContact contact)
49+
{
50+
Scripts.SpawnVehicle("ADDER");
51+
UI.Notify("Your Adder has been delivered!");
2952
}
3053

3154
void OnTick(object sender, EventArgs e)
3255
{
3356
ifruit.Update();
3457
}
35-
3658
}
3759

3860
public static class Scripts
@@ -52,13 +74,11 @@ public static void TeleportToWaypoint()
5274
}
5375
}
5476

55-
public static void SpawnVehicle(string vehiclename, Vector3 pos)
77+
public static void SpawnVehicle(string vehiclename)
5678
{
5779
Model model = new Model(vehiclename);
5880
model.Request(1000);
59-
var veh = Function.Call<Vehicle>((Hash)0xAF35D0D2583051B0, model.Hash, pos.X, pos.Y, pos.Z, Game.Player.Character.Heading, 0, 0);
60-
Function.Call(Hash.SET_PED_INTO_VEHICLE, Game.Player.Character.Handle, veh.Handle, -1);
81+
World.CreateVehicle(model, Game.Player.Character.Position + Game.Player.Character.ForwardVector * 5);
6182
}
6283
}
63-
6484
}

0 commit comments

Comments
 (0)