[Constants]
global $depthsaved = 0
global $rangesaved = 0

[KeyHelp]
key = no_modifiers F1
type = toggle
run = CommandListHelp
;run = CommandListHelp, CommandListA1

;Left range down.
[KeyLRD]
Key = shift VK_LEFT
type = hold
x7 = 10
transition = 30000
transition_type = linear

;Left range up.
[KeyLRU]
Key = shift VK_RIGHT
type = hold
y7 = 10
transition = 30000
transition_type = linear

;Right range down.
[KeyRRD]
Key = shift VK_DOWN
type = hold
z7 = 10
transition = 30000
transition_type = linear

;Right range up.
[KeyRRU]
Key = shift VK_UP
type = hold
w7 = 10
transition = 30000
transition_type = linear

;Left range down single.
[KeyLRDS]
Key = no_shift VK_LEFT
type = hold
x7 = 10

;Left range up single.
[KeyLRUS]
Key = no_shift VK_RIGHT
type = hold
y7 = 10

;Right range down single.
[KeyRRDS]
Key = no_shift VK_DOWN
type = hold
z7 = 10

;Right range up single.
[KeyRRUS]
Key = no_shift VK_UP
type = hold
w7 = 10

;Range speed mult.
[KeySM]
Key = no_shift ctrl
back = shift ctrl
type = cycle
x20 = 10, 25, 50, 100, 500, 1000, 10000, 100000, 1

;Current regex.
[KeyCR]
Key = no_modifiers x
back = no_modifiers z
type = cycle
y20 = 1, 2, 3, 0

;;Save the depth value.
;[KeySaveDepth]
;Key = no_modifiers a
;run = CommandListSaveDepth
;
;;Save the depth range values.
;[KeySaveDepthRange]
;Key = no_modifiers q
;run = CommandListSaveDepthRange

[CommandListA1]
pre ResourceNotification = ref ResourceA1
pre ResourceNotificationParams = ref ResourceNotificationParams
pre run = CustomShaderFormatText
$\ShaderFixes\help.ini\notification_timeout = time + 2.0
[CommandListA1OK]
pre ResourceNotification = ref ResourceA1OK
pre ResourceNotificationParams = ref ResourceNotificationParams
pre run = CustomShaderFormatText
$\ShaderFixes\help.ini\notification_timeout = time + 2.0
[CommandListA2]
pre ResourceNotification = ref ResourceA2
pre ResourceNotificationParams = ref ResourceNotificationParams
pre run = CustomShaderFormatText
$\ShaderFixes\help.ini\notification_timeout = time + 2.0
[CommandListA2OK]
pre ResourceNotification = ref ResourceA2OK
pre ResourceNotificationParams = ref ResourceNotificationParams
pre run = CustomShaderFormatText
$\ShaderFixes\help.ini\notification_timeout = time + 2.0
[CommandListA3]
pre ResourceNotification = ref ResourceA3
pre ResourceNotificationParams = ref ResourceNotificationParams
pre run = CustomShaderFormatText
$\ShaderFixes\help.ini\notification_timeout = time + 2.0
[CommandListA3OK]
pre ResourceNotification = ref ResourceA3OK
pre ResourceNotificationParams = ref ResourceNotificationParams
pre run = CustomShaderFormatText
$\ShaderFixes\help.ini\notification_timeout = time + 2.0

[CommandListR1]
pre ResourceNotification = ref ResourceR1
pre ResourceNotificationParams = ref ResourceNotificationParams
pre run = CustomShaderFormatText
$\ShaderFixes\help.ini\notification_timeout = time + 2.0
[CommandListR1OK]
pre ResourceNotification = ref ResourceR1OK
pre ResourceNotificationParams = ref ResourceNotificationParams
pre run = CustomShaderFormatText
$\ShaderFixes\help.ini\notification_timeout = time + 2.0
[CommandListR2]
pre ResourceNotification = ref ResourceR2
pre ResourceNotificationParams = ref ResourceNotificationParams
pre run = CustomShaderFormatText
$\ShaderFixes\help.ini\notification_timeout = time + 2.0
[CommandListR2OK]
pre ResourceNotification = ref ResourceR2OK
pre ResourceNotificationParams = ref ResourceNotificationParams
pre run = CustomShaderFormatText
$\ShaderFixes\help.ini\notification_timeout = time + 2.0
[CommandListR3]
pre ResourceNotification = ref ResourceR3
pre ResourceNotificationParams = ref ResourceNotificationParams
pre run = CustomShaderFormatText
$\ShaderFixes\help.ini\notification_timeout = time + 2.0
[CommandListR3OK]
pre ResourceNotification = ref ResourceR3OK
pre ResourceNotificationParams = ref ResourceNotificationParams
pre run = CustomShaderFormatText
$\ShaderFixes\help.ini\notification_timeout = time + 2.0


