feat: command executor (search bar) (#1029)

This commit is contained in:
Johann
2023-03-11 00:06:09 +01:00
committed by GitHub
parent 4af9c7f258
commit 10bbf1f4bb
16 changed files with 250 additions and 73 deletions

View File

@ -29,5 +29,6 @@ namespace big
g_gui_service->get_selected()->func();
ImGui::PopStyleVar();
}
ImGui::End();
}
}

View File

@ -0,0 +1,72 @@
#include "backend/context/default_command_context.hpp"
#include "gui.hpp"
#include "pointers.hpp"
#include "services/hotkey/hotkey_service.hpp"
#include "views/view.hpp"
namespace big
{
void view::cmd_executor()
{
if (!g.cmd_executor.enabled)
return;
float screen_x = (float)*g_pointers->m_resolution_x;
float screen_y = (float)*g_pointers->m_resolution_y;
ImGui::SetNextWindowPos(ImVec2(screen_x * 0.25f, screen_y * 0.2f), ImGuiCond_Always);
ImGui::SetNextWindowBgAlpha(0.65f);
ImGui::SetNextWindowSize({screen_x * 0.5f, -1});
if (ImGui::Begin("cmd_executor", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav))
{
static char command_buffer[255];
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {10.f, 15.f});
components::sub_title("CMD_EXECUTOR_TITLE"_T);
// set focus by default on input box
ImGui::SetKeyboardFocusHere(0);
ImGui::SetNextItemWidth(screen_x * 0.5f);
components::input_text_with_hint("", "CMD_EXECUTOR_TYPE_CMD"_T, command_buffer, sizeof(command_buffer), ImGuiInputTextFlags_EnterReturnsTrue, [] {
if (command::process(command_buffer, std::make_shared<default_command_context>(), true))
{
g.cmd_executor.enabled = false;
command_buffer[0] = 0;
}
});
components::small_text("CMD_EXECUTOR_MULTIPLE_CMDS"_T);
ImGui::Spacing();
auto possible_commands = command::get_suggestions(command_buffer);
if (possible_commands.size() == 0)
{
ImGui::Text("CMD_EXECUTOR_NO_CMD"_T.data());
}
else
{
for (auto cmd : possible_commands)
{
ImGui::Text(std::vformat("CMD_EXECUTOR_CMD_TEMPLATE"_T,
std::make_format_args(cmd->get_name(),
cmd->get_label(),
cmd->get_description(),
cmd->get_num_args() ? cmd->get_num_args().value() : 0))
.data());
// check if we aren't on the last iteration
if (cmd != possible_commands.back())
ImGui::Separator();
}
}
ImGui::PopStyleVar();
}
ImGui::End();
}
bool_command
g_cmd_executor("cmdexecutor", "Toggle Command Executor", "Toggles the command executor window", g.cmd_executor.enabled, false);
}

View File

@ -35,5 +35,6 @@ namespace big
}
ImGui::PopStyleColor();
}
ImGui::End();
}
}

View File

@ -8,7 +8,7 @@ namespace big
ImGui::SetNextWindowPos({10.f, 100.f * g.window.gui_scale}, ImGuiCond_Always);
ImGui::SetNextWindowSize({300.f * g.window.gui_scale, 0.f}, ImGuiCond_Always);
if (ImGui::Begin("navigation", 0, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoNav))
if (ImGui::Begin("navigation", 0, window_flags))
{
g_gui_service->reset_nav_size();
for (std::pair<tabs, navigation_struct> navItem : g_gui_service->get_navigation())

View File

@ -9,7 +9,7 @@ namespace big
ImGui::PushItemWidth(350.f);
if (ImGui::Hotkey("Menu Toggle", &g.settings.hotkeys.menu_toggle))
g.settings.hotkeys.editing_menu_toggle = true;// make our menu reappear
g.settings.hotkeys.editing_menu_toggle = true; // make our menu reappear
if (ImGui::Hotkey("Teleport to waypoint", &g.settings.hotkeys.teleport_waypoint))
g_hotkey_service->update_hotkey("waypoint", g.settings.hotkeys.teleport_waypoint);
@ -42,6 +42,8 @@ namespace big
g_hotkey_service->update_hotkey("localinvisveh", g.settings.hotkeys.localinvisveh);
if (ImGui::Hotkey("Rage Quit (Like Alt + F4)", &g.settings.hotkeys.fast_quit))
g_hotkey_service->update_hotkey("fastquit", g.settings.hotkeys.fast_quit);
if (ImGui::Hotkey("Toggle Command Executor", &g.settings.hotkeys.cmd_excecutor))
g_hotkey_service->update_hotkey("cmdexecutor", g.settings.hotkeys.cmd_excecutor);
ImGui::PopItemWidth();
}

View File

@ -9,7 +9,7 @@ namespace big
{
class view
{
inline static animator window_animator = animator();
inline static animator window_animator = animator();
inline static ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoNav;
public:
@ -63,6 +63,7 @@ namespace big
static void player_kick();
static void player_toxic();
static void player_misc();
static void cmd_executor();
static void player_vehicle();
};
}