class UIRichListTest extends UICommonAPI;

var WindowHandle Me;
var ComboBoxHandle typeComboBox;
var RichListCtrlHandle testRichListCtrl;
var ButtonHandle test1Button;
var ButtonHandle test2Button;
var bool toggleB;

function OnRegisterEvent();

function OnLoad()
{
	Initialize();
	Load();	
}

function Initialize()
{
	Me = GetWindowHandle("UIRichListTest");
	typeComboBox = GetComboBoxHandle("UIRichListTest.typeComboBox");
	testRichListCtrl = GetRichListCtrlHandle("UIRichListTest.testRichListCtrl");
	test1Button = GetButtonHandle("UIRichListTest.test1Button");
	test2Button = GetButtonHandle("UIRichListTest.test2Button");	
}

function Load()
{
	typeComboBox.AddStringWithReserved("6", 6);
	typeComboBox.AddStringWithReserved("5", 5);
	typeComboBox.AddStringWithReserved("4", 4);
	typeComboBox.AddStringWithReserved("3", 3);
	typeComboBox.AddStringWithReserved("2", 2);
	typeComboBox.AddStringWithReserved("1", 1);	
}

function OnShow()
{
	testRichListCtrl.DeleteAllItem();
	InsertList("오징어");
	InsertList("문어");
	InsertList("고등어");
	InsertList("오징어");
	InsertList("문어");
	InsertList("고등어");
	InsertList("오징어");
	InsertList("문어");
	InsertList("고등어");
	InsertList("오징어");
	InsertList("문어");
	InsertList("고등어");
	InsertList("오징어");
	InsertList("문어");
	InsertList("고등어");
	InsertList("오징어");
	InsertList("문어");
	InsertList("고등어");
	InsertList("오징어");
	InsertList("5문어");
	InsertList("고등어");
	InsertList("오징어");
	InsertList("문어");
	InsertList("고등어");
	InsertList("오징어");
	InsertList("5문어");
	InsertList("고등어");
	InsertList("오징어");
	InsertList("문어");
	InsertList("고등어");
	InsertList("5오징어");
	InsertList("문어");
	InsertList("고등어");
	InsertList("오징어");
	InsertList("문어");
	InsertList("고등어");
	InsertList("오징어");
	InsertList("문어");
	InsertList("고등어");
	InsertList("오징어");
	InsertList("문어");
	InsertList("고등어");
	InsertList("4오징어");
	InsertList("3문어");
	InsertList("2고등어");	
}

function InsertList(string Title)
{
	local RichListCtrlRowData rowData;

	rowData.cellDataList.Length = 2;
	addRichListCtrlButton(rowData.cellDataList[0].drawitems, "rewardBtn", 4, 12, "L2UI.Control.CheckBox", "L2UI.Control.CheckBox", "L2UI.Control.CheckBox", 16, 16, 16, 16);
	rowData.cellDataList[0].drawitems[rowData.cellDataList[0].drawitems.Length - 1].TooltipDesc = GetSystemString(7529);
	rowData.nReserved1 = 0;
	addRichListCtrlString(rowData.cellDataList[0].drawitems, Title, GTColor().White, false, 5, 2);
	testRichListCtrl.InsertRecord(rowData);	
}

function onRewardBtnClick()
{
	local RichListCtrlRowData rowData;

	Debug("rewardBtn --> " @ string(testRichListCtrl.GetSelectedIndex()));
	testRichListCtrl.GetRec(testRichListCtrl.GetSelectedIndex(), rowData);
	Debug("rowData.nReserved1" @ string(rowData.nReserved1));
	if(rowData.nReserved1 == 0)
	{
		modifyRichListCtrlButton(rowData.cellDataList[0].drawitems, 0, "rewardBtn", 4, 12, "L2UI.Control.CheckBox_checked", "L2UI.Control.CheckBox_checked", "L2UI.Control.CheckBox_checked", 16, 16, 16, 16);
		rowData.nReserved1 = 1;		
	}
	else
	{
		modifyRichListCtrlButton(rowData.cellDataList[0].drawitems, 0, "rewardBtn", 4, 12, "L2UI.Control.CheckBox", "L2UI.Control.CheckBox", "L2UI.Control.CheckBox", 16, 16, 16, 16);
		rowData.nReserved1 = 0;
	}
	testRichListCtrl.ModifyRecord(testRichListCtrl.GetSelectedIndex(), rowData);
	checkBoxSelectCheck();	
}

function OnClickCheckBox(string strID)
{
	local int i;
	local RichListCtrlRowData rowData;

	toggleB = ! toggleB;

	for(i = 0; i < testRichListCtrl.GetRecordCount(); i++)
	{
		testRichListCtrl.GetRec(i, rowData);
		if(GetMeCheckBox("allSelectCheckBox").IsChecked())
		{
			modifyRichListCtrlButton(rowData.cellDataList[0].drawitems, 0, "rewardBtn", 4, 12, "L2UI.Control.CheckBox_checked", "L2UI.Control.CheckBox_checked", "L2UI.Control.CheckBox_checked", 16, 16, 16, 16);
			rowData.nReserved1 = 1;			
		}
		else
		{
			modifyRichListCtrlButton(rowData.cellDataList[0].drawitems, 0, "rewardBtn", 4, 12, "L2UI.Control.CheckBox", "L2UI.Control.CheckBox", "L2UI.Control.CheckBox", 16, 16, 16, 16);
			rowData.nReserved1 = 0;
		}
		testRichListCtrl.ModifyRecord(i, rowData);
	}	
}

function checkBoxSelectCheck()
{
	local int i;
	local RichListCtrlRowData rowData;

	for(i = 0; i < testRichListCtrl.GetRecordCount(); i++)
	{
		testRichListCtrl.GetRec(i, rowData);
		if(rowData.nReserved1 == 0)
		{
			GetMeCheckBox("allSelectCheckBox").SetCheck(false);
			// [Explicit Break]
			break;
		}
	}	
}

function OnClickCheckBoxPage()
{
	local int i;
	local RichListCtrlRowData rowData;
	local int pageNum, Start, End;

	pageNum = typeComboBox.GetReserved(typeComboBox.GetSelectedNum());
	toggleB = ! toggleB;
	Start = (pageNum - 1) * 8;
	End = pageNum * 8;
	if(End > testRichListCtrl.GetRecordCount())
	{
		End = testRichListCtrl.GetRecordCount();
	}

	for(i = Start; i < End; i++)
	{
		testRichListCtrl.GetRec(i, rowData);
		if(GetMeCheckBox("allSelectCheckBox").IsChecked())
		{
			modifyRichListCtrlButton(rowData.cellDataList[0].drawitems, 0, "rewardBtn", 4, 12, "L2UI.Control.CheckBox_checked", "L2UI.Control.CheckBox_checked", "L2UI.Control.CheckBox_checked", 16, 16, 16, 16);
			rowData.nReserved1 = 1;			
		}
		else
		{
			modifyRichListCtrlButton(rowData.cellDataList[0].drawitems, 0, "rewardBtn", 4, 12, "L2UI.Control.CheckBox", "L2UI.Control.CheckBox", "L2UI.Control.CheckBox", 16, 16, 16, 16);
			rowData.nReserved1 = 0;
		}
		testRichListCtrl.ModifyRecord(i, rowData);
	}	
}

function OnClickButton(string Name)
{
	Debug("Name" @ Name);
	switch(Name)
	{
		case "test1Button":
			Ontest1ButtonClick();
			break;
		case "test2Button":
			Ontest2ButtonClick();
			break;
		case "rewardBtn":
			onRewardBtnClick();
			break;
		default:
			break;
	}	
}

function Ontest1ButtonClick()
{
	local int i, sum;
	local RichListCtrlRowData rowData;

	for(i = 0; i < testRichListCtrl.GetRecordCount(); i++)
	{
		testRichListCtrl.GetRec(i, rowData);
		if(rowData.nReserved1 > 0)
		{
			++ sum;
		}
	}
	Debug("checkbox Sum" $ string(sum));	
}

function Ontest2ButtonClick()
{
	Debug(".typeComboBox.GetReserved:" @ string(typeComboBox.GetReserved(typeComboBox.GetSelectedNum())));	
}
