Skip to content

Commit

Permalink
Notification update
Browse files Browse the repository at this point in the history
  • Loading branch information
RickyB505 committed Sep 12, 2023
1 parent a69996d commit 91df039
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 37 deletions.
1 change: 1 addition & 0 deletions SharedClasses/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public enum Setting
vmenu_dv_retries,
vmenu_dv_distance,
vmenu_freecam_toggle_key,
vmenu_notification_type,
}

/// <summary>
Expand Down
26 changes: 23 additions & 3 deletions vMenu/EventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public EventManager()
EventHandlers.Add("vMenu:SetPermissions", new Action<string>(MainMenu.SetPermissions));
EventHandlers.Add("vMenu:GoToPlayer", new Action<string>(SummonPlayer));
EventHandlers.Add("vMenu:KillMe", new Action<string>(KillMe));
EventHandlers.Add("vMenu:Notify", new Action<string>(NotifyPlayer));
EventHandlers.Add("vMenu:Notify", new Action<string, string>(NotifyPlayer));
EventHandlers.Add("vMenu:SetClouds", new Action<float, string>(SetClouds));
EventHandlers.Add("vMenu:GoodBye", new Action(GoodBye));
EventHandlers.Add("vMenu:SetBanList", new Action<string>(UpdateBanList));
Expand Down Expand Up @@ -339,9 +339,29 @@ private void SetClouds(float opacity, string cloudsType)
/// Used by events triggered from the server to notify a user.
/// </summary>
/// <param name="message"></param>
private void NotifyPlayer(string message)
private void NotifyPlayer(string message, string type)
{
Notify.Custom(message, true, true);
if (type.ToLower() == "alert")
{
Notify.Alert(message, true, true);
}
else if (type.ToLower() == "error")
{
Notify.Error(message, true, true);
}
else if (type.ToLower() == "info")
{
Notify.Info(message, true, true);
}
else if (type.ToLower() == "success")
{
Notify.Success(message, true, true);
}
else
{
Notify.Custom(message, true, true, type);
}

}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions vMenu/Freecam2/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private async void ResourceStart(string Name)
IsInFreecam = !IsInFreecam;
if (IsInFreecam)
{
TriggerEvent("mosh_notify:notify", "INFO", "<span class=\"text-black\">You are now using Freecam²!</span>", "info", "info", 5000);
//TriggerEvent("mosh_notify:notify", "INFO", "<span class=\"text-black\">You are now using Freecam²!</span>", "info", "info", 5000);
Notify.Success("You are now using Freecam²!");
Freecam.Enable();
}
Expand All @@ -51,7 +51,7 @@ private async void ResourceStart(string Name)
}
else
{
TriggerEvent("mosh_notify:notify", "Error", "<span class=\"text-black\">You are not allowed to use Freecam²!</span>", "error", "error", 5000);
//TriggerEvent("mosh_notify:notify", "Error", "<span class=\"text-black\">You are not allowed to use Freecam²!</span>", "error", "error", 5000);
Notify.Error("You are not allowed to use Freecam²!");
}
}), false);
Expand Down
14 changes: 7 additions & 7 deletions vMenu/MainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public MainMenu()
Notify.Error("You must be in the driver's seat to delete this vehicle!");
if (vMenuShared.ConfigManager.GetSettingsBool(vMenuShared.ConfigManager.Setting.pfvmenu_moshnotify_setting))
{
TriggerEvent("mosh_notify:notify", "ERROR", "<span class=\"text-white\">You must be in the driver's seat to delete this vehicle!</span>", "darkred", "error", 5000);
//TriggerEvent("mosh_notify:notify", "ERROR", "<span class=\"text-white\">You must be in the driver's seat to delete this vehicle!</span>", "darkred", "error", 5000);
}
}
}
Expand All @@ -247,7 +247,7 @@ public MainMenu()
Notify.Error("No vehicle found. Maybe it's not close to you?");
if (vMenuShared.ConfigManager.GetSettingsBool(vMenuShared.ConfigManager.Setting.pfvmenu_moshnotify_setting))
{
TriggerEvent("mosh_notify:notify", "ERROR", "<span class=\"text-white\">No vehicle found. Maybe it's not close to you?</span>", "darkred", "error", 5000);
//TriggerEvent("mosh_notify:notify", "ERROR", "<span class=\"text-white\">No vehicle found. Maybe it's not close to you?</span>", "darkred", "error", 5000);
}
}
}
Expand All @@ -269,7 +269,7 @@ public MainMenu()
Notify.Error("You do NOT have permission to use this command.");
if (vMenuShared.ConfigManager.GetSettingsBool(vMenuShared.ConfigManager.Setting.pfvmenu_moshnotify_setting))
{
TriggerEvent("mosh_notify:notify", "ERROR", "<span class=\"text-white\">You do NOT have permission to use this command.</span>", "darkred", "error", 5000);
//TriggerEvent("mosh_notify:notify", "ERROR", "<span class=\"text-white\">You do NOT have permission to use this command.</span>", "darkred", "error", 5000);
}
}
}), false);
Expand All @@ -292,7 +292,7 @@ static async void DelVeh(Vehicle veh, int maxtimeout, int vehicle)
Notify.Error("You can't delete this vehicle, someone else is driving it!");
if (vMenuShared.ConfigManager.GetSettingsBool(vMenuShared.ConfigManager.Setting.pfvmenu_moshnotify_setting))
{
TriggerEvent("mosh_notify:notify", "ERROR", "<span class=\"text-white\">You can't delete this vehicle, someone else is driving it!</span>", "darkred", "error", 5000);
//TriggerEvent("mosh_notify:notify", "ERROR", "<span class=\"text-white\">You can't delete this vehicle, someone else is driving it!</span>", "darkred", "error", 5000);
}
return;
}
Expand All @@ -312,7 +312,7 @@ static async void DelVeh(Vehicle veh, int maxtimeout, int vehicle)
Notify.Success("The vehicle has been deleted!");
if (vMenuShared.ConfigManager.GetSettingsBool(vMenuShared.ConfigManager.Setting.pfvmenu_moshnotify_setting))
{
TriggerEvent("mosh_notify:notify", "SUCCESS", "<span class=\"text-white\">The vehicle has been deleted!</span>", "success", "success", 5000);
//TriggerEvent("mosh_notify:notify", "SUCCESS", "<span class=\"text-white\">The vehicle has been deleted!</span>", "success", "success", 5000);
}
}
timeout++;
Expand All @@ -322,7 +322,7 @@ static async void DelVeh(Vehicle veh, int maxtimeout, int vehicle)
Notify.Error($"Failed to delete vehicle, after {maxtimeout} retries.");
if (vMenuShared.ConfigManager.GetSettingsBool(vMenuShared.ConfigManager.Setting.pfvmenu_moshnotify_setting))
{
TriggerEvent("mosh_notify:notify", "ERROR", $"<span class=\"text-white\">Failed to delete vehicle, after {maxtimeout} retries.</span>", "darkred", "error", 5000);
//TriggerEvent("mosh_notify:notify", "ERROR", $"<span class=\"text-white\">Failed to delete vehicle, after {maxtimeout} retries.</span>", "darkred", "error", 5000);
}
}
}
Expand All @@ -332,7 +332,7 @@ static async void DelVeh(Vehicle veh, int maxtimeout, int vehicle)
Notify.Success("The vehicle has been deleted!");
if (vMenuShared.ConfigManager.GetSettingsBool(vMenuShared.ConfigManager.Setting.pfvmenu_moshnotify_setting))
{
TriggerEvent("mosh_notify:notify", "SUCCESS", "<span class=\"text-white\">The vehicle has been deleted!</span>", "success", "success", 5000);
//TriggerEvent("mosh_notify:notify", "SUCCESS", "<span class=\"text-white\">The vehicle has been deleted!</span>", "success", "success", 5000);
}
}
return;
Expand Down
4 changes: 2 additions & 2 deletions vMenu/Noclip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private async Task NoClipHandler()
{
if (vMenuShared.ConfigManager.GetSettingsBool(vMenuShared.ConfigManager.Setting.pfvmenu_moshnotify_setting))
{
TriggerEvent("mosh_notify:notify", "SUCCESS", "<span class=\"text-white\">You are now in NoClip! Press F2 to turn off NoClip.</span>", "success", "success", 5000);
//TriggerEvent("mosh_notify:notify", "SUCCESS", "<span class=\"text-white\">You are now in NoClip! Press F2 to turn off NoClip.</span>", "success", "success", 5000);
}
Scale = RequestScaleformMovie("INSTRUCTIONAL_BUTTONS");
while (!HasScaleformMovieLoaded(Scale))
Expand Down Expand Up @@ -229,7 +229,7 @@ private async Task NoClipHandler()
}
if (vMenuShared.ConfigManager.GetSettingsBool(vMenuShared.ConfigManager.Setting.pfvmenu_moshnotify_setting))
{
TriggerEvent("mosh_notify:notify", "SUCCESS", $"<span class=\"text-white\">Your NoClip speed is: {speeds[MovingSpeed]}.</span>", "success", "success", 3000);
//TriggerEvent("mosh_notify:notify", "SUCCESS", $"<span class=\"text-white\">Your NoClip speed is: {speeds[MovingSpeed]}.</span>", "success", "success", 3000);
}
}

