Page 1 of 1

little-used history chips

Posted: Sat Jul 30, 2022 4:53 pm
by Andredron
Image
1)Add a play sound button

Code: Select all

screen history():

    tag menu

    ## Avoid predicting this screen as it can be very
    ## massive.
    predict False

    use game_menu(_("History"), scroll=("vpgrid" if gui.history_height else "viewport"), yinitial=1.0):

        style_prefix "history"

        for h in _history_list:

            windows:

                ## This will properly equalize if history_height is
                ## is set to None.
                has fixed:
                    yfit True

                if h.who:
############################################################################
                    if h.voice and h.voice.filename:                                          ###Here, of course, it is better to put a graphic button, less hassle with setting its location
                        textbutton "Play" action Play("voice", h.voice.filename)
############################################################################
                    label h.who:
                        style "history_name"
                        substitute False

                        ## Gets the color from the character's who parameter, if it
                        ## installed.
                        if "color" in h.who_args:
                            text_color h.who_args["color"]

                $ what = renpy.filter_text_tags(h.what, allow=gui.history_allow_tags)
                text what:
                    substitute False

        if not _history_list:
            label _("History of dialogs is empty.")
2)Roll back to this text

Code: Select all

screenhistory():

    tag menu

    ## Avoid predicting this screen as it can be very
    ## massive.
    predict False

    use game_menu(_("History"), scroll=("vpgrid" if gui.history_height else "viewport"), yinitial=1.0):

        style_prefix "history"

        for h in _history_list:

            windows:

                ## This will properly equalize if history_height is
                ## is set to None.
                has fixed:
                    yfit True

                if h.who:

                    if h.voice and h.voice.filename:
                        textbutton "Play" action Play("voice", h.voice.filename)
#############################################################################################
                       textbutton "ROLL BACK" action Confirm("Jump?", yes=RollbackToIdentifier(h.rollback_identifier), no=None, confirm_selected=False) ​​xpos 0 ypos 30           ##########After pressing the button, you will roll back
############################################################################################
                    label h.who:
                        style "history_name"
                        substitute False

                        ## Gets the color from the character's who parameter, if it
                        ## installed.
                        if "color" in h.who_args:
                            text_color h.who_args["color"]

                $ what = renpy.filter_text_tags(h.what, allow=gui.history_allow_tags)
                text what:
                    substitute False

        if not _history_list:
            label _("History of dialogs is empty.")
And in the gui file, you will have to change the size of the saved points, and the size of the control points

Code: Select all

define config.hard_rollback_limit = 100
define config.rollback_length = 100

3) How to change the text on the history screen

Code: Select all

label start:
	"Hi! I couldn't wait to see you again!"
	$ _history_list[-1].what = "I hate you. Wish you were dead."
	"If you check history now, you will notice that the last entry changed"


4) Add head

Code: Select all

screenhistory():

    tag menu

    ## Avoid predicting this screen as it can be very
    ## massive.
    predict False

    use game_menu(_("History"), scroll=("vpgrid" if gui.history_height else "viewport"), yinitial=1.0):

        style_prefix "history"

        for h in _history_list:

            windows:

                ## This will properly equalize if history_height is
                ## is set to None.
                has fixed:
                    yfit True
#####################################################################
                    if h.who:
                        hbox:
                            if h.image_tag:
                                add "history" + h.image_tag
                            else:
                                null width 100
######################################################################

                    if h.voice and h.voice.filename:
                        textbutton "Play" action Play("voice", h.voice.filename)

                    textbutton "ROLL BACK" action RollbackToIdentifier(h.rollback_identifier) ​​xpos 0 ypos 30

                    label h.who:
                        style "history_name"
                        substitute False

                        ## Gets the color from the character's who parameter, if it
                        ## installed.
                        if "color" in h.who_args:
                            text_color h.who_args["color"]

                $ what = renpy.filter_text_tags(h.what, allow=gui.history_allow_tags)
                text what:
                    substitute False

        if not _history_list:
            label _("History of dialogs is empty.")
script.rpy

Code: Select all

define character.yesod = Character("Yesod", image="yesod")
image yesod smiling = "_YesodSmiling.png"
image history yesod = "yesod-6.png"

label start:
    show yesod smiling
    yesod "Hello"
    yesod ". . ."
    ". . ."
    yesod "Test"
    return
