class ShortcutWnd extends UICommonAPI;

const MAX_ShortcutPerPage = 12;
const MAX_ShortcutPerPage2 = 24;
const MAX_ShortcutPerPage3 = 36;
const MAX_ShortcutPerPage4 = 48;

enum EJoyShortcut
{
	JOYSHORTCUT_Left,
	JOYSHORTCUT_Center,
	JOYSHORTCUT_Right
};

var int MAX_Page;
var int MAX_ShortcutExtend;
var int m_extendBounsSlot;
var WindowHandle Me;
var int CurrentShortcutPage;
var int CurrentShortcutPage2;
var int CurrentShortcutPage3;
var int CurrentShortcutPage4;
var int CurrentShortcutPage5;
var int CurrentShortcutPageExtend;
var bool m_IsLocked;
var bool m_IsVertical;
var bool m_IsJoypad;
var bool m_IsJoypadExpand;
var bool m_IsJoypadOn;
var int m_Expand;
var bool m_IsShortcutExpand;
var string m_ShortcutWndName;
var string m_ShortcutWndExtendName;
var AutoShotItemWnd AutoShotItemWndScript;

function OnRegisterEvent()
{
	RegisterEvent(EV_GameStart);
	RegisterEvent(EV_ShortcutUpdate);
	RegisterEvent(EV_ShortcutPageUpdate);
	RegisterEvent(EV_ShortcutJoypad);
	RegisterEvent(EV_ShortcutClear);
	RegisterEvent(EV_JoypadLButtonDown);
	RegisterEvent(EV_JoypadLButtonUp);
	RegisterEvent(EV_JoypadRButtonDown);
	RegisterEvent(EV_JoypadRButtonUp);
	RegisterEvent(EV_ShortcutCommandSlot);
	RegisterEvent(EV_ShortcutKeyAssignChanged);
	RegisterEvent(EV_SetEnterChatting);
	RegisterEvent(EV_UnSetEnterChatting);
	RegisterEvent(EV_EquipItemTooltipClear);
}

function OnShow()
{
	LoadINIValues();
	if(m_IsLocked)
	{
		Lock();		
	}
	else
	{
		UNLOCK();
	}
	class'UIAPI_WINDOW'.static.HideWindow("ShortcutWnd.ShortcutWndVertical_1");
	class'UIAPI_WINDOW'.static.HideWindow("ShortcutWnd.ShortcutWndHorizontal_1");
	class'UIAPI_WINDOW'.static.HideWindow("ShortcutWnd.ShortcutWndVertical_2");
	class'UIAPI_WINDOW'.static.HideWindow("ShortcutWnd.ShortcutWndHorizontal_2");
	class'UIAPI_WINDOW'.static.HideWindow("ShortcutWnd.ShortcutWndVertical_3");
	class'UIAPI_WINDOW'.static.HideWindow("ShortcutWnd.ShortcutWndHorizontal_3");
	SettingShortCut();
	if(getInstanceUIData().getIsClassicServer())
	{
		GetButtonHandle("ShortcutWnd.ShortcutWndVertical.ReduceButton").HideWindow();
		GetButtonHandle("ShortcutWnd.ShortcutWndHorizontal.ReduceButton").HideWindow();
		GetButtonHandle("ShortcutWnd.ShortcutWndVertical.ExpandButton").ShowWindow();
		GetButtonHandle("ShortcutWnd.ShortcutWndHorizontal.ExpandButton").ShowWindow();
		if(MAX_ShortcutExtend <= m_Expand)
		{
			m_Expand = MAX_ShortcutExtend - 1;
		}
		ExpandByNum(m_Expand);
		if(GetWindowHandle("ShortcutWnd.ShortcutWnd_Extend").IsShowWindow())
		{
			GetWindowHandle("ShortcutWnd.ShortcutWnd_Extend").HideWindow();
		}
	}
	else
	{
		if(MAX_ShortcutExtend <= m_Expand)
		{
			m_Expand = MAX_ShortcutExtend - 1;
		}
		GetButtonHandle("ShortcutWnd.ShortcutWndVertical.ExpandButton").ShowWindow();
		GetButtonHandle("ShortcutWnd.ShortcutWndHorizontal.ExpandButton").ShowWindow();
		ExpandByNum(m_Expand);
		if(m_extendBounsSlot > 0)
		{
			GetWindowHandle("ShortcutWnd.ShortcutWnd_Extend").ShowWindow();
		}
		else
		{
			GetWindowHandle("ShortcutWnd.ShortcutWnd_Extend").HideWindow();
		}
	}
	SetVertical(m_IsVertical);
}

function LoadINIValues()
{
	local int tmpInt;

	GetINIInt("ShortcutWnd", "e", m_Expand, "WindowsInfo.ini");
	GetINIInt("ShortcutWnd", "m", m_extendBounsSlot, "WindowsInfo.ini");
	GetINIBool("ShortcutWnd", "l", tmpInt, "windowsInfo.ini");
	m_IsLocked = GetOptionBool("Game", "IsLockShortcutWnd");
	if(bool(tmpInt))
	{
		OnMaxBtn();		
	}
	else
	{
		OnMinBtn();
	}
	GetINIInt("ShortcutWnd", "v", tmpInt, "WindowsInfo.ini");
	m_IsVertical = bool(tmpInt);
}

