Ejemplo n.º 1
0
        /// <summary>
        /// Add a new button to the H Scene "trespassing" menu (red button below position selections on the right, originally used when having H near another girl so you can start 3P).
        /// </summary>
        /// <param name="buttonText">Text on the button. The button is styled as a speech bubble, so consider spelling it like the MC is saying this.</param>
        /// <param name="spawnConditionCheck">
        /// Check if the button should be shown in the current H scene.
        /// Called at scene start. Return true if button should be spawned, false if not.
        /// Set to null if the button should always be spawned.
        /// </param>
        /// <param name="onButtonClicked">Called when user clicks the button and it is interactable.</param>
        /// <returns>Returns a disposable that when disposed removes this button permanently.</returns>
        public static IDisposable AddHsceneTrespassingButton(
            string buttonText, Func <HSprite, bool> spawnConditionCheck,
            Action <HSprite> onButtonClicked)
        {
            var btn = new CustomTrespassingButton(buttonText, spawnConditionCheck, onButtonClicked);

            _customTrespassingButtons.Add(btn);

            Hooks.ApplyHooks();

            return(Disposable.Create(() =>
            {
                btn.Dispose();
                _customTrespassingButtons.Remove(btn);
            }));
        }
Ejemplo n.º 2
0
        private static bool SpawnSingleButton(int id, HSprite hSprite, CustomTrespassingButton buttonData)
        {
            if (buttonData.SpawnConditionCheck != null && !buttonData.SpawnConditionCheck(hSprite))
            {
                return(false);
            }

            //Console.WriteLine($"spawn id={id} name=" + buttonData.ButtonText);

            var defaultBtn = hSprite.menuActionSub.GetObject(7);

            var copyBtn = Object.Instantiate(defaultBtn, defaultBtn.transform.parent, false);

            try
            {
                copyBtn.name = "CustomTrespassButton_" + id;

                Object.DestroyImmediate(copyBtn.GetComponent <TextChangeCtrl>());
                Object.DestroyImmediate(copyBtn.GetComponent <HSpriteAutoDisable>());

                var pa = copyBtn.GetComponent <PointerAction>();
                pa.listDownAction.Add(hSprite.OnMouseDownSlider);

                copyBtn.GetComponentInChildren <TextMeshProUGUI>().text = buttonData.ButtonText;

                // Offset by 100 for each new button, don't offset first if the default button isn't shown
                copyBtn.transform.SetLocalPositionY(copyBtn.transform.localPosition.y - 100 * id);

                var btn = copyBtn.GetComponent <Button>();

                var evt = btn.onClick;
                evt.m_Calls.Clear();
                evt.m_Calls.ClearPersistent();
                evt.m_PersistentCalls.Clear();
                evt.m_CallsDirty = false;

                btn.onClick.AddListener(() =>
                {
                    if (Scene.IsNowLoadingFade)
                    {
                        return;
                    }
                    if (Scene.NowSceneNames[0] != "HProc")
                    {
                        return;
                    }
                    if (!hSprite.IsSpriteAciotn())
                    {
                        return;
                    }

                    Utils.Sound.Play(SystemSE.sel);

                    buttonData.OnButtonClicked(hSprite);
                });

                hSprite.menuActionSub.lstObj.Add(copyBtn);
                hSprite.menuActionSub.makeParent.Add(copyBtn);

                buttonData.Instance = copyBtn;
            }
            catch
            {
                Object.Destroy(copyBtn);
                throw;
            }

            return(true);
        }