refactor: create MainMenu and GameMenu classes
This commit is contained in:
@@ -25,6 +25,9 @@ public:
|
||||
void sendTimeRemaining();
|
||||
|
||||
void tick();
|
||||
|
||||
//static constexpr int LobbyWaitingTime = 2 * 60 * 1000; // in millis
|
||||
static constexpr int LobbyWaitingTime = 5 * 1000; // in millis
|
||||
};
|
||||
|
||||
} // namespace server
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <thread>
|
||||
|
||||
#include "network/TCPListener.h"
|
||||
#include "protocol/Protocol.h"
|
||||
@@ -11,9 +12,6 @@
|
||||
#include "ServerConnexion.h"
|
||||
#include "Lobby.h"
|
||||
|
||||
//#define LOBBY_WAITING_TIME 2 * 60 * 1000
|
||||
#define LOBBY_WAITING_TIME 5 * 1000
|
||||
|
||||
#define SERVER_TPS 20
|
||||
#define SERVER_TICK 1000 / SERVER_TPS
|
||||
|
||||
@@ -58,12 +56,14 @@ private:
|
||||
ServerGame m_Game{ this };
|
||||
Lobby m_Lobby{ this };
|
||||
TickCounter m_TickCounter;
|
||||
|
||||
std::thread m_Thread;
|
||||
bool m_ServerRunning;
|
||||
public:
|
||||
Server(const std::string& worldFilePath);
|
||||
virtual ~Server() {}
|
||||
|
||||
bool start(std::uint16_t port);
|
||||
void tick(std::uint64_t delta);
|
||||
void stop();
|
||||
|
||||
void lauchGame();
|
||||
@@ -88,6 +88,10 @@ private:
|
||||
void accept();
|
||||
void updateSockets();
|
||||
|
||||
void startThread();
|
||||
void stopThread();
|
||||
void tick(std::uint64_t delta);
|
||||
|
||||
void OnPlayerJoin(std::uint8_t id);
|
||||
void OnPlayerLeave(std::uint8_t id);
|
||||
};
|
||||
|
||||
24
include/render/gui/GameMenu.h
Normal file
24
include/render/gui/GameMenu.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "SummonMenu.h"
|
||||
|
||||
namespace td {
|
||||
namespace gui {
|
||||
|
||||
class GameMenu : public GuiWidget {
|
||||
private:
|
||||
std::unique_ptr<SummonMenu> m_SummonMenu;
|
||||
public:
|
||||
GameMenu(client::Client* client);
|
||||
|
||||
virtual void render();
|
||||
private:
|
||||
void showTPS();
|
||||
void showStats();
|
||||
void showPlayers();
|
||||
void showLobbyProgress();
|
||||
void showTeamSelection();
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
} // namespace td
|
||||
37
include/render/gui/MainMenu.h
Normal file
37
include/render/gui/MainMenu.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include "GuiWidget.h"
|
||||
|
||||
#include "render/gui/imgui/imgui_filebrowser.h"
|
||||
|
||||
#include "game/server/Server.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace td {
|
||||
namespace gui {
|
||||
|
||||
class MainMenu : public GuiWidget {
|
||||
private:
|
||||
bool m_TriedToConnect = false;
|
||||
bool m_TriedToCreate = false;
|
||||
std::string m_ConnectAddress;
|
||||
int m_ConnectPort;
|
||||
int m_ServerPort = 25565;
|
||||
std::string m_WorldFilePath;
|
||||
imgui_addons::ImGuiFileBrowser m_FileDialog;
|
||||
|
||||
std::unique_ptr<server::Server> m_Server;
|
||||
public:
|
||||
MainMenu(client::Client* client);
|
||||
~MainMenu();
|
||||
|
||||
virtual void render();
|
||||
|
||||
const server::Server* getServer() const { return m_Server.get(); }
|
||||
private:
|
||||
bool startServer();
|
||||
};
|
||||
|
||||
} // namespace gui
|
||||
} // namespace td
|
||||
Reference in New Issue
Block a user