function OnLoad()
{
	local bool bMinTooltip;
	local ToolTip script;
	local int minTooltip;

	if(getInstanceUIData().getIsArenaServer())
	{
		return;
	}
	m_ShortcutWndExtendName = "ShortcutWnd_Extend";
	Me = GetWindowHandle("ShortcutWnd");
	AutoShotItemWndScript = AutoShotItemWnd(GetScript("AutoShotItemWnd"));
	LoadINIValues();
	InitShortPageNum();
	GetINIBool("ShortcutWnd", "l", minTooltip, "windowsInfo.ini");
	bMinTooltip = bool(minTooltip);
	script = ToolTip(GetScript("Tooltip"));
	script.setBoolSelect(! bMinTooltip);
	if(bMinTooltip)
	{
		HideWindow("ShortcutWnd.ShortcutWndHorizontal.TooltipMaxBtn");
		ShowWindow("ShortcutWnd.ShortcutWndHorizontal.TooltipMinBtn");
		HideWindow("ShortcutWnd.ShortcutWndVertical.TooltipMaxBtn");
		ShowWindow("ShortcutWnd.ShortcutWndVertical.TooltipMinBtn");		
	}
	else
	{
		ShowWindow("ShortcutWnd.ShortcutWndHorizontal.TooltipMaxBtn");
		HideWindow("ShortcutWnd.ShortcutWndHorizontal.TooltipMinBtn");
		ShowWindow("ShortcutWnd.ShortcutWndVertical.TooltipMaxBtn");
		HideWindow("ShortcutWnd.ShortcutWndVertical.TooltipMinBtn");
	}
}

function OnDefaultPosition()
{
	if(getInstanceUIData().getIsArenaServer())
	{
		return;
	}
	if(GetOptionInt("Game", "LayoutDF") == 1)
	{
		m_Expand = MAX_ShortcutExtend - 1;
		SetVertical(false);
	}
	ArrangeWnd();
	ExpandWnd();
	ExtendShortcutDefaultPostion();
}

function ExtendShortcutDefaultPostion()
{
	GetWindowHandle("ShortcutWnd." $ m_ShortcutWndExtendName).SetAnchor("", "BottomCenter", "TopLeft", 280, -220);
	GetWindowHandle("ShortcutWnd." $ m_ShortcutWndExtendName).ClearAnchor();
}

function OnEnterState(name a_CurrentStateName)
{
	if(getInstanceUIData().getIsArenaServer())
	{
		return;
	}
	ArrangeWnd();
	ExpandWnd();
}

function OnExitState(name a_CurrentStateName)
{
	if(a_CurrentStateName == 'LoadingState')
	{
		InitShortPageNum();
	}
}

function SettingShortCut()
{
	if(getInstanceUIData().getIsClassicServer())
	{
		if(GetLanguage() == LANG_Korean)
		{
			GetButtonHandle("ShortcutWnd.ShortcutWndHorizontal.BounsExtendSlotBtn").HideWindow();
			GetButtonHandle("ShortcutWnd.ShortcutWndVertical.BounsExtendSlotBtn").HideWindow();
			MAX_ShortcutExtend = 3;			
		}
		else
		{
			if(IsAdenServer())
			{
				GetButtonHandle("ShortcutWnd.ShortcutWndHorizontal.BounsExtendSlotBtn").HideWindow();
				GetButtonHandle("ShortcutWnd.ShortcutWndVertical.BounsExtendSlotBtn").HideWindow();
				MAX_ShortcutExtend = 3;				
			}
			else
			{
				GetButtonHandle("ShortcutWnd.ShortcutWndHorizontal.BounsExtendSlotBtn").ShowWindow();
				GetButtonHandle("ShortcutWnd.ShortcutWndVertical.BounsExtendSlotBtn").ShowWindow();
				MAX_ShortcutExtend = 4;
			}
		}		
	}
	else
	{
		GetButtonHandle("ShortcutWnd.ShortcutWndHorizontal.BounsExtendSlotBtn").ShowWindow();
		GetButtonHandle("ShortcutWnd.ShortcutWndVertical.BounsExtendSlotBtn").ShowWindow();
		MAX_ShortcutExtend = 4;
	}
	if(GetLanguage() == LANG_Korean)
	{
		MAX_Page = 10;		
	}
	else
	{
		MAX_Page = 20;
	}
}

function OnEvent(int a_EventID, string a_Param)
{
	if(getInstanceUIData().getIsArenaServer())
	{
		return;
	}
	switch(a_EventID)
	{
		case EV_GameStart:
			SettingShortCut();
			break;
		case EV_ShortcutCommandSlot:
			ExecuteShortcutCommandBySlot(a_Param);
			break;
		case EV_ShortcutPageUpdate:
			HandleShortcutPageUpdate(a_Param);
			break;
		case EV_ShortcutJoypad:
			HandleShortcutJoypad(a_Param);
			break;
		case EV_JoypadLButtonDown:
			HandleJoypadLButtonDown(a_Param);
			break;
		case EV_JoypadLButtonUp:
			HandleJoypadLButtonUp(a_Param);
			break;
		case EV_JoypadRButtonDown:
			HandleJoypadRButtonDown(a_Param);
			break;
		case EV_JoypadRButtonUp:
			HandleJoypadRButtonUp(a_Param);
			break;
		case EV_ShortcutUpdate:
			HandleShortcutUpdate(a_Param);
			break;
		case EV_ShortcutClear:
			HandleShortcutClear();
			ArrangeWnd();
			ExpandWnd();
			break;
		case EV_ShortcutKeyAssignChanged:
		case EV_SetEnterChatting:
		case EV_UnSetEnterChatting:
		case EV_EquipItemTooltipClear:
			ClearAllShortcutItemTooltip();
			break;
	}
}

function ClearAllShortcutItemTooltip()
{
	Me.ClearAllChildShortcutItemTooltip();
}

function InitShortPageNum()
{
	CurrentShortcutPage = 0;
	CurrentShortcutPage2 = 1;
	CurrentShortcutPage3 = 2;
	//수정(10.02.25)
	CurrentShortcutPage4 = 3;
	CurrentShortcutPage5 = 4;
	CurrentShortcutPageExtend = 4;
}

