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/StarBookmarkInterface.cpp | 81 +++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 source/frontend/StarBookmarkInterface.cpp (limited to 'source/frontend/StarBookmarkInterface.cpp') diff --git a/source/frontend/StarBookmarkInterface.cpp b/source/frontend/StarBookmarkInterface.cpp new file mode 100644 index 0000000..132ac13 --- /dev/null +++ b/source/frontend/StarBookmarkInterface.cpp @@ -0,0 +1,81 @@ +#include "StarBookmarkInterface.hpp" +#include "StarGuiReader.hpp" +#include "StarButtonWidget.hpp" +#include "StarImageWidget.hpp" +#include "StarTextBoxWidget.hpp" +#include "StarLabelWidget.hpp" +#include "StarRoot.hpp" +#include "StarAssets.hpp" + +namespace Star { + +EditBookmarkDialog::EditBookmarkDialog(PlayerUniverseMapPtr playerUniverseMap) { + m_playerUniverseMap = playerUniverseMap; + + GuiReader reader; + auto assets = Root::singleton().assets(); + reader.registerCallback("ok", [this](Widget*) { ok(); }); + reader.registerCallback("remove", [this](Widget*) { remove(); }); + reader.registerCallback("close", [this](Widget*) { close(); }); + reader.registerCallback("name", [](Widget*) {}); + reader.construct(assets->json("/interface/windowconfig/editbookmark.config:paneLayout"), this); + dismiss(); +} + +void EditBookmarkDialog::setBookmark(TeleportBookmark bookmark) { + m_bookmark = bookmark; + + m_isNew = true; + for (auto& existing : m_playerUniverseMap->teleportBookmarks()) { + if (existing == bookmark) { + m_bookmark.bookmarkName = existing.bookmarkName; + m_isNew = false; + } + } +} + +void EditBookmarkDialog::show() { + Pane::show(); + + if (m_isNew) { + fetchChild("lblTitle")->setText("NEW BOOKMARK"); + fetchChild("remove")->hide(); + } else { + fetchChild("lblTitle")->setText("EDIT BOOKMARK"); + fetchChild("remove")->show(); + } + + auto assets = Root::singleton().assets(); + fetchChild("imgIcon")->setImage(strf("/interface/bookmarks/icons/%s.png", m_bookmark.icon)); + + fetchChild("lblPlanetName")->setText(m_bookmark.targetName); + fetchChild("name")->setText(m_bookmark.bookmarkName, false); + fetchChild("name")->focus(); +} + +void EditBookmarkDialog::ok() { + m_bookmark.bookmarkName = fetchChild("name")->getText(); + if (m_bookmark.bookmarkName.empty()) + m_bookmark.bookmarkName = m_bookmark.targetName; + if (!m_isNew) + m_playerUniverseMap->removeTeleportBookmark(m_bookmark); + m_playerUniverseMap->addTeleportBookmark(m_bookmark); + dismiss(); +} + +void EditBookmarkDialog::remove() { + m_playerUniverseMap->removeTeleportBookmark(m_bookmark); + dismiss(); +} + +void EditBookmarkDialog::close() { + dismiss(); +} + +void setupBookmarkEntry(WidgetPtr const& entry, TeleportBookmark const& bookmark) { + entry->fetchChild("name")->setText(bookmark.bookmarkName); + entry->fetchChild("planetName")->setText(bookmark.targetName); + entry->fetchChild("icon")->setImage(strf("/interface/bookmarks/icons/%s.png", bookmark.icon)); +} + +} -- cgit v1.2.3