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

Commit

Permalink
Update FavsExporterByPlague.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
MistressPlague authored Jul 7, 2022
1 parent a39e0d2 commit 794e779
Showing 1 changed file with 54 additions and 62 deletions.
116 changes: 54 additions & 62 deletions UniversalFavsExporter/UniversalFavsExporter/FavsExporterByPlague.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,89 +40,81 @@ public IEnumerator VRChat_OnUiManagerInit()

public IEnumerator DelayedUIInit()
{
//Get All Fav Lists
var AvatarFavsArea =
GameObject.Find("UserInterface/MenuContent/Screens/Avatar/Vertical Scroll View/Viewport/Content/");
MelonLogger.Msg("Init!");

while (AvatarFavsArea == null || !AvatarFavsArea.active)
while (true)
{
yield return new WaitForSeconds(1f);
//Get All Fav Lists
var AvatarFavsArea =
GameObject.Find("UserInterface/MenuContent/Screens/Avatar/Vertical Scroll View/Viewport/Content/");

AvatarFavsArea = GameObject.Find("UserInterface/MenuContent/Screens/Avatar/Vertical Scroll View/Viewport/Content/");
}
while (AvatarFavsArea == null || !AvatarFavsArea.active)
{
yield return new WaitForSeconds(1f);

for (var i = 0; i < AvatarFavsArea.transform.childCount; i++)
{
var Child = AvatarFavsArea.transform.GetChild(i);
AvatarFavsArea = GameObject.Find("UserInterface/MenuContent/Screens/Avatar/Vertical Scroll View/Viewport/Content/");
}

if (Child.GetComponent<UiAvatarList>() != null) // Is A Avi List
var Lists = Resources.FindObjectsOfTypeAll<UiAvatarList>().Select(o => o.transform).ToList();

for (var i = 0; i < Lists.Count; i++)
{
//Make Button
var Dupe = UnityEngine.Object.Instantiate(GameObject.Find("UserInterface/MenuContent/Screens/Avatar/Change Button"), Child.Find("Button"));
var Child = Lists[i];

Dupe.GetComponent<RectTransform>().sizeDelta = new Vector2(30f, 80f);
if (Child.GetComponent<UiAvatarList>() != null && Child.Find("Button/TitleText/FavsExporter") == null) // Is A Avi List
{
//Make Button
var Dupe = UnityEngine.Object.Instantiate(GameObject.Find("UserInterface/MenuContent/Screens/Avatar/Change Button"), Child.Find("Button"));

//This Is Done To Fix Positioning
Dupe.transform.localPosition = new Vector3(115f, 0f, 0f);
Dupe.transform.SetParent(Child.Find("Button/TitleText"));
Dupe.name = "FavsExporter";
Dupe.GetComponent<RectTransform>().sizeDelta = new Vector2(30f, 80f);

Dupe.GetComponentInChildren<Text>(true).text = "E";
Dupe.GetComponent<Button>().onClick = new Button.ButtonClickedEvent();
Dupe.GetComponent<Button>().onClick.AddListener(DelegateSupport.ConvertDelegate<UnityAction>(
new Action(() =>
{
var FavsInList = Child.GetComponentsInChildren<VRCUiContentButton>(true)
.Select(o => o.field_Public_String_0).Where(p => p != null).ToList();
//This Is Done To Fix Positioning
Dupe.transform.localPosition = new Vector3(115f, 0f, 0f);
Dupe.transform.SetParent(Child.Find("Button/TitleText"));

if (FavsInList.Count > 0)
Dupe.GetComponentInChildren<Text>(true).text = "E";
Dupe.GetComponent<Button>().onClick = new Button.ButtonClickedEvent();
Dupe.GetComponent<Button>().onClick.AddListener(DelegateSupport.ConvertDelegate<UnityAction>(
new Action(() =>
{
var Json = JsonConvert.SerializeObject(FavsInList);
var FavsInList = Child.GetComponentsInChildren<VRCUiContentButton>(true)
.Select(o => o.field_Public_String_0).Where(p => p != null).ToList();

if (!Directory.Exists(Environment.CurrentDirectory + "\\ExportedFavs"))
if (FavsInList.Count > 0)
{
Directory.CreateDirectory(Environment.CurrentDirectory + "\\ExportedFavs");
}
var Json = JsonConvert.SerializeObject(FavsInList);

var FilePath = Environment.CurrentDirectory + "\\ExportedFavs\\" +
MakeValidFileName(Child.Find("Button/TitleText").GetComponent<Text>().text) + ".json";
if (!Directory.Exists(Environment.CurrentDirectory + "\\ExportedFavs"))
{
Directory.CreateDirectory(Environment.CurrentDirectory + "\\ExportedFavs");
}

File.WriteAllText(FilePath, Json);
var FilePath = Environment.CurrentDirectory + "\\ExportedFavs\\" +
MakeValidFileName(Child.Find("Button/TitleText").GetComponent<Text>().text) + ".json";

ChillOkayPopup("Alert",
"Your Fav List Was Exported To: " + FilePath + "\n\nYou Can Move It To " +
Environment.CurrentDirectory +
"\\UserData\\FavCatImport\\ To Import The Fav List Into Plague's Modpack.\n\nModpack Discord Invite: https://plague.cx",
PopupType.FullScreen);
}
else
{
ChillOkayPopup("Error",
"No Favs In List To Export!",
PopupType.FullScreen);
}
})));

Dupe.SetActive(Child.gameObject.active);
File.WriteAllText(FilePath, Json);

EnableDisableListener Listener = null;
ChillOkayPopup("Alert",
"Your Fav List Was Exported To: " + FilePath + "\n\nYou Can Move It To " +
Environment.CurrentDirectory +
"\\UserData\\FavCatImport\\ To Import The Fav List Into Plague's Modpack.\n\nModpack Discord Invite: https://plague.cx",
PopupType.FullScreen);
}
else
{
ChillOkayPopup("Error",
"No Favs In List To Export!",
PopupType.FullScreen);
}
})));

Listener = Child.gameObject.GetComponent<EnableDisableListener>() == null ? Child.gameObject.AddComponent<EnableDisableListener>() : Child.gameObject.GetComponent<EnableDisableListener>();

Listener.OnEnabled += () =>
{
Dupe.SetActive(true);
};

Listener.OnDisabled += () =>
{
Dupe.SetActive(false);
};
}
}
}

MelonLogger.Msg("Init!");

yield break;
yield return new WaitForSeconds(5f);
}
}

static char[] _invalids;
Expand Down

0 comments on commit 794e779

Please sign in to comment.