// ----------------------------------
// RSDK Project: Sonic 1
// Script Description: Menu DPad Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

// ========================
// Aliases
// ========================

private alias object.value1 : object.pressedLR


// ========================
// Events
// ========================

event ObjectUpdate
#platform: MOBILE
	temp0 = screen.xcenter
	temp0 -= 56
	CheckTouchRect(0, 96, temp0, screen.ysize)
	if checkResult > -1
		arrayPos0 = checkResult
		temp0 = touchscreen[arrayPos0].xpos
		temp0 -= 64
		temp1 = touchscreen[arrayPos0].ypos
		temp1 -= 194
		ATan2(temp2, temp0, temp1)
		temp2 += 0x20
		temp2 &= 0xFF
		temp2 >>= 6
		switch temp2
		case 0
			keyDown[0].right = true
			if object.pressedLR == false
				keyPress[0].right |= keyDown[0].right
			end if
			object.pressedLR = keyDown[0].right
			break

		case 1
			keyDown[0].down = true
			break

		case 2
			keyDown[0].left = true
			if object.pressedLR == false
				keyPress[0].left |= keyDown[0].left
			end if
			object.pressedLR = keyDown[0].left
			break

		case 3
			keyDown[0].up = true
			break
			
		end switch
	else
		object.pressedLR = false
	end if
#endplatform
end event


event ObjectDraw
	if keyDown[0].up == true
		DrawSpriteScreenXY(1, 64, 194)
	else
		DrawSpriteScreenXY(0, 64, 194)
	end if

	if keyDown[0].down == true
		DrawSpriteScreenXY(3, 64, 194)
	else
		DrawSpriteScreenXY(2, 64, 194)
	end if

	if keyDown[0].left == true
		DrawSpriteScreenXY(5, 64, 194)
	else
		DrawSpriteScreenXY(4, 64, 194)
	end if

	if keyDown[0].right == true
		DrawSpriteScreenXY(7, 64, 194)
	else
		DrawSpriteScreenXY(6, 64, 194)
	end if
end event


event ObjectStartup
	LoadSpriteSheet("LevelSelect/Icons.gif")
	
	foreach (TypeName[Menu DPad], arrayPos0, ALL_ENTITIES)
		switch engine.deviceType
		case STANDARD
			// If on a standard platform, then touch controls aren't needed
			object[arrayPos0].type = TypeName[Blank Object]
			break

		case MOBILE
			object[arrayPos0].priority = PRIORITY_ACTIVE
			break
			
		end switch
	next

	SpriteFrame(-10, -30, 20, 20, 138, 1)	// 0 - Blue up arrow
	SpriteFrame(-10, -30, 20, 20, 138, 43)	// 1 - Red up arrow
	SpriteFrame(-10, 10, 20, 20, 159, 1)	// 2 - Blue down arrow
	SpriteFrame(-10, 10, 20, 20, 159, 43)	// 3 - Red down arrow
	SpriteFrame(-30, -10, 20, 20, 138, 22)	// 4 - Blue left arrow
	SpriteFrame(-30, -10, 20, 20, 138, 64)	// 5 - Red left arrow
	SpriteFrame(10, -10, 20, 20, 159, 22)	// 6 - Blue right arrow
	SpriteFrame(10, -10, 20, 20, 159, 64)	// 7 - Red right arrow
end event


// ========================
// Editor Events
// ========================

event RSDKDraw
	DrawSprite(0)
	DrawSprite(2)
	DrawSprite(4)
	DrawSprite(6)
end event


event RSDKLoad
	LoadSpriteSheet("LevelSelect/Icons.gif")
	SpriteFrame(-10, -30, 20, 20, 138, 1)	// 0 - Blue up arrow
	SpriteFrame(-10, -30, 20, 20, 138, 43)	// 1 - Red up arrow
	SpriteFrame(-10, 10, 20, 20, 159, 1)	// 2 - Blue down arrow
	SpriteFrame(-10, 10, 20, 20, 159, 43)	// 3 - Red down arrow
	SpriteFrame(-30, -10, 20, 20, 138, 22)	// 4 - Blue left arrow
	SpriteFrame(-30, -10, 20, 20, 138, 64)	// 5 - Red left arrow
	SpriteFrame(10, -10, 20, 20, 159, 22)	// 6 - Blue right arrow
	SpriteFrame(10, -10, 20, 20, 159, 64)	// 7 - Red right arrow
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
