feat(scene): add credits scene and UI

This commit is contained in:
2026-07-14 16:28:26 +08:00
parent 279f6162b8
commit e911413d84
10 changed files with 174 additions and 6 deletions

77
src/ui/credits_ui.cpp Normal file
View File

@@ -0,0 +1,77 @@
#include "Cubed/ui/credits_ui.hpp"
#include "Cubed/app.hpp"
#include "Cubed/scene/credits_scene.hpp"
#include "Cubed/scene/scene_manager.hpp"
#include "Cubed/ui/button.hpp"
#include "Cubed/ui/column_layout.hpp"
#include "Cubed/ui/image.hpp"
#include "Cubed/ui/rect.hpp"
namespace Cubed {
CreditsUI::CreditsUI(CreditsScene& scene) : m_scene(scene) {}
void CreditsUI::init() {
auto& renderer = m_scene.scene_manager().app().renderer();
auto image = std::make_unique<Image>(nullptr);
image->set_fill(true)
.set_image("texture/ui/background.png",
m_scene.scene_manager().app().texture_manager())
.set_anchor(Anchor::TOP_LEFT)
.set_window_size(renderer.window_width(), renderer.window_height());
auto& rect = image->add_child<Rect>();
rect.set_fill(true).set_color(Color::BLACK).set_alpha(0.7f);
{
auto& button = rect.add_child<Button>();
auto& back = button.set_background<Image>();
back.set_image("texture/ui/button001.png",
m_scene.scene_manager().app().texture_manager());
auto& fore = button.set_foreground<Label>();
fore.set_scale(0.5f).set_text("Return");
button.set_scale(4.0f)
.set_anchor(Anchor::BOTTOM_CENTER)
.set_offset({0, -20});
button.set_clicked([this]() { m_scene.scene_manager().request_pop(); });
}
{
auto& layout = rect.add_child<ColumnLayout>();
layout.set_spacing(20)
.set_anchor(Anchor::TOP_CENTER)
.set_offset({0, 20});
layout.add_child<Label>().set_text("Cubed");
auto add_text = [&](std::string_view view, float scale = 0.5f) {
layout.add_child<Label>().set_text(view).set_scale(scale);
};
add_text("A cube game like Minecraft, using C++ and OpenGL.");
add_text("Author: zhenyan121");
add_text("Libraries Used", 0.8f);
add_text("glad");
add_text("GLFW");
add_text("SOIL2");
add_text("GLM");
add_text("FreeType");
add_text("toml++");
add_text("Dear ImGui");
add_text("Tbb");
add_text("Asio");
add_text("protobuf");
add_text("zstd");
add_text("OpenAl Soft");
add_text("dr_libs");
add_text("Music", 0.8f);
add_text("'Find a Peaceful Place' by ROZKOL (Free Music Archive), CC "
"BY 4.0.");
add_text("Special Thanks", 0.8f);
add_text("TANGERIME");
add_text("SkyOnPole");
add_text("free_w_cloud");
add_text("Last but not least, thanks to you");
}
m_root_widget = std::move(image);
}
} // namespace Cubed