Save menu position in config

This commit is contained in:
Grinch_ 2022-10-01 13:49:11 +06:00
parent c413c53043
commit 24c9564928
5 changed files with 28 additions and 25 deletions

View File

@ -72,7 +72,15 @@ void CheatMenuMgr::Draw()
bRunning = true;
if (m_bVisible)
{
ImGui::SetNextWindowSize(m_fSize);
ImGui::SetNextWindowSize(m_fSize, ImGuiCond_Once);
ImGui::SetNextWindowPos(m_fPos, ImGuiCond_Once);
if (m_bWindowParamUpdated)
{
ImGui::SetNextWindowSize(m_fSize);
ImGui::SetNextWindowPos(m_fPos);
m_bWindowParamUpdated = false;
}
if (ImGui::Begin(MENU_TITLE, NULL, ImGuiWindowFlags_NoCollapse || ImGuiWindowFlags_NoTitleBar))
{
@ -80,21 +88,17 @@ void CheatMenuMgr::Draw()
ImGui::PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(250, 350));
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding,
ImVec2(ImGui::GetWindowWidth() / 85, ImGui::GetWindowHeight() / 200));
PageHandler::DrawPages();
if (m_bSizeUpdated)
{
m_bSizeUpdated = false;
}
else
if (ImGui::IsWindowHovered())
{
m_fSize = ImGui::GetWindowSize();
m_fPos = ImGui::GetWindowPos();
gConfig.Set("Window.PosX", m_fPos.x);
gConfig.Set("Window.PosY", m_fPos.y);
gConfig.Set("Window.SizeX", m_fSize.x);
gConfig.Set("Window.SizeY", m_fSize.y);
}
gConfig.Set("Window.SizeX", m_fSize.x);
gConfig.Set("Window.SizeY", m_fSize.y);
ImGui::PopStyleVar(2);
ImGui::End();
}
@ -215,6 +219,9 @@ CheatMenuMgr::CheatMenuMgr()
// Load menu settings
m_fSize.x = gConfig.Get("Window.SizeX", screen::GetScreenWidth() / 4.0f);
m_fSize.y = gConfig.Get("Window.SizeY", screen::GetScreenHeight() / 1.2f);
m_fPos.x = gConfig.Get("Window.PosX", 50.0f);
m_fPos.y = gConfig.Get("Window.PosY", 50.0f);
srand(CTimer::m_snTimeInMilliseconds);
};
@ -322,9 +329,10 @@ void CheatMenuMgr::ApplyStyle()
style->Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.6f);
}
void CheatMenuMgr::ResetSize()
void CheatMenuMgr::ResetParams()
{
m_fSize.x = screen::GetScreenWidth() / 4.0f;
m_fSize.y = screen::GetScreenHeight() / 1.2f;
m_bSizeUpdated = true;
m_fPos = {50.0f, 50.0f};
m_bWindowParamUpdated = true;
}

View File

@ -9,9 +9,9 @@
class CheatMenuMgr : public IFeature<CheatMenuMgr>
{
private:
ImVec2 m_fSize;
ImVec2 m_fSize, m_fPos;
bool m_bVisible; // should the menu be drawn
bool m_bSizeUpdated; // Was menu size change requested
bool m_bWindowParamUpdated; // Was menu size/pos changed
bool m_bIsOnline; // SAMP & VCMP flag
friend class IFeature;
@ -29,7 +29,7 @@ public:
bool IsVisible();
// Resets the menu height & width to default
void ResetSize();
void ResetParams();
};
extern CheatMenuMgr& CheatMenu;

View File

@ -5,7 +5,7 @@
LONG WINAPI CrashHandler(PEXCEPTION_POINTERS pInfo)
{
Log::Print<eLogLevel::None>("");
Log::Print<eLogLevel::Error>("Game crashed. Unhandled exception at {} (0x{:x})",
Log::Print<eLogLevel::Error>("Unhandled exception at {} (0x{:x})",
pInfo->ExceptionRecord->ExceptionAddress, pInfo->ExceptionRecord->ExceptionCode);
return EXCEPTION_CONTINUE_SEARCH;
}

View File

@ -61,7 +61,7 @@ void MenuPage::Draw()
ImGui::Spacing();
if (ImGui::Button(TEXT("Menu.ResetSize"), ImVec2(Widget::CalcSize(2))))
{
CheatMenu.ResetSize();
CheatMenu.ResetParams();
}
ImGui::SameLine();
if (ImGui::Button(TEXT("Menu.ReloadFonts"), ImVec2(Widget::CalcSize(2))))
@ -78,7 +78,6 @@ void MenuPage::Draw()
if (Locale::SetLocale(selected) == Locale::eReturnCodes::SUCCESS)
{
gConfig.Set("Menu.Language", vec[selected]);
// CheatMenu::GenHeaderList();
}
else
{

View File

@ -7,11 +7,6 @@
----------------------------
-- Should get picked up automatically if you installed them properly
PSDK_DIR = os.getenv("PLUGIN_SDK_DIR")
DX9SDK_DIR = os.getenv("DXSDK_DIR")
if (DX9SDK_DIR == nil) then
-- error("DXSDK_DIR environment variable not set")
end
if (PSDK_DIR == nil) then
error("PLUGIN_SDK_DIR environment variable not set")
@ -101,7 +96,8 @@ workspace "CheatMenu"
"d3d9",
"d3d11",
"Pdh",
"urlmon"
"urlmon",
"Xinput9_1_0"
}
defines {