Skip to content

Instantly share code, notes, and snippets.

@qreeves
Last active September 18, 2023 03:19
Show Gist options
  • Save qreeves/d562d6eea8d3a66a90c3ac2ca1b87139 to your computer and use it in GitHub Desktop.
Save qreeves/d562d6eea8d3a66a90c3ac2ca1b87139 to your computer and use it in GitHub Desktop.
newuistyle = [
[ui_style_@arg1] = [@arg2]
]
uistyle = [
[ui_style_@arg1] [@arg2] [@arg3] [@arg4] [@arg5] [@arg6] [@arg7] [@arg8] [@arg9] [@arg10] [@arg11] [@arg12] [@arg13] [@arg14] [@arg15] [@arg16] [@arg17] [@arg18] [@arg19] [@arg20] [@arg21] [@arg22] [@arg23] [@arg24] [@arg25]
]
newuistyle clampxy [uiclamp 1 1 1 1]
newuistyle clampx [uiclamp 1 1 0 0]
newuistyle clampy [uiclamp 0 0 1 1]
newuistyle lefttop [uialign -1 -1]
newuistyle leftmiddle [uialign -1 0]
newuistyle leftbottom [uialign -1 1]
newuistyle centertop [uialign 0 -1]
newuistyle centermiddle [uialign 0 0]
newuistyle centerbottom [uialign 0 1]
newuistyle righttop [uialign 1 -1]
newuistyle rightmiddle [uialign 1 0]
newuistyle rightbottom [uialign 1 1]
ui_vars_searchstr = ""
ui_vars_defaultfilters = [
ui_vars_types = (| (<< 1 $ididxvar) (<< 1 $ididxfvar) (<< 1 $ididxsvar))
ui_vars_notypes = 0
ui_vars_flags = $idfbitcomplete
ui_vars_noflags = 0
]
ui_vars_defaultfilters
ui_vars_more = 0
ui_vars_init = [
ui_vars_index = 0
ui_vars_num = -1
ui_vars_page = 0
ui_vars_reset = 1
]
ui_vars_typevar = [
uicheckbox $arg1 (& $$arg2 $arg3) $ui_checksize [
if (& $$arg2 $arg3) [
$arg2 = (&~ $$arg2 $arg3)
] [
$arg2 = (| $$arg2 $arg3)
]
ui_vars_init
] 0 0 0 [uialign -1]
]
ui_vars_display = [
local textstyle
textstyle = [
uistyle leftbottom
uitextalign -1
uitextwrap 0.6
]
local idname
idname = $arg1
local idtype
idtype = (getvartype $idname)
local idflags
idflags = (getvarflags $idname)
local idtype_s
idtype_s = ""
// IDF_CLIENT || IDF_SERVER
if (|| (& $idflags $idfbitclient) (& $idflags $idfbitserver)) [
idtype_s = (concatif $idtype_s (? (& $idflags $idfbitclient) "Game" "Server"))
]
// not ID_COMMAND
if (!= $idtype $ididxcommand) [
// IDF_INIT
if (& $idflags $idfbitinit) [ idtype_s = (concatif $idtype_s "Initialiser")]
// IDF_PERSIST
if (& $idflags $idfbitpersist) [ idtype_s = (concatif $idtype_s "Persistent")]
// IDF_READONLY
if (& $idflags $idfbitreadonly) [ idtype_s = (concatif $idtype_s "Read-only")]
// IDF_WORLD
if (& $idflags $idfbitworld) [ idtype_s = (concatif $idtype_s "World")]
]
idtype_s = (concatif $idtype_s $[idname@(at $ididxname $idtype)])
uivlist $ui_padsmall [
uistyle lefttop
uitext $idname $ui_textbig $textstyle
uicolourtext $idtype_s $ui_main0 $ui_textstatus $textstyle
]
uivlist $ui_padsmall [
uistyle lefttop
[@[idname]_varval] = $$idname
uiinput [@[idname]_varval] 10 [@idname $[@@[idname]_varval]] 1 0
]
uivlist $ui_padsmall [
uistyle lefttop
uistyle clampx
case $idtype $ididxvar [
if (& $idflags $idfbithex) [
uitext (format "^faMin: ^fw%1^fa, Max: ^fw%2" (tohex (getvarmin $idname)) (tohex (getvarmax $idname))) $ui_textstatus $textstyle
if (= (getvardef $idname) $$idname) [
uitext (format "^faCurrent: ^fw%1 ^fa(default)" (tohex (getvardef $idname))) $ui_textstatus $textstyle
] [
uitext (format "^faDefault: ^fw%1^fa, Current: ^fy%2" (tohex (getvardef $idname)) (tohex $$idname)) $ui_textstatus $textstyle
]
] [
uitext (format "^faMin: ^fw%1^fa, Max: ^fw%2" (getvarmin $idname) (getvarmax $idname)) $ui_textstatus $textstyle
if (= (getvardef $idname) $$idname) [
uitext (format "^faCurrent: ^fw%1 ^fa(default)" (getvardef $idname)) $ui_textstatus $textstyle
] [
uitext (format "^faDefault: ^fw%1^fa, Current: ^fy%2" (getvardef $idname) $$idname) $ui_textstatus $textstyle
]
]
] $ididxfvar [
uitext (format "^faMin: ^fw%1^fa, Max: ^fw%2" (getfvarmin $idname) (getfvarmax $idname)) $ui_textstatus $textstyle
if (=f (getfvardef $idname) $$idname) [
uitext (format "^faCurrent: ^fw%1 ^fa(default)" (getfvardef $idname)) $ui_textstatus $textstyle
] [
uitext (format "^faDefault: ^fw%1^fa, Current: ^fy%2" (getfvardef $idname) $$idname) $ui_textstatus $textstyle
]
] $ididxsvar [
if (=s (getsvardef $idname) $$idname) [
uitext (format "^faCurrent: ^fw%1 ^fa(default)" (getsvardef $idname)) $ui_textstatus $textstyle
] [
uitext (format "^faDefault: ^fw%1^fa, Current: ^fy%2" (getsvardef $idname) $$idname) $ui_textstatus $textstyle
]
] $ididxcommand [
if (strlen (getvarargs $idname)) [
uitext (format "^faArguments: ^fw%1 ^fa(^fw%2^fa)" (strlen (getvarargs $idname)) (getvarargs $idname)) $ui_textstatus $textstyle
] [
uitext "^fAArguments: ^fwnone" $ui_textstatus $textstyle
]
]
local idusage_s
idusage_s = (concatword "Usage: ^fa/" $idname)
// ID_VAR Bitfield
if (&& (= $idtype $ididxvar) (> (getvarfields $idname) 1)) [
idusage_s = (concat $idusage_s "<bitfield>")
uitext $idusage_s $ui_textstatus $textstyle
loop i (getvarfields $idname) [
uitext (format "^t^fa%1 = %2" (<< 1 $i) (getvarfields $idname $i)) $ui_textstatus $textstyle
]
] [
if (getvarfields $idname) [
loop i (getvarfields $idname) [
if (strlen (getvarfields $idname $i)) [
idusage_s = (concat $idusage_s (concatword "<" (getvarfields $idname $i) ">"))
]
]
] [
case $idtype $ididxalias [
idusage_s = (concat $idusage_s "<arguments>")
] $ididxvar [
idusage_s = (concat $idusage_s "<integer>")
] $ididxfvar [
idusage_s = (concat $idusage_s "<float>")
] $ididxsvar [
idusage_s = (concat $idusage_s "<string>")
] $ididxcommand [
loop i (strlen (getvarargs $idname)) [
local c
c = (substr (getvarargs $idname) $i 1)
cases $c s [n = "<string>"
] i [n = (? (& $idflags $idfbithex) "<bitfield>" "<integer>")
] b [n = (? (& $idflags $idfbithex) "<bitfield>" "<integer>")
] n [n = (? (& $idflags $idfbithex) "<bitfield>" "<integer>")
] f [n = "<float>"
] g [n = "<float>"
] t [n = "<null>"
] e [n = "<command>"
] r [n = "<ident>"
] "^$" [n = "<ident>"
] () [n = "<?>"]
idusage_s = (concat $idusage_s $n)
]
]
]
uitext $idusage_s $ui_textstatus $textstyle
]
if (strlen (getvardesc $idname)) [
uitext (concatword "^fa" (getvardesc $idname)) $ui_textstatus $textstyle
]
if (= $idtype $ididxalias) [
idusage_alias = (getalias $idname)
if (>= (strlen $idusage_alias) 256) [
idusage_alias = (concat (substr $idusage_alias 0 252) "..")
]
uitext (concatword "^faContents: ^fw" $idusage_alias) $ui_textsmall $textstyle
]
]
]
defvarp varsuipaginate 10 100 1000
newui "vars" [
local numvars
local scurflag
local scurvar
numvars = (getvarinfo -1 $ui_vars_types $ui_vars_notypes $ui_vars_flags $ui_vars_noflags $ui_vars_searchstr 3)
if (>= $ui_vars_num $numvars) [ ui_vars_init ]
uihlist $ui_padbutton [
uistyle lefttop
uivlist $ui_padbutton [
uistyle clampy
uistyle lefttop
uiskinborder 0 0 $ui_menu $ui_menu $ui_menu $ui_line $colourred $colourpink [
uistyle clampxy
uistyle lefttop
uispace $ui_padbutton $ui_padbutton [
uistyle lefttop
uivlist $ui_padbutton [
uistyle lefttop
uiinput ui_vars_searchstr 32 [ui_vars_num = -1] 1 0 "[click here to enter wildcard search text]" 0 [] [uialtrelease [ui_vars_searchstr = ""]]
uihlist 0 [
uistyle clampx
uistyle leftmiddle
uibuttonz "Export" [inputconsole "writevars"] 0 $colourgreen [] $ui_buttonzh $ui_text $ui_padsmall
uihlist 0 [
uistyle clampx
uistyle centermiddle
uitext (format "^fg%1 ^fa%2 found" $numvars (? (= $numvars 1) "match" "matches")) $ui_text [
uistyle clampx
uistyle centermiddle
uitextalign 0
uitextwrap 0.6
]
]
]
uitextleft "Types" $ui_text
uigrid 2 0 0 [
uistyle clampx
uistyle lefttop
loop n $ididxmax [
uifill 0.125 0 [
uistyle lefttop
ui_vars_typevar $[idname@(at $ididxname $n)] ui_vars_types (<< 1 $n)
]
]
]
uitextleft "Flags" $ui_text
uigrid 2 0 0 [
uistyle clampx
uistyle lefttop
loop n (listlen $idfidxname) [
uifill 0.125 0 [
uistyle lefttop
scurflag = (at $idfidxname $n)
ui_vars_typevar $[idfname@scurflag] ui_vars_flags $[idfbit@scurflag]
]
]
]
]
]
] [uistyle clampxy]
]
uivlist $ui_padbutton [
uistyle lefttop
uistyle clampy
uistyle lefttop
uiskinborder 0 0 $ui_menu $ui_menu $ui_menu $ui_line $colourred $colourpink [
uistyle clampxy
uistyle lefttop
uispace $ui_padbutton $ui_padbutton [
uivlist $ui_padbutton [
uistyle clampxy
uistyle lefttop
uihlist 0 [uispace 0.175]
local pages; pages = (ceil (divf $numvars $varsuipaginate))
if (< $ui_vars_page 0) [ ui_vars_page = $pages ]
if (> $ui_vars_page $pages) [ ui_vars_page = 0 ]
local curpage; curpage = (clamp $ui_vars_page 0 (- $pages 1))
local curindex; curindex = (clamp (* $curpage $varsuipaginate) 0 (- $numvars 1))
local curlist; curlist = (clamp (- $numvars $curindex) 1 $varsuipaginate)
uihlist $ui_padbutton [
uistyle clampxy
uistyle lefttop
uiscroll 0.3 0.5 [
uistyle lefttop
uivlist $ui_padtiny [
uistyle clampxy
uistyle lefttop
loop m $curlist [
local n; n = (+ $curindex $m)
uihlist 0 [
uistyle clampx
uialign -1
ui_vars_curname = (getvarinfo $n $ui_vars_types $ui_vars_notypes $ui_vars_flags $ui_vars_noflags $ui_vars_searchstr 3)
uiradio $ui_vars_curname (= $ui_vars_num $n) $ui_radiosize [ui_vars_num = @n]
]
]
]
if $ui_vars_reset [
uiclipoffsetx 0
uiclipoffsety 0
ui_vars_reset = 0
]
]
uivscroll $ui_slidersize 0.5
]
uihlist $ui_padbutton [
uistyle leftmiddle
uibuttonz "<" [ui_vars_page = (- $ui_vars_page 1); ui_vars_reset = 1] 0 $colourwhite [] $ui_buttonzh $ui_text $ui_padsmall
uibuttonz ">" [ui_vars_page = (+ $ui_vars_page 1); ui_vars_reset = 1] 0 $colourwhite [] $ui_buttonzh $ui_text $ui_padsmall
uitext (concatword "Page ^fs^fy" (+ $curpage 1) "^fS of ^fs^fy" $pages "^fS")
]
]
]
] [uistyle clampxy]
]
uivlist $ui_padbutton [
uistyle lefttop
uistyle clampxy
uiskinborder 0 0 $ui_menu $ui_menu $ui_menu $ui_line $colourred $colourpink [
uistyle clampxy
uistyle lefttop
uispace $ui_padbutton $ui_padbutton [
uistyle clampxy
uistyle lefttop
uihlist 0 [uispace 0.3]
if (&& (>= $ui_vars_num 0) (< $ui_vars_num $numvars) (> $numvars 0)) [
scurvar = (getvarinfo $ui_vars_num $ui_vars_types $ui_vars_notypes $ui_vars_flags $ui_vars_noflags $ui_vars_searchstr)
uivlist $ui_padbutton [
uistyle lefttop
ui_vars_display $scurvar
]
] [
uivlist $ui_padsmall [
uistyle lefttop
uitext "No variable selected" $ui_textbig [
uistyle leftbottom
uitextalign -1
uitextwrap 0.6
]
uicolourtext "Search using the text box at the top of the middle column." $ui_main0 $ui_texttip [
uistyle leftbottom
uitextalign -1
uitextwrap 0.6
]
uicolourtext "Select a variable by clicking on it." $ui_main0 $ui_texttip [
uistyle leftbottom
uitextalign -1
uitextwrap 0.6
] $ui_main3
]
]
]
] [uistyle clampxy]
uibuttonz "Close Menu" [hideui vars] 0 $colourred [] $ui_buttonzh $ui_text $ui_padsmall
]
]
]
ui_vars_init
showui vars
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment