2023-02-21 06:20:40 +08:00
|
|
|
#include "pointers.hpp"
|
2023-03-01 21:27:15 +00:00
|
|
|
#include "views/view.hpp"
|
2023-02-21 06:20:40 +08:00
|
|
|
|
|
|
|
namespace big
|
|
|
|
{
|
|
|
|
void view::model_swapper()
|
|
|
|
{
|
2023-10-20 12:24:44 -04:00
|
|
|
ImGui::Text("VIEW_MODEL_SWAPPER_LINE1"_T.data());
|
|
|
|
ImGui::Text("VIEW_MODEL_SWAPPER_LINE2"_T.data());
|
|
|
|
ImGui::Text("VIEW_MODEL_SWAPPER_LINE3"_T.data());
|
2023-02-21 06:20:40 +08:00
|
|
|
|
|
|
|
static char dst_text[256];
|
|
|
|
static char src_text[256];
|
|
|
|
static size_t selected_index = -1;
|
2023-04-14 18:54:07 +02:00
|
|
|
static float width = *g_pointers->m_gta.m_resolution_x / 5.0;
|
2023-02-21 06:20:40 +08:00
|
|
|
|
|
|
|
ImGui::SetNextItemWidth(width);
|
2023-10-20 12:24:44 -04:00
|
|
|
ImGui::InputText("VIEW_MODEL_SWAPPER_DEST"_T.data(), dst_text, IM_ARRAYSIZE(dst_text));
|
2023-09-17 16:23:26 -04:00
|
|
|
if (ImGui::IsItemActive())
|
|
|
|
g.self.hud.typing = TYPING_TICKS;
|
2023-03-01 21:27:15 +00:00
|
|
|
ImGui::SameLine();
|
2023-02-21 06:20:40 +08:00
|
|
|
ImGui::SetNextItemWidth(width);
|
2023-10-20 12:24:44 -04:00
|
|
|
ImGui::InputText("VIEW_MODEL_SWAPPER_SRC"_T.data(), src_text, IM_ARRAYSIZE(src_text));
|
2023-09-17 16:23:26 -04:00
|
|
|
if (ImGui::IsItemActive())
|
|
|
|
g.self.hud.typing = TYPING_TICKS;
|
2023-03-01 21:27:15 +00:00
|
|
|
ImGui::SameLine();
|
2023-02-21 06:20:40 +08:00
|
|
|
|
2023-10-20 12:24:44 -04:00
|
|
|
if (ImGui::Button("ADD"_T.data()))
|
2023-02-21 06:20:40 +08:00
|
|
|
{
|
|
|
|
std::lock_guard lock(g.world.model_swapper.m);
|
|
|
|
if (dst_text[0] == '\0' || src_text[0] == '\0')
|
|
|
|
{
|
2023-10-20 12:24:44 -04:00
|
|
|
g_notification_service->push_error("GUI_TAB_MODEL_SWAPPER"_T.data(), "VIEW_MODEL_SWAPPER_WRONG_INPUT"_T.data());
|
2023-02-21 06:20:40 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
std::string str = dst_text;
|
|
|
|
transform(str.begin(), str.end(), str.begin(), ::tolower);
|
|
|
|
size_t i = 0;
|
|
|
|
for (; i < g.world.model_swapper.models.size(); i++)
|
|
|
|
{
|
|
|
|
std::string tmp = g.world.model_swapper.models[i].first;
|
|
|
|
transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower);
|
|
|
|
if (str == tmp)
|
|
|
|
{
|
2023-03-01 21:27:15 +00:00
|
|
|
g.world.model_swapper.models[i].first = dst_text;
|
2023-02-21 06:20:40 +08:00
|
|
|
g.world.model_swapper.models[i].second = src_text;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == g.world.model_swapper.models.size())
|
|
|
|
g.world.model_swapper.models.push_back(std::make_pair(dst_text, src_text));
|
|
|
|
g.world.model_swapper.update = true;
|
2023-03-01 21:27:15 +00:00
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
2023-10-20 12:24:44 -04:00
|
|
|
if (ImGui::Button("DELETE"_T.data()))
|
2023-02-21 06:20:40 +08:00
|
|
|
{
|
|
|
|
std::lock_guard lock(g.world.model_swapper.m);
|
2023-03-01 21:27:15 +00:00
|
|
|
if (!g.world.model_swapper.models.size() || selected_index < 0
|
|
|
|
|| selected_index >= g.world.model_swapper.models.size())
|
2023-02-21 06:20:40 +08:00
|
|
|
{
|
2023-10-20 12:24:44 -04:00
|
|
|
g_notification_service->push_error("GUI_TAB_MODEL_SWAPPER"_T.data(), "VIEW_MODEL_SWAPPER_INVALID_INDEX"_T.data());
|
2023-02-21 06:20:40 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
g.world.model_swapper.models.erase(std::begin(g.world.model_swapper.models) + selected_index);
|
|
|
|
g.world.model_swapper.update = true;
|
2023-03-01 21:27:15 +00:00
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
2023-10-20 12:24:44 -04:00
|
|
|
if (ImGui::Button("VIEW_DEBUG_GLOBAL_CLEAR"_T.data()))
|
2023-02-21 06:20:40 +08:00
|
|
|
{
|
|
|
|
std::lock_guard lock(g.world.model_swapper.m);
|
|
|
|
g.world.model_swapper.models.clear();
|
|
|
|
g.world.model_swapper.update = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::SetNextItemWidth(width);
|
2023-10-20 12:24:44 -04:00
|
|
|
ImGui::PushID(2);
|
|
|
|
if (ImGui::BeginListBox("VIEW_MODEL_SWAPPER_DEST"_T.data()))
|
2023-02-21 06:20:40 +08:00
|
|
|
{
|
|
|
|
for (size_t i = 0; i < g.world.model_swapper.models.size(); i++)
|
|
|
|
{
|
|
|
|
if (ImGui::Selectable(g.world.model_swapper.models[i].first.c_str(), selected_index == i))
|
|
|
|
{
|
|
|
|
selected_index = i;
|
|
|
|
strcpy_s(dst_text, sizeof(dst_text), g.world.model_swapper.models[i].first.c_str());
|
|
|
|
strcpy_s(src_text, sizeof(src_text), g.world.model_swapper.models[i].second.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selected_index == i)
|
|
|
|
ImGui::SetItemDefaultFocus();
|
|
|
|
}
|
|
|
|
ImGui::EndListBox();
|
2023-03-01 21:27:15 +00:00
|
|
|
}
|
|
|
|
ImGui::SameLine();
|
2023-02-21 06:20:40 +08:00
|
|
|
ImGui::SetNextItemWidth(width);
|
2023-10-20 12:24:44 -04:00
|
|
|
if (ImGui::BeginListBox("VIEW_MODEL_SWAPPER_SRC"_T.data()))
|
2023-02-21 06:20:40 +08:00
|
|
|
{
|
|
|
|
for (size_t i = 0; i < g.world.model_swapper.models.size(); i++)
|
|
|
|
{
|
|
|
|
if (ImGui::Selectable(g.world.model_swapper.models[i].second.c_str(), selected_index == i))
|
|
|
|
{
|
|
|
|
selected_index = i;
|
|
|
|
strcpy_s(dst_text, sizeof(dst_text), g.world.model_swapper.models[i].first.c_str());
|
|
|
|
strcpy_s(src_text, sizeof(src_text), g.world.model_swapper.models[i].second.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selected_index == i)
|
|
|
|
ImGui::SetItemDefaultFocus();
|
|
|
|
}
|
|
|
|
ImGui::EndListBox();
|
|
|
|
}
|
2023-10-20 12:24:44 -04:00
|
|
|
ImGui::PopID();
|
2023-02-21 06:20:40 +08:00
|
|
|
}
|
|
|
|
}
|