class QuitReportDrawerMagicLampWnd extends UICommonAPI
	dependson(QuitReportWnd);

var WindowHandle Me;
var RichListCtrlHandle RichListCtrl;
var ButtonHandle CloseBtn;
var QuitReportWnd QuitReportWndScript;

function Initialize()
{
	local string ownerFullPath;

	ownerFullPath = m_hOwnerWnd.m_WindowNameWithFullPath;
	Me = GetWindowHandle(ownerFullPath);
	RichListCtrl = GetRichListCtrlHandle(ownerFullPath $ ".Magiclamp_ListCtrl");
	CloseBtn = GetButtonHandle(ownerFullPath $ ".CloseBtn");
	QuitReportWndScript = QuitReportWnd(GetScript("QuitReportWnd"));
	RichListCtrl.SetTooltipType("");
	RichListCtrl.SetSelectedSelTooltip(false);
	RichListCtrl.SetSelectable(false);	
}

function UpdateMagicLampList()
{
	local RichListCtrlRowData rowData, oldRowData;
	local int Grade, recordCnt;
	local bool needModify;
	local L2Util util;
	local QuitReportWnd.MagicLampGetInfo getInfo;
	local QuitReportWnd.MagicLampExpInfo expInfo;
	local string expStr;
	local Color expStrColor;

	util = L2Util(GetScript("L2Util"));
	getInfo = class'QuitReportWnd'.static.Inst().GetMagicLampGetInfo();
	rowData.cellDataList.Length = 2;
	recordCnt = RichListCtrl.GetRecordCount();

	for(Grade = 0; Grade < class'QuitReportWnd'.const.MAGIC_LAMP_MAX_GRADE; Grade++)
	{
		expInfo = getInfo.expInfos[Grade];
		if(Grade < recordCnt)
		{
			RichListCtrl.GetRec(Grade, oldRowData);
			if((oldRowData.nReserved1 == expInfo.Exp) && oldRowData.nReserved2 == expInfo.Count)
			{
				// [Explicit Continue]
				continue;				
			}
			else
			{
				needModify = true;
			}
		}
		rowData.cellDataList[0].drawitems.Length = 0;
		rowData.cellDataList[1].drawitems.Length = 0;
		rowData.nReserved1 = expInfo.Exp;
		rowData.nReserved2 = expInfo.Count;
		if(expInfo.Exp == 0)
		{
			expStr = string(expInfo.Exp);			
		}
		else
		{
			expStr = ConvertNumToTextNoAdena(string(expInfo.Exp));
		}
		expStrColor = GetExpNumericColor(string(expInfo.Exp));
		AddRichListCtrlItem(rowData.cellDataList[0].drawitems, GetMagicLampItemInfo(Grade), 32, 32, 10);
		addRichListCtrlString(rowData.cellDataList[0].drawitems, GetMagicLampGradeName(Grade), util.ColorGold, false, 6, 2);
		addRichListCtrlString(rowData.cellDataList[0].drawitems, "x" $ MakeCostString(string(expInfo.Count)), util.White, true, 48, 2);
		addRichListCtrlString(rowData.cellDataList[1].drawitems, expStr, expStrColor, false, 10);
		if(needModify == true)
		{
			needModify = false;
			RichListCtrl.ModifyRecord(Grade, rowData);
			// [Explicit Continue]
			continue;
		}
		RichListCtrl.InsertRecord(rowData);
	}
}

function ClearListControls()
{
	RichListCtrl.DeleteAllItem();	
}

function ItemInfo GetMagicLampItemInfo(int Grade)
{
	local string Icon, panel;
	local ItemInfo Info;

	switch(Grade)
	{
		case 0:
			Icon = "icon.r99_soul_stone_i00";
			panel = "icon.panel_star_r3";
			break;
		case 1:
			Icon = "icon.r99_soul_stone_i05";
			panel = "icon.panel_star_r2";
			break;
		case 2:
			Icon = "icon.r99_soul_stone_i02";
			panel = "icon.panel_star_r1";
			break;
		case 3:
			Icon = "icon.r99_soul_stone_i04";
			panel = "icon.panel_2";
			break;
	}
	Info.IconName = Icon;
	Info.IconPanel = panel;
	return Info;	
}

function string GetMagicLampGradeName(int Grade)
{
	switch(Grade)
	{
		case 0:
			return GetSystemString(14471);
		case 1:
			return GetSystemString(14472);
		case 2:
			return GetSystemString(14473);
		case 3:
			return GetSystemString(14474);
	}

	return "";
}

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

function OnShow()
{
	UpdateMagicLampList();	
}

function OnClickButton(string Name)
{
	switch(Name)
	{
		case "CloseBtn":
			OnCloseBtnClick();
			break;
	}	
}

function OnCloseBtnClick()
{
	QuitReportWndScript.SetDrawerMagicLampButtonState(true);
	Me.HideWindow();	
}

function OnReceivedCloseUI()
{
	PlayConsoleSound(IFST_WINDOW_CLOSE);
	GetWindowHandle(getCurrentWindowName(string(self))).HideWindow();	
}
