feature(GUI): Notifications are gui styled. (#69)

* feature(GUI): Notifications are gui styled.

* feature(GUI): Removed ~r~
This commit is contained in:
LiamD-Flop 2022-03-02 00:21:29 +01:00 committed by GitHub
parent 665371e116
commit dcdeebf415
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 201 additions and 58 deletions

View File

@ -2,7 +2,6 @@
#include "gta_util.hpp"
#include "script_local.hpp"
#include "util/math.hpp"
#include "util/notify.hpp"
#include "util/scripts.hpp"
namespace big
@ -38,7 +37,7 @@ namespace big
busy = false;
g->vehicle.ls_customs = false;
notify::above_map("You aren't in a vehicle.");
g_notification_service->push_warning("LS Customs", "You aren't in a vehicle.");
return;
}

View File

@ -1,7 +1,6 @@
#include "backend/looped/looped.hpp"
#include "core/enums.hpp"
#include "util/entity.hpp"
#include "util/notify.hpp"
namespace big
{
@ -30,7 +29,7 @@ namespace big
entity::cage_ped(entity);
}
}
else notify::above_map("No entity found.");
else g_notification_service->push_error("Weapons", "No entity found.");
}
}
}

View File

@ -2,7 +2,6 @@
#include "core/enums.hpp"
#include "util/entity.hpp"
#include "util/math.hpp"
#include "util/notify.hpp"
namespace big
{
@ -28,7 +27,7 @@ namespace big
{
if (ENTITY::IS_ENTITY_A_PED(entity) && PED::IS_PED_A_PLAYER(entity))
{
notify::above_map("You can't delete player entities!");
g_notification_service->push_error("Weapons", "You can't delete player entities!");
}
else
{
@ -38,7 +37,7 @@ namespace big
if (dist > 500)
{
notify::above_map("Entity is too far.");
g_notification_service->push_error("Weapons", "Entity is too far.");
}
else
{
@ -46,11 +45,11 @@ namespace big
{
entity::delete_entity(entity);
}
else notify::above_map("~r~Failed to take control of entity.");
else g_notification_service->push_error("Weapons", "Failed to take control of entity.");
}
}
}
else notify::above_map("No entity found.");
else g_notification_service->push_error("Weapons", "No entity found.");
}
}
}

View File

@ -2,7 +2,6 @@
#include "core/enums.hpp"
#include "util/entity.hpp"
#include "util/math.hpp"
#include "util/notify.hpp"
namespace big
{
@ -37,7 +36,7 @@ namespace big
{
ent = 0;
notify::above_map("You can't move player entities!");
g_notification_service->push_warning("Weapons", "You can't move player entities!");
}
else
{
@ -48,7 +47,7 @@ namespace big
{
ent = 0;
notify::above_map("Entity is too far.");
g_notification_service->push_warning("Weapons", "Entity is too far.");
}
else
{
@ -56,7 +55,7 @@ namespace big
{
TASK::SET_HIGH_FALL_TASK(ent, 0, 0, 0);
notify::above_map("Selected entity at crosshair.");
g_notification_service->push_warning("Weapons", "Selected entity at crosshair.");
}
}
}
@ -65,7 +64,7 @@ namespace big
{
ent = 0;
notify::above_map("No entity found.");
g_notification_service->push_warning("Weapons", "No entity found.");
}
}
@ -80,7 +79,7 @@ namespace big
{
ent = 0;
return notify::above_map("Failed to take control of entity.");
return g_notification_service->push_warning("Weapons", "Failed to take control of entity.");
}
ENTITY::SET_ENTITY_COLLISION(ent, false, false);
@ -109,7 +108,7 @@ namespace big
ent = 0;
notify::above_map("Released entity.");
g_notification_service->push("Weapons", "Released entity.");
}
}
}

View File

@ -2,7 +2,6 @@
#include "core/enums.hpp"
#include "util/entity.hpp"
#include "util/vehicle.hpp"
#include "util/notify.hpp"
namespace big
{
@ -32,10 +31,10 @@ namespace big
}
else
{
notify::above_map("Entity is not a vehicle.");
g_notification_service->push_warning("Weapons", "Entity is not a vehicle.");
}
}
else notify::above_map("No entity found.");
else g_notification_service->push_warning("Weapons", "No entity found.");
}
}
}

