diff --git a/assets/lang/en_US.json b/assets/lang/en_US.json index bd45502..1efc672 100644 --- a/assets/lang/en_US.json +++ b/assets/lang/en_US.json @@ -4,6 +4,7 @@ "menu.main.join_game": "Join Game", "menu.main.credits": "Credits", "menu.main.quit": "Quit", + "menu.screenshot": "Screenshots", "menu.main.player_name": "Player: {name}", "menu.main.cubed_version": "Cubed: {version}", "menu.pause.pause_menu": "Pause Menu", @@ -46,5 +47,6 @@ "item.snowy_grass_block.name": "snowy grass block", "item.stone.name": "stone", "item.water.name": "water", - "item.pig_spawn_egg.name": "pig spawn egg" + "item.pig_spawn_egg.name": "pig spawn egg", + "screenshot.no_screenshot": "No Screenshot" } \ No newline at end of file diff --git a/assets/lang/zh_CN.json b/assets/lang/zh_CN.json index 362fb53..f86e61e 100644 --- a/assets/lang/zh_CN.json +++ b/assets/lang/zh_CN.json @@ -4,6 +4,7 @@ "menu.main.join_game": "加入游戏", "menu.main.credits": "制作人员", "menu.main.quit": "退出", + "menu.screenshot": "屏幕截图", "menu.main.player_name": "玩家:{name}", "menu.main.cubed_version": "Cubed:{version}", "menu.pause.pause_menu": "暂停菜单", @@ -46,5 +47,6 @@ "item.snowy_grass_block.name": "覆雪草方块", "item.stone.name": "石头", "item.water.name": "水", - "item.pig_spawn_egg.name": "猪猪刷怪蛋" + "item.pig_spawn_egg.name": "猪猪刷怪蛋", + "screenshot.no_screenshot": "没有截图" } \ No newline at end of file diff --git a/include/Cubed/scene/scene.hpp b/include/Cubed/scene/scene.hpp index b11f8c2..ce94a9b 100644 --- a/include/Cubed/scene/scene.hpp +++ b/include/Cubed/scene/scene.hpp @@ -9,7 +9,8 @@ enum class SceneType { CREDITS, SETTINGS, HOST_GAME, - JOIN_GAME + JOIN_GAME, + SCREENSHOT }; class Scene { diff --git a/include/Cubed/scene/screenshot_scene.hpp b/include/Cubed/scene/screenshot_scene.hpp new file mode 100644 index 0000000..49c0cef --- /dev/null +++ b/include/Cubed/scene/screenshot_scene.hpp @@ -0,0 +1,29 @@ +#pragma once +#include "Cubed/scene/scene.hpp" +#include "Cubed/ui/screenshot_ui.hpp" +namespace Cubed { +class SceneManager; +class ScreenshotScene : public Scene { +public: + ScreenshotScene(SceneManager& scene_manager); + ~ScreenshotScene(); + + ScreenshotScene(const ScreenshotScene&) = delete; + ScreenshotScene(ScreenshotScene&&) = delete; + ScreenshotScene& operator=(const ScreenshotScene&) = delete; + ScreenshotScene& operator=(ScreenshotScene&&) = 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; + ScreenshotUI m_ui; +}; +} // namespace Cubed diff --git a/include/Cubed/texture_manager.hpp b/include/Cubed/texture_manager.hpp index b078106..5ea2c45 100644 --- a/include/Cubed/texture_manager.hpp +++ b/include/Cubed/texture_manager.hpp @@ -20,7 +20,8 @@ public: const Texture* get_block_status_array() const; const Texture* get_texture_array() const; const Texture* get_cross_plane_array() const; - const Texture* get_image_texture(const std::string& path); + const Texture* get_image_texture(const std::string& path, + bool full_path = false); const Texture* get_pbr_texture() const; const ItemTextureMap& get_item_textures() const; const Texture* get_skin() const; @@ -49,7 +50,8 @@ private: void load_block_texture(unsigned block_id); void init_item_texture(); void load_cross_plane_texture(unsigned id); - const Texture* load_image_texture(const std::string& path); + const Texture* load_image_texture(const std::string& path, + bool full_path = false); void load_pbr_texture(unsigned id); void init_item(); void init_block(); diff --git a/include/Cubed/ui/screenshot_ui.hpp b/include/Cubed/ui/screenshot_ui.hpp new file mode 100644 index 0000000..7c316b7 --- /dev/null +++ b/include/Cubed/ui/screenshot_ui.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include "Cubed/ui/ui_manager.hpp" +namespace Cubed { +class ScreenshotScene; +class ScreenshotUI : public UIManager { +public: + ScreenshotUI(ScreenshotScene& m_scene); + ~ScreenshotUI(); + + ScreenshotUI(const ScreenshotUI&) = delete; + ScreenshotUI(ScreenshotUI&&) = delete; + ScreenshotUI& operator=(const ScreenshotUI&) = delete; + ScreenshotUI& operator=(ScreenshotUI&&) = delete; + + void init(); + + void update_layout(int width, int height); + +private: + ScreenshotScene& m_scene; +}; +} // namespace Cubed \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2665999..5ef935c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -106,4 +106,6 @@ target_sources(${PROJECT_NAME} tools/json_utils.cpp gameplay/item_manager.cpp gameplay/block_manager.cpp + ui/screenshot_ui.cpp + scene/screenshot_scene.cpp ) \ No newline at end of file diff --git a/src/scene/scene_manager.cpp b/src/scene/scene_manager.cpp index 6c58b16..2ac27f2 100644 --- a/src/scene/scene_manager.cpp +++ b/src/scene/scene_manager.cpp @@ -4,6 +4,7 @@ #include "Cubed/scene/host_game_scene.hpp" #include "Cubed/scene/join_game_scene.hpp" #include "Cubed/scene/main_menu_scene.hpp" +#include "Cubed/scene/screenshot_scene.hpp" #include "Cubed/scene/settings_scene.hpp" #include "Cubed/scene/world_scene.hpp" @@ -33,15 +34,24 @@ bool SceneManager::handle_event(const Event& e) { } void SceneManager::request_change(SceneType type) { - ASSERT(!m_operation.has_value()); + if (m_operation.has_value()) { + Logger::error("Scene operation has_value"); + return; + } m_operation = {OperationType::CHANGE, type}; } void SceneManager::request_push(SceneType type) { - ASSERT(!m_operation.has_value()); + if (m_operation.has_value()) { + Logger::error("Scene operation has_value"); + return; + } m_operation = {OperationType::PUSH, type}; } void SceneManager::request_pop() { - ASSERT(!m_operation.has_value()); + if (m_operation.has_value()) { + Logger::error("Scene operation has_value"); + return; + } m_operation = {OperationType::POP, std::nullopt}; } @@ -103,6 +113,8 @@ std::unique_ptr SceneManager::create_scene(SceneType type) { return std::make_unique(*this); case SceneType::JOIN_GAME: return std::make_unique(*this); + case SceneType::SCREENSHOT: + return std::make_unique(*this); } std::string err = std::format("Unknown Scene"); diff --git a/src/scene/screenshot_scene.cpp b/src/scene/screenshot_scene.cpp new file mode 100644 index 0000000..1e04ff9 --- /dev/null +++ b/src/scene/screenshot_scene.cpp @@ -0,0 +1,20 @@ +#include "Cubed/scene/screenshot_scene.hpp" + +namespace Cubed { +ScreenshotScene::ScreenshotScene(SceneManager& scene_manager) + : m_scene_manager(scene_manager), m_ui(*this) {} + +ScreenshotScene::~ScreenshotScene() {} + +void ScreenshotScene::update(float dt) { m_ui.update(dt); } +void ScreenshotScene::render(Renderer& renderer) { m_ui.render(renderer); } +bool ScreenshotScene::handle_event(const Event& e) { + return m_ui.handle_event(e); +} +void ScreenshotScene::on_enter() { m_ui.init(); } +void ScreenshotScene::on_leave() {} +void ScreenshotScene::on_re_enter() {} + +SceneManager& ScreenshotScene::scene_manager() { return m_scene_manager; } + +} // namespace Cubed \ No newline at end of file diff --git a/src/texture_manager.cpp b/src/texture_manager.cpp index c49d7a8..83ca742 100644 --- a/src/texture_manager.cpp +++ b/src/texture_manager.cpp @@ -57,12 +57,13 @@ const Texture* TextureManager::get_texture_array() const { const Texture* TextureManager::get_cross_plane_array() const { return m_cross_plane_array.get(); } -const Texture* TextureManager::get_image_texture(const std::string& path) { +const Texture* TextureManager::get_image_texture(const std::string& path, + bool full_path) { auto it = m_ui_map.find(path); if (it != m_ui_map.end()) { return it->second.get(); } - return load_image_texture(path); + return load_image_texture(path, full_path); } const Texture* TextureManager::get_pbr_texture() const { @@ -151,9 +152,10 @@ void TextureManager::load_cross_plane_texture(unsigned id) { CROSS_PLANE_SIZE, CROSS_PLANE_SIZE); } -const Texture* TextureManager::load_image_texture(const std::string& path) { +const Texture* TextureManager::load_image_texture(const std::string& path, + bool full_path) { - auto image_data = (Tools::load_image_data(path)); + auto image_data = (Tools::load_image_data(path, true, full_path)); std::unique_ptr image = std::make_unique(TextureType::TEXTURE_2D); image->tex_image_2d(RGBA, RGBA, GL_UNSIGNED_BYTE, image_data.data, diff --git a/src/ui/main_menu_ui_manager.cpp b/src/ui/main_menu_ui_manager.cpp index 7d63f16..cf57931 100644 --- a/src/ui/main_menu_ui_manager.cpp +++ b/src/ui/main_menu_ui_manager.cpp @@ -58,7 +58,16 @@ void MainMenuUIManager::init() { }); m_pending_enable.emplace_back(&button); } - + { + auto& button = layout.add_child