Skip to content

Commit

Permalink
Changed notification/subtitles struct into a public static class for …
Browse files Browse the repository at this point in the history
…easier global access
  • Loading branch information
TomGrobbe committed May 10, 2018
1 parent 4887b73 commit 9f60c33
Show file tree
Hide file tree
Showing 19 changed files with 29 additions and 61 deletions.
12 changes: 6 additions & 6 deletions vMenu/CommonFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class CommonFunctions : BaseScript
{
#region Variables
// Variables
private Notification Notify = MainMenu.Notify;
private Subtitles Subtitle = MainMenu.Subtitle;
//private readonly Notification Notify = MainMenu.Notify;
//private readonly Subtitles Subtitle = MainMenu.Subtitle;
private string currentScenario = "";
private Vehicle previousVehicle;
private StorageManager sm = new StorageManager();
Expand Down Expand Up @@ -254,7 +254,7 @@ public async void TeleportToPlayerAsync(int playerId, bool inVehicle = false)
else
{
Notify.Error(CommonErrors.PlayerNotFound, placeholderValue: "So the teleport has been cancelled.");
//Notify.Error("This player does not exist so the teleport has been cancelled.");
//Notification.Error("This player does not exist so the teleport has been cancelled.");
return;
}
}
Expand Down Expand Up @@ -1147,14 +1147,14 @@ public async void SetLicensePlateTextAsync()
else
{
Notify.Error(CommonErrors.NoVehicle);
//Notify.Error("You're not inside a vehicle!");
//Notification.Error("You're not inside a vehicle!");
}
}
// No valid text was given.
else
{
Notify.Error(CommonErrors.InvalidInput);
//Notify.Error($"License plate text ~r~{(text == "NULL" ? "(empty input)" : text)} ~s~can not be used on a license plate!");
//Notification.Error($"License plate text ~r~{(text == "NULL" ? "(empty input)" : text)} ~s~can not be used on a license plate!");
}

}
Expand Down Expand Up @@ -1233,7 +1233,7 @@ public void PlayScenario(string scenarioName)
// Check if the player CAN play a scenario...
//if (IsPedInAnyVehicle(PlayerPedId(), true))
//{
// Notify.Alert("You can't start a scenario when you are inside a vehicle.", true, false);
// Notification.Alert("You can't start a scenario when you are inside a vehicle.", true, false);
// canPlay = false;
//}
if (IsPedRunning(PlayerPedId()))
Expand Down
3 changes: 1 addition & 2 deletions vMenu/EventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public class EventManager : BaseScript
{
// common functions.
private CommonFunctions cf = MainMenu.Cf;
private Notification Notify = new Notification();
public static string currentWeatherType = "CLEAR";
public static bool blackoutMode = false;
public static bool dynamicWeather = true;
Expand Down Expand Up @@ -299,7 +298,7 @@ private void KillMe()
/// <param name="targetPlayer"></param>
private void SummonPlayer(string targetPlayer)
{
//MainMenu.Notify.Error(targetPlayer);
//MainMenu.Notification.Error(targetPlayer);
cf.TeleportToPlayerAsync(GetPlayerFromServerId(int.Parse(targetPlayer)));
}
}
Expand Down
2 changes: 0 additions & 2 deletions vMenu/FunctionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ namespace vMenuClient
class FunctionsController : BaseScript
{
// Variables
private Notification Notify = MainMenu.Notify;
private Subtitles Subtitle = MainMenu.Subtitle;
private CommonFunctions cf = MainMenu.Cf;

private int LastVehicle = 0;
Expand Down
2 changes: 0 additions & 2 deletions vMenu/MainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public class MainMenu : BaseScript
#region Variables
// Function Variables
public static CommonFunctions Cf { get; } = new CommonFunctions();
public static Notification Notify { get; } = new Notification();
public static Subtitles Subtitle { get; } = new Subtitles();

public static MenuPool Mp { get; } = new MenuPool();

Expand Down
38 changes: 19 additions & 19 deletions vMenu/Notification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public enum CommonErrors
/// <summary>
/// Gets the formatted error message.
/// </summary>
public struct ErrorMessage
public static class ErrorMessage
{
/// <summary>
/// Returns the formatted error message for the specified error type.
Expand Down Expand Up @@ -97,20 +97,20 @@ public static string Get(CommonErrors errorType, string placeholderValue = null)
}
#endregion

#region Notifications Struct
#region Notifications class
/// <summary>
/// Notifications struct to easilly show notifications using custom made templates,
/// Notifications class to easilly show notifications using custom made templates,
/// or completely custom style if none of the templates are fitting for the current task.
/// </summary>
public struct Notification
public static class Notify
{
/// <summary>
/// Show a custom notification above the minimap.
/// </summary>
/// <param name="message">Message to display.</param>
/// <param name="blink">Should the notification blink 3 times?</param>
/// <param name="saveToBrief">Should the notification be logged to the brief (PAUSE menu > INFO > Notifications)?</param>
public void Custom(string message, bool blink = false, bool saveToBrief = true)
public static void Custom(string message, bool blink = false, bool saveToBrief = true)
{
SetNotificationTextEntry("THREESTRINGS");
string[] messages = MainMenu.Cf.StringToArray(message);
Expand All @@ -131,7 +131,7 @@ public void Custom(string message, bool blink = false, bool saveToBrief = true)
/// <param name="message">The message to be displayed on the notification.</param>
/// <param name="blink">Should the notification blink 3 times?</param>
/// <param name="saveToBrief">Should the notification be logged to the brief (PAUSE menu > INFO > Notifications)?</param>
public void Alert(string message, bool blink = false, bool saveToBrief = true)
public static void Alert(string message, bool blink = false, bool saveToBrief = true)
{
Custom("~y~~h~Alert~h~~s~: " + message, blink, saveToBrief);
}
Expand All @@ -143,7 +143,7 @@ public void Alert(string message, bool blink = false, bool saveToBrief = true)
/// <param name="blink">Should the notification blink 3 times?</param>
/// <param name="saveToBrief">Should the notification be logged to the brief (PAUSE menu > INFO > Notifications)?</param>
/// <param name="placeholderValue">An optional string that will be replaced inside the error message template.</param>
public void Alert(CommonErrors errorMessage, bool blink = false, bool saveToBrief = true, string placeholderValue = null)
public static void Alert(CommonErrors errorMessage, bool blink = false, bool saveToBrief = true, string placeholderValue = null)
{
string message = ErrorMessage.Get(errorMessage, placeholderValue);
Alert(message, blink, saveToBrief);
Expand All @@ -155,7 +155,7 @@ public void Alert(CommonErrors errorMessage, bool blink = false, bool saveToBrie
/// <param name="message">The message to be displayed on the notification.</param>
/// <param name="blink">Should the notification blink 3 times?</param>
/// <param name="saveToBrief">Should the notification be logged to the brief (PAUSE menu > INFO > Notifications)?</param>
public void Error(string message, bool blink = false, bool saveToBrief = true)
public static void Error(string message, bool blink = false, bool saveToBrief = true)
{
Custom("~r~~h~Error~h~~s~: " + message, blink, saveToBrief);
}
Expand All @@ -167,7 +167,7 @@ public void Error(string message, bool blink = false, bool saveToBrief = true)
/// <param name="blink">Should the notification blink 3 times?</param>
/// <param name="saveToBrief">Should the notification be logged to the brief (PAUSE menu > INFO > Notifications)?</param>
/// <param name="placeholderValue">An optional string that will be replaced inside the error message template.</param>
public void Error(CommonErrors errorMessage, bool blink = false, bool saveToBrief = true, string placeholderValue = null)
public static void Error(CommonErrors errorMessage, bool blink = false, bool saveToBrief = true, string placeholderValue = null)
{
string message = ErrorMessage.Get(errorMessage, placeholderValue);
Error(message, blink, saveToBrief);
Expand All @@ -179,7 +179,7 @@ public void Error(CommonErrors errorMessage, bool blink = false, bool saveToBrie
/// <param name="message">The message to be displayed on the notification.</param>
/// <param name="blink">Should the notification blink 3 times?</param>
/// <param name="saveToBrief">Should the notification be logged to the brief (PAUSE menu > INFO > Notifications)?</param>
public void Info(string message, bool blink = false, bool saveToBrief = true)
public static void Info(string message, bool blink = false, bool saveToBrief = true)
{
Custom("~b~~h~Info~h~~s~: " + message, blink, saveToBrief);
}
Expand All @@ -190,27 +190,27 @@ public void Info(string message, bool blink = false, bool saveToBrief = true)
/// <param name="message">The message to be displayed on the notification.</param>
/// <param name="blink">Should the notification blink 3 times?</param>
/// <param name="saveToBrief">Should the notification be logged to the brief (PAUSE menu > INFO > Notifications)?</param>
public void Success(string message, bool blink = false, bool saveToBrief = true)
public static void Success(string message, bool blink = false, bool saveToBrief = true)
{
Custom("~g~~h~Success~h~~s~: " + message, blink, saveToBrief);
}
}
#endregion

#region Custom Subtitles Struct
#region Custom Subtitle class
/// <summary>
/// Custom Subtitles struct used to display subtitles using preformatted templates.
/// Custom Subtitle class used to display subtitles using preformatted templates.
/// Optionally you can also use a blank/custom style if you don't want to use an existing template.
/// </summary>
public struct Subtitles
public static class Subtitle
{
/// <summary>
/// Custom (white/custom text style subtitle)
/// </summary>
/// <param name="message">The message to be displayed.</param>
/// <param name="duration">(Optional) duration in ms.</param>
/// <param name="drawImmediately">(Optional) draw the notification immediately or wait for the previous subtitle text to disappear.</param>
public void Custom(string message, int duration = 2500, bool drawImmediately = true)
public static void Custom(string message, int duration = 2500, bool drawImmediately = true)
{
BeginTextCommandPrint("THREESTRINGS");
var messages = MainMenu.Cf.StringToArray(message);
Expand All @@ -228,7 +228,7 @@ public void Custom(string message, int duration = 2500, bool drawImmediately = t
/// <param name="duration">(Optional) duration in ms.</param>
/// <param name="drawImmediately">(Optional) draw the notification immediately or wait for the previous subtitle text to disappear.</param>
/// <param name="prefix">(Optional) add a prefix to your message, if you use this, only the prefix will be colored. The rest of the message will be left white.</param>
public void Alert(string message, int duration = 2500, bool drawImmediately = true, string prefix = null)
public static void Alert(string message, int duration = 2500, bool drawImmediately = true, string prefix = null)
{
Custom((prefix != null ? "~y~" + prefix + " ~s~" : "~y~") + message, duration, drawImmediately);
}
Expand All @@ -240,7 +240,7 @@ public void Alert(string message, int duration = 2500, bool drawImmediately = tr
/// <param name="duration">(Optional) duration in ms.</param>
/// <param name="drawImmediately">(Optional) draw the notification immediately or wait for the previous subtitle text to disappear.</param>
/// <param name="prefix">(Optional) add a prefix to your message, if you use this, only the prefix will be colored. The rest of the message will be left white.</param>
public void Error(string message, int duration = 2500, bool drawImmediately = true, string prefix = null)
public static void Error(string message, int duration = 2500, bool drawImmediately = true, string prefix = null)
{
Custom((prefix != null ? "~r~" + prefix + " ~s~" : "~r~") + message, duration, drawImmediately);
}
Expand All @@ -252,7 +252,7 @@ public void Error(string message, int duration = 2500, bool drawImmediately = tr
/// <param name="duration">(Optional) duration in ms.</param>
/// <param name="drawImmediately">(Optional) draw the notification immediately or wait for the previous subtitle text to disappear.</param>
/// <param name="prefix">(Optional) add a prefix to your message, if you use this, only the prefix will be colored. The rest of the message will be left white.</param>
public void Info(string message, int duration = 2500, bool drawImmediately = true, string prefix = null)
public static void Info(string message, int duration = 2500, bool drawImmediately = true, string prefix = null)
{
Custom((prefix != null ? "~b~" + prefix + " ~s~" : "~b~") + message, duration, drawImmediately);
}
Expand All @@ -264,7 +264,7 @@ public void Info(string message, int duration = 2500, bool drawImmediately = tru
/// <param name="duration">(Optional) duration in ms.</param>
/// <param name="drawImmediately">(Optional) draw the notification immediately or wait for the previous subtitle text to disappear.</param>
/// <param name="prefix">(Optional) add a prefix to your message, if you use this, only the prefix will be colored. The rest of the message will be left white.</param>
public void Success(string message, int duration = 2500, bool drawImmediately = true, string prefix = null)
public static void Success(string message, int duration = 2500, bool drawImmediately = true, string prefix = null)
{
Custom((prefix != null ? "~g~" + prefix + " ~s~" : "~g~") + message, duration, drawImmediately);
}
Expand Down
3 changes: 1 addition & 2 deletions vMenu/UserDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ public static bool ShowCurrentSpeaker

#endregion


#region Private functions
/// <summary>
/// Gets whether or not the specified setting is enabled or disabled in the saved user settings.
Expand Down Expand Up @@ -366,7 +365,7 @@ public static void SaveSettings()
prefs.Add("WeaponsUnlimitedAmmo", MainMenu.WeaponOptionsMenu.UnlimitedAmmo);
}

MainMenu.Notify.Success("Your settings have been saved.");
Notify.Success("Your settings have been saved.");

MainMenu.Cf.Log($"Saving preferences:\n{JsonConvert.SerializeObject(prefs)}");
}
Expand Down
4 changes: 1 addition & 3 deletions vMenu/menus/About.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ public class About
{
// Variables
private UIMenu menu;
private Notification Notify = MainMenu.Notify;
private Subtitles Subtitle = MainMenu.Subtitle;
private CommonFunctions cf = MainMenu.Cf;
private readonly CommonFunctions cf = MainMenu.Cf;

private void CreateMenu()
{
Expand Down
2 changes: 0 additions & 2 deletions vMenu/menus/BannedPlayers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ public class BannedPlayers
{
// Variables
private UIMenu menu;
private Notification Notify = MainMenu.Notify;
private Subtitles Subtitle = MainMenu.Subtitle;
private CommonFunctions cf = MainMenu.Cf;

/// <summary>
Expand Down
2 changes: 0 additions & 2 deletions vMenu/menus/MiscSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public class MiscSettings
{
// Variables
private UIMenu menu;
private Notification Notify = MainMenu.Notify;
private Subtitles Subtitle = MainMenu.Subtitle;
private CommonFunctions cf = MainMenu.Cf;

public bool ShowSpeedoKmh { get; private set; } = UserDefaults.MiscSpeedKmh;
Expand Down
2 changes: 0 additions & 2 deletions vMenu/menus/OnlinePlayers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public class OnlinePlayers
{
// Menu variable, will be defined in CreateMenu()
private UIMenu menu;
private Notification Notify = MainMenu.Notify;
private Subtitles Subtitle = MainMenu.Subtitle;
private CommonFunctions cf = MainMenu.Cf;


Expand Down
2 changes: 0 additions & 2 deletions vMenu/menus/PlayerAppearance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ namespace vMenuClient
public class PlayerAppearance
{
// Variables
private Notification Notify = MainMenu.Notify;
private Subtitles Subtitle = MainMenu.Subtitle;
private CommonFunctions cf = MainMenu.Cf;
private StorageManager sm = new StorageManager();

Expand Down
2 changes: 0 additions & 2 deletions vMenu/menus/PlayerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public class PlayerOptions
{
// Menu variable, will be defined in CreateMenu()
private UIMenu menu;
private static Notification Notify = MainMenu.Notify;
private static Subtitles Subtitle = MainMenu.Subtitle;
private static CommonFunctions cf = MainMenu.Cf;

// Public variables (getters only), return the private variables.
Expand Down
4 changes: 1 addition & 3 deletions vMenu/menus/SavedVehicles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public class SavedVehicles
{
// Variables
private UIMenu menu;
private Notification Notify = MainMenu.Notify;
private Subtitles Subtitle = MainMenu.Subtitle;
private CommonFunctions cf = MainMenu.Cf;
private Dictionary<string, CommonFunctions.VehicleInfo> SavedVehiclesDict;

Expand Down Expand Up @@ -120,7 +118,7 @@ private void CreateMenu()
// Refresh the index of the page.
spawnSavedVehicles.RefreshIndex();
// Update the scaleform.
spawnSavedVehicles.UpdateScaleform();
}
Expand Down
2 changes: 0 additions & 2 deletions vMenu/menus/TimeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public class TimeOptions
{
// Variables
private UIMenu menu;
private Notification Notify = MainMenu.Notify;
private Subtitles Subtitle = MainMenu.Subtitle;
private CommonFunctions cf = MainMenu.Cf;
public UIMenuItem freezeTimeToggle;

Expand Down
2 changes: 0 additions & 2 deletions vMenu/menus/VehicleOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ public class VehicleOptions
#region Variables
// Menu variable, will be defined in CreateMenu()
private UIMenu menu;
private Notification Notify = MainMenu.Notify;
private Subtitles Subtitle = MainMenu.Subtitle;
private CommonFunctions cf = MainMenu.Cf;
private static VehicleData vd = new VehicleData();

Expand Down
2 changes: 0 additions & 2 deletions vMenu/menus/VehicleSpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public class VehicleSpawner
{
// Variables
private UIMenu menu;
private Notification Notify = MainMenu.Notify;
private Subtitles Subtitle = MainMenu.Subtitle;
private CommonFunctions cf = MainMenu.Cf;
public static Dictionary<string, uint> AddonVehicles;

Expand Down
2 changes: 0 additions & 2 deletions vMenu/menus/VoiceChat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public class VoiceChat
{
// Variables
private UIMenu menu;
private Notification Notify = MainMenu.Notify;
private Subtitles Subtitle = MainMenu.Subtitle;
private CommonFunctions cf = MainMenu.Cf;
public bool EnableVoicechat = UserDefaults.VoiceChatEnabled;
public bool ShowCurrentSpeaker = UserDefaults.ShowCurrentSpeaker;
Expand Down
2 changes: 0 additions & 2 deletions vMenu/menus/WeaponOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public class WeaponOptions
{
// Variables
private UIMenu menu;
private Notification Notify = MainMenu.Notify;
private Subtitles Subtitle = MainMenu.Subtitle;
private CommonFunctions cf = MainMenu.Cf;

public bool UnlimitedAmmo { get; private set; } = UserDefaults.WeaponsUnlimitedAmmo;
Expand Down
2 changes: 0 additions & 2 deletions vMenu/menus/WeatherOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public class WeatherOptions
{
// Variables
private UIMenu menu;
private Notification Notify = MainMenu.Notify;
private Subtitles Subtitle = MainMenu.Subtitle;
private CommonFunctions cf = MainMenu.Cf;

public static Dictionary<string, UIMenuItem> weatherHashMenuIndex = new Dictionary<string, UIMenuItem>();
Expand Down

0 comments on commit 9f60c33

Please sign in to comment.