PlayAppButton.prototype = Object.create(BasicButton.prototype);
PlayAppButton.constructor = PlayAppButton;

function PlayAppButton(x, y) {
	this.appData = null;

	var setting = new ButtonSetting(x, y, PlayAppButton.WIDTH, PlayAppButton.HEIGHT);
	setting.setStrokeWidth(0);
	setting.setRound(30);
	// setting.setFont("Nanum Brush Script");
	setting.setFont("Nanum Gothic");
	setting.setFontSize(20);
	setting.setShortcutFont("Nanum Gothic");
	setting.setShortcutFontSize(18);
	setting.fontStyle.boundsAlignH = "center";	// left, center. right
	setting.fontStyle.boundsAlignV = "middle";	// top, middle, bottom
	setting.setStrokeColor(
		PlayAppButton.STROKE_COLOR_OUT_HEX,
		PlayAppButton.STROKE_COLOR_OVER_HEX,
		PlayAppButton.STROKE_COLOR_DOWN_HEX,
		PlayAppButton.STROKE_COLOR_DISABLED_HEX
	);
	setting.setButtonColor(
		PlayAppButton.BUTTON_COLOR_OUT_HEX,
		PlayAppButton.BUTTON_COLOR_OVER_HEX,
		PlayAppButton.BUTTON_COLOR_DOWN_HEX,
		PlayAppButton.BUTTON_COLOR_DISABLED_HEX
	);
	setting.setIconColor(
		PlayAppButton.ICON_COLOR_OUT_HEX,
		PlayAppButton.ICON_COLOR_OVER_HEX,
		PlayAppButton.ICON_COLOR_DOWN_HEX,
		PlayAppButton.ICON_COLOR_DISABLED_HEX
	);
	setting.setTextColor(
		PlayAppButton.TEXT_COLOR_OUT_STRING,
		PlayAppButton.TEXT_COLOR_OVER_STRING,
		PlayAppButton.TEXT_COLOR_DOWN_STRING,
		PlayAppButton.TEXT_COLOR_DISABLED_STRING
	);

	BasicButton.call(this, setting, this.clickEvent);

	// this.setMainText("");
	// this.addIcon("tile_choco");
	// this.setIconSize(40);
	// this.setShortcutText("[단축키]");

	this.setShorcutTextBounds();

	this.addIcon("home");
	this.setIconSize(80);
}

PlayAppButton.prototype.setShorcutTextBounds = function() {
	var offsetX = 10;
	var offsetY = -20;
	var textWidth = PlayAppButton.WIDTH - offsetX * 2;

	this.shortcutText.font = this.setting.font;
	this.shortcutText.fontSize = this.setting.fontSize;

	this.shortcutText.style.align = "center";
	this.shortcutText.style.boundsAlignH = "center";
	this.shortcutText.style.boundsAlignV = "top"
	this.shortcutText.style.wordWrap = true;
	this.shortcutText.style.wordWrapWidth = textWidth;
	this.shortcutText.style.fill = "white";
	// this.shortcutText.style.backgroundColor = "black";

	this.shortcutText.anchor.set(0, 0);
	this.shortcutText.x = offsetX;
	this.shortcutText.setTextBounds(0, offsetY, textWidth, 200);
}

PlayAppButton.prototype.setInputEnabled = function(isEnabled) {
	this.strokeSprite.inputEnabled = isEnabled;
	this.buttonSprite.inputEnabled = isEnabled;

	if(isEnabled === true)
		this.mouseOut();
	else
		this.buttonDisabled();
}

PlayAppButton.prototype.setActive = function(flag) {
	this.setInputEnabled(flag);

	if(flag) {
		this.buttonSprite.alpha = 1;
		this.strokeSprite.alpha = 1;
	} else {
		this.buttonSprite.alpha = 0;
		this.strokeSprite.alpha = 0;
	}
}

PlayAppButton.prototype.showEmptyDisabled = function() {
	this.setInputEnabled(false);

	this.buttonSprite.alpha = 0;
	this.strokeSprite.alpha = 1;
	this.strokeSprite.tint = MainColor.SADDLE_BROWN_HEX;
}

