feat(hud): Add force show HUD component and replaced some hard-coded values. (#628)

This commit is contained in:
SpaghettDev 2022-11-26 20:42:58 +01:00 committed by GitHub
parent 89ad2755ac
commit 2db1ce1c48
5 changed files with 44 additions and 17 deletions

View File

@ -1,16 +1,18 @@
#include "backend/looped/looped.hpp" #include "backend/looped/looped.hpp"
#include "natives.hpp" #include "natives.hpp"
#include "core/data/hud_component_names.hpp" #include "core/data/hud_component_names.hpp"
#include <algorithm>
namespace big namespace big
{ {
static bool bLastHideRadar = false; static bool bLastHideRadar = false;
static bool bHasHUDBeenHidden = false;
void looped::self_hud() void looped::self_hud()
{ {
const bool bHideRadar = g->self.hide_radar; const bool bHideRadar = g->self.hide_radar;
const bool bHideAmmo = g->self.hide_ammo; const bool bHideAmmo = g->self.hide_ammo;
const bool bForceShowElement = g->self.force_show_hud_element;
const bool bForceShowHUD = g->self.force_show_hud;
auto& bHudComponents = g->self.hud_components_states; auto& bHudComponents = g->self.hud_components_states;
if (bHideRadar) if (bHideRadar)
@ -28,6 +30,11 @@ namespace big
HUD::DISPLAY_AMMO_THIS_FRAME(false); HUD::DISPLAY_AMMO_THIS_FRAME(false);
} }
if (bForceShowHUD) {
HUD::DISPLAY_HUD_WHEN_NOT_IN_STATE_OF_PLAY_THIS_FRAME();
HUD::DISPLAY_HUD_WHEN_PAUSED_THIS_FRAME();
}
if ( if (
std::all_of( std::all_of(
std::begin(bHudComponents), std::begin(bHudComponents),
@ -36,14 +43,22 @@ namespace big
) )
) { ) {
HUD::DISPLAY_HUD(false); HUD::DISPLAY_HUD(false);
bHasHUDBeenHidden = true;
} }
else else
{ {
HUD::DISPLAY_HUD(true); HUD::DISPLAY_HUD(true);
for (int i = 0; i < (int)HudComponents::HUD_WEAPONS; i++) bHasHUDBeenHidden = false;
}
if (!bHasHUDBeenHidden)
{
for (int i = 0; i < static_cast<int>(HudComponents::HUD_WEAPONS); i++)
{ {
if (bHudComponents[i]) if (bHudComponents[i])
HUD::HIDE_HUD_COMPONENT_THIS_FRAME(i + 1); HUD::HIDE_HUD_COMPONENT_THIS_FRAME(i + 1);
else if (!bHudComponents[i] && bForceShowElement)
HUD::SHOW_HUD_COMPONENT_THIS_FRAME(i + 1);
} }
} }
} }

View File

@ -1,12 +1,13 @@
#include "backend/looped/looped.hpp" #include "backend/looped/looped.hpp"
#include "natives.hpp" #include "natives.hpp"
#include "core/enums.hpp"
namespace big namespace big
{ {
void looped::weapons_force_crosshairs() void looped::weapons_force_crosshairs()
{ {
if (g->weapons.force_crosshairs) { if (g->weapons.force_crosshairs) {
HUD::SHOW_HUD_COMPONENT_THIS_FRAME(14 /*RETICLE*/); HUD::SHOW_HUD_COMPONENT_THIS_FRAME(static_cast<int>(HudComponents::RETICLE));
} }
} }
} }

View File

@ -184,6 +184,8 @@ namespace big
bool hide_ammo = false; bool hide_ammo = false;
int selected_hud_component = 1; int selected_hud_component = 1;
bool hud_components_states[(int)HudComponents::HUD_WEAPONS] = { false }; bool hud_components_states[(int)HudComponents::HUD_WEAPONS] = { false };
bool force_show_hud_element = false;
bool force_show_hud = false;
bool mobile_radio = false; bool mobile_radio = false;
}; };
@ -640,6 +642,8 @@ namespace big
this->self.selected_hud_component = j["self"]["selected_hud_component"]; this->self.selected_hud_component = j["self"]["selected_hud_component"];
for (int i = 0; i < (int)HudComponents::HUD_WEAPONS; i++) for (int i = 0; i < (int)HudComponents::HUD_WEAPONS; i++)
this->self.hud_components_states[i] = j["self"]["hud_components_states"].at(i); this->self.hud_components_states[i] = j["self"]["hud_components_states"].at(i);
this->self.force_show_hud_element = j["self"]["force_show_hud_element"];
this->self.force_show_hud = j["self"]["force_show_hud"];
this->self.unlimited_oxygen = j["self"]["unlimited_oxygen"]; this->self.unlimited_oxygen = j["self"]["unlimited_oxygen"];
this->self.no_water_collision = j["self"]["no_water_collision"]; this->self.no_water_collision = j["self"]["no_water_collision"];
this->self.mobile_radio = j["self"]["mobile_radio"]; this->self.mobile_radio = j["self"]["mobile_radio"];
@ -979,6 +983,8 @@ namespace big
this->self.hud_components_states[20], this->self.hud_components_states[20],
this->self.hud_components_states[21] }) this->self.hud_components_states[21] })
}, },
{ "force_show_hud_element", this->self.force_show_hud_element },
{ "force_show_hud", this->self.force_show_hud },
{ "unlimited_oxygen", this->self.unlimited_oxygen }, { "unlimited_oxygen", this->self.unlimited_oxygen },
{ "no_water_collision", this->self.no_water_collision }, { "no_water_collision", this->self.no_water_collision },
{ "mobile_radio", this->self.mobile_radio }, { "mobile_radio", this->self.mobile_radio },