[CommandListHelp]
; The pre commands run when the F1 key is first pressed. Set the current help
; text to the full help text and run the formatting shader
pre ResourceHelp = ref ResourceHelpFull
pre ResourceParams = ref ResourceParamsFull
pre run = CustomShaderFormatText
; Setting the short help text to null disables the timeout in the present
; command list:
pre ResourceHelpShort = null
; The post commands run when the help key is pressed again. Set the current
; help text to null to disable the help shader:
post ResourceHelp = null

;[CommandListSaveDepth]
;$depthsaved=1
;if y20==1
;if $a0==0
;$a0=z6-1
;else if $a1==0
;$a1=z6-1
;else if $a2==0
;$a2=z6-1
;else if $a3==0
;$a3=z6-1
;else if $a4==0
;$a4=z6-1
;else if $a5==0
;$a5=z6-1
;else if $a6==0
;$a6=z6-1
;else if $a7==0
;$a7=z6-1
;else if $a8==0
;$a8=z6-1
;else if $a9==0
;$a9=z6-1
;else if $a10==0
;$a10=z6-1
;else if $a11==0
;$a11=z6-1
;else if $a12==0
;$a12=z6-1
;else if $a13==0
;$a13=z6-1
;else if $a14==0
;$a14=z6-1
;else if $a15==0
;$a15=z6-1
;else if $a16==0
;$a16=z6-1
;else if $a17==0
;$a17=z6-1
;else if $a18==0
;$a18=z6-1
;else if $a19==0
;$a19=z6-1
;else if $a20==0
;$a20=z6-1
;else if $a21==0
;$a21=z6-1
;else if $a22==0
;$a22=z6-1
;else if $a23==0
;$a23=z6-1
;else if $a24==0
;$a24=z6-1
;else if $a25==0
;$a25=z6-1
;else if $a26==0
;$a26=z6-1
;else if $a27==0
;$a27=z6-1
;else if $a28==0
;$a28=z6-1
;else if $a29==0
;$a29=z6-1
;else if $a30==0
;$a30=z6-1
;else if $a31==0
;$a31=z6-1
;else if $a32==0
;$a32=z6-1
;else if $a33==0
;$a33=z6-1
;else if $a34==0
;$a34=z6-1
;else if $a35==0
;$a35=z6-1
;else if $a36==0
;$a36=z6-1
;else if $a37==0
;$a37=z6-1
;else if $a38==0
;$a38=z6-1
;else if $a39==0
;$a39=z6-1
;else
;$depthsaved=0
;run=CommandListA1
;endif
;if $depthsaved==1
;run=CommandListA1OK
;endif
;endif
;if y20==2
;if $b0==0
;$b0=z6-1
;else if $b1==0
;$b1=z6-1
;else if $b2==0
;$b2=z6-1
;else if $b3==0
;$b3=z6-1
;else if $b4==0
;$b4=z6-1
;else if $b5==0
;$b5=z6-1
;else if $b6==0
;$b6=z6-1
;else if $b7==0
;$b7=z6-1
;else if $b8==0
;$b8=z6-1
;else if $b9==0
;$b9=z6-1
;else if $b10==0
;$b10=z6-1
;else if $b11==0
;$b11=z6-1
;else if $b12==0
;$b12=z6-1
;else if $b13==0
;$b13=z6-1
;else if $b14==0
;$b14=z6-1
;else if $b15==0
;$b15=z6-1
;else if $b16==0
;$b16=z6-1
;else if $b17==0
;$b17=z6-1
;else if $b18==0
;$b18=z6-1
;else if $b19==0
;$b19=z6-1
;else if $b20==0
;$b20=z6-1
;else if $b21==0
;$b21=z6-1
;else if $b22==0
;$b22=z6-1
;else if $b23==0
;$b23=z6-1
;else if $b24==0
;$b24=z6-1
;else if $b25==0
;$b25=z6-1
;else if $b26==0
;$b26=z6-1
;else if $b27==0
;$b27=z6-1
;else if $b28==0
;$b28=z6-1
;else if $b29==0
;$b29=z6-1
;else if $b30==0
;$b30=z6-1
;else if $b31==0
;$b31=z6-1
;else if $b32==0
;$b32=z6-1
;else if $b33==0
;$b33=z6-1
;else if $b34==0
;$b34=z6-1
;else if $b35==0
;$b35=z6-1
;else if $b36==0
;$b36=z6-1
;else if $b37==0
;$b37=z6-1
;else if $b38==0
;$b38=z6-1
;else if $b39==0
;$b39=z6-1
;else
;$depthsaved=0
;run=CommandListA2
;endif
;if $depthsaved==1
;run=CommandListA2OK
;endif
;endif
;if y20==3
;if $c0==0
;$c0=z6-1
;else if $c1==0
;$c1=z6-1
;else if $c2==0
;$c2=z6-1
;else if $c3==0
;$c3=z6-1
;else if $c4==0
;$c4=z6-1
;else if $c5==0
;$c5=z6-1
;else if $c6==0
;$c6=z6-1
;else if $c7==0
;$c7=z6-1
;else if $c8==0
;$c8=z6-1
;else if $c9==0
;$c9=z6-1
;else if $c10==0
;$c10=z6-1
;else if $c11==0
;$c11=z6-1
;else if $c12==0
;$c12=z6-1
;else if $c13==0
;$c13=z6-1
;else if $c14==0
;$c14=z6-1
;else if $c15==0
;$c15=z6-1
;else if $c16==0
;$c16=z6-1
;else if $c17==0
;$c17=z6-1
;else if $c18==0
;$c18=z6-1
;else if $c19==0
;$c19=z6-1
;else if $c20==0
;$c20=z6-1
;else if $c21==0
;$c21=z6-1
;else if $c22==0
;$c22=z6-1
;else if $c23==0
;$c23=z6-1
;else if $c24==0
;$c24=z6-1
;else if $c25==0
;$c25=z6-1
;else if $c26==0
;$c26=z6-1
;else if $c27==0
;$c27=z6-1
;else if $c28==0
;$c28=z6-1
;else if $c29==0
;$c29=z6-1
;else if $c30==0
;$c30=z6-1
;else if $c31==0
;$c31=z6-1
;else if $c32==0
;$c32=z6-1
;else if $c33==0
;$c33=z6-1
;else if $c34==0
;$c34=z6-1
;else if $c35==0
;$c35=z6-1
;else if $c36==0
;$c36=z6-1
;else if $c37==0
;$c37=z6-1
;else if $c38==0
;$c38=z6-1
;else if $c39==0
;$c39=z6-1
;else
;$depthsaved=0
;run=CommandListA3
;endif
;if $depthsaved==1
;run=CommandListA3OK
;endif
;endif
;
;[CommandListSaveDepthRange]
;$depthsaved=1
;if y20==1
;if $ar1==0 && $ar2==0
;$ar1=y6
;$ar2=z6
;else if $ar3==0 && $ar4==0
;$ar3=y6
;$ar4=z6
;else if $ar5==0 && $ar6==0
;$ar5=y6
;$ar6=z6
;else if $ar7==0 && $ar8==0
;$ar7=y6
;$ar8=z6
;else
;$depthsaved=0
;run=CommandListR1
;endif
;if $depthsaved==1
;run=CommandListR1OK
;endif
;endif
;if y20==2
;if $br1==0 && $br2==0
;$br1=y6
;$br2=z6
;else if $br3==0 && $br4==0
;$br3=y6
;$br4=z6
;else if $br5==0 && $br6==0
;$br5=y6
;$br6=z6
;else if $br7==0 && $br8==0
;$br7=y6
;$br8=z6
;else
;$depthsaved=0
;run=CommandListR2
;endif
;if $depthsaved==1
;run=CommandListR2OK
;endif
;endif
;if y20==3
;if $cr1==0 && $cr2==0
;$cr1=y6
;$cr2=z6
;else if $cr3==0 && $cr4==0
;$cr3=y6
;$cr4=z6
;else if $cr5==0 && $cr6==0
;$cr5=y6
;$cr6=z6
;else if $cr7==0 && $cr8==0
;$cr7=y6
;$cr8=z6
;else
;$depthsaved=0
;run=CommandListR3
;endif
;if $depthsaved==1
;run=CommandListR3OK
;endif
;endif

