class QuestProgressWnd extends UICommonAPI;

const QUEST_REQUEST_TIMERID = 1123;
const LISTWIDTH = 250;
const WNDWIDTH = 270;
const MaxHeight = 200;
const MAXLISTCOUNT = 4;
const LIST_HEIGHT = 40;
const DIALOG_TOOLTIP_KEY0 = "\\#$Tooltip0";

enum NotifType 
{
	NOTIF_ACCEPT,
	NOTIF_PROGRESS,
	NOTIF_COMPLETE
};

var private int RecentlyAddedQuestID;
var WindowHandle Me;
var private L2UITimerObject tObject;
var private L2UITimerObject tObjectDeactiveOld;
var private int lastActiveQID;
var RichListCtrlHandle QuestAlarmList_RichList;
var private UIControlDialogAssets teleportDialog;

delegate int OnSortValueCompare(int bitA, int bitB)
{
	if(bitA > bitB)
	{
		return -1;
	}
	return 1;	
}

event OnRegisterEvent()
{
	RegisterEvent(EV_Restart);
	RegisterEvent(EV_PacketID(class'UIPacket'.const.S_EX_QUEST_NOTIFICATION_ALL));
	RegisterEvent(EV_PacketID(class'UIPacket'.const.S_EX_QUEST_NOTIFICATION));	
}

event OnLoad()
{
	SetClosingOnESC();
	Initialize();
	tObject = class'L2UITimer'.static.Inst()._AddTimer(8000, 1);
	tObject._DelegateOnTime = DlegateOnTimeCheckNew;
	tObjectDeactiveOld = class'L2UITimer'.static.Inst()._AddTimer(4000, 1);
	tObjectDeactiveOld._DelegateOnTime = DlegateOnTimeCheckDeactiveOld;	
}

function Initialize()
{
	QuestAlarmList_RichList = GetRichListCtrlHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".QuestAlarmList_RichList");
	QuestAlarmList_RichList.SetSelectedSelTooltip(false);
	QuestAlarmList_RichList.SetAppearTooltipAtMouseX(true);
	QuestAlarmList_RichList.SetUseStripeBackTexture(false);
	teleportDialog = class'UIControlDialogAssets'.static.InitScript(GetWindowHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".UIControlDialogAsset"));
	teleportDialog.NeedItemRichListCtrl.SetColumnWidth(0, MaxHeight);
	teleportDialog.m_hOwnerWnd.ClearAnchor();
	teleportDialog.Hide();	
}

event OnEvent(int a_EventID, string a_Param)
{
	switch(a_EventID)
	{
		case EV_Restart:
			tObject._Stop();
			tObjectDeactiveOld._Stop();
			Me.KillTimer(QUEST_REQUEST_TIMERID);
			RecentlyAddedQuestID = 0;
			break;
		case EV_PacketID(class'UIPacket'.const.S_EX_QUEST_NOTIFICATION_ALL):
			RT_S_EX_QUEST_NOTIFICATION_ALL();
			break;
		case EV_PacketID(class'UIPacket'.const.S_EX_QUEST_NOTIFICATION):
			RT_S_EX_QUEST_NOTIFICATION();
			break;
	}	
}

event OnTick()
{
	m_hOwnerWnd.DisableTick();
	RQ_C_EX_Teleport_UI();	
}

event OnClickButton(string Name)
{
	switch(Name)
	{
		case "btnClose":
			_Hide();
			SetINIBool(m_hOwnerWnd.m_WindowNameWithFullPath, "v", false, "windowsInfo.ini");
			break;
	}	
}

event OnHide()
{
	teleportDialog.Hide();
	ReLoadOnTeleportShowHide();	
}

event OnReceivedCloseUI()
{
	if(teleportDialog.m_hOwnerWnd.IsShowWindow())
	{
		teleportDialog.Hide();
		ReLoadOnTeleportShowHide();		
	}
	else
	{
		SetINIBool(m_hOwnerWnd.m_WindowNameWithFullPath, "v", false, "windowsInfo.ini");
		_Hide();
	}
}

event OnShow()
{
	TeleportDialogModeOnOff();	
}

event OnRClickListCtrlRecord(string ListCtrlID)
{
	local int Index;

	Index = QuestAlarmList_RichList.GetSelectedIndex();
	class'QuestWnd'.static.Inst()._SetSelectQuest(GetQuestIDAtIndex(Index));
	QuestAlarmList_RichList.SetSelectedIndex(-1, false);
	class'QuestWnd'.static.Inst().m_hOwnerWnd.SetFocus();	
}

