Exemplo n.º 1
0
        private static void DebugControls()
        {
            var cat = GetOrCreateCurrentStateCategory("Control test category");

            cat.AddControl(
                new CurrentStateCategoryToggle(
                    "Test 1", 2, c =>
            {
#if PH
                var charInfoHuman = c?.charInfo?.human;
                KoikatuAPI.Logger.LogMessage((charInfoHuman == null ? "NULL" : charInfoHuman.GetCharacterName()) + " - updateValue");
#else
                KoikatuAPI.Logger.LogMessage(c?.charInfo?.name + " - updateValue");
#endif
                return(1);
            }))
            .Value.Subscribe(val => KoikatuAPI.Logger.LogMessage(val));
            cat.AddControl(new CurrentStateCategoryToggle("Test 2", 3, c => 2)).Value.Subscribe(val => KoikatuAPI.Logger.LogMessage(val));
            cat.AddControl(new CurrentStateCategoryToggle("Test 3", 4, c => 3)).Value.Subscribe(val => KoikatuAPI.Logger.LogMessage(val));

            var cat2 = GetOrCreateCurrentStateCategory("Control test category");
            cat2.AddControl(new CurrentStateCategorySwitch("Test add", c => true)).Value.Subscribe(val => KoikatuAPI.Logger.LogMessage(val));
            cat2.AddControl(new CurrentStateCategorySlider("Test slider", c => 0.75f)).Value.Subscribe(val => KoikatuAPI.Logger.LogMessage(val));
            cat2.AddControl(new CurrentStateCategoryDropdown("dropdown test", new[] { "item 1", "i2", "test 3" }, c => 1)).Value.Subscribe(val => KoikatuAPI.Logger.LogMessage("dd " + val));

            CustomToolbarButtons.AddLeftToolbarButton(new Texture2D(32, 32), () => Console.WriteLine("click"));
            CustomToolbarButtons.AddLeftToolbarToggle(new Texture2D(55, 32), true, v => Console.WriteLine("click " + v));
        }
Exemplo n.º 2
0
            internal static void RegisterControls()
            {
                if (!JetPack.CharaStudio.Running)
                {
                    return;
                }

                _charaConfigWindow = _instance.gameObject.AddComponent <AccStateSyncUI>();

                Texture2D _iconTex = TextureUtils.LoadTexture(ResourceUtils.GetEmbeddedResource("toolbar_icon.png"));

                _ttConfigWindow = CustomToolbarButtons.AddLeftToolbarToggle(_iconTex, false, _value => _charaConfigWindow.enabled = _value);

                List <Button> _buttons = GameObject.Find("StudioScene/Canvas Main Menu/02_Manipulate/00_Chara/01_State/Viewport/Content/Clothing Details").GetComponentsInChildren <Button>().ToList();

                _buttons.Add(GameObject.Find($"StudioScene/Canvas Main Menu/02_Manipulate/00_Chara/01_State/Viewport/Content/Cos/Button Shoes 1").GetComponent <Button>());
                _buttons.Add(GameObject.Find($"StudioScene/Canvas Main Menu/02_Manipulate/00_Chara/01_State/Viewport/Content/Cos/Button Shoes 2").GetComponent <Button>());
                foreach (Button _button in _buttons)
                {
                    _button.onClick.AddListener(delegate()
                    {
                        _instance.StartCoroutine(StatusPanelUpdateCoroutine());
                    });
                }

                JetPack.CharaStudio.OnSelectNodeChange += (_sender, _args) =>
                {
                    _curTreeNodeObjID = JetPack.CharaStudio.CurTreeNodeObjID;
                    _curOCIChar       = JetPack.CharaStudio.CurOCIChar;
                    UpdateUI();
                };

                HarmonyLib.Harmony.CreateAndPatchAll(typeof(HooksCharaStudio));
            }
Exemplo n.º 3
0
        private void Awake()
        {
            Logger = base.Logger;

            _showGizmo = Config.Bind("Extra gizmos", "Show extra move gizmo", false,
                                     "Show extra set of gizmos in the bottom right corner of the screen. An object must be selected for gizmo to be visible." +
                                     "You can use left toolbar to turn the gizmo on or off.");
#if !PH
            _referenceToSelectedObject = Config.Bind("Extra gizmos", "Use selected object as reference", true,
                                                     "If true, using the extra XYZ move gizmo is the same as using the default gizmo on the currently selected object (so direction of the arrow may not be the same as direction of movement).\n" +
                                                     "If false, current camera position is used as the reference frame, so using the extra XYZ gizmo will move the object to where the gizmo arrows are actually pointing.\n" +
                                                     "Change currently selected object to apply the setting.");
#endif

            if (StudioAPI.StudioLoaded)
            {
                // for debug purposes, doesn't get called normally
                Initialize();
            }
            else
            {
                var texRes    = ResourceUtils.GetEmbeddedResource("toolbar_icon.png", typeof(StudioExtraMoveAxisPlugin).Assembly) ?? throw new ArgumentException("icon resource not found");
                var buttonTex = texRes.LoadTexture(TextureFormat.DXT5, false) ?? throw new ArgumentException("failed to load icon texture");
                var tgl       = CustomToolbarButtons.AddLeftToolbarToggle(buttonTex, _showGizmo.Value, b => _showGizmo.Value = b);
                _showGizmo.SettingChanged += (o, eventArgs) =>
                {
                    tgl.SetValue(_showGizmo.Value, false);
                    SetVisibility();
                };

                StudioAPI.StudioLoadedChanged += (sender, args) => Initialize();
            }
        }