function HandleShortcutPageUpdate(string param)
{
	local int i, nShortcutID, ShortcutPage;

	if(ParseInt(param, "ShortcutPage", ShortcutPage))
	{
		if((0 > ShortcutPage) || MAX_Page <= ShortcutPage)
		{
			return;
		}
		CurrentShortcutPage = ShortcutPage;
		class'UIAPI_TEXTBOX'.static.SetText(("ShortcutWnd." $ m_ShortcutWndName) $ ".PageNumTextBox", string(CurrentShortcutPage + 1));
		nShortcutID = CurrentShortcutPage * MAX_ShortcutPerPage;

		for(i = 0; i < MAX_ShortcutPerPage; i++)
		{
			class'UIAPI_SHORTCUTITEMWINDOW'.static.UpdateShortcut("ShortcutWnd." $ m_ShortcutWndName $ ".Shortcut" $ (i + 1), nShortcutID);
			++ nShortcutID;
		}
	}
}

function HandleShortcutUpdate(string param)
{
	local int nShortcutID, nShortcutNum;

	ParseInt(param, "ShortcutID", nShortcutID);
	nShortcutNum = int(nShortcutID % MAX_ShortcutPerPage) + 1;
	if(IsShortcutIDInCurPage(CurrentShortcutPage, nShortcutID))
	{
		class'UIAPI_SHORTCUTITEMWINDOW'.static.UpdateShortcut("ShortcutWnd." $ m_ShortcutWndName $ ".Shortcut" $ string(nShortcutNum), nShortcutID);
	}
	if(IsShortcutIDInCurPage(CurrentShortcutPage2, nShortcutID))
	{
		class'UIAPI_SHORTCUTITEMWINDOW'.static.UpdateShortcut("ShortcutWnd." $ m_ShortcutWndName $ "_1.Shortcut" $ string(nShortcutNum), nShortcutID);
	}
	if(IsShortcutIDInCurPage(CurrentShortcutPage3, nShortcutID))
	{
		class'UIAPI_SHORTCUTITEMWINDOW'.static.UpdateShortcut("ShortcutWnd." $ m_ShortcutWndName $ "_2.Shortcut" $ string(nShortcutNum), nShortcutID);
	}
	if(IsShortcutIDInCurPage(CurrentShortcutPage4, nShortcutID))
	{
		class'UIAPI_SHORTCUTITEMWINDOW'.static.UpdateShortcut("ShortcutWnd." $ m_ShortcutWndName $ "_3.Shortcut" $ string(nShortcutNum), nShortcutID);
	}
	if(IsShortcutIDInCurPage(CurrentShortcutPage5, nShortcutID))
	{
		class'UIAPI_SHORTCUTITEMWINDOW'.static.UpdateShortcut("ShortcutWnd." $ m_ShortcutWndName $ "_4.Shortcut" $ string(nShortcutNum), nShortcutID);
	}
	if(IsShortcutIDInCurPage(CurrentShortcutPageExtend, nShortcutID))
	{
		class'UIAPI_SHORTCUTITEMWINDOW'.static.UpdateShortcut("ShortcutWnd." $ m_ShortcutWndExtendName $ ".Shortcut" $ string(nShortcutNum), nShortcutID);
	}
}

function HandleShortcutClear()
{
	local int i;

	for(i = 0; i < MAX_ShortcutPerPage; i++)
	{
		class'UIAPI_SHORTCUTITEMWINDOW'.static.Clear("ShortcutWnd.ShortcutWndVertical.Shortcut" $ (i + 1));
		class'UIAPI_SHORTCUTITEMWINDOW'.static.Clear("ShortcutWnd.ShortcutWndVertical_1.Shortcut" $ (i + 1));
		class'UIAPI_SHORTCUTITEMWINDOW'.static.Clear("ShortcutWnd.ShortcutWndVertical_2.Shortcut" $ (i + 1));
		class'UIAPI_SHORTCUTITEMWINDOW'.static.Clear("ShortcutWnd.ShortcutWndVertical_3.Shortcut" $ (i + 1));
		class'UIAPI_SHORTCUTITEMWINDOW'.static.Clear("ShortcutWnd.ShortcutWndHorizontal.Shortcut" $ (i + 1));
		class'UIAPI_SHORTCUTITEMWINDOW'.static.Clear("ShortcutWnd.ShortcutWndHorizontal_1.Shortcut" $ (i + 1));
		class'UIAPI_SHORTCUTITEMWINDOW'.static.Clear("ShortcutWnd.ShortcutWndHorizontal_2.Shortcut" $ (i + 1));
		class'UIAPI_SHORTCUTITEMWINDOW'.static.Clear("ShortcutWnd.ShortcutWndHorizontal_3.Shortcut" $ (i + 1));
		class'UIAPI_SHORTCUTITEMWINDOW'.static.Clear("ShortcutWnd.ShortcutWnd_Extend.Shortcut" $ (i + 1));
		class'UIAPI_SHORTCUTITEMWINDOW'.static.Clear("ShortcutWnd.ShortcutWndJoypadExpand.Shortcut" $ (i + 1));
	}

	for(i = 0; i < 4; i++)
	{
		class'UIAPI_SHORTCUTITEMWINDOW'.static.Clear("ShortcutWnd.ShortcutWndJoypad.Shortcut" $ (i + 1));
	}
}