Expand Down
117 changes: 106 additions & 11 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 static class ErrorMessage
public static class ErrorMessage
{
/// <summary>
/// Returns the formatted error message for the specified error type.
Expand Down Expand Up @@ -73,22 +73,45 @@ public static string Get(CommonErrors errorType, string placeholderValue = null)
/// 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 static class Notify
public class Notify : BaseScript
{
/// <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 static void Custom(string message, bool blink = true, bool saveToBrief = true)
public static void Custom(string message, bool blink = true, bool saveToBrief = true, string type = "Custom")
{
SetNotificationTextEntry("CELL_EMAIL_BCON"); // 10x ~a~
foreach (var s in CitizenFX.Core.UI.Screen.StringToArray(message))
string notiftype = vMenuShared.ConfigManager.GetSettingsString(vMenuShared.ConfigManager.Setting.vmenu_notification_type);

if (notiftype.ToLower() == "native")
{
AddTextComponentSubstringPlayerName(s);
SetNotificationTextEntry("CELL_EMAIL_BCON"); // 10x ~a~
foreach (var s in CitizenFX.Core.UI.Screen.StringToArray(message))
{
AddTextComponentSubstringPlayerName(s);
}
DrawNotification(blink, saveToBrief);
}
else if (notiftype.ToLower() == "mosh")
{
if (!((type.ToLower()=="alert")||(type.ToLower()=="error")||(type.ToLower()=="info")||(type.ToLower()=="success")))
TriggerEvent("mosh_notify:notify", type, $"<span class=\"text-black\">{message}</span>", "info", "info", 5000);
}
else if (notiftype.ToLower() == "none")
{

}
else
{
SetNotificationTextEntry("CELL_EMAIL_BCON"); // 10x ~a~
foreach (var s in CitizenFX.Core.UI.Screen.StringToArray(message))
{
AddTextComponentSubstringPlayerName(s);
}
DrawNotification(blink, saveToBrief);
}
DrawNotification(blink, saveToBrief);
}

/// <summary>
Expand All @@ -99,7 +122,25 @@ public static void Custom(string message, bool blink = true, bool saveToBrief =
/// <param name="saveToBrief">Should the notification be logged to the brief (PAUSE menu > INFO > Notifications)?</param>
public static void Alert(string message, bool blink = true, bool saveToBrief = true)
{
Custom("~y~~h~Alert~h~~s~: " + message, blink, saveToBrief);
string notiftype = vMenuShared.ConfigManager.GetSettingsString(vMenuShared.ConfigManager.Setting.vmenu_notification_type);

if (notiftype.ToLower() == "native")
{
Custom("~y~~h~Alert~h~~s~: " + message, blink, saveToBrief, "alert");
}
else if (notiftype.ToLower() == "mosh")
{
TriggerEvent("mosh_notify:notify", "ALERT", $"<span class=\"text-black\">{message}</span>", "warning", "warning", 5000);

}
else if (notiftype.ToLower() == "none")
{

}
else
{
Custom("~y~~h~Alert~h~~s~: " + message, blink, saveToBrief, "alert");
}
}

/// <summary>
Expand All @@ -123,7 +164,25 @@ public static void Alert(CommonErrors errorMessage, bool blink = true, bool save
/// <param name="saveToBrief">Should the notification be logged to the brief (PAUSE menu > INFO > Notifications)?</param>
public static void Error(string message, bool blink = true, bool saveToBrief = true)
{
Custom("~r~~h~Error~h~~s~: " + message, blink, saveToBrief);
string notiftype = vMenuShared.ConfigManager.GetSettingsString(vMenuShared.ConfigManager.Setting.vmenu_notification_type);

if (notiftype.ToLower() == "native")
{
Custom("~r~~h~Error~h~~s~: " + message, blink, saveToBrief, "error");
}
else if (notiftype.ToLower() == "mosh")
{
TriggerEvent("mosh_notify:notify", "ERROR", $"<span class=\"text-black\">{message}</span>", "error", "error", 5000);

}
else if (notiftype.ToLower() == "none")
{

}
else
{
Custom("~r~~h~Error~h~~s~: " + message, blink, saveToBrief, "error");
}
Debug.Write("[vMenu] [ERROR] " + message + "\n");
}

Expand All @@ -148,7 +207,25 @@ public static void Error(CommonErrors errorMessage, bool blink = true, bool save
/// <param name="saveToBrief">Should the notification be logged to the brief (PAUSE menu > INFO > Notifications)?</param>
public static void Info(string message, bool blink = true, bool saveToBrief = true)
{
Custom("~b~~h~Info~h~~s~: " + message, blink, saveToBrief);
string notiftype = vMenuShared.ConfigManager.GetSettingsString(vMenuShared.ConfigManager.Setting.vmenu_notification_type);

if (notiftype.ToLower() == "native")
{
Custom("~b~~h~Info~h~~s~: " + message, blink, saveToBrief, "info");
}
else if (notiftype.ToLower() == "mosh")
{
TriggerEvent("mosh_notify:notify", "INFO", $"<span class=\"text-black\">{message}</span>", "info", "info", 5000);

}
else if (notiftype.ToLower() == "none")
{

}
else
{
Custom("~b~~h~Info~h~~s~: " + message, blink, saveToBrief, "info");
}
}

/// <summary>
Expand All @@ -159,7 +236,25 @@ public static void Info(string message, bool blink = true, bool saveToBrief = tr
/// <param name="saveToBrief">Should the notification be logged to the brief (PAUSE menu > INFO > Notifications)?</param>
public static void Success(string message, bool blink = true, bool saveToBrief = true)
{
Custom("~g~~h~Success~h~~s~: " + message, blink, saveToBrief);
string notiftype = vMenuShared.ConfigManager.GetSettingsString(vMenuShared.ConfigManager.Setting.vmenu_notification_type);

if (notiftype.ToLower() == "native")
{
Custom("~g~~h~Success~h~~s~: " + message, blink, saveToBrief, "success");
}
else if (notiftype.ToLower() == "mosh")
{
TriggerEvent("mosh_notify:notify", "SUCCESS", $"<span class=\"text-black\">{message}</span>", "success", "success", 5000);

}
else if (notiftype.ToLower() == "none")
{

}
else
{
Custom("~g~~h~Success~h~~s~: " + message, blink, saveToBrief, "success");
}
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions vMenuServer/BanManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,18 +209,18 @@ private void BanPlayer([FromSource] Player source, int targetPlayer, double banD

string timeRemaining = GetRemainingTimeMessage(ban.bannedUntil.Subtract(DateTime.Now));
target.Drop($"You are banned from this server. Ban time remaining: {timeRemaining}. Banned by: {ban.bannedBy}. Ban reason: {ban.banReason}. Aditional information: {vMenuShared.ConfigManager.GetSettingsString(vMenuShared.ConfigManager.Setting.vmenu_default_ban_message_information)}.");
source.TriggerEvent("vMenu:Notify", "~g~Target player successfully banned.");
source.TriggerEvent("vMenu:Notify", "~g~Target player successfully banned.", "info");
}
else
{
Log("Player could not be banned because he is exempt from being banned.", LogLevel.error);
source.TriggerEvent("vMenu:Notify", "~r~Could not ban this player, they are exempt from being banned.");
source.TriggerEvent("vMenu:Notify", "~r~Could not ban this player, they are exempt from being banned.", "info");
}
}
else
{
Log("Player is invalid (no longer online) and therefor the banning has failed.", LogLevel.error);
source.TriggerEvent("vMenu:Notify", "Could not ban this player because they already left the server.");
source.TriggerEvent("vMenu:Notify", "Could not ban this player because they already left the server.", "info");
}
}
else
Expand Down
Loading

0 comments on commit 91df039

Please sign in to comment.