Files
EGameTools/DL2GameOverhaulScript/source/menu/menu.cpp

65 lines
3.2 KiB
C++
Raw Normal View History

#include <pch.h>
#include "menu.h"
2023-07-30 06:14:30 +03:00
namespace Menu {
const std::string title = "EGameTools (" + std::string(MOD_VERSION_STR) + ")";
ImGuiStyle defStyle{};
ImTextureID EGTLogoTexture{};
static constexpr ImVec2 defEGTLogoSize = ImVec2(278.0f, 100.0f);
static ImVec2 EGTLogoSize = defEGTLogoSize;
static constexpr ImGuiWindowFlags windowFlags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoScrollbar;
static constexpr ImVec2 defMinWndSize = ImVec2(425.0f, 725.0f);
static ImVec2 minWndSize = defMinWndSize;
static constexpr ImVec2 defMaxWndSize = ImVec2(900.0f, 725.0f);
static ImVec2 maxWndSize = defMaxWndSize;
KeyBindOption menuToggle = KeyBindOption(VK_F5);
float opacity = 99.0f;
2024-02-03 20:40:17 +02:00
float scale = 1.0f;
2023-07-30 06:14:30 +03:00
Option firstTimeRunning{};
2024-02-12 03:51:26 +02:00
Option hasSeenChangelog{};
2023-07-30 06:14:30 +03:00
void Render() {
ImGui::StyleScaleAllSizes(&ImGui::GetStyle(), scale, &defStyle);
ImGui::GetIO().FontGlobalScale = scale;
minWndSize = defMinWndSize * scale;
2024-02-03 20:40:17 +02:00
maxWndSize = defMaxWndSize * scale;
EGTLogoSize = defEGTLogoSize * scale;
ImGui::SetNextWindowBgAlpha(static_cast<float>(opacity) / 100.0f);
ImGui::SetNextWindowSizeConstraints(minWndSize, maxWndSize);
ImGui::Begin(title.c_str(), &menuToggle.value, windowFlags); {
ImGui::SetCursorPosX((ImGui::GetWindowWidth() / 2.0f) - (EGTLogoSize.x / 2.0f));
ImGui::Image(EGTLogoTexture, EGTLogoSize);
const float footerHeight = ImGui::GetFrameHeightWithSpacing() * 3.0f + GImGui->Style.WindowPadding.y * 2.0f + GImGui->Style.FramePadding.y * 2.0f;
const float remainingHeight = ImGui::GetContentRegionAvail().y - footerHeight;
2023-07-30 06:14:30 +03:00
if (ImGui::BeginTabBar("##MainTabBar")) {
for (auto& tab : *MenuTab::GetInstances()) {
static float childWidth = 0.0f;
ImGui::SpanNextTabAcrossWidth(childWidth, MenuTab::GetInstances()->size());
if (ImGui::BeginTabItem(tab.second->tabName.data())) {
ImGui::SetNextWindowBgAlpha(static_cast<float>(opacity) / 100.0f);
ImGui::SetNextWindowSizeConstraints(ImVec2(minWndSize.x - GImGui->Style.WindowPadding.x * 2.0f, remainingHeight), ImVec2(maxWndSize.x - GImGui->Style.WindowPadding.x * 2.0f, remainingHeight));
if (ImGui::BeginChild("##TabChild", ImVec2(0.0f, 0.0f), ImGuiChildFlags_AlwaysAutoResize | ImGuiChildFlags_AutoResizeX | ImGuiChildFlags_Border)) {
childWidth = ImGui::GetItemRectSize().x;
tab.second->Render();
ImGui::EndChild();
}
ImGui::EndTabItem();
}
2023-07-30 06:14:30 +03:00
}
ImGui::EndTabBarEx();
2023-07-30 06:14:30 +03:00
}
ImGui::Hotkey("Menu Toggle Key", &menuToggle);
ImGui::SliderFloat("Menu Opacity", &opacity, 0.0f, 100.0f, "%.1f%%", ImGuiSliderFlags_AlwaysClamp);
ImGui::SliderFloat("Menu Scale", &scale, 1.0f, 2.5f, "%.1f%%", ImGuiSliderFlags_AlwaysClamp);
ImGui::End();
}
2023-07-30 06:14:30 +03:00
}
}