mirror of
https://github.com/Mr-X-GTA/YimMenu.git
synced 2025-01-03 16:13:36 +08:00
feat(SavedProfiles): Prepping for saving handling profiles
This commit is contained in:
parent
d91819a49c
commit
6d13ad8c25
@ -3,7 +3,8 @@
|
||||
|
||||
namespace big::api
|
||||
{
|
||||
const std::string domain = "http://home.damon.sh:8089/api/v1";
|
||||
//const std::string domain = "http://home.damon.sh:8089/api/v1";
|
||||
const std::string domain = "http://localhost:8080/api/v1";
|
||||
inline std::string session_id;
|
||||
|
||||
namespace util
|
||||
@ -140,6 +141,22 @@ namespace big::api
|
||||
return util::parse_body(res, out);
|
||||
}
|
||||
|
||||
static bool save_profile(std::string share_code)
|
||||
{
|
||||
if (!util::signed_in()) return false;
|
||||
|
||||
const std::string path = "/vehicle/handling/save_profile";
|
||||
|
||||
http::Request request(domain + path);
|
||||
|
||||
nlohmann::json body = { { "share_code", share_code } };
|
||||
|
||||
http::Response res = request.send("POST", body.dump(), {
|
||||
util::authorization_header()
|
||||
});
|
||||
return util::parse_body(res, body);
|
||||
}
|
||||
|
||||
static bool update(uint32_t handling_hash, const char* name, const char* description, std::string share_code, nlohmann::json &update)
|
||||
{
|
||||
if (!util::signed_in()) return false;
|
||||
|
@ -0,0 +1,55 @@
|
||||
#include "handling_tabs.hpp"
|
||||
|
||||
namespace big
|
||||
{
|
||||
void tab_handling::tab_saved_profiles()
|
||||
{
|
||||
if (ImGui::BeginTabItem("Saved Profiles"))
|
||||
{
|
||||
if (!g_vehicle_service->load_saved_profiles())
|
||||
ImGui::Text("Loading profiles...");
|
||||
else
|
||||
{
|
||||
if (g_vehicle_service->m_my_profiles.size() == 0)
|
||||
ImGui::Text("You have no saved 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::BeginTable("table", 3, ImGuiTableFlags_SizingStretchProp);
|
||||
|
||||
ImGui::TableNextRow();
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("Name:");
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text(profile.name.c_str());
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("Share Code: %s", profile.share_code.c_str());
|
||||
|
||||
ImGui::TableNextRow();
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("Description:");
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextWrapped(profile.description.c_str());
|
||||
ImGui::TableNextColumn();
|
||||
if (ImGui::Button("Load Profile"))
|
||||
g_vehicle_service->set_handling_profile(profile);
|
||||
|
||||
ImGui::EndTable();
|
||||
|
||||
ImGui::Separator();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
#include "api/api.hpp"
|
||||
#include "fiber_pool.hpp"
|
||||
#include "handling_tabs.hpp"
|
||||
#include "natives.hpp"
|
||||
@ -63,6 +64,9 @@ namespace big
|
||||
ImGui::TableNextColumn();
|
||||
if (ImGui::Button("Load Profile"))
|
||||
g_vehicle_service->set_handling_profile(profile);
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Save Profile"))
|
||||
g_thread_pool->push([&] { api::vehicle::handling::save_profile(profile.share_code); });
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ namespace big
|
||||
public:
|
||||
static void tab_current_profile();
|
||||
static void tab_my_profiles();
|
||||
static void tab_saved_profiles();
|
||||
static void tab_search();
|
||||
};
|
||||
}
|
@ -155,6 +155,28 @@ namespace big
|
||||
return true;
|
||||
}
|
||||
|
||||
bool vehicle_service::load_saved_profiles(bool force_update)
|
||||
{
|
||||
static bool busy = false, up_to_date = false;
|
||||
|
||||
if (busy) return false;
|
||||
|
||||
if (!safe_to_modify())
|
||||
return false;
|
||||
|
||||
if (!force_update && up_to_date) return true;
|
||||
|
||||
busy = true;
|
||||
|
||||
g_thread_pool->push([]()
|
||||
{
|
||||
//api::vehicle::handling::save_profile()
|
||||
|
||||
busy = false;
|
||||
up_to_date = true;
|
||||
});
|
||||
}
|
||||
|
||||
bool vehicle_service::publish_profile(const char* name, const char* description, std::string share_code)
|
||||
{
|
||||
if (this->m_publish_status == PublishStatus::SAVED)
|
||||
|
@ -123,16 +123,17 @@ namespace big
|
||||
std::string get_active_profile(std::uint32_t hash);
|
||||
bool get_by_share_code(const char* share_code);
|
||||
bool handling_data_to_json(CHandlingData& handling_data, nlohmann::json& out);
|
||||
bool load_saved_profiles(bool force_update = false);
|
||||
bool publish_profile(const char* name, const char* description, std::string share_code = "");
|
||||
PublishStatus publish_status(PublishStatus new_status = PublishStatus::NONE);
|
||||
bool restore_vehicle();
|
||||
void set_active_profile(std::uint32_t hash, std::string share_code);
|
||||
void set_handling_profile(HandlingProfile& profile);
|
||||
|
||||
bool update_mine(bool force_update = false);
|
||||
|
||||
inline static std::unordered_map<std::uint32_t, std::string> m_active_profiles;
|
||||
inline static std::vector<std::string> m_my_profiles;
|
||||
inline static std::vector<std::string> m_saved_profiles;
|
||||
inline static std::unordered_map<std::string, HandlingProfile> m_handling_profiles;
|
||||
|
||||
SearchStatus m_search_status = SearchStatus::IDLE;
|
||||
|
Loading…
x
Reference in New Issue
Block a user