another option viewtopic.php?p=517246#p517246

5) change text color

Code: Select all

$ what = renpy.filter_text_tags(h.what, allow=gui.history_allow_tags)
                 text what:
                     color "#FFD700" ###################color
                     substitute False

         if not _history_list:
             label _("History of dialogs is empty.")
6) Adding choices selected to History without showing to user
viewtopic.php?t=40329

https://old.reddit.com/r/RenPy/comments ... ?context=3

7) Having unselected choices in History?
viewtopic.php?p=548775#p548775

8) disable history

Code: Select all


     $ store._history = True ### history on
     
     voice "voice/003.ogg"
     nez "{w=0.5}How are you feeling?{w=1.0}{nw}"

     $ store._history = False ### # history off
     show mor02
     nez "How do you feel?{fast}"
     
9) Replace rollback with History
viewtopic.php?p=545688#p545688

10) Scrollbar thumb has a white border
viewtopic.php?p=534763#p534763

11) add images to history log [works with layeredimages]
viewtopic.php?p=534271#p534271

12) How to register a mouse call with a wheel

Code: Select all

screen my_keys:
    key "mousedown_5" action ShowMenu("history")
    key 'K_ESCAPE' action ShowMenu('preferences')
    key 'mouseup_3' action ShowMenu('save')
    
label start:
    show screen my_keys
    "text"
13)Implementation of a history scrollbar scrolling to the end to close

Code: Select all

init python:
    class MyAdjustment(renpy.display.behavior.Adjustment):
        def change(self, value):
            if value > self._range and self._value == self._range:
                # *Return to the game screen*
                return Return()
            else:
                # Otherwise, just do what the Adjustment normally does
                return renpy.display.behavior.Adjustment.change(self, value)
screen game_menu add

Code: Select all

default adj = MyAdjustment(range = 100,changed =None,adjustable=True)
viewport

Code: Select all

yadjustment adj
14)Start from latest dialogue

viewtopic.php?f=8&t=50647

15)Changing dialogue history in rollback


viewtopic.php?p=542946#p542946

16) History search
https://devilspider.itch.io/history-search-tool

You may be interested in the following materials:

Re: little-used history chips

Posted: Sun Aug 21, 2022 1:34 pm
by Johan
Oh my god, thank you so much!!
I had used other code for some of these but yours are way simpler, so I'm using it!! Thanks!! ^^

Re: little-used history chips

Posted: Fri Sep 16, 2022 12:14 am
by Tess
This is insanely cool! Thanks so much for writing it up.

Re: little-used history chips

Posted: Wed Feb 21, 2024 10:50 am
by Li yuanlin
13)Implementation of a history scrollbar scrolling to the end to close
This one has no effect in my new project,I don't kown why

Re: little-used history chips

Posted: Thu Feb 22, 2024 11:22 am
by Andredron
Li yuanlin wrote: Wed Feb 21, 2024 10:50 am 13)Implementation of a history scrollbar scrolling to the end to close
This one has no effect in my new project,I don't kown why
Try this, I tried to update the code from my phone, so it's not a sure working method.

Code: Select all


init python:
import renpy.display.behavior.Adjustment

class MyAdjustment(renpy.display.behavior.Adjustment):
    def change(self, value):
        if value > self._range and self._value == self._range:
            # *Return to the game screen*
            return Return()
        else:
            # Otherwise, just do what the Adjustment normally does
            return renpy.display.behavior.Adjustment.change(self, value)

def my_change_function(value):
    if value > self._range and self._value == self._range:
        # 
        renpy.scene("game_menu")

###screen game_menu add
default adj = MyAdjustment(range = 100, changed = my_change_function, adjustable=True)

###viewport
    adj

Re: little-used history chips

Posted: Wed May 22, 2024 4:22 am
by Andredron
https://devilspider.itch.io/history-search-tool

This tool adds support for searching through contents of the history screen. The tool adds a button which invokes a pop-up, allowing the end user to type in their search prompt. Simple regex patterns are also possible. The tool then filters out the history list and highlights all found results. This extension only works in Ren'Py 8 and onwards!

If you end up using this tool, mention of me in the credits would be appreciated.

If you have any questions about this plug-in, please head to the Community Tab to post a discussion topic

Screenshots in this page are from my games in development.

Code: Select all

