Add and return a directional pad (DPad) to a default location

The 4 buttons fire events with the corresponding name in names. Items in names should be in order of top, left, down and right. If null, defaults to WASD.

If this method is called, it should be before add_button to avoid overlapping controls.

A maximum of 2 DPad may be added using this method. The first DPad is placed on the left of the screen. The second DPad is on the right and replaces some buttons added by add_button.

Require: names == null or names.length == 4

Property definitions

gamnit $ VirtualGamepad :: add_dpad
	# Add and return a directional pad (`DPad`) to a default location
	#
	# The 4 buttons fire events with the corresponding name in `names`.
	# Items in `names` should be in order of top, left, down and right.
	# If `null`, defaults to WASD.
	#
	# If this method is called, it should be before `add_button` to
	# avoid overlapping controls.
	#
	# A maximum of 2 `DPad` may be added using this method.
	# The first `DPad` is placed on the left of the screen.
	# The second `DPad` is on the right and replaces some buttons
	# added by `add_button`.
	#
	# Require: `names == null or names.length == 4`
	fun add_dpad(names: nullable Array[String]): nullable DPad
	do
		if names == null then names = ["w","a","s","d"]
		assert names.length == 4

		if n_dpads == 0 then
			var dpad = new DPad(app.ui_camera.bottom_left.offset(200.0, 100.0, 0.0), names)
			controls.add dpad
			return dpad
		else if n_dpads == 1 then
			var dpad = new DPad(app.ui_camera.bottom_right.offset(-200.0, 100.0, 0.0), names)
			controls.add dpad
			return dpad
		else
			print_error "Too many DPad ({n_dpads}) in {self}"
			return null
		end
	end
lib/gamnit/virtual_gamepad/virtual_gamepad.nit:89,2--121,4