//
// ------------------- ezHUD --------------------
// Head Up Display configuration script
// Made by johnnycz 2006
//
// About:
// This script helps you customize your HUD.
// You select, move, resize, change the frame,
// show, hide and align the HUD elements using
// your keyboard.
// 
// Requirements:
// ezQuake 1517 or newer 
// [ http://ezquake.sourceforge.net/ ]
//
// Usage:
// 1) Place the script into <quake>/ezquake/cfg
// 2) Run ezQuake, go into the console and type: 
//    /exec cfg/ezhud
// 3) Follow the instructions on the screen
//
// ----------------------------------------------
//

// init
unset_re ezhud_.
unalias_re .ezhud_.
hud_planmode 1
if $scr_newhud == 0 scr_newhud 1
hud_recalculate
set ezhud_verbose 1

// store current binds
set ezhud_cfg_save_cmds $cfg_save_cmds
set ezhud_cfg_save_cmdline $cfg_save_cmdline
set ezhud_cfg_save_sysinfo $cfg_save_sysinfo
set ezhud_cfg_save_aliases $cfg_save_aliases
set ezhud_cfg_save_userinfo $cfg_save_userinfo
set ezhud_cfg_save_cvars $cfg_save_cvars
set ezhud_cfg_save_binds $cfg_save_binds
cfg_save_cmds 0
cfg_save_cmdline 0
cfg_save_sysinfo 0
cfg_save_aliases 0
cfg_save_cvars 0
cfg_save_binds 1
wait
echo dumping current bindings...
cfg_save _temp_ezhud_binds

// set binds
bind [ ezhud_sel_prev
bind ] ezhud_sel_next
bind pgdn ezhud_sel_nextmore
bind pgup ezhud_sel_prevmore
bind end ezhud_sel_last
bind home ezhud_sel_first
bind del ezhud_hide
bind ins ezhud_show

bind uparrow ezhud_move_up
bind downarrow ezhud_movedown
bind leftarrow ezhud_moveleft
bind rightarrow ezhud_moveright
bind space +ezhud_mark
bind enter ezhud_toggle
bind h ezhud_help

bind kp_1 "ezhud_align left bottom"
bind kp_2 "ezhud_align center bottom"
bind kp_3 "ezhud_align right bottom"
bind kp_4 "ezhud_align left center"
bind kp_5 "ezhud_align center center"
bind kp_6 "ezhud_align right center"
bind kp_7 "ezhud_align left top"
bind kp_8 "ezhud_align center top"
bind kp_9 "ezhud_align right top"

bind w "ezhud_align_rel_y before"
bind s "ezhud_align_rel_y after"
bind a "ezhud_align_rel_x before"
bind d "ezhud_align_rel_x after"

bind z ezhud_widthdown
bind x ezhud_widthup
bind c ezhud_heightdown
bind v ezhud_heightup

bind q "ezhud_showmore"
bind r "ezhud_resetpos"

bind shift +ezhud_bigchange
bind kp_plus ezhud_scaleup
bind kp_minus ezhud_scaledown
bind kp_slash ezhud_frameup
bind kp_star ezhud_framedown
bind , ezhud_styleup
bind . ezhud_styledown
bind kp_ins ezhud_place_sel
bind kp_enter ezhud_place_conf

bind 1 "ezhud_selplace 1"
bind 2 "ezhud_selplace 2"
bind 3 "ezhud_selplace 3"
bind 4 "ezhud_selplace 4"
bind 5 "ezhud_selplace 5"
bind 6 "ezhud_selplace 6"
bind 7 "ezhud_selplace 7"
bind 8 "ezhud_selplace 8"
bind 9 "ezhud_selplace 9"

bind u ezhud_finish

// instructions
echo "ezHud config loaded"
echo "press $[h$] for help"

