feat(Notify): Simplified code, using std::string_view

This commit is contained in:
Yimura 2022-02-21 01:24:27 +01:00
parent 95f646aaad
commit 80ac68bce2
No known key found for this signature in database
GPG Key ID: 3D8FF4397E768682
4 changed files with 28 additions and 25 deletions

View File

@ -15,13 +15,12 @@ namespace big
{ {
int amount_fixed = mobile::mors_mutual::fix_all(); int amount_fixed = mobile::mors_mutual::fix_all();
QUEUE_JOB_BEGIN_CLAUSE(amount_fixed) g_fiber_pool->queue_job([amount_fixed]
{ {
char vehicles_fixed[42]; notify::above_map(
sprintf(vehicles_fixed, "<C>%d</C> vehicle%s been fixed.", amount_fixed, amount_fixed == 1 ? " has" : "s have"); fmt::format("<C>{}</C> vehicle{} been fixed.", amount_fixed, amount_fixed == 1 ? " has" : "s have")
);
notify::above_map(vehicles_fixed); });
}QUEUE_JOB_END_CLAUSE
} }
ImGui::Separator(); ImGui::Separator();

View File

@ -35,9 +35,10 @@ namespace big
if (source_player->m_player_id < 32) if (source_player->m_player_id < 32)
{ {
g_pointers->m_send_event_ack(event_manager, source_player, target_player, event_index, event_handled_bitset); g_pointers->m_send_event_ack(event_manager, source_player, target_player, event_index, event_handled_bitset);
std::string msg = fmt::format("<C>{}</C> possible attempt at freezing entity.", source_player->get_name()); notify::above_map(
notify::above_map(msg); fmt::format("<C>{}</C> possible attempt at freezing entity.", source_player->get_name())
);
return false; return false;
} }
@ -56,8 +57,9 @@ namespace big
if (money >= 2000) if (money >= 2000)
{ {
std::string msg = fmt::format("<C>{}</C> is spawning cash.", source_player->get_name()); notify::above_map(
notify::above_map(msg); fmt::format("<C>{}</C> is spawning cash.", source_player->get_name())
);
} }
break; break;
@ -66,17 +68,19 @@ namespace big
case RockstarEvent::NETWORK_CHECK_CODE_CRCS_EVENT: case RockstarEvent::NETWORK_CHECK_CODE_CRCS_EVENT:
case RockstarEvent::REPORT_MYSELF_EVENT: case RockstarEvent::REPORT_MYSELF_EVENT:
{ {
std::string msg = fmt::format("Detected <C>{}</C> as cheating.", source_player->get_name()); notify::above_map(
notify::above_map(msg); fmt::format("Detected <C>{}</C> as cheating.", source_player->get_name())
);
break; break;
} }
case RockstarEvent::REQUEST_CONTROL_EVENT: case RockstarEvent::REQUEST_CONTROL_EVENT:
{ {
g_pointers->m_send_event_ack(event_manager, source_player, target_player, event_index, event_handled_bitset); g_pointers->m_send_event_ack(event_manager, source_player, target_player, event_index, event_handled_bitset);
std::string msg = fmt::format("Denied player control request from <C>{}</C>", source_player->get_name()); notify::above_map(
notify::above_map(msg); fmt::format("Denied player control request from <C>{}</C>", source_player->get_name())
);
return false; return false;
} }

View File

@ -114,8 +114,9 @@ namespace big
if (strlen(type) != 0) if (strlen(type) != 0)
{ {
std::string msg = fmt::format("~g~BLOCKED SCRIPT EVENT~s~\nFrom: <C>{}</C>\nEvent Type: ~b~{}", player->get_name(), type); notify::above_map(
notify::above_map(msg); fmt::format("~g~BLOCKED SCRIPT EVENT~s~\nFrom: <C>{}</C>\nEvent Type: ~b~{}", player->get_name(), type)
);
return true; return true;
} }

View File

@ -5,14 +5,13 @@
namespace big::notify namespace big::notify
{ {
inline void above_map(const char* text) inline void above_map(std::string_view text)
{ {
HUD::SET_TEXT_OUTLINE(); HUD::SET_TEXT_OUTLINE();
HUD::BEGIN_TEXT_COMMAND_THEFEED_POST("STRING"); HUD::BEGIN_TEXT_COMMAND_THEFEED_POST("STRING");
HUD::ADD_TEXT_COMPONENT_SUBSTRING_PLAYER_NAME(text); HUD::ADD_TEXT_COMPONENT_SUBSTRING_PLAYER_NAME(text.data());
HUD::END_TEXT_COMMAND_THEFEED_POST_TICKER(false, false); HUD::END_TEXT_COMMAND_THEFEED_POST_TICKER(false, false);
} }
inline void above_map(std::string text) { above_map(text.c_str()); }
// deprecated/unused // deprecated/unused
inline void blocked_event(const char* name, Player player) inline void blocked_event(const char* name, Player player)
@ -29,10 +28,10 @@ namespace big::notify
} }
// Shows a busy spinner till the value at the address equals the value passed or if timeout is hit // Shows a busy spinner till the value at the address equals the value passed or if timeout is hit
inline void busy_spinner(const char* text, int* address, int value, int timeout = 15) inline void busy_spinner(std::string_view text, int* address, int value, int timeout = 15)
{ {
HUD::BEGIN_TEXT_COMMAND_BUSYSPINNER_ON("STRING"); HUD::BEGIN_TEXT_COMMAND_BUSYSPINNER_ON("STRING");
HUD::ADD_TEXT_COMPONENT_SUBSTRING_PLAYER_NAME(text); HUD::ADD_TEXT_COMPONENT_SUBSTRING_PLAYER_NAME(text.data());
HUD::END_TEXT_COMMAND_BUSYSPINNER_ON(3); HUD::END_TEXT_COMMAND_BUSYSPINNER_ON(3);
for (size_t i = 0; *address != value && i < (size_t)timeout * 100; i++) for (size_t i = 0; *address != value && i < (size_t)timeout * 100; i++)
@ -41,10 +40,10 @@ namespace big::notify
HUD::BUSYSPINNER_OFF(); HUD::BUSYSPINNER_OFF();
} }
inline void display_help_text(const char* text) inline void display_help_text(std::string_view text)
{ {
HUD::BEGIN_TEXT_COMMAND_DISPLAY_HELP("STRING"); HUD::BEGIN_TEXT_COMMAND_DISPLAY_HELP("STRING");
HUD::ADD_TEXT_COMPONENT_SUBSTRING_PLAYER_NAME(text); HUD::ADD_TEXT_COMPONENT_SUBSTRING_PLAYER_NAME(text.data());
HUD::END_TEXT_COMMAND_DISPLAY_HELP(0, 0, 1, -1); HUD::END_TEXT_COMMAND_DISPLAY_HELP(0, 0, 1, -1);
} }