From f4aedc659d9b59d3cca914af19028fd4afa87890 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Jul 2022 17:17:47 -0400 Subject: [PATCH 01/50] Added basic Phone Contact class --- LemonUI/Phone/PhoneContact.cs | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 LemonUI/Phone/PhoneContact.cs diff --git a/LemonUI/Phone/PhoneContact.cs b/LemonUI/Phone/PhoneContact.cs new file mode 100644 index 00000000..71305b2b --- /dev/null +++ b/LemonUI/Phone/PhoneContact.cs @@ -0,0 +1,36 @@ +#if SHVDN3 +using System; + +namespace LemonUI.Phone +{ + /// + /// A phone contact. + /// + public class PhoneContact + { + #region Events + + /// + /// Event triggered when the contact is called. + /// + public event EventHandler Called; + /// + /// Event triggered when the call is answered by the player. + /// + /// + /// This event will trigger both, when the player calls the contact and when the contact calls the player. + /// + public event EventHandler Answered; + /// + /// Event triggered when the call is hung up by the player. + /// + public event EventHandler Cancelled; + /// + /// Event triggered when the call finishes naturally, without player input. + /// + public event EventHandler Finished; + + #endregion + } +} +#endif From b8f0949364ae508e4c274cb812503e2713819ebc Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Jul 2022 17:18:45 -0400 Subject: [PATCH 02/50] Added main Phone class --- LemonUI/Phone/Phone.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 LemonUI/Phone/Phone.cs diff --git a/LemonUI/Phone/Phone.cs b/LemonUI/Phone/Phone.cs new file mode 100644 index 00000000..06678553 --- /dev/null +++ b/LemonUI/Phone/Phone.cs @@ -0,0 +1,11 @@ +#if SHVDN3 +namespace LemonUI.Phone +{ + /// + /// Class used to manage the phone. + /// + public static class Phone + { + } +} +#endif From 433ea3b15163155a907f274f0b8d3663b45612f2 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Jul 2022 17:28:17 -0400 Subject: [PATCH 03/50] Added function to add and remove contacts --- LemonUI/Phone/Phone.cs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/LemonUI/Phone/Phone.cs b/LemonUI/Phone/Phone.cs index 06678553..086d6aa7 100644 --- a/LemonUI/Phone/Phone.cs +++ b/LemonUI/Phone/Phone.cs @@ -1,4 +1,6 @@ #if SHVDN3 +using System.Collections.Generic; + namespace LemonUI.Phone { /// @@ -6,6 +8,35 @@ namespace LemonUI.Phone /// public static class Phone { + #region Fields + + private static readonly List contacts = new List(); + + #endregion + + #region Functions + + /// + /// Adds a new contact to the phone. + /// + /// The contact to add. + public static void Add(PhoneContact contact) + { + if (contacts.Contains(contact)) + { + return; + } + + contacts.Add(contact); + } + /// + /// Removes a contact from the phone. + /// + /// The contact to remove. + /// if the contact was removed, otherwise. + public static bool Remove(PhoneContact contact) => contacts.Remove(contact); + + #endregion } } #endif From 034d07ee729be9cf290e11b8bca2a59635d80883 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Jul 2022 18:02:25 -0400 Subject: [PATCH 04/50] Added event that gets triggered when the contact info changes --- LemonUI/Phone/PhoneContact.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/LemonUI/Phone/PhoneContact.cs b/LemonUI/Phone/PhoneContact.cs index 71305b2b..85049471 100644 --- a/LemonUI/Phone/PhoneContact.cs +++ b/LemonUI/Phone/PhoneContact.cs @@ -29,6 +29,10 @@ public class PhoneContact /// Event triggered when the call finishes naturally, without player input. /// public event EventHandler Finished; + /// + /// Event triggered when the picture or name of the contact changes. + /// + public event EventHandler Changed; #endregion } From 9c3567d10e4d045ecd39c750b8d01749982278b7 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Jul 2022 18:02:44 -0400 Subject: [PATCH 05/50] Added customizable properties for the contacts --- LemonUI/Phone/PhoneContact.cs | 64 +++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/LemonUI/Phone/PhoneContact.cs b/LemonUI/Phone/PhoneContact.cs index 85049471..17371ade 100644 --- a/LemonUI/Phone/PhoneContact.cs +++ b/LemonUI/Phone/PhoneContact.cs @@ -8,6 +8,14 @@ namespace LemonUI.Phone /// public class PhoneContact { + #region Fields + + private string name = string.Empty; + private string pictureDictionary = string.Empty; + private string pictureTexture = string.Empty; + + #endregion + #region Events /// @@ -35,6 +43,62 @@ public class PhoneContact public event EventHandler Changed; #endregion + + #region Properties + + /// + /// The name of the contact. + /// + public string Name + { + get => name; + set + { + if (name == value) + { + return; + } + + name = value; + Changed?.Invoke(this, EventArgs.Empty); + } + } + /// + /// The dictionary where the contact picture is located. + /// + public string PictureDictionary + { + get => pictureDictionary; + set + { + if (pictureDictionary == value) + { + return; + } + + pictureDictionary = value; + Changed?.Invoke(this, EventArgs.Empty); + } + } + /// + /// The texture inside of the dictionary used for the contact picture. + /// + public string PictureTexture + { + get => pictureTexture; + set + { + if (pictureTexture == value) + { + return; + } + + pictureTexture = value; + Changed?.Invoke(this, EventArgs.Empty); + } + } + + #endregion } } #endif From 771722ba1bdae1e0519d66ba4dd81879da01b442 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Jul 2022 18:13:44 -0400 Subject: [PATCH 06/50] Make the Phone class a GTA Script --- LemonUI/Phone/Phone.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/LemonUI/Phone/Phone.cs b/LemonUI/Phone/Phone.cs index 086d6aa7..057f4011 100644 --- a/LemonUI/Phone/Phone.cs +++ b/LemonUI/Phone/Phone.cs @@ -1,4 +1,5 @@ #if SHVDN3 +using GTA; using System.Collections.Generic; namespace LemonUI.Phone @@ -6,7 +7,7 @@ namespace LemonUI.Phone /// /// Class used to manage the phone. /// - public static class Phone + public class Phone : Script { #region Fields From 8c627fef338843f3e6d057fc6655febd5691aec9 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Jul 2022 18:14:10 -0400 Subject: [PATCH 07/50] Added process function for the Phone class --- LemonUI/Phone/Phone.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/LemonUI/Phone/Phone.cs b/LemonUI/Phone/Phone.cs index 057f4011..5d508086 100644 --- a/LemonUI/Phone/Phone.cs +++ b/LemonUI/Phone/Phone.cs @@ -15,8 +15,20 @@ public class Phone : Script #endregion + #region Constructors + + public Phone() + { + Tick += (sender, e) => Process(); + } + + #endregion + #region Functions + private static void Process() + { + } /// /// Adds a new contact to the phone. /// From 456888d11f1d31388c0077d8a38ddc749de0f431 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Jul 2022 18:32:10 -0400 Subject: [PATCH 08/50] Added enum to track the contact property changes --- LemonUI/Phone/PhoneInfoChanged.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 LemonUI/Phone/PhoneInfoChanged.cs diff --git a/LemonUI/Phone/PhoneInfoChanged.cs b/LemonUI/Phone/PhoneInfoChanged.cs new file mode 100644 index 00000000..b9804019 --- /dev/null +++ b/LemonUI/Phone/PhoneInfoChanged.cs @@ -0,0 +1,19 @@ +#if SHVDN3 +namespace LemonUI.Phone +{ + /// + /// Represents the possible visual changes of a Contact. + /// + public enum PhoneInfoChanged + { + /// + /// The name of the contact. + /// + Name = 0, + /// + /// The picture or icon of the contact. + /// + Picture = 1 + } +} +#endif From 8adb1a44427c19f37defad5d1a793dcd705bb4d0 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Jul 2022 18:33:18 -0400 Subject: [PATCH 09/50] Added event arguments and handler for contact changes --- LemonUI/Phone/PhoneContactChangedEventArgs.cs | 35 +++++++++++++++++++ .../Phone/PhoneContactChangedEventHandler.cs | 11 ++++++ 2 files changed, 46 insertions(+) create mode 100644 LemonUI/Phone/PhoneContactChangedEventArgs.cs create mode 100644 LemonUI/Phone/PhoneContactChangedEventHandler.cs diff --git a/LemonUI/Phone/PhoneContactChangedEventArgs.cs b/LemonUI/Phone/PhoneContactChangedEventArgs.cs new file mode 100644 index 00000000..b33831fd --- /dev/null +++ b/LemonUI/Phone/PhoneContactChangedEventArgs.cs @@ -0,0 +1,35 @@ +#if SHVDN3 +using System; + +namespace LemonUI.Phone +{ + /// + /// Represents the event data when one of the contact properties are changed. + /// + public class PhoneContactChangedEventArgs : EventArgs + { + #region Properties + + /// + /// The that was changed. + /// + public PhoneContact Contact { get; } + /// + /// The property that was changed in the contact. + /// + public PhoneInfoChanged Changed { get; } + + #endregion + + #region Constructors + + internal PhoneContactChangedEventArgs(PhoneContact contact, PhoneInfoChanged changed) + { + Contact = contact; + Changed = changed; + } + + #endregion + } +} +#endif diff --git a/LemonUI/Phone/PhoneContactChangedEventHandler.cs b/LemonUI/Phone/PhoneContactChangedEventHandler.cs new file mode 100644 index 00000000..a204382e --- /dev/null +++ b/LemonUI/Phone/PhoneContactChangedEventHandler.cs @@ -0,0 +1,11 @@ +#if SHVDN3 +namespace LemonUI.Phone +{ + /// + /// Represents the method that is called when one of the properties of the contact are changed. + /// + /// The source of the event. + /// An with the contact information. + public delegate void PhoneContactChangedEventHandler(object sender, PhoneContactChangedEventArgs e); +} +#endif From 24324d1d3b332408fd51084de8dd37ef7f9e3838 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Jul 2022 18:35:52 -0400 Subject: [PATCH 10/50] Use PhoneContactChangedEventHandler for the contact changes --- LemonUI/Phone/PhoneContact.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/LemonUI/Phone/PhoneContact.cs b/LemonUI/Phone/PhoneContact.cs index 17371ade..d281e68f 100644 --- a/LemonUI/Phone/PhoneContact.cs +++ b/LemonUI/Phone/PhoneContact.cs @@ -40,7 +40,7 @@ public class PhoneContact /// /// Event triggered when the picture or name of the contact changes. /// - public event EventHandler Changed; + public event PhoneContactChangedEventHandler Changed; #endregion @@ -60,7 +60,7 @@ public string Name } name = value; - Changed?.Invoke(this, EventArgs.Empty); + OnChanged(PhoneInfoChanged.Name); } } /// @@ -77,7 +77,7 @@ public string PictureDictionary } pictureDictionary = value; - Changed?.Invoke(this, EventArgs.Empty); + OnChanged(PhoneInfoChanged.Picture); } } /// @@ -94,11 +94,17 @@ public string PictureTexture } pictureTexture = value; - Changed?.Invoke(this, EventArgs.Empty); + OnChanged(PhoneInfoChanged.Picture); } } #endregion + + #region Functions + + private void OnChanged(PhoneInfoChanged info) => Changed?.Invoke(this, new PhoneContactChangedEventArgs(this, info)); + + #endregion } } #endif From 47a7d25223e3f62be156858dffd7056467714065 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Jul 2022 18:44:22 -0400 Subject: [PATCH 11/50] Added tracking of the property changes of the contacts --- LemonUI/Phone/Phone.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/LemonUI/Phone/Phone.cs b/LemonUI/Phone/Phone.cs index 5d508086..62d87e8c 100644 --- a/LemonUI/Phone/Phone.cs +++ b/LemonUI/Phone/Phone.cs @@ -29,6 +29,9 @@ public Phone() private static void Process() { } + private static void HandleChanges(object sender, PhoneContactChangedEventArgs e) + { + } /// /// Adds a new contact to the phone. /// @@ -40,6 +43,7 @@ public static void Add(PhoneContact contact) return; } + contact.Changed += HandleChanges; contacts.Add(contact); } /// @@ -47,7 +51,16 @@ public static void Add(PhoneContact contact) /// /// The contact to remove. /// if the contact was removed, otherwise. - public static bool Remove(PhoneContact contact) => contacts.Remove(contact); + public static bool Remove(PhoneContact contact) + { + if (!contacts.Contains(contact)) + { + return false; + } + + contact.Changed -= HandleChanges; + return contacts.Remove(contact); + } #endregion } From acb2aa7872f8ee0f004fb2f8b5e2007704879aac Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Jul 2022 22:19:14 -0400 Subject: [PATCH 12/50] Looks like there is no need to keep track of the state --- LemonUI/Phone/PhoneContact.cs | 66 ++++--------------- LemonUI/Phone/PhoneContactChangedEventArgs.cs | 35 ---------- .../Phone/PhoneContactChangedEventHandler.cs | 11 ---- LemonUI/Phone/PhoneInfoChanged.cs | 19 ------ 4 files changed, 12 insertions(+), 119 deletions(-) delete mode 100644 LemonUI/Phone/PhoneContactChangedEventArgs.cs delete mode 100644 LemonUI/Phone/PhoneContactChangedEventHandler.cs delete mode 100644 LemonUI/Phone/PhoneInfoChanged.cs diff --git a/LemonUI/Phone/PhoneContact.cs b/LemonUI/Phone/PhoneContact.cs index d281e68f..d0986282 100644 --- a/LemonUI/Phone/PhoneContact.cs +++ b/LemonUI/Phone/PhoneContact.cs @@ -8,14 +8,6 @@ namespace LemonUI.Phone /// public class PhoneContact { - #region Fields - - private string name = string.Empty; - private string pictureDictionary = string.Empty; - private string pictureTexture = string.Empty; - - #endregion - #region Events /// @@ -37,10 +29,6 @@ public class PhoneContact /// Event triggered when the call finishes naturally, without player input. /// public event EventHandler Finished; - /// - /// Event triggered when the picture or name of the contact changes. - /// - public event PhoneContactChangedEventHandler Changed; #endregion @@ -49,60 +37,30 @@ public class PhoneContact /// /// The name of the contact. /// - public string Name - { - get => name; - set - { - if (name == value) - { - return; - } + public string Name { get; set; } - name = value; - OnChanged(PhoneInfoChanged.Name); - } - } /// /// The dictionary where the contact picture is located. /// - public string PictureDictionary - { - get => pictureDictionary; - set - { - if (pictureDictionary == value) - { - return; - } + public string PictureDictionary { get; set; } - pictureDictionary = value; - OnChanged(PhoneInfoChanged.Picture); - } - } /// /// The texture inside of the dictionary used for the contact picture. /// - public string PictureTexture - { - get => pictureTexture; - set - { - if (pictureTexture == value) - { - return; - } - - pictureTexture = value; - OnChanged(PhoneInfoChanged.Picture); - } - } + public string PictureTexture { get; set; } #endregion - #region Functions + #region Constructors - private void OnChanged(PhoneInfoChanged info) => Changed?.Invoke(this, new PhoneContactChangedEventArgs(this, info)); + /// + /// Creates a new contact. + /// + /// The name of the contact. + public PhoneContact(string name) + { + Name = name; + } #endregion } diff --git a/LemonUI/Phone/PhoneContactChangedEventArgs.cs b/LemonUI/Phone/PhoneContactChangedEventArgs.cs deleted file mode 100644 index b33831fd..00000000 --- a/LemonUI/Phone/PhoneContactChangedEventArgs.cs +++ /dev/null @@ -1,35 +0,0 @@ -#if SHVDN3 -using System; - -namespace LemonUI.Phone -{ - /// - /// Represents the event data when one of the contact properties are changed. - /// - public class PhoneContactChangedEventArgs : EventArgs - { - #region Properties - - /// - /// The that was changed. - /// - public PhoneContact Contact { get; } - /// - /// The property that was changed in the contact. - /// - public PhoneInfoChanged Changed { get; } - - #endregion - - #region Constructors - - internal PhoneContactChangedEventArgs(PhoneContact contact, PhoneInfoChanged changed) - { - Contact = contact; - Changed = changed; - } - - #endregion - } -} -#endif diff --git a/LemonUI/Phone/PhoneContactChangedEventHandler.cs b/LemonUI/Phone/PhoneContactChangedEventHandler.cs deleted file mode 100644 index a204382e..00000000 --- a/LemonUI/Phone/PhoneContactChangedEventHandler.cs +++ /dev/null @@ -1,11 +0,0 @@ -#if SHVDN3 -namespace LemonUI.Phone -{ - /// - /// Represents the method that is called when one of the properties of the contact are changed. - /// - /// The source of the event. - /// An with the contact information. - public delegate void PhoneContactChangedEventHandler(object sender, PhoneContactChangedEventArgs e); -} -#endif diff --git a/LemonUI/Phone/PhoneInfoChanged.cs b/LemonUI/Phone/PhoneInfoChanged.cs deleted file mode 100644 index b9804019..00000000 --- a/LemonUI/Phone/PhoneInfoChanged.cs +++ /dev/null @@ -1,19 +0,0 @@ -#if SHVDN3 -namespace LemonUI.Phone -{ - /// - /// Represents the possible visual changes of a Contact. - /// - public enum PhoneInfoChanged - { - /// - /// The name of the contact. - /// - Name = 0, - /// - /// The picture or icon of the contact. - /// - Picture = 1 - } -} -#endif From 994c60394716572f0cf2c6638320b08a66263b59 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Jul 2022 22:43:36 -0400 Subject: [PATCH 13/50] Merge both dictionary and texture to Icon --- LemonUI/Phone/PhoneContact.cs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/LemonUI/Phone/PhoneContact.cs b/LemonUI/Phone/PhoneContact.cs index d0986282..64f56c56 100644 --- a/LemonUI/Phone/PhoneContact.cs +++ b/LemonUI/Phone/PhoneContact.cs @@ -38,16 +38,10 @@ public class PhoneContact /// The name of the contact. /// public string Name { get; set; } - - /// - /// The dictionary where the contact picture is located. - /// - public string PictureDictionary { get; set; } - /// - /// The texture inside of the dictionary used for the contact picture. + /// The icon of the contact. /// - public string PictureTexture { get; set; } + public string Icon { get; set; } = string.Empty; #endregion From 2f3c30f248307470c730439bd8b99cc9c653ebd3 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Jul 2022 22:46:41 -0400 Subject: [PATCH 14/50] Added Scaleform class for handling phones --- LemonUI/Scaleform/Phone.cs | 50 ++++++++++++++++++++++++++++++++++ LemonUI/Scaleform/PhoneType.cs | 21 ++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 LemonUI/Scaleform/Phone.cs create mode 100644 LemonUI/Scaleform/PhoneType.cs diff --git a/LemonUI/Scaleform/Phone.cs b/LemonUI/Scaleform/Phone.cs new file mode 100644 index 00000000..df5e644a --- /dev/null +++ b/LemonUI/Scaleform/Phone.cs @@ -0,0 +1,50 @@ +namespace LemonUI.Scaleform +{ + /// + /// Class used to manage the phone scaleform. + /// + public sealed class Phone : BaseScaleform + { + #region Properties + + /// + /// The type of phone. + /// + public PhoneType Type { get; } + + #endregion + + #region Constructors + + /// + public Phone(PhoneType type) : base(GetName(type)) + { + Type = type; + } + + #endregion + + #region Functions + + private static string GetName(PhoneType type) + { + switch (type) + { + case PhoneType.Badger: + return "cellphone_badger"; + case PhoneType.Facade: + return "cellphone_facade"; + case PhoneType.IFruit: + return "cellphone_ifruit"; + default: + return "cellphone_ifruit"; + } + } + /// + public override void Update() + { + } + + #endregion + } +} diff --git a/LemonUI/Scaleform/PhoneType.cs b/LemonUI/Scaleform/PhoneType.cs new file mode 100644 index 00000000..5a95c292 --- /dev/null +++ b/LemonUI/Scaleform/PhoneType.cs @@ -0,0 +1,21 @@ +namespace LemonUI.Scaleform +{ + /// + /// The different type of phones in GTA V. + /// + public enum PhoneType + { + /// + /// Badger, the phone used by Franklin. + /// + Badger = 0, + /// + /// Facade, the phone used by Trevor. + /// + Facade = 1, + /// + /// iFruit, the phone used by Michael and the GTA Online protagonist. + /// + IFruit = 2 + } +} From 5bbbc29c62b2956e5b50514cd5b53bad491cf16f Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Jul 2022 22:48:11 -0400 Subject: [PATCH 15/50] Renamed Phone to PhoneManager --- LemonUI/Phone/Phone.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LemonUI/Phone/Phone.cs b/LemonUI/Phone/Phone.cs index 62d87e8c..8fc1c948 100644 --- a/LemonUI/Phone/Phone.cs +++ b/LemonUI/Phone/Phone.cs @@ -7,7 +7,7 @@ namespace LemonUI.Phone /// /// Class used to manage the phone. /// - public class Phone : Script + public class PhoneManager : Script { #region Fields @@ -17,7 +17,7 @@ public class Phone : Script #region Constructors - public Phone() + public PhoneManager() { Tick += (sender, e) => Process(); } From 1605bb9e0edfd667487e0114b1125a46242eaac8 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Jul 2022 23:11:49 -0400 Subject: [PATCH 16/50] Added property to check if the contacts are open --- LemonUI/Phone/Phone.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/LemonUI/Phone/Phone.cs b/LemonUI/Phone/Phone.cs index 8fc1c948..14556b91 100644 --- a/LemonUI/Phone/Phone.cs +++ b/LemonUI/Phone/Phone.cs @@ -1,5 +1,6 @@ #if SHVDN3 using GTA; +using GTA.Native; using System.Collections.Generic; namespace LemonUI.Phone @@ -15,6 +16,15 @@ public class PhoneManager : Script #endregion + #region Properties + + /// + /// If the phone's contact are open on the screen. + /// + public static bool AreContactsOpen => Function.Call(Hash._GET_NUMBER_OF_REFERENCES_OF_SCRIPT_WITH_NAME_HASH, Game.GenerateHash("appcontacts")); + + #endregion + #region Constructors public PhoneManager() From 65d2882012d3f77916bcf00c034fcb0d04eb2271 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Jul 2022 23:43:35 -0400 Subject: [PATCH 17/50] Set the unknown contact picture by default --- LemonUI/Phone/PhoneContact.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LemonUI/Phone/PhoneContact.cs b/LemonUI/Phone/PhoneContact.cs index 64f56c56..6db02731 100644 --- a/LemonUI/Phone/PhoneContact.cs +++ b/LemonUI/Phone/PhoneContact.cs @@ -41,7 +41,7 @@ public class PhoneContact /// /// The icon of the contact. /// - public string Icon { get; set; } = string.Empty; + public string Icon { get; set; } = "CHAR_DEFAULT"; #endregion From 06431da21564d8e7efd99848ee77eecf2d00eb7c Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Jul 2022 23:54:00 -0400 Subject: [PATCH 18/50] Added the 3 default phones --- LemonUI/Phone/Phone.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/LemonUI/Phone/Phone.cs b/LemonUI/Phone/Phone.cs index 14556b91..98c53ad7 100644 --- a/LemonUI/Phone/Phone.cs +++ b/LemonUI/Phone/Phone.cs @@ -2,6 +2,7 @@ using GTA; using GTA.Native; using System.Collections.Generic; +using LemonUI.Scaleform; namespace LemonUI.Phone { @@ -13,6 +14,9 @@ public class PhoneManager : Script #region Fields private static readonly List contacts = new List(); + private static Scaleform.Phone badger = new Scaleform.Phone(PhoneType.Badger); + private static Scaleform.Phone facade = new Scaleform.Phone(PhoneType.Facade); + private static Scaleform.Phone ifruit = new Scaleform.Phone(PhoneType.IFruit); #endregion From d86ef06f6a746355a7e583f13d27988ef7bb4de6 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Jul 2022 23:54:50 -0400 Subject: [PATCH 19/50] Added processing of the actual contacts --- LemonUI/Phone/Phone.cs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/LemonUI/Phone/Phone.cs b/LemonUI/Phone/Phone.cs index 98c53ad7..66d01956 100644 --- a/LemonUI/Phone/Phone.cs +++ b/LemonUI/Phone/Phone.cs @@ -1,6 +1,7 @@ #if SHVDN3 using GTA; using GTA.Native; +using System; using System.Collections.Generic; using LemonUI.Scaleform; @@ -33,18 +34,27 @@ public class PhoneManager : Script public PhoneManager() { - Tick += (sender, e) => Process(); + Tick += Process; } #endregion #region Functions - private static void Process() - { - } - private static void HandleChanges(object sender, PhoneContactChangedEventArgs e) + private static void Process(object sender, EventArgs e) { + Scaleform.Phone currentPhone = CurrentPhone; + + if (AreContactsOpen && Game.IsControlJustPressed(Control.PhoneSelect)) + { + Function.Call(Hash.TERMINATE_ALL_SCRIPTS_WITH_THIS_NAME, "appcontacts"); + } + + for (int i = 0; i < contacts.Count; i++) + { + PhoneContact contact = contacts[i]; + currentPhone.AddContactAt(40 + i, contact.Name, contact.Icon); + } } /// /// Adds a new contact to the phone. From 6bd167e1683b10fedefc4991ad463818218c4f25 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Jul 2022 23:55:11 -0400 Subject: [PATCH 20/50] Added property to get the current phone --- LemonUI/Phone/Phone.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/LemonUI/Phone/Phone.cs b/LemonUI/Phone/Phone.cs index 66d01956..4a0c902b 100644 --- a/LemonUI/Phone/Phone.cs +++ b/LemonUI/Phone/Phone.cs @@ -23,6 +23,21 @@ public class PhoneManager : Script #region Properties + private static Scaleform.Phone CurrentPhone + { + get + { + switch (Game.Player.Character.Model.NativeValue) + { + case (uint)PedHash.Franklin: + return badger; + case (uint)PedHash.Trevor: + return facade; + default: + return ifruit; + } + } + } /// /// If the phone's contact are open on the screen. /// From 5fa6a491bcfebd2225d7209d9e8b3b11df50e5f8 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Jul 2022 23:55:30 -0400 Subject: [PATCH 21/50] Added function to add a raw contact to the scaleform --- LemonUI/Scaleform/Phone.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/LemonUI/Scaleform/Phone.cs b/LemonUI/Scaleform/Phone.cs index df5e644a..4b74825a 100644 --- a/LemonUI/Scaleform/Phone.cs +++ b/LemonUI/Scaleform/Phone.cs @@ -44,6 +44,16 @@ private static string GetName(PhoneType type) public override void Update() { } + /// + /// Adds a contact at the specified location. + /// + /// The position to add the contact at. + /// The name of the contact. + /// The icon to use. + public void AddContactAt(int position, string name, string icon) + { + CallFunction("SET_DATA_SLOT", 2, position, 0, name, string.Empty, icon); + } #endregion } From 8adf799247d96b0a3b14fb282a413573ddf8a66a Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sat, 16 Jul 2022 23:55:56 -0400 Subject: [PATCH 22/50] Remove outdated code from the Add and Remove contact functions --- LemonUI/Phone/Phone.cs | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/LemonUI/Phone/Phone.cs b/LemonUI/Phone/Phone.cs index 4a0c902b..fcd179bc 100644 --- a/LemonUI/Phone/Phone.cs +++ b/LemonUI/Phone/Phone.cs @@ -82,7 +82,6 @@ public static void Add(PhoneContact contact) return; } - contact.Changed += HandleChanges; contacts.Add(contact); } /// @@ -90,16 +89,7 @@ public static void Add(PhoneContact contact) /// /// The contact to remove. /// if the contact was removed, otherwise. - public static bool Remove(PhoneContact contact) - { - if (!contacts.Contains(contact)) - { - return false; - } - - contact.Changed -= HandleChanges; - return contacts.Remove(contact); - } + public static bool Remove(PhoneContact contact) => contacts.Remove(contact); #endregion } From 08bc048a13588b8d5018df8b41f679706211ff7e Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sun, 17 Jul 2022 00:11:28 -0400 Subject: [PATCH 23/50] Make the Phone scaleform only available on SHVDN3 --- LemonUI/Scaleform/Phone.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/LemonUI/Scaleform/Phone.cs b/LemonUI/Scaleform/Phone.cs index 4b74825a..e75f0e42 100644 --- a/LemonUI/Scaleform/Phone.cs +++ b/LemonUI/Scaleform/Phone.cs @@ -1,4 +1,7 @@ -namespace LemonUI.Scaleform +#if SHVDN3 +using GTA; + +namespace LemonUI.Scaleform { /// /// Class used to manage the phone scaleform. @@ -58,3 +61,4 @@ public void AddContactAt(int position, string name, string icon) #endregion } } +#endif From fdbb5681d330faf5dcb13af435a7c7276008735b Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sun, 17 Jul 2022 01:05:37 -0400 Subject: [PATCH 24/50] Added tracking of the total number of contacts --- LemonUI/Phone/Phone.cs | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/LemonUI/Phone/Phone.cs b/LemonUI/Phone/Phone.cs index fcd179bc..d658e92a 100644 --- a/LemonUI/Phone/Phone.cs +++ b/LemonUI/Phone/Phone.cs @@ -15,6 +15,7 @@ public class PhoneManager : Script #region Fields private static readonly List contacts = new List(); + private static int total = -1; private static Scaleform.Phone badger = new Scaleform.Phone(PhoneType.Badger); private static Scaleform.Phone facade = new Scaleform.Phone(PhoneType.Facade); private static Scaleform.Phone ifruit = new Scaleform.Phone(PhoneType.IFruit); @@ -60,15 +61,29 @@ private static void Process(object sender, EventArgs e) { Scaleform.Phone currentPhone = CurrentPhone; - if (AreContactsOpen && Game.IsControlJustPressed(Control.PhoneSelect)) + if (AreContactsOpen) { - Function.Call(Hash.TERMINATE_ALL_SCRIPTS_WITH_THIS_NAME, "appcontacts"); - } + if (total == -1) + { + total = currentPhone.Total; + } + + int index = currentPhone.Index; + + if (Game.IsControlJustPressed(Control.PhoneSelect) && index >= total) + { + Function.Call(Hash.TERMINATE_ALL_SCRIPTS_WITH_THIS_NAME, "appcontacts"); + } - for (int i = 0; i < contacts.Count; i++) + for (int i = 0; i < contacts.Count; i++) + { + PhoneContact contact = contacts[i]; + currentPhone.AddContactAt(total + i, contact.Name, contact.Icon); + } + } + else { - PhoneContact contact = contacts[i]; - currentPhone.AddContactAt(40 + i, contact.Name, contact.Icon); + total = -1; } } /// From a5535a2357ee48a284bcd436f095e4dc62d529fa Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Sun, 17 Jul 2022 01:06:22 -0400 Subject: [PATCH 25/50] Added properties to get the current Index and Total --- LemonUI/Scaleform/Phone.cs | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/LemonUI/Scaleform/Phone.cs b/LemonUI/Scaleform/Phone.cs index e75f0e42..0b0a73eb 100644 --- a/LemonUI/Scaleform/Phone.cs +++ b/LemonUI/Scaleform/Phone.cs @@ -14,6 +14,51 @@ public sealed class Phone : BaseScaleform /// The type of phone. /// public PhoneType Type { get; } + /// + /// The currently selected index. + /// + public int Index + { + get + { + int value = CallFunctionReturn("GET_CURRENT_SELECTION"); + + while (!IsValueReady(value)) + { + Script.Yield(); + } + + return GetValue(value); + } + } + /// + /// The total amount of contacts. + /// + /// + /// This will set the contact position to the first element. + /// + public int Total + { + get + { + while (Index != 0) + { + Controls.DisableThisFrame(Control.PhoneUp); + Controls.DisableThisFrame(Control.PhoneDown); + Controls.DisableThisFrame(Control.PhoneLeft); + Controls.DisableThisFrame(Control.PhoneRight); + Controls.DisableThisFrame(Control.PhoneSelect); + Controls.DisableThisFrame(Control.PhoneCancel); + Controls.DisableThisFrame(Control.PhoneOption); + CallFunction("SET_INPUT_EVENT", 3); + } + + CallFunction("SET_INPUT_EVENT", 1); + int last = Index; + CallFunction("SET_INPUT_EVENT", 3); + return last + 1; + } + } #endregion From f0a47e0117ab8f92bb56493ed40a7426a62106e5 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Mon, 25 Jul 2022 20:19:29 -0400 Subject: [PATCH 26/50] Added phone scaleform --- LemonUI/Scaleform/Phone.cs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/LemonUI/Scaleform/Phone.cs b/LemonUI/Scaleform/Phone.cs index 0b0a73eb..3ae816ae 100644 --- a/LemonUI/Scaleform/Phone.cs +++ b/LemonUI/Scaleform/Phone.cs @@ -93,6 +93,11 @@ public override void Update() { } /// + /// Shows a specific page on the phone. + /// + /// The page ID to show. + public void ShowPage(int page) => CallFunction("DISPLAY_VIEW", page, 0); + /// /// Adds a contact at the specified location. /// /// The position to add the contact at. @@ -102,6 +107,17 @@ public void AddContactAt(int position, string name, string icon) { CallFunction("SET_DATA_SLOT", 2, position, 0, name, string.Empty, icon); } + /// + /// Shows the calling screen. + /// + /// The name of the contact. + /// The label used to dial up. + /// The icon to use. + public void ShowCalling(string name, string dialingLabel, string icon) + { + CallFunction("SET_DATA_SLOT", 4, 0, 3, name, icon, Game.GetLocalizedString(dialingLabel)); + CallFunction("DISPLAY_VIEW", 4); + } #endregion } From 97239f224c9443920afbafaf68aacd61ab7894cf Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Mon, 25 Jul 2022 20:21:58 -0400 Subject: [PATCH 27/50] Added enum with the behavior of the call --- LemonUI/Phone/CallBehavior.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 LemonUI/Phone/CallBehavior.cs diff --git a/LemonUI/Phone/CallBehavior.cs b/LemonUI/Phone/CallBehavior.cs new file mode 100644 index 00000000..4f57187b --- /dev/null +++ b/LemonUI/Phone/CallBehavior.cs @@ -0,0 +1,17 @@ +namespace LemonUI.Phone +{ + /// + /// The behavior of a call after is initiated by the user. + /// + public enum CallBehavior + { + /// + /// The contact being called is busy. + /// + Busy = 0, + /// + /// The contact is available and will answer. + /// + Available = 1 + } +} From ca7fa78476364826bfa684a75f702f90a3d800e9 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Mon, 25 Jul 2022 20:22:18 -0400 Subject: [PATCH 28/50] Added Handler and Event Arguments for the call --- LemonUI/Phone/CalledEventArgs.cs | 38 +++++++++++++++++++++++++++++ LemonUI/Phone/CalledEventHandler.cs | 11 +++++++++ 2 files changed, 49 insertions(+) create mode 100644 LemonUI/Phone/CalledEventArgs.cs create mode 100644 LemonUI/Phone/CalledEventHandler.cs diff --git a/LemonUI/Phone/CalledEventArgs.cs b/LemonUI/Phone/CalledEventArgs.cs new file mode 100644 index 00000000..9e5bb4af --- /dev/null +++ b/LemonUI/Phone/CalledEventArgs.cs @@ -0,0 +1,38 @@ +#if SHVDN3 +using System; + +namespace LemonUI.Phone +{ + /// + /// Represents the call process when the player initiates a call + /// + public class CalledEventArgs : EventArgs + { + #region Properties + + /// + /// The contact that was called by the player. + /// + public PhoneContact Contact { get; } + /// + /// The behavior of the call after the wait. + /// + public CallBehavior Behavior { get; set; } = CallBehavior.Busy; + /// + /// The time to wait before the is applied. + /// + public int Wait { get; set; } = 3000; + + #endregion + + #region Constructors + + internal CalledEventArgs(PhoneContact contact) + { + Contact = contact; + } + + #endregion + } +} +#endif diff --git a/LemonUI/Phone/CalledEventHandler.cs b/LemonUI/Phone/CalledEventHandler.cs new file mode 100644 index 00000000..5e0fcd19 --- /dev/null +++ b/LemonUI/Phone/CalledEventHandler.cs @@ -0,0 +1,11 @@ +#if SHVDN3 +namespace LemonUI.Phone +{ + /// + /// Represents the method that is called when the value on a grid is changed. + /// + /// The source of the event. + /// An with the call information. + public delegate void CalledEventHandler(object sender, CalledEventArgs e); +} +#endif From f8553781779d10ebb78cbc23db40701a52a953be Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Mon, 25 Jul 2022 20:24:26 -0400 Subject: [PATCH 29/50] Added phone contact calling support --- LemonUI/Phone/PhoneContact.cs | 64 +++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/LemonUI/Phone/PhoneContact.cs b/LemonUI/Phone/PhoneContact.cs index 6db02731..46bcf410 100644 --- a/LemonUI/Phone/PhoneContact.cs +++ b/LemonUI/Phone/PhoneContact.cs @@ -1,4 +1,5 @@ #if SHVDN3 +using GTA; using System; namespace LemonUI.Phone @@ -8,12 +9,19 @@ namespace LemonUI.Phone /// public class PhoneContact { + #region Fields + + private static readonly Sound busySound = new Sound("Phone_SoundSet_Default", "Remote_Engaged"); + private static readonly Sound callingSound = new Sound("Phone_SoundSet_Default", "Dial_and_Remote_Ring"); + + #endregion + #region Events /// - /// Event triggered when the contact is called. + /// Event triggered when the contact is called by the player. /// - public event EventHandler Called; + public event CalledEventHandler Called; /// /// Event triggered when the call is answered by the player. /// @@ -57,6 +65,58 @@ public PhoneContact(string name) } #endregion + + #region Functions + + internal void Call(Scaleform.Phone phone) + { + const string dialing = "CELL_211"; + const string busy = "CELL_220"; + const string connected = "CELL_219"; + + callingSound.PlayFrontend(false); + phone.ShowCalling(Name, dialing, Icon); + + CalledEventArgs called = new CalledEventArgs(this); + Called?.Invoke(phone, called); + + int waitUntil = Game.GameTime + called.Wait; + + while (waitUntil > Game.GameTime) + { + phone.ShowCalling(Name, dialing, Icon); + + if (Game.IsControlJustPressed(Control.PhoneCancel)) + { + phone.ShowPage(2); + callingSound.Stop(); + return; + } + + Script.Yield(); + } + + callingSound.Stop(); + + switch (called.Behavior) + { + case CallBehavior.Busy: + busySound.PlayFrontend(false); + while (!Game.IsControlPressed(Control.PhoneCancel)) + { + phone.ShowCalling(Name, busy, Icon); + Script.Yield(); + } + busySound.Stop(); + break; + case CallBehavior.Available: + phone.ShowCalling(Name, connected, Icon); + Answered?.Invoke(phone, EventArgs.Empty); + break; + } + } + + #endregion } } #endif From fafe8498c1ededea96832640946cbbed5bbbc78a Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Mon, 25 Jul 2022 20:24:59 -0400 Subject: [PATCH 30/50] Added support for calling the contact --- LemonUI/Phone/Phone.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/LemonUI/Phone/Phone.cs b/LemonUI/Phone/Phone.cs index d658e92a..910daca5 100644 --- a/LemonUI/Phone/Phone.cs +++ b/LemonUI/Phone/Phone.cs @@ -43,6 +43,10 @@ private static Scaleform.Phone CurrentPhone /// If the phone's contact are open on the screen. /// public static bool AreContactsOpen => Function.Call(Hash._GET_NUMBER_OF_REFERENCES_OF_SCRIPT_WITH_NAME_HASH, Game.GenerateHash("appcontacts")); + /// + /// The contact currently being called. + /// + public static PhoneContact Current { get; private set; } #endregion @@ -51,6 +55,8 @@ private static Scaleform.Phone CurrentPhone public PhoneManager() { Tick += Process; + Add(new PhoneContact("One")); + Add(new PhoneContact("Two")); } #endregion @@ -70,9 +76,12 @@ private static void Process(object sender, EventArgs e) int index = currentPhone.Index; - if (Game.IsControlJustPressed(Control.PhoneSelect) && index >= total) + if (Game.IsControlPressed(Control.PhoneSelect) && index >= total) { Function.Call(Hash.TERMINATE_ALL_SCRIPTS_WITH_THIS_NAME, "appcontacts"); + Current = contacts[index - total]; + Current.Call(currentPhone); + return; } for (int i = 0; i < contacts.Count; i++) From 0a77ebb08b9d6048527a63eef405ad5238825f05 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Mon, 25 Jul 2022 22:54:02 -0400 Subject: [PATCH 31/50] Don't return to the contacts screen --- LemonUI/Phone/PhoneContact.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/LemonUI/Phone/PhoneContact.cs b/LemonUI/Phone/PhoneContact.cs index 46bcf410..5df29e5a 100644 --- a/LemonUI/Phone/PhoneContact.cs +++ b/LemonUI/Phone/PhoneContact.cs @@ -88,7 +88,6 @@ internal void Call(Scaleform.Phone phone) if (Game.IsControlJustPressed(Control.PhoneCancel)) { - phone.ShowPage(2); callingSound.Stop(); return; } From 3c6539c1e6dfc2b4b86c68d16137807fe3969b5b Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Tue, 26 Jul 2022 04:24:37 -0400 Subject: [PATCH 32/50] Added function to set the button icons --- LemonUI/Scaleform/Phone.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/LemonUI/Scaleform/Phone.cs b/LemonUI/Scaleform/Phone.cs index 3ae816ae..783396d1 100644 --- a/LemonUI/Scaleform/Phone.cs +++ b/LemonUI/Scaleform/Phone.cs @@ -93,6 +93,12 @@ public override void Update() { } /// + /// Sets the icon of a button. + /// + /// The button to change. + /// The icon to set. + public void SetButtonIcon(int button, int icon) => CallFunction("SET_SOFT_KEYS", button, true, icon); + /// /// Shows a specific page on the phone. /// /// The page ID to show. From f58c100d2e81e5b5dfcfcd980b6ad1bc5cce0a47 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Tue, 26 Jul 2022 04:25:31 -0400 Subject: [PATCH 33/50] Set the correct buttons when calling a contact --- LemonUI/Phone/PhoneContact.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/LemonUI/Phone/PhoneContact.cs b/LemonUI/Phone/PhoneContact.cs index 5df29e5a..42825b3c 100644 --- a/LemonUI/Phone/PhoneContact.cs +++ b/LemonUI/Phone/PhoneContact.cs @@ -74,6 +74,10 @@ internal void Call(Scaleform.Phone phone) const string busy = "CELL_220"; const string connected = "CELL_219"; + phone.SetButtonIcon(1, 1); + phone.SetButtonIcon(2, 1); + phone.SetButtonIcon(3, 6); + callingSound.PlayFrontend(false); phone.ShowCalling(Name, dialing, Icon); From c97becd1d55146171bec0d5783c2889004c96ac6 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Tue, 26 Jul 2022 04:26:25 -0400 Subject: [PATCH 34/50] Added function to restart the contacts script --- LemonUI/Phone/PhoneContact.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/LemonUI/Phone/PhoneContact.cs b/LemonUI/Phone/PhoneContact.cs index 42825b3c..02a6ed20 100644 --- a/LemonUI/Phone/PhoneContact.cs +++ b/LemonUI/Phone/PhoneContact.cs @@ -1,6 +1,7 @@ #if SHVDN3 using GTA; using System; +using GTA.Native; namespace LemonUI.Phone { @@ -66,6 +67,25 @@ public PhoneContact(string name) #endregion + #region Tools + + private static void RestoreContactsScript() + { + if (PhoneManager.AreContactsOpen) + { + return; + } + + while (!Function.Call(Hash.HAS_SCRIPT_LOADED, "appContacts")) + { + Function.Call(Hash.REQUEST_SCRIPT, "appContacts"); + } + + Function.Call(Hash.START_NEW_SCRIPT, "appContacts", 4000); + } + + #endregion + #region Functions internal void Call(Scaleform.Phone phone) From 38e9154bb50a48dc48ceb71b68a6fd8aa443eb99 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Tue, 26 Jul 2022 04:28:29 -0400 Subject: [PATCH 35/50] Start using the phone when calling --- LemonUI/Phone/PhoneContact.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/LemonUI/Phone/PhoneContact.cs b/LemonUI/Phone/PhoneContact.cs index 02a6ed20..c1908934 100644 --- a/LemonUI/Phone/PhoneContact.cs +++ b/LemonUI/Phone/PhoneContact.cs @@ -101,6 +101,7 @@ internal void Call(Scaleform.Phone phone) callingSound.PlayFrontend(false); phone.ShowCalling(Name, dialing, Icon); + Game.Player.Character.Task.UseMobilePhone(); CalledEventArgs called = new CalledEventArgs(this); Called?.Invoke(phone, called); From 8f022c5270f3dcb1eb8cdc947338d8fce94a740b Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Tue, 26 Jul 2022 04:30:00 -0400 Subject: [PATCH 36/50] Put away the mobile phone when returning to the contacts --- LemonUI/Phone/PhoneContact.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/LemonUI/Phone/PhoneContact.cs b/LemonUI/Phone/PhoneContact.cs index c1908934..33f37ab9 100644 --- a/LemonUI/Phone/PhoneContact.cs +++ b/LemonUI/Phone/PhoneContact.cs @@ -126,12 +126,15 @@ internal void Call(Scaleform.Phone phone) { case CallBehavior.Busy: busySound.PlayFrontend(false); + while (!Game.IsControlPressed(Control.PhoneCancel)) { phone.ShowCalling(Name, busy, Icon); Script.Yield(); } + busySound.Stop(); + Game.Player.Character.Task.PutAwayMobilePhone(); break; case CallBehavior.Available: phone.ShowCalling(Name, connected, Icon); From 755e822f73a1d830128c4474b683cbf36b2fbc19 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Tue, 26 Jul 2022 04:32:23 -0400 Subject: [PATCH 37/50] Show the contacts page when the contact is not available --- LemonUI/Phone/PhoneContact.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/LemonUI/Phone/PhoneContact.cs b/LemonUI/Phone/PhoneContact.cs index 33f37ab9..d03d2b7f 100644 --- a/LemonUI/Phone/PhoneContact.cs +++ b/LemonUI/Phone/PhoneContact.cs @@ -135,6 +135,8 @@ internal void Call(Scaleform.Phone phone) busySound.Stop(); Game.Player.Character.Task.PutAwayMobilePhone(); + phone.ShowPage(2); + RestoreContactsScript(); break; case CallBehavior.Available: phone.ShowCalling(Name, connected, Icon); From 356dd6e772d77b5129c730def996f49aec7556fc Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Tue, 26 Jul 2022 06:27:03 -0400 Subject: [PATCH 38/50] Added enum to track the call origin --- LemonUI/Phone/CallOrigin.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 LemonUI/Phone/CallOrigin.cs diff --git a/LemonUI/Phone/CallOrigin.cs b/LemonUI/Phone/CallOrigin.cs new file mode 100644 index 00000000..7c73913b --- /dev/null +++ b/LemonUI/Phone/CallOrigin.cs @@ -0,0 +1,17 @@ +namespace LemonUI.Phone +{ + /// + /// The origin of the call. + /// + public enum CallOrigin + { + /// + /// The Contact called the Player. + /// + Contact = 0, + /// + /// The Player called the Contact. + /// + Player = 1 + } +} From 48139d37cc8017ed00e97e58841f5e23102f7d73 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Tue, 26 Jul 2022 06:27:48 -0400 Subject: [PATCH 39/50] Added event Arguments and Handler for when the call is connected --- LemonUI/Phone/ConnectedEventArgs.cs | 30 ++++++++++++++++++++++++++ LemonUI/Phone/ConnectedEventHandler.cs | 11 ++++++++++ 2 files changed, 41 insertions(+) create mode 100644 LemonUI/Phone/ConnectedEventArgs.cs create mode 100644 LemonUI/Phone/ConnectedEventHandler.cs diff --git a/LemonUI/Phone/ConnectedEventArgs.cs b/LemonUI/Phone/ConnectedEventArgs.cs new file mode 100644 index 00000000..d4ae18d3 --- /dev/null +++ b/LemonUI/Phone/ConnectedEventArgs.cs @@ -0,0 +1,30 @@ +#if SHVDN3 +using System; + +namespace LemonUI.Phone +{ + /// + /// Represents the call process when the player answers the phone and the call is connected. + /// + public class ConnectedEventArgs : EventArgs + { + #region Properties + + /// + /// The contact that was called by the player. + /// + public PhoneContact Contact { get; } + + #endregion + + #region Constructors + + internal ConnectedEventArgs(PhoneContact contact) + { + Contact = contact; + } + + #endregion + } +} +#endif diff --git a/LemonUI/Phone/ConnectedEventHandler.cs b/LemonUI/Phone/ConnectedEventHandler.cs new file mode 100644 index 00000000..0bfcbc84 --- /dev/null +++ b/LemonUI/Phone/ConnectedEventHandler.cs @@ -0,0 +1,11 @@ +#if SHVDN3 +namespace LemonUI.Phone +{ + /// + /// Represents the method that is called when the phone call is connected. + /// + /// The source of the event. + /// An with the connection information. + public delegate void ConnectedEventHandler(object sender, ConnectedEventArgs e); +} +#endif From 8bb6f2a277754252e6f1cc97b6d23088b1d51dbc Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Tue, 26 Jul 2022 06:29:09 -0400 Subject: [PATCH 40/50] Make the Connected event use the new Handler and Args --- LemonUI/Phone/PhoneContact.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LemonUI/Phone/PhoneContact.cs b/LemonUI/Phone/PhoneContact.cs index d03d2b7f..9e4b3dde 100644 --- a/LemonUI/Phone/PhoneContact.cs +++ b/LemonUI/Phone/PhoneContact.cs @@ -29,7 +29,7 @@ public class PhoneContact /// /// This event will trigger both, when the player calls the contact and when the contact calls the player. /// - public event EventHandler Answered; + public event ConnectedEventHandler Connected; /// /// Event triggered when the call is hung up by the player. /// @@ -140,7 +140,7 @@ internal void Call(Scaleform.Phone phone) break; case CallBehavior.Available: phone.ShowCalling(Name, connected, Icon); - Answered?.Invoke(phone, EventArgs.Empty); + Connected?.Invoke(phone, new ConnectedEventArgs(this)); break; } } From 33fff60b1af859b6b5613b62d183b22eddce54a5 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Tue, 26 Jul 2022 07:32:09 -0400 Subject: [PATCH 41/50] Made the restore script function more generic --- LemonUI/Phone/PhoneContact.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/LemonUI/Phone/PhoneContact.cs b/LemonUI/Phone/PhoneContact.cs index 9e4b3dde..4b351707 100644 --- a/LemonUI/Phone/PhoneContact.cs +++ b/LemonUI/Phone/PhoneContact.cs @@ -69,19 +69,19 @@ public PhoneContact(string name) #region Tools - private static void RestoreContactsScript() + private static void RestoreScript(string script, int stack) { - if (PhoneManager.AreContactsOpen) + if (Function.Call(Hash._GET_NUMBER_OF_REFERENCES_OF_SCRIPT_WITH_NAME_HASH, Game.GenerateHash("appcontacts") > 0)) { return; } - while (!Function.Call(Hash.HAS_SCRIPT_LOADED, "appContacts")) + while (!Function.Call(Hash.HAS_SCRIPT_LOADED, script)) { - Function.Call(Hash.REQUEST_SCRIPT, "appContacts"); + Function.Call(Hash.REQUEST_SCRIPT, script); } - Function.Call(Hash.START_NEW_SCRIPT, "appContacts", 4000); + Function.Call(Hash.START_NEW_SCRIPT, script, stack); } #endregion @@ -136,7 +136,7 @@ internal void Call(Scaleform.Phone phone) busySound.Stop(); Game.Player.Character.Task.PutAwayMobilePhone(); phone.ShowPage(2); - RestoreContactsScript(); + RestoreScript("appContacts", 4000); break; case CallBehavior.Available: phone.ShowCalling(Name, connected, Icon); From 8768d242d4e189b91233a0491706a304bc16dc72 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Tue, 26 Jul 2022 07:32:23 -0400 Subject: [PATCH 42/50] Added sound to hide the phone --- LemonUI/Phone/PhoneContact.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/LemonUI/Phone/PhoneContact.cs b/LemonUI/Phone/PhoneContact.cs index 4b351707..3b7f015c 100644 --- a/LemonUI/Phone/PhoneContact.cs +++ b/LemonUI/Phone/PhoneContact.cs @@ -14,6 +14,7 @@ public class PhoneContact private static readonly Sound busySound = new Sound("Phone_SoundSet_Default", "Remote_Engaged"); private static readonly Sound callingSound = new Sound("Phone_SoundSet_Default", "Dial_and_Remote_Ring"); + private static readonly Sound hideSound = new Sound("Phone_SoundSet_Michael", "Put_Away"); #endregion From e8dd0e79a27c32992cdd2b847670428f76ed3865 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Tue, 26 Jul 2022 07:32:39 -0400 Subject: [PATCH 43/50] Removed the Cancelled event (not gonna be used) --- LemonUI/Phone/PhoneContact.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/LemonUI/Phone/PhoneContact.cs b/LemonUI/Phone/PhoneContact.cs index 3b7f015c..f5f00c67 100644 --- a/LemonUI/Phone/PhoneContact.cs +++ b/LemonUI/Phone/PhoneContact.cs @@ -32,10 +32,6 @@ public class PhoneContact /// public event ConnectedEventHandler Connected; /// - /// Event triggered when the call is hung up by the player. - /// - public event EventHandler Cancelled; - /// /// Event triggered when the call finishes naturally, without player input. /// public event EventHandler Finished; From ce5c33263fbdc069cdf8fc3ab34340ecb843ca88 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Tue, 26 Jul 2022 07:33:15 -0400 Subject: [PATCH 44/50] Hide the phone after the call is completed --- LemonUI/Phone/PhoneContact.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/LemonUI/Phone/PhoneContact.cs b/LemonUI/Phone/PhoneContact.cs index f5f00c67..def76f70 100644 --- a/LemonUI/Phone/PhoneContact.cs +++ b/LemonUI/Phone/PhoneContact.cs @@ -131,15 +131,24 @@ internal void Call(Scaleform.Phone phone) } busySound.Stop(); - Game.Player.Character.Task.PutAwayMobilePhone(); phone.ShowPage(2); RestoreScript("appContacts", 4000); break; case CallBehavior.Available: phone.ShowCalling(Name, connected, Icon); + Connected?.Invoke(phone, new ConnectedEventArgs(this)); + Finished?.Invoke(phone, EventArgs.Empty); + + hideSound.PlayFrontend(true); + Function.Call(Hash.TERMINATE_ALL_SCRIPTS_WITH_THIS_NAME, "cellphone_flashhand"); + Function.Call(Hash.TERMINATE_ALL_SCRIPTS_WITH_THIS_NAME, "cellphone_controller"); + RestoreScript("cellphone_flashhand", 1424); + RestoreScript("cellphone_controller", 1424); break; } + + Game.Player.Character.Task.PutAwayMobilePhone(); } #endregion From 41cb9cc96a0083825e6c00ceb5be7b7062bbe5e3 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Tue, 26 Jul 2022 07:33:58 -0400 Subject: [PATCH 45/50] Removed test contacts (whops) --- LemonUI/Phone/Phone.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/LemonUI/Phone/Phone.cs b/LemonUI/Phone/Phone.cs index 910daca5..d505fa37 100644 --- a/LemonUI/Phone/Phone.cs +++ b/LemonUI/Phone/Phone.cs @@ -55,8 +55,6 @@ private static Scaleform.Phone CurrentPhone public PhoneManager() { Tick += Process; - Add(new PhoneContact("One")); - Add(new PhoneContact("Two")); } #endregion From 70beb56cd50775b05d12c90595b1c424b1adbf61 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Tue, 26 Jul 2022 20:38:20 -0400 Subject: [PATCH 46/50] Fixed phone not working for Franklin and Trevor --- LemonUI/Phone/Phone.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/LemonUI/Phone/Phone.cs b/LemonUI/Phone/Phone.cs index d505fa37..8291a362 100644 --- a/LemonUI/Phone/Phone.cs +++ b/LemonUI/Phone/Phone.cs @@ -28,11 +28,13 @@ private static Scaleform.Phone CurrentPhone { get { - switch (Game.Player.Character.Model.NativeValue) + switch ((uint)Game.Player.Character.Model.Hash) { - case (uint)PedHash.Franklin: + case 0x9B22DBAF: // Franklin return badger; - case (uint)PedHash.Trevor: + case 0x0D7114C9: // Michael + return ifruit; + case 0x9B810FA2: // Trevor return facade; default: return ifruit; From 21b8cc6c018b8dbe94e3ef597a968ca3c1857dd9 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Tue, 26 Jul 2022 21:08:48 -0400 Subject: [PATCH 47/50] No need to call the hide phone sound --- LemonUI/Phone/PhoneContact.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/LemonUI/Phone/PhoneContact.cs b/LemonUI/Phone/PhoneContact.cs index def76f70..b2b9356c 100644 --- a/LemonUI/Phone/PhoneContact.cs +++ b/LemonUI/Phone/PhoneContact.cs @@ -14,7 +14,6 @@ public class PhoneContact private static readonly Sound busySound = new Sound("Phone_SoundSet_Default", "Remote_Engaged"); private static readonly Sound callingSound = new Sound("Phone_SoundSet_Default", "Dial_and_Remote_Ring"); - private static readonly Sound hideSound = new Sound("Phone_SoundSet_Michael", "Put_Away"); #endregion @@ -140,7 +139,6 @@ internal void Call(Scaleform.Phone phone) Connected?.Invoke(phone, new ConnectedEventArgs(this)); Finished?.Invoke(phone, EventArgs.Empty); - hideSound.PlayFrontend(true); Function.Call(Hash.TERMINATE_ALL_SCRIPTS_WITH_THIS_NAME, "cellphone_flashhand"); Function.Call(Hash.TERMINATE_ALL_SCRIPTS_WITH_THIS_NAME, "cellphone_controller"); RestoreScript("cellphone_flashhand", 1424); From a11b6abeaffd2a5c0209a2df20e4bc86d68a1f68 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Wed, 31 Aug 2022 07:10:27 -0400 Subject: [PATCH 48/50] Change the Phone Contact loading so it doesn't blocks checks --- LemonUI/Phone/CallStatus.cs | 33 ++++++++++ LemonUI/Phone/Phone.cs | 14 +++++ LemonUI/Phone/PhoneContact.cs | 115 +++++++++++++++++++++++----------- 3 files changed, 125 insertions(+), 37 deletions(-) create mode 100644 LemonUI/Phone/CallStatus.cs diff --git a/LemonUI/Phone/CallStatus.cs b/LemonUI/Phone/CallStatus.cs new file mode 100644 index 00000000..8143fb49 --- /dev/null +++ b/LemonUI/Phone/CallStatus.cs @@ -0,0 +1,33 @@ +namespace LemonUI.Phone +{ + /// + /// The status of the current call. + /// + internal enum CallStatus + { + /// + /// The contact is not being called. + /// + Inactive = -1, + /// + /// The contact has been triggered and is currently idling. + /// + Idle = 0, + /// + /// The contact is currently being called. + /// + Calling = 1, + /// + /// The contact has been called and has answered as Busy or Connected. + /// + Called = 2, + /// + /// The contact is busy. + /// + Busy = 3, + /// + /// The contact has been connected. + /// + Connected = 4 + } +} diff --git a/LemonUI/Phone/Phone.cs b/LemonUI/Phone/Phone.cs index 8291a362..70224a3d 100644 --- a/LemonUI/Phone/Phone.cs +++ b/LemonUI/Phone/Phone.cs @@ -67,6 +67,20 @@ private static void Process(object sender, EventArgs e) { Scaleform.Phone currentPhone = CurrentPhone; + if (Current != null) + { + Current.Process(currentPhone); + + if (!Current.IsActive) + { + Current = null; + } + else + { + return; + } + } + if (AreContactsOpen) { if (total == -1) diff --git a/LemonUI/Phone/PhoneContact.cs b/LemonUI/Phone/PhoneContact.cs index b2b9356c..09edd3bb 100644 --- a/LemonUI/Phone/PhoneContact.cs +++ b/LemonUI/Phone/PhoneContact.cs @@ -12,8 +12,15 @@ public class PhoneContact { #region Fields + private const string dialing = "CELL_211"; + private const string busy = "CELL_220"; + private const string connected = "CELL_219"; private static readonly Sound busySound = new Sound("Phone_SoundSet_Default", "Remote_Engaged"); private static readonly Sound callingSound = new Sound("Phone_SoundSet_Default", "Dial_and_Remote_Ring"); + private CalledEventArgs called; + private string label = dialing; + private CallStatus status = CallStatus.Inactive; + private int waitUntil = -1; #endregion @@ -47,6 +54,10 @@ public class PhoneContact /// The icon of the contact. /// public string Icon { get; set; } = "CHAR_DEFAULT"; + /// + /// If this phone contact is currently active. + /// + public bool IsActive => status != CallStatus.Inactive; #endregion @@ -84,69 +95,99 @@ private static void RestoreScript(string script, int stack) #region Functions + private static void Restart() + { + Function.Call(Hash.TERMINATE_ALL_SCRIPTS_WITH_THIS_NAME, "cellphone_flashhand"); + Function.Call(Hash.TERMINATE_ALL_SCRIPTS_WITH_THIS_NAME, "cellphone_controller"); + RestoreScript("cellphone_flashhand", 1424); + RestoreScript("cellphone_controller", 1424); + } internal void Call(Scaleform.Phone phone) { - const string dialing = "CELL_211"; - const string busy = "CELL_220"; - const string connected = "CELL_219"; - + status = CallStatus.Idle; + Process(phone); + } + internal void Process(Scaleform.Phone phone) + { phone.SetButtonIcon(1, 1); phone.SetButtonIcon(2, 1); phone.SetButtonIcon(3, 6); - callingSound.PlayFrontend(false); - phone.ShowCalling(Name, dialing, Icon); + phone.ShowCalling(Name, label, Icon); - Game.Player.Character.Task.UseMobilePhone(); - CalledEventArgs called = new CalledEventArgs(this); - Called?.Invoke(phone, called); + if (status == CallStatus.Idle) + { + callingSound.PlayFrontend(false); + + Game.Player.Character.Task.UseMobilePhone(); + called = new CalledEventArgs(this); + Called?.Invoke(phone, called); - int waitUntil = Game.GameTime + called.Wait; + waitUntil = Game.GameTime + called.Wait; + + status = CallStatus.Calling; + } - while (waitUntil > Game.GameTime) + if (status == CallStatus.Calling) { - phone.ShowCalling(Name, dialing, Icon); + if (waitUntil < Game.GameTime) + { + callingSound.Stop(); + status = CallStatus.Called; + waitUntil = -1; + } if (Game.IsControlJustPressed(Control.PhoneCancel)) { callingSound.Stop(); + status = CallStatus.Inactive; + waitUntil = -1; return; } - - Script.Yield(); } - callingSound.Stop(); - - switch (called.Behavior) + if (status == CallStatus.Called) { - case CallBehavior.Busy: - busySound.PlayFrontend(false); + switch (called.Behavior) + { + case CallBehavior.Busy: + busySound.PlayFrontend(false); + status = CallStatus.Busy; + label = busy; + break; + case CallBehavior.Available: + Connected?.Invoke(phone, new ConnectedEventArgs(this)); + status = CallStatus.Connected; + label = connected; + break; + } - while (!Game.IsControlPressed(Control.PhoneCancel)) - { - phone.ShowCalling(Name, busy, Icon); - Script.Yield(); - } + Game.Player.Character.Task.PutAwayMobilePhone(); + } + if (status == CallStatus.Busy) + { + if (Game.IsControlPressed(Control.PhoneCancel)) + { busySound.Stop(); phone.ShowPage(2); RestoreScript("appContacts", 4000); - break; - case CallBehavior.Available: - phone.ShowCalling(Name, connected, Icon); - - Connected?.Invoke(phone, new ConnectedEventArgs(this)); - Finished?.Invoke(phone, EventArgs.Empty); - - Function.Call(Hash.TERMINATE_ALL_SCRIPTS_WITH_THIS_NAME, "cellphone_flashhand"); - Function.Call(Hash.TERMINATE_ALL_SCRIPTS_WITH_THIS_NAME, "cellphone_controller"); - RestoreScript("cellphone_flashhand", 1424); - RestoreScript("cellphone_controller", 1424); - break; + status = CallStatus.Inactive; + return; + } } - Game.Player.Character.Task.PutAwayMobilePhone(); + if (status == CallStatus.Connected) + { + if (Game.IsControlPressed(Control.PhoneCancel)) + { + status = CallStatus.Inactive; + Restart(); + } + + status = CallStatus.Inactive; + Restart(); + } } #endregion From b6b3a68c2faece4d35dc01c48fdc4f557d651e3b Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Wed, 31 Aug 2022 07:32:41 -0400 Subject: [PATCH 49/50] Allow the call to be disconnected after some time --- LemonUI/Phone/ConnectedEventArgs.cs | 4 ++++ LemonUI/Phone/PhoneContact.cs | 28 ++++++++++++---------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/LemonUI/Phone/ConnectedEventArgs.cs b/LemonUI/Phone/ConnectedEventArgs.cs index d4ae18d3..343991e4 100644 --- a/LemonUI/Phone/ConnectedEventArgs.cs +++ b/LemonUI/Phone/ConnectedEventArgs.cs @@ -14,6 +14,10 @@ public class ConnectedEventArgs : EventArgs /// The contact that was called by the player. /// public PhoneContact Contact { get; } + /// + /// After how much time should the call be disconnected automatically. + /// + public int DisconnectAfter { get; set; } #endregion diff --git a/LemonUI/Phone/PhoneContact.cs b/LemonUI/Phone/PhoneContact.cs index 09edd3bb..a510e883 100644 --- a/LemonUI/Phone/PhoneContact.cs +++ b/LemonUI/Phone/PhoneContact.cs @@ -12,13 +12,13 @@ public class PhoneContact { #region Fields - private const string dialing = "CELL_211"; - private const string busy = "CELL_220"; - private const string connected = "CELL_219"; + private const string dialingLabel = "CELL_211"; + private const string busyLabel = "CELL_220"; + private const string connectedLabel = "CELL_219"; private static readonly Sound busySound = new Sound("Phone_SoundSet_Default", "Remote_Engaged"); private static readonly Sound callingSound = new Sound("Phone_SoundSet_Default", "Dial_and_Remote_Ring"); private CalledEventArgs called; - private string label = dialing; + private string label = dialingLabel; private CallStatus status = CallStatus.Inactive; private int waitUntil = -1; @@ -122,9 +122,7 @@ internal void Process(Scaleform.Phone phone) Game.Player.Character.Task.UseMobilePhone(); called = new CalledEventArgs(this); Called?.Invoke(phone, called); - waitUntil = Game.GameTime + called.Wait; - status = CallStatus.Calling; } @@ -153,12 +151,14 @@ internal void Process(Scaleform.Phone phone) case CallBehavior.Busy: busySound.PlayFrontend(false); status = CallStatus.Busy; - label = busy; + label = busyLabel; break; case CallBehavior.Available: - Connected?.Invoke(phone, new ConnectedEventArgs(this)); + ConnectedEventArgs connected = new ConnectedEventArgs(this); + Connected?.Invoke(phone, connected); + waitUntil = Game.GameTime + connected.DisconnectAfter; status = CallStatus.Connected; - label = connected; + label = connectedLabel; break; } @@ -177,15 +177,11 @@ internal void Process(Scaleform.Phone phone) } } - if (status == CallStatus.Connected) + if (status == CallStatus.Connected && + (waitUntil < Game.GameTime || Game.IsControlPressed(Control.PhoneCancel))) { - if (Game.IsControlPressed(Control.PhoneCancel)) - { - status = CallStatus.Inactive; - Restart(); - } - status = CallStatus.Inactive; + waitUntil = -1; Restart(); } } From 5c8c2f0b5ce870200491b44b71e788ba927731e7 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Mon, 24 Oct 2022 07:03:14 -0300 Subject: [PATCH 50/50] Implemented IEnumerable on classes that hold object's Closes #97 --- LemonUI/Menus/NativeColorPanel.cs | 7 ++++++- LemonUI/Menus/NativeListItem.cs | 7 ++++++- LemonUI/Menus/NativeMenu.cs | 12 +++++++++++- LemonUI/Menus/NativeStatsPanel.cs | 7 ++++++- LemonUI/ObjectPool.cs | 7 ++++++- 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/LemonUI/Menus/NativeColorPanel.cs b/LemonUI/Menus/NativeColorPanel.cs index b643ca47..be024211 100644 --- a/LemonUI/Menus/NativeColorPanel.cs +++ b/LemonUI/Menus/NativeColorPanel.cs @@ -11,6 +11,7 @@ #endif using LemonUI.Elements; using System; +using System.Collections; using System.Collections.Generic; using System.Drawing; @@ -19,7 +20,7 @@ namespace LemonUI.Menus /// /// A Panel that allows you to select a Color. /// - public class NativeColorPanel : NativePanel + public class NativeColorPanel : NativePanel, IEnumerable { #region Constants @@ -487,6 +488,10 @@ private void UpdateOpacityBar() #region Public Functions + /// + public IEnumerator GetEnumerator() => Colors.GetEnumerator(); + /// + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); /// /// Moves to the Previous Color. /// diff --git a/LemonUI/Menus/NativeListItem.cs b/LemonUI/Menus/NativeListItem.cs index be3c6a91..b2c803be 100644 --- a/LemonUI/Menus/NativeListItem.cs +++ b/LemonUI/Menus/NativeListItem.cs @@ -1,5 +1,6 @@ using LemonUI.Elements; using System; +using System.Collections; using System.Collections.Generic; using System.Drawing; @@ -29,7 +30,7 @@ public NativeListItem(string title, string subtitle) : base(title, subtitle) /// /// An item that allows you to scroll between a set of objects. /// - public class NativeListItem : NativeListItem + public class NativeListItem : NativeListItem, IEnumerable { #region Fields @@ -188,6 +189,10 @@ private void UpdateIndex() #region Functions + /// + public IEnumerator GetEnumerator() => Items.GetEnumerator(); + /// + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); /// /// Adds a into this item. /// diff --git a/LemonUI/Menus/NativeMenu.cs b/LemonUI/Menus/NativeMenu.cs index e52f34fb..236fbc17 100644 --- a/LemonUI/Menus/NativeMenu.cs +++ b/LemonUI/Menus/NativeMenu.cs @@ -24,6 +24,7 @@ using LemonUI.Extensions; using LemonUI.Scaleform; using System; +using System.Collections; using System.Collections.Generic; using System.Drawing; @@ -32,7 +33,7 @@ namespace LemonUI.Menus /// /// Menu that looks like the ones used by Rockstar. /// - public class NativeMenu : IContainer + public class NativeMenu : IContainer, IEnumerable { #region Public Fields @@ -1361,12 +1362,21 @@ private void Draw() #region Public Functions + /// + public IEnumerator GetEnumerator() => Items.GetEnumerator(); + /// + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); /// /// Adds an item at the end of the menu. /// /// The item to add. public void Add(NativeItem item) => Add(Items.Count, item); /// + /// Adds a specific menu as a submenu with an item. + /// + /// The menu to add. + public void Add(NativeMenu menu) => AddSubMenu(menu); + /// /// Adds an item at the specified position. /// /// The position of the item. diff --git a/LemonUI/Menus/NativeStatsPanel.cs b/LemonUI/Menus/NativeStatsPanel.cs index f6798052..97fa435e 100644 --- a/LemonUI/Menus/NativeStatsPanel.cs +++ b/LemonUI/Menus/NativeStatsPanel.cs @@ -1,5 +1,6 @@ using LemonUI.Elements; using System; +using System.Collections; using System.Collections.Generic; using System.Drawing; @@ -8,7 +9,7 @@ namespace LemonUI.Menus /// /// Represents a Statistics panel. /// - public class NativeStatsPanel : NativePanel, IContainer + public class NativeStatsPanel : NativePanel, IContainer, IEnumerable { #region Fields @@ -75,6 +76,10 @@ public NativeStatsPanel(params NativeStatsInfo[] stats) #region Functions + /// + public IEnumerator GetEnumerator() => fields.GetEnumerator(); + /// + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); /// /// Adds a stat to the player field. /// diff --git a/LemonUI/ObjectPool.cs b/LemonUI/ObjectPool.cs index f0fd451d..918168cb 100644 --- a/LemonUI/ObjectPool.cs +++ b/LemonUI/ObjectPool.cs @@ -13,6 +13,7 @@ using GTA.UI; #endif using System; +using System.Collections; using System.Collections.Generic; using System.Drawing; @@ -75,7 +76,7 @@ internal SafeZoneChangedEventArgs(float before, float after) /// /// Manager for Menus and Items. /// - public class ObjectPool + public class ObjectPool : IEnumerable { #region Private Fields @@ -206,6 +207,10 @@ private void DetectSafezoneChanges() #region Public Function + /// + public IEnumerator GetEnumerator() => objects.GetEnumerator(); + /// + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); /// /// Adds the object into the pool. ///