// yeah, this sucks, TCL please! (this config is not made in TCL because I think most people would be too lazy to turn off smackdown ruleset to try it)
alias ezhud_help "ezhud_help1; ezhud_help2; ezhud_help3; ezhud_help4; ezhud_help4b; ezhud_help5; ezhud_help6; ezhud_help7; ezhud_help8; ezhud_help9; ezhud_help10; ezhud_help11"
alias ezhud_help1 "echo $[[$], $[]$], $[page up$], $[page down$], $[home$], $[end$] to select elements"
alias ezhud_help2 "echo $[Enter$], $[Del$], $[Ins$] to show/hide elements"
alias ezhud_help3 "echo $[Space$] to mark mark selected elements"
alias ezhud_help4 "echo arrows to move, keypad and w,a,s,d keys to align elements"
alias ezhud_help4b "echo $[r$] to reset element position"
alias ezhud_help5 "echo hold $[shift$] to move in larger steps"
alias ezhud_help6 "echo $[z$], $[x$], $[c$], $[v$] to change width and height"
alias ezhud_help7 "echo keypad plus/minus to scale up/down, slash/star to adjust frame"
alias ezhud_help8 "echo use $[,$] and $[.$] to change style of an element"
alias ezhud_help9 "echo use $[keypad 0$] to align elements to each other"
alias ezhud_help10 "echo press $[q$] to see all element properties"
alias ezhud_help11 "echo press $[u$] when you are done"

// code, etc...
set ezhud_elem_1 ammo
set ezhud_elem_2 ammo1
set ezhud_elem_3 ammo2
set ezhud_elem_4 ammo3
set ezhud_elem_5 ammo4
set ezhud_elem_6 armor
set ezhud_elem_7 armordamage
set ezhud_elem_8 clock
set ezhud_elem_9 cross
set ezhud_elem_10 democlock
set ezhud_elem_11 face
set ezhud_elem_12 fps
set ezhud_elem_13 frags
set ezhud_elem_14 gameclock
set ezhud_elem_15 group1
set ezhud_elem_16 group2
set ezhud_elem_17 group3
set ezhud_elem_18 group4
set ezhud_elem_19 group5
set ezhud_elem_20 group6
set ezhud_elem_21 group7
set ezhud_elem_22 group8
set ezhud_elem_23 group9
set ezhud_elem_24 gun
set ezhud_elem_25 gun2
set ezhud_elem_26 gun3
set ezhud_elem_27 gun4
set ezhud_elem_28 gun5
set ezhud_elem_29 gun6
set ezhud_elem_30 gun7
set ezhud_elem_31 gun8
set ezhud_elem_32 health
set ezhud_elem_33 healthdamage
set ezhud_elem_34 iammo
set ezhud_elem_35 iammo1
set ezhud_elem_36 iammo2
set ezhud_elem_37 iammo3
set ezhud_elem_38 iammo4
set ezhud_elem_39 iarmor
set ezhud_elem_40 key1
set ezhud_elem_41 key2
set ezhud_elem_42 mp3_time
set ezhud_elem_43 mp3_title
set ezhud_elem_44 net
set ezhud_elem_45 netgraph
set ezhud_elem_46 pent
set ezhud_elem_47 ping
set ezhud_elem_48 quad
set ezhud_elem_49 radar
set ezhud_elem_50 ring
set ezhud_elem_51 sigil1
set ezhud_elem_52 sigil2
set ezhud_elem_53 sigil3
set ezhud_elem_54 sigil4
set ezhud_elem_55 speed
set ezhud_elem_56 suit
set ezhud_elem_57 teamfrags
set ezhud_elem_58 teamholdbar
set ezhud_elem_59 tracking
set ezhud_max_elems 59
set ezhud_curnum 1
alias ezhud_curcheck "if $ezhud_curnum > $ezhud_max_elems set ezhud_curnum $ezhud_max_elems else if $ezhud_curnum < 1 set ezhud_curnum 1"
alias ezhud_setcur "ezhud_curcheck; set_ex ezhud_curelem $ezhud_elem_$ezhud_curnum"
alias ezhud_echocur "echo ($ezhud_curnum/$ezhud_max_elems) $ezhud_curelem selected"
ezhud_setcur