event OnClickListCtrlRecord(string ListCtrlID)
{
	local RichListCtrlRowData rowData;
	local int Index;

	Index = QuestAlarmList_RichList.GetSelectedIndex();
	QuestAlarmList_RichList.GetRec(Index, rowData);
	if(rowData.cellDataList[0].nReserved1 == 1)
	{
		class'QuestDialogWnd'.static.Inst()._ShowCompleteDialog(GetQuestIDAtIndex(Index), true);		
	}
	else
	{
		ChkTeleport(GetQuestIDAtIndex(Index));
	}
	QuestAlarmList_RichList.SetSelectedIndex(-1, false);	
}

event OnDBClickListCtrlRecord(string ListCtrlID)
{
	QuestAlarmList_RichList.SetSelectedIndex(-1, false);	
}

event OnEnterState(name a_CurrentStateName)
{
	if(QuestAlarmList_RichList.GetRecordCount() == 0)
	{
		return;
	}
	if(IsVisible())
	{
		m_hOwnerWnd.ShowWindow();		
	}
	else
	{
		m_hOwnerWnd.HideWindow();
	}	
}

function externalDelayTimerRequestAddExpandQuest(int nRecentlyAddedQuestID)
{
	RecentlyAddedQuestID = nRecentlyAddedQuestID;
	if(RecentlyAddedQuestID > 0)
	{
		Me.KillTimer(QUEST_REQUEST_TIMERID);
		Me.SetTimer(QUEST_REQUEST_TIMERID, 1000);
	}
}

function _Show(optional bool bSetFocus)
{
	local bool isFocus;

	if(! IsShowCondition())
	{
		return;
	}
	isFocus = ! m_hOwnerWnd.IsShowWindow() || bSetFocus;
	reSizeWindow();
	SetINIBool(m_hOwnerWnd.m_WindowNameWithFullPath, "v", true, "windowsInfo.ini");
	m_hOwnerWnd.ShowWindow();
	if(isFocus)
	{
		m_hOwnerWnd.SetFocus();
	}	
}

function _Hide()
{
	m_hOwnerWnd.HideWindow();	
}

private function MoveRecord(int fromIndex, int toIndex)
{
	local RichListCtrlRowData rowData;

	if(fromIndex == toIndex)
	{
		return;
	}
	QuestAlarmList_RichList.GetRec(fromIndex, rowData);
	if(fromIndex < toIndex)
	{
		InsertRecord(rowData, toIndex);
		QuestAlarmList_RichList.DeleteRecord(fromIndex);		
	}
	else
	{
		QuestAlarmList_RichList.DeleteRecord(fromIndex);
		InsertRecord(rowData, toIndex);
	}	
}

private function InsertRecord(RichListCtrlRowData rowDataNew, int Index)
{
	local int i, lastIndex;
	local RichListCtrlRowData rowData;

	if(QuestAlarmList_RichList.GetRecordCount() == 0)
	{
		QuestAlarmList_RichList.InsertRecord(rowDataNew);		
	}
	else
	{
		lastIndex = QuestAlarmList_RichList.GetRecordCount() - 1;
		QuestAlarmList_RichList.GetRec(lastIndex, rowData);
		QuestAlarmList_RichList.InsertRecord(rowData);

		for(i = lastIndex; i > Index; i--)
		{
			QuestAlarmList_RichList.GetRec(i - 1, rowData);
			QuestAlarmList_RichList.ModifyRecord(i, rowData);
		}
		QuestAlarmList_RichList.ModifyRecord(Index, rowDataNew);
	}	
}

private function string GetQuestName(int qid)
{
	local NQuestUIData questUIData;

	if(! API_GetNQuestData(qid, questUIData))
	{
		return "";
	}
	return questUIData.Name;	
}

