From f4a957c7830a85c7cd18600bd1e34db733fce2ac Mon Sep 17 00:00:00 2001 From: Yimura Date: Sat, 18 Sep 2021 22:13:10 +0200 Subject: [PATCH] feat(HandlingModals): Added update handling profile modal --- .../current_profile/current_profile_tabs.hpp | 1 + .../handling/modals/update_handling.cpp | 91 +++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 BigBaseV2/src/gui/window/handling/modals/update_handling.cpp diff --git a/BigBaseV2/src/gui/window/handling/current_profile/current_profile_tabs.hpp b/BigBaseV2/src/gui/window/handling/current_profile/current_profile_tabs.hpp index 57ec9e55..6385f6f5 100644 --- a/BigBaseV2/src/gui/window/handling/current_profile/current_profile_tabs.hpp +++ b/BigBaseV2/src/gui/window/handling/current_profile/current_profile_tabs.hpp @@ -23,5 +23,6 @@ namespace big { public: static void modal_save_handling(); + static void modal_update_handling(); }; } \ No newline at end of file diff --git a/BigBaseV2/src/gui/window/handling/modals/update_handling.cpp b/BigBaseV2/src/gui/window/handling/modals/update_handling.cpp new file mode 100644 index 00000000..7ec7e399 --- /dev/null +++ b/BigBaseV2/src/gui/window/handling/modals/update_handling.cpp @@ -0,0 +1,91 @@ +#include "../current_profile/current_profile_tabs.hpp" +#include "fiber_pool.hpp" +#include "thread_pool.hpp" +#include "natives.hpp" +#include "script.hpp" + +namespace big +{ + void modal_handling::modal_update_handling() + { + ImGui::SetNextWindowSize({ 520, 325 }, ImGuiCond_FirstUseEver); + if (ImGui::BeginPopupModal("Update Handling")) + { + auto share_code = g_vehicle_service->get_active_profile(g_local_player->m_vehicle->m_handling->m_model_hash); + if (share_code.empty()) + { + // should be impossible to trigger but still + + return ImGui::EndPopup(); + } + auto it = g_vehicle_service->m_handling_profiles.find(share_code); + if (it == g_vehicle_service->m_handling_profiles.end()) + return ImGui::EndPopup(); + auto profile = it->second; + + static char name[32], description[256] = "No description."; + + strcpy(name, profile.name.c_str()); + strcpy(description, profile.description.c_str()); + + switch (g_vehicle_service->publish_status()) + { + case PublishStatus::SAVING: + ImGui::Text("Saving..."); + + return ImGui::EndPopup(); + case PublishStatus::SAVED: + strcpy(name, ""); + strcpy(description, "No description."); + + g_vehicle_service->publish_status(PublishStatus::IDLE); + g_vehicle_service->update_mine(true); + + ImGui::CloseCurrentPopup(); + + return ImGui::EndPopup(); + case PublishStatus::FAILED: + ImGui::TextColored({ 255, 0, 0, 1 }, "Failed to update handling profile."); + + ImGui::Separator(); + } + + QUEUE_JOB_BEGIN_CLAUSE() + { + PAD::DISABLE_ALL_CONTROL_ACTIONS(0); + }QUEUE_JOB_END_CLAUSE + + ImGui::BeginGroup(); + + ImGui::Text("Name:"); + ImGui::Text("Description:"); + + ImGui::EndGroup(); + ImGui::SameLine(); + ImGui::BeginGroup(); + + ImGui::InputText("##modal_handling_name", name, sizeof(name)); + ImGui::InputTextMultiline("##modal_handling_description", description, sizeof(description)); + + ImGui::EndGroup(); + + if (ImGui::Button("Cancel")) + { + strcpy(name, ""); + strcpy(description, "No description."); + + ImGui::CloseCurrentPopup(); + } + ImGui::SameLine(); + if (ImGui::Button("Update")) + { + g_thread_pool->push([&] + { + g_vehicle_service->publish_profile(name, description, profile.share_code); + }); + } + + ImGui::EndPopup(); + } + } +} \ No newline at end of file