View File

@ -313,7 +313,7 @@ namespace big
if (g_context_menu_service->enabled) if (g_context_menu_service->enabled)
{ {
HUD::SHOW_HUD_COMPONENT_THIS_FRAME(14 /*RETICLE*/); HUD::SHOW_HUD_COMPONENT_THIS_FRAME(static_cast<int>(HudComponents::RETICLE));
g_context_menu_service->get_entity_closest_to_screen_center(); g_context_menu_service->get_entity_closest_to_screen_center();

View File

@ -75,11 +75,8 @@ namespace big
if (g->self.invisibility) { if (g->self.invisibility) {
ImGui::Checkbox("Locally Visible", &g->self.local_visibility); ImGui::Checkbox("Locally Visible", &g->self.local_visibility);
} }
ImGui::Checkbox("Keep Player Clean", &g->self.clean_player); ImGui::Checkbox("Keep Player Clean", &g->self.clean_player);
ImGui::Checkbox("No Collision", &g->self.no_collision); ImGui::Checkbox("No Collision", &g->self.no_collision);
ImGui::Checkbox("Mobile Radio", &g->self.mobile_radio); ImGui::Checkbox("Mobile Radio", &g->self.mobile_radio);
ImGui::EndGroup(); ImGui::EndGroup();
@ -173,6 +170,10 @@ namespace big
ImGui::Checkbox("Hide Ammo", &g->self.hide_ammo); ImGui::Checkbox("Hide Ammo", &g->self.hide_ammo);
ImGui::SameLine();
ImGui::Checkbox("Force show HUD", &g->self.force_show_hud);
ImGui::Combo("##hud_comp_combo", &g->self.selected_hud_component, hud_component_names, (int)HudComponents::HUD_WEAPONS); ImGui::Combo("##hud_comp_combo", &g->self.selected_hud_component, hud_component_names, (int)HudComponents::HUD_WEAPONS);
ImGui::SameLine(); ImGui::SameLine();
components::button("Hide", [] { components::button("Hide", [] {
@ -200,6 +201,10 @@ namespace big
g->self.hud_components_states[i] = false; g->self.hud_components_states[i] = false;
} }
}); });
ImGui::SameLine();
ImGui::Checkbox("Force show HUD element", &g->self.force_show_hud_element);
if (ImGui::IsItemHovered())
ImGui::SetTooltip("To force show a HUD specific element, click Hide all then click Show on the desired element.");
ImGui::EndGroup(); ImGui::EndGroup();