private function bool MakeRowData(int qID, int nCount, bool IsActive, out RichListCtrlRowData o_rowData, out int isComplete)
{
	local NQuestUIData questUIData;
	local RichListCtrlRowData rowData;
	local Color typeColor;
	local int textW, textH;
	local array<string> tooltipStrings;
	local NQuestDialogUIData questDialogUIData;
	local int i;

	if(! API_GetNQuestData(qID, questUIData))
	{
		return false;
	}
	rowData.cellDataList.Length = 1;
	if(questUIData.Goal.Num <= nCount)
	{
		isComplete = 1;		
	}
	else
	{
		isComplete = 0;
	}
	rowData.nReserved1 = qID;
	rowData.nReserved2 = nCount;
	rowData.cellDataList[0].nReserved1 = isComplete;
	rowData.cellDataList[0].nReserved2 = int(IsActive);
	if(isComplete == 1)
	{
		typeColor = GetColor(255, 221, 102, 255);		
	}
	else
	{
		if(IsActive)
		{
			typeColor = GetColor(221, 221, 221, 255);			
		}
		else
		{
			typeColor = GetColor(120, 120, 120, 255);
		}
	}
	addRichListCtrlTexture(rowData.cellDataList[0].drawitems, "L2UI_NewTex.QuestWnd.AlarmListBg", 235, 40, 0, -40);
	addRichListCtrlString(rowData.cellDataList[0].drawitems, "", GetColor(0, 0, 0, 0), true);
	addRichListCtrlTexture(rowData.cellDataList[0].drawitems, GetTypeIcon(qID), 14, 14, 2, 5);
	AddEllipsisString(rowData.cellDataList[0].drawitems, questUIData.Name, 190, GetColor(170, 153, 119, 255), false, true, 20, 0);
	if(isComplete == 0 && questUIData.TeleportID > 0)
	{
		addRichListCtrlString(rowData.cellDataList[0].drawitems, "", GetColor(0, 0, 0, 0), true);
		addRichListCtrlTexture(rowData.cellDataList[0].drawitems, "L2UI_CT1.Minimap.TelIcon_16", 16, 16, 193, -15);
		ValidateTeleportInfo();
	}
	if(questUIData.Goal.Num > 1)
	{
		GetTextSizeDefault(string(nCount) $ "/" $ string(questUIData.Goal.Num), textW, textH);
		addRichListCtrlString(rowData.cellDataList[0].drawitems, string(nCount) $ "/" $ string(questUIData.Goal.Num), typeColor, true, 0, 0);
		AddEllipsisString(rowData.cellDataList[0].drawitems, questUIData.Goal.Name, (LISTWIDTH - LIST_HEIGHT) - textW, typeColor, false, true, 2, 0);		
	}
	else
	{
		AddEllipsisString(rowData.cellDataList[0].drawitems, questUIData.Goal.Name, LISTWIDTH - LIST_HEIGHT, typeColor, true, true, 2, 2);
	}
	if(teleportDialog.m_hOwnerWnd.IsShowWindow() && teleportDialog.nDialogID == qID)
	{
		rowData.sOverlayTex = "L2UI_NewTex.QuestWnd.ListBg_Teleoprt";
		rowData.OverlayTexU = 232;
		rowData.OverlayTexV = LIST_HEIGHT;		
	}
	else
	{
		rowData.sOverlayTex = "";
	}
	API_GetNQuestDialogData(qID, questDialogUIData);
	GetStrings(DIALOG_TOOLTIP_KEY0, questDialogUIData.QuestInfo, tooltipStrings);
	if(tooltipStrings.Length > 0)
	{
		rowData.szReserved = tooltipStrings[0];

		for(i = 1; i < tooltipStrings.Length; i++)
		{
			rowData.szReserved = rowData.szReserved $ "\\n" $ tooltipStrings[i];
		}
	}
	o_rowData = rowData;
	return true;	
}

private function ValidateTeleportInfo()
{
	m_hOwnerWnd.EnableTick();
}

private function string GetTypeIcon(int qID)
{
	if(qID < class'QuestDialogWnd'.const.QUEST_CATEGORY_SUB)
	{
		return "L2UI_NewTex.QuestWnd.QIcon_Main";
	}
	if(qID < class'QuestDialogWnd'.const.QUEST_CATEGORY_SPECIAL)
	{
		return "L2UI_NewTex.QuestWnd.QIcon_Sub";
	}
	return "L2UI_NewTex.QuestWnd.QIcon_Especial";	
}

private function reSizeWindow()
{
	local int listHeight;

	listHeight = Min(160, QuestAlarmList_RichList.GetRecordCount() * LIST_HEIGHT);
	QuestAlarmList_RichList.ShowScrollBar(LIST_HEIGHT * MAXLISTCOUNT <= listHeight);
	QuestAlarmList_RichList.SetWindowSize(LISTWIDTH, listHeight);
	m_hOwnerWnd.SetWindowSize(WNDWIDTH, Min(MaxHeight, listHeight) + LIST_HEIGHT);	
}

private function Handle_S_EX_QUEST_NOTIFICATION_ALL(array<UIPacket._PkQuestNotif> pkQuestNotifs)
{
	local int i;
	local RichListCtrlRowData rowData;
	local int isComplete;

	QuestAlarmList_RichList.DeleteAllItem();

	for(i = 0; i < pkQuestNotifs.Length; i++)
	{
		if(MakeRowData(pkQuestNotifs[i].nID, pkQuestNotifs[i].nCount, false, rowData, isComplete))
		{
			if(IsMainQuest(pkQuestNotifs[i].nID))
			{
				InsertRecord(rowData, 0);
				// [Explicit Continue]
				continue;
			}
			if(isComplete == 1)
			{
				if(IsMainQuestFirst())
				{
					InsertRecord(rowData, 1);					
				}
				else
				{
					InsertRecord(rowData, 0);
				}
				// [Explicit Continue]
				continue;
			}
			QuestAlarmList_RichList.InsertRecord(rowData);
		}
	}
	if((IsShowCondition()) && IsVisible())
	{
		_Show();		
	}
	else
	{
		_Hide();
	}	
}

private function Handle_S_EX_QUEST_NOTIFICATION(int qID, int nCount, int cNotifType)
{
	local int i, isComplete, toIndex;
	local RichListCtrlRowData rowData;

	switch(cNotifType)
	{
		case 0:
			if(MakeRowData(qID, nCount, false, rowData, isComplete))
			{
				if(IsMainQuest(qID))
				{
					InsertRecord(rowData, 0);					
				}
				else
				{
					InsertRecord(rowData, GetActieLastOrNewFirstRecordIndex());
				}
				class'L2Util'.static.Inst().showGfxScreenMessage(MakeFullSystemMsg(GetSystemMessage(13854), "&quot;" $ GetQuestName(qid) $ "&quot;"));
				_Show();
			}
			break;
		case 1:
			i = GetQuestIndex(qID);
			if(MakeRowData(qID, nCount, true, rowData, isComplete))
			{
				QuestAlarmList_RichList.ModifyRecord(i, rowData);
				if(isComplete == 1)
				{
					if(teleportDialog.nDialogID == qID)
					{
						teleportDialog.Hide();
						ReLoadOnTeleportShowHide();
					}
				}
				if(! IsMainQuest(qID))
				{
					if(isComplete == 1)
					{
						toIndex = GetCompleteLastRecord();						
					}
					else
					{
						toIndex = GetActieLastOrNewFirstRecordIndex();
					}
					MoveRecord(i, toIndex);
				}
				if(isComplete == 0)
				{
					if(lastActiveQID != qID)
					{
						lastActiveQID = qID;
						tObjectDeactiveOld._Reset();
					}
					tObject._Reset();
				}
			}
			break;
		case 2:
			if(teleportDialog.nDialogID == qID)
			{
				teleportDialog.Hide();
				ReLoadOnTeleportShowHide();
			}
			i = GetQuestIndex(qID);
			QuestAlarmList_RichList.DeleteRecord(i);
			break;
	}
	if(IsShowCondition() && IsVisible())
	{
		_Show();
	}
	else
	{
		_Hide();
	}
	if(isComplete == 1)
	{
		class'QuestDialogWnd'.static.Inst()._ShowCompleteDialog(qID);
	}
	if(cNotifType == 0)
	{
		ChkTeleportOnAccept(qID);
	}	
}

private function HandleAlarm(string completedTitle, string acceptedTitle)
{
	if(completedTitle != "")
	{
		class'L2Util'.static.Inst().showGfxScreenMessage(GetSystemMessage(13648));
	}
	if(acceptedTitle != "")
	{
		class'L2Util'.static.Inst().showGfxScreenMessage(GetSystemMessage(13648));
	}	
}

private function int GetFirstCompletedTitle()
{
	local int i;
	local RichListCtrlRowData rowData;

	for(i = 0; i < QuestAlarmList_RichList.GetRecordCount(); i++)
	{
		QuestAlarmList_RichList.GetRec(i, rowData);
		if(rowData.cellDataList[0].nReserved1 == 1)
		{
			return i;
		}
	}
	return -1;	
}

