1defvarp showconsole 0 1 1
2defsvarp consolelevels [1 2 3]
3defvarp allconsole 0 0 1
4defsvarp allconsolelevels [0 1 2 3]
5
6defvar fullconsole 0 0 1
7toggleconsole = [fullconsole (! $fullconsole)]
8
9defvarp conintime 0 500 $varidxmax
10defvarp conouttime 0 10000 $varidxmax
11defvarp confadetime 0 1000 $varidxmax
12defvarp conlines 0 5 $varidxmax
13defvarp conlinesopen 0 7 $varidxmax
14deffvarp conblend 0 0.75 1
15
16defsvarp ui_hud_connames [Debug Event Frag Chat]
17defsvarp ui_hud_concols [red orange yellow green]
18
19// 1:console 2:count 3:outtime 4:fadetime 5:intime 6:blend 7:size 8:textsize
20ui_hud_displayconsole = [
21    loopconlinesrev $arg1 $arg2 0 ui_hud_consoleline [
22        ui_hud_consoleblend = (ceil (*f 255 $arg6))
23        ui_hud_consoletime = (getconlinereftime $arg1 $ui_hud_consoleline)
24        ui_hud_consolemillis = (- (getmillis 1) $ui_hud_consoletime)
25        ui_hud_consolegrowth = 1.0
26        caseif (&& $arg3 (> $ui_hud_consolemillis $arg3)) [
27            ui_hud_consolectime = (- $ui_hud_consolemillis $arg3)
28            if (&& $arg4 (< $ui_hud_consolectime $arg4)) [
29                ui_hud_consolegrowth = (-f 1 (divf $ui_hud_consolectime $arg4))
30                ui_hud_consoleblend = (clamp (*f $ui_hud_consolegrowth $arg6 255) 0 255)
31            ] [ui_hud_consoleblend = 0]
32        ] (&& $arg5 (< $ui_hud_consolemillis $arg5)) [
33            ui_hud_consolegrowth = (divf $ui_hud_consolemillis $arg5)
34            ui_hud_consoleblend = (clamp (*f $ui_hud_consolegrowth $arg6 255) 0 255)
35            ui_hud_consolegrowth = (-f $ui_hud_consolegrowth)
36        ]
37        if $ui_hud_consoleblend [
38            uitext (getconlinecref $arg1 $ui_hud_consoleline) $arg8 [
39                uicolourset (| (<< $ui_hud_consoleblend 24) $colourwhite)
40                uitextwrap $arg7
41                uitextalign -1
42                uialign -1 1
43                if (<f $ui_hud_consolegrowth 1) [uitextgrowth $ui_hud_consolegrowth]
44            ]
45        ]
46    ]
47]
48
49ui_console_colour_var = [
50    result (format "%1 (%2, %3, %4)" (tohex $arg1 6) (& (>> $arg1 16) 0xFF) (& (>> $arg1 8) 0xFF) (& $arg1 0xFF))
51]
52
53ui_console_current_idname = [
54    if $ui_hud_commandopen [
55        local current_command
56        current_command = (getcommandbuf)
57        if (=s (substr $current_command 0 1) "/") [
58            current_command = (substr $current_command 1)
59
60            // Get start of last id into idname_idx
61            local idname_idx
62            idname_idx = 0
63            local chrlist
64            chrlist = ";()[]^"$"
65            loop i (strlen chrlist) [
66                // strrchr-like functionality
67                local new_idx
68                new_idx = 0
69                local idx_add
70                idx_add = 0
71                while [ (!= $new_idx -1) ] [
72                    new_idx = (strstr (substr $current_command $idx_add) (substr $chrlist $i 1))
73                    idx_add = (+ $idx_add $new_idx 1)
74                    // If character found and after last found, use this index
75                    if (&& (!= $new_idx -1) (> $idx_add $idname_idx ))[
76                        idname_idx = $idx_add
77                    ]
78                ]
79            ]
80
81            // Skip any leading whitespace
82            while [ ( =s (substr (substr $current_command $idname_idx) 0 1) " ") ] [
83                idname_idx = (+ $idname_idx 1)
84            ]
85
86            // Get single id into idname, stopping at next space/tab.
87            local idname
88            idname = (substr $current_command $idname_idx)
89            local idname_end
90            idname_end = (strstr $idname " ")
91            if ( = $idname_end -1 ) [
92                idname_end = (strstr $idname "^t")
93            ]
94            if ( = $idname_end -1 ) [
95                idname_end = (strlen $idname)
96            ]
97            idname = (substr $idname 0 $idname_end)
98
99            if (&& (strlen $idname) ( >= (getvartype $idname) 0)) [
100                result $idname
101            ] [
102                result ""
103            ]
104        ] [
105            result ""
106        ]
107    ] [
108        result ""
109    ]
110]
111
112ui_console_usage_text = [
113    local textstyle
114    textstyle = [uialign -1 1; uitextalign -1; uitextwrap (-f (uiaspect) 1.15)]
115    local idname
116    idname = $arg1
117    local idtype
118    idtype = (getvartype $idname)
119    local idflags
120    idflags = (getvarflags $idname)
121    local idtype_s
122    idtype_s = ""
123    // IDF_CLIENT || IDF_SERVER
124    if (|| (& $idflags $idfbitclient) (& $idflags $idfbitserver)) [
125        idtype_s = (concatif $idtype_s (? (& $idflags $idfbitclient) "Client" "Server"))
126    ]
127    // not ID_COMMAND
128    if (!= $idtype $ididxcommand) [
129        // IDF_INIT
130        if (& $idflags $idfbitinit) [ idtype_s = (concatif $idtype_s "Initialiser")]
131        // IDF_PERSIST
132        if (& $idflags $idfbitpersist) [ idtype_s = (concatif $idtype_s "Persistent")]
133        // IDF_READONLY
134        if (& $idflags $idfbitreadonly) [ idtype_s = (concatif $idtype_s "Read-only")]
135        // IDF_WORLD
136        if (& $idflags $idfbitworld) [ idtype_s = (concatif $idtype_s "World")]
137    ]
138
139    idtype_s = (concatif $idtype_s $[idname@(at $ididxname $idtype)])
140
141    uitext $idtype_s $ui_textstatus $textstyle
142
143    case $idtype $ididxvar [
144        if (& $idflags $idfbithex) [
145            if (= (getvarmax $idname) 0xFFFFFF) [
146                uitext (format "^faMin: ^fw%1^fa, Max: ^fw%2" (ui_console_colour_var (getvarmin $idname)) (ui_console_colour_var (getvarmax $idname))) $ui_textstatus $textstyle
147                uitext (format "^faDefault: ^fw%1^fa, Current: ^fw%2^fa [^fs^f[%3]#^fS]" (ui_console_colour_var (getvardef $idname)) (ui_console_colour_var $$idname) $$idname) $ui_textstatus $textstyle
148            ] [
149                uitext (format "^faMin: ^fw%1^fa, Max: ^fw%2" (tohex (getvarmin $idname)) (tohex (getvarmax $idname))) $ui_textstatus $textstyle
150                uitext (format "^faDefault: ^fw%1^fa, Current: ^fw%2" (tohex (getvardef $idname)) (tohex $$idname)) $ui_textstatus $textstyle
151            ]
152        ] [
153            uitext (format "^faMin: ^fw%1^fa, Max: ^fw%2" (getvarmin $idname) (getvarmax $idname)) $ui_textstatus $textstyle
154            uitext (format "^faDefault: ^fw%1^fa, Current: ^fw%2" (getvardef $idname) $$idname) $ui_textstatus $textstyle
155        ]
156    ] $ididxfvar [
157        uitext (format "^faMin: ^fw%1^fa, Max: ^fw%2" (getfvarmin $idname) (getfvarmax $idname)) $ui_textstatus $textstyle
158        uitext (format "^faDefault: ^fw%1^fa, Current: ^fw%2" (getfvardef $idname) $$idname) $ui_textstatus $textstyle
159    ] $ididxsvar [
160        uitext (format "^faDefault: ^fw%1^fa, Current: ^fw%2" (getsvardef $idname) $$idname) $ui_textstatus $textstyle
161    ] $ididxcommand [
162        if (strlen (getvarargs $idname)) [
163            uitext (format "^faArgs: ^fw%1 ^fa(^fw%2^fa)" (strlen (getvarargs $idname)) (getvarargs $idname)) $ui_textstatus $textstyle
164        ] [
165            uitext "^fAargs: ^fwnone" $ui_textstatus $textstyle
166        ]
167    ]
168
169    local idusage_s
170    idusage_s = (concatword "Usage: ^fa/" $idname)
171
172    // ID_VAR Bitfield
173    if (&& (= $idtype $ididxvar) (> (getvarfields $idname) 1)) [
174        idusage_s = (concat $idusage_s "<bitfield>")
175        uitext $idusage_s $ui_textstatus $textstyle
176        loop i (getvarfields $idname) [
177            uitext (format "^t^fa%1 = %2" (<< 1 $i) (getvarfields $idname $i)) $ui_textstatus $textstyle
178        ]
179    ] [
180        if (getvarfields $idname) [
181            loop i (getvarfields $idname) [
182                if (strlen (getvarfields $idname $i)) [
183                    idusage_s = (concat $idusage_s (concatword "<" (getvarfields $idname $i) ">"))
184                ]
185            ]
186        ] [
187            case $idtype $ididxalias [
188                idusage_s = (concat $idusage_s "<arguments>")
189            ] $ididxvar [
190                idusage_s = (concat $idusage_s "<integer>")
191            ] $ididxfvar [
192                idusage_s = (concat $idusage_s "<float>")
193            ] $ididxsvar [
194                idusage_s = (concat $idusage_s "<string>")
195            ] $ididxcommand [
196                loop i (strlen (getvarargs $idname)) [
197                    local c
198                    c = (substr (getvarargs $idname) $i 1)
199                    cases $c s [n = "<string>"
200                    ] i [n = (? (& $idflags $idfbithex) "<bitfield>" "<integer>")
201                    ] b [n = (? (& $idflags $idfbithex) "<bitfield>" "<integer>")
202                    ] n [n = (? (& $idflags $idfbithex) "<bitfield>" "<integer>")
203                    ] f [n = "<float>"
204                    ] g [n = "<float>"
205                    ] t [n = "<null>"
206                    ] e [n = "<command>"
207                    ] r [n = "<ident>"
208                    ] "^$" [n = "<ident>"
209                    ] () [n = "<?>"]
210                    idusage_s = (concat $idusage_s $n)
211                ]
212            ]
213        ]
214        uitext $idusage_s $ui_textstatus $textstyle
215    ]
216
217    if (strlen (getvardesc $idname)) [
218        uitext (concatword "^fa" (getvardesc $idname)) $ui_textstatus $textstyle
219    ]
220
221    if (= $idtype $ididxalias) [
222        idusage_alias = (getalias $idname)
223        if (>= (strlen $idusage_alias) 256) [
224            idusage_alias = (concat (substr $idusage_alias 0 252) "...")
225        ]
226        uitext (concatword "^faContents: ^fw" $idusage_alias) $ui_textsmall $textstyle
227    ]
228]
229
230ui_hud_showconsole = [
231    uivlist 0 [
232        uialign -1 -1
233        if $ui_hud_commandopen [
234            uiskinborder 0 0 $ui_menu $ui_menu $ui_menu $ui_menu_t $ui_menu_t $ui_menu_t [
235                uialign -1 -1
236                uispace $ui_padsmall $ui_padsmall [
237                    uialign -1 -1
238                    uivlist 0 [
239                        uialign -1 -1
240                        loop i 4 [
241                            if (getconlines $i) [
242                                uihlist 0 [
243                                    uialign -1 -1
244                                    uipad 0 0 $ui_screenborder $ui_screenborder [
245                                        uialign -1 -1
246                                        uivtabskin 0 0 $ui_menu $ui_menu $ui_menu $ui_menu_t $ui_menu_t $ui_menu_t [
247                                            uispace $ui_padsmall $ui_padsmall [
248                                                uitext (at $ui_hud_connames $i) $ui_text [
249                                                    uitextrotate 3
250                                                    uicolourset $[colour@(at $ui_hud_concols $i)]
251                                                ]
252                                            ]
253                                        ]
254                                    ]
255                                    uiskinborder (*f (uiaspect) 0.9) 0 $ui_menu $ui_menu $ui_menu $ui_menu_t $ui_menu_t $ui_menu_t [
256                                        uiclamp 1 1 1 1
257                                        uialign -1 -1
258                                        uispace $ui_padnormal $ui_padsmall [
259                                            uiclamp 1 1 1 1
260                                            uialign -1 -1
261                                            uivlist 0 [
262                                                uiclamp 1 1 1 1
263                                                uialign -1 -1
264                                                ui_hud_displayconsole $i (- $conlinesopen) 0 0 0 1 (-f (*f (uiaspect) 0.9) $ui_padnormal $ui_padnormal $ui_padnormal) $ui_text
265                                            ]
266                                        ]
267                                    ] [uiclamp 1 1 1 1; uialign -1 -1]
268                                ]
269                            ]
270                            uispace 0 $ui_padtiny
271                        ]
272                        uiskinborder 0 0 $ui_menu $ui_menu $ui_menu $ui_menu_t $ui_menu_t $ui_menu_t [
273                            uiclamp 1 1
274                            uialign -1 -1
275                            uihlist 0 [
276                                uialign -1 -1
277                                ui_hud_commandicon = (getcommandicon)
278                                if (=s $ui_hud_commandicon "") [ui_hud_commandicon = $inputtex]
279                                uispace $ui_padsmall $ui_padsmall [uialign -1 -1; uiimage $ui_hud_commandicon (getcommandcolour) 0 0.0225 0.0225]
280                                uitext (getcommandbuf) $ui_textlarge [uitextwrap (-f (*f (uiaspect) 0.9) $ui_padnormal $ui_padnormal); uitextpos (getcommandpos); uitextalign -1; uialign -1 1]
281                            ]
282                        ] [uiclamp 1 1; uialign -1 -1]
283                        local idname
284                        idname = (ui_console_current_idname)
285                        if $idname [
286                            uispace 0 $ui_padtiny
287                            uihlist 0 [
288                                uialign -1 -1
289                                uipad 0 0 $ui_screenborder $ui_screenborder [
290                                    uialign -1 -1
291                                    uivtabskin 0 0 $ui_menu $ui_menu $ui_menu $ui_menu_t $ui_menu_t $ui_menu_t [
292                                        uispace $ui_padsmall $ui_padsmall [
293                                            uitext "Desc" $ui_text [
294                                                uitextrotate 3
295                                                uicolourset $colourgrey
296                                            ]
297                                        ]
298                                    ]
299                                ]
300                                uiskinborder (*f (uiaspect) 0.9) 0 $ui_menu $ui_menu $ui_menu $ui_menu_t $ui_menu_t $ui_menu_t [
301                                    uiclamp 1 1 1 1
302                                    uialign -1 -1
303                                    uispace $ui_padnormal $ui_padsmall [
304                                        uiclamp 1 1 1 1
305                                        uialign -1 -1
306                                        uivlist 0 [
307                                            uiclamp 1 1 1 1
308                                            uialign -1 -1
309                                            ui_console_usage_text $idname
310                                        ]
311                                    ]
312                                ] [uiclamp 1 1 1 1; uialign -1 -1]
313                            ]
314                        ]
315                    ]
316                ]
317            ] [uialign -1 -1]
318        ] [
319            looplist i (? (|| $fullconsole $allconsole (&& (isconnected) (= (gamemode) $modeidxediting))) $allconsolelevels $consolelevels) [
320                ui_hud_displayconsole $i (- $conlines) (? $fullconsole 0 $conouttime) (? $fullconsole 0 $confadetime) (? $fullconsole 0 $conintime) (? $fullconsole 1 $conblend) 1 $ui_text
321            ]
322        ]
323    ]
324]
325