Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
Don't show current portal in dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
sweetgiorni committed Mar 6, 2021
1 parent 1cf8dfc commit f808955
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions AnyPortal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ static void Postfix(TeleportWorld __instance, ref ZNetView ___m_nview, ref bool
{
lastPortalInteracted = __instance;
lastPortalZNetView = ___m_nview;

if (!__result)
{
return;
Expand All @@ -256,20 +256,24 @@ static void Postfix(TeleportWorld __instance, ref ZNetView ___m_nview, ref bool
DropdownValueChanged(dropdown);
});
dropdown.options.Clear();
ZDOID thisPortalZDOID = ___m_nview.GetZDO().m_uid;
// If the portal currently has a target configured, make sure that is the value selected in the dropdown
// Otherwise, set the dropdown value to 0 (No destination)
ZDOID targetZDOID = ___m_nview.GetZDO().GetZDOID("target");

dropdown.options.Add(new Dropdown.OptionData("No destination"));
var tmpPortalList = new List<ZDO>();
ZDOMan.instance.GetAllZDOsWithPrefab(Game.instance.m_portalPrefab.name, tmpPortalList);
portalList = tmpPortalList.OrderBy(zdo => zdo.GetString("tag")).ToList();

// Sort alphabetically by portal tag and exclude self
portalList = tmpPortalList.OrderBy(zdo => zdo.GetString("tag")).Where(zdo => zdo.m_uid != thisPortalZDOID).ToList();
int index = 0;
foreach (ZDO portalZDO in portalList)
{
float distance = Vector3.Distance(__instance.transform.position, portalZDO.GetPosition());

if (distance == 0f)
{
continue;
}
dropdown.options.Add(new Dropdown.OptionData($"\"{portalZDO.GetString("tag")}\" -- Distance: " + (int)distance));
if (portalZDO.m_uid == targetZDOID)
dropdown.value = index + 1;
Expand Down

0 comments on commit f808955

Please sign in to comment.