diff --git a/.gitmodules b/.gitmodules index e29de68d..64a8f14c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -42,4 +42,4 @@ url = https://github.com/madler/zlib.git [submodule "deps/imgui"] path = deps/imgui - url = https://github.com/ocornut/imgui.git + url = https://github.com/fedddddd/imgui.git diff --git a/deps/imgui b/deps/imgui index 0cdc4a95..f791ff33 160000 --- a/deps/imgui +++ b/deps/imgui @@ -1 +1 @@ -Subproject commit 0cdc4a956530cbe64a4e319446f8d9d2d7d149ee +Subproject commit f791ff33702d55603d182b586a2850418ec49e3d diff --git a/src/client/component/gui.cpp b/src/client/component/gui.cpp index 4ad15f53..b20aa0cb 100644 --- a/src/client/component/gui.cpp +++ b/src/client/component/gui.cpp @@ -20,6 +20,7 @@ namespace gui namespace { utils::concurrency::container>> on_frame_callbacks; + utils::concurrency::container> notifications; ID3D11Device* device; ID3D11DeviceContext* device_context; @@ -58,8 +59,52 @@ namespace gui enabled_menus[name] = !enabled_menus[name]; } + void show_notifications() + { + static auto window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoSavedSettings | + ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav | + ImGuiWindowFlags_NoMove; + + notifications.access([](std::vector& notifications_) + { + auto index = 0; + for (auto i = notifications_.begin(); i != notifications_.end(); ++i) + { + const auto now = std::chrono::high_resolution_clock::now(); + if (now - i->creation_time >= i->duration) + { + notifications_.erase(i--); + continue; + } + + const auto title = i->title.size() <= 34 + ? i->title + : i->title.substr(0, 31) + "..."; + + const auto text = i->text.size() <= 34 + ? i->text + : i->text.substr(0, 31) + "..."; + + ImGui::SetNextWindowSizeConstraints(ImVec2(250, 50), ImVec2(250, 50)); + ImGui::SetNextWindowBgAlpha(0.6f); + ImGui::Begin(utils::string::va("Notification #%i", index), nullptr, window_flags); + + ImGui::SetWindowPos(ImVec2(10, 30.f + static_cast(index) * 60.f)); + ImGui::SetWindowSize(ImVec2(250, 0)); + ImGui::Text(title.data()); + ImGui::Text(text.data()); + + ImGui::End(); + + index++; + } + }); + } + void gui_draw() { + show_notifications(); + on_frame_callbacks.access([](std::vector>& callbacks) { for (const auto& callback : callbacks) @@ -180,6 +225,20 @@ namespace gui return enabled_menus[name]; } + void notification(const std::string& title, const std::string& text, const std::chrono::milliseconds duration) + { + notification_t notification{}; + notification.title = title; + notification.text = text; + notification.duration = duration; + notification.creation_time = std::chrono::high_resolution_clock::now(); + + notifications.access([notification](std::vector& notifications_) + { + notifications_.insert(notifications_.begin(), notification); + }); + } + class component final : public component_interface { public: diff --git a/src/client/component/gui.hpp b/src/client/component/gui.hpp index e570de33..8d0e2e98 100644 --- a/src/client/component/gui.hpp +++ b/src/client/component/gui.hpp @@ -2,6 +2,14 @@ namespace gui { + struct notification_t + { + std::string title; + std::string text; + std::chrono::milliseconds duration{}; + std::chrono::high_resolution_clock::time_point creation_time{}; + }; + extern std::unordered_map enabled_menus; bool gui_key_event(const int local_client_num, const int key, const int down); @@ -10,4 +18,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); } \ 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 cb2715f5..19c7756f 100644 --- a/src/client/component/gui_asset_list.cpp +++ b/src/client/component/gui_asset_list.cpp @@ -81,6 +81,7 @@ namespace asset_list if (ImGui::Button(asset_name)) { utils::string::set_clipboard_data(asset_name); + gui::notification("Text copied to clipboard!", utils::string::va("\"%s\"", asset_name)); } }, true); diff --git a/src/client/component/gui_entity_list.cpp b/src/client/component/gui_entity_list.cpp index de682e65..246a2fe9 100644 --- a/src/client/component/gui_entity_list.cpp +++ b/src/client/component/gui_entity_list.cpp @@ -466,7 +466,6 @@ namespace entity_list } catch (...) { - } } @@ -568,6 +567,7 @@ namespace entity_list } catch (...) { + gui::notification("Error", utils::string::va("^1error setting field '%s'!", name.data())); } }); } @@ -589,6 +589,7 @@ namespace entity_list } catch (...) { + gui::notification("Error", utils::string::va("^1error setting field '%s'!", name.data())); } }); } @@ -789,6 +790,7 @@ 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())); } ImGui::SameLine(); @@ -796,6 +798,7 @@ namespace entity_list 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())); } }