diff --git a/src/graphics/ui/GUI.cpp b/src/graphics/ui/GUI.cpp
index cdff6fc5..0fc17f8c 100644
--- a/src/graphics/ui/GUI.cpp
+++ b/src/graphics/ui/GUI.cpp
@@ -1,9 +1,14 @@
#include "GUI.hpp"
+
+#include "gui_util.hpp"
+
#include "elements/UINode.hpp"
+#include "elements/Label.hpp"
#include "elements/Menu.hpp"
#include "../../assets/Assets.hpp"
#include "../../frontend/UiDocument.hpp"
+#include "../../frontend/locale.hpp"
#include "../../graphics/core/Batch2D.hpp"
#include "../../graphics/core/Shader.hpp"
#include "../../graphics/core/DrawContext.hpp"
@@ -27,6 +32,15 @@ GUI::GUI() {
menu->setId("menu");
container->add(menu);
container->setScrollable(false);
+
+ tooltip = guiutil::create(
+ ""
+ ""
+ ""
+ );
+ store("tooltip", tooltip);
+ store("tooltip.label", UINode::find(tooltip, "tooltip.label"));
+ container->add(tooltip);
}
GUI::~GUI() {
@@ -45,10 +59,34 @@ void GUI::onAssetsLoad(Assets* assets) {
), "core:root");
}
+void GUI::updateTooltip(float delta) {
+ float mouseDelta = glm::length(Events::delta);
+ if ((hover && mouseDelta < 1.0f) ||
+ (hover && hover->isInside(Events::cursor) && tooltipTimer >= tooltipDelay)) {
+ if (tooltipTimer + delta >= tooltipDelay) {
+ auto label = std::dynamic_pointer_cast(get("tooltip.label"));
+ const auto& text = hover->getTooltip();
+ if (label && !text.empty()) {
+ tooltip->setVisible(true);
+ tooltip->setPos(Events::cursor+glm::vec2(10.0f));
+ label->setText(langs::get(text));
+ tooltip->setSize(label->getSize()+glm::vec2(4.0f));
+ }
+ }
+ tooltipTimer += delta;
+ } else {
+ tooltipTimer = 0.0f;
+ tooltip->setVisible(false);
+ }
+}
+
/// @brief Mouse related input and logic handling
void GUI::actMouse(float delta) {
+ updateTooltip(delta);
+
+ float mouseDelta = glm::length(Events::delta);
doubleClicked = false;
- doubleClickTimer += delta + glm::length(Events::delta) * 0.1f;
+ doubleClickTimer += delta + mouseDelta * 0.1f;
auto hover = container->getAt(Events::cursor, nullptr);
if (this->hover && this->hover != hover) {
diff --git a/src/graphics/ui/GUI.hpp b/src/graphics/ui/GUI.hpp
index e88a3ea1..cb1dc4ff 100644
--- a/src/graphics/ui/GUI.hpp
+++ b/src/graphics/ui/GUI.hpp
@@ -54,21 +54,25 @@ namespace gui {
/// @brief The main UI controller
class GUI {
std::shared_ptr container;
- std::shared_ptr hover = nullptr;
- std::shared_ptr pressed = nullptr;
- std::shared_ptr focus = nullptr;
+ std::shared_ptr hover;
+ std::shared_ptr pressed;
+ std::shared_ptr focus;
+ std::shared_ptr tooltip;
std::unordered_map> storage;
std::unique_ptr uicamera;
std::shared_ptr