function OnClickButton(string a_strID)
{
	switch(a_strID)
	{
		case "PrevBtn":
			OnPrevBtn();
			break;
		case "NextBtn":
			OnNextBtn();
			break;
		case "PrevBtn2":
			OnPrevBtn2();
			break;
		case "NextBtn2":
			OnNextBtn2();
			break;
		case "PrevBtn3":
			OnPrevBtn3();
			break;
		case "NextBtn3":
			OnNextBtn3();
			break;
		case "PrevBtn4":
			OnPrevBtn4();
			break;
		case "PrevBtnExtend":
			OnPrevBtnExtend();
			break;
		case "NextBtn4":
			OnNextBtn4();
			break;
		case "NextBtnExtend":
			OnNextBtnExtend();
			break;
		case "PrevBtn5":
			OnPrevBtn5();
			break;
		case "NextBtn5":
			OnNextBtn5();
			break;
		case "LockBtn":
			OnClickLockBtn();
			break;
		case "UnlockBtn":
			OnClickUnlockBtn();
			break;
		case "RotateBtn":
			OnRotateBtn();
			break;
		case "JoypadBtn":
			OnJoypadBtn();
			break;
		case "ExpandBtn":
			OnExpandBtn();
			break;
		case "ExpandButton":
			OnClickExpandShortcutButton();
			break;
		case "ReduceButton":
			OnClickExpandShortcutButton();
			break;
		case "TooltipMinBtn":
			OnMinBtn();
			break;
		case "TooltipMaxBtn":
			OnMaxBtn();
			break;
		case "BounsExtendSlotBtn":
			OnBounsExtendSlotBtn();
			break;
		default:
			break;
	}
}

function OnBounsExtendSlotBtn()
{
	if(GetWindowHandle("ShortcutWnd.ShortcutWnd_Extend").IsShowWindow())
	{
		GetWindowHandle("ShortcutWnd.ShortcutWnd_Extend").HideWindow();
		SetINIInt("ShortcutWnd", "m", 0, "WindowsInfo.ini");		
	}
	else
	{
		GetWindowHandle("ShortcutWnd.ShortcutWnd_Extend").ShowWindow();
		SetINIInt("ShortcutWnd", "m", 1, "WindowsInfo.ini");
	}
}

function OnMinBtn()
{
	local ToolTip script;

	HandleShortcutClear();
	ArrangeWnd();
	ExpandWnd();
	script = ToolTip(GetScript("Tooltip"));
	script.setBoolSelect(true);
	ShowWindow("ShortcutWnd.ShortcutWndHorizontal.TooltipMaxBtn");
	HideWindow("ShortcutWnd.ShortcutWndHorizontal.TooltipMinBtn");
	ShowWindow("ShortcutWnd.ShortcutWndVertical.TooltipMaxBtn");
	HideWindow("ShortcutWnd.ShortcutWndVertical.TooltipMinBtn");
	SetINIBool("ShortcutWnd", "l", false, "windowsInfo.ini");
}

function OnMaxBtn()
{
	local ToolTip script;

	HandleShortcutClear();
	ArrangeWnd();
	ExpandWnd();
	script = ToolTip(GetScript("Tooltip"));
	script.setBoolSelect(false);
	ShowWindow("ShortcutWnd.ShortcutWndHorizontal.TooltipMinBtn");
	HideWindow("ShortcutWnd.ShortcutWndHorizontal.TooltipMaxBtn");
	ShowWindow("ShortcutWnd.ShortcutWndVertical.TooltipMinBtn");
	HideWindow("ShortcutWnd.ShortcutWndVertical.TooltipMaxBtn");
	SetINIBool("ShortcutWnd", "l", true, "windowsInfo.ini");
}

function OnPrevBtn()
{
	local int nNewPage;

	nNewPage = CurrentShortcutPage - 1;
	if(0 > nNewPage)
	{
		nNewPage = MAX_Page - 1;
	}
	SetCurPage(nNewPage);
}

function OnPrevBtn2()
{
	local int nNewPage;

	nNewPage = CurrentShortcutPage2 - 1;
	if(0 > nNewPage)
	{
		nNewPage = MAX_Page - 1;
	}
	SetCurPage2(nNewPage);
}

function OnPrevBtn3()
{
	local int nNewPage;

	nNewPage = CurrentShortcutPage3 - 1;
	if(0 > nNewPage)
	{
		nNewPage = MAX_Page - 1;
	}
	SetCurPage3(nNewPage);
}

function OnPrevBtn4()
{
	local int nNewPage;

	nNewPage = CurrentShortcutPage4 - 1;
	if(0 > nNewPage)
	{
		nNewPage = MAX_Page - 1;
	}
	SetCurPage4(nNewPage);
}

function OnPrevBtnExtend()
{
	local int nNewPage;

	nNewPage = CurrentShortcutPageExtend - 1;
	if(0 > nNewPage)
	{
		nNewPage = MAX_Page - 1;
	}
	SetCurPageExtend(nNewPage);
}

function OnNextBtnExtend()
{
	local int nNewPage;

	nNewPage = CurrentShortcutPageExtend + 1;
	if(MAX_Page <= nNewPage)
	{
		nNewPage = 0;
	}
	SetCurPageExtend(nNewPage);
}

function OnNextBtn()
{
	local int nNewPage;

	nNewPage = CurrentShortcutPage + 1;
	if(MAX_Page <= nNewPage)
	{
		nNewPage = 0;
	}
	SetCurPage(nNewPage);
}

function OnNextBtn2()
{
	local int nNewPage;

	nNewPage = CurrentShortcutPage2 + 1;
	if(MAX_Page <= nNewPage)
	{
		nNewPage = 0;
	}
	SetCurPage2(nNewPage);
}

function OnNextBtn3()
{
	local int nNewPage;

	nNewPage = CurrentShortcutPage3 + 1;
	if(MAX_Page <= nNewPage)
	{
		nNewPage = 0;
	}
	SetCurPage3(nNewPage);
}

function OnNextBtn4()
{
	local int nNewPage;

	nNewPage = CurrentShortcutPage4 + 1;
	if(MAX_Page <= nNewPage)
	{
		nNewPage = 0;
	}
	SetCurPage4(nNewPage);
}

function OnPrevBtn5()
{
	local int nNewPage;

	nNewPage = CurrentShortcutPage5 - 1;
	if(0 > nNewPage)
	{
		nNewPage = MAX_Page - 1;
	}
	SetCurPage5(nNewPage);
}

function OnNextBtn5()
{
	local int nNewPage;

	nNewPage = CurrentShortcutPage5 + 1;
	if(MAX_Page <= nNewPage)
	{
		nNewPage = 0;
	}
	SetCurPage5(nNewPage);
}