Exemplo n.º 4
0
        private static void SceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
#endif
        {
            if (!StudioLoaded && scene.name == "Studio")
            {
                StudioLoaded = true;

                if (StudioLoadedChanged != null)
                {
                    foreach (var callback in StudioLoadedChanged.GetInvocationList())
                    {
                        try
                        {
                            ((EventHandler)callback)(KoikatuAPI.Instance, EventArgs.Empty);
                        }
                        catch (Exception e)
                        {
                            KoikatuAPI.Logger.LogError(e);
                        }
                    }
                }

                // Delay to let plugins not using the api create their toggles so we don't overlap
                KoikatuAPI.Instance.StartCoroutine(DelayedLoadCo());
                IEnumerator DelayedLoadCo()
                {
                    yield return(null);

                    foreach (var cat in _customCurrentStateCategories)
                    {
                        CreateCategory(cat);
                    }

                    yield return(null); // todo Only needed for compat with QAB. Can remove once QAB is using this API

                    CustomToolbarButtons.OnStudioLoaded();
                }
            }
        }
Exemplo n.º 5
0
        public void CreateUI()
        {
            UISystem = UIUtility.CreateNewUISystem("BetterSceneLoaderCanvas");
            UISystem.GetComponent <CanvasScaler>().referenceResolution = new Vector2(1920f / UIScale, 1080f / UIScale);
            ShowWindow(false);

            mainPanel       = UIUtility.CreatePanel("Panel", UISystem.transform);
            mainPanel.color = backgroundColor;
            UIUtility.AddOutlineToObject(mainPanel.transform, outlineColor);

            var drag = UIUtility.CreatePanel("Draggable", mainPanel.transform);

            drag.transform.SetRect(0f, 1f, 1f, 1f, 0f, -headerSize);
            drag.color = dragColor;
            UIUtility.MakeObjectDraggable(drag.rectTransform, mainPanel.rectTransform);

            nametext = UIUtility.CreateText("Nametext", drag.transform, "Scenes");
            nametext.transform.SetRect(0f, 0f, 1f, 1f, 340f, 0f, -buttonSize * 2f);
            nametext.alignment = TextAnchor.MiddleCenter;

            var close = UIUtility.CreateButton("CloseButton", drag.transform, "");

            close.transform.SetRect(1f, 0f, 1f, 1f, -buttonSize * 2f);
            close.onClick.AddListener(() => ShowWindow(false));

            var x1 = UIUtility.CreatePanel("x1", close.transform);

            x1.transform.SetRect(0f, 0f, 1f, 1f, 8f, 0f, -8f);
            x1.rectTransform.eulerAngles = new Vector3(0f, 0f, 45f);
            x1.color = new Color(0f, 0f, 0f, 1f);
            var x2 = UIUtility.CreatePanel("x2", close.transform);

            x2.transform.SetRect(0f, 0f, 1f, 1f, 8f, 0f, -8f);
            x2.rectTransform.eulerAngles = new Vector3(0f, 0f, -45f);
            x2.color = new Color(0f, 0f, 0f, 1f);

            var category = UIUtility.CreateDropdown("Dropdown", drag.transform, "Categories");

            category.transform.SetRect(0f, 0f, 0f, 1f, 0f, 0f, 100f);
            category.captionText.transform.SetRect(0f, 0f, 1f, 1f, 0f, 2f, -15f, -2f);
            category.captionText.alignment = TextAnchor.MiddleCenter;
            category.options = GetCategories();
            category.onValueChanged.AddListener(x =>
            {
                currentCategoryFolder = CategoryFolders[category.options[x].text];
                imagelist.content.GetComponentInChildren <Image>().gameObject.SetActive(false);
                imagelist.content.anchoredPosition = new Vector2(0f, 0f);
                PopulateGrid();
            });

            var refresh = UIUtility.CreateButton("RefreshButton", drag.transform, "Refresh");

            refresh.transform.SetRect(0f, 0f, 0f, 1f, 100f, 0f, 180f);
            refresh.onClick.AddListener(ReloadImages);

            var save = UIUtility.CreateButton("SaveButton", drag.transform, "Save");

            save.transform.SetRect(0f, 0f, 0f, 1f, 180f, 0f, 260f);
            save.interactable = false;
            save.onClick.AddListener(() =>
            {
                string path = Path.Combine(currentCategoryFolder, DateTime.Now.ToString("yyyy_MMdd_HHmm_ss_fff") + ".png");
                OnSaveButtonClick(path);
                var button = CreateSceneButton(imagelist.content.GetComponentInChildren <Image>().transform, PngAssist.LoadTexture(path), path);
                button.transform.SetAsFirstSibling();
            });

            var folder = UIUtility.CreateButton("FolderButton", drag.transform, "Folder");

            folder.transform.SetRect(0f, 0f, 0f, 1f, 260f, 0f, 340f);
            folder.onClick.AddListener(() => OnFolderButtonClick(scenePath));

            var loadingPanel = UIUtility.CreatePanel("LoadingIconPanel", drag.transform);

            loadingPanel.transform.SetRect(0f, 0f, 0f, 1f, 340f, 0f, 340f + headerSize);
            loadingPanel.color = new Color(0f, 0f, 0f, 0f);
            var loadingIcon = UIUtility.CreatePanel("LoadingIcon", loadingPanel.transform);

            loadingIcon.transform.SetRect(0.1f, 0.1f, 0.9f, 0.9f);
            var loadiconTex = PngAssist.ChangeTextureFromByte(Resource.GetResourceAsBytes(typeof(SceneLoaderUI).Assembly, "Resources.loadicon"));

            loadingIcon.sprite = Sprite.Create(loadiconTex, new Rect(0, 0, loadiconTex.width, loadiconTex.height), new Vector2(0.5f, 0.5f));
            LoadingIcon.Init(loadingIcon, -5f);

            imagelist = UIUtility.CreateScrollView("Imagelist", mainPanel.transform);
            imagelist.transform.SetRect(0f, 0f, 1f, 1f, marginSize, marginSize, -marginSize, -headerSize - marginSize / 2f);
            imagelist.gameObject.AddComponent <Mask>();
            imagelist.content.gameObject.AddComponent <VerticalLayoutGroup>();
            imagelist.content.gameObject.AddComponent <ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize;
            imagelist.verticalScrollbar.GetComponent <RectTransform>().offsetMin        = new Vector2(scrollOffsetX, 0f);
            imagelist.viewport.offsetMax = new Vector2(scrollOffsetX, 0f);
            imagelist.movementType       = ScrollRect.MovementType.Clamped;

            optionspanel = UIUtility.CreatePanel("ButtonPanel", imagelist.transform);
            optionspanel.gameObject.SetActive(false);

            confirmpanel = UIUtility.CreatePanel("ConfirmPanel", imagelist.transform);
            confirmpanel.gameObject.SetActive(false);

            yesbutton = UIUtility.CreateButton("YesButton", confirmpanel.transform, "Y");
            yesbutton.transform.SetRect(0f, 0f, 0.5f, 1f);
            yesbutton.onClick.AddListener(() => OnDeleteButtonClick(currentPath));

            nobutton = UIUtility.CreateButton("NoButton", confirmpanel.transform, "N");
            nobutton.transform.SetRect(0.5f, 0f, 1f, 1f);
            nobutton.onClick.AddListener(() => confirmpanel.gameObject.SetActive(false));

            var loadbutton = UIUtility.CreateButton("LoadButton", optionspanel.transform, "Load");

            loadbutton.transform.SetRect(0f, 0f, 0.3f, 1f);
            loadbutton.onClick.AddListener(() =>
            {
                confirmpanel.gameObject.SetActive(false);
                optionspanel.gameObject.SetActive(false);
                OnLoadButtonClick(currentPath);
                if (BetterSceneLoaderCore.AutoClose.Value)
                {
                    ShowWindow(false);
                }
            });

            var importbutton = UIUtility.CreateButton("ImportButton", optionspanel.transform, "Import");

            importbutton.transform.SetRect(0.35f, 0f, 0.65f, 1f);
            importbutton.onClick.AddListener(() =>
            {
                OnImportButtonClick(currentPath);
                confirmpanel.gameObject.SetActive(false);
                optionspanel.gameObject.SetActive(false);
            });

            var deletebutton = UIUtility.CreateButton("DeleteButton", optionspanel.transform, "Delete");

            deletebutton.transform.SetRect(0.7f, 0f, 1f, 1f);
            deletebutton.onClick.AddListener(() =>
            {
                confirmpanel.gameObject.SetActive(true);
                currentButton.gameObject.SetActive(false);
                confirmpanel.gameObject.SetActive(false);
                optionspanel.gameObject.SetActive(false);
            });

            var pluginiconTex = PngAssist.ChangeTextureFromByte(Resource.GetResourceAsBytes(typeof(SceneLoaderUI).Assembly, "Resources.pluginicon"));

            toolbarToggle = CustomToolbarButtons.AddLeftToolbarToggle(pluginiconTex, false, ShowWindow);

            UpdateWindow();
            PopulateGrid();
        }