refactor: add FrameMenu
This commit is contained in:
16
include/render/gui/FrameMenu.h
Normal file
16
include/render/gui/FrameMenu.h
Normal 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
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include "GuiWidget.h"
|
#include "GuiWidget.h"
|
||||||
|
|
||||||
#include "render/gui/imgui/imgui_filebrowser.h"
|
#include "imgui/imgui_filebrowser.h"
|
||||||
|
|
||||||
#include "game/server/Server.h"
|
#include "game/server/Server.h"
|
||||||
|
|
||||||
|
|||||||
30
src/render/gui/FrameMenu.cpp
Normal file
30
src/render/gui/FrameMenu.cpp
Normal 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
|
||||||
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "render/gui/MainMenu.h"
|
#include "render/gui/MainMenu.h"
|
||||||
#include "render/gui/GameMenu.h"
|
#include "render/gui/GameMenu.h"
|
||||||
|
#include "render/gui/FrameMenu.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
@@ -29,16 +30,16 @@ namespace TowerGui {
|
|||||||
static SDL_Window* window;
|
static SDL_Window* window;
|
||||||
static SDL_GLContext gl_context;
|
static SDL_GLContext gl_context;
|
||||||
static std::unique_ptr<td::client::Client> client;
|
static std::unique_ptr<td::client::Client> client;
|
||||||
static std::thread* serverThread;
|
|
||||||
static td::render::Renderer* renderer;
|
static td::render::Renderer* renderer;
|
||||||
static std::unique_ptr<td::gui::MainMenu> mainMenu;
|
static std::unique_ptr<td::gui::MainMenu> mainMenu;
|
||||||
static std::unique_ptr<td::gui::GameMenu> gameMenu;
|
static std::unique_ptr<td::gui::GameMenu> gameMenu;
|
||||||
|
static std::unique_ptr<td::gui::FrameMenu> frameMenu;
|
||||||
|
|
||||||
bool serverShouldStop = false;
|
|
||||||
|
|
||||||
void initWidgets(){
|
void initWidgets(){
|
||||||
mainMenu = std::make_unique<td::gui::MainMenu>(client.get());
|
mainMenu = std::make_unique<td::gui::MainMenu>(client.get());
|
||||||
gameMenu = std::make_unique<td::gui::GameMenu>(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) {
|
void init(SDL_Window* sdl_window, SDL_GLContext sdlContext, td::render::Renderer* render) {
|
||||||
@@ -69,20 +70,6 @@ void endFrame() {
|
|||||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
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() {
|
void tick() {
|
||||||
static std::uint64_t lastTime = td::utils::getTime();
|
static std::uint64_t lastTime = td::utils::getTime();
|
||||||
std::uint64_t time = td::utils::getTime();
|
std::uint64_t time = td::utils::getTime();
|
||||||
@@ -104,18 +91,16 @@ void render() {
|
|||||||
static bool demo_open = false;
|
static bool demo_open = false;
|
||||||
if (demo_open)
|
if (demo_open)
|
||||||
ImGui::ShowDemoWindow(&demo_open);
|
ImGui::ShowDemoWindow(&demo_open);
|
||||||
renderFPSCounter();
|
frameMenu->render();
|
||||||
endFrame();
|
endFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy() {
|
void destroy() {
|
||||||
client->closeConnection();
|
client->closeConnection();
|
||||||
client.reset();
|
client.reset();
|
||||||
serverShouldStop = true;
|
mainMenu.reset();
|
||||||
if (serverThread != nullptr) {
|
gameMenu.reset();
|
||||||
serverThread->join();
|
frameMenu.reset();
|
||||||
delete serverThread;
|
|
||||||
}
|
|
||||||
ImGui_ImplOpenGL3_Shutdown();
|
ImGui_ImplOpenGL3_Shutdown();
|
||||||
ImGui_ImplSDL2_Shutdown();
|
ImGui_ImplSDL2_Shutdown();
|
||||||
ImGui::DestroyContext();
|
ImGui::DestroyContext();
|
||||||
|
|||||||
Reference in New Issue
Block a user