private function ChkTeleportOnAccept(int qID)
{
	local NQuestUIData questUIData;
	local TeleportListAPI.TeleportListData targetTeleport;

	teleportDialog.nDialogID = -1;
	if(! API_GetNQuestData(qID, questUIData))
	{
		return;
	}
	if(questUIData.TeleportID < 1)
	{
		return;
	}
	if(! GetTeleportInfo(qID, targetTeleport))
	{
		return;
	}
	if((API_GetCurrentZoneName()) == targetTeleport.Name)
	{
		return;
	}
	ShowTeleportDialog(qID);
	if(teleportDialog.nDialogID == qID)
	{
		m_hOwnerWnd.ShowWindow();
	}	
}

private function ChkTeleport(int qID)
{
	local NQuestUIData questUIData;

	if(! API_GetNQuestData(qID, questUIData))
	{
		return;
	}
	if(questUIData.TeleportID < 1)
	{
		return;
	}
	ShowTeleportDialog(qID);	
}

private function ShowTeleportDialog(int qID)
{
	local string Desc, teleportName;
	local TeleportListAPI.TeleportListData targetTeleport;
	local INT64 teleportCost;

	if(! GetTeleportInfo(qID, targetTeleport))
	{
		return;
	}
	if(targetTeleport.Level > 0)
	{
		teleportName = "(" $ targetTeleport.Name $ " Lv " $ string(targetTeleport.Level) $ ")";		
	}
	else
	{
		teleportName = "(" $ targetTeleport.Name $ ")";
	}
	GetRichListCtrlHandle(m_hOwnerWnd.m_WindowNameWithFullPath $ ".UIControlDialogAsset.NeedItemWnd.NeedItemRichListCtrl").SetUseHorizontalScrollBar(false);
	if((API_GetCurrentZoneName()) == targetTeleport.Name)
	{
		Desc = htmlSetHtmlStart(htmlAddText(GetSystemString(14434), "", getColorHexString(GTColor().Red)) $ "</br1>" $ htmlAddText(teleportName, ""));
		teleportDialog.SetDialogDesc(Desc, 0, 0, true);		
	}
	else
	{
		Desc = GetSystemMessage(5239) $ "  " $ teleportName;
		teleportDialog.SetDialogDesc(Desc);
	}
	teleportDialog.SetUseNeedItem(true);
	teleportDialog.StartNeedItemList(1);
	teleportCost = class'TeleportWnd'.static.Inst().GetTeleportCost(targetTeleport.Price[0].Amount, targetTeleport.UsableLevel, targetTeleport.UsableTransferDegree);
	if(targetTeleport.Price.Length > 0)
	{
		teleportDialog.AddNeedItemClassID(targetTeleport.Price[0].Id, teleportCost);
	}
	teleportDialog.SetItemNum(1);
	ReloadOnTeleportHide();
	teleportDialog.nDialogID = qID;
	teleportDialog.Show();
	teleportDialog.DelegateOnClickBuy = OnTeleportDialogConfirm;
	teleportDialog.DelegateOnCancel = OnTeleportDialogCancel;
	ReLoadOnTeleportShowHide();	
}

private function TeleportDialogModeOnOff()
{
	local int i;
	local array<WindowHandle> childs;

	m_hOwnerWnd.GetChildWindowList(childs);
	if(IsVisible())
	{
		for(i = 0; i < childs.Length; i++)
		{
			if(teleportDialog.m_hOwnerWnd != childs[i])
			{
				childs[i].ShowWindow();
			}
		}
		teleportDialog.m_hOwnerWnd.MoveC(18, -188);
		reSizeWindow();
	}
	else
	{
		for(i = 0; i < childs.Length; i++)
		{
			if(teleportDialog.m_hOwnerWnd != childs[i])
			{
				childs[i].HideWindow();
			}
		}
		teleportDialog.m_hOwnerWnd.MoveC(18, -158);
		m_hOwnerWnd.SetWindowSize(WNDWIDTH, 30);
	}	
}

private function int GetTeleportID(int qID)
{
	local NQuestUIData questUIData;

	if(! API_GetNQuestData(qID, questUIData))
	{
		return -1;
	}
	return questUIData.TeleportID;	
}

