ICT290 / src / scene / theArchanist / gui / hud.cpp
hud.cpp
Raw
#include "hud.h"
#include "../../../engine/UI.h"
#include "../../../glIncludes.h"

void ARCH_HUD::drawHud(float time,
                       float health,
                       float mana,
                       int level,
                       int maxLevel,
                       int difficulty,
                       int enemies) {
    UI::startUIFrame();
    FRAME::hud(time, level, maxLevel, difficulty, enemies);
    FRAME::status(health, mana);
    UI::stopUIFrame();
}

void ARCH_HUD::FRAME::hud(float time,
                          int level,
                          int maxLevel,
                          int difficulty,
                          int enemies) {
    ImGui::Begin("hud", nullptr, windowSettings());

    ImGui::Text("Time: %.2f \nLevel: %i/%i", time, level, maxLevel);

    if (difficulty == 0) {
        ImGui::Text("Difficulty: Easy");
    } else if (difficulty == 1) {
        ImGui::Text("Difficulty: Normal");
    } else {
        ImGui::Text("Difficulty: Hard");
    }

    ImGui::Text("Enemies left: %i", enemies);

    ImGui::End();
}

void ARCH_HUD::FRAME::status(float health, float mana) {
    int h, w;
    SDL_GetWindowSize(SDL_GL_GetCurrentWindow(), &w, &h);
    ImGui::SetNextWindowPos(ImVec2{(float)w / 2, (float)h - 50},
                            0,
                            ImVec2{0.5f, 0.5f});
    ImGui::Begin("status", nullptr, windowSettings());

    ImGui::Text("Health ");
    ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
    ImGui::PushItemWidth((float)w / 4);
    ImGui::PushStyleColor(ImGuiCol_PlotHistogram,
                          ImVec4(ImColor{153, 0, 0, 200}));
    ImGui::ProgressBar(health, ImVec2(0.0f, 0.0f));

    ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);

    ImGui::PopStyleColor(1);

    ImGui::PushItemWidth((float)w / 4);
    ImGui::PushStyleColor(ImGuiCol_PlotHistogram,
                          ImVec4(ImColor{0, 0, 153, 200}));
    ImGui::ProgressBar(mana, ImVec2(0.0f, 0.0f));
    ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
    ImGui::Text(" Mana");

    ImGui::PopStyleColor(1);

    ImGui::End();
}

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

void ARCH_HUD::FRAME::trapDoorOpened() {
    int h, w;
    SDL_GetWindowSize(SDL_GL_GetCurrentWindow(), &w, &h);
    ImGui::SetNextWindowPos(ImVec2{(float)w / 2, (float)h - 150.f},
                            0,
                            ImVec2{0.5f, 0.5f});
    ImGui::Begin("msg", nullptr, windowSettings());

    ImGui::Text("All enemies slain, the Trapdoor has opened!");

    ImGui::End();
}

void ARCH_HUD::drawTrapdoorMsg() {
    UI::startUIFrame();
    FRAME::trapDoorOpened();
    UI::stopUIFrame();
}