void Awake()
        {
            instance = this;

            On.RoR2.Chat.AddMessage_string += (orig, message) =>
            {
                orig(message);
                if (ParseUserAndMessage(message, out string userName, out string text))
                {
                    string[] pieces = text.Split(' ');
                    TriggerChatCommand(userName, pieces);
                }
            };

            FrogtownModDetails details = new FrogtownModDetails("com.frogtown.shared")
            {
                githubAuthor = "ToyDragon",
                githubRepo   = "ROR2ModShared",
                description  = "Powers this UI and contains shared resources for other mods.",
                noDisable    = true,
                OnGUI        = () =>
                {
                    bool newShowOnStart = GUILayout.Toggle(UI.instance.uiSettings.showOnStart, "Show this window on startup", GUILayout.ExpandWidth(false));
                    if (newShowOnStart != UI.instance.uiSettings.showOnStart)
                    {
                        UI.instance.uiSettings.showOnStart = newShowOnStart;
                        UI.instance.SaveSettings();
                    }
                }
            };

            details.OnlyContainsBugFixesOrUIChangesThatArentContriversial();
            ModManager.RegisterMod(details);

            //I use this to test multiplayer, leave it off in releases
            Invoke(nameof(Init), 1f);
        }
 private IEnumerator CheckForUpdates()
 {
     return(ModManager.CheckForUpdates());
 }
 public static void RegisterMod(FrogtownModDetails details)
 {
     ModManager.RegisterMod(details);
 }
