## Экран истории ###############################################################
##
## Этот экран показывает игроку историю диалогов. Хотя в этом экране нет ничего
## особенного, он имеет доступ к истории диалогов, хранимом в _history_list.
##
## https://www.renpy.org/doc/html/history.html

screen history():
    $ his = History()
    
    tag menu

    ## Избегайте предсказывания этого экрана, так как он может быть очень
    ## массивным.
    predict False

    use game_menu(_("История"), scroll=("vpgrid" if gui.history_height else "viewport"), yinitial=1.0, spacing=gui.history_spacing):
        
        style_prefix "history"
        
        vbox:
            for h in _history_list:
                $ his.set_current_id(h.who_args.get("id")) 

                if (his.current_id == his.pl or his.current_id == his.nr):
                    use player(his.prev_id, his.current_id, h)
                else:
                    use char(his.prev_id, his.current_id, h)

                $ his.set_prev_id(his.current_id)

            if not _history_list:
                label _("История диалогов пуста.") xalign 0.55


screen player(prev_id, current_id, h):
    style_prefix "player"
    
    frame:
        if prev_id != current_id:
            background Frame("gui/history/frame_player_polygon.webp", 15, 12, 12, 12)
        else:
            background Frame("gui/history/frame_player.webp", 15, 12, 12, 12)

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


screen char(prev_id, current_id, h):
    style_prefix "char"
   
    hbox:        
        hbox:
            style "char_avatar"
            if renpy.exists("gui/history/" + current_id + ".webp") and prev_id != current_id:
                add "gui/history/[current_id].webp" yalign 1.0
        
        frame:
            if prev_id != current_id:
                background Frame("gui/history/frame_char_polygon.webp", 45, 12, 12, 12)
            else:
                background Frame("gui/history/frame_char.webp", 45, 12, 12, 12)

            has vbox
            
            if prev_id != current_id:
                if h.who:
                    label h.who:            
                        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)
            text what substitute False


style history_vbox is empty
style player_frame is history_frame
style char_frame is history_frame

style history_vbox:
    spacing 5
    xsize 1050

style history_frame:
    padding (30, 10)
    xmaximum 613
    xminimum 100

style player_frame:
    xalign 1.0
    
style char_hbox:
    xalign 0.0

style char_avatar:
    xsize 48
    yalign 1.0

style player_text:
    color "#fdfcf8"
    size 24
    xoffset -15

style char_label_text:
    bold True
    size 24

style char_text:
    color "#675842"
    size 24

style player_text:
    variant "small"
    size 28

style char_label_text:
    variant "small"
    size 28

style char_text:
    variant "small"
    size 28