From 6352e8e3196f78388b6c771073f9e03eaa612673 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Tue, 20 Jun 2023 14:33:09 +1000 Subject: everything everywhere all at once --- source/frontend/StarJoinRequestDialog.cpp | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 source/frontend/StarJoinRequestDialog.cpp (limited to 'source/frontend/StarJoinRequestDialog.cpp') diff --git a/source/frontend/StarJoinRequestDialog.cpp b/source/frontend/StarJoinRequestDialog.cpp new file mode 100644 index 0000000..9d854df --- /dev/null +++ b/source/frontend/StarJoinRequestDialog.cpp @@ -0,0 +1,52 @@ +#include "StarJoinRequestDialog.hpp" +#include "StarGuiReader.hpp" +#include "StarRoot.hpp" +#include "StarLabelWidget.hpp" +#include "StarButtonWidget.hpp" +#include "StarImageWidget.hpp" +#include "StarRandom.hpp" +#include "StarAssets.hpp" + +namespace Star { + +JoinRequestDialog::JoinRequestDialog() {} + +void JoinRequestDialog::displayRequest(String const& userName, function callback) { + auto assets = Root::singleton().assets(); + + removeAllChildren(); + + GuiReader reader; + + m_callback = move(callback); + + reader.registerCallback("yes", [this](Widget*){ reply(P2PJoinRequestReply::Yes); }); + reader.registerCallback("no", [this](Widget*){ reply(P2PJoinRequestReply::No); }); + reader.registerCallback("ignore", [this](Widget*){ reply(P2PJoinRequestReply::Ignore); }); + + m_confirmed = false; + + Json config = assets->json("/interface/windowconfig/joinrequest.config"); + + reader.construct(config.get("paneLayout"), this); + + String message = config.getString("joinMessage").replaceTags(StringMap{{"username", userName}}); + fetchChild("message")->setText(message); + + show(); +} + +void JoinRequestDialog::reply(P2PJoinRequestReply reply) { + m_confirmed = true; + m_callback(reply); + dismiss(); +} + +void JoinRequestDialog::dismissed() { + if (!m_confirmed) + m_callback(P2PJoinRequestReply::No); + + Pane::dismissed(); +} + +} -- cgit v1.2.3