set ezhud_place_1 screen
set ezhud_place_2 view
set ezhud_place_3 top
set ezhud_place_4 sbar
set ezhud_place_5 ibar
set ezhud_place_6 hbar
set ezhud_place_7 sfree
set ezhud_place_8 ifree
set ezhud_place_9 hfree

alias ezhud_sel_next "inc ezhud_curnum 1; ezhud_setcur; ezhud_echocur"
alias ezhud_sel_prev "inc ezhud_curnum -1; ezhud_setcur; ezhud_echocur"
alias ezhud_sel_nextmore "inc ezhud_curnum $ezhud_bigchange; ezhud_setcur; ezhud_echocur"
alias ezhud_sel_prevmore "inc ezhud_curnum -$ezhud_bigchange; ezhud_setcur; ezhud_echocur"
alias ezhud_sel_first "set ezhud_curnum 1; ezhud_setcur; ezhud_echocur"
alias ezhud_sel_last "set ezhud_curnum $ezhud_max_elems; ezhud_setcur; ezhud_echocur"

alias ezhud_refresh "hud_recalculate"

set ezhud_smallchange 1
set ezhud_bigchange 8
alias +ezhud_bigchange "set ezhud_curchange $ezhud_bigchange"
alias -ezhud_bigchange "set ezhud_curchange $ezhud_smallchange"
-ezhud_bigchange

alias ezhud_move_up "inc hud_$ezhud_curelem_pos_y -$ezhud_curchange; ezhud_refresh"
alias ezhud_movedown "inc hud_$ezhud_curelem_pos_y $ezhud_curchange; ezhud_refresh"
alias ezhud_moveleft "inc hud_$ezhud_curelem_pos_x -$ezhud_curchange; ezhud_refresh"
alias ezhud_moveright "inc hud_$ezhud_curelem_pos_x $ezhud_curchange; ezhud_refresh"

alias ezhud_resetpos "move $ezhud_curelem 0 0"

alias +ezhud_mark "set_ex ezhud_tempframe $hud_$ezhud_curelem_frame; set_ex ezhud_tempshow $hud_$ezhud_curelem_show;set hud_$ezhud_curelem_frame 2; set hud_$ezhud_curelem_show 1"
alias -ezhud_mark "set hud_$ezhud_curelem_frame $ezhud_tempframe; set hud_$ezhud_curelem_show $ezhud_tempshow; ezhud_refresh"

alias ezhud_toggle "toggle hud_$ezhud_curelem_show"
alias ezhud_hide "hide $ezhud_curelem"
alias ezhud_show "show $ezhud_curelem"

alias ezhud_align "align $ezhud_curelem %1 %2; ezhud_refresh"

alias ezhud_align_rel_y "set hud_$ezhud_curelem_align_y %1; ezhud_refresh"
alias ezhud_align_rel_x "set hud_$ezhud_curelem_align_x %1; ezhud_refresh"

alias ezhud_echoscale "set_ex ezhud_curscale $hud_$ezhud_curelem_scale; set_calc ezhud_curscale $ezhud_curscale * 100; echo $ezhud_curelem size: $ezhud_curscale%"
alias ezhud_echoframe "set_ex ezhud_curframe $hud_$ezhud_curelem_frame; set_calc ezhud_curpframe $ezhud_curframe * 100; if $ezhud_curpframe <= 0 ezhud_echonoframe else if $ezhud_curpframe == 200 echo $ezhud_curelem bordered frame else echo $ezhud_curelem frame: $ezhud_curpframe%%"
alias ezhud_echonoframe "echo $ezhud_curelem frame removed"
alias ezhud_echostyle "set_ex ezhud_curstyle $hud_$ezhud_curelem_style; echo $ezhud_curelem style: $ezhud_curstyle"

