#include scener
#include sound
#include input
#include stdlib
#include kds3

export ON_CREATE;
export ON_COMMAND;

LINK* buttonOk;
LINK* buttonCancel;

void SetHandler(LINK* pObj)
{
	message mes;
	mes.message_id = EM_COMMAND;
	mes.p_target = pObj;
	mes.lparam = EMC_SETHANDLER;
	mes.rparam = self;
	scene.PostMessage(mes);
}

// initialize script
void ON_CREATE()
{
	buttonOk = scene.FindObjectByName("buttonOk");
	SetHandler(buttonOk);
	
	buttonCancel = scene.FindObjectByName("buttonCancel");
	SetHandler(buttonCancel);

	WriteLog("Create Options!");
	
	LoadOptions();
}

void ON_COMMAND(int lparam, int rparam)
{
	if (lparam == EMC_BUTTONCLICK)
	{
		if (rparam == buttonOk)
		{
			SaveOptions();
			WriteLog("Ok");
			scene.Delete();
			scene.Load("GUI_MainMenu.xml");
		}
		if (rparam == buttonCancel)
		{
			WriteLog("Cancel");
			scene.Delete();
			scene.Load("GUI_MainMenu.xml");
		}
	}
}
