refactor: Load tooltips from commands and disable unusable command buttons (#777)

* Set tooltips from command descriptions
* Disable unusable commands
This commit is contained in:
pelecanidae 2022-12-29 20:43:31 -05:00 committed by GitHub
parent 2b1aee98de
commit bd7bc362e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 8 deletions

View File

@ -48,6 +48,8 @@ namespace big
static command* command = command::get(rage::consteval_joaat(cmd_str.value));
if (ImGui::Button(label_override.value_or(command->get_label()).data()))
command->call(args);
if (ImGui::IsItemHovered())
ImGui::SetTooltip(command->get_description().c_str());
}
template<template_str cmd_str>
@ -56,6 +58,8 @@ namespace big
static player_command* command = (player_command*)command::get(rage::consteval_joaat(cmd_str.value));
if (ImGui::Button(label_override.value_or(command->get_label()).data()))
command->call(player, args);
if (ImGui::IsItemHovered())
ImGui::SetTooltip(command->get_description().c_str());
}
template<template_str cmd_str>
@ -64,6 +68,18 @@ namespace big
static bool_command* command = (bool_command*)command::get(rage::consteval_joaat(cmd_str.value));
if (ImGui::Checkbox(label_override.value_or(command->get_label()).data(), &command->is_enabled()))
command->refresh();
if (ImGui::IsItemHovered())
ImGui::SetTooltip(command->get_description().c_str());
}
template<typename PredicateFn, typename ComponentsFn>
static void disable_unless(PredicateFn predicate_fn, ComponentsFn components_fn) {
auto const result = predicate_fn();
if (!result)
ImGui::BeginDisabled(true);
components_fn();
if (!result)
ImGui::EndDisabled();
}
};
}

View File

@ -8,19 +8,21 @@ namespace big
{
if (ImGui::TreeNode("Kick"))
{
auto const is_session_host = [] { return gta_util::get_network()->m_game_session_ptr->is_host(); };
components::player_command_button<"breakup">(g_player_service->get_selected());
components::player_command_button<"lckick">(g_player_service->get_selected());
components::disable_unless(std::not_fn(is_session_host), [] {
components::player_command_button<"lckick">(g_player_service->get_selected());
});
components::player_command_button<"bailkick">(g_player_service->get_selected());
components::player_command_button<"nfkick">(g_player_service->get_selected());
components::player_command_button<"oomkick">(g_player_service->get_selected());
components::player_command_button<"shkick">(g_player_service->get_selected());
components::player_command_button<"endkick">(g_player_service->get_selected());
if (ImGui::IsItemHovered())
ImGui::SetTooltip("The kick can take around 10 seconds to work");
components::player_command_button<"hostkick">(g_player_service->get_selected());
components::disable_unless(is_session_host, [] {
components::player_command_button<"hostkick">(g_player_service->get_selected());
});
components::player_command_button<"desync">(g_player_service->get_selected());
if (ImGui::IsItemHovered())
ImGui::SetTooltip("The kick can take around 10 seconds to work");
ImGui::TreePop();
}

View File

@ -54,8 +54,6 @@ namespace big
components::command_checkbox<"mobileradio">();
ImGui::Checkbox("Dance Mode", &g.self.dance_mode);
if (ImGui::IsItemHovered())
ImGui::SetTooltip("Hold Right DPAD or E to enter dance mode");
ImGui::EndGroup();