## HISTORY SEARCH FUNCTIONALITY by Devil Spiδεr ##
# Version 1.0 #
# The following pieces of code allow the history list to be searched through regex patterns.
# The code is intentionally barebones and separated into chunks so it can be integrated into custom history screens.
# To enable the functionality in your game, please follow the following steps

# INSERT THE FOLLOWING CODE BEFORE YOUR HISTORY SCREEN

default filter_string = ""
default speaker_string = ""

define gui.history_highlight_tags = (["u", f"color={gui.accent_color}"], ["/color", "/u"]) #this will customize the text tags applied to highlighted results

init python:
    import re
    from renpy.text.textsupport import tokenize
    def process_match(m):
        prefix_tags = [t for t in gui.history_highlight_tags[0]]
        suffix_tags = [t for t in gui.history_highlight_tags[1]]
        out = ""
        for t in prefix_tags:
            out += f"{{{t}}}"
        out += m.group(0)
        for t in suffix_tags:
            out += f"{{{t}}}"
        return out

    def highlight(pat="",st=""):
        tk = tokenize(st)
        out = ""
        for i in tk:
            if i[0] == 1:
                out += re.sub(pat, process_match, i[1], flags=re.I)
            if i[0] == 2:
                out += f"{{{i[1]}}}"
        return out

## INSERT THIS INSIDE YOUR HISTORY SCREEN - BE AWARE OF INDENTATION

# screen history():

    default new_list = _history_list

    python:
        new_list=[]
        if filter_string != "":
            for h in _history_list:
                if (speaker_string=="") or ((h.who!=None) and (speaker_string.lower() in h.who.lower())):
                    msg = h.what.lower()
                    out_string = h.what
                    if re.findall(re.compile(filter_string),msg)==[]:
                        continue
                    else:
                        brace = f"{{.*{filter_string}.*}}"
                        if re.findall(re.compile(brace),msg)!=[]:
                            continue
                        new_list.append(h)
                else:
                    continue
        else:
            if speaker_string != "":
                print(speaker_string)
                new_list = [h for h in _history_list if (h.who!=None)and(speaker_string.lower() in h.who.lower())]
            else:
                new_list = _history_list

# REPLACE THE _history_list BLOCK WITH THIS - CUSTOMIZE HOWEVER YOU WANT
    for h in new_list:

        window:
            has fixed:
                yfit True
            if h.who:
                label h.who:
                    style "history_name"
                    substitute False
                    if "color" in h.who_args:
                        text_color h.who_args["color"]

            $ what = renpy.filter_text_tags(h.what, allow=gui.history_allow_tags)
            if filter_string != "":
                $ u_what=highlight(filter_string,what)
            else:
                $ u_what=what
            text u_what:
                substitute False

    if (not new_list) and _history_list:
        label _("No dialogue history entries found.")
    elif not _history_list:
        label _("The dialogue history is empty.")

# ADD THIS TO YOUR HISTORY SCREEN - CUSTOMIZE HOWEVER YOU WANT
    textbutton "Search":
        action Show("input_filter")
        alternate [SetVariable("filter_string", ""), SetVariable("speaker_string", "")]
        xpos 500
        yalign 1.0
        yoffset -45

# ADD THIS AFTER YOUR HISTORY SCREEN - CUSTOMIZE HOWEVER YOU WANT

screen input_filter():

    add "gui/overlay/confirm.png"

    default keyword = filter_string
    default keyperson = speaker_string
    default page = "keyword"
    modal True
    frame:
        align (0.5, 0.5)
        xysize (700,350)
        padding (10, 10)
        vbox:
            xfill True
            style_prefix "confirm_prompt"
            spacing 5
            text "Search for" xalign 0.5
            hbox:
                xalign 0.5
                textbutton "Text" xsize 250 align (0.5, 0.5) action [SetScreenVariable("page", "keyword")]
                textbutton "Speaker"xsize 250  align (0.5, 0.5) action [SetScreenVariable("page", "keyperson")]
            frame:
                xalign 0.5
                has vbox
                input:
                    xalign 0.5
                    value LocalVariableInputValue(page, default=True, returnable=False)

        textbutton "Return":
            align (0.5, 0.9)
            action [Hide("input_filter"), SetVariable("filter_string", keyword.lower()), SetVariable("speaker_string", keyperson.lower())] #, transition=dissolve)
            keysym "game_menu"