function OnClickLockBtn()
{
	UNLOCK();
}

function OnClickUnlockBtn()
{
	Lock();
}

function OnRotateBtn()
{
	SetVertical(! m_IsVertical);
	if(m_IsVertical)
	{
		class'UIAPI_WINDOW'.static.SetAnchor("ShortcutWnd.ShortcutWndVertical", "ShortcutWnd.ShortcutWndHorizontal", "BottomRight", "BottomRight", 0, 0);
		class'UIAPI_WINDOW'.static.ClearAnchor("ShortcutWnd.ShortcutWndVertical");
		class'UIAPI_WINDOW'.static.SetAnchor("ShortcutWnd.ShortcutWndHorizontal", "ShortcutWnd.ShortcutWndVertical", "BottomRight", "BottomRight", 0, 0);		
	}
	else
	{
		class'UIAPI_WINDOW'.static.SetAnchor("ShortcutWnd.ShortcutWndHorizontal", "ShortcutWnd.ShortcutWndVertical", "BottomRight", "BottomRight", 0, 0);
		class'UIAPI_WINDOW'.static.ClearAnchor("ShortcutWnd.ShortcutWndHorizontal");
		class'UIAPI_WINDOW'.static.SetAnchor("ShortcutWnd.ShortcutWndVertical", "ShortcutWnd.ShortcutWndHorizontal", "BottomRight", "BottomRight", 0, 0);
	}
	ExpandByNum(m_Expand);
	class'UIAPI_WINDOW'.static.SetFocus("ShortcutWnd." $ m_ShortcutWndName);
	AutoShotItemWndScript.ExHideSubWnd();
}

function OnJoypadBtn()
{
	SetJoypad(! m_IsJoypad);
	class'UIAPI_WINDOW'.static.SetFocus("ShortcutWnd." $ m_ShortcutWndName);
}

function OnExpandBtn()
{
	SetJoypadExpand(! m_IsJoypadExpand);
	class'UIAPI_WINDOW'.static.SetFocus("ShortcutWnd." $ m_ShortcutWndName);
}

function SetCurPage(int a_nCurPage)
{
	if(0 > a_nCurPage || MAX_Page <= a_nCurPage)
	{
		return;
	}
	class'ShortcutWndAPI'.static.SetShortcutPage(a_nCurPage);
}

function SetCurPage2(int a_nCurPage)
{
	local int i, nShortcutID;

	if(0 > a_nCurPage || MAX_Page <= a_nCurPage)
	{
		return;
	}
	CurrentShortcutPage2 = a_nCurPage;
	class'UIAPI_TEXTBOX'.static.SetText("ShortcutWnd." $ m_ShortcutWndName $ "." $ m_ShortcutWndName $ "_1" $ ".PageNumTextBox", string(CurrentShortcutPage2 + 1));
	nShortcutID = CurrentShortcutPage2 * MAX_ShortcutPerPage;

	for(i = 0; i < MAX_ShortcutPerPage; i++)
	{
		class'UIAPI_SHORTCUTITEMWINDOW'.static.UpdateShortcut("ShortcutWnd." $ m_ShortcutWndName $ "." $ m_ShortcutWndName $ "_1" $ ".Shortcut" $ (i + 1), nShortcutID);
		nShortcutID++;
	}
}

function SetCurPage3(int a_nCurPage)
{
	local int i, nShortcutID;

	if(0 > a_nCurPage || MAX_Page <= a_nCurPage)
	{
		return;
	}
	CurrentShortcutPage3 = a_nCurPage;
	class'UIAPI_TEXTBOX'.static.SetText("ShortcutWnd." $ m_ShortcutWndName $ "." $ m_ShortcutWndName $ "_1." $ m_ShortcutWndName $ "_2" $ ".PageNumTextBox", string(CurrentShortcutPage3 + 1));
	nShortcutID = CurrentShortcutPage3 * MAX_ShortcutPerPage;

	for(i = 0; i < MAX_ShortcutPerPage; i++)
	{
		class'UIAPI_SHORTCUTITEMWINDOW'.static.UpdateShortcut("ShortcutWnd." $ m_ShortcutWndName $ "." $ m_ShortcutWndName $ "_1." $ m_ShortcutWndName $ "_2" $ ".Shortcut" $ (i + 1), nShortcutID);
		++ nShortcutID;
	}
}

function SetCurPage4(int a_nCurPage)
{
	local int i, nShortcutID;

	if(0 > a_nCurPage || MAX_Page <= a_nCurPage)
	{
		return;
	}
	CurrentShortcutPage4 = a_nCurPage;
	class'UIAPI_TEXTBOX'.static.SetText("ShortcutWnd." $ m_ShortcutWndName $ "." $ m_ShortcutWndName $ "_1." $ m_ShortcutWndName $ "_3" $ ".PageNumTextBox", string(CurrentShortcutPage4 + 1));
	nShortcutID = CurrentShortcutPage4 * MAX_ShortcutPerPage;

	for(i = 0; i < MAX_ShortcutPerPage; i++)
	{
		class'UIAPI_SHORTCUTITEMWINDOW'.static.UpdateShortcut("ShortcutWnd." $ m_ShortcutWndName $ "." $ m_ShortcutWndName $ "_1." $ m_ShortcutWndName $ "_3" $ ".Shortcut" $ (i + 1), nShortcutID);
		nShortcutID++;
	}
}