private function bool GetTeleportInfo(int qID, out TeleportListAPI.TeleportListData o_tInfo)
{
	local TeleportListAPI.TeleportListData tInfo;
	local NQuestUIData questUIData;

	if(! API_GetNQuestData(qID, questUIData))
	{
		return false;
	}
	if(questUIData.TeleportID < 1)
	{
		return false;
	}
	tInfo = class'TeleportListAPI'.static.GetFirstTeleportListData();

	while("" != tInfo.Name)
	{
		if(tInfo.Id == questUIData.TeleportID)
		{
			o_tInfo = tInfo;
			return true;
		}
		tInfo = class'TeleportListAPI'.static.GetNextTeleportListData();
	}
	return false;	
}

private function OnTeleportDialogConfirm()
{
	local UserInfo UserInfo;

	teleportDialog.Hide();
	if(GetPlayerInfo(UserInfo) == false)
	{
		return;
	}
	if(UserInfo.nCurHP == 0)
	{
		getInstanceL2Util().showGfxScreenMessage(GetSystemMessage(5243));
		return;
	}
	class'TeleportListAPI'.static.RequestTeleport(GetTeleportID(teleportDialog.nDialogID));
	ReLoadOnTeleportShowHide();
	if(! IsVisible())
	{
		m_hOwnerWnd.HideWindow();
	}	
}

private function OnTeleportDialogCancel()
{
	teleportDialog.Hide();
	ReLoadOnTeleportShowHide();
	if(! IsVisible())
	{
		m_hOwnerWnd.HideWindow();
	}	
}

private function ReLoadOnTeleportShowHide()
{
	local int Index, isCompleted;
	local RichListCtrlRowData rowData;

	Index = GetQuestIndex(teleportDialog.nDialogID);
	QuestAlarmList_RichList.GetRec(Index, rowData);
	if(MakeRowData(int(rowData.nReserved1), int(rowData.nReserved2), rowData.cellDataList[0].nReserved2 == 1, rowData, isCompleted))
	{
		QuestAlarmList_RichList.ModifyRecord(Index, rowData);
	}	
}

private function ReloadOnTeleportHide()
{
	local int Index, isComplete;
	local RichListCtrlRowData rowData;

	if(teleportDialog.nDialogID == -1)
	{
		return;
	}
	Index = GetQuestIndex(teleportDialog.nDialogID);
	QuestAlarmList_RichList.GetRec(Index, rowData);
	teleportDialog.nDialogID = -1;
	if(MakeRowData(int(rowData.nReserved1), int(rowData.nReserved2), rowData.cellDataList[0].nReserved2 == 1, rowData, isComplete))
	{
		QuestAlarmList_RichList.ModifyRecord(Index, rowData);
	}	
}

private function DlegateOnTimeCheckDeactiveOld(int Cnt)
{
	local int i;
	local RichListCtrlRowData rowData;

	for(i = 0; i < QuestAlarmList_RichList.GetRecordCount(); i++)
	{
		QuestAlarmList_RichList.GetRec(i, rowData);
		if(rowData.nReserved1 == lastActiveQID)
		{
			// [Explicit Continue]
			continue;
		}
		if(rowData.cellDataList[0].nReserved2 != 1)
		{
			// [Explicit Continue]
			continue;
		}
		if(MakeRowData(int(rowData.nReserved1), int(rowData.nReserved2), false, rowData, rowData.cellDataList[0].nReserved1))
		{
			QuestAlarmList_RichList.ModifyRecord(i, rowData);
		}
	}	
}

private function DlegateOnTimeCheckNew(int Cnt)
{
	local int Index, isComplete;
	local RichListCtrlRowData rowData;

	Index = GetQuestIndex(lastActiveQID);
	QuestAlarmList_RichList.GetRec(Index, rowData);
	if(MakeRowData(int(rowData.nReserved1), int(rowData.nReserved2), false, rowData, isComplete))
	{
		QuestAlarmList_RichList.ModifyRecord(Index, rowData);
	}
	lastActiveQID = -1;	
}

private function RT_S_EX_QUEST_NOTIFICATION()
{
	local UIPacket._S_EX_QUEST_NOTIFICATION packet;

	if(! class'UIPacket'.static.Decode_S_EX_QUEST_NOTIFICATION(packet))
	{
		return;
	}
	Handle_S_EX_QUEST_NOTIFICATION(packet.nID, packet.nCount, packet.cNotifType);	
}

