[gui] playdemo

[gui] playdemo

Postby bonifarz » 06 Oct 2012, 14:26

When Quin pointed out that one can actually manipulate the gamespeed when playing a demo file, I thought it could be useful to write a small cube script for that.

So if you find this useful or run into any problems, feel free to leave your comment here.

dmo.jpeg
This is how it looks like

playdmo.png
previous version to compare and a trial time challenge

{l Code}: {l Select All Code}

// playdmo menu by Bonifarz

dmofile = ""
dmospeed = "100"
ffwtime = "10"
dmomark = "0"
dmomarks = "0"
dmomarkm = "0"
time0 = ""
dmotail = "0"

resetdemo = [
    demo $dmofile
    time0 = (getmillis)
    sleep 100 [
        showgui dmo
    ]
]

ffwdemo = [
     dmopaused = $sv_gamepaused
     sv_gamepaused 0
     sv_gamespeed 10000
     sleep ( $arg1 )  [
         sv_gamespeed $dmospeed
         sv_gamepaused $dmopaused
     ]
]

newgui pickdmo [
            guitext "Select a demo file: ^fg"
            guibar
            loopfiles fn demos dmo [
                guibutton $fn [
                    dmofile = @fn
                    resetdemo
                ]
            ]
]

newgui dmo [
guistayopen [
    if (> (strlen $dmofile) 0)  [
        guibar
        guilist [
            if (> $sv_gamepaused 0 )[
                guitext "^f(textures/checkboxon)"
                guibutton " paused " [
                    sv_gamepaused 0
                    dmopaused = $sv_gamepaused
                ]
            ] [
                guitext "^f(textures/checkbox)"
                guibutton " paused " [
                    sv_gamepaused 1
                    dmopaused = $sv_gamepaused
                ]
            ]
            guitext "  speed "
            guifield dmospeed 3 [ sv_gamespeed $dmospeed]
            guitext " %"
            dmotime = (- (getmillis ) $time0 )
            guibutton (concatword "  ^f(textures/modes/timetrial) "(timestr $dmotime) ) [
                dmomark = $dmotime
                dmomarks = (divf $dmotime 1000)
                dmomarkm = (div $dmomarks 60)
                dmomarks = (-f $dmomarks (* dmomarkm 60) )
            ]
            guibutton " ^f(textures/warning)restart " [
                resetdemo
            ]
            guibutton "  ^f(textures/menu)browse demos" [
                showgui pickdmo
            ]
        ]
        guibar
        guilist [
            guibutton "^f(textures/modes/jetpack)skip " [
                // ffwdemo (getalias ffwtime)
                 ffwdemo (*f $ffwtime 1000)
            ]
            guifield ffwtime 3
            guitext " seconds "
            // debug: guitext (timestr $dmomark)
            guibutton  "or jump to " [
                if (< $dmotime $dmomark) [
                    ffwdemo (-f $dmomark $dmotime)
                ]
            ]
            guifield dmomarkm 2 [
                dmomark = (*f (+f (*f $dmomarkm 60) $dmomarks ) 1000)
            ]
            guitext " m "
            guifield dmomarks 6 [
                dmomark = (*f (+f (*f $dmomarkm 60) $dmomarks ) 1000)
            ]
            guitext " s"
            if (> $dmotime $dmomark) [
                guibutton " (needs restart)" [ resetdemo ]
            ]
        ]
        guibar
        guilist [
            guitext "gui options:"
            guibutton "^f(textures/player)hide for a second to switch targets" [
                cleargui
                dmopaused = $sv_gamepaused
                sv_gamepaused 0
                sleep 1000 [
                      showgui dmo
                      sv_gamepaused $dmopaused
                     
                ]
            ] 
            guibutton " ^f(textures/hud/arrow)move up " [
                dmotail = (+ $dmotail 3)
            ]
            guibutton " ^f(textures/action)center " [
                dmotail = 0
            ]
        ]
        guibar
        // some empty lines to push this gui a bit upwards, such that we can see something ;)
        loop i $dmotail [
            guilist [ guitext  "  " ]
        ]
    ] [ // else: no dmofile picked yet
        showgui pickdmo
    ]
]
]

showgui dmo

User avatar
bonifarz
 
Posts: 379
Joined: 09 Apr 2012, 12:16
Location: switzerland

Re: [gui] playdemo

Postby bonifarz » 01 Aug 2013, 13:04

Update for RE 1.4 with a few changes (browse for dmo files, hide for a second to switch targets, layout changes) - I hope it is more useful now.
User avatar
bonifarz
 
Posts: 379
Joined: 09 Apr 2012, 12:16
Location: switzerland

Re: [gui] playdemo

Postby Ulukai » 01 Aug 2013, 13:25

Very nice! Thanks for sharing! :)
User avatar
Ulukai
 
Posts: 741
Joined: 19 Mar 2011, 10:55
Location: Mechelen, Belgium

Who is online

Users browsing this forum: No registered users and 1 guest