PlayAppButton.prototype.getIconName = function(appID) {
	switch(appID) {
		case 50:
		case 51:
		return "mole";

		case 52:
		case 53:
		return "alienship";

		case 101:
		return "alien";

		case 102:
		return "card";

		case 103:
		return "grill";

		case 104:
		return "spaceship";

		case 105:
		return "chocoball";

		case 106:
		return "timer";

		default:
		return "keyboard";
	}
}

PlayAppButton.prototype.updateAppData = function(appData) {
	this.appData = appData;

	// console.log(this.appData);
	this.iconSprite.loadTexture(this.getIconName(this.appData.appID));
	this.setIconSize(80);
	// this.addIcon(this.appData.appName);
	// this.setMainText(this.appData.koreanName);
	this.setShortcutText(this.appData.koreanName);

	this.iconSprite.y = PlayAppButton.HEIGHT / 2 - 20;
	this.shortcutText.y = PlayAppButton.HEIGHT / 2 + 40;

	this.setInputEnabled(this.appData.activated);
}

PlayAppButton.prototype.clickEvent = function() {
	sessionStorageManager.setPlayingAppID(this.appData.appID);
	sessionStorageManager.setPlayingAppName(this.appData.appName);
	sessionStorageManager.setPlayingAppKoreanName(this.appData.koreanName);

	if(isExperiencePlayerAccount())
		location.href = '../../web/client/ads.html';
	else
		location.href = '../../web/client/start.html';
}

PlayAppButton.loadResources = function() {
	game.load.image('mole',			'../../../resources/image/icon/mole.png');
	game.load.image('alienship',	'../../../resources/image/icon/alienship.png');

	game.load.image('alien',		'../../../resources/image/icon/alien.png');
	game.load.image('card',			'../../../resources/image/icon/card.png');
	game.load.image('grill',		'../../../resources/image/icon/grill.png');
	game.load.image('spaceship',	'../../../resources/image/icon/spaceship.png');
	game.load.image('chocoball',	'../../../resources/image/icon/chocoball.png');
	game.load.image('timer',	'../../../resources/image/icon/timer.png');
}


PlayAppButton.WIDTH		= 150;
PlayAppButton.HEIGHT	= 180;

PlayAppButton.STROKE_COLOR_OUT_HEX			= MainColor.LIGHT_CHOCO_HEX;
PlayAppButton.STROKE_COLOR_OVER_HEX			= MainColor.LIGHT_CHOCO_HEX;
PlayAppButton.STROKE_COLOR_DOWN_HEX			= MainColor.LIGHT_CHOCO_HEX;
PlayAppButton.STROKE_COLOR_DISABLED_HEX		= MainColor.LIGHT_CHOCO_HEX;

PlayAppButton.BUTTON_COLOR_OUT_HEX			= MainColor.DARKER_CHOCO_HEX;
PlayAppButton.BUTTON_COLOR_OVER_HEX			= MainColor.DARK_CHOCO_HEX;
PlayAppButton.BUTTON_COLOR_DOWN_HEX			= MainColor.LIGHTER_CHOCO_HEX;
PlayAppButton.BUTTON_COLOR_DISABLED_HEX		= MainColor.LIGHT_GRAY_HEX;

PlayAppButton.ICON_COLOR_OUT_HEX			= MainColor.WHITE_HEX;
PlayAppButton.ICON_COLOR_OVER_HEX			= MainColor.WHITE_HEX;
PlayAppButton.ICON_COLOR_DOWN_HEX			= MainColor.WHITE_HEX;
PlayAppButton.ICON_COLOR_DISABLED_HEX		= MainColor.LIGHT_GRAY_HEX;

PlayAppButton.TEXT_COLOR_OUT_STRING			= MainColor.LINEN_STRING;
PlayAppButton.TEXT_COLOR_OVER_STRING		= MainColor.LINEN_STRING;
PlayAppButton.TEXT_COLOR_DOWN_STRING		= MainColor.LIGHT_CHOCO_STRING;
PlayAppButton.TEXT_COLOR_DISABLED_STRING	= MainColor.GRAY_STRING;