View File

@ -1,7 +1,6 @@
#include "backend/looped/looped.hpp"
#include "core/enums.hpp"
#include "util/entity.hpp"
#include "util/notify.hpp"
namespace big
{
@ -38,9 +37,9 @@ namespace big
PED::SET_PED_INTO_VEHICLE(PLAYER::PLAYER_PED_ID(), ent, -1);
}
else notify::above_map("Entity is not a vehicle.");
else g_notification_service->push_warning("Weapons", "Entity is not a vehicle.");
}
else notify::above_map("No entity found.");
else g_notification_service->push_warning("Weapons", "No entity found.");
}
}
}

View File

@ -54,6 +54,8 @@
#include "gta/natives.hpp"
#include "CPed.hpp"
#include "services/notification_service.hpp"
namespace big
{
using namespace std::chrono_literals;

View File

@ -14,7 +14,7 @@
#include <imgui.h>
#include "views/view.hpp"
#include "util/notify.hpp"
#include "services/notification_service.hpp"
namespace big
{
@ -87,9 +87,18 @@ namespace big
EXCEPT_CLAUSE
}
void gui::always_draw()
{
TRY_CLAUSE
{
view::always();
}
EXCEPT_CLAUSE
}
void gui::script_init()
{
notify::display_help_text("Press INSERT on your keyboard to open Yim's Mod Menu.");
g_notification_service->push("Welcome", "Loaded YimMenu. Press INSERT to open");
}
void gui::script_on_tick()

View File

@ -8,6 +8,7 @@ namespace big
public:
void dx_init();
void dx_on_tick();
void always_draw();
void script_init();
void script_on_tick();

View File

@ -1,6 +1,5 @@
#include "hooking.hpp"
#include "natives.hpp"
#include "util/notify.hpp"
namespace big
{
@ -13,9 +12,9 @@ namespace big
case RAGE_JOAAT("MPPLY_EXPLOITS"):
case RAGE_JOAAT("MPPLY_TC_ANNOYINGME"):
case RAGE_JOAAT("MPPLY_TC_HATE"):
std::string report = fmt::format("~g~BLOCKED REPORT~s~\nFrom: <C>{}</C>", sender->get_name());
std::string report = fmt::format("From: {}", sender->get_name());
notify::above_map(report);
g_notification_service->push_warning("BLOCKED REPORT", report);
return true;
}

View File

@ -2,7 +2,6 @@
#include "gta/net_game_event.hpp"
#include "hooking.hpp"
#include "natives.hpp"
#include "util/notify.hpp"
namespace big
{
@ -36,8 +35,8 @@ namespace big
{
g_pointers->m_send_event_ack(event_manager, source_player, target_player, event_index, event_handled_bitset);
notify::above_map(
fmt::format("<C>{}</C> possible attempt at freezing entity.", source_player->get_name())
g_notification_service->push_warning("Protection",
fmt::format("{} possible attempt at freezing entity.", source_player->get_name())
);
return false;
@ -57,8 +56,8 @@ namespace big
if (money >= 2000)
{
notify::above_map(
fmt::format("<C>{}</C> is spawning cash.", source_player->get_name())
g_notification_service->push_warning("Protection",
fmt::format("{} is spawning cash.", source_player->get_name())
);
}
@ -68,8 +67,8 @@ namespace big
case RockstarEvent::NETWORK_CHECK_CODE_CRCS_EVENT:
case RockstarEvent::REPORT_MYSELF_EVENT:
{
notify::above_map(
fmt::format("Detected <C>{}</C> as cheating.", source_player->get_name())
g_notification_service->push_warning("Protection",
fmt::format("Detected {} as cheating.", source_player->get_name())
);
break;
@ -78,8 +77,8 @@ namespace big
{
g_pointers->m_send_event_ack(event_manager, source_player, target_player, event_index, event_handled_bitset);
notify::above_map(
fmt::format("Denied player control request from <C>{}</C>", source_player->get_name())
g_notification_service->push_warning("Protection",
fmt::format("Denied player control request from {}", source_player->get_name())
);
return false;

View File

@ -1,6 +1,5 @@
#include "hooking.hpp"
#include "gta/enums.hpp"
#include "util/notify.hpp"
namespace big
{
@ -114,8 +113,8 @@ namespace big
if (strlen(type) != 0)
{
notify::above_map(
fmt::format("~g~BLOCKED SCRIPT EVENT~s~\nFrom: <C>{}</C>\nEvent Type: ~b~{}", player->get_name(), type)
g_notification_service->push_warning("Protection",
fmt::format("BLOCKED SCRIPT EVENT\nFrom: {}\nEvent Type: {}", player->get_name(), type)
);
return true;

View File

@ -14,6 +14,7 @@
#include "services/globals_service.hpp"
#include "services/player_service.hpp"
#include "services/mobile_service.hpp"
#include "services/notification_service.hpp"
#include "services/vehicle_service.hpp"
BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID)
@ -64,6 +65,7 @@ BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID)
auto globals_service_instace = std::make_unique<globals_service>();
auto mobile_service_instance = std::make_unique<mobile_service>();
auto notification_service_instance = std::make_unique<notification_service>();
auto player_service_instance = std::make_unique<player_service>();
auto vehicle_service_instance = std::make_unique<vehicle_service>();
LOG(INFO) << "Registered service instances...";

View File

@ -83,6 +83,7 @@ namespace big
{
g_gui.dx_on_tick();
}
g_gui.always_draw();
ImGui::Render();
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());

View File

@ -0,0 +1,58 @@
#include "notification_service.hpp"
namespace big
{
notification_service::notification_service()
{
g_notification_service = this;
}
notification_service::~notification_service()
{
g_notification_service = nullptr;
}
void notification_service::push(notification n)
{
this->notifications.emplace(std::hash<std::string>{}(n.message), n);
}
void notification_service::push(std::string title, std::string message)
{
this->push({ NotificationType::INFO, title, message, std::chrono::system_clock::now(), 3000.f , 1.f});
}
void notification_service::push_warning(std::string title, std::string message)
{
this->push({ NotificationType::WARNING, title, message, std::chrono::system_clock::now(), 3000.f , 1.f });
}
void notification_service::push_error(std::string title, std::string message)
{
this->push({ NotificationType::DANGER, title, message, std::chrono::system_clock::now(), 3000.f , 1.f });
}
std::vector<notification> notification_service::get()
{
std::vector<notification> notifications_to_sent;
std::vector<std::size_t> to_remove;
for (auto& n : this->notifications) {
std::chrono::time_point<std::chrono::system_clock> curTime = std::chrono::system_clock::now();
const float time_diff = (float)std::chrono::duration_cast<std::chrono::milliseconds>(curTime - n.second.created_on).count();
n.second.alpha = 1;
if (n.second.destroy_in <= time_diff) {
n.second.alpha = 1.f - ((time_diff - n.second.destroy_in) / 600);
n.second.alpha = n.second.alpha < 0.f ? 0.f : n.second.alpha;
}
if (n.second.alpha > 0.f)
notifications_to_sent.push_back(n.second);
else to_remove.push_back(n.first);
}
for (std::size_t k : to_remove)
this->notifications.erase(k);
return notifications_to_sent;
}
}

View File

@ -0,0 +1,45 @@
#pragma once
namespace big
{
enum class NotificationType {
INFO,
SUCCESS,
WARNING,
DANGER,
};
struct notification
{
NotificationType type;
const std::string title;
const std::string message;
const std::chrono::time_point<std::chrono::system_clock> created_on;
const float destroy_in;
float alpha;
};
class notification_service final
{
std::unordered_map<std::size_t, notification> notifications;
public:
notification_service();
virtual ~notification_service();
void push(notification);
void push(std::string, std::string);
void push_warning(std::string, std::string);
void push_error(std::string, std::string);
std::vector<notification> get();
std::map<NotificationType, ImVec4> notification_colors = {
{NotificationType::INFO, ImVec4(0.80f, 0.80f, 0.83f, 1.00f)},
{NotificationType::SUCCESS, ImVec4(0.29f, 0.69f, 0.34f, 1.00f)},
{NotificationType::WARNING, ImVec4(0.69f ,0.49f, 0.29f, 1.00f) },
{NotificationType::DANGER, ImVec4(0.69f, 0.29f , 0.29f, 1.00f)},
};
};
inline notification_service* g_notification_service{};
}

View File

@ -87,7 +87,7 @@ namespace big::mobile
inline void summon_vehicle_by_index(int veh_idx)
{
if (*mechanic_global.at(958).as<int*>() != -1)
return notify::display_help_text("Mechanic is not ready to deliver a vehicle right now.");
return g_notification_service->push_warning("Vehicle", "Mechanic is not ready to deliver a vehicle right now.");
TASK::CLEAR_PED_TASKS_IMMEDIATELY(PLAYER::PLAYER_PED_ID());

View File

@ -1,7 +1,6 @@
#pragma once
#include "blip.hpp"
#include "entity.hpp"
#include "notify.hpp"
namespace big::teleport
{
@ -11,14 +10,14 @@ namespace big::teleport
if (ENTITY::IS_ENTITY_DEAD(ent, true))
{
notify::display_help_text("Target player is dead.");
g_notification_service->push_warning("Teleport", "Target player is dead.");
return false;
}
if (!PED::IS_PED_IN_ANY_VEHICLE(ent, true))
{
notify::display_help_text("Target player is not in a vehicle.");
g_notification_service->push_warning("Teleport", "Target player is not in a vehicle.");
return false;
}
@ -30,7 +29,7 @@ namespace big::teleport
if (entity::take_control_of(ent))
ENTITY::SET_ENTITY_COORDS(ent, location.x, location.y, location.z, 0, 0, 0, 0);
else
notify::display_help_text("Failed to take control of player vehicle.");
g_notification_service->push_warning("Teleport", "Failed to take control of player vehicle.");
return true;
}
@ -69,7 +68,7 @@ namespace big::teleport
{
if (!veh)
{
notify::display_help_text("Player is not in a vehicle.");
g_notification_service->push_warning("Teleport", "Player is not in a vehicle.");
return false;
}
@ -82,7 +81,7 @@ namespace big::teleport
if (seat_index == 255)
{
notify::display_help_text("No seats are free in the player vehicle.");
g_notification_service->push_warning("Teleport", "No seats are free in the player vehicle.");
return false;
}
@ -136,7 +135,7 @@ namespace big::teleport
{
if (!to_blip((int)BlipIcons::Waypoint))
{
notify::above_map("Failed to find waypoint position");
g_notification_service->push_warning("Teleport", "Failed to find waypoint position");
return false;
}

View File

@ -3,7 +3,6 @@
#include "gta/joaat.hpp"
#include "math.hpp"
#include "natives.hpp"
#include "notify.hpp"
#include "pointers.hpp"
#include "script.hpp"
#include "teleport.hpp"
@ -16,7 +15,7 @@ namespace big::vehicle
teleport::load_ground_at_3dcoord(vecVehicleLocation);
if (!entity::take_control_of(veh))
return notify::above_map("Failed to take control of remote vehicle.");
return g_notification_service->push_warning("Vehicle", "Failed to take control of remote vehicle.");
ENTITY::SET_ENTITY_COORDS(veh, location.x, location.y, location.z + 1.f, 0, 0, 0, 0);
ENTITY::SET_ENTITY_HEADING(veh, ENTITY::GET_ENTITY_HEADING(PLAYER::PLAYER_PED_ID()));
@ -59,7 +58,7 @@ namespace big::vehicle
}
if (!STREAMING::HAS_MODEL_LOADED(hash))
{
notify::above_map("~r~Failed to spawn model, did you give an incorrect model?");
g_notification_service->push_warning("Spawn", "Failed to spawn model, did you give an incorrect model?");
return -1;
}

View File

@ -40,6 +40,7 @@ namespace big
static void settings();
static void spoofing();
static void navigation();
static void notifications();
static void active_view();
inline static animator window_animator = animator();
@ -67,5 +68,10 @@ namespace big
active_view();
navigation();
}
static void always()
{
notifications();
}
};
}

View File

@ -30,7 +30,7 @@ namespace big
ImGui::SetNextWindowPos({ tabs_open_animation, 0.f }, ImGuiCond_Always);
ImGui::SetNextWindowSize({ (float)g->window.x * 0.3f, (float)g->window.y }, ImGuiCond_Always);
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0.10f, 0.09f, 0.12f, 1.00f));
if (ImGui::Begin("main", 0, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoNav))
if (ImGui::Begin("main", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoNav))
{
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, alpha);
if (current_tab->tab != tabs::NONE)

View File

@ -2,7 +2,6 @@
#include "fiber_pool.hpp"
#include "script.hpp"
#include "util/mobile.hpp"
#include "util/notify.hpp"
#include "services/mobile_service.hpp"
namespace big
@ -10,8 +9,8 @@ namespace big
void view::mobile() {
components::button("Mors Mutual Fix All Vehicles", [] {
int amount_fixed = mobile::mors_mutual::fix_all();
notify::above_map(
fmt::format("<C>{}</C> vehicle{} been fixed.", amount_fixed, amount_fixed == 1 ? " has" : "s have")
g_notification_service->push("Mobile",
fmt::format("{} vehicle{} been fixed.", amount_fixed, amount_fixed == 1 ? " has" : "s have")
);
});

View File

@ -0,0 +1,32 @@
#include "view.hpp"
#include "services/notification_service.hpp"
namespace big
{
void view::notifications()
{
ImGui::SetNextWindowSize({ (float)g->window.x * 0.2f, (float)g->window.y });
ImGui::SetNextWindowPos({ (float)g->window.x - (float)g->window.x * 0.2f, 0 });
if (ImGui::Begin("notifications", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoBackground))
{
std::vector<notification> notifications = g_notification_service->get();
for (int i = 0; i < notifications.size(); i++)
{
notification& n = notifications[i];
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, n.alpha);
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.10f, 0.09f, 0.12f, 1.00f));
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0.10f, 0.09f, 0.12f, 1.00f));
ImGui::SetNextWindowBgAlpha(n.alpha);
ImGui::BeginChild(i, ImVec2(0, 75.f + (float)(20 * (int)(n.message.size() / 28) + 20 * (float)std::count(n.message.begin(), n.message.end(), '\n'))), true, ImGuiWindowFlags_NoScrollbar);
ImGui::Text(n.title.c_str());
ImGui::PushStyleColor(ImGuiCol_Text, g_notification_service->notification_colors.at(n.type));
ImGui::TextWrapped(n.message.c_str());
ImGui::PopStyleColor();
ImGui::EndChild();
ImGui::PopStyleVar();
ImGui::PopStyleColor(2);
}
}
}
}

View File

@ -4,7 +4,6 @@
#include "script_global.hpp"
#include "util/entity.hpp"
#include "util/player.hpp"
#include "util/notify.hpp"
#include "util/session.hpp"
namespace big
@ -79,7 +78,7 @@ namespace big
}
if (!STREAMING::HAS_MODEL_LOADED(hash))
{
notify::above_map("~r~Failed to spawn model, did you give an incorrect model?");
g_notification_service->push_error("Self", "Failed to spawn model, did you give an incorrect model ? ");
return;
}

View File

@ -28,7 +28,7 @@ namespace big
components::button("Bring Personal Vehicle", [] {
Vehicle veh = globals::get_personal_vehicle();
if (ENTITY::IS_ENTITY_DEAD(veh, false)) return notify::above_map("Invalid vehicle handle...");
if (ENTITY::IS_ENTITY_DEAD(veh, false)) return g_notification_service->push_error("Teleport", "Invalid vehicle handle...");
Vector3 location = ENTITY::GET_ENTITY_COORDS(PLAYER::PLAYER_PED_ID(), true);
@ -37,7 +37,7 @@ namespace big
components::button("Teleport to Personal Vehicle", [] {
Vehicle veh = globals::get_personal_vehicle();
if (ENTITY::IS_ENTITY_DEAD(veh, false)) return notify::above_map("Invalid vehicle handle...");
if (ENTITY::IS_ENTITY_DEAD(veh, false)) return g_notification_service->push_error("Teleport", "Invalid vehicle handle...");
teleport::to_coords(
ENTITY::GET_ENTITY_COORDS(veh, true)