refactor: add FrameMenu

This commit is contained in:
2021-11-04 11:21:37 +01:00
parent 9453b25aaa
commit a4d3a9472b
4 changed files with 54 additions and 23 deletions

View File

@@ -0,0 +1,16 @@
#pragma once
#include "GuiWidget.h"
namespace td {
namespace gui {
class FrameMenu : public GuiWidget {
public:
FrameMenu(client::Client* client);
virtual void render();
};
} // namespace gui
} // namespace td

View File

@@ -2,7 +2,7 @@
#include "GuiWidget.h"
#include "render/gui/imgui/imgui_filebrowser.h"
#include "imgui/imgui_filebrowser.h"
#include "game/server/Server.h"

View File

@@ -0,0 +1,30 @@
#include "render/gui/FrameMenu.h"
#include "render/gui/imgui/imgui.h"
#include "game/client/Client.h"
#include <SDL2/SDL.h>
namespace td {
namespace gui {
FrameMenu::FrameMenu(client::Client* client) : GuiWidget(client){
}
void FrameMenu::render() {
ImGui::Begin("FPS Counter");
ImGui::Text("FPS : %i", (int)ImGui::GetIO().Framerate);
static bool vsync = true;
if (ImGui::Checkbox("V-Sync", &vsync)) {
SDL_GL_SetSwapInterval(vsync);
}
static bool isometric = true;
if (ImGui::Checkbox("Vue Isometrique ?", &isometric)) {
getClient()->getRenderer()->setIsometricView(isometric);
}
ImGui::End();
}
} // namespace gui
} // namespace td

View File

@@ -20,6 +20,7 @@
#include "render/gui/MainMenu.h"
#include "render/gui/GameMenu.h"
#include "render/gui/FrameMenu.h"
#include <iostream>
#include <cmath>
@@ -29,16 +30,16 @@ namespace TowerGui {
static SDL_Window* window;
static SDL_GLContext gl_context;
static std::unique_ptr<td::client::Client> client;
static std::thread* serverThread;
static td::render::Renderer* renderer;
static std::unique_ptr<td::gui::MainMenu> mainMenu;
static std::unique_ptr<td::gui::GameMenu> gameMenu;
static std::unique_ptr<td::gui::FrameMenu> frameMenu;
bool serverShouldStop = false;
void initWidgets(){
mainMenu = std::make_unique<td::gui::MainMenu>(client.get());
gameMenu = std::make_unique<td::gui::GameMenu>(client.get());
frameMenu = std::make_unique<td::gui::FrameMenu>(client.get());
}
void init(SDL_Window* sdl_window, SDL_GLContext sdlContext, td::render::Renderer* render) {
@@ -69,20 +70,6 @@ void endFrame() {
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}
void renderFPSCounter() {
ImGui::Begin("FPS Counter");
ImGui::Text("FPS : %i", (int)ImGui::GetIO().Framerate);
static bool vsync = true;
if (ImGui::Checkbox("V-Sync", &vsync)) {
SDL_GL_SetSwapInterval(vsync);
}
static bool isometric = true;
if (ImGui::Checkbox("Vue Isometrique ?", &isometric)) {
renderer->setIsometricView(isometric);
}
ImGui::End();
}
void tick() {
static std::uint64_t lastTime = td::utils::getTime();
std::uint64_t time = td::utils::getTime();
@@ -104,18 +91,16 @@ void render() {
static bool demo_open = false;
if (demo_open)
ImGui::ShowDemoWindow(&demo_open);
renderFPSCounter();
frameMenu->render();
endFrame();
}
void destroy() {
client->closeConnection();
client.reset();
serverShouldStop = true;
if (serverThread != nullptr) {
serverThread->join();
delete serverThread;
}
mainMenu.reset();
gameMenu.reset();
frameMenu.reset();
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext();