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/StarTeleportDialog.cpp | 173 +++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 source/frontend/StarTeleportDialog.cpp (limited to 'source/frontend/StarTeleportDialog.cpp') diff --git a/source/frontend/StarTeleportDialog.cpp b/source/frontend/StarTeleportDialog.cpp new file mode 100644 index 0000000..eef6250 --- /dev/null +++ b/source/frontend/StarTeleportDialog.cpp @@ -0,0 +1,173 @@ +#include "StarTeleportDialog.hpp" +#include "StarWorldClient.hpp" +#include "StarUniverseClient.hpp" +#include "StarClientContext.hpp" +#include "StarCelestialDatabase.hpp" +#include "StarTeamClient.hpp" +#include "StarPlayer.hpp" +#include "StarQuestManager.hpp" +#include "StarAssets.hpp" +#include "StarRoot.hpp" +#include "StarGuiReader.hpp" +#include "StarPaneManager.hpp" +#include "StarButtonWidget.hpp" +#include "StarImageWidget.hpp" +#include "StarLabelWidget.hpp" +#include "StarListWidget.hpp" + +namespace Star { + +TeleportDialog::TeleportDialog(UniverseClientPtr client, + PaneManager* paneManager, + Json config, + EntityId sourceEntityId, + TeleportBookmark currentLocation) { + m_client = client; + m_paneManager = paneManager; + m_sourceEntityId = sourceEntityId; + m_currentLocation = currentLocation; + + auto assets = Root::singleton().assets(); + + GuiReader reader; + + reader.registerCallback("dismiss", bind(&Pane::dismiss, this)); + reader.registerCallback("teleport", bind(&TeleportDialog::teleport, this)); + reader.registerCallback("selectDestination", bind(&TeleportDialog::selectDestination, this)); + + reader.construct(assets->json("/interface/windowconfig/teleportdialog.config:paneLayout"), this); + + config = assets->fetchJson(config); + auto destList = fetchChild("bookmarkList.bookmarkItemList"); + destList->registerMemberCallback("editBookmark", bind(&TeleportDialog::editBookmark, this)); + + for (auto dest : config.getArray("destinations", JsonArray())) { + if (auto prerequisite = dest.optString("prerequisiteQuest")) { + if (!m_client->mainPlayer()->questManager()->hasCompleted(*prerequisite)) + continue; + } + + auto warpAction = parseWarpAction(dest.getString("warpAction")); + bool deploy = dest.getBool("deploy", false); + if (warpAction == WarpAlias::OrbitedWorld && !m_client->canBeamDown(deploy)) + continue; + + auto entry = destList->addItem(); + entry->fetchChild("name")->setText(dest.getString("name")); + entry->fetchChild("planetName")->setText(dest.getString("planetName", "")); + if (dest.contains("icon")) + entry->fetchChild("icon")->setImage( + strf("/interface/bookmarks/icons/%s.png", dest.getString("icon"))); + entry->fetchChild("editButton")->hide(); + + if (dest.getBool("mission", false)) { + // if the warpaction is for an instance world, set the uuid to the team uuid + if (auto warpToWorld = warpAction.ptr()) { + if (auto worldId = warpToWorld->world.ptr()) + warpAction = WarpToWorld(InstanceWorldId(worldId->instance, m_client->teamUuid(), worldId->level), warpToWorld->target); + } + } + + m_destinations.append({warpAction, deploy}); + } + + String beamPartyMember = assets->json("/interface/windowconfig/teleportdialog.config:beamPartyMemberLabel").toString(); + String deployPartyMember = assets->json("/interface/windowconfig/teleportdialog.config:deployPartyMemberLabel").toString(); + String beamPartyMemberIcon = assets->json("/interface/windowconfig/teleportdialog.config:beamPartyMemberIcon").toString(); + String deployPartyMemberIcon = assets->json("/interface/windowconfig/teleportdialog.config:deployPartyMemberIcon").toString(); + + if (config.getBool("includePartyMembers", false)) { + auto teamClient = m_client->teamClient(); + for (auto member : teamClient->members()) { + if (member.uuid == m_client->mainPlayer()->uuid() || member.warpMode == WarpMode::None) + continue; + + auto entry = destList->addItem(); + entry->fetchChild("name")->setText(member.name); + + if (member.warpMode == WarpMode::DeployOnly) + entry->fetchChild("planetName")->setText(deployPartyMember); + else + entry->fetchChild("planetName")->setText(beamPartyMember); + + if (member.warpMode == WarpMode::DeployOnly) + entry->fetchChild("icon")->setImage(deployPartyMemberIcon); + else + entry->fetchChild("icon")->setImage(beamPartyMemberIcon); + + entry->fetchChild("editButton")->hide(); + + m_destinations.append({WarpToPlayer(member.uuid), member.warpMode == WarpMode::DeployOnly}); + } + } + + if (config.getBool("includePlayerBookmarks", false)) { + auto teleportBookmarks = m_client->mainPlayer()->universeMap()->teleportBookmarks(); + + teleportBookmarks.sort([](auto const& a, auto const& b) { return a.bookmarkName.toLower() < b.bookmarkName.toLower(); }); + + for (auto bookmark : teleportBookmarks) { + auto entry = destList->addItem(); + setupBookmarkEntry(entry, bookmark); + if (bookmark == m_currentLocation) { + destList->setEnabled(destList->itemPosition(entry), false); + entry->fetchChild("editButton")->setEnabled(false); + } + m_destinations.append({WarpToWorld(bookmark.target.first, bookmark.target.second), false}); + } + } + + fetchChild("btnTeleport")->setEnabled(destList->selectedItem() != NPos); +} + +void TeleportDialog::tick() { + if (!m_client->worldClient()->playerCanReachEntity(m_sourceEntityId)) + dismiss(); +} + +void TeleportDialog::selectDestination() { + auto destList = fetchChild("bookmarkList.bookmarkItemList"); + fetchChild("btnTeleport")->setEnabled(destList->selectedItem() != NPos); +} + +void TeleportDialog::teleport() { + auto destList = fetchChild("bookmarkList.bookmarkItemList"); + if (destList->selectedItem() != NPos) { + auto& destination = m_destinations[destList->selectedItem()]; + auto warpAction = destination.first; + bool deploy = destination.second; + + auto warp = [this, deploy](WarpAction const& action, String const& animation = "default") { + if (deploy) + m_client->warpPlayer(action, true, "deploy", true); + else + m_client->warpPlayer(action, true, animation); + }; + + m_client->worldClient()->sendEntityMessage(m_sourceEntityId, "onTeleport", {printWarpAction(warpAction)}); + if (warpAction.is() && warpAction.get() == WarpAlias::OrbitedWorld) { + warp(take(destination).first, "beam"); + } else { + warp(take(destination).first); + } + dismiss(); + } +} + +void TeleportDialog::editBookmark() { + auto destList = fetchChild("bookmarkList.bookmarkItemList"); + if (destList->selectedItem() != NPos) { + size_t selectedItem = destList->selectedItem(); + auto bookmarks = m_client->mainPlayer()->universeMap()->teleportBookmarks(); + bookmarks.sort([](auto const& a, auto const& b) { return a.bookmarkName.toLower() < b.bookmarkName.toLower(); }); + selectedItem = selectedItem - (m_destinations.size() - bookmarks.size()); + if (bookmarks.size() > selectedItem) { + auto editBookmarkDialog = make_shared(m_client->mainPlayer()->universeMap()); + editBookmarkDialog->setBookmark(bookmarks[selectedItem]); + m_paneManager->displayPane(PaneLayer::ModalWindow, editBookmarkDialog); + } + dismiss(); + } +} + +} -- cgit v1.2.3