Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
f4aedc6
Added basic Phone Contact class
justalemon Jul 16, 2022
b8f0949
Added main Phone class
justalemon Jul 16, 2022
433ea3b
Added function to add and remove contacts
justalemon Jul 16, 2022
034d07e
Added event that gets triggered when the contact info changes
justalemon Jul 16, 2022
9c3567d
Added customizable properties for the contacts
justalemon Jul 16, 2022
771722b
Make the Phone class a GTA Script
justalemon Jul 16, 2022
8c627fe
Added process function for the Phone class
justalemon Jul 16, 2022
456888d
Added enum to track the contact property changes
justalemon Jul 16, 2022
8adb1a4
Added event arguments and handler for contact changes
justalemon Jul 16, 2022
24324d1
Use PhoneContactChangedEventHandler for the contact changes
justalemon Jul 16, 2022
47a7d25
Added tracking of the property changes of the contacts
justalemon Jul 16, 2022
acb2aa7
Looks like there is no need to keep track of the state
justalemon Jul 17, 2022
994c603
Merge both dictionary and texture to Icon
justalemon Jul 17, 2022
2f3c30f
Added Scaleform class for handling phones
justalemon Jul 17, 2022
5bbbc29
Renamed Phone to PhoneManager
justalemon Jul 17, 2022
1605bb9
Added property to check if the contacts are open
justalemon Jul 17, 2022
65d2882
Set the unknown contact picture by default
justalemon Jul 17, 2022
06431da
Added the 3 default phones
justalemon Jul 17, 2022
d86ef06
Added processing of the actual contacts
justalemon Jul 17, 2022
6bd167e
Added property to get the current phone
justalemon Jul 17, 2022
5fa6a49
Added function to add a raw contact to the scaleform
justalemon Jul 17, 2022
8adf799
Remove outdated code from the Add and Remove contact functions
justalemon Jul 17, 2022
08bc048
Make the Phone scaleform only available on SHVDN3
justalemon Jul 17, 2022
fdbb568
Added tracking of the total number of contacts
justalemon Jul 17, 2022
a5535a2
Added properties to get the current Index and Total
justalemon Jul 17, 2022
f0a47e0
Added phone scaleform
justalemon Jul 26, 2022
97239f2
Added enum with the behavior of the call
justalemon Jul 26, 2022
ca7fa78
Added Handler and Event Arguments for the call
justalemon Jul 26, 2022
f855378
Added phone contact calling support
justalemon Jul 26, 2022
fafe849
Added support for calling the contact
justalemon Jul 26, 2022
0e5f937
Merge branch 'master' into features/phone
justalemon Jul 26, 2022
0a77ebb
Don't return to the contacts screen
justalemon Jul 26, 2022
3c6539c
Added function to set the button icons
justalemon Jul 26, 2022
f58c100
Set the correct buttons when calling a contact
justalemon Jul 26, 2022
c97becd
Added function to restart the contacts script
justalemon Jul 26, 2022
38e9154
Start using the phone when calling
justalemon Jul 26, 2022
8f022c5
Put away the mobile phone when returning to the contacts
justalemon Jul 26, 2022
755e822
Show the contacts page when the contact is not available
justalemon Jul 26, 2022
356dd6e
Added enum to track the call origin
justalemon Jul 26, 2022
48139d3
Added event Arguments and Handler for when the call is connected
justalemon Jul 26, 2022
8bb6f2a
Make the Connected event use the new Handler and Args
justalemon Jul 26, 2022
33fff60
Made the restore script function more generic
justalemon Jul 26, 2022
8768d24
Added sound to hide the phone
justalemon Jul 26, 2022
e8dd0e7
Removed the Cancelled event (not gonna be used)
justalemon Jul 26, 2022
ce5c332
Hide the phone after the call is completed
justalemon Jul 26, 2022
41cb9cc
Removed test contacts (whops)
justalemon Jul 26, 2022
70beb56
Fixed phone not working for Franklin and Trevor
justalemon Jul 27, 2022
21b8cc6
No need to call the hide phone sound
justalemon Jul 27, 2022
a11b6ab
Change the Phone Contact loading so it doesn't blocks checks
justalemon Aug 31, 2022
b6b3a68
Allow the call to be disconnected after some time
justalemon Aug 31, 2022
5b8f687
Merge branch 'master' into features/phone
justalemon Oct 8, 2022
5c8c2f0
Implemented IEnumerable<T> on classes that hold object's
justalemon Oct 24, 2022
a2492fe
Merge branch 'master' into features/phone
justalemon Nov 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions LemonUI/Phone/CallBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace LemonUI.Phone
{
/// <summary>
/// The behavior of a call after is initiated by the user.
/// </summary>
public enum CallBehavior
{
/// <summary>
/// The contact being called is busy.
/// </summary>
Busy = 0,
/// <summary>
/// The contact is available and will answer.
/// </summary>
Available = 1
}
}
17 changes: 17 additions & 0 deletions LemonUI/Phone/CallOrigin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace LemonUI.Phone
{
/// <summary>
/// The origin of the call.
/// </summary>
public enum CallOrigin
{
/// <summary>
/// The Contact called the Player.
/// </summary>
Contact = 0,
/// <summary>
/// The Player called the Contact.
/// </summary>
Player = 1
}
}
33 changes: 33 additions & 0 deletions LemonUI/Phone/CallStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace LemonUI.Phone
{
/// <summary>
/// The status of the current call.
/// </summary>
internal enum CallStatus
{
/// <summary>
/// The contact is not being called.
/// </summary>
Inactive = -1,
/// <summary>
/// The contact has been triggered and is currently idling.
/// </summary>
Idle = 0,
/// <summary>
/// The contact is currently being called.
/// </summary>
Calling = 1,
/// <summary>
/// The contact has been called and has answered as Busy or Connected.
/// </summary>
Called = 2,
/// <summary>
/// The contact is busy.
/// </summary>
Busy = 3,
/// <summary>
/// The contact has been connected.
/// </summary>
Connected = 4
}
}
38 changes: 38 additions & 0 deletions LemonUI/Phone/CalledEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#if SHVDN3
using System;

