mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-08-08 17:57:02 +08:00
refactor(config): rename hot_reload to reload_config and add settings scene
This commit is contained in:
@@ -27,6 +27,7 @@ public:
|
||||
|
||||
void init();
|
||||
void play_bgm();
|
||||
void stop_bgm();
|
||||
void change_bgm(const std::string& sound);
|
||||
void play_3d(const std::string& sound, const glm::vec3& pos,
|
||||
bool check = false);
|
||||
|
||||
@@ -25,7 +25,6 @@ public:
|
||||
}
|
||||
|
||||
set(key, default_value);
|
||||
save_to_file();
|
||||
|
||||
return default_value;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
const MoveState& get_move_state() const;
|
||||
|
||||
void change_mode(GameMode mode);
|
||||
void hot_reload();
|
||||
void reload_config();
|
||||
void set_player_pos(const glm::vec3& pos);
|
||||
void set_place_block(unsigned id);
|
||||
void update(float delta_time);
|
||||
|
||||
@@ -83,7 +83,7 @@ public:
|
||||
void start_thread_pool();
|
||||
void stop_thread_pool();
|
||||
void change_pool_threads(int threads);
|
||||
void hot_reload();
|
||||
void reload_config(bool chunk_build = true);
|
||||
void request_chunk();
|
||||
std::vector<glm::vec4>& planes();
|
||||
const std::vector<const ChunkRenderSnapshot*>& render_snapshots() const;
|
||||
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
|
||||
Renderer(TextureManager& texture_manager, Config& config);
|
||||
~Renderer();
|
||||
void hot_reload();
|
||||
void reload_config();
|
||||
void init(bool debug_on);
|
||||
const Shader& get_shader(const std::string& name) const;
|
||||
void begin_frame();
|
||||
|
||||
@@ -11,6 +11,7 @@ public:
|
||||
void render(Renderer& renderer) override;
|
||||
bool handle_event(const Event& e) override;
|
||||
void on_enter() override;
|
||||
void on_re_enter() override;
|
||||
SceneManager& scene_manager();
|
||||
|
||||
private:
|
||||
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
bool handle_event(const Event& e) override;
|
||||
void on_enter() override;
|
||||
void on_leave() override;
|
||||
|
||||
void on_re_enter() override;
|
||||
SceneManager& scene_manager();
|
||||
|
||||
private:
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace Cubed {
|
||||
class Renderer;
|
||||
|
||||
enum class SceneType { MAIN_MENU, WORLD, CREDITS };
|
||||
enum class SceneType { MAIN_MENU, WORLD, CREDITS, SETTINGS };
|
||||
|
||||
class Scene {
|
||||
public:
|
||||
@@ -20,6 +20,7 @@ public:
|
||||
virtual bool handle_event(const Event& e) = 0;
|
||||
virtual void on_enter() {};
|
||||
virtual void on_leave() {};
|
||||
virtual void on_re_enter() {};
|
||||
|
||||
protected:
|
||||
virtual bool handle_mouse_move_event(const MouseMoveEvent&) {
|
||||
|
||||
@@ -40,7 +40,7 @@ private:
|
||||
void process_operation();
|
||||
void change(SceneType type);
|
||||
void push(SceneType type);
|
||||
void pop();
|
||||
void pop(bool re_enter = true);
|
||||
|
||||
std::unique_ptr<Scene> create_scene(SceneType);
|
||||
};
|
||||
|
||||
39
include/Cubed/scene/settings_scene.hpp
Normal file
39
include/Cubed/scene/settings_scene.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
#include "Cubed/scene/scene.hpp"
|
||||
#include "Cubed/ui/settings_ui.hpp"
|
||||
namespace Cubed {
|
||||
|
||||
struct SliderVariable {
|
||||
float fov = 70.0f;
|
||||
float mouse_sensitivity = 0.15f;
|
||||
float sfx = 1.0f;
|
||||
float music = 0.5f;
|
||||
int rendering_distance = 24;
|
||||
};
|
||||
|
||||
class SceneManager;
|
||||
class SettingsScene : public Scene {
|
||||
public:
|
||||
SettingsScene(const SettingsScene&) = delete;
|
||||
SettingsScene(SettingsScene&&) = delete;
|
||||
SettingsScene& operator=(const SettingsScene&) = delete;
|
||||
SettingsScene& operator=(SettingsScene&&) = delete;
|
||||
SettingsScene(SceneManager& scene_manager);
|
||||
~SettingsScene();
|
||||
|
||||
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();
|
||||
SliderVariable& slider_variable();
|
||||
|
||||
private:
|
||||
void save_and_apply();
|
||||
SceneManager& m_scene_manager;
|
||||
SliderVariable m_slider_variable;
|
||||
SettingsUI m_settings_ui;
|
||||
};
|
||||
} // namespace Cubed
|
||||
@@ -24,7 +24,7 @@ public:
|
||||
bool handle_event(const Event& e) override;
|
||||
void on_enter() override;
|
||||
void on_leave() override;
|
||||
|
||||
void on_re_enter() override;
|
||||
Camera& camera();
|
||||
SceneManager& scene_manager();
|
||||
ClientWorld& client_world();
|
||||
|
||||
@@ -27,6 +27,7 @@ public:
|
||||
Button& set_height(float height);
|
||||
Button& set_background_image(const std::string& path,
|
||||
TextureManager& texture_manager);
|
||||
Button& set_default_image(TextureManager& texture_manager);
|
||||
Button& set_text(const std::string& text);
|
||||
|
||||
float scale() const;
|
||||
@@ -38,6 +39,8 @@ public:
|
||||
private:
|
||||
static constexpr float PADDING = 5.0f;
|
||||
static constexpr float DEFAULT_SCALE = 3.0f;
|
||||
static constexpr const char* DEFAULT_BUTTON_IMAGE =
|
||||
"texture/ui/button001.png";
|
||||
std::function<void()> m_clicked;
|
||||
std::unique_ptr<Image> m_background;
|
||||
std::unique_ptr<Label> m_foreground;
|
||||
|
||||
16
include/Cubed/ui/settings_ui.hpp
Normal file
16
include/Cubed/ui/settings_ui.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "Cubed/ui/ui_manager.hpp"
|
||||
namespace Cubed {
|
||||
class SettingsScene;
|
||||
class SettingsUI : public UIManager {
|
||||
public:
|
||||
SettingsUI(SettingsScene& scene);
|
||||
void init() override;
|
||||
|
||||
private:
|
||||
bool handle_key_event(const KeyEvent& e) override;
|
||||
SettingsScene& m_scene;
|
||||
};
|
||||
|
||||
} // namespace Cubed
|
||||
@@ -29,13 +29,18 @@ public:
|
||||
Slider& set_thumb_image(const std::string& path,
|
||||
TextureManager& texture_manager);
|
||||
|
||||
Slider& set_default_image(TextureManager& texture_manager);
|
||||
|
||||
bool handle_mouse_move_event(const MouseMoveEvent& e) override;
|
||||
bool handle_mouse_button_event(const MouseButtonEvent& e) override;
|
||||
|
||||
private:
|
||||
static constexpr float PADDING = 5.0f;
|
||||
static constexpr float DEFAULT_SCALE = 3.0f;
|
||||
|
||||
static constexpr const char* DEFAULT_TRACK_IMAGE =
|
||||
"texture/ui/slider_track001.png";
|
||||
static constexpr const char* DEFAULT_THUMB_IMAGE =
|
||||
"texture/ui/slider_thumb001.png";
|
||||
std::unique_ptr<Image> m_track;
|
||||
std::unique_ptr<Image> m_thumb;
|
||||
std::unique_ptr<Label> m_label;
|
||||
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
// end of frame to reload!
|
||||
bool handle_event(const Event& e);
|
||||
|
||||
void hot_reload();
|
||||
void reload_config();
|
||||
|
||||
void toggle_fullscreen();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user