Git Product home page Git Product logo

Comments (3)

Richd4y avatar Richd4y commented on June 15, 2024

We can add additional information directly to the line with the link (and show it in the frame on hover), for example:

def set_encentry_from_text_anchor(value: str) -> None:
    """Parse a Ren'Py text anchor to open an EncEntry.

    This function is added to Ren'Py's config.hyperlink_handlers with the key
    "set_entry"

    Args:
        value: A string in the format of "Encyclopaedia->EncEntry->hint_description->hint_note"
    """
    enc_name, entry_name, entry_hint_description, entry_hint_note = value.split('->')

    enc: 'Encyclopaedia' = getattr(store, enc_name)
    entry: 'EncEntry' = getattr(store, entry_name)

    enc.active = entry

    # Concole test event "show tooltip on hover" 
    print(f"Name: {entry}")
    print(f"Desc: {entry_hint_description}")
    print(f"Note: {entry_hint_note}")

    # Open the Encyclopaedia, the screen will open the active entry for us.
    ShowMenu(enc.list_screen, enc=enc)()

A better way, which I wrote about at the beginning of the topic, is to specify information during the creation of EncEntry objects.

label setup_enc:

    python:
        library_enc = Encyclopaedia(
            name="Wanderer in the Library",
            show_locked_buttons=True,  # show unseen (???) buttons in codex list or no
            sorting_mode=3,
        )

        # Register a callback function.
        library_enc.on('entry_unlocked')(notify_entry_unlocked)

        # Use EncEntryTemplate to set reasonable defaults and reduce duplication
        LibraryEntry = EncEntryTemplate(parent=library_enc, locked=True)

        about_custom = LibraryEntry(
                    name=_('Custom'),
                    subject=_('Other'),
                    text=[
                        "Cusotm info done succesfully",
                    ],
                    hint_description=["desc1", "desc2", "desc3"],
                    hint_note="This is a short one-string note."
                )

And get it later from the object in hyperlink_ren.py with set_encentry_from_text_anchor:

def set_encentry_from_text_anchor(value: str) -> None:
    """Parse a Ren'Py text anchor to open an EncEntry.

    This function is added to Ren'Py's config.hyperlink_handlers with the key
    "set_entry"

    Args:
        value: A string in the format of "Encyclopaedia->EncEntry"
    """
    enc_name, entry_name = value.split('->')

    enc: 'Encyclopaedia' = getattr(store, enc_name)
    entry: 'EncEntry' = getattr(store, entry_name)
    
    # Example logic (not sure if it's the right thing to do)
    hint_description: 'EncEntry' = getattr(store, entry_hint_description)
    hint_note: 'EncEntry' = getattr(store, entry_hint_note)

    enc.active = entry

    # Concole test event "show tooltip on hover" 
    print(f"Name: {entry}")
    print(f"Desc: {hint_description}")
    print(f"Note: {hint_note}")

    # Open the Encyclopaedia, the screen will open the active entry for us.
    ShowMenu(enc.list_screen, enc=enc)()

from renpy-encyclopaedia.

jsfehler avatar jsfehler commented on June 15, 2024

I can make the hyperlink more flexible by letting you specify the screen that the hyperlink will call. You could then create a separate view for when hyperlinks are clicked. I don't think adding hint attributes is worth it. If you need hints that sounds like a separate system.

from renpy-encyclopaedia.

Richd4y avatar Richd4y commented on June 15, 2024

Considering tooltips as part of the codex/glossary system to be able to give the player the bare minimum of knowledge (short description) without having to open the glossary screen where the full (long) description will be given.

Example
image

Solved for me with subclass:

class MyEntry(EncEntry):
    def __init__(self, *args, hint_description: list|str, hint_note: list|str, **kwargs):
        super().__init__(*args, **kwargs)
        self.hint_description = hint_description
        self.hint_note = hint_note

And a hyperlink modified in a custom tag:

screen glossary_word(entry):
    $ focus_rect = GetFocusRect('glossary_tooltip')
    if focus_rect:
        fixed:
            xfit True
            yfit True
            use glossary_word_frame(entry, focus_rect)

screen glossary_word_frame(entry, focus_rect):
    frame:
        xmaximum 600

        # __FitChild will place frame at the screen so that it doesn't go off the screen
        at renpy.curry(__FitChild)(focus_rect=focus_rect)

        style_prefix 'glossary'

        has vbox
        text entry.name style_suffix 'title_text'
        vbox:
            for line in entry.hint_description:
                text line style_suffix 'description_text'

            text entry.hint_note
            
init python:
    class __EncentryGlossaryShow:
        def __init__(self, enc, entry):
            self.enc = enc
            self.entry = entry
        
        def __call__(self):
            enc = self.enc
            enc.active = self.entry
            return ShowMenu(enc.list_screen, enc=enc)()

    def encentry_glossary_tag(tag, argument, contents):
        # modified version of hyperlink_ren.set_encentry_from_text_anchor
        enc_name, entry_name = argument.split('->')

        enc: 'Encyclopaedia' = getattr(store, enc_name)
        entry: 'EncEntry' = getattr(store, entry_name)

        open_glossary_action = __EncentryGlossaryShow(enc, entry)
        
        button = TextButton(
            contents, 
            text_tokenized=True,
            hovered=[CaptureFocus('glossary_tooltip'), ShowTransient('glossary_word', None, entry)],
            unhovered=[ClearFocus('glossary_tooltip'), Hide('glossary_word')],
            action=__EncentryGlossaryShow(enc, entry),
            style='glossary_button'
        )

        return [
            (renpy.TEXT_DISPLAYABLE, button)
        ]

    config.custom_text_tags["glossary"] = encentry_glossary_tag

from renpy-encyclopaedia.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.