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

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

private alias object.value1 : object.pressed

// MenuControl aliases
private alias object.value3 : menuControl.currentSelection


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

event ObjectUpdate
	temp0 = screen.xsize
	temp0 -= 62
	temp1 = temp0
	temp1 += 48
	CheckTouchRect(0, 0, screen.xsize, screen.ysize)
	if checkResult > -1
		CheckTouchRect(temp0, 164, temp1, 214)
		if checkResult > -1
			object.pressed = true
		else
			object.pressed = false
		end if
	else
		if object.pressed == true
			object.pressed = false
			if menuControl[+1].currentSelection < 26
				keyPress[0].start = true
			else
#platform: USE_STANDALONE
				keyPress[0].buttonC = true
#endplatform
#platform: USE_ORIGINS
				keyPress[0].buttonA = true
#endplatform
			end if
		end if
	end if
end event


event ObjectDraw
	temp0 = screen.xsize
	temp0 -= 38
	if menuControl[+1].currentSelection < 27 // (Selection 27 is the Sound Test btw)
		if object.pressed == true
			DrawSpriteScreenXY(1, temp0, 194)
		else
			DrawSpriteScreenXY(0, temp0, 194)
		end if
	else
		if object.pressed == true
			DrawSpriteScreenXY(3, temp0, 194)
		else
			DrawSpriteScreenXY(2, temp0, 194)
		end if
	end if
end event


event ObjectStartup
	LoadSpriteSheet("LevelSelect/Icons.gif")

	foreach (TypeName[Menu Button], 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(-20, -10, 40, 20, 97, 1)	// 0 - Blue `GO` button
	SpriteFrame(-20, -10, 40, 20, 97, 43)	// 1 - Blue large right arrow
	SpriteFrame(-20, -10, 40, 20, 97, 22)	// 2 - Red `GO` button
	SpriteFrame(-20, -10, 40, 20, 97, 64)	// 3 - Red large right arrow
end event


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

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("LevelSelect/Icons.gif")
	SpriteFrame(-20, -10, 40, 20, 97, 1) // Blue `GO` button
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