[Constants]
; The Constants command list is used for initialisation on application load
; time and after config reload. We set up the short help message here:
;ResourceHelp = ref ResourceHelpShort
ResourceParams = ref ResourceParamsShort
global $last_window_width
global $last_window_height
global $notification_timeout

[Present]
local $bak_x = x
local $bak_y = y
if ResourceHelp !== null
	x = window_width
	y = window_height
	if window_width != $last_window_width || window_height != $last_window_height
		; Resolution changed, reformat text
		$last_window_width = window_width
		$last_window_height = window_height
		run = CustomShaderFormatText
	endif
	gs-t112 = ResourceHelpCS2GS
	gs-t113 = ResourceHelp
	gs-t114 = ResourceParams
	ps-t114 = ResourceParams
	run = CustomShaderRenderText
	gs-t112 = null
	gs-t113 = null
	gs-t114 = null
	ps-t114 = null

	; Automatically clear the short help prompt a few seconds after
	; launching the game
	;if ResourceHelpShort !== null && time > 10.0
	;	ResourceHelpShort = null
	;	ResourceHelp = null
	;endif
endif
if ResourceNotification !== null
	x = window_width
	y = window_height
	if window_width != $last_window_width || window_height != $last_window_height
		; Resolution changed, reformat text
		$last_window_width = window_width
		$last_window_height = window_height
		run = CustomShaderFormatText
	endif
	gs-t112 = ResourceNotificationCS2GS
	gs-t113 = ResourceNotification
	gs-t114 = ResourceNotificationParams
	ps-t114 = ResourceNotificationParams
	run = CustomShaderRenderTextOriginal
	gs-t112 = null
	gs-t113 = null
	gs-t114 = null
	ps-t114 = null
	if time > $notification_timeout
		ResourceNotification = null
	endif