function SetCurPage5(int a_nCurPage)
{
	local int i, nShortcutID;

	if(0 > a_nCurPage || MAX_Page <= a_nCurPage)
	{
		return;
	}
	CurrentShortcutPage5 = a_nCurPage;
	class'UIAPI_TEXTBOX'.static.SetText("ShortcutWnd." $ m_ShortcutWndName $ "." $ m_ShortcutWndName $ "_1." $ m_ShortcutWndName $ "_4" $ ".PageNumTextBox", string(CurrentShortcutPage5 + 1));
	nShortcutID = CurrentShortcutPage5 * MAX_ShortcutPerPage;

	for(i = 0; i < MAX_ShortcutPerPage; i++)
	{
		class'UIAPI_SHORTCUTITEMWINDOW'.static.UpdateShortcut("ShortcutWnd." $ m_ShortcutWndName $ "." $ m_ShortcutWndName $ "_1." $ m_ShortcutWndName $ "_4" $ ".Shortcut" $ (i + 1), nShortcutID);
		++ nShortcutID;
	}
}

function SetCurPageExtend(int a_nCurPage)
{
	local int i, nShortcutID;

	if(0 > a_nCurPage || MAX_Page <= a_nCurPage)
	{
		return;
	}
	CurrentShortcutPageExtend = a_nCurPage;
	class'UIAPI_TEXTBOX'.static.SetText(("ShortcutWnd." $ m_ShortcutWndExtendName) $ ".PageNumTextBox", string(CurrentShortcutPageExtend + 1));
	nShortcutID = CurrentShortcutPageExtend * MAX_ShortcutPerPage;

	for(i = 0; i < MAX_ShortcutPerPage; i++)
	{
		class'UIAPI_SHORTCUTITEMWINDOW'.static.UpdateShortcut("ShortcutWnd." $ m_ShortcutWndExtendName $ ".Shortcut" $ string(i + 1), nShortcutID);
		++ nShortcutID;
	}
}

function bool IsShortcutIDInCurPage(int pageNum, int a_nShortcutID)
{
	if(pageNum * MAX_ShortcutPerPage > a_nShortcutID)
	{
		return false;
	}
	if((pageNum + 1) * MAX_ShortcutPerPage <= a_nShortcutID)
	{
		return false;
	}
	return true;
}

function Lock()
{
	m_IsLocked = true;
	SetOptionBool("Game", "IsLockShortcutWnd", true);
	ShowWindow("ShortcutWnd." $ m_ShortcutWndName $ ".LockBtn");
	HideWindow("ShortcutWnd." $ m_ShortcutWndName $ ".UnlockBtn");
}

function UNLOCK()
{
	m_IsLocked = false;
	SetOptionBool("Game", "IsLockShortcutWnd", false);
	ShowWindow("ShortcutWnd." $ m_ShortcutWndName $ ".UnlockBtn");
	HideWindow("ShortcutWnd." $ m_ShortcutWndName $ ".LockBtn");
}

function SetVertical(bool a_IsVertical)
{
	m_IsVertical = a_IsVertical;
	SetINIInt("ShortcutWnd", "v", int(m_IsVertical), "WindowsInfo.ini");
	ArrangeWnd();
	ExpandWnd();
}

function ArrangeWnd()
{
	local Rect WindowRect;

	if(m_IsJoypad)
	{
		HideWindow("ShortcutWnd.ShortcutWndVertical");
		HideWindow("ShortcutWnd.ShortcutWndHorizontal");
		if(m_IsJoypadExpand)
		{
			HideWindow("ShortcutWnd.ShortcutWndJoypad");
			ShowWindow("ShortcutWnd.ShortcutWndJoypadExpand");
			m_ShortcutWndName = "ShortcutWndJoypadExpand";			
		}
		else
		{
			HideWindow("ShortcutWnd.ShortcutWndJoypadExpand");
			ShowWindow("ShortcutWnd.ShortcutWndJoypad");
			m_ShortcutWndName = "ShortcutWndJoypad";
		}		
	}
	else
	{
		HideWindow("ShortcutWnd.ShortcutWndJoypadExpand");
		HideWindow("ShortcutWnd.ShortcutWndJoypad");
		if(m_IsVertical)
		{
			m_ShortcutWndName = "ShortcutWndVertical";
			WindowRect = class'UIAPI_WINDOW'.static.GetRect("ShortcutWnd.ShortcutWndVertical");
			if(WindowRect.nY < 0)
			{
				class'UIAPI_WINDOW'.static.MoveTo("ShortcutWnd.ShortcutWndVertical", WindowRect.nX, 0);
			}
			HideWindow("ShortcutWnd.ShortcutWndHorizontal");
			ShowWindow("ShortcutWnd.ShortcutWndVertical");			
		}
		else
		{
			m_ShortcutWndName = "ShortcutWndHorizontal";
			WindowRect = class'UIAPI_WINDOW'.static.GetRect("ShortcutWnd.ShortcutWndHorizontal");
			if(WindowRect.nX < 0)
			{
				class'UIAPI_WINDOW'.static.MoveTo("ShortcutWnd.ShortcutWndHorizontal", 0, WindowRect.nY);
			}
			HideWindow("ShortcutWnd.ShortcutWndVertical");
			ShowWindow("ShortcutWnd.ShortcutWndHorizontal");
		}
		if(m_IsJoypadOn)
		{
			ShowWindow("ShortcutWnd." $ m_ShortcutWndName $ ".JoypadBtn");			
		}
		else
		{
			HideWindow("ShortcutWnd." $ m_ShortcutWndName $ ".JoypadBtn");
		}
	}
	if(m_IsLocked)
	{
		Lock();		
	}
	else
	{
		UNLOCK();
	}
	SetCurPage(CurrentShortcutPage);
	SetCurPage2(CurrentShortcutPage2);
	SetCurPage3(CurrentShortcutPage3);
	SetCurPage4(CurrentShortcutPage4);
	SetCurPageExtend(CurrentShortcutPageExtend);
	m_IsShortcutExpand = m_Expand != (MAX_ShortcutExtend - 1);
	HandleExpandButton();
}

function ExpandWnd()
{
	if(m_Expand > 0)
	{
		m_IsShortcutExpand = false;
		ExpandByNum(m_Expand);		
	}
	else
	{
		m_IsShortcutExpand = true;
		Reduce();
	}
}