Example #4
0
        private void DrawModTab(ref UnityAction buttons)
        {
            var minWidth = GUILayout.MinWidth(windowSize.x);

            scrollPositions[0] = GUILayout.BeginScrollView(scrollPositions[0], minWidth, GUILayout.ExpandHeight(false));
            var amountWidth = columns.Where(x => !x.skip).Sum(x => x.width);
            var expandWidth = columns.Where(x => x.expand && !x.skip).Sum(x => x.width);

            var colWidth = columns.Select(x =>
                                          x.expand
                    ? GUILayout.Width(x.width / expandWidth * (windowSize.x - 60 + expandWidth - amountWidth))
                    : GUILayout.Width(x.width)).ToArray();

            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal("box");
            for (int i = 0; i < columns.Count; i++)
            {
                if (columns[i].skip)
                {
                    continue;
                }
                GUILayout.Label(columns[i].name, colWidth[i]);
            }

            GUILayout.EndHorizontal();
            var GUIDs = ModManager.modDetails.Keys.ToArray();

            Array.Sort(GUIDs, (a, b) => {
                ModManager.modDetails.TryGetValue(a, out ModDetails details);
                string aAuthor = details.frogtownModDetails?.githubAuthor ?? "Unknown";

                ModManager.modDetails.TryGetValue(b, out details);
                string bAuthor = details.frogtownModDetails?.githubAuthor ?? "Unknown";

                return(aAuthor.CompareTo(bAuthor));
            });

            List <ModRow> rows = new List <ModRow>();

            string lastAuthor = "";
            ModRow authorRow  = null;

            foreach (string GUID in GUIDs)
            {
                ModManager.modDetails.TryGetValue(GUID, out ModDetails details);
                if (ModManager.whitelistFrameworkUnlisted.Contains(details.GUID))
                {
                    continue;
                }

                string author = details.frogtownModDetails?.githubAuthor ?? "Unknown";
                if (author != lastAuthor)
                {
                    if (authorRow != null)
                    {
                        rows.Add(authorRow);
                        authorRow = null;
                    }
                    if (collapsedAuthors.Contains(author))
                    {
                        authorRow = new ModRow();
                        ModRow rowAnchor = authorRow;
                        authorRow.canToggle = ModManager.CanToggleMod(GUID, out bool isActive);
                        if (authorRow.canToggle)
                        {
                            authorRow.isActive = isActive;
                        }
                        authorRow.githubAuthor = author;
                        if (authorRow.githubAuthor != "Unknown")
                        {
                            authorRow.url     = "https://github.com/" + author;
                            authorRow.modName = "All mods from " + author;
                        }
                        else
                        {
                            authorRow.modName = "All mods from unknown authors";
                        }
                        authorRow.isAuthorCollapsed = true;
                        authorRow.description       = details.modName;
                        authorRow.firstForAuthor    = true;

                        if (details.frogtownModDetails == null && details.enabled != details.initialEnabled)
                        {
                            authorRow.statusStyle   = red;
                            authorRow.statusMessage = "Mod will be " + (details.enabled ? "enabled" : "disabled") + " the next time the game is started.";
                        }

                        authorRow.onToggleActive += () =>
                        {
                            FrogtownShared.Log("FrogShared", LogLevel.Info, "Setting mods from " + rowAnchor.githubAuthor + " to " + !rowAnchor.isActive);
                            foreach (string otherGUID in GUIDs)
                            {
                                ModManager.modDetails.TryGetValue(otherGUID, out ModDetails otherDetails);
                                string otherAuthor = otherDetails.frogtownModDetails?.githubAuthor ?? "Unknown";
                                if (otherAuthor == author)
                                {
                                    if (ModManager.CanToggleMod(otherGUID, out bool unused))
                                    {
                                        ModManager.ToggleMod(otherGUID, !rowAnchor.isActive);
                                    }
                                }
                            }
                        };

                        authorRow.onToggleAuthor += () =>
                        {
                            collapsedAuthors.Remove(rowAnchor.githubAuthor);
                        };
                        lastAuthor = author;

                        continue;
                    }
                }

                if (authorRow != null)
                {
                    bool canToggle = ModManager.CanToggleMod(GUID, out bool isActive);
                    authorRow.canToggle = authorRow.canToggle || canToggle;
                    if (canToggle)
                    {
                        authorRow.isActive = authorRow.isActive || isActive;
                    }
                    authorRow.description += ", " + details.modName;

                    if (details.frogtownModDetails == null && details.enabled != details.initialEnabled)
                    {
                        authorRow.statusStyle   = red;
                        authorRow.statusMessage = "Mod will be " + (details.enabled ? "enabled" : "disabled") + " the next time the game is started.";
                    }
                }
                else
                {
                    ModRow row = new ModRow();
                    row.canToggle = ModManager.CanToggleMod(GUID, out bool isActive);
                    row.isActive  = isActive;

                    row.githubAuthor = author;
                    if (details.frogtownModDetails != null)
                    {
                        row.url = "https://github.com/" + details.frogtownModDetails.githubAuthor + "/" + details.frogtownModDetails.githubRepo;
                    }
                    row.isAuthorCollapsed = false;
                    row.modName           = details.modName;
                    row.description       = details.frogtownModDetails?.description ?? "";
                    row.firstForAuthor    = author != lastAuthor;
                    row.version           = details.version;
                    row.newVersionLoading = details.frogtownModDetails?.newVersionLoading ?? false;
                    row.newVersion        = details.frogtownModDetails?.newVersion ?? "";
                    row.onToggleActive   += () =>
                    {
                        ModManager.ToggleMod(GUID, !row.isActive);
                    };
                    row.onToggleAuthor += () =>
                    {
                        collapsedAuthors.Add(row.githubAuthor);
                    };

                    if (details.frogtownModDetails == null && details.enabled != details.initialEnabled)
                    {
                        row.statusStyle   = red;
                        row.statusMessage = "Mod will be " + (details.enabled ? "enabled" : "disabled") + " the next time the game is started.";
                    }

                    rows.Add(row);
                }

                lastAuthor = author;
            }

            if (authorRow != null)
            {
                rows.Add(authorRow);
            }

            foreach (var row in rows)
            {
                int col = -1;
                GUILayout.BeginHorizontal("box");
                GUILayout.BeginHorizontal(colWidth[++col]);
                if (row.firstForAuthor)
                {
                    bool newIsCollapsed = row.isAuthorCollapsed;
                    newIsCollapsed = GUILayout.Toggle(newIsCollapsed, new GUIContent("", "Collapse mods from " + row.githubAuthor + "."));
                    if (newIsCollapsed != row.isAuthorCollapsed)
                    {
                        row.onToggleAuthor?.Invoke();
                    }
                }
                else
                {
                    GUILayout.Label(" ", GUILayout.Width(56f));
                }
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal(colWidth[++col]);
                GUILayout.Label(new GUIContent(row.githubAuthor, row.description));
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal(colWidth[++col]);
                GUILayout.Label(new GUIContent(row.modName, row.description));

                GUILayout.FlexibleSpace();
                if (!string.IsNullOrEmpty(row.url))
                {
                    if (GUILayout.Button(new GUIContent("www", row.url), button))
                    {
                        Application.OpenURL(row.url);
                    }
                }
                else
                {
                    GUILayout.Label(new GUIContent("---", "No repository available."));
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal(colWidth[++col]);
                GUILayout.Label(row.version, curVersion, GUILayout.ExpandWidth(false));
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal(colWidth[++col]);
                if (row.githubAuthor != "Unknown" && !row.isAuthorCollapsed)
                {
                    if (row.newVersionLoading)
                    {
                        GUILayout.Label(new GUIContent("...", "Checking latest release..."));
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(row.newVersion))
                        {
                            if (GUILayout.Button(row.newVersion, h2))
                            {
                                Application.OpenURL(row.url + "/releases");
                            }
                        }
                        else
                        {
                            GUILayout.Label(new GUIContent("---", "No new version found."));
                        }
                    }
                }
                else
                {
                    GUILayout.Label(new GUIContent("---", "Can't load releases for " + row.modName + "."));
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal(colWidth[++col]);
                if (row.canToggle)
                {
                    bool newIsActive = row.isActive;
                    newIsActive = GUILayout.Toggle(row.isActive, new GUIContent("", (row.isActive ? "Disable" : "Enable") + " " + row.modName + "."));
                    if (newIsActive != row.isActive)
                    {
                        row.onToggleActive?.Invoke();
                    }
                }
                else
                {
                    GUILayout.Label(new GUIContent("X", row.modName + " cannot be disabled."), nodisable);
                }
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal(colWidth[++col]);
                if (!string.IsNullOrEmpty(row.statusMessage))
                {
                    GUILayout.Label(new GUIContent("R", row.statusMessage), row.statusStyle);
                }
                GUILayout.EndHorizontal();
                GUILayout.EndHorizontal();
            }
            GUILayout.EndVertical();
            GUILayout.EndScrollView();
        }