endif
x = $bak_x
y = $bak_y

;Left range down.
if x7>0
y6=y6-(1*x20)
x7=0
endif

;Left range up.
if y7>0
y6=y6+(1*x20)
y7=0
endif


;Right range down.
if z7>0
z6=z6-(1*x20)
z7=0
endif

;Right range up.
if w7>0
z6=z6+(1*x20)
w7=0
endif

; Custom resources that load the long and short help text from file:
[ResourceHelpFull]
type = buffer
format = R8_UINT
filename = help.txt
[ResourceHelpShort]
type = buffer
format = R8_UINT
filename = help_short.txt

; Using these parameter buffers as a way to pass in constant parameters without
; taking up any of the IniParams slots while still allowing the parameters to
; be customised on a per-message basis.
[ResourceParamsFull]
type = StructuredBuffer
array = 1
data = R32_FLOAT  -0.95 -0.25 0.8 -1   0.5 0.7 0.15 1   0 0 0 0.75   0.01 0.01   1 1   0   1.0
;                 ^^^^Rectangle^^ | ^^^Colour^^^ | Background | ^Border^^ | ^ ^ | ^ | ^-- font scale
;                 x1   y1  x2  y2 | r g   b    a | r g b a    | horz vert |  ^  | ^------ text alignment: 0=left 1=center 2=right
;                   range -1:+1   |              | r g b a    | horz vert |  ^----------- h/v-anchor: 0=none 1=left/top 2=center 3=right/bottom
[ResourceParamsShort]
type = StructuredBuffer
array = 1
data = R32_FLOAT  -0.93 -0.9 +1 -0.9   1 0.7 0.15 1   0 0 0 0.75   0.01 0.01   1 3   1   1.0
;                 ^Bounds Rectangle^ | ^^^Colour^^^ | Background | ^Border^^ | ^ ^ | ^ | ^-- font scale
;                 x1    y1   x2 y2   | r g   b    a | r g b a    | horz vert |  ^  | ^------ text alignment: 0=left 1=center 2=right
;                    range -1:+1     |              |            |           |  ^----------- h/v-anchor: 0=none 1=left/top 2=center 3=right/bottom

; These resources hold the currently displayed help text and parameters. When
; ResourceHelp is null the shader will not be run:
[ResourceHelp]
[ResourceParams]
[ResourceNotification]
[ResourceNotificationParams]
type = StructuredBuffer
array = 1
data = R32_FLOAT  -1.00 -1.0 +1 -1.0   0.25 1 0.25 1   0 0 0 0.75   0.00 0.00   1 3   0   1.0
;                 ^Bounds Rectangle^ | ^^^Colour^^^^ | Background | ^Border^^ | ^ ^ | ^ | ^-- font scale
;                 x1    y1   x2 y2   | r    g b    a | r g b a    | horz vert |  ^  | ^------ text alignment: 0=left 1=center 2=right
;                    range -1:+1     |               |            |           |  ^----------- h/v-anchor: 0=none 1=left/top 2=center 3=right/bottom

