From a2b2308b208fbed17fb2bd7527ec34ebdc3c3802 Mon Sep 17 00:00:00 2001 From: Yimura Date: Thu, 16 Sep 2021 22:21:42 +0200 Subject: [PATCH] chore: Cleaned and moved handling window code --- .../handling/handling_current_profile.cpp | 38 +++++ .../window/handling/handling_my_profiles.cpp | 54 +++++++ .../gui/window/handling/handling_search.cpp | 63 +++++++++ .../src/gui/window/handling/handling_tabs.hpp | 13 ++ BigBaseV2/src/gui/window/window_handling.cpp | 133 +----------------- 5 files changed, 171 insertions(+), 130 deletions(-) create mode 100644 BigBaseV2/src/gui/window/handling/handling_current_profile.cpp create mode 100644 BigBaseV2/src/gui/window/handling/handling_my_profiles.cpp create mode 100644 BigBaseV2/src/gui/window/handling/handling_search.cpp create mode 100644 BigBaseV2/src/gui/window/handling/handling_tabs.hpp diff --git a/BigBaseV2/src/gui/window/handling/handling_current_profile.cpp b/BigBaseV2/src/gui/window/handling/handling_current_profile.cpp new file mode 100644 index 00000000..f7b49d71 --- /dev/null +++ b/BigBaseV2/src/gui/window/handling/handling_current_profile.cpp @@ -0,0 +1,38 @@ +#include "handling_tabs.hpp" + +namespace big +{ + void tab_handling::tab_current_profile() + { + if (ImGui::BeginTabItem("Current Profile")) + { + if (ImGui::Button("Save Profile")) + { + ImGui::OpenPopup("Save Handling"); + } + + modal_handling::modal_save_handling(); + ImGui::SameLine(); + if (ImGui::Button("Restore Handling")) + { + g_vehicle_service->restore_vehicle(); + } + + ImGui::Separator(); + + ImGui::BeginTabBar("handling_tabbar"); + tab_current_profile::tab_general(); + tab_current_profile::tab_other(); + tab_current_profile::tab_brakes(); + tab_current_profile::tab_gearing(); + tab_current_profile::tab_traction(); + tab_current_profile::tab_steering(); + tab_current_profile::tab_suspension(); + tab_current_profile::tab_rollbars(); + tab_current_profile::tab_roll_centre_height(); + ImGui::EndTabBar(); + + ImGui::EndTabItem(); + } + } +} \ No newline at end of file diff --git a/BigBaseV2/src/gui/window/handling/handling_my_profiles.cpp b/BigBaseV2/src/gui/window/handling/handling_my_profiles.cpp new file mode 100644 index 00000000..be4c86fc --- /dev/null +++ b/BigBaseV2/src/gui/window/handling/handling_my_profiles.cpp @@ -0,0 +1,54 @@ +#include "handling_tabs.hpp" + +namespace big +{ + void tab_handling::tab_my_profiles() + { + if (ImGui::BeginTabItem("My Profiles")) + { + if (!g_vehicle_service->update_mine()) + ImGui::Text("Loading profiles..."); + else + { + if (g_vehicle_service->m_my_profiles.size() == 0) + ImGui::Text("You have no profiles available for this vehicle."); + for (auto& key : g_vehicle_service->m_my_profiles) + { + if (auto it = g_vehicle_service->m_handling_profiles.find(key); it != g_vehicle_service->m_handling_profiles.end()) + { + auto& profile = it->second; + + if (profile.share_code == g_vehicle_service->get_active_profile(profile.handling_hash)) + ImGui::TextColored({ 0.1254f,0.8039f,0.3137f,1.f }, "Active"); + + ImGui::BeginGroup(); + + ImGui::Text("Name:"); + ImGui::Text("Description:"); + + ImGui::EndGroup(); + ImGui::SameLine(); + ImGui::BeginGroup(); + + ImGui::Text(profile.name.c_str()); + ImGui::TextWrapped(profile.description.c_str()); + + ImGui::EndGroup(); + ImGui::SameLine(); + ImGui::BeginGroup(); + + ImGui::Text("Share Code: %s", profile.share_code.c_str()); + if (ImGui::Button("Load Profile")) + g_vehicle_service->set_handling_profile(profile); + + ImGui::EndGroup(); + + ImGui::Separator(); + } + } + } + + ImGui::EndTabItem(); + } + } +} \ No newline at end of file diff --git a/BigBaseV2/src/gui/window/handling/handling_search.cpp b/BigBaseV2/src/gui/window/handling/handling_search.cpp new file mode 100644 index 00000000..15ce28ae --- /dev/null +++ b/BigBaseV2/src/gui/window/handling/handling_search.cpp @@ -0,0 +1,63 @@ +#include "fiber_pool.hpp" +#include "handling_tabs.hpp" + +namespace big +{ + void tab_handling::tab_search() + { + if (ImGui::BeginTabItem("Search")) + { + static char search[13]; + ImGui::InputTextWithHint("##search_share_code", "Search by share code", search, sizeof(search)); + ImGui::SameLine(); + if (ImGui::Button("Search")) + g_fiber_pool->queue_job([&] { g_vehicle_service->get_by_share_code(search); }); + + switch (g_vehicle_service->m_search_status) + { + case SearchStatus::SEARCHING: + ImGui::Text("Searching..."); + + break; + case SearchStatus::NO_RESULT: + ImGui::Text("No results found for %s", search); + + break; + case SearchStatus::FAILED: + ImGui::Text("Search failed, host is down or response body is invalid..."); + + break; + case SearchStatus::FOUND: + if (auto it = g_vehicle_service->m_handling_profiles.find(search); it != g_vehicle_service->m_handling_profiles.end()) + { + auto& profile = it->second; + ImGui::BeginGroup(); + + ImGui::Text("Name:"); + ImGui::Text("Description:"); + + ImGui::EndGroup(); + ImGui::SameLine(); + ImGui::BeginGroup(); + + ImGui::Text(profile.name.c_str()); + ImGui::TextWrapped(profile.description.c_str()); + + ImGui::EndGroup(); + ImGui::SameLine(); + ImGui::BeginGroup(); + + ImGui::Text("Share Code: %s", profile.share_code.c_str()); + if (ImGui::Button("Load Profile")) + g_vehicle_service->set_handling_profile(profile); + + ImGui::EndGroup(); + } + + break; + } + + ImGui::EndTabItem(); + } + } +} \ No newline at end of file diff --git a/BigBaseV2/src/gui/window/handling/handling_tabs.hpp b/BigBaseV2/src/gui/window/handling/handling_tabs.hpp new file mode 100644 index 00000000..fcd9e424 --- /dev/null +++ b/BigBaseV2/src/gui/window/handling/handling_tabs.hpp @@ -0,0 +1,13 @@ +#pragma once +#include "current_profile/current_profile_tabs.hpp" + +namespace big +{ + class tab_handling + { + public: + static void tab_current_profile(); + static void tab_my_profiles(); + static void tab_search(); + }; +} \ No newline at end of file diff --git a/BigBaseV2/src/gui/window/window_handling.cpp b/BigBaseV2/src/gui/window/window_handling.cpp index e19bcd7d..3dadf6e5 100644 --- a/BigBaseV2/src/gui/window/window_handling.cpp +++ b/BigBaseV2/src/gui/window/window_handling.cpp @@ -20,136 +20,9 @@ namespace big g_vehicle_service->attempt_save(); ImGui::BeginTabBar("handling_profiles"); - if (ImGui::BeginTabItem("Current Profile")) - { - if (ImGui::Button("Save Profile")) - { - ImGui::OpenPopup("Save Handling"); - } - - modal_handling::modal_save_handling(); - ImGui::SameLine(); - if (ImGui::Button("Restore Handling")) - { - g_vehicle_service->restore_vehicle(); - } - - ImGui::Separator(); - - ImGui::BeginTabBar("handling_tabbar"); - tab_handling::tab_general(); - tab_handling::tab_other(); - tab_handling::tab_brakes(); - tab_handling::tab_gearing(); - tab_handling::tab_traction(); - tab_handling::tab_steering(); - tab_handling::tab_suspension(); - tab_handling::tab_rollbars(); - tab_handling::tab_roll_centre_height(); - ImGui::EndTabBar(); - - ImGui::EndTabItem(); - } - if (ImGui::BeginTabItem("My Profiles")) - { - if (!g_vehicle_service->update_mine()) - ImGui::Text("Loading profiles..."); - else - { - if (g_vehicle_service->m_my_profiles.size() == 0) - ImGui::Text("You have no profiles available for this vehicle."); - for (auto &key : g_vehicle_service->m_my_profiles) - { - if (auto it = g_vehicle_service->m_handling_profiles.find(key); it != g_vehicle_service->m_handling_profiles.end()) - { - auto& profile = it->second; - - if (profile.share_code == g_vehicle_service->get_active_profile(profile.handling_hash)) - ImGui::TextColored({ 0.1254f,0.8039f,0.3137f,1.f }, "Active"); - - ImGui::BeginGroup(); - - ImGui::Text("Name:"); - ImGui::Text("Description:"); - - ImGui::EndGroup(); - ImGui::SameLine(); - ImGui::BeginGroup(); - - ImGui::Text(profile.name.c_str()); - ImGui::TextWrapped(profile.description.c_str()); - - ImGui::EndGroup(); - ImGui::SameLine(); - ImGui::BeginGroup(); - - ImGui::Text("Share Code: %s", profile.share_code.c_str()); - if (ImGui::Button("Load Profile")) - g_vehicle_service->set_handling_profile(profile); - - ImGui::EndGroup(); - - ImGui::Separator(); - } - } - } - - ImGui::EndTabItem(); - } - if (ImGui::BeginTabItem("Search")) - { - static char search[13]; - ImGui::InputTextWithHint("##search_share_code", "Search by share code", search, sizeof(search)); - ImGui::SameLine(); - if (ImGui::Button("Search")) - g_fiber_pool->queue_job([&] { g_vehicle_service->get_by_share_code(search); }); - - switch (g_vehicle_service->m_search_status) - { - case SearchStatus::SEARCHING: - ImGui::Text("Searching..."); - - break; - case SearchStatus::NO_RESULT: - ImGui::Text("No results found for %s", search); - - break; - case SearchStatus::FAILED: - ImGui::Text("Search failed, host is down or response body is invalid..."); - - break; - case SearchStatus::FOUND: - if (auto it = g_vehicle_service->m_handling_profiles.find(search); it != g_vehicle_service->m_handling_profiles.end()) - { - auto& profile = it->second; - ImGui::BeginGroup(); - - ImGui::Text("Name:"); - ImGui::Text("Description:"); - - ImGui::EndGroup(); - ImGui::SameLine(); - ImGui::BeginGroup(); - - ImGui::Text(profile.name.c_str()); - ImGui::TextWrapped(profile.description.c_str()); - - ImGui::EndGroup(); - ImGui::SameLine(); - ImGui::BeginGroup(); - - ImGui::Text("Share Code: %s", profile.share_code.c_str()); - if (ImGui::Button("Load Profile")) - g_vehicle_service->set_handling_profile(profile); - - ImGui::EndGroup(); - } - - break; - } - - ImGui::EndTabItem(); - } + tab_handling::tab_current_profile(); + tab_handling::tab_my_profiles(); + tab_handling::tab_search(); ImGui::EndTabBar(); ImGui::End();