function ExpandByNum(int expandNum)
{
	m_IsShortcutExpand = true;
	m_Expand = expandNum;
	switch(expandNum)
	{
		case 3:
			class'UIAPI_WINDOW'.static.ShowWindow("ShortcutWnd.ShortcutWndVertical_3");
			class'UIAPI_WINDOW'.static.ShowWindow("ShortcutWnd.ShortcutWndHorizontal_3");
		case 2:
			class'UIAPI_WINDOW'.static.ShowWindow("ShortcutWnd.ShortcutWndVertical_2");
			class'UIAPI_WINDOW'.static.ShowWindow("ShortcutWnd.ShortcutWndHorizontal_2");
		case 1:
			class'UIAPI_WINDOW'.static.ShowWindow("ShortcutWnd.ShortcutWndVertical_1");
			class'UIAPI_WINDOW'.static.ShowWindow("ShortcutWnd.ShortcutWndHorizontal_1");
			break;
		default:
			break;
	}
	SetINIInt("ShortcutWnd", "e", m_Expand, "WindowsInfo.ini");
	HandleExpandButton();
	AutoShotItemWndScript.windowPositionAutoMove();
	AutoShotItemWndScript.checkSlotShowState();
}

function Reduce()
{
	m_IsShortcutExpand = true;
	class'UIAPI_WINDOW'.static.HideWindow("ShortcutWnd.ShortcutWndVertical_1");
	class'UIAPI_WINDOW'.static.HideWindow("ShortcutWnd.ShortcutWndVertical_2");
	class'UIAPI_WINDOW'.static.HideWindow("ShortcutWnd.ShortcutWndHorizontal_1");
	class'UIAPI_WINDOW'.static.HideWindow("ShortcutWnd.ShortcutWndHorizontal_2");
	class'UIAPI_WINDOW'.static.HideWindow("ShortcutWnd.ShortcutWndVertical_3");
	class'UIAPI_WINDOW'.static.HideWindow("ShortcutWnd.ShortcutWndHorizontal_3");
	m_Expand = 0;
	SetINIInt("ShortcutWnd", "e", m_Expand, "WindowsInfo.ini");
	HandleExpandButton();
	AutoShotItemWndScript.windowPositionAutoMove();
	AutoShotItemWndScript.checkSlotShowState();
}

function OnClickExpandShortcutButton()
{
	if(m_Expand == (MAX_ShortcutExtend - 1))
	{
		Reduce();		
	}
	else
	{
		ExpandByNum(m_Expand + 1);
	}
}

function ExecuteShortcutCommandBySlot(string param)
{
	local int Slot;

	ParseInt(param, "Slot", Slot);
	if(Me.IsShowWindow())
	{
		if(Slot >= 0 && Slot < MAX_ShortcutPerPage)
		{
			class'ShortcutWndAPI'.static.ExecuteShortcutBySlot((CurrentShortcutPage * 12) + Slot);			
		}
		else
		{
			if(Slot >= MAX_ShortcutPerPage && Slot < MAX_ShortcutPerPage * 2)
			{
				class'ShortcutWndAPI'.static.ExecuteShortcutBySlot(CurrentShortcutPage2 * MAX_ShortcutPerPage + Slot - MAX_ShortcutPerPage);				
			}
			else
			{
				if(Slot >= (MAX_ShortcutPerPage * 2) && Slot < MAX_ShortcutPerPage * 3)
				{
					class'ShortcutWndAPI'.static.ExecuteShortcutBySlot(CurrentShortcutPage3 * MAX_ShortcutPerPage + Slot - MAX_ShortcutPerPage2);					
				}
				else
				{
					if(Slot >= MAX_ShortcutPerPage * 3 && Slot < (MAX_ShortcutPerPage * 4))
					{
						class'ShortcutWndAPI'.static.ExecuteShortcutBySlot(CurrentShortcutPage4 * MAX_ShortcutPerPage + Slot - MAX_ShortcutPerPage3);
					}
				}
			}
		}
	}
}

function HandleExpandButton()
{
	if(IsAdenServer())
	{
		return;
	}
	if(m_IsShortcutExpand)
	{
		ShowWindow("ShortcutWnd." $ m_ShortcutWndName $ ".ExpandButton");
		HideWindow("ShortcutWnd." $ m_ShortcutWndName $ ".ReduceButton");		
	}
	else
	{
		HideWindow("ShortcutWnd." $ m_ShortcutWndName $ ".ExpandButton");
		ShowWindow("ShortcutWnd." $ m_ShortcutWndName $ ".ReduceButton");
	}
}

function bool IsVertical()
{
	return m_IsVertical;
}

// 숏컷 확장슬롯 상태 0~4
function int getExpandNum()
{
	return m_Expand;
}

// 자동 정탄 위치 보정 TT#72738
function AutoShotPositionAutoMove()
{
	AutoShotItemWndScript.windowPositionAutoMove();
	AutoShotItemWndScript.checkSlotShowState();
}

function SetJoypad(bool a_IsJoypad)
{
	m_IsJoypad = a_IsJoypad;
	ArrangeWnd();
}

function SetJoypadExpand(bool a_IsJoypadExpand)
{
	m_IsJoypadExpand = a_IsJoypadExpand;
	if(m_IsJoypadExpand)
	{
		class'UIAPI_WINDOW'.static.SetAnchor("ShortcutWnd.ShortcutWndJoypadExpand", "ShortcutWnd.ShortcutWndJoypad", "TopLeft", "TopLeft", 0, 0);
		class'UIAPI_WINDOW'.static.ClearAnchor("ShortcutWnd.ShortcutWndJoypadExpand");		
	}
	else
	{
		class'UIAPI_WINDOW'.static.SetAnchor("ShortcutWnd.ShortcutWndJoypad", "ShortcutWnd.ShortcutWndJoypadExpand", "TopLeft", "TopLeft", 0, 0);
		class'UIAPI_WINDOW'.static.ClearAnchor("ShortcutWnd.ShortcutWndJoypad");
	}
	ArrangeWnd();
}

