#if FIVEM
using CitizenFX.Core;
using CitizenFX.Core.Native;
#elif RAGEMP
using RAGE.Game;
#elif RPH
using Rage.Native;
using Control = Rage.GameControl;
#elif SHVDN3
using GTA;
using GTA.Native;
#endif
using System;
using System.Collections.Generic;
namespace LemonUI.Scaleform
{
///
/// An individual instructional button.
///
public struct InstructionalButton
{
#region Private Fields
private Control control;
private string raw;
#endregion
#region Public Properties
///
/// The description of this button.
///
public string Description { get; set; }
///
/// The Control used by this button.
///
public Control Control
{
get => control;
set
{
control = value;
#if FIVEM
raw = API.GetControlInstructionalButton(2, (int)value, 1);
#elif RAGEMP
raw = Invoker.Invoke(Natives.GetControlInstructionalButton, 2, (int)value, 1);
#elif RPH
raw = (string)NativeFunction.CallByHash(0x0499D7B09FC9B407, typeof(string), 2, (int)control, 1);
#elif SHVDN3
raw = Function.Call(Hash.GET_CONTROL_INSTRUCTIONAL_BUTTON, 2, (int)value, 1);
#endif
}
}
///
/// The Raw Control sent to the Scaleform.
///
public string Raw
{
get => raw;
set
{
raw = value;
control = (Control)(-1);
}
}
#endregion
#region Constructor
///
/// Creates an instructional button for a Control.
///
/// The text for the description.
/// The control to use.
public InstructionalButton(string description, Control control)
{
Description = description;
this.control = control;
#if FIVEM
raw = API.GetControlInstructionalButton(2, (int)control, 1);
#elif RAGEMP
raw = Invoker.Invoke(Natives.GetControlInstructionalButton, 2, (int)control, 1);
#elif RPH
raw = (string)NativeFunction.CallByHash(0x0499D7B09FC9B407, typeof(string), 2, (int)control, 1);
#elif SHVDN3
raw = Function.Call(Hash.GET_CONTROL_INSTRUCTIONAL_BUTTON, 2, (int)control, 1);
#endif
}
///
/// Creates an instructional button for a raw control.
///
/// The text for the description.
/// The raw value of the control.
public InstructionalButton(string description, string raw)
{
Description = description;
control = (Control)(-1);
this.raw = raw;
}
#endregion
}
///
/// Buttons shown on the bottom right of the screen.
///
public class InstructionalButtons : BaseScaleform
{
#region Public Fields
///
/// The buttons used in this Scaleform.
///
private readonly List buttons = new List();
#endregion
#region Constructors
///
/// Creates a new set of Instructional Buttons.
///
/// The buttons to add into this menu.
public InstructionalButtons(params InstructionalButton[] buttons) : base("INSTRUCTIONAL_BUTTONS")
{
this.buttons.AddRange(buttons);
}
#endregion
#region Public Functions
///
/// Adds an Instructional Button.
///
/// The button to add.
public void Add(InstructionalButton button)
{
// If the item is already in the list, raise an exception
if (buttons.Contains(button))
{
throw new InvalidOperationException("The button is already in the Scaleform.");
}
// Otherwise, add it to the list of items
buttons.Add(button);
}
///
/// Removes an Instructional Button.
///
/// The button to remove.
public void Remove(InstructionalButton button)
{
// If the button is not in the list, return
if (!buttons.Contains(button))
{
return;
}
// Otherwise, remove it
buttons.Remove(button);
}
///
/// Removes all of the instructional buttons.
///
public void Clear()
{
buttons.Clear();
}
///
/// Refreshes the items shown in the Instructional buttons.
///
public override void Update()
{
// Clear all of the existing items
CallFunction("CLEAR_ALL");
CallFunction("TOGGLE_MOUSE_BUTTONS", 0);
CallFunction("CREATE_CONTAINER");
// And add them again
for (int i = 0; i < buttons.Count; i++)
{
InstructionalButton button = buttons[i];
CallFunction("SET_DATA_SLOT", i, button.Raw, button.Description);
}
CallFunction("DRAW_INSTRUCTIONAL_BUTTONS", -1);
}
#endregion
}
}