ICT290 / src / scene / theArchanist / gui / pause.cpp
pause.cpp
Raw
#include "pause.h"

ARCH_GUI::PauseState ARCH_GUI::pauseState{};
ARCH_GUI::Click ARCH_GUI::click{};

void ARCH_GUI::pauseMenu(Resources& resources) {
    UI::startUIFrame();

    if (pauseState.options) {
        FRAME::optionMenuFrame(resources);
    } else {
        FRAME::pauseMenuFrame(resources);
    }

    UI::stopUIFrame();
}

void ARCH_GUI::FRAME::pauseMenuFrame(Resources& resources) {
    ImGui::Begin("The Archanist - Pause", nullptr, windowSettings());
    ImGui::Text("The Archanist    FPS: %d ", resources.settings.fps);
    if (ImGui::Button("Resume")) {
        pauseState.resume = true;
        click.occurred = true;
    }
    if (ImGui::Button("Settings")) {
        pauseState.options = true;
        click.occurred = true;
    }
    if (ImGui::Button("Exit")) {
        pauseState.exit = true;
        click.occurred = true;
    }
    ImGui::End();
}

void ARCH_GUI::FRAME::optionMenuFrame(Resources& resources) {
    ImGui::Begin("The Archanist - Settings", nullptr, windowSettings());
    ImGui::Text("The Archanist");

    ImGui::Text("\nVideo:");

    ImGui::Text("Width:");
    ImGui::PushItemWidth(350);
    ImGui::InputInt("##width", &resources.settings.width);

    ImGui::Text("Height:");
    ImGui::PushItemWidth(350);
    ImGui::InputInt("##height", &resources.settings.height);

    ImGui::Text("Fullscreen: ");
    ImGui::SameLine();
    ImGui::Checkbox("##fullscreen", &resources.settings.fullscreen);

    ImGui::Text("Vsync: ");
    ImGui::SameLine();
    ImGui::Checkbox("##vsync", &resources.settings.vsync);

    ImGui::Text("\nAudio:");

    ImGui::Text("Volume:");
    ImGui::PushItemWidth(350);
    ImGui::InputFloat("##volume",
                      &resources.settings.volume,
                      0.01f,
                      0.1f,
                      "%.2f");
    ImGui::Text("Mute: ");
    ImGui::SameLine();
    ImGui::Checkbox("##mute", &resources.settings.mute);

    ImGui::Text(" ");
    if (ImGui::Button("Return & Save")) {
        pauseState.options = false;
        // Update settings function
        resources.settings.settingsUpdated = true;
        click.occurred = true;
    }
    ImGui::End();
}

void ARCH_GUI::resetPauseState() {
    pauseState.resume = false;
    pauseState.options = false;
    pauseState.exit = false;
}

int ARCH_GUI::FRAME::windowSettings() {
    return ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar
           | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize
           | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoMove;
}