function HandleShortcutJoypad(string a_Param)
{
	local int OnOff;

	if(ParseInt(a_Param, "OnOff", OnOff))
	{
		if(1 == OnOff)
		{
			m_IsJoypadOn = true;
			if(Len(m_ShortcutWndName) > 0)
			{
				ShowWindow("ShortcutWnd." $ m_ShortcutWndName $ ".JoypadBtn");
			}			
		}
		else
		{
			if(0 == OnOff)
			{
				m_IsJoypadOn = false;
				if(Len(m_ShortcutWndName) > 0)
				{
					HideWindow("ShortcutWnd." $ m_ShortcutWndName $ ".JoypadBtn");
				}
			}
		}
	}
}

function HandleJoypadLButtonUp(string a_Param)
{
	SetJoypadShortcut(JOYSHORTCUT_Center);
}

function HandleJoypadLButtonDown(string a_Param)
{
	SetJoypadShortcut(JOYSHORTCUT_Left);
}

function HandleJoypadRButtonUp(string a_Param)
{
	SetJoypadShortcut(JOYSHORTCUT_Center);
}

function HandleJoypadRButtonDown(string a_Param)
{
	SetJoypadShortcut(JOYSHORTCUT_Right);
}

function SetJoypadShortcut(EJoyShortcut a_JoyShortcut)
{
	local int i, nShortcutID;

	switch(a_JoyShortcut)
	{
		case JOYSHORTCUT_Left:
			class'UIAPI_TEXTURECTRL'.static.SetTexture("ShortcutWnd.ShortcutWndJoypadExpand.JoypadButtonBackTex", "L2UI_CH3.ShortcutWnd.joypad2_back_over1");
			class'UIAPI_TEXTURECTRL'.static.SetAnchor("ShortcutWnd.ShortcutWndJoypadExpand.JoypadButtonBackTex", "ShortcutWnd.ShortcutWndJoypadExpand", "TopLeft", "TopLeft", 28, 0);
			class'UIAPI_TEXTURECTRL'.static.SetTexture("ShortcutWnd.ShortcutWndJoypad.JoypadLButtonTex", "L2UI_ch3.Joypad.joypad_L_HOLD");
			class'UIAPI_TEXTURECTRL'.static.SetTexture("ShortcutWnd.ShortcutWndJoypad.JoypadRButtonTex", "L2UI_ch3.Joypad.joypad_R");
			nShortcutID = CurrentShortcutPage * MAX_ShortcutPerPage + 4;

			for(i = 0; i < 4; i++)
			{
				class'UIAPI_SHORTCUTITEMWINDOW'.static.UpdateShortcut("ShortcutWnd.ShortcutWndJoypad.Shortcut" $ string(i + 1), nShortcutID);
				++ nShortcutID;
			}
			break;
		case JOYSHORTCUT_Center:
			class'UIAPI_TEXTURECTRL'.static.SetTexture("ShortcutWnd.ShortcutWndJoypadExpand.JoypadButtonBackTex", "L2UI_CH3.ShortcutWnd.joypad2_back_over2");
			class'UIAPI_TEXTURECTRL'.static.SetAnchor("ShortcutWnd.ShortcutWndJoypadExpand.JoypadButtonBackTex", "ShortcutWnd.ShortcutWndJoypadExpand", "TopLeft", "TopLeft", 158, 0);
			class'UIAPI_TEXTURECTRL'.static.SetTexture("ShortcutWnd.ShortcutWndJoypad.JoypadLButtonTex", "L2UI_ch3.Joypad.joypad_L");
			class'UIAPI_TEXTURECTRL'.static.SetTexture("ShortcutWnd.ShortcutWndJoypad.JoypadRButtonTex", "L2UI_ch3.Joypad.joypad_R");
			nShortcutID = CurrentShortcutPage * MAX_ShortcutPerPage;

			for(i = 0; i < 4; i++)
			{
				class'UIAPI_SHORTCUTITEMWINDOW'.static.UpdateShortcut("ShortcutWnd.ShortcutWndJoypad.Shortcut" $ string(i + 1), nShortcutID);
				++ nShortcutID;
			}
			break;
		case JOYSHORTCUT_Right/*2*/:
			class'UIAPI_TEXTURECTRL'.static.SetTexture("ShortcutWnd.ShortcutWndJoypadExpand.JoypadButtonBackTex", "L2UI_CH3.ShortcutWnd.joypad2_back_over3");
			class'UIAPI_TEXTURECTRL'.static.SetAnchor("ShortcutWnd.ShortcutWndJoypadExpand.JoypadButtonBackTex", "ShortcutWnd.ShortcutWndJoypadExpand", "TopLeft", "TopLeft", 288, 0);
			class'UIAPI_TEXTURECTRL'.static.SetTexture("ShortcutWnd.ShortcutWndJoypad.JoypadLButtonTex", "L2UI_ch3.Joypad.joypad_L");
			class'UIAPI_TEXTURECTRL'.static.SetTexture("ShortcutWnd.ShortcutWndJoypad.JoypadRButtonTex", "L2UI_ch3.Joypad.joypad_R_HOLD");
			nShortcutID = CurrentShortcutPage * MAX_ShortcutPerPage + 8;

			for(i = 0; i < 4; i++)
			{
				class'UIAPI_SHORTCUTITEMWINDOW'.static.UpdateShortcut("ShortcutWnd.ShortcutWndJoypad.Shortcut" $ string(i + 1), nShortcutID);
				++ nShortcutID;
			}
			break;
	}
}

defaultproperties
{
	MAX_Page=10
	MAX_ShortcutExtend=3
	m_IsVertical=false
}
