internal static void GameSpecificSetup(Harmony harmony) { Assert.IsNotNull(harmony); SceneManager.activeSceneChanged += SceneChanged; ExtendedSave.CardBeingSaved += CardBeingSaved; TranslationHelper.CardTranslationBehaviorChanged += TranslationHelperCardTranslationBehaviorChanged; CharaFileInfoWrapper.RegisterWrapperType(typeof(CustomFileInfo), typeof(CustomFileInfoWrapper)); if (KoikatuAPI.IsSteamRelease()) { Party.Hooks.Setup(); } else { Standard.Hooks.Setup(); } }
private static IEnumerator CreateSidebarWindow() { var origWindow = GameObject.Find("CharaCustom/CustomControl/CanvasDraw"); var copyWindow = Object.Instantiate(origWindow, origWindow.transform.parent, false); copyWindow.name = "Canvas_AIAPI_Sidebar"; yield return(null); yield return(null); yield return(new WaitForEndOfFrame()); var copyWindowContents = copyWindow.transform.Find("DrawWindow"); Object.Destroy(copyWindowContents.GetComponent <CustomDrawMenu>()); var windowCgroup = copyWindowContents.GetComponent <CanvasGroup>(); windowCgroup.Enable(true); var rt = copyWindowContents.GetComponent <RectTransform>(); // Needed to account for different resolutions rt.anchoredPosition = new Vector2(rt.anchoredPosition.x, rt.anchoredPosition.y - rt.sizeDelta.y); copyWindowContents.Find("textTitle").GetComponent <Text>().text = "Plugin settings"; var closeBtn = copyWindowContents.Find("imgBack/btnClose").GetComponent <UI_ButtonEx>(); closeBtn.onClick.ActuallyRemoveAllListeners(); var tryCount = 0; closeBtn.onClick.AddListener(() => { if (tryCount == 0) { KoikatuAPI.Logger.LogMessage("Don't do this, you don't want to"); } else if (tryCount == 1) { KoikatuAPI.Logger.LogMessage("This is a bad idea and you know it"); } else if (tryCount == 2) { KoikatuAPI.Logger.LogMessage("Uh-oh, what now?"); copyWindow.SetActive(false); } tryCount++; }); foreach (Transform windowContent in copyWindowContents) { switch (windowContent.name) { case "drawMenu": case "dwChara": case "dwLight": case "dwBG": Object.Destroy(windowContent.gameObject); break; case "dwCoorde": windowContent.name = "dwMain_AIAPI"; Object.Destroy(windowContent.Find("accessory").gameObject); windowContent.GetComponent <CanvasGroup>().Enable(true); var clothTransform = windowContent.Find("clothes"); clothTransform.name = "dwInner_AIAPI"; Object.Destroy(clothTransform.Find("textTitle").gameObject); var clothesRect = clothTransform.GetComponent <RectTransform>(); clothesRect.offsetMin = new Vector2(0, 0); clothesRect.offsetMax = new Vector2(374, 0); var itemsTransform = clothTransform.Find("items"); Object.Destroy(itemsTransform.GetComponent <ToggleGroup>()); var gridLayout = itemsTransform.GetComponent <GridLayoutGroup>(); gridLayout.cellSize = new Vector2(170, 28); // These make layout go down first instead of right first gridLayout.constraint = GridLayoutGroup.Constraint.FixedRowCount; gridLayout.constraintCount = 4; gridLayout.startAxis = GridLayoutGroup.Axis.Vertical; // Use 1 full column if there are not enough items for 2 columns, else use 2 half width columns // Steam release messes with sizes a bit var singleCellSize = KoikatuAPI.IsSteamRelease() ? 240 : 170; gridLayout.cellSize = _sidebarEntries.Count > 4 ? new Vector2(singleCellSize, 28) : new Vector2(singleCellSize * 2, 28); var itemsRect = itemsTransform.GetComponent <RectTransform>(); itemsRect.offsetMin = new Vector2(17, 0); itemsRect.offsetMax = new Vector2(374, 0); foreach (Transform item in itemsTransform) { Object.Destroy(item.gameObject); } foreach (var sidebarEntry in _sidebarEntries) { sidebarEntry.CreateControl(itemsTransform); } KoikatuAPI.Logger.LogDebug( $"Added {_sidebarEntries.Count} custom controls " + "to Control Panel sidebar"); break; } } var control = CustomBase.Instance.customCtrl; while (true) { yield return(null); yield return(null); if (windowCgroup == null || control == null) { yield break; } windowCgroup.Enable(!control.showFusionCvs && !control.showFileList); } }