namespace LemonUI.Phone
{
/// <summary>
/// Represents the call process when the player initiates a call
/// </summary>
public class CalledEventArgs : EventArgs
{
#region Properties

/// <summary>
/// The contact that was called by the player.
/// </summary>
public PhoneContact Contact { get; }
/// <summary>
/// The behavior of the call after the wait.
/// </summary>
public CallBehavior Behavior { get; set; } = CallBehavior.Busy;
/// <summary>
/// The time to wait before the <see cref="Behavior"/> is applied.
/// </summary>
public int Wait { get; set; } = 3000;

#endregion

#region Constructors

internal CalledEventArgs(PhoneContact contact)
{
Contact = contact;
}

#endregion
}
}
#endif
11 changes: 11 additions & 0 deletions LemonUI/Phone/CalledEventHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#if SHVDN3
namespace LemonUI.Phone
{
/// <summary>
/// Represents the method that is called when the value on a grid is changed.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">An <see cref="CalledEventArgs"/> with the call information.</param>
public delegate void CalledEventHandler(object sender, CalledEventArgs e);
}
#endif
34 changes: 34 additions & 0 deletions LemonUI/Phone/ConnectedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#if SHVDN3
using System;

namespace LemonUI.Phone
{
/// <summary>
/// Represents the call process when the player answers the phone and the call is connected.
/// </summary>
public class ConnectedEventArgs : EventArgs
{
#region Properties

/// <summary>
/// The contact that was called by the player.
/// </summary>
public PhoneContact Contact { get; }
/// <summary>
/// After how much time should the call be disconnected automatically.
/// </summary>
public int DisconnectAfter { get; set; }

#endregion

#region Constructors

internal ConnectedEventArgs(PhoneContact contact)
{
Contact = contact;
}

#endregion
}
}
#endif
11 changes: 11 additions & 0 deletions LemonUI/Phone/ConnectedEventHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#if SHVDN3
namespace LemonUI.Phone
{
/// <summary>
/// Represents the method that is called when the phone call is connected.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">An <see cref="CalledEventArgs"/> with the connection information.</param>
public delegate void ConnectedEventHandler(object sender, ConnectedEventArgs e);
}
#endif
135 changes: 135 additions & 0 deletions LemonUI/Phone/Phone.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#if SHVDN3
using GTA;
using GTA.Native;
using System;
using System.Collections.Generic;
using LemonUI.Scaleform;

namespace LemonUI.Phone
{
/// <summary>
/// Class used to manage the phone.
/// </summary>
public class PhoneManager : Script
{
#region Fields

private static readonly List<PhoneContact> contacts = new List<PhoneContact>();
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);

#endregion

#region Properties

private static Scaleform.Phone CurrentPhone
{
get
{
switch ((uint)Game.Player.Character.Model.Hash)
{
case 0x9B22DBAF: // Franklin
return badger;
case 0x0D7114C9: // Michael
return ifruit;
case 0x9B810FA2: // Trevor
return facade;
default:
return ifruit;
}
}
}
/// <summary>
/// If the phone's contact are open on the screen.
/// </summary>
public static bool AreContactsOpen => Function.Call<bool>(Hash._GET_NUMBER_OF_REFERENCES_OF_SCRIPT_WITH_NAME_HASH, Game.GenerateHash("appcontacts"));
/// <summary>
/// The contact currently being called.
/// </summary>
public static PhoneContact Current { get; private set; }

#endregion

#region Constructors

public PhoneManager()
{
Tick += Process;
}

#endregion

#region Functions

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)
{
total = currentPhone.Total;
}

int index = currentPhone.Index;

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++)
{
PhoneContact contact = contacts[i];
currentPhone.AddContactAt(total + i, contact.Name, contact.Icon);
}
}
else
{
total = -1;
}
}
/// <summary>
/// Adds a new contact to the phone.
/// </summary>
/// <param name="contact">The contact to add.</param>
public static void Add(PhoneContact contact)
{
if (contacts.Contains(contact))
{
return;
}

contacts.Add(contact);
}
/// <summary>
/// Removes a contact from the phone.
/// </summary>
/// <param name="contact">The contact to remove.</param>
/// <returns><see langword="true"/> if the contact was removed, <see langword="false"/> otherwise.</returns>
public static bool Remove(PhoneContact contact) => contacts.Remove(contact);

#endregion
}
}
#endif
Loading