[ResourceA1]
type = Buffer
data = "All values for Regex 1 are used."
[ResourceA1OK]
type = Buffer
data = "Depth for Regex 1 saved."
[ResourceA2]
type = Buffer
data = "All values for Regex 2 are used."
[ResourceA2OK]
type = Buffer
data = "Depth for Regex 2 saved."
[ResourceA3]
type = Buffer
data = "All values for Regex 3 are used."
[ResourceA3OK]
type = Buffer
data = "Depth for Regex 3 saved."

[ResourceR1]
type = Buffer
data = "All ranges for Regex 1 are used."
[ResourceR1OK]
type = Buffer
data = "Range for Regex 1 saved."
[ResourceR2]
type = Buffer
data = "All ranges for Regex 2 are used."
[ResourceR2OK]
type = Buffer
data = "Range for Regex 2 saved."
[ResourceR3]
type = Buffer
data = "All ranges for Regex 3 are used."
[ResourceR3OK]
type = Buffer
data = "Range for Regex 3 saved."



[ResourceFont]
; Note that this font has the size of each character embedded in the unused
; space of the final character, which the geometry shader uses to render each
; character the correct width. This font was generated with gen_bm_font.py,
; then converted to DDS (because our PNG loading seems to be broken o_O):
filename = LiberationSans-Bold.dds

[ResourceHelpCS2GS]
; A buffer passed from the formatting compute shader to the geometry shader,
; indicating which shader invocation draws which text at what position.
type = StructuredBuffer
stride = 16
array = 4096
[ResourceNotificationCS2GS]
type = StructuredBuffer
stride = 16
array = 4096

[CustomShaderFormatText]
; The compute shader scans the text and breaks it up into smaller chunks for
; each geometry shader invocation to render (max 64 characters each),
; calculating the position on the screen where each chunk of text is positioned
; wrapping long lines as needed. This is only run when necessary, not every
; frame.
cs = help.hlsl

local $bak_x = x
local $bak_y = y
x = window_width
y = window_height

cs-t100 = ResourceFont
if ResourceHelp !== null
	cs-t113 = ResourceHelp
	cs-t114 = ResourceParams
	clear = ResourceHelpCS2GS
	cs-u0 = ResourceHelpCS2GS
	dispatch = 1, 1, 1
endif
if ResourceNotification !== null
	cs-t113 = ResourceNotification
	cs-t114 = ResourceNotificationParams
	clear = ResourceNotificationCS2GS
	cs-u0 = ResourceNotificationCS2GS
	dispatch = 1, 1, 1
endif

cs-u0 = null
cs-t100 = null
cs-t113 = null
cs-t114 = null
x = $bak_x
y = $bak_y
flags = skip_optimization

[CustomShaderRenderText]
; The vertex shader passes draw indexes to the geometry shader:
vs = help.hlsl
; The geometry shader generates the text for a given draw index:
gs = help.hlsl
; The pixel shader draws the font:
ps = help.hlsl
; Allows us to use SV_Position.z to pack a texcoord, increasing the character
; limit per geometry shader invocation:
depth_clip_enable = false
cull = none
; Enable alpha blending. To change the text colour, edit the pixel shader:
blend = add one inv_src_alpha
; Use points as the primitive from the vertex shader to the geometry shader:
topology = point_list
run = CommandListUnbindAllRenderTargets
o0 = set_viewport no_view_cache bb
; Font is passed into the pixel shader (to draw it) *and* the geometry shader
; (as the character sizes are encoded in the final character of the font):
gs-t100 = ResourceFont
ps-t100 = ResourceFont
post gs-t100 = null
post ps-t100 = null
; Change this number to limit how much text may be drawn:
draw = 4096, 0
flags = skip_optimization

[CustomShaderRenderTextOriginal]
; The vertex shader passes draw indexes to the geometry shader:
vs = help_original.hlsl
; The geometry shader generates the text for a given draw index:
gs = help_original.hlsl
; The pixel shader draws the font:
ps = help_original.hlsl
; Allows us to use SV_Position.z to pack a texcoord, increasing the character
; limit per geometry shader invocation:
depth_clip_enable = false
cull = none
; Enable alpha blending. To change the text colour, edit the pixel shader:
blend = add one inv_src_alpha
; Use points as the primitive from the vertex shader to the geometry shader:
topology = point_list
run = CommandListUnbindAllRenderTargets
o0 = set_viewport no_view_cache bb
; Font is passed into the pixel shader (to draw it) *and* the geometry shader
; (as the character sizes are encoded in the final character of the font):
gs-t100 = ResourceFont
ps-t100 = ResourceFont
post gs-t100 = null
post ps-t100 = null
; Change this number to limit how much text may be drawn:
draw = 4096, 0
flags = skip_optimization