diff --git a/src/editor.cpp b/src/editor.cpp index 1043ef0..ca4ca94 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -16,6 +16,8 @@ void Editor::Init() Updater::CheckUpdate(); // Load config data + Interface::m_bAutoSave = gConfig.GetValue("editor.autoSave", true); + Interface::m_bAutoTpToLoc = gConfig.GetValue("editor.autoTpToLoc", false); Interface::m_bAutoSnapToGround = gConfig.GetValue("editor.autoSnap", true); Interface::m_bShowInfoMenu = gConfig.GetValue("editor.showInfoMenu", true); ObjManager::m_bDrawBoundingBox = gConfig.GetValue("editor.drawBoundingBox", true); @@ -44,19 +46,44 @@ void Editor::Init() { Editor::m_bShowEditor = !Editor::m_bShowEditor; - if (!Editor::m_bShowEditor) + if (Editor::m_bShowEditor) { - Viewport::m_eViewportMode = EDIT_MODE; - Interface::m_bObjectBrowserShown = false; - Interface::m_bOpenObjectBrowser = false; - D3dHook::SetMouseState(false); - gConfig.WriteToDisk(); - Viewport::Shutdown(); + if (Interface::m_bAutoTpToLoc) + { + CVector pos; + pos.x = gConfig.GetValue("editor.tp.X", -1.0f); + pos.y = gConfig.GetValue("editor.tp.Y", -1.0f); + pos.z = gConfig.GetValue("editor.tp.Z", -1.0f); + + if (pos.x != -1.0f) + { + Viewport::SetCameraPosn(pos); + } + } + } + else + { + Editor::Cleanup(); } } }; + + Events::shutdownRwEvent += []() + { + gConfig.WriteToDisk(); + }; }; +void Editor::Cleanup() +{ + Viewport::m_eViewportMode = EDIT_MODE; + Interface::m_bObjectBrowserShown = false; + Interface::m_bOpenObjectBrowser = false; + D3dHook::SetMouseState(false); + gConfig.WriteToDisk(); + Viewport::Shutdown(); +} + void Editor::DrawWindow() { static bool bTriedtoHideCursor; diff --git a/src/editor.h b/src/editor.h index d69c012..7d5c60f 100644 --- a/src/editor.h +++ b/src/editor.h @@ -15,4 +15,5 @@ class Editor static void Init(); static void CheckForUpdate(); static void DrawWindow(); + static void Cleanup(); }; \ No newline at end of file diff --git a/src/interface.cpp b/src/interface.cpp index b3936bc..537aa05 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -513,6 +513,10 @@ void Interface::DrawMainMenuBar() { gConfig.SetValue("editor.autoSnap", Interface::m_bAutoSnapToGround); } + if (ImGui::MenuItem("Auto teleport to location", NULL, &Interface::m_bAutoTpToLoc)) + { + gConfig.SetValue("editor.autoTpToLoc", Interface::m_bAutoTpToLoc); + } if (ImGui::MenuItem("No pedstrain", NULL, &bNoPeds)) { if (bNoPeds) @@ -840,94 +844,127 @@ void Interface::DrawInfoMenu() // Created objects Tab if(ImGui::BeginTabItem("Objects")) { - static bool bShowAnyway; - static ImGuiTextFilter filter; - ImGui::Spacing(); - if (ObjManager::m_pVecEntities.size() == 0) + if (ImGui::BeginTabBar("OBJBAR")) { - ImGui::TextWrapped("You haven't placed any objects yet!"); - } - else - { - if (ImGui::Button("Remove All", Utils::GetSize(bShowAnyway ? 2 : 1))) + if(ImGui::BeginTabItem("All")) { - for (auto &pObj : ObjManager::m_pVecEntities) - { - pObj->Remove(); - } - ObjManager::m_pSelected = nullptr; - ObjManager::m_pVecEntities.clear(); - } + static bool bShowAnyway; + static ImGuiTextFilter filter; - if (ObjManager::m_pVecEntities.size() > 500) - { - if (bShowAnyway) + ImGui::Spacing(); + if (ObjManager::m_pVecEntities.size() == 0) { - ImGui::SameLine(); - if (ImGui::Button("Hide list", Utils::GetSize(2))) - { - bShowAnyway = false; - } + ImGui::TextWrapped("You haven't placed any objects yet!"); } else { - ImGui::Spacing(); - ImGui::TextWrapped("You've placed more than 500 objects. The list has been hidden to avoid performance issues."); - ImGui::Spacing(); - if (ImGui::Button("Show anyway", Utils::GetSize())) + if (ImGui::Button("Remove All", Utils::GetSize(bShowAnyway ? 2 : 1))) { - bShowAnyway = true; + for (auto &pObj : ObjManager::m_pVecEntities) + { + pObj->Remove(); + } + ObjManager::m_pSelected = nullptr; + ObjManager::m_pVecEntities.clear(); } - } - } - ImGui::Spacing(); - if (ObjManager::m_pVecEntities.size() < 500 || bShowAnyway) - { - filter.Draw("Search"); - if (ImGui::IsItemActive()) - { - m_bIsInputLocked = true; - } - ImGui::Spacing(); - if (ImGui::BeginChild("Objects child")) - { - for (size_t i = 0; i < ObjManager::m_pVecEntities.size(); i++) + if (ObjManager::m_pVecEntities.size() > 500) { - CObject *pObj = ObjManager::m_pVecEntities[i]; - auto &data = ObjManager::m_objData.Get(pObj); - - if (data.m_modelName == "") + if (bShowAnyway) { - data.m_modelName = ObjManager::FindNameFromModel(pObj->m_nModelIndex); + ImGui::SameLine(); + if (ImGui::Button("Hide list", Utils::GetSize(2))) + { + bShowAnyway = false; + } } - char buf[32]; - sprintf(buf, "%d. %s(%d)", i+1, data.m_modelName.c_str(), pObj->m_nModelIndex); - - if (filter.PassFilter(buf) && ImGui::MenuItem(buf)) + else { - // Setting the camera pos to bounding box - CMatrix *matrix = pObj->GetMatrix(); - CColModel *pColModel = pObj->GetColModel(); - CVector min = pColModel->m_boundBox.m_vecMin; - CVector max = pColModel->m_boundBox.m_vecMax; - - CVector workVec = min; - workVec.x = max.x; - workVec.z = max.z; - CVector vec = *matrix * workVec; + ImGui::Spacing(); + ImGui::TextWrapped("You've placed more than 500 objects. The list has been hidden to avoid performance issues."); + ImGui::Spacing(); + if (ImGui::Button("Show anyway", Utils::GetSize())) + { + bShowAnyway = true; + } + } + } + ImGui::Spacing(); - // TODO: Rotate the camera to face the object + if (ObjManager::m_pVecEntities.size() < 500 || bShowAnyway) + { + filter.Draw("Search"); + if (ImGui::IsItemActive()) + { + m_bIsInputLocked = true; + } + ImGui::Spacing(); + if (ImGui::BeginChild("Objects child")) + { + for (size_t i = 0; i < ObjManager::m_pVecEntities.size(); i++) + { + CObject *pObj = ObjManager::m_pVecEntities[i]; + auto &data = ObjManager::m_objData.Get(pObj); + + if (data.m_modelName == "") + { + data.m_modelName = ObjManager::FindNameFromModel(pObj->m_nModelIndex); + } + char buf[32]; + sprintf(buf, "%d. %s(%d)", i+1, data.m_modelName.c_str(), pObj->m_nModelIndex); + + if (filter.PassFilter(buf) && ImGui::MenuItem(buf)) + { + // Setting the camera pos to bounding box + CMatrix *matrix = pObj->GetMatrix(); + CColModel *pColModel = pObj->GetColModel(); + CVector min = pColModel->m_boundBox.m_vecMin; + CVector max = pColModel->m_boundBox.m_vecMax; + + CVector workVec = min; + workVec.x = max.x; + workVec.z = max.z; + CVector vec = *matrix * workVec; + + // TODO: Rotate the camera to face the object + + Viewport::SetCameraPosn(vec); + ObjManager::m_pSelected = pObj; + } + } - Viewport::SetCameraPosn(vec); - ObjManager::m_pSelected = pObj; + ImGui::EndChild(); } } - - ImGui::EndChild(); } + ImGui::EndTabItem(); + } + if(ImGui::BeginTabItem("Favourites")) + { + ImGui::Spacing(); + Widgets::DrawJSON(m_favData, + [](std::string& root, std::string& key, std::string& value) + { + Viewport::COPY_MODEL::m_nModel = std::stoi(value); + CHud::SetHelpMessage("Object Copied", false, false, false); + }, + [](std::string& root, std::string& key, std::string& value) + { + if (ImGui::MenuItem("Copy")) + { + Viewport::COPY_MODEL::m_nModel = std::stoi(value); + CHud::SetHelpMessage("Object Copied", false, false, false); + } + if (ImGui::MenuItem("Remove")) + { + m_favData.m_pJson->m_Data["All"].erase(key); + m_favData.m_pJson->WriteToDisk(); + }; + }); + ImGui::EndTabItem(); } + ImGui::EndTabBar(); } ImGui::EndTabItem(); } @@ -935,6 +972,15 @@ void Interface::DrawInfoMenu() // Locations if(ImGui::BeginTabItem("Locations")) { + if (ImGui::Button("Set auto teleport location", Utils::GetSize())) + { + CVector pos = TheCamera.GetPosition(); + gConfig.SetValue("editor.tp.X", pos.x); + gConfig.SetValue("editor.tp.Y", pos.y); + gConfig.SetValue("editor.tp.Z", pos.z); + CHud::SetHelpMessage("Teleport location set", false, false, false); + } + ImGui::Spacing(); if (ImGui::CollapsingHeader("Add new")) { static char m_nLocationBuffer[64], m_nInputBuffer[64]; diff --git a/src/interface.h b/src/interface.h index 55db8c0..d465f7a 100644 --- a/src/interface.h +++ b/src/interface.h @@ -18,6 +18,7 @@ class Interface public: static inline bool m_bAutoSave = true; + static inline bool m_bAutoTpToLoc = false; static inline bool m_bAutoSnapToGround; static inline bool m_bWelcomeScreenDisplayed; static inline bool m_bShowInfoMenu; // right hand menu