private function RT_S_EX_QUEST_NOTIFICATION_ALL()
{
	local UIPacket._S_EX_QUEST_NOTIFICATION_ALL packet;

	if(! class'UIPacket'.static.Decode_S_EX_QUEST_NOTIFICATION_ALL(packet))
	{
		return;
	}
	Handle_S_EX_QUEST_NOTIFICATION_ALL(packet.questNotifs);	
}

private function RQ_C_EX_QUEST_NOTIFICATION_ALL()
{
	class'UIPacket'.static.RequestUIPacket(class'UIPacket'.const.C_EX_QUEST_NOTIFICATION_ALL);	
}

private function Rq_C_EX_TELEPORT_UI()
{
	class'UIPacket'.static.RequestUIPacket(class'UIPacket'.const.C_EX_TELEPORT_UI);
}

private function string API_GetCurrentZoneName()
{
	return GetCurrentZoneName();	
}

private function bool API_GetNQuestData(int a_QuestID, out NQuestUIData o_data)
{
	return GetNQuestData(a_QuestID, o_data);	
}

private function bool API_GetNQuestDialogData(int a_QuestID, out NQuestDialogUIData o_data)
{
	return GetNQuestDialogData(a_QuestID, o_data);	
}

private function GetStrings(string keyString, string wordString, out array<string> strings)
{
	local int startIndex, endIndex, keylen;

	startIndex = InStr(wordString, keyString $ "S");
	if(startIndex == -1)
	{
		return;
	}
	endIndex = InStr(wordString, keyString $ "E");
	keylen = Len(keyString) + 1;
	strings[strings.Length] = Mid(wordString, startIndex + keylen, endIndex - (startIndex + keylen));
	GetStrings(keyString, Right(wordString, Len(wordString) - (endIndex + keylen)), strings);	
}

private function bool IsMainQuestFirst()
{
	if(QuestAlarmList_RichList.GetRecordCount() == 0)
	{
		return false;
	}
	return IsMainQuest(GetQuestIDAtIndex(0));	
}

private function bool IsMainQuest(int qID)
{
	return qID < class'QuestDialogWnd'.const.QUEST_CATEGORY_SUB;	
}

private function int GetCompleteLastRecord()
{
	local int i;
	local RichListCtrlRowData rowData;

	if(IsMainQuestFirst())
	{
		i = 1;		
	}
	else
	{
		i = 0;
	}

	for(i = i; i < QuestAlarmList_RichList.GetRecordCount(); i++)
	{
		QuestAlarmList_RichList.GetRec(i, rowData);
		if(rowData.cellDataList[0].nReserved1 == 1)
		{
			// [Explicit Continue]
			continue;
		}
		return i;
	}
	return i;	
}

private function int GetActieLastOrNewFirstRecordIndex()
{
	local int i;
	local RichListCtrlRowData rowData;

	for(i = GetCompleteLastRecord(); i < QuestAlarmList_RichList.GetRecordCount(); i++)
	{
		QuestAlarmList_RichList.GetRec(i, rowData);
		if(rowData.cellDataList[0].nReserved2 == 1)
		{
			// [Explicit Continue]
			continue;
		}
		return i;
	}
	return i;	
}

private function int GetQuestIDAtIndex(int Index)
{
	local RichListCtrlRowData rowData;

	if(QuestAlarmList_RichList.GetRecordCount() <= Index)
	{
		return -1;
	}
	QuestAlarmList_RichList.GetRec(Index, rowData);
	return int(rowData.nReserved1);	
}

private function int GetQuestIndex(int qID)
{
	local int i;
	local RichListCtrlRowData rowData;

	for(i = 0; i < QuestAlarmList_RichList.GetRecordCount(); i++)
	{
		QuestAlarmList_RichList.GetRec(i, rowData);
		if(rowData.nReserved1 == qID)
		{
			return i;
		}
	}
	return -1;	
}

private function bool IsVisible()
{
	local int bValue;

	if(! GetINIBool(m_hOwnerWnd.m_WindowNameWithFullPath, "v", bValue, "windowsInfo.ini"))
	{
		bValue = 1;
	}
	return bValue == 1;	
}

private function bool IsShowCondition()
{
	if(GetGameStateName() == "COLLECTIONSTATE")
	{
		return false;
	}
	if(QuestAlarmList_RichList.GetRecordCount() == 0)
	{
		return false;
	}
	return true;	
}
