standardFont = "fonts/arial.mvec";
buttonFont = "fonts/expressway_condensed_semibold.mvec";

BlackColor = Color(0,0,0,255);
BlueColor = Color(77,115,178,255);
DarkBlueColor = Color(40,60,120,255);
WhiteColor = Color(255,255,255,255);
MenuButtonFontColor = Color(255,255,255,255);
DarkPurpleColor = Color(153,102,204,255);

StandardButtonGraphics = {
	"buttons/buttonup",
	"buttons/buttondown",
	"buttons/buttonrollover"
};

LongButtonGraphics = {
	"buttons/long_button_up.png",
	"buttons/long_button_down.png",
	"buttons/long_button_over.png"
};

CheckboxButtonGraphics = {
	"buttons/checkup",
	"buttons/checkdown",
	"buttons/checkover",
	"buttons/checkdownover"
};

MenuButtonGraphics = {
	"buttons/menu_button_up",
	"buttons/menu_button_down",
	"buttons/menu_button_over",
	"buttons/menu_button_over"
};

StandardButtonFont = {
  buttonFont,
  21,
  Color(90,90,90,255)
};

MenuButtonFont = {
  buttonFont,
  22,
  MenuButtonFontColor
};

DialogTitleFont = {
  buttonFont,
  24,
  WhiteColor
};
DialogTitleShadowFont = {
  buttonFont,
  24,
  DarkPurpleColor
};

DialogBodyFont = {
  buttonFont,
  21,
  Color(150,150,150,255)
};

ProfileButtonFont = {
  "fonts/agilohandwriting.mvec",
  34,
  Color(153,102,204,255)
};

DefaultStyle = {
	font=DialogBodyFont
};

DialogTitleText = {
	parent=DefaultStyle,
	font = DialogTitleFont,
	flags = kVAlignCenter + kHAlignCenter,
	x=kCenter,y=12,w=kMax-50,h=30
};
DialogTitleShadowText = {
	parent=DefaultStyle,
	font = DialogTitleShadowFont,
	flags = kVAlignCenter + kHAlignCenter,
	x=kCenter-1,y=13,w=kMax-50,h=30
};

DialogBodyText = {
	parent=DefaultStyle,
	font = DialogBodyFont,
	flags = kVAlignCenter + kHAlignCenter,
	x=kCenter,y=46,w=kMax-50,h=kMax-80
};

SliderStyle =
{
	parent=DefaultStyle,
	railtop = "slider/sliderrailtop",
	railmid = "slider/sliderrailmid",
	railbot = "slider/sliderrailbot",
	sliderimage = "slider/sliderknob",
	sliderrollimage = "slider/sliderknobover",

	yoffset = -1, -- scoot the slider down by one pixel to center it.
};

kDefaultButtonSound="audio/sfx/clickbutton.ogg";
kDefaultButtonRollOverSound="audio/sfx/hoverbutton.ogg";
kButtonConfirmSound="audio/sfx/confirm.ogg";

MenuButtonStyle = {
	parent = DefaultStyle,
	font = MenuButtonFont,
	sound = kDefaultButtonSound,
	rolloversound = kDefaultButtonRollOverSound,
	graphics = {
		"images/main/menubutton_up.png",
		"images/main/menubutton_down.png",
		"images/main/menubutton_over.png"
	},
	w=169, h=40
};
ClickToChangePlayerStyle = {
	parent = DefaultStyle,
	font = MenuButtonFont,
	sound = kDefaultButtonSound,
	rolloversound = kDefaultButtonRollOverSound,
	graphics = {}
};

ButtonStyle = {
	parent = DefaultStyle,
	font = StandardButtonFont,
	sound = kDefaultButtonSound,
	rolloversound = kDefaultButtonRollOverSound,
	type= kPush,
	graphics = StandardButtonGraphics,
};

MainMenuButtonStyle = {
	parent = DefaultStyle,
	font = StandardButtonFont,
	sound = kDefaultButtonSound,
	rolloversound = kDefaultButtonRollOverSound,
	type= kPush,
	graphics = {
		"buttons/button_mainup",
		"buttons/button_maindown",
		"buttons/button_mainover"
	}
};

HelpButtonStyle = {
	parent = DefaultStyle,
	font = StandardButtonFont,
	sound = kDefaultButtonSound,
	rolloversound = kDefaultButtonRollOverSound,
	type= kPush,
	graphics = {
		"buttons/button_helpup",
		"buttons/button_helpdown",
		"buttons/button_helpover"
	}
};

LongButtonStyle = {
	parent = ButtonStyle,
	graphics = LongButtonGraphics
};

CheckboxButtonStyle = {
	parent = DefaultStyle,
	font = DialogBodyFont,
	type = kToggle,
	sound = kDefaultButtonSound,
    rolloversound = kDefaultButtonRollOverSound,
	graphics = CheckboxButtonGraphics,
	tx=28,
};



Match3_MenuButtonStyle = {
	parent = DefaultStyle,
	font = StandardButtonFont,
	type = kToggle,
	sound = kDefaultButtonSound,
    rolloversound = kDefaultButtonRollOverSound,
	graphics = MenuButtonGraphics,
	tx=0,
};

