Forum rules - please read before posting.

Creating a diary system like the ones in Uncharted/ NiTW

2

Comments

  • edited October 2018
    Unsure, but I think I get what you mean now - the page snaps but the texture doesn't update to reflect it.

    Both scripts rely on the OnMenuElementShift custom event, so you can incorporate them into one:

  • Awesome! That works :) Last question (hopefully) Any way to make sure that the diary always opens to the newest page? That is, open to the latest page that was added through the action list -> add journal page command?
  • The Menu: Set Journal page Action can be used to set the open page to a set value, but I'll look into exposing events that occur when adding/removing pages so that you can set it through script too.
  • Ah alright, missed there was an action for that - I'm able to use that to open the desired page by a bit of calculation.

    Unfortunately, a new issue has cropped up. Setting add journal page to an index of -1 (add to end of journal) and using the Set Journal page action to open to Last Page causes the latest page to shift positions. It fixes itself once I turn the page. This video should make it clearer-

    https://youtu.be/tdV54f_cUT8
  • Yes, I thought this might occur.  Hence the need to rely on custom events upon adding a page so that you can set the correct index.  This'll be included in v1.65.2.
  • Alright, I'll wait for that. Thank you so much for all the help!! :)
  • edited October 2018
    There's another thing - blank pages or pages that haven't had textures assigned to them through the script yet appear as white boxes, even if I set the image UI sprite as a transparent sprite. 

  • edited October 2018
    What's the state of the Unity UI Image component at that time?  Is the transparent sprite assigned?  If you update it in the Inspector, does any new sprite show?
  • Yes, a blank texture has been assigned. Even if I change it to a random sprite for the image UI in the inspector, it just shows the white box. It's as if the script is overriding anything set in the inspector.
  • Also very odd thing I noticed - Linking RightTexture UI to the left page's Texture Menu element makes the white box appear transparent for the left page. But if I also link the left page's Texture UI to the RightTexture menu element, both white boxes reappear. Keeping both elements unlinked by default also makes the boxes reappear.
  • Try this, and supply a transparent texture in the new "empty texture" field:


  • Thanks! So this kind of works. I'm still trying to figure out what exactly is going wrong, but it seems to be leaving blank textures at alternate points. It also seems like instead of adding the correct texture at page 3 it's adding a blank texture at 3, and adding the right texture next to it.
    Also there's still a white box on the first page, but not anywhere else.

    I'll test it out a bit more and get back to you.
  • Alright, here's an explanation of the new issues. While writing this post I noticed the pattern of the issue - The texture assigned by the script appears on one side of the journal, and the text assigned by the action list appears on the opposite side (instead of appearing together on the same page) Here's the original explanation:

    1. Journal menu. The first page cannot be deleted, and I've entered its text as "A" to identify it. Maybe the presence of this page causes issues?


    2. Status of the diary before any note is added through action lists. (White box appears on page next to page 1)


    3. First note is added, but its texture goes to the right and its text goes to the left side (Text is "1" on top left corner) I don't need the text but I added it so that Gather Speech could find it.



    image

    4. Pressing next page button does this - The texture shifts to the left side, the text "1" is replaced by "A" (as I stated above) and "1" shifts to the right side. White box appears on the right. Pressing left/ right correctly does nothing as this is the first/ only entry.



    5. New entry with text "2" is added like this - texture on the right, text on the left. (The previous entry looks the same as above)

    image

    6. Third entry with text "3" is now added on the left, and leaves its text on the right. So essentially, textures for entry 2 and 3 have exchanged places but the text is in the right spot-

    image

    7. Entries 4 and 5 follow the same pattern:
    Entry 4 - 

    image

    Entry 5 - 

    image

    As of now, only the above pattern seems to be an issue.

    I did notice another problem that occurred only during one cutscene (one texture became permanent on one side of the page, all other textures disappeared and turning pages only changed the number text, but the permanent texture stayed in the same place) but I'll lock the menu for this scene and ignore it if it doesn't occur anywhere else (we can get to it later if it reoccurs)

    Thanks!




  • I'll look into these and let you know if I need more information.
  • I'll add the ability to remove the first page in v1.66.0.

    For a fix on the white boxes, try this:

    I can't recreate the other issues, and the lack of detail (e.g. what texture you've actually got with what page) makes it difficult to see what's going on exactly.  I'm assuming you've double-checked that the correct graphic elements are linked to the script.

    Since the "page snapping" feature only complicates things further, remove it temporarily by commenting out the code in the script's SnapJournalPage function.  Does behaviour then improve?
  • edited November 2018
    The white boxes have been fixed, thanks. I'll try to explain the issue in more detail: The very first texture is supposed to be the drawing of the house (crime scene exterior) On that same page, through the action list I've added the text "1". (as shown in the 4th picture above, ID 6309. 6309 is also the ID for "Element 0" in JournalPageTexture's inspector, as it's supposed to be) So the texture of the house, and the text "1" should appear on the same page. 

    But they appear on adjacent pages as seen in the 3rd and 5th pic (I don't mean the 3rd and 5th bullet point in the list above - I mean the order of the pictures - sorry if this is confusing!)

    The 6th picture (bullet point 5) shows the 2nd entry that's added in the game (Texture that says "Local cops' account") But as you can see, it leaves a blank page on its left. The text "2" is supposed to appear on the same page as the texture, using the action list same way as before, but it appears on the left, adjacent to the texture.

    Entry number 3 ("Crime scene") now comes before entry 2, and its text appears on the right side.

    To make this simpler to understand, here's a photoshopped mockup of the diary with the pages in the correct places. This is how it's supposed to look. Compare it with the pictures above and maybe it'll be apparent what's going wrong.


    Compare with the 5th pic (bullet point 4)



    Compare with the 5th and 6th pics




    Compare with 7th, 8th and 9th pics



    I commented out the code relevant to the Snap function, but it caused this issue as I described above-

    "one (latest) texture became permanent on one side of the page, all other textures disappeared and turning pages only changed the number text, but the permanent texture stayed in the same place"

    The code I commented out was - 

    Line 20 //  EventManager.OnMenuElementShift += OnMenuElementShift;
    Line 27 //    EventManager.OnMenuElementShift -= OnMenuElementShift;

    Lines 40-71-

    //private void OnMenuElementShift(MenuElement _element, AC_ShiftInventory shiftType)
       // {
           // if (PlayerMenus.GetMenuWithName("Journal").elements.Contains(_element))
           // {
           //     SnapJournalPage(_element as MenuJournal, shiftType);
              //  UpdatePageTexture();
           // }
       // }


        //private void SnapJournalPage(MenuJournal journal, AC_ShiftInventory shiftType)
       // {
           // if (journal == null) return;

           // 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;
           // }
       // }


  • No, there's nothing obvious I can see.

    I'll have to see it for myself.  Duplicate the project and reduce it to its core essentials for me to see it, and I'll take a look.
  • This script will snap the open journal page to multiples of two:
    http://pasteall.org/1322581/csharp

    I'm building a similar feature, but unfortunately the script is gone. Does anyone have a copy of this script? It would help me so much, thanks.

  • I believe this was it:

    using UnityEngine;
    using System.Collections;
    using AC;
    
    public class JournalSnapPage : MonoBehaviour
    {
    
        public string journalMenuName = "Journal";
    
    
        private void OnEnable ()
        {
            EventManager.OnMenuElementShift += OnMenuElementShift;
        }
    
    
        private void OnDisable ()
        {
            EventManager.OnMenuElementShift -= OnMenuElementShift;
        }
    
    
        private void OnMenuElementShift (MenuElement _element, AC_ShiftInventory shiftType)
        {
            if (PlayerMenus.GetMenuWithName (journalMenuName).elements.Contains (_element))
            {
                MenuJournal journal = _element 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;
                }
            }
        }
    
    }
    
  • Thank you very much Chris!

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.