Forum rules - please read before posting.

Journal: shift right button still shows when not effective

Hi!
I have an "open book" journal that I made following the tutorial, it has a left page and right page. I made sure to have the shift buttons with an offset of 2, so that it behaves like an actual book (pages that are on the right don't switch to the left). Everything is working, and I have "Only show when effective" set. But when I reach the final page (a 'right' page, in this case), it still allows me to use the shift right button, as if there was another page. When I click it, however, it shifts ONE empty page (when there shouldn't be any).
I checked if something similar happened with the shift LEFT button when reaching the beginning of the document, but there are no problems with that, it is only with the shift right button reaching the end.
Maybe the fact that I have two pages (two journal elements) is creating this problem? As if when checking effectiveness of the button it only looks ahead based on the left journal element (which understandably has 1 page of overhead in this case), instead of the right journal element, where the limit is actually at?
As a work around, I added a page with empty space on it. It's not ideal because it still allows me to shift beyond the end of the diary, but at least it preserves the layout when moving back.

Comments

  • Maybe the fact that I have two pages (two journal elements) is creating this problem?

    The Button refers to just the original Journal element - it's not aware of the second offset page.

    You can get around this with a custom script. Uncheck "Only show when effective?" on the right shift button, and attach the script below to a GameObject in your scene:

    using UnityEngine;
    using AC;
    
    public class JournalSnapPage : MonoBehaviour
    {
    
        public string journalMenuName = "Journal";
        public string journalElementName = "PageLeft";
        public string shiftRightButtonName = "ShiftRight";
    
        private void OnEnable ()
        {
            EventManager.OnMenuElementShift += OnMenuElementShift;
            EventManager.OnMenuTurnOn += OnMenuTurnOn;
        }
    
        private void OnDisable ()
        {
            EventManager.OnMenuElementShift -= OnMenuElementShift;
            EventManager.OnMenuTurnOn -= OnMenuTurnOn;
        }
    
        private void OnMenuElementShift (MenuElement _element, AC_ShiftInventory shiftType)
        {
            if (PlayerMenus.GetMenuWithName (journalMenuName).elements.Contains (_element))
            {
                MenuJournal journal = PlayerMenus.GetElementWithName (journalMenuName, journalElementName) as MenuJournal;
                bool isEven = (journal.showPage%2 == 0);
    
                if (isEven)
                {
                    int newShowPage = journal.showPage + ((shiftType == AC_ShiftInventory.ShiftNext) ? 1 : -1);
    
                    if (newShowPage < 1)
                    {
                        newShowPage = 1;
                    }
                    if (newShowPage >= journal.pages.Count - 1)
                    {
                        newShowPage = journal.pages.Count - 1;
                    }
    
                    journal.showPage = newShowPage;
                }
    
                UpdateShiftRightButton ();
            }
        }
    
        private void OnMenuTurnOn (Menu _menu, bool isInstant)
        {
            if (_menu.title == journalMenuName)
            {
                UpdateShiftRightButton ();
            }
        }
    
    
        private void UpdateShiftRightButton ()
        {
            MenuJournal journal = PlayerMenus.GetElementWithName (journalMenuName, journalElementName) as MenuJournal;
            MenuButton shiftRightButton = PlayerMenus.GetElementWithName (journalMenuName, shiftRightButtonName) as MenuButton;
            int pageDiff = journal.pages.Count - journal.showPage;
            shiftRightButton.IsVisible = (pageDiff > 1);
        }
    
    }
    

    Fill in the field names in the Inspector, and it should do the trick.

  • Indeed it did the trick! thanks a lot!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.