alias ezhud_scalecheck "set_ex ezhud_curscale $hud_$ezhud_curelem_scale; if $ezhud_curscale < 0 set hud_$ezhud_curelem_scale 1"
alias ezhud_framecheck "set_ex ezhud_curframe $hud_$ezhud_curelem_frame; if $ezhud_curframe < 0 set hud_$ezhud_curelem_frame 0; if $ezhud_curframe > 1 ezhud_framecheck2"
alias ezhud_framecheck2 "if $ezhud_curframe < 1.5 set hud_$ezhud_curelem_frame 2 else set hud_$ezhud_curelem_frame 1"
alias ezhud_stylecheck "set_ex ezhud_curstyle $hud_$ezhud_curelem_style; if $ezhud_curstyle < 0 set hud_$ezhud_curelem_style 0"

alias ezhud_widthcheck "set_ex ezhud_curwidth $hud_$ezhud_curelem_width; if $ezhud_curwidth < 0 set hud_$ezhud_curelem_width 0"
alias ezhud_heightcheck "set_ex ezhud_curheight $hud_$ezhud_curelem_height; if $ezhud_curheight < 0 set hud_$ezhud_curelem_height 0"

alias ezhud_scaleup "inc hud_$ezhud_curelem_scale 0.1; ezhud_scalecheck; if $ezhud_verbose == 1 ezhud_echoscale"
alias ezhud_scaledown "inc hud_$ezhud_curelem_scale -0.1; ezhud_scalecheck; if $ezhud_verbose == 1 ezhud_echoscale"
alias ezhud_frameup "inc hud_$ezhud_curelem_frame 0.1; ezhud_framecheck; if $ezhud_verbose == 1 ezhud_echoframe"
alias ezhud_framedown "inc hud_$ezhud_curelem_frame -0.1; ezhud_framecheck; if $ezhud_verbose == 1 ezhud_echoframe"
alias ezhud_styleup "inc hud_$ezhud_curelem_style -1; ezhud_stylecheck; if $ezhud_verbose == 1 ezhud_echostyle"
alias ezhud_styledown "inc hud_$ezhud_curelem_style 1; ezhud_stylecheck; if $ezhud_verbose == 1 ezhud_echostyle"

alias ezhud_widthup "inc hud_$ezhud_curelem_width $ezhud_curchange; ezhud_widthcheck"
alias ezhud_widthdown "inc hud_$ezhud_curelem_width -$ezhud_curchange; ezhud_widthcheck"
alias ezhud_heightup "inc hud_$ezhud_curelem_height $ezhud_curchange; ezhud_heightcheck"
alias ezhud_heightdown "inc hud_$ezhud_curelem_height -$ezhud_curchange; ezhud_heightcheck"

alias ezhud_selplace "set ezhud_curelem $ezhud_place_%1; echo $ezhud_curelem selected as a target for alignment"

alias ezhud_place_sel "echo select which element '$ezhud_curelem' should be aligned to with 1-9 or [ & ] keys and press keypad Enter to confirm; set ezhud_align_what $ezhud_curelem"
alias ezhud_place_conf "place $ezhud_align_what $ezhud_curelem; set ezhud_curelem $ezhud_align_what"

alias ezhud_showmore "$ezhud_curelem"

// we will load bindings back and put back all cfg_save_* values
alias ezhud_clearbinds "echo unloading keyboard bindings...; exec configs/_temp_ezhud_binds; wait; set cfg_save_cmds $ezhud_cfg_save_cmds; set cfg_save_cmdline $ezhud_cfg_save_cmdline; set cfg_save_sysinfo $ezhud_cfg_save_sysinfo; set cfg_save_aliases $ezhud_cfg_save_aliases; set cfg_save_userinfo $ezhud_cfg_save_userinfo; set cfg_save_cvars $ezhud_cfg_save_cvars; set cfg_save_binds $ezhud_cfg_save_binds"

alias ezhud_finish "ezhud_clearbinds; unset_re ezhud_.; unalias_re ezhud_.; hud_planmode 0; hud_recalculate; hud_export ezhud_$name; echo your HUD configuration has been saved into ezquake/configs/ezhud_$name.cfg" 
