Skip to content

Commit

Permalink
Added auto tp to location
Browse files Browse the repository at this point in the history
  • Loading branch information
user-grinch committed Mar 6, 2022
1 parent f42a8f7 commit a0ad883
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 74 deletions.
41 changes: 34 additions & 7 deletions src/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ class Editor
static void Init();
static void CheckForUpdate();
static void DrawWindow();
static void Cleanup();
};
180 changes: 113 additions & 67 deletions src/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -840,101 +844,143 @@ 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();
}
//----------------------------------------------------
// 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];
Expand Down
1 change: 1 addition & 0 deletions src/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a0ad883

Please sign in to comment.