ProfileButtonStyle = {
	parent = DefaultStyle,
	font = StandardButtonFont,
	sound = kDefaultButtonSound,
	rolloversound = kDefaultButtonRollOverSound,
	type= kPush,
	graphics = {
		"images/main/button_profile_up",
		"images/main/button_profile_down",
		"images/main/button_profile_over"
	}
};


SetDefaultStyle(DefaultStyle);

-- Create a TButton with a label
--
-- We're overriding the default "Button" here with
-- some custom behavior. Specifically, we're layering
-- a Text{} object on top of every button, and it's placed
-- on all layers (up, down, roll-over).
function Button( button )
	return function()
		-- Grab the label from the button or current style
		if (GetTag(button,"label")) then

			-- Look for text dimensions
			local tx = GetTag(button,"tx");
			local ty = GetTag(button,"ty");
			local tw = GetTag(button,"tw");
			local th = GetTag(button,"th");

			-- Set defaults
			if (not tx) then
				tx = 0;
			end
			if (not ty) then
				ty = 0;
			end
			if (not tw) then
				tw=kMax ;
			end
			if (not th) then
				th=kMax ;
			end

-- 4.0.15 -- Begin new hotkey support
			-- Get the label
			local label = GetTag(button,"label");
			local hotkey = GetTag(button,"hotkey");

			label,labelkey = StripKeyFromLabel( GetString(label) );

			-- If no hotkey was specified explicitly, then
			-- use the translated key.
			if not hotkey then
				-- change our local
				hotkey = labelkey
			end;

			RegisterHotkey( hotkey, GetTag(button,"name") );
-- 4.0.15 -- End new hotkey support (more below!)

			local defflags = kPushButtonAlignment ;
			if (GetTag(button,"type")==kToggle) then
				defflags = kToggleButtonAlignment ;
			elseif (GetTag(button,"type")==kRadio) then
				defflags = kRadioButtonAlignment ;
			end

			local textfactory = GetTag(button,"textfactory");
			if (not textfactory) then
				textfactory = "_text"
			end
			table.insert(button,
				SelectLayer( kAllLayers )
			);
			-- Grow our window to encompass any children we've added
			-- already.
			table.insert(button,
				FitToChildren()
			);

			table.insert(button,
				AppendStyle{ font=button.font; flags=button.flags; }
			);

			table.insert(button,
				Text
				{
-- 4.0.15 -- Begin new hotkey support
					label="#"..TagHotKey( hotkey, label ),
-- 4.0.15 -- End new hotkey support
					x=tx, y=ty, w=tw, h=th,
					name='label',
					defflags =defflags
				}
			)
		end

		-- Type name of window to create; in our case, "Button".
		-- If you want to create a derived button type, you can do that here.
		button.typename='Button';
		DoWindow( button )
	end
end

-- Create several bits of text that combine to make a blended shadow
function ColorShadowText( x,y,size, label, color, fontPath )

	return Group(
		{
		-- Add these traits to the current style
			AppendStyle{ x=x, y=y, w=kMax, h=kMax, label=label },
			AppendStyle{ font = { fontPath, size, Color(0,0,0,40)} },
			Text{ y=y+4 },
			AppendStyle{ font = { fontPath, size, Color(0,0,0,255)} },
			Text{ y=y+2 },
			AppendStyle{ font = { fontPath, size, color } } ,
			Text{},
		}
	)
end

kMenuButtonFontSize = 44;

function MenuButtonLabel( label, color, colorHighlight, fontsize, fontX, fontY, omitButtonImage )

	if not color then
		color =Color(255,255,255,255);	-- the default colors
		colorHighlight=Color(192,207,255,255)
	end
	if not fontsize then
		fontsize = kMenuButtonFontSize;
	end
	if not fontX then
		fontX = 5;
	end
	if not fontY then
		fontY = 4;
	end
	
	imageUp = "images/main/menubutton_up";
	imageDown = "images/main/menubutton_down";
	imageOver = "images/main/menubutton_over";
	if omitButtonImage then
		imageUp = "";
		imageDown = "";
		imageOver = "";
	end

	return Group{
		--[[
		Bitmap
		{
			image="backgrounds/bar",
			x=0,y=0,scale=1,
		},
		--]]
		SelectLayer(0),
		ColorShadowText(fontX,fontY,fontsize, label, color, buttonFont ),
		SelectLayer(1),
		ColorShadowText(fontX,fontY,fontsize, label, colorHighlight, buttonFont ),
		SelectLayer(2),
		ColorShadowText(fontX,fontY,fontsize, label, colorHighlight, buttonFont )
	}

end

-- Create a more limited-use button type here; the label is defined inline
-- with MenuButtonLabel above
function MenuButton( button )
	return function()
		-- Type name of window to create; in our case, "Button".
		-- If you want to create a derived button type, you can do that here.
		button.typename='Button';
		DoWindow( button )
	end
end

kInvisibleButtonName = "invisiblePause";
function AddInvisiblePauseButton(replayButton, diaryButton, townButton, studioButton)
	return Button{
		name=kInvisibleButtonName,
		--[[
		command=
			function()
				DisplayDialog{'scripts/pause.lua', showReplayButton=replayButton, showDiaryButton=diaryButton, showTownButton=townButton, showStudioButton=studioButton};
			end
		--]]
	}
end

function HideInvisiblePauseButton()
	SetWindowVisible(kInvisibleButtonName, false);
end

kIllegalNameChars = "!@#$%^&*()><\\\"\'[]{}|?/+=~`.,;:-";