jsfehler / renpy-encyclopaedia

A Ren'Py plugin for creating an Encyclopaedia/Glossary/Bestiary or similar system.
https://renpy-encyclopaedia.readthedocs.io/
MIT License
56 stars 6 forks source link

Showing sub-Entry before the main Entry is unlocked? #10

Closed birctreel closed 6 months ago

birctreel commented 6 months ago

Hello there! I had an interesting problem and wonder if it's possible to show a sub entry before its parent unlocked? To put it simple, I’m using the encyclopedia as a character file. Some of the characters will have several entries differing from where you find them. Such as:

Character_A = CharacterEntry(
    name = 'A',
    text = ('dataA'),
    )

Character_A_2 = EncEntry(
    parent = Character_A,
    name = 'A',
    text = ('dataB'),
    )

Sometimes, it is Character_A_2 that unlock first.

But if we don't unlock Character_A, the player cannot attach Character_A_2.

To solve this problem, I tried to put the Character A as a parent-entry, and put the data A into another sub-entry. For example:

Character_A = CharacterEntry(
    name = 'A',
    text = (''),
    )

Character_A_2 = EncEntry(
    parent = Character_A,
    name = 'A',
    text = ('dataA'),
    )

Character_A_3 = EncEntry(
    parent = Character_A,
    name = 'A',
    text = ('dataB'),
    )

So I can unlock Both Character_A and Character_A_3, to avoid the player reading dataA first.

However, if I write so, then everytime the player open the file, they would always firstly saw Character A's data, as an empty page (because I cannot write the text in the parent entry.)

Is that anyway to avoid that? For example, is there any ways in the screen, that we can judge if the parent entry has text or not, and if not, we start to show the sub entry first?

Maybe there are any better way to solve this problems?

========================== Thank you so much for reading my question. I'm newbee about python code so it took me a while to use encyclopedia system, but it's fascinating and really great!!! I love it so much and I really want to attach my goal by it...!!

jsfehler commented 6 months ago

There's no way to show a sub-entry if the main entry is locked. There's a built-in assumption that there's always a main page, but your approach here with a blank main entry is good. The alternative would be to have a separate Encyclopaedia for each character. You'd have to write a custom screen and I think that's going to be more work.

When you open an Entry, your_encyclopaedia.SetEntry(your_entry) is called. You can try adding the your_encyclopaedia.NextPage() to the button's actions. Something like:

screen entry_button(enc, entry):
    button:
        style "encyclopaedia_list_button"

        action [enc.SetEntry(entry), enc.NextPage()]

        hbox:
            spacing 10
            text entry.name style "encyclopaedia_list_button_text"
            # If an entry is not locked and not viewed, display an indication
            # for the user.
            if (entry.locked is False) and (not entry.viewed):
                text _("New!") style "unread_entry_notice_text"

That might get you what you want but I haven't tested it.

Try it out and if it doesn't work I'll see what else we can do.

birctreel commented 6 months ago

There's no way to show a sub-entry if the main entry is locked. There's a built-in assumption that there's always a main page, but your approach here with a blank main entry is good. The alternative would be to have a separate Encyclopaedia for each character. You'd have to write a custom screen and I think that's going to be more work.

When you open an Entry, your_encyclopaedia.SetEntry(your_entry) is called. You can try adding the your_encyclopaedia.NextPage() to the button's actions. Something like:

screen entry_button(enc, entry):
    button:
        style "encyclopaedia_list_button"

        action [enc.SetEntry(entry), enc.NextPage()]

        hbox:
            spacing 10
            text entry.name style "encyclopaedia_list_button_text"
            # If an entry is not locked and not viewed, display an indication
            # for the user.
            if (entry.locked is False) and (not entry.viewed):
                text _("New!") style "unread_entry_notice_text"

That might get you what you want but I haven't tested it.

Try it out and if it doesn't work I'll see what else we can do.

I see! I think that's what I want! I need a way to enter the next page, and maybe enc.NextPage would help. Also it could happened when I use texttag to call the entry too, so maybe I would judge this whenever I opened the entry screen.

Thank you again for this super quick replying! I will give it a try now and probably close it later after I confirm to solve this problem, or I will get back here if there are any more problems. :DDDDD