mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-09 02:07:04 +08:00
feat(scene): add host game scene and world parameter handling
This commit is contained in:
@@ -18,6 +18,7 @@ public:
|
||||
ChunkGenerator(ServerChunk& chunk);
|
||||
|
||||
static void init();
|
||||
static void init(unsigned seed);
|
||||
static void reload();
|
||||
static const unsigned& seed();
|
||||
static void seed(unsigned s);
|
||||
|
||||
29
include/Cubed/scene/host_game_scene.hpp
Normal file
29
include/Cubed/scene/host_game_scene.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "Cubed/scene/scene.hpp"
|
||||
#include "Cubed/ui/host_game_ui.hpp"
|
||||
namespace Cubed {
|
||||
class SceneManager;
|
||||
class HostGameScene : public Scene {
|
||||
public:
|
||||
HostGameScene(SceneManager& scene_manager);
|
||||
~HostGameScene();
|
||||
|
||||
HostGameScene(const HostGameScene&) = delete;
|
||||
HostGameScene(HostGameScene&&) = delete;
|
||||
HostGameScene& operator=(const HostGameScene&) = delete;
|
||||
HostGameScene& operator=(HostGameScene&&) = delete;
|
||||
|
||||
void update(float dt) override;
|
||||
void render(Renderer& renderer) override;
|
||||
bool handle_event(const Event& e) override;
|
||||
void on_enter() override;
|
||||
void on_leave() override;
|
||||
void on_re_enter() override;
|
||||
SceneManager& scene_manager();
|
||||
|
||||
private:
|
||||
SceneManager& m_scene_manager;
|
||||
HostGameUI m_ui;
|
||||
};
|
||||
} // namespace Cubed
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace Cubed {
|
||||
class Renderer;
|
||||
|
||||
enum class SceneType { MAIN_MENU, WORLD, CREDITS, SETTINGS };
|
||||
enum class SceneType { MAIN_MENU, WORLD, CREDITS, SETTINGS, HOST_GAME };
|
||||
|
||||
class Scene {
|
||||
public:
|
||||
|
||||
@@ -6,6 +6,14 @@
|
||||
#include <vector>
|
||||
namespace Cubed {
|
||||
class App;
|
||||
|
||||
struct WorldSceneParam {
|
||||
bool host_game = true;
|
||||
std::optional<unsigned> seed = std::nullopt;
|
||||
std::string ip{"127.0.0.1"};
|
||||
int port = 25530;
|
||||
};
|
||||
|
||||
class SceneManager {
|
||||
public:
|
||||
SceneManager(const SceneManager&) = delete;
|
||||
@@ -25,6 +33,7 @@ public:
|
||||
void request_pop();
|
||||
|
||||
App& app();
|
||||
WorldSceneParam& world_scene_param();
|
||||
|
||||
private:
|
||||
enum class OperationType { PUSH, POP, CHANGE };
|
||||
@@ -34,6 +43,7 @@ private:
|
||||
};
|
||||
|
||||
App& m_app;
|
||||
WorldSceneParam m_world_param;
|
||||
std::vector<std::unique_ptr<Scene>> m_pending_delete_scene;
|
||||
std::optional<SceneOperation> m_operation;
|
||||
std::stack<std::unique_ptr<Scene>> m_scenes;
|
||||
|
||||
16
include/Cubed/ui/host_game_ui.hpp
Normal file
16
include/Cubed/ui/host_game_ui.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "Cubed/ui/ui_manager.hpp"
|
||||
namespace Cubed {
|
||||
class HostGameScene;
|
||||
class HostGameUI : public UIManager {
|
||||
public:
|
||||
HostGameUI(HostGameScene& scene);
|
||||
|
||||
void init() override;
|
||||
void on_re_enter();
|
||||
|
||||
private:
|
||||
HostGameScene& m_scene;
|
||||
};
|
||||
} // namespace Cubed
|
||||
Reference in New Issue
Block a user