Skip to content

Commit

Permalink
Merge pull request #18 from Bob74/v3
Browse files Browse the repository at this point in the history
Update to SHVDN 3
  • Loading branch information
Bob74 authored Jan 5, 2025
2 parents 348000a + 36ddeb3 commit d20739f
Show file tree
Hide file tree
Showing 13 changed files with 295 additions and 353 deletions.
178 changes: 78 additions & 100 deletions CustomiFruit.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,53 @@
using System.Drawing;
using System.Collections.Generic;

using GTA;
using GTA.Native;

namespace iFruitAddon2
{
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
}

//public delegate void ContactSelectedEvent(iFruitContactCollection sender, iFruitContact selectedItem);
public delegate void ContactAnsweredEvent(iFruitContact contact);

public class CustomiFruit
{
private static CustomiFruit _instance;
internal static CustomiFruit Instance = null;
private bool _shouldDraw = true;
private PhoneImage _wallpaper;
private iFruitContactCollection _contacts;
private int _mScriptHash;
private readonly int _scriptHash = Game.GenerateHash("cellphone_flashhand");
private int _timerClose = -1;
private Scaleform _cellphoneScaleform = null; // Scaleforms must be disposed when unused

private readonly Dictionary<uint, string> _characterScaleformDict = new Dictionary<uint, string>() {
{ (uint)PedHash.Michael, "cellphone_ifruit" },
{ (uint)PedHash.Franklin, "cellphone_badger" },
{ (uint)PedHash.Trevor, "cellphone_facade" }
};

/// <summary>
/// Left Button Color
Expand Down Expand Up @@ -65,43 +97,30 @@ public CustomiFruit() : this(new iFruitContactCollection())
/// <param name="contacts"></param>
public CustomiFruit(iFruitContactCollection contacts)
{
_instance = this;
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)
// If the scaleform is null, create it.
if (_cellphoneScaleform == null)
{
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;
if (_characterScaleformDict.ContainsKey((uint)Game.Player.Character.Model.Hash))
{
_cellphoneScaleform = new Scaleform(_characterScaleformDict[(uint)Game.Player.Character.Model.Hash]);
}
else
{
_cellphoneScaleform = new Scaleform("cellphone_ifruit");
}
}
return _cellphoneScaleform.Handle;
}
}

Expand All @@ -111,25 +130,21 @@ public int Handle
/// <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);
Function.Call(Hash.BEGIN_SCALEFORM_MOVIE_METHOD, Handle, "SET_HEADER");
Function.Call(Hash.BEGIN_TEXT_COMMAND_SCALEFORM_STRING, "STRING");
Function.Call(Hash.ADD_TEXT_COMPONENT_SUBSTRING_PHONE_NUMBER, text, -1);
Function.Call(Hash.END_TEXT_COMMAND_SCALEFORM_STRING);
Function.Call(Hash.END_SCALEFORM_MOVIE_METHOD);
}

/// <summary>
/// Set icon of the soft key buttons directly.
/// Set icon of the soft key buttons directly. Must be called every update!
/// </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);
_cellphoneScaleform.CallFunction("SET_SOFT_KEYS", buttonID, true, (int)icon);
}

/// <summary>
Expand All @@ -139,21 +154,16 @@ public void SetSoftKeyIcon(int buttonID, SoftKeyIcon icon)
/// <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);
_cellphoneScaleform.CallFunction("SET_SOFT_KEYS_COLOUR", buttonID, (int)color.R, (int)color.G, (int)color.B);
}

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);
Function.Call(Hash.BEGIN_SCALEFORM_MOVIE_METHOD, Handle, "SET_BACKGROUND_CREW_IMAGE");
Function.Call(Hash.BEGIN_TEXT_COMMAND_SCALEFORM_STRING, "CELL_2000");
Function.Call(Hash.ADD_TEXT_COMPONENT_SUBSTRING_PLAYER_NAME, textureDict);
Function.Call(Hash.END_TEXT_COMMAND_SCALEFORM_STRING);
Function.Call(Hash.END_SCALEFORM_MOVIE_METHOD);
}

/// <summary>
Expand All @@ -175,40 +185,31 @@ public void SetWallpaper(string textureDict)

public void Update()
{
if (Function.Call<int>(Hash._GET_NUMBER_OF_INSTANCES_OF_STREAMED_SCRIPT, _mScriptHash) > 0)
if (Function.Call<int>(Hash.GET_NUMBER_OF_THREADS_RUNNING_THE_SCRIPT_WITH_THIS_HASH, _scriptHash) > 0)
{
// Must always be called when the phone is on screen
if (LeftButtonIcon != SoftKeyIcon.Blank) SetSoftKeyIcon(1, LeftButtonIcon);
if (CenterButtonIcon != SoftKeyIcon.Blank) SetSoftKeyIcon(2, CenterButtonIcon);
if (RightButtonIcon != SoftKeyIcon.Blank) SetSoftKeyIcon(3, RightButtonIcon);

// Need to be called once when phone is on screen
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);
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);
if (_wallpaper != null) SetWallpaperTXD(_wallpaper.Name);

_shouldDraw = !_shouldDraw;
}
}
}
else
{
// When the phone is closed, we set the next time it opens to draw custom elements
_shouldDraw = true;
}


if (_timerClose != -1)
{
if (_timerClose <= Game.GameTime)
Expand All @@ -228,20 +229,22 @@ public void Update()
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)
if (Function.Call<int>(Hash.GET_NUMBER_OF_THREADS_RUNNING_THE_SCRIPT_WITH_THIS_HASH, _scriptHash) > 0)
{
Function.Call(Hash._PUSH_SCALEFORM_MOVIE_FUNCTION, Handle, "SHUTDOWN_MOVIE");
Function.Call(Hash._POP_SCALEFORM_MOVIE_FUNCTION_VOID);
_cellphoneScaleform.CallFunction("SHUTDOWN_MOVIE");

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");
Expand All @@ -254,29 +257,4 @@ private void Close()
}

}


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
}
}
60 changes: 0 additions & 60 deletions Debug.cs

This file was deleted.

Loading

0 comments on commit d20739f

Please sign in to comment.