diff --git a/src/client/component/game_console.cpp b/src/client/component/game_console.cpp index 97c9681d..381c95c1 100644 --- a/src/client/component/game_console.cpp +++ b/src/client/component/game_console.cpp @@ -498,9 +498,15 @@ namespace game_console void add(const std::string& cmd, bool print_) { - print(cmd, print_); + execute(cmd.data()); + history.push_front(cmd); - game::Cbuf_AddText(0, utils::string::va("%s \n", cmd.data())); + if (history.size() > 10) + { + history.erase(history.begin() + 10); + } + + print(cmd, print_); } bool console_key_event(const int localClientNum, const int key, const int down) diff --git a/src/client/component/gui.cpp b/src/client/component/gui.cpp index eed43ef0..48ba7b97 100644 --- a/src/client/component/gui.cpp +++ b/src/client/component/gui.cpp @@ -113,8 +113,6 @@ namespace gui } }); - ImGui::ShowDemoWindow(); - if (ImGui::BeginMainMenuBar()) { if (ImGui::BeginMenu("Windows")) @@ -242,6 +240,12 @@ namespace gui }); } + void copy_to_clipboard(const std::string& text) + { + utils::string::set_clipboard_data(text); + gui::notification("Text copied to clipboard", utils::string::va("\"%s\"", text.data())); + } + class component final : public component_interface { public: diff --git a/src/client/component/gui.hpp b/src/client/component/gui.hpp index 8d0e2e98..0665215b 100644 --- a/src/client/component/gui.hpp +++ b/src/client/component/gui.hpp @@ -19,4 +19,5 @@ namespace gui void on_frame(const std::function& callback); bool is_menu_open(const std::string& name); void notification(const std::string& title, const std::string& text, const std::chrono::milliseconds duration = 3s); + void copy_to_clipboard(const std::string& text); } \ No newline at end of file diff --git a/src/client/component/gui_asset_list.cpp b/src/client/component/gui_asset_list.cpp index 4732068a..7f77abe3 100644 --- a/src/client/component/gui_asset_list.cpp +++ b/src/client/component/gui_asset_list.cpp @@ -43,7 +43,7 @@ namespace asset_list const auto name = game::g_assetNames[i]; const auto type = static_cast(i); - if (strstr(name, filter_buffer.data())) + if (utils::string::find_lower(name, filter_buffer)) { ImGui::Checkbox(name, &shown_assets[type]); } @@ -73,15 +73,14 @@ namespace asset_list const auto asset = game::XAsset{type, header}; const auto* const asset_name = game::DB_GetXAssetName(&asset); - if (!strstr(asset_name, filter)) + if (!utils::string::find_lower(asset_name, filter)) { return; } if (ImGui::Button(asset_name)) { - utils::string::set_clipboard_data(asset_name); - gui::notification("Text copied to clipboard!", utils::string::va("\"%s\"", asset_name)); + gui::copy_to_clipboard(asset_name); } }, true); diff --git a/src/client/component/gui_console.cpp b/src/client/component/gui_console.cpp index 3495a53c..1ac281fb 100644 --- a/src/client/component/gui_console.cpp +++ b/src/client/component/gui_console.cpp @@ -99,7 +99,7 @@ namespace gui_console const auto history = game_console::get_output(); for (const auto& line : history) { - if (strstr(line.data(), filter.data())) + if (utils::string::find_lower(line, filter)) { text.append(line.data()); text.append("\n"); @@ -144,6 +144,7 @@ namespace gui_console if (ImGui::Button("Copy")) { utils::string::set_clipboard_data(filtered_text); + gui::notification("Console", "Text copied to clipboard"); } ImGui::Separator(); @@ -170,7 +171,20 @@ namespace gui_console if (ImGui::InputText("Input", &input, input_text_flags, input_text_edit)) { + auto history = game_console::get_history(); + + if (history_index != -1) + { + const auto itr = history.begin() + history_index; + + if (*itr == input) + { + history.erase(history.begin() + history_index); + } + } + game_console::add(input.data()); + input.clear(); ImGui::SetKeyboardFocusHere(-1); } diff --git a/src/client/component/gui_entity_list.cpp b/src/client/component/gui_entity_list.cpp index 246a2fe9..f1cae700 100644 --- a/src/client/component/gui_entity_list.cpp +++ b/src/client/component/gui_entity_list.cpp @@ -348,7 +348,8 @@ namespace entity_list const auto classname = classname_value.as(); const auto team_ = team_value.as(); - if (strstr(classname.data(), "actor_") && (team == entity_team::team_any || team_ == team_names[team])) + if (utils::string::find_lower(classname, "actor_") && + (team == entity_team::team_any || team_ == team_names[team])) { result.push(entity); } @@ -457,8 +458,8 @@ namespace entity_list for (const auto& filter : data.filters.fields) { if (field_value.is() && - strstr(field.first.data(), utils::string::to_lower(filter.first).data()) && - strstr(value_string.data(), filter.second.data())) + utils::string::find_lower(field.first, filter.first) && + utils::string::find_lower(value_string, filter.second)) { match_count++; } @@ -789,16 +790,14 @@ namespace entity_list if (ImGui::Button(field.first.data())) { - utils::string::set_clipboard_data(field.first); - gui::notification("Text copied to clipboard!", utils::string::va("\"%s\"", field.first.data())); + gui::copy_to_clipboard(field.first); } ImGui::SameLine(); if (ImGui::Button(field.second.data())) { - utils::string::set_clipboard_data(field.second); - gui::notification("Text copied to clipboard!", utils::string::va("\"%s\"", field.second.data())); + gui::copy_to_clipboard(field.second); } } @@ -815,7 +814,8 @@ namespace entity_list ImGui::InputText("field name", field_filter, IM_ARRAYSIZE(field_filter)); for (auto& field : data.selected_fields) { - if (strstr(field.first.data(), field_filter) && ImGui::Checkbox(field.first.data(), &field.second)) + if (utils::string::find_lower(field.first, field_filter) && + ImGui::Checkbox(field.first.data(), &field.second)) { data.force_update = true; } diff --git a/src/common/utils/string.cpp b/src/common/utils/string.cpp index 3f90744c..546433db 100644 --- a/src/common/utils/string.cpp +++ b/src/common/utils/string.cpp @@ -192,4 +192,9 @@ namespace utils::string return str; } + + bool find_lower(const std::string& a, const std::string& b) + { + return to_lower(a).find(to_lower(b)) != std::string::npos; + } } diff --git a/src/common/utils/string.hpp b/src/common/utils/string.hpp index 924e5441..9d6afb16 100644 --- a/src/common/utils/string.hpp +++ b/src/common/utils/string.hpp @@ -98,4 +98,6 @@ namespace utils::string std::wstring convert(const std::string& str); std::string replace(std::string str, const std::string& from, const std::string& to); + + bool find_lower(const std::string& a, const std::string& b); }