//================================================================================
// MenuEntireWnd.
//================================================================================

class MenuEntireWnd extends UICommonAPI;

const TIMER_ID = 123401;
const TIMER_DELAY = 300;
const CATEGORY_LINE_0 = 0;
const CATEGORY_LINE_1 = 1;
const CATEGORY_LINE_2 = 2;
const CATEGORY_LINE_3 = 3;
const CATEGORY_LINE_4 = 4;
const BG_TYPE1_TEXTURE = "L2UI_NewTex.MenuWnd.MainMenu_MainButton.MenuWnd.MainMenu_iconBg02";
const BG_TYPE2_TEXTURE = "L2UI_NewTex.MenuWnd.MainMenu_MainButton.MenuWnd.MainMenu_iconBg01";
const MAX_CATEGORY = 5;
const MAX_CATEGORYBUTTONNUM = 18;
const ADD_HEIGHT_ADEN = 140;
const ADD_HEIGHT_TALKINGISLAND = 140;
const MAX_FIXMENU_NUM = 10;
const ADD_HEIGHT_LIVE = 140;
const CATEGORYBG_ADD_HEIGHT = 4;
const MENU_Ability = "Ability";
const MENU_Attend = "Attend";
const MENU_OlympiadRandomChallengeWnd = "OlympiadRandomChallengeWnd";
const MENU_Productinven = "Productinven";
const MENU_ShopLcoinCraft = "ShopLcoinCraft";
const MENU_NShop = "NShop";
const MENU_OlympiadWnd = "OlympiadWnd";
const MENU_RevengeWnd = "RevengeWnd";
const MENU_IngameWebWnd = "IngameWebWnd";
const MENU_BBS = "BBS";
const MENU_ShopSell = "ShopSell";
const MENU_ShopBuy = "ShopBuy";
const MENU_ShopSellAll = "ShopSellAll";
const MENU_ShopSearch = "ShopSearch";
const MENU_ShopFind = "ShopFind";
const MENU_Post = "Post";
const MENU_ShopLcoinCraftWnd = "ShopLcoinCraftWnd";
const MENU_PartyMatchWnd = "PartyMatchWnd";
const MENU_PersonalConnectionsWnd = "PersonalConnectionsWnd";
const MENU_InstancedZone = "InstancedZone";
const MENU_Petition = "Petition";
const MENU_ShortcutAssign = "ShortcutAssign";
const MENU_MacroWnd = "MacroWnd";
const MENU_SiegeCastleInfoWnd = "SiegeCastleInfoWnd";
const MENU_ClanSearch = "ClanSearch";
const MENU_FactionWnd = "FactionWnd";
const MENU_HennaEngraveWndLive = "HennaEngraveWndLive";
const MENU_PlayerAgeWnd = "PlayerAgeWnd";
const MENU_Qna = "Qna";
const MENU_OptionWnd = "OptionWnd";
const MENU_Rec = "Rec";
const MENU_TimeZoneWnd = "TimeZoneWnd";
const MENU_VitamainService = "VitamainService";
const MENU_YetiWnd = "YetiWnd";
const MENU_DetailStatusWnd = "DetailStatusWnd";
const MENU_InventoryWnd = "InventoryWnd";
const MENU_ActionWnd = "ActionWnd";
const MENU_MagicSkillWnd = "MagicSkillWnd";
const MENU_QuestTreeWnd = "QuestTreeWnd";
const MENU_ClanWnd = "ClanWnd";
const MENU_LShop = "LShop";
const MENU_PcRoom = "PcRoom";
const MENU_Shortcut = "Shortcut";
const MENU_PathToAwakening = "PathToAwakening";
const MENU_HomunculusWnd = "HomunculusWnd";
const MENU_Einhasad = "Einhasad";
const MENU_RestoreLostPropertyWnd = "RestoreLostPropertyWnd";
const MENU_CollectionSystem = "CollectionSystem";
const MENU_WorldSiegeRankingWnd = "WorldSiegeRankingWnd";
const MENU_DethroneWnd = "DethroneWnd";
const MENU_HennaMenuWnd = "HennaMenuWnd";
const MENU_HeroBookWnd = "HeroBookWnd";
const MENU_AdenaDistributionWnd = "AdenaDistributionWnd";
const MENU_TeleportWnd = "TeleportWnd";
const MENU_TodoListWnd = "TodoListWnd";
const MENU_WorldExchangeBuyWnd = "WorldExchangeBuyWnd";
const MENU_ElementalSpiritWnd = "ElementalSpiritWnd";
const MENU_MiniMapGfxWnd = "MinimapWnd";
const MENU_CostumeWnd = "CostumeWnd";
const BG_TYPE1 = 0;
const BG_TYPE2 = 1;

enum GameRuleType
{
	GRT_TEAM,
	GRT_CLASSLESS,
	GRT_CLASS,
	GRT_MAX
};

struct MenuButtonSlotStructCategory
{
	var int categoryIndex;
	var array<MenuButtonSlotStruct> MenuButtonSlotStructArray;
};

var WindowHandle Me;
var TextureHandle menuBgTexture;
var int lastButtonCount;
var Rect firstRect;
var bool bIsWorkingTimer;
var int nSystemMenuWndFocus;
var bool bEditMode;
var int nSquenceAdd;
var array<MenuButtonSlotStructCategory> menuSlotArray;
var array<MenuButtonSlotStruct> fixedMenuSlotStructArray;

function OnRegisterEvent()
{
	RegisterEvent(EV_GamingStateEnter);
	RegisterEvent(EV_ShowWindow);
	RegisterEvent(EV_Restart);
	RegisterEvent(EV_VipAttendanceRefresh);
}

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

function Initialize()
{
	Me = GetWindowHandle("MenuEntireWnd");
	menuBgTexture = GetTextureHandle("MenuEntireWnd.menuBgTexture");
	firstRect = Me.GetRect();
}

function OnSetFocus(WindowHandle a_WindowHandle, bool bFocused)
{
	if (nSystemMenuWndFocus == 1)
	{
		if ((bIsWorkingTimer == false) && Me.IsShowWindow() && !bFocused)
		{
			if(bEditMode == false)
			{
				Me.HideWindow();
			}
		}
	}
	nSystemMenuWndFocus = 0;
}

function initAllMenu()
{
	menuSlotArray.Remove(0, menuSlotArray.Length);
	addCatogory(CATEGORY_LINE_0);
	addCatogory(CATEGORY_LINE_1);
	addCatogory(CATEGORY_LINE_2);
	addCatogory(CATEGORY_LINE_3);
	addCatogory(CATEGORY_LINE_4);
}

function OnShow()
{
	bIsWorkingTimer = true;
	Me.KillTimer(TIMER_ID);
	Me.SetTimer(TIMER_ID, TIMER_DELAY);
}

function OnHide()
{
	bIsWorkingTimer = true;
	Me.KillTimer(TIMER_ID);
	Me.SetTimer(TIMER_ID, TIMER_DELAY);
	if(bEditMode)
	{
		bEditMode = false;
		setEditMode(false);
		loadOptionIni();
		refreshMenu();
	}
	nSystemMenuWndFocus = 1;
}

function OnTimer(int TimerID)
{
	if (TimerID == TIMER_ID)
	{
		KillIsWorkingTimerTimer();
		nSystemMenuWndFocus = 1;
	}
}

function OnEvent(int Event_ID, string param)
{
	local string nameStr;
	local string SystemMenuWndFocus;

	if (Event_ID == EV_GamingStateEnter)
	{
		KillIsWorkingTimerTimer();
		initAllMenu();
		configurationMenuData(true);
		configurationFixedMenuData();
		bEditMode = false;
		setEditMode(false);
		loadOptionIni();
		refreshMenu();
	}
	else if (Event_ID == EV_ShowWindow)
	{
		ParseString(param, "Name", nameStr);
		if (nameStr == "SystemMenuWnd")
		{
			ParseString(param, "SystemMenuWndFocus", SystemMenuWndFocus);
			nSystemMenuWndFocus = int(SystemMenuWndFocus);
			if (Me.IsShowWindow())
			{
				Me.HideWindow();
			}
			else if (!bIsWorkingTimer)
			{
				ShowWindowWithFocus(getCurrentWindowName(string(self)));
			}
		}
	}
	else if (Event_ID == EV_Restart)
	{
		KillIsWorkingTimerTimer();
	}
	else if (Event_ID == EV_VipAttendanceRefresh)
	{
		initAllMenu();
		configurationMenuData();
		configurationFixedMenuData();
		loadOptionIni();
		refreshMenu();
	}
}

function configurationFixedMenuData()
{
	local ELanguageType Language;
	local bool isClassic, isKorean, isAden, isLive;

	isLive = getInstanceUIData().getIsLiveServer();
	isClassic = getInstanceUIData().getIsClassicServer();
	isAden = IsAdenServer();
	Language = GetLanguage();
	isKorean = Language == ELanguageType.LANG_Korean/*0*/;
	fixedMenuSlotStructArray.Remove(0, fixedMenuSlotStructArray.Length);
	if(isAden)
	{
		setListFixed(314, MENU_ClanWnd, "");
		setListFixed(389, MENU_PartyMatchWnd, "");
		setListFixed(470, MENU_Petition, "", ! isKorean);
		setListFixed(13515, MENU_RestoreLostPropertyWnd, "");
		setListFixed(2668, MENU_InstancedZone, "");
		setListFixed(3529, MENU_SiegeCastleInfoWnd, "");
		setListFixed(3327, MENU_PlayerAgeWnd, "", ! isKorean);
		setListFixed(2448, MENU_Rec, "");
		setListFixed(14168, MENU_PersonalConnectionsWnd, MENU_PersonalConnectionsWnd);		
	}
	else if(isClassic && ! isAden)
	{
		setListFixed(314, MENU_ClanWnd, "");
		setListFixed(389, MENU_PartyMatchWnd, "");
		setListFixed(13515, MENU_RestoreLostPropertyWnd, "");
		setListFixed(470, MENU_Petition, "", ! isKorean);
		setListFixed(2668, MENU_InstancedZone, "");
		setListFixed(3529, MENU_SiegeCastleInfoWnd, "");
		setListFixed(3327, MENU_PlayerAgeWnd, "", ! isKorean);
		setListFixed(2448, MENU_Rec, "");
		setListFixed(14168, MENU_PersonalConnectionsWnd, MENU_PersonalConnectionsWnd);			
	}
	else
	{
		setListFixed(3471, MENU_IngameWebWnd, "", ! isKorean);
		setListFixed(387, MENU_BBS, "BoardWnd");
		setListFixed(470, MENU_Petition, "", ! isKorean);
		setListFixed(3136, MENU_Qna, "", ! isKorean);
		setListFixed(2448, MENU_Rec, "");
		setListFixed(3327, MENU_PlayerAgeWnd, "", ! isKorean);
	}
}


function configurationMenuData(optional bool bGamingStateEnter)
{
	local ELanguageType Language;
	local bool isClassic, isKorean, isAden, isLive;

	isLive = getInstanceUIData().getIsLiveServer();
	isClassic = getInstanceUIData().getIsClassicServer();
	isAden = IsAdenServer();
	Language = GetLanguage();
	isKorean = Language == LANG_Korean;
	GetMeButton("OptionBtn").SetTooltipCustomType(MakeTooltipSimpleColorText(setMainShortcutString(getAssignedKeyGroup(), MENU_OptionWnd), getInstanceL2Util().White));

	if(isKorean)
	{
		if(isAden)
		{
			setList(CATEGORY_LINE_0, 14063, MENU_WorldExchangeBuyWnd, "", ! class'WorldExchangeBuyWnd'.static.Inst().ChkUseableServerID(), GetColor(255, 211, 102, 255));
			setList(CATEGORY_LINE_0, 13025, MENU_TimeZoneWnd, "");
			setList(CATEGORY_LINE_0, 1, MENU_InventoryWnd, MENU_InventoryWnd);
			setList(CATEGORY_LINE_0, 3651, MENU_DetailStatusWnd, MENU_DetailStatusWnd);
			setList(CATEGORY_LINE_0, 447, MENU_MiniMapGfxWnd, MENU_MiniMapGfxWnd);
			setList(CATEGORY_LINE_1, 13832, MENU_ShopFind, "",, GetColor(255, 211, 102, 255));
			setList(CATEGORY_LINE_1, 7464, MENU_Attend, "", ! getUseVipAttendance());
			setList(CATEGORY_LINE_1, 119, MENU_MagicSkillWnd, MENU_MagicSkillWnd);
			setList(CATEGORY_LINE_1, 3506, MENU_TodoListWnd, "");
			setList(CATEGORY_LINE_1, 13476, MENU_CollectionSystem, "");
			setList(CATEGORY_LINE_2, 3634, MENU_NShop, MENU_IngameWebWnd, ! isKorean, GetColor(255, 211, 102, 255));
			setList(CATEGORY_LINE_2, 687, MENU_TeleportWnd, "");
			setList(CATEGORY_LINE_2, 127, MENU_ActionWnd, MENU_ActionWnd);
			setList(CATEGORY_LINE_2, 13904, MENU_HennaMenuWnd, "");
			setList(CATEGORY_LINE_2, 3776, MENU_ElementalSpiritWnd, "");
			setList(CATEGORY_LINE_3, 2469, MENU_Productinven, "", ! GetINIBool2Bool("PrimeShop", "UseGoodsInventory"), GetColor(255, 211, 102, 255));
			setList(CATEGORY_LINE_3, 13249, MENU_YetiWnd, MENU_YetiWnd, ! isKorean);
			setList(CATEGORY_LINE_3, 711, MENU_MacroWnd, MENU_MacroWnd);
			setList(CATEGORY_LINE_3, 13082, MENU_RevengeWnd, "");
			setList(CATEGORY_LINE_3, 2074, MENU_Post, "PostWnd");
			setList(CATEGORY_LINE_4, 3932, MENU_LShop, "", ! isKorean, GetColor(255, 211, 102, 255));
			setList(CATEGORY_LINE_4, 118, MENU_QuestTreeWnd, MENU_QuestTreeWnd);
			setList(CATEGORY_LINE_4, 387, MENU_BBS, "BoardWnd");
			setList(CATEGORY_LINE_4, 13799, MENU_WorldSiegeRankingWnd, "", ! isKorean);
			setList(CATEGORY_LINE_4, 146, MENU_OptionWnd, MENU_OptionWnd);			
		}
		else if(isClassic && ! isAden)
		{
			setList(CATEGORY_LINE_0, 687, MENU_TeleportWnd, "");
			setList(CATEGORY_LINE_0, 13025, MENU_TimeZoneWnd, "");
			setList(CATEGORY_LINE_0, 13476, MENU_CollectionSystem, "");
			setList(CATEGORY_LINE_0, 1, MENU_InventoryWnd, MENU_InventoryWnd);
			setList(CATEGORY_LINE_0, 3651, MENU_DetailStatusWnd, MENU_DetailStatusWnd);
			setList(CATEGORY_LINE_1, 447, MENU_MiniMapGfxWnd, MENU_MiniMapGfxWnd);
			setList(CATEGORY_LINE_1, 7464, MENU_Attend, "", ! getUseVipAttendance());
			setList(CATEGORY_LINE_1, 119, MENU_MagicSkillWnd, MENU_MagicSkillWnd);
			setList(CATEGORY_LINE_1, 3506, MENU_TodoListWnd, "");
			setList(CATEGORY_LINE_1, 2074, MENU_Post, "PostWnd");
			setList(CATEGORY_LINE_2, 13832, MENU_ShopFind, "",, GetColor(255, 211, 102, 255));
			setList(CATEGORY_LINE_2, 127, MENU_ActionWnd, MENU_ActionWnd);
			setList(CATEGORY_LINE_2, 13904, MENU_HennaMenuWnd, "");
			setList(CATEGORY_LINE_2, 3776, MENU_ElementalSpiritWnd, "");
			setList(CATEGORY_LINE_2, 118, MENU_QuestTreeWnd, MENU_QuestTreeWnd);
			setList(CATEGORY_LINE_3, 387, MENU_BBS, "BoardWnd");
			setList(CATEGORY_LINE_3, 13249, MENU_YetiWnd, MENU_YetiWnd, ! isKorean);
			setList(CATEGORY_LINE_3, 711, MENU_MacroWnd, MENU_MacroWnd);
			setList(CATEGORY_LINE_3, 13082, MENU_RevengeWnd, "");
			setList(CATEGORY_LINE_4, 3932, MENU_LShop, "", ! isKorean, GetColor(255, 211, 102, 255));
			setList(CATEGORY_LINE_4, 3634, MENU_NShop, MENU_IngameWebWnd, ! isKorean, GetColor(255, 211, 102, 255));
			setList(CATEGORY_LINE_4, 2469, MENU_Productinven, "", ! GetINIBool2Bool("PrimeShop", "UseGoodsInventory"), GetColor(255, 211, 102, 255));
			setList(CATEGORY_LINE_4, 146, MENU_OptionWnd, MENU_OptionWnd);				
		}
		else
		{
			setList(CATEGORY_LINE_0, 3634, MENU_NShop, MENU_IngameWebWnd, ! isKorean, GetColor(255, 211, 102, 255), 1);
			setList(CATEGORY_LINE_0, 2469, MENU_Productinven, "", ! GetINIBool2Bool("PrimeShop", "UseGoodsInventory"), GetColor(255, 211, 102, 255), 1);
			setList(CATEGORY_LINE_0, 13535, MENU_Einhasad, "", false, GetColor(255, 211, 102, 255), 1);
			setList(CATEGORY_LINE_0, 1277, MENU_PcRoom, "", ! GetINIBool2Bool("Localize", "UsePCBangPoint"), GetColor(255, 211, 102, 255), 1);
			setList(CATEGORY_LINE_0, 13832, MENU_ShopFind, "",, GetColor(255, 211, 102, 255), 1);
			setList(CATEGORY_LINE_0, 3137, MENU_AdenaDistributionWnd, "", false, GetColor(255, 211, 102, 255), 1);
			setList(CATEGORY_LINE_1, 687, MENU_TeleportWnd, "");
			setList(CATEGORY_LINE_1, 3651, MENU_DetailStatusWnd, MENU_DetailStatusWnd);
			setList(CATEGORY_LINE_1, 1, MENU_InventoryWnd, MENU_InventoryWnd);
			setList(CATEGORY_LINE_1, 127, MENU_ActionWnd, MENU_ActionWnd);
			setList(CATEGORY_LINE_1, 119, MENU_MagicSkillWnd, MENU_MagicSkillWnd);
			setList(CATEGORY_LINE_1, 118, MENU_QuestTreeWnd, MENU_QuestTreeWnd);
			setList(CATEGORY_LINE_2, 314, MENU_ClanWnd, MENU_ClanWnd);
			setList(CATEGORY_LINE_2, 447, MENU_MiniMapGfxWnd, MENU_MiniMapGfxWnd);
			setList(CATEGORY_LINE_2, 7464, MENU_Attend, "", ! getUseVipAttendance());
			setList(CATEGORY_LINE_2, 3966, MENU_HennaEngraveWndLive, "");
			setList(CATEGORY_LINE_2, 2383, MENU_PersonalConnectionsWnd, MENU_PersonalConnectionsWnd);
			setList(CATEGORY_LINE_2, 2074, MENU_Post, "PostWnd");
			setList(CATEGORY_LINE_3, 645, MENU_ShopLcoinCraftWnd, MENU_ShopLcoinCraftWnd);
			setList(CATEGORY_LINE_3, 2796, MENU_InstancedZone, MENU_InstancedZone);
			setList(CATEGORY_LINE_3, 389, MENU_PartyMatchWnd, MENU_PartyMatchWnd);
			setList(CATEGORY_LINE_3, 13476, MENU_CollectionSystem, "");
			setList(CATEGORY_LINE_3, 14157, MENU_HeroBookWnd, "");
			setList(CATEGORY_LINE_3, 13025, MENU_TimeZoneWnd, "");
			setList(CATEGORY_LINE_4, 3845, MENU_OlympiadWnd, "");
			setList(CATEGORY_LINE_4, 13343, MENU_HomunculusWnd, "");
			setList(CATEGORY_LINE_4, 13733, MENU_DethroneWnd, "");
			setList(CATEGORY_LINE_4, 711, MENU_MacroWnd, MENU_MacroWnd);
			setList(CATEGORY_LINE_4, 13249, MENU_YetiWnd, MENU_YetiWnd, ! isKorean);
			setList(CATEGORY_LINE_4, 146, MENU_OptionWnd, MENU_OptionWnd);
		}
	}
	else
	{
		if(isAden)
		{
			setList(CATEGORY_LINE_0, 14063, MENU_WorldExchangeBuyWnd, "", ! class'WorldExchangeBuyWnd'.static.Inst().ChkUseableServerID());
			setList(CATEGORY_LINE_0, 13025, MENU_TimeZoneWnd, "");
			setList(CATEGORY_LINE_0, 1, MENU_InventoryWnd, MENU_InventoryWnd);
			setList(CATEGORY_LINE_0, 3651, MENU_DetailStatusWnd, MENU_DetailStatusWnd);
			setList(CATEGORY_LINE_0, 447, MENU_MiniMapGfxWnd, MENU_MiniMapGfxWnd);
			setList(CATEGORY_LINE_1, 687, MENU_TeleportWnd, "");
			setList(CATEGORY_LINE_1, 7464, MENU_Attend, "", ! getUseVipAttendance());
			setList(CATEGORY_LINE_1, 119, MENU_MagicSkillWnd, MENU_MagicSkillWnd);
			setList(CATEGORY_LINE_1, 3506, MENU_TodoListWnd, "");
			setList(CATEGORY_LINE_1, 13476, MENU_CollectionSystem, "");
			setList(CATEGORY_LINE_2, 3634, MENU_NShop, MENU_IngameWebWnd, ! isKorean, GetColor(255, 211, 102, 255));
			setList(CATEGORY_LINE_2, 13832, MENU_ShopFind);
			setList(CATEGORY_LINE_2, 127, MENU_ActionWnd, MENU_ActionWnd);
			setList(CATEGORY_LINE_2, 13904, MENU_HennaMenuWnd, "");
			setList(CATEGORY_LINE_2, 3776, MENU_ElementalSpiritWnd, "");
			setList(CATEGORY_LINE_3, 387, MENU_BBS, "BoardWnd");
			setList(CATEGORY_LINE_3, 13249, MENU_YetiWnd, MENU_YetiWnd, ! isKorean);
			setList(CATEGORY_LINE_3, 711, MENU_MacroWnd, MENU_MacroWnd);
			setList(CATEGORY_LINE_3, 13082, MENU_RevengeWnd, "");
			setList(CATEGORY_LINE_3, 2074, MENU_Post, "PostWnd");
			setList(4, 3932, MENU_LShop, "",, GetColor(255, 211, 102, 255));
			setList(CATEGORY_LINE_4, 2469, MENU_Productinven, "", ! GetINIBool2Bool("PrimeShop", "UseGoodsInventory"), GetColor(255, 211, 102, 255));
			setList(CATEGORY_LINE_4, 118, MENU_QuestTreeWnd, MENU_QuestTreeWnd);
			setList(4, 13799, MENU_WorldSiegeRankingWnd, "");
			setList(CATEGORY_LINE_4, 146, MENU_OptionWnd, MENU_OptionWnd);			
		}
		else if(isClassic && ! isAden)
		{
			setList(CATEGORY_LINE_0, 687, MENU_TeleportWnd, "");
			setList(CATEGORY_LINE_0, 13025, MENU_TimeZoneWnd, "");
			setList(CATEGORY_LINE_0, 13476, MENU_CollectionSystem, "");
			setList(CATEGORY_LINE_0, 1, MENU_InventoryWnd, MENU_InventoryWnd);
			setList(CATEGORY_LINE_0, 3651, MENU_DetailStatusWnd, MENU_DetailStatusWnd);
			setList(CATEGORY_LINE_1, 447, MENU_MiniMapGfxWnd, MENU_MiniMapGfxWnd);
			setList(CATEGORY_LINE_1, 7464, MENU_Attend, "", ! getUseVipAttendance());
			setList(CATEGORY_LINE_1, 119, MENU_MagicSkillWnd, MENU_MagicSkillWnd);
			setList(CATEGORY_LINE_1, 3506, MENU_TodoListWnd, "");
			setList(CATEGORY_LINE_1, 2074, MENU_Post, "PostWnd");
			setList(CATEGORY_LINE_2, 13832, MENU_ShopFind);
			setList(CATEGORY_LINE_2, 127, MENU_ActionWnd, MENU_ActionWnd);
			setList(CATEGORY_LINE_2, 13904, MENU_HennaMenuWnd, "");
			setList(CATEGORY_LINE_2, 3776, MENU_ElementalSpiritWnd, "");
			setList(CATEGORY_LINE_2, 5867, MENU_CostumeWnd, "", ! IsUseCostume());
			setList(CATEGORY_LINE_3, 387, MENU_BBS, "BoardWnd");
			setList(CATEGORY_LINE_3, 13249, MENU_YetiWnd, MENU_YetiWnd, ! isKorean);
			setList(CATEGORY_LINE_3, 711, MENU_MacroWnd, MENU_MacroWnd);
			setList(CATEGORY_LINE_3, 13082, MENU_RevengeWnd, "");
			setList(CATEGORY_LINE_4, 3634, MENU_NShop, MENU_IngameWebWnd, ! isKorean, GetColor(255, 211, 102, 255));
			setList(CATEGORY_LINE_4, 3932, MENU_LShop, "", ! GetINIBool2Bool("Localize", "UseOldClassicLCoinShop"), GetColor(255, 211, 102, 255));
			setList(CATEGORY_LINE_4, 2469, MENU_Productinven, "", ! GetINIBool2Bool("PrimeShop", "UseGoodsInventory"), GetColor(255, 211, 102, 255));
			setList(CATEGORY_LINE_4, 118, MENU_QuestTreeWnd, MENU_QuestTreeWnd);
			setList(CATEGORY_LINE_4, 146, MENU_OptionWnd, MENU_OptionWnd);				
		}
		else
		{
			setList(CATEGORY_LINE_0, 3634, MENU_NShop, MENU_IngameWebWnd, ! isKorean, GetColor(255, 211, 102, 255), 1);
			setList(CATEGORY_LINE_0, 2469, MENU_Productinven, "", ! GetINIBool2Bool("PrimeShop", "UseGoodsInventory"), GetColor(255, 211, 102, 255), 1);
			setList(CATEGORY_LINE_0, 13535, MENU_Einhasad, "", ! GetINIBool2Bool("Localize", "UseEinhasad"), GetColor(255, 211, 102, 255), 1);
			setList(CATEGORY_LINE_0, 1277, MENU_PcRoom, "", ! GetINIBool2Bool("Localize", "UsePCBangPoint"), GetColor(255, 211, 102, 255), 1);
			setList(CATEGORY_LINE_0, 13832, MENU_ShopFind, "",, GetColor(255, 211, 102, 255), 1);
			setList(CATEGORY_LINE_0, 3137, MENU_AdenaDistributionWnd, "", false, GetColor(255, 211, 102, 255), 1);
			setList(CATEGORY_LINE_1, 687, MENU_TeleportWnd, "");
			setList(CATEGORY_LINE_1, 3651, MENU_DetailStatusWnd, MENU_DetailStatusWnd);
			setList(CATEGORY_LINE_1, 1, MENU_InventoryWnd, MENU_InventoryWnd);
			setList(CATEGORY_LINE_1, 127, MENU_ActionWnd, MENU_ActionWnd);
			setList(CATEGORY_LINE_1, 119, MENU_MagicSkillWnd, MENU_MagicSkillWnd);
			setList(CATEGORY_LINE_1, 118, MENU_QuestTreeWnd, MENU_QuestTreeWnd);
			setList(CATEGORY_LINE_2, 314, MENU_ClanWnd, MENU_ClanWnd);
			setList(CATEGORY_LINE_2, 447, MENU_MiniMapGfxWnd, MENU_MiniMapGfxWnd);
			setList(CATEGORY_LINE_2, 7464, MENU_Attend, "", ! getUseVipAttendance());
			setList(CATEGORY_LINE_2, 3966, MENU_HennaEngraveWndLive, "");
			setList(CATEGORY_LINE_2, 2383, MENU_PersonalConnectionsWnd, MENU_PersonalConnectionsWnd);
			setList(CATEGORY_LINE_2, 2074, MENU_Post, "PostWnd");
			setList(CATEGORY_LINE_3, 645, MENU_ShopLcoinCraftWnd, MENU_ShopLcoinCraftWnd);
			setList(CATEGORY_LINE_3, 2796, MENU_InstancedZone, MENU_InstancedZone);
			setList(CATEGORY_LINE_3, 389, MENU_PartyMatchWnd, MENU_PartyMatchWnd);
			setList(CATEGORY_LINE_3, 13476, MENU_CollectionSystem, "");
			setList(CATEGORY_LINE_3, 14157, MENU_HeroBookWnd, "");
			setList(CATEGORY_LINE_3, 13025, MENU_TimeZoneWnd, "");
			setList(CATEGORY_LINE_4, 3845, MENU_OlympiadWnd, "");
			setList(CATEGORY_LINE_4, 13343, MENU_HomunculusWnd, "");
			setList(CATEGORY_LINE_4, 13733, MENU_DethroneWnd, "");
			setList(CATEGORY_LINE_4, 711, MENU_MacroWnd, MENU_MacroWnd);
			setList(CATEGORY_LINE_4, 13249, MENU_YetiWnd, MENU_YetiWnd, ! isKorean);
			setList(CATEGORY_LINE_4, 146, MENU_OptionWnd, MENU_OptionWnd);
		}
	}	
}

function onMenuClick(string MenuName)
{
	switch(MenuName)
	{
		case MENU_Attend:
			if(class'UIAPI_WINDOW'.static.IsShowWindow("AttendCheckWnd"))
			{
				class'UIAPI_WINDOW'.static.HideWindow("AttendCheckWnd");			
			}
			else
			{
				AttendCheckWnd(GetScript("AttendCheckWnd"))._Rq_C_EX_VIP_ATTENDANCE_LIST();
			}
			break;
		case MENU_NShop:
			clickNShopMenu();
			break;
		case MENU_OlympiadWnd:
			OlympiadWndMenu();
			break;
		case MENU_OlympiadRandomChallengeWnd:
			if(class'UIAPI_WINDOW'.static.IsShowWindow(MENU_OlympiadRandomChallengeWnd))
			{
				class'UIAPI_WINDOW'.static.HideWindow(MENU_OlympiadRandomChallengeWnd);				
			}
			else
			{
				OlympiadRandomChallengeMenu();
			}
			break;
		case MENU_Ability:
			showHideAbilityWnd();
			break;
		case MENU_RevengeWnd:
			showHideRevengeWnd();
			break;
		case MENU_IngameWebWnd:
			ShowHideIngameWebMain();
			break;
		case MENU_BBS:
			ShowHideIngameWebBBS();
			break;
		case MENU_MacroWnd:
			ShowHideMacroWnd();
			break;
		case MENU_LShop:
			HandleToggleShowShopDailyWnd();
			break;
		case MENU_VitamainService:
			if(class'UIAPI_WINDOW'.static.IsShowWindow("PremiumManagerWnd"))
			{
				class'UIAPI_WINDOW'.static.HideWindow("PremiumManagerWnd");				
			}
			else
			{
				RequestOpenWndWithoutNPC(OPEN_PREMIUM_MANAGER);
			}
			break;
		case MENU_PcRoom:
			HandleToggleShowPCCafeCommuniWnd();
			break;
		case MENU_YetiWnd:
			YetiPCModeChangeWnd(GetScript("YetiPCModeChangeWnd")).setYetiMode(true);
			break;
		case MENU_Qna:
			handleShowQABoardWnd();
			break;
		case MENU_FactionWnd:
			if(class'UIDATA_PLAYER'.static.IsInDethrone())
			{
				getInstanceL2Util().showGfxScreenMessage(GetSystemMessage(4047));				
			}
			else
			{
				toggleWindow(MENU_FactionWnd, true, true);
			}
			break;
		case MENU_ClanSearch:
			toggleWindow(MENU_ClanSearch, true, true);
			break;
		case MENU_Einhasad:
			HandleToggleShowShopDailyWnd();
			break;
		case MENU_RestoreLostPropertyWnd:
			toggleWindow(MENU_RestoreLostPropertyWnd, true, true);
			break;
		case MENU_CollectionSystem:
			OpenCollectionSelectedItem();
			break;
		case MENU_ShopLcoinCraft:
			toggleWindow(MENU_ShopLcoinCraftWnd, true, true);
			break;
		case MENU_ShopFind:
			toggleWindow("PrivateShopFindWnd", true, true);
			break;
		case MENU_HennaMenuWnd:
			if(GetWindowHandle(MENU_HennaMenuWnd).IsShowWindow())
			{
				GetWindowHandle(MENU_HennaMenuWnd).HideWindow();				
			}
			else if(GetWindowHandle("HennaEnchantWnd").IsShowWindow())
			{
				GetWindowHandle("HennaEnchantWnd").HideWindow();					
			}
			else
			{
				toggleWindow(MENU_HennaMenuWnd, true, true);
			}
			break;
		case MENU_TimeZoneWnd:
			if(getInstanceUIData().getIsClassicServer())
			{
				toggleWindow(MENU_TimeZoneWnd, true, true);				
			}
			else if(IsPlayerOnWorldRaidServer())				
			{
				getInstanceL2Util().showGfxScreenMessage(GetSystemMessage(4047));					
			}
			else
			{
				toggleWindow(MENU_TimeZoneWnd, true, true);
			}
			break;
		case MENU_AdenaDistributionWnd:
			if(! class'UIAPI_WINDOW'.static.IsShowWindow("PrivateShopWndReport"))
			{
				CallGFxFunction(MENU_AdenaDistributionWnd, "RequestDivideAdenaStart", "");				
			}
			else
			{
				getInstanceL2Util().showGfxScreenMessage(GetSystemMessage(5104));
			}
			break;
		case MENU_WorldExchangeBuyWnd:
			if(GetWindowHandle("WorldExchangeBuyWnd").IsShowWindow())
			{
				class'WorldExchangeBuyWnd'.static.Inst()._Hide();				
			}
			else if(GetWindowHandle("WorldExchangeRegiWnd").IsShowWindow())
			{
				class'WorldExchangeRegiWnd'.static.Inst()._Hide();					
			}
			else
			{
				class'WorldExchangeBuyWnd'.static.Inst()._Show();
			}
			break;
		case MENU_ElementalSpiritWnd:
			if(class'UIAPI_WINDOW'.static.IsShowWindow("elementalSpiritWnd"))
			{
				class'UIAPI_WINDOW'.static.HideWindow("elementalSpiritWnd");				
			}
			else
			{
				ElementalSpiritWnd(GetScript(MENU_ElementalSpiritWnd))._API_RequestElementalSpiritInfo(true);
			}
			break;
		case MENU_MagicSkillWnd:
			if(IsUseRenewalSkillWnd())
			{
				if(class'UIAPI_WINDOW'.static.IsShowWindow("SkillWnd"))
				{
					class'UIAPI_WINDOW'.static.HideWindow("SkillWnd");					
				}
				else
				{
					class'UIAPI_WINDOW'.static.ShowWindow("SkillWnd");
				}				
			}
			else
			{
				showByShortcutFunction(MenuName);
			}
			break;
		case MENU_CostumeWnd:
			if(class'UIAPI_WINDOW'.static.IsShowWindow(MENU_CostumeWnd))
			{
				class'UIAPI_WINDOW'.static.HideWindow(MENU_CostumeWnd);				
			}
			else
			{
				class'UIAPI_WINDOW'.static.ShowWindow(MENU_CostumeWnd);
			}
			break;
		default:
			showByShortcutFunction(MenuName);
			break;
	}
}

function OpenCollectionSelectedItem()
{
	local CollectionSystem collectionSystemScript;

	collectionSystemScript = CollectionSystem(GetScript(MENU_CollectionSystem));
	collectionSystemScript.API_C_EX_COLLECTION_OPEN_UI();
}

function handleShowQABoardWnd()
{
	local string strParam;

	ParamAdd(strParam, "Index", "8");
	ExecuteEvent(EV_ShowBBS, strParam);
}

function HandleToggleShowShopDailyWnd()
{
	if(IsAdenServer() || getInstanceUIData().getIsClassicServer())
	{
		toggleWindow("ShopLcoinWnd", true, true);		
	}
	else
	{
		toggleWindow("ShopLcoinWnd", true, true);
	}
}

function string getMenuIconTexture(string MenuName)
{
	local string Tex;

	switch(MenuName)
	{
		case MENU_Ability:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_Ability";
			break;
		case MENU_Attend:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_AttendCheack";
			break;
		case MENU_OlympiadRandomChallengeWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_RandomChallenge";
			break;
		case MENU_Productinven:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_Product";
			break;
		case MENU_ShopLcoinCraft:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_ShopLcoinCraft";
			break;
		case MENU_NShop:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_Nshop";
			break;
		case MENU_OlympiadWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_Olympiad";
			break;
		case MENU_RevengeWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_Revenge";
			break;
		case MENU_IngameWebWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_Lineage2Home";
			break;
		case MENU_BBS:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_Bbs";
			break;
		case MENU_ShopSell:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_ShopSell";
			break;
		case MENU_ShopBuy:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_ShopBuy";
			break;
		case MENU_ShopSellAll:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_ShopSellAll";
			break;
		case MENU_ShopSearch:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_ShopSearch";
			break;
		case MENU_ShopFind:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_PrivateShopFind";
			break;
		case MENU_Ability:
			Tex = "L2UI_NewTex.MenuWnd.icon_Nshop";
			break;
		case MENU_Post:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_Post";
			break;
		case MENU_ShopLcoinCraftWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_ShopLcoinCraft";
			break;
		case MENU_PartyMatchWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_PartyMatch";
			break;
		case MENU_PersonalConnectionsWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_PersonalConnection";
			break;
		case MENU_InstancedZone:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_InstancedZone";
			break;
		case MENU_Petition:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_Petition";
			break;
		case MENU_ShortcutAssign:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_ShortcutAssign";
			break;
		case MENU_MacroWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_Macro";
			break;
		case MENU_SiegeCastleInfoWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_CastleInfo";
			break;
		case MENU_ClanSearch:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_ClanSearch";
			break;
		case MENU_FactionWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_FactionMark";
			break;
		case MENU_HennaEngraveWndLive:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_HennaEngrave";
			break;
		case MENU_PlayerAgeWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_Playerage";
			break;
		case MENU_Qna:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_QnA";
			break;
		case MENU_OptionWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_Option";
			break;
		case MENU_Rec:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_MovieRec";
			break;
		case MENU_TimeZoneWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_TimeZone";
			break;
		case MENU_VitamainService:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_VitamainService";
			break;
		case MENU_YetiWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_Yeti";
			break;
		case MENU_DetailStatusWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_Character";
			break;
		case MENU_InventoryWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_Inventory";
			break;
		case MENU_ActionWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_Action";
			break;
		case MENU_MagicSkillWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_Skill";
			break;
		case MENU_QuestTreeWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_Quest";
			break;
		case MENU_ClanWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_Clan";
			break;
		case MENU_LShop:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_LconShop";
			break;
		case MENU_PcRoom:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_PcRoomEvent";
			break;
		case MENU_Shortcut:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_ShortcutAssign";
			break;
		case MENU_PathToAwakening:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_PathToAwakening";
			break;
		case MENU_HomunculusWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_Homunculus";
			break;
		case MENU_Einhasad:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_Einhasad";
			break;
		case MENU_RestoreLostPropertyWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_icon_RestoreLostPropert";
			break;
		case MENU_CollectionSystem:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_Collection";
			break;
		case MENU_WorldSiegeRankingWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_WorldSiege";
			break;
		case MENU_DethroneWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_Dethrone";
			break;
		case MENU_HennaMenuWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_dyepotential";
			break;
		case MENU_HeroBookWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_Herobook";
			break;
		case MENU_AdenaDistributionWnd:
			if(getInstanceUIData().getIsLiveServer())
			{
				Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_AdenaCalculate";				
			}
			else
			{
				Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_AdenaCalculate_Live";
			}
			break;
		case MENU_TeleportWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_TeleportMap";
			break;
		case MENU_TodoListWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_ToDoListWnd";
			break;
		case MENU_WorldExchangeBuyWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_WorldExchangeWnd";
			break;
		case MENU_ElementalSpiritWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_ElementalSpiritWnd";
			break;
		case MENU_MiniMapGfxWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_Map";
			break;
		case MENU_CostumeWnd:
			Tex = "L2UI_NewTex.MenuWnd.MainMenu_Icon_Costume";
			break;
	}
	return Tex;
}

function int getMenuIndex(string MenuName)
{
	local int Index;

	switch(MenuName)
	{
		case MENU_Ability:
			Index = 1;
			break;
		case MENU_Attend:
			Index = 2;
			break;
		case MENU_OlympiadRandomChallengeWnd:
			Index = 3;
			break;
		case MENU_Productinven:
			Index = 4;
			break;
		case MENU_ShopLcoinCraft:
			Index = 5;
			break;
		case MENU_NShop:
			Index = 6;
			break;
		case MENU_OlympiadWnd:
			Index = 7;
			break;
		case MENU_RevengeWnd:
			Index = 8;
			break;
		case MENU_IngameWebWnd:
			Index = 9;
			break;
		case MENU_BBS:
			Index = 10;
			break;
		case MENU_ShopSell:
			Index = 11;
			break;
		case MENU_ShopBuy:
			Index = 12;
			break;
		case MENU_ShopSellAll:
			Index = 13;
			break;
		case MENU_ShopSearch:
			Index = 14;
			break;
		case MENU_ShopFind:
			Index = 15;
			break;
		case MENU_Ability:
			Index = 16;
			break;
		case MENU_Post:
			Index = 17;
			break;
		case MENU_ShopLcoinCraftWnd:
			Index = 18;
			break;
		case MENU_PartyMatchWnd:
			Index = 19;
			break;
		case MENU_PersonalConnectionsWnd:
			Index = 20;
			break;
		case MENU_InstancedZone:
			Index = 21;
			break;
		case MENU_Petition:
			Index = 22;
			break;
		case MENU_ShortcutAssign:
			Index = 23;
			break;
		case MENU_MacroWnd:
			Index = 24;
			break;
		case MENU_SiegeCastleInfoWnd:
			Index = 25;
			break;
		case MENU_ClanSearch:
			Index = 26;
			break;
		case MENU_FactionWnd:
			Index = 27;
			break;
		case MENU_HennaEngraveWndLive:
			Index = 28;
			break;
		case MENU_PlayerAgeWnd:
			Index = 29;
			break;
		case MENU_Qna:
			Index = 30;
			break;
		case MENU_OptionWnd:
			Index = 31;
			break;
		case MENU_Rec:
			Index = 32;
			break;
		case MENU_TimeZoneWnd:
			Index = 33;
			break;
		case MENU_VitamainService:
			Index = 34;
			break;
		case MENU_YetiWnd:
			Index = 35;
			break;
		case MENU_DetailStatusWnd:
			Index = 36;
			break;
		case MENU_InventoryWnd:
			Index = 37;
			break;
		case MENU_ActionWnd:
			Index = 38;
			break;
		case MENU_MagicSkillWnd:
			Index = 39;
			break;
		case MENU_QuestTreeWnd:
			Index = 40;
			break;
		case MENU_ClanWnd:
			Index = 41;
			break;
		case MENU_LShop:
			Index = 42;
			break;
		case MENU_PcRoom:
			Index = 43;
			break;
		case MENU_Shortcut:
			Index = 44;
			break;
		case MENU_PathToAwakening:
			Index = 45;
			break;
		case MENU_HomunculusWnd:
			Index = 46;
			break;
		case MENU_Einhasad:
			Index = 47;
			break;
		case MENU_RestoreLostPropertyWnd:
			Index = 48;
			break;
		case MENU_CollectionSystem:
			Index = 49;
			break;
		case MENU_WorldSiegeRankingWnd:
			Index = 50;
			break;
		case MENU_DethroneWnd:
			Index = 51;
			break;
		case MENU_HennaMenuWnd:
			Index = 52;
			break;
		case MENU_HeroBookWnd:
			Index = 53;
			break;
		case MENU_AdenaDistributionWnd:
			Index = 54;
			break;
		case MENU_TeleportWnd:
			Index = 55;
			break;
		case MENU_TodoListWnd:
			Index = 56;
			break;
		case MENU_WorldExchangeBuyWnd:
			Index = 57;
			break;
		case MENU_ElementalSpiritWnd:
			Index = 58;
			break;
		case MENU_MiniMapGfxWnd:
			Index = 59;
			break;
		case MENU_CostumeWnd:
			Index = 60;
			break;
	}
	return Index;	
}

function string getMenuString(int menuNameIndex)
{
	local string MenuName;

	switch(menuNameIndex)
	{
		case 1:
			MenuName = MENU_Ability;
			break;
		case 2:
			MenuName = MENU_Attend;
			break;
		case 3:
			MenuName = MENU_OlympiadRandomChallengeWnd;
			break;
		case 4:
			MenuName = MENU_Productinven;
			break;
		case 5:
			MenuName = MENU_ShopLcoinCraft;
			break;
		case 6:
			MenuName = MENU_NShop;
			break;
		case 7:
			MenuName = MENU_OlympiadWnd;
			break;
		case 8:
			MenuName = MENU_RevengeWnd;
			break;
		case 9:
			MenuName = MENU_IngameWebWnd;
			break;
		case 10:
			MenuName = MENU_BBS;
			break;
		case 11:
			MenuName = MENU_ShopSell;
			break;
		case 12:
			MenuName = MENU_ShopBuy;
			break;
		case 13:
			MenuName = MENU_ShopSellAll;
			break;
		case 14:
			MenuName = MENU_ShopSearch;
			break;
		case 15:
			MenuName = MENU_ShopFind;
			break;
		case 16:
			MenuName = MENU_Ability;
			break;
		case 17:
			MenuName = MENU_Post;
			break;
		case 18:
			MenuName = MENU_ShopLcoinCraftWnd;
			break;
		case 19:
			MenuName = MENU_PartyMatchWnd;
			break;
		case 20:
			MenuName = MENU_PersonalConnectionsWnd;
			break;
		case 21:
			MenuName = MENU_InstancedZone;
			break;
		case 22:
			MenuName = MENU_Petition;
			break;
		case 23:
			MenuName = MENU_ShortcutAssign;
			break;
		case 24:
			MenuName = MENU_MacroWnd;
			break;
		case 25:
			MenuName = MENU_SiegeCastleInfoWnd;
			break;
		case 26:
			MenuName = MENU_ClanSearch;
			break;
		case 27:
			MenuName = MENU_FactionWnd;
			break;
		case 28:
			MenuName = MENU_HennaEngraveWndLive;
			break;
		case 29:
			MenuName = MENU_PlayerAgeWnd;
			break;
		case 30:
			MenuName = MENU_Qna;
			break;
		case 31:
			MenuName = MENU_OptionWnd;
			break;
		case 32:
			MenuName = MENU_Rec;
			break;
		case 33:
			MenuName = MENU_TimeZoneWnd;
			break;
		case 34:
			MenuName = MENU_VitamainService;
			break;
		case 35:
			MenuName = MENU_YetiWnd;
			break;
		case 36:
			MenuName = MENU_DetailStatusWnd;
			break;
		case 37:
			MenuName = MENU_InventoryWnd;
			break;
		case 38:
			MenuName = MENU_ActionWnd;
			break;
		case 39:
			MenuName = MENU_MagicSkillWnd;
			break;
		case 40:
			MenuName = MENU_QuestTreeWnd;
			break;
		case 41:
			MenuName = MENU_ClanWnd;
			break;
		case 42:
			MenuName = MENU_LShop;
			break;
		case 43:
			MenuName = MENU_PcRoom;
			break;
		case 44:
			MenuName = MENU_Shortcut;
			break;
		case 45:
			MenuName = MENU_PathToAwakening;
			break;
		case 46:
			MenuName = MENU_HomunculusWnd;
			break;
		case 47:
			MenuName = MENU_Einhasad;
			break;
		case 48:
			MenuName = MENU_RestoreLostPropertyWnd;
			break;
		case 49:
			MenuName = MENU_CollectionSystem;
			break;
		case 50:
			MenuName = MENU_WorldSiegeRankingWnd;
			break;
		case 51:
			MenuName = MENU_DethroneWnd;
			break;
		case 52:
			MenuName = MENU_HennaMenuWnd;
			break;
		case 53:
			MenuName = MENU_HeroBookWnd;
			break;
		case 54:
			MenuName = MENU_AdenaDistributionWnd;
			break;
		case 55:
			MenuName = MENU_TeleportWnd;
			break;
		case 56:
			MenuName = MENU_TodoListWnd;
			break;
		case 57:
			MenuName = MENU_WorldExchangeBuyWnd;
			break;
		case 58:
			MenuName = MENU_ElementalSpiritWnd;
			break;
		case 59:
			MenuName = MENU_MiniMapGfxWnd;
			break;
		case 60:
			MenuName = MENU_CostumeWnd;
			break;
	}
	return MenuName;	
}

event OnCilckCheckBoxWithHandle(CheckBoxHandle a_CheckBoxHandle)
{
	local array<MenuButtonSlotStruct> arrayCheckedMenu;
	local int CategoryIndex, buttonIndex;

	CategoryIndex = int(Right(a_CheckBoxHandle.GetParentWindowHandle().GetParentWindowName(), 1));
	buttonIndex = int(Right(a_CheckBoxHandle.GetParentWindowName(), 2));
	if(GetCheckBoxHandle("MenuEntireWnd.MenuCategory" $ string(CategoryIndex) $ ".MenuButtonSlot" $ fillZero(buttonIndex) $ ".checkBox").IsChecked())
	{
		menuSlotArray[CategoryIndex].MenuButtonSlotStructArray[buttonIndex].nSequence = nSquenceAdd;
		nSquenceAdd++;		
	}
	else
	{
		menuSlotArray[CategoryIndex].MenuButtonSlotStructArray[buttonIndex].nSequence = 0;
	}
	arrayCheckedMenu = getCheckboxChecked();
	if(arrayCheckedMenu.Length > 9)
	{
		lockCheckboxChecked();
		getInstanceL2Util().showGfxScreenMessage(GetSystemMessage(13806));		
	}
	else
	{
		unlockCheckboxChecked();
	}
	Menu(GetScript("Menu")).setBTN();	
}

function lockCheckboxChecked()
{
	local int CategoryIndex, buttonIndex;

	for(CategoryIndex = 0; CategoryIndex < menuSlotArray.Length; CategoryIndex++)
	{
		for(buttonIndex = 0; buttonIndex < MAX_CATEGORYBUTTONNUM; buttonIndex++)
		{
			if(buttonIndex < menuSlotArray[CategoryIndex].MenuButtonSlotStructArray.Length)
			{
				if(! GetCheckBoxHandle("MenuEntireWnd.MenuCategory" $ string(CategoryIndex) $ ".MenuButtonSlot" $ fillZero(buttonIndex) $ ".checkBox").IsChecked())
				{
					GetCheckBoxHandle("MenuEntireWnd.MenuCategory" $ string(CategoryIndex) $ ".MenuButtonSlot" $ fillZero(buttonIndex) $ ".checkBox").DisableWindow();
					// [Explicit Continue]
					continue;
				}
				GetCheckBoxHandle("MenuEntireWnd.MenuCategory" $ string(CategoryIndex) $ ".MenuButtonSlot" $ fillZero(buttonIndex) $ ".checkBox").EnableWindow();
			}
		}
	}	
}

function unlockCheckboxChecked()
{
	local int CategoryIndex, buttonIndex;

	for(CategoryIndex = 0; CategoryIndex < menuSlotArray.Length; CategoryIndex++)
	{
		for(buttonIndex = 0; buttonIndex < MAX_CATEGORYBUTTONNUM; buttonIndex++)
		{
			if(buttonIndex < menuSlotArray[CategoryIndex].MenuButtonSlotStructArray.Length)
			{
				GetCheckBoxHandle("MenuEntireWnd.MenuCategory" $ string(CategoryIndex) $ ".MenuButtonSlot" $ fillZero(buttonIndex) $ ".checkBox").EnableWindow();
			}
		}
	}	
}

function array<MenuButtonSlotStruct> getCheckboxChecked()
{
	local int CategoryIndex, buttonIndex;
	local array<MenuButtonSlotStruct> MainMenuButtonSlotStructArray;

	for(CategoryIndex = 0; CategoryIndex < menuSlotArray.Length; CategoryIndex++)
	{
		
		for(buttonIndex = 0; buttonIndex < MAX_CATEGORYBUTTONNUM; buttonIndex++)
		{
			if(buttonIndex < menuSlotArray[CategoryIndex].MenuButtonSlotStructArray.Length)
			{
				if(GetCheckBoxHandle("MenuEntireWnd.MenuCategory" $ string(CategoryIndex) $ ".MenuButtonSlot" $ fillZero(buttonIndex) $ ".checkBox").IsChecked())
				{
					MainMenuButtonSlotStructArray[MainMenuButtonSlotStructArray.Length] = menuSlotArray[CategoryIndex].MenuButtonSlotStructArray[buttonIndex];
				}
			}
		}
	}
	MainMenuButtonSlotStructArray.Sort(SortDelegate);
	return MainMenuButtonSlotStructArray;	
}

function loadOptionIni()
{
	local int CategoryIndex, buttonIndex, i;
	local array<string> ArrayStr;
	local string rStr, isMenuSetting;

	GetINIString("MenuEntireWnd", "e", isMenuSetting, "WindowsInfo.ini");
	if(int(isMenuSetting) == 0)
	{
		setDefaultOptionIni();
	}
	GetINIString("MenuEntireWnd", "a", rStr, "WindowsInfo.ini");
	nSquenceAdd = 0;
	if(rStr != "")
	{
		Split(rStr, ",", ArrayStr);

		for(CategoryIndex = 0; CategoryIndex < menuSlotArray.Length; CategoryIndex++)
		{
			for(buttonIndex = 0; buttonIndex < MAX_CATEGORYBUTTONNUM; buttonIndex++)
			{
				if(buttonIndex < menuSlotArray[CategoryIndex].MenuButtonSlotStructArray.Length)
				{
					GetCheckBoxHandle("MenuEntireWnd.MenuCategory" $ string(CategoryIndex) $ ".MenuButtonSlot" $ fillZero(buttonIndex) $ ".checkBox").SetCheck(false);

					for(i = 0; i < ArrayStr.Length; i++)
					{
						if(getMenuString(int(ArrayStr[i])) == menuSlotArray[CategoryIndex].MenuButtonSlotStructArray[buttonIndex].MenuName)
						{
							menuSlotArray[CategoryIndex].MenuButtonSlotStructArray[buttonIndex].nSequence = i;
							++ nSquenceAdd;
							GetCheckBoxHandle("MenuEntireWnd.MenuCategory" $ string(CategoryIndex) $ ".MenuButtonSlot" $ fillZero(buttonIndex) $ ".checkBox").SetCheck(true);
							// [Explicit Break]
							break;
						}
					}
				}
			}
		}
	}
	if(ArrayStr.Length != nSquenceAdd)
	{
		Debug("----- 전체 메뉴와 메인 메뉴 수량이 달라짐, 다시 저장 하기 ------");
		Debug("menuSlotArray.Length :" @ string(ArrayStr.Length));
		Debug("nSquenceAdd: " @ string(nSquenceAdd));
		saveOptionIni(true);
	}	
}

function setDefaultOptionIni()
{
	local string saveString;
	local ELanguageType Language;
	local bool isKorean;

	Language = GetLanguage();
	isKorean = Language == ELanguageType.LANG_Korean;
	if(isKorean)
	{
		if(getInstanceUIData().getIsClassicServer())
		{
			if(IsAdenServer())
			{
				saveString = string(getMenuIndex(MENU_TeleportWnd)) $ "," $ string(getMenuIndex(MENU_MiniMapGfxWnd)) $ "," $ string(getMenuIndex(MENU_DetailStatusWnd)) $ "," $ string(getMenuIndex(MENU_InventoryWnd)) $ "," $ string(getMenuIndex(MENU_TimeZoneWnd)) $ "," $ string(getMenuIndex(MENU_WorldExchangeBuyWnd)) $ "," $ string(getMenuIndex(MENU_LShop));				
			}
			else
			{
				saveString = string(getMenuIndex(MENU_TeleportWnd)) $ "," $ string(getMenuIndex(MENU_CollectionSystem)) $ "," $ string(getMenuIndex(MENU_MiniMapGfxWnd)) $ "," $ string(getMenuIndex(MENU_DetailStatusWnd)) $ "," $ string(getMenuIndex(MENU_InventoryWnd)) $ "," $ string(getMenuIndex(MENU_TimeZoneWnd)) $ "," $ string(getMenuIndex(MENU_LShop));
			}			
		}
		else
		{
			saveString = string(getMenuIndex(MENU_TeleportWnd)) $ "," $ string(getMenuIndex(MENU_DetailStatusWnd)) $ "," $ string(getMenuIndex(MENU_InventoryWnd)) $ "," $ string(getMenuIndex(MENU_ActionWnd)) $ "," $ string(getMenuIndex(MENU_MagicSkillWnd)) $ "," $ string(getMenuIndex(MENU_QuestTreeWnd)) $ "," $ string(getMenuIndex(MENU_ClanWnd)) $ "," $ string(getMenuIndex(MENU_MiniMapGfxWnd));
		}		
	}
	else
	{
		if(getInstanceUIData().getIsClassicServer())
		{
			if(IsAdenServer())
			{
				saveString = string(getMenuIndex(MENU_TeleportWnd)) $ "," $ string(getMenuIndex(MENU_MiniMapGfxWnd)) $ "," $ string(getMenuIndex(MENU_DetailStatusWnd)) $ "," $ string(getMenuIndex(MENU_InventoryWnd)) $ "," $ string(getMenuIndex(MENU_TimeZoneWnd)) $ "," $ string(getMenuIndex(MENU_WorldExchangeBuyWnd));				
			}
			else
			{
				saveString = string(getMenuIndex(MENU_TeleportWnd)) $ "," $ string(getMenuIndex(MENU_CollectionSystem)) $ "," $ string(getMenuIndex(MENU_MiniMapGfxWnd)) $ "," $ string(getMenuIndex(MENU_DetailStatusWnd)) $ "," $ string(getMenuIndex(MENU_InventoryWnd)) $ "," $ string(getMenuIndex(MENU_TimeZoneWnd));
			}			
		}
		else
		{
			saveString = string(getMenuIndex(MENU_TeleportWnd)) $ "," $ string(getMenuIndex(MENU_DetailStatusWnd)) $ "," $ string(getMenuIndex(MENU_InventoryWnd)) $ "," $ string(getMenuIndex(MENU_ActionWnd)) $ "," $ string(getMenuIndex(MENU_MagicSkillWnd)) $ "," $ string(getMenuIndex(MENU_QuestTreeWnd)) $ "," $ string(getMenuIndex(MENU_ClanWnd)) $ "," $ string(getMenuIndex(MENU_MiniMapGfxWnd));
		}
	}
	SetINIString("MenuEntireWnd", "a", saveString, "WindowsInfo.ini");
	SetINIString("MenuEntireWnd", "b", "1", "WindowsInfo.ini");	
}

function saveOptionIni(optional bool bDoNotNeverUse)
{
	local int i;
	local array<MenuButtonSlotStruct> menuArr;
	local string rStr;

	menuArr = getCheckboxChecked();

	for(i = 0; i < menuArr.Length; i++)
	{
		if(i == 0)
		{
			rStr = string(getMenuIndex(menuArr[i].MenuName));
			// [Explicit Continue]
			continue;
		}
		rStr = rStr $ "," $ string(getMenuIndex(menuArr[i].MenuName));
	}
	Debug("저장된 save str:" @ rStr);
	SetINIString("MenuEntireWnd", "a", rStr, "WindowsInfo.ini");
	if(bDoNotNeverUse == false)
	{
		SetINIString("MenuEntireWnd", "e", "1", "WindowsInfo.ini");
	}	
}

delegate int SortDelegate(MenuButtonSlotStruct A, MenuButtonSlotStruct B)
{
	if(A.nSequence > B.nSequence)
	{
		return -1;
	}
	return 0;	
}

function MenuButtonSlotStruct getSlotStructByMenuName(string MenuName)
{
	local int CategoryIndex, buttonIndex;
	local MenuButtonSlotStruct emptyStruct;

	for(CategoryIndex = 0; CategoryIndex < menuSlotArray.Length; CategoryIndex++)
	{
		for(buttonIndex = 0; buttonIndex < MAX_CATEGORYBUTTONNUM; buttonIndex++)
		{
			if(buttonIndex < menuSlotArray[CategoryIndex].MenuButtonSlotStructArray.Length)
			{
				if(menuSlotArray[CategoryIndex].MenuButtonSlotStructArray[buttonIndex].MenuName == MenuName)
				{
					return menuSlotArray[CategoryIndex].MenuButtonSlotStructArray[buttonIndex];
				}
			}
		}
	}
	return emptyStruct;	
}

function OnLButtonDown(WindowHandle btnHandle, int X, int Y)
{
	local int CategoryIndex, buttonIndex;

	if(Left(btnHandle.GetWindowName(), 7) == "MenuBtn")
	{
		CategoryIndex = int(Right(btnHandle.GetParentWindowHandle().GetParentWindowName(), 1));
		buttonIndex = int(Right(btnHandle.GetParentWindowName(), 2));
		onMenuClick(menuSlotArray[CategoryIndex].MenuButtonSlotStructArray[buttonIndex].MenuName);		
	}
	else if(btnHandle.GetWindowName() == "FixedMenuBtn" && bEditMode == false)
	{
		buttonIndex = int(Right(btnHandle.GetParentWindowName(), 2));
		Debug("btnHandle.GetParentWindowName()" @ btnHandle.GetParentWindowName());
		Debug("buttonIndex" @ string(buttonIndex));
		onMenuClick(fixedMenuSlotStructArray[buttonIndex].MenuName);			
	}
	else
	{
		switch(btnHandle.GetWindowName())
		{
			case "RestartBtn":
				showHideRestart();
				break;
			case "ExitBtn":
				showHideExit();
				break;
			case "HelpBtn":
				ShowHelp();
				break;
			case "EditBtn":
			case "ApplyMenuEditBtn":
				bEditMode = ! bEditMode;
				if(bEditMode)
				{
					nSystemMenuWndFocus = 0;
					refreshMenu();
					setEditMode(true);
					Me.ShowWindow();
					Me.SetFocus();						
				}
				else
				{
					nSystemMenuWndFocus = 0;
					getInstanceL2Util().showGfxScreenMessage(GetSystemMessage(13803));
					saveOptionIni();
					refreshMenu();
					setEditMode(false);
					Me.KillTimer(TIMER_ID);
					Me.SetTimer(TIMER_ID, TIMER_DELAY);
				}
				break;
				case "DefaultMenuBtn":
					MenueClose();
					nSystemMenuWndFocus = 1;
					bEditMode = false;
					setEditMode(false);
					setDefaultOptionIni();
					loadOptionIni();
					Menu(GetScript("Menu")).ShowHideMenus(true);
					refreshMenu();
					getInstanceL2Util().showGfxScreenMessage(GetSystemMessage(13805));
					break;
				case "CancelMenuEditBtn":
					bEditMode = false;
					nSystemMenuWndFocus = 0;
					getInstanceL2Util().showGfxScreenMessage(GetSystemMessage(13804));
					loadOptionIni();
					refreshMenu();
					setEditMode(false);
					Me.KillTimer(TIMER_ID);
					Me.SetTimer(TIMER_ID, TIMER_DELAY);
					break;
				case "OptionBtn":
					onMenuClick(MENU_OptionWnd);
					break;
		}
	}
}

function setEditMode(bool bLock)
{
	local int i;

	if(bLock)
	{
		GetMeButton("RestartBtn").HideWindow();
		GetMeButton("ExitBtn").HideWindow();
		GetMeButton("OptionBtn").HideWindow();
		GetMeButton("EditBtn").HideWindow();
		GetMeButton("DefaultMenuBtn").ShowWindow();
		GetMeButton("CancelMenuEditBtn").ShowWindow();
		GetMeButton("ApplyMenuEditBtn").ShowWindow();

		for(i = 0; i < MAX_FIXMENU_NUM; i++)
		{
			GetWindowHandle("MenuEntireWnd.MenuFixedButtonSlot" $ fillZero(i) $ ".FixedMenuBtn").DisableWindow();
		}		
	}
	else
	{
		GetMeButton("EditBtn").ShowWindow();
		GetMeButton("RestartBtn").ShowWindow();
		GetMeButton("ExitBtn").ShowWindow();
		GetMeButton("ExitBtn").ShowWindow();
		GetMeButton("OptionBtn").ShowWindow();
		GetMeButton("DefaultMenuBtn").HideWindow();
		GetMeButton("CancelMenuEditBtn").HideWindow();
		GetMeButton("ApplyMenuEditBtn").HideWindow();

		for(i = 0; i < MAX_FIXMENU_NUM; i++)
		{
			GetWindowHandle("MenuEntireWnd.MenuFixedButtonSlot" $ fillZero(i) $ ".FixedMenuBtn").EnableWindow();
		}
	}	
}

function ShowHelp()
{
	Shortcut(GetScript(MENU_Shortcut)).HandleShowHelpHtmlWnd();
}

function MenueClose()
{
	Me.HideWindow();
}

function showHideRestart()
{
	ExecuteEvent(EV_OpenDialogRestart);	
}

function showHideExit()
{
	ExecuteEvent(EV_OpenDialogQuit);	
}

function setList(int categoryIndex, int stringNum, string MenuName, optional string tooltipKey, optional bool bDoNotUse, optional Color TextColor, optional int bgType)
{
	if(bDoNotUse)
	{
		return;
	}
	if(TextColor.R == 0 && TextColor.G == 0 && TextColor.B == 0)
	{
		TextColor = GetColor(170, 170, 170, 255);
	}
	addMenu(categoryIndex, GetSystemString(stringNum), MenuName, tooltipKey, "", TextColor, bgType);
}

function addCatogory(int categoryIndex)
{
	menuSlotArray.Insert(menuSlotArray.Length, 1);
	menuSlotArray[menuSlotArray.Length - 1].categoryIndex = categoryIndex;
	menuSlotArray[menuSlotArray.Length - 1].MenuButtonSlotStructArray.Remove(0, menuSlotArray[menuSlotArray.Length - 1].MenuButtonSlotStructArray.Length);
}

function addMenu(int CategoryIndex, string buttonText, string MenuName, string tooltipKey, optional string SpecialParam, optional Color TextColor, optional int bgType)
{
	local int buttonIndex;

	buttonIndex = menuSlotArray[CategoryIndex].MenuButtonSlotStructArray.Length;
	menuSlotArray[CategoryIndex].MenuButtonSlotStructArray.Insert(buttonIndex, 1);
	menuSlotArray[CategoryIndex].MenuButtonSlotStructArray[buttonIndex].CategoryIndex = CategoryIndex;
	menuSlotArray[CategoryIndex].MenuButtonSlotStructArray[buttonIndex].buttonIndex = buttonIndex;
	menuSlotArray[CategoryIndex].MenuButtonSlotStructArray[buttonIndex].MenuName = MenuName;
	menuSlotArray[CategoryIndex].MenuButtonSlotStructArray[buttonIndex].nBGTextureIndex = bgType;
	menuSlotArray[CategoryIndex].MenuButtonSlotStructArray[buttonIndex].buttonTextColor = TextColor;
	class'L2Util'.static.GetEllipsisString(buttonText, 110);
	menuSlotArray[CategoryIndex].MenuButtonSlotStructArray[buttonIndex].buttonText = buttonText;
	menuSlotArray[CategoryIndex].MenuButtonSlotStructArray[buttonIndex].tooltipKey = tooltipKey;
	menuSlotArray[CategoryIndex].MenuButtonSlotStructArray[buttonIndex].SpecialParam = SpecialParam;	
}

function setListFixed(int stringNum, string MenuName, optional string tooltipKey, optional bool bDoNotUse, optional Color TextColor)
{
	if(bDoNotUse)
	{
		return;
	}
	if(TextColor.R == 0 && TextColor.G == 0 && TextColor.B == 0)
	{
		TextColor = GetColor(170, 170, 170, 255);
	}
	addFixedMenu(GetSystemString(stringNum), MenuName, tooltipKey, "", TextColor);	
}

function addFixedMenu(string buttonText, string MenuName, string tooltipKey, optional string SpecialParam, optional Color TextColor)
{
	fixedMenuSlotStructArray.Length = fixedMenuSlotStructArray.Length + 1;
	fixedMenuSlotStructArray[fixedMenuSlotStructArray.Length - 1].MenuName = MenuName;
	fixedMenuSlotStructArray[fixedMenuSlotStructArray.Length - 1].buttonTextColor = TextColor;
	fixedMenuSlotStructArray[fixedMenuSlotStructArray.Length - 1].buttonText = buttonText;
	fixedMenuSlotStructArray[fixedMenuSlotStructArray.Length - 1].tooltipKey = tooltipKey;
	fixedMenuSlotStructArray[fixedMenuSlotStructArray.Length - 1].SpecialParam = SpecialParam;	
}

function string getTooltipShortcutAutoPlay()
{
	return setMainShortcutString(getAssignedKeyGroup(), "AutoPlay");
}

function setFixedMenuWindow(int buttonIndex, MenuButtonSlotStruct slotStruct)
{
	local string controlPath, ToolTipString;

	controlPath = "MenuEntireWnd.MenuFixedButtonSlot" $ fillZero(buttonIndex);
	GetTextBoxHandle(controlPath $ ".MenuNameTextBox").SetText(slotStruct.buttonText);
	textBoxShortStringWithTooltip(GetTextBoxHandle(controlPath $ ".MenuNameTextBox"), false, -6);
	GetTextBoxHandle(controlPath $ ".MenuNameTextBox").SetTextColor(slotStruct.buttonTextColor);
	ToolTipString = setMainShortcutString(getAssignedKeyGroup(), slotStruct.tooltipKey);
	GetButtonHandle(controlPath $ ".FixedMenuBtn").ClearTooltip();
	if (ToolTipString != "")
	{
		GetButtonHandle(controlPath $ ".FixedMenuBtn").SetTooltipCustomType(MakeTooltipSimpleColorText(ToolTipString, getInstanceL2Util().White));
	}
	GetTextureHandle(controlPath $ ".MenuIcon").SetTexture(getMenuIconTexture(slotStruct.MenuName));
}

function setMenuWindow(int CategoryIndex, int buttonIndex, MenuButtonSlotStruct slotStruct)
{
	local string controlPath, ToolTipString;

	controlPath = "MenuEntireWnd.MenuCategory" $ string(CategoryIndex) $ ".MenuButtonSlot" $ fillZero(buttonIndex);
	GetTextBoxHandle(controlPath $ ".MenuNameTextBox").SetFontIDByName("hs10");
	GetTextBoxHandle(controlPath $ ".MenuNameTextBox").SetText(slotStruct.buttonText);
	textBoxShortStringWithTooltip(GetTextBoxHandle(controlPath $ ".MenuNameTextBox"), false, -6);
	GetTextBoxHandle(controlPath $ ".MenuNameTextBox").SetTextColor(slotStruct.buttonTextColor);
	if(slotStruct.nBGTextureIndex == BG_TYPE2)
	{
		GetTextureHandle(controlPath $ ".MenuBgTexture").SetTexture(BG_TYPE2_TEXTURE);		
	}
	else
	{
		GetTextureHandle(controlPath $ ".MenuBgTexture").SetTexture(BG_TYPE1_TEXTURE);
	}
	ToolTipString = setMainShortcutString(getAssignedKeyGroup(), slotStruct.tooltipKey);
	GetButtonHandle(controlPath $ ".MenuBtn").ClearTooltip();
	if(ToolTipString != "")
	{
		GetButtonHandle(controlPath $ ".MenuBtn").SetTooltipCustomType(MakeTooltipSimpleColorText(ToolTipString, getInstanceL2Util().White));
	}
	if(bEditMode)
	{
		GetCheckBoxHandle(controlPath $ ".checkBox").ShowWindow();
		GetButtonHandle(controlPath $ ".MenuBtn").HideWindow();		
	}
	else
	{
		GetButtonHandle(controlPath $ ".MenuBtn").ShowWindow();
		GetCheckBoxHandle(controlPath $ ".checkBox").HideWindow();
		GetTextureHandle(controlPath $ ".MenuIcon").SetTexture(getMenuIconTexture(slotStruct.MenuName));
	}	
}

function refreshMenu()
{
	local int categoryIndex, buttonIndex, i;

	for (categoryIndex = 0; categoryIndex < menuSlotArray.Length; categoryIndex++)
	{
		if(lastButtonCount < menuSlotArray[categoryIndex].MenuButtonSlotStructArray.Length)
		{
			lastButtonCount = menuSlotArray[categoryIndex].MenuButtonSlotStructArray.Length;
		}

		for (buttonIndex = 0; buttonIndex < MAX_CATEGORYBUTTONNUM; buttonIndex++)
		{
			if (buttonIndex < menuSlotArray[categoryIndex].MenuButtonSlotStructArray.Length)
			{
				GetWindowHandle("MenuEntireWnd.MenuCategory" $ string(categoryIndex) $ ".MenuButtonSlot" $ fillZero(buttonIndex)).ShowWindow();
  				setMenuWindow(categoryIndex, buttonIndex, menuSlotArray[categoryIndex].MenuButtonSlotStructArray[buttonIndex]);
			}
			else
			{
				GetWindowHandle("MenuEntireWnd.MenuCategory" $ string(categoryIndex) $ ".MenuButtonSlot" $ fillZero(buttonIndex)).HideWindow();
			}
		}
	}

	for(i = 0; i < MAX_FIXMENU_NUM; i++)
	{
		GetWindowHandle("MenuEntireWnd.MenuFixedButtonSlot" $ fillZero(i)).HideWindow();
	}
	
	for(i = 0; i < fixedMenuSlotStructArray.Length; i++)
	{
		GetWindowHandle("MenuEntireWnd.MenuFixedButtonSlot" $ fillZero(i)).ShowWindow();
		setFixedMenuWindow(i, fixedMenuSlotStructArray[i]);
	}
	
	resizeMenuWnd();
	if(getInstanceUIData().getIsLiveServer())
	{
		AutoUseItemWnd(GetScript("AutoUseItemWnd")).setShortcutTooltip(getTooltipShortcutAutoPlay());
		AutoUseItemWndMin(GetScript("AutoUseItemWndMin")).setShortcutTooltip(getTooltipShortcutAutoPlay());
	}
	else
	{
		AutomaticPlay(GetScript("AutomaticPlay")).setShortcutTooltip(getTooltipShortcutAutoPlay());
	}
	Menu(GetScript("Menu")).setBTN();
}

function resizeMenuWnd()
{
	local Rect R, C, B;
	local int i;

	C = GetWindowHandle("MenuEntireWnd.MenuCategory0").GetRect();
	R = GetWindowHandle("MenuEntireWnd.MenuCategory0.MenuButtonSlot" $ fillZero(lastButtonCount)).GetRect();
	B = menuBgTexture.GetRect();
	Debug("lastButtonCount" @ string(lastButtonCount));

	for (i = 0; i < MAX_CATEGORY; i++)
	{
		GetWindowHandle("MenuEntireWnd.MenuCategory" $ string(i)).SetWindowSize(C.nWidth, R.nY - C.nY);
	}
	Me.SetWindowSize(firstRect.nWidth, (R.nY - C.nY) + (getAddHeight()));
	menuBgTexture.SetWindowSize(B.nWidth, (R.nY - C.nY) + CATEGORYBG_ADD_HEIGHT);
}

function int getAddHeight()
{
	if(getInstanceUIData().getIsClassicServer())
	{
		if(IsAdenServer())
		{
			return ADD_HEIGHT_ADEN;			
		}
		else
		{
			return ADD_HEIGHT_TALKINGISLAND;
		}
	}
	return ADD_HEIGHT_LIVE;	
}

function showByShortcutFunction(string MenuName)
{
	local string param;

	ParamAdd(param, "Name", MenuName);
	ExecuteEvent(EV_ShowWindow, param);
}

function HandleToggleShowPCCafeCommuniWnd()
{
	if (getInstanceL2Util().getIsPrologueGrowType())
	{
		AddSystemMessage(4533);
	}
	else if(class'UIAPI_WINDOW'.static.IsShowWindow("NPCDialogWnd"))
	{
		class'UIAPI_WINDOW'.static.HideWindow("NPCDialogWnd");			
	}
	else
	{
		RequestOpenWndWithoutNPC(OPEN_PCCAFE_HTML);
	}
}

function ShowHideMacroWnd()
{
	ExecuteEvent(EV_MacroShowListWnd);
}

function ShowHideIngameWebBBS()
{
	local string param;

	ParamAdd(param, "Category", "bbs");
	ExecuteEvent(EV_InGameWebWnd_Info, param);
}

function ShowHideIngameWebMain()
{
	local string param;

	ParamAdd(param, "Category", "main");
	ExecuteEvent(EV_InGameWebWnd_Info, param);
}

function showHideRevengeWnd()
{
	if (Class 'UIAPI_WINDOW'.static.IsShowWindow(MENU_RevengeWnd))
	{
		Class 'UIAPI_WINDOW'.static.HideWindow(MENU_RevengeWnd);
	}
	else
	{
		class'UIAPI_WINDOW'.static.ShowWindow(MENU_RevengeWnd);
	}
}

function clickNShopMenu()
{
	NoticeWnd(GetScript("NoticeWnd")).showHideL2InGameWeb(MENU_NShop, "");
}

function showHideAbilityWnd()
{
	if (GetGameStateName() == "ARENABATTLESTATE")
	{
		getInstanceL2Util().showGfxScreenMessage(GetSystemMessage(5575));
		return;
	}
	if (Class 'UIAPI_WINDOW'.static.IsShowWindow("AbilityWnd"))
	{
		Class 'UIAPI_WINDOW'.static.HideWindow("AbilityWnd");
	}
	else
	{
		CallGFxFunction("AbilityWnd", "setShow", "");
	}
}

function OlympiadWndMenu()
{
	if (Class 'UIAPI_WINDOW'.static.IsShowWindow(MENU_OlympiadWnd))
	{
		Class 'UIAPI_WINDOW'.static.HideWindow(MENU_OlympiadWnd);
	}
	else
	{
		RequestOlympiadRecord();
	}
}

function OlympiadRandomChallengeMenu()
{
	local array<byte> stream;
	local UIPacket._C_EX_OLYMPIAD_UI packet;

	packet.cGameRuleType = GameRuleType.GRT_TEAM;
	if (!Class 'UIPacket'.static.Encode_C_EX_OLYMPIAD_UI(stream, packet))
	{
		return;
	}
	Class 'UIPacket'.static.RequestUIPacket(class'UIPacket'.const.C_EX_OLYMPIAD_UI, stream);
}

function int b2i(bool Value)
{
	if(Value)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

function bool i2b(int Value)
{
	if(Value == 0)
	{
		return false;
	}
	else
	{
		return true;
	}
}

function bool GetINIBool2Bool(string Category, string ItemName)
{
	local int bValue;

	if(! GetINIBool(Category, ItemName, bValue, "L2.ini"))
	{
		return false;
	}
	return i2b(bValue);
}

function bool getUseVipAttendance()
{
	return IsAttendanceSystemEnable();
}

function KillIsWorkingTimerTimer()
{
	bIsWorkingTimer = false;
	Me.KillTimer(TIMER_ID);
}

function string fillZero(int Num)
{
	if (Num <= 9)
	{
		return "0" $ string(Num);
	}
	return string(Num);
}

function string getAssignedKeyGroup()
{
	if (GetChatFilterBool("global", "EnterChatting"))
	{
		return "TempStateShortcut";
	}
	return "GamingStateShortcut";
}

function string setMainShortcutString(string GroupName, string commandName, optional bool B)
{
	local ShortcutCommandItem commandItem;
	local OptionWnd optionWndScript;
	local string strShort;

	if(commandName == "")
	{
		return "";
	}
	optionWndScript = OptionWnd(GetScript(MENU_OptionWnd));
	if(commandName == "AutoPlay" || commandName == "NextTargetModeChange")
	{
		class'ShortcutAPI'.static.GetAssignedKeyFromCommand(GroupName, commandName, commandItem);		
	}
	else
	{
		class'ShortcutAPI'.static.GetAssignedKeyFromCommand(GroupName, "ShowWindow Name=" $ commandName, commandItem);
	}
	if(commandItem.subkey1 == "" && commandItem.subkey2 == "" && commandItem.Key == "")
	{
		if(commandName == "AutoPlay" || commandName == "NextTargetModeChange")
		{
			class'ShortcutAPI'.static.GetAssignedKeyFromCommand("GamingStateShortcut", commandName, commandItem);			
		}
		else
		{
			class'ShortcutAPI'.static.GetAssignedKeyFromCommand("GamingStateShortcut", "ShowWindow Name=" $ commandName, commandItem);
		}
		if(commandItem.subkey1 == "" && commandItem.subkey2 == "" && commandItem.Key == "")
		{
			strShort = "";			
		}
		else
		{
			if(B)
			{
				strShort = strShort $ "n";
			}
			strShort = strShort $ "<" $ GetSystemString(1523) $ ": ";
		}		
	}
	else
	{
		if(B)
		{
			strShort = strShort $ "n";
		}
		strShort = strShort $ "<" $ GetSystemString(1523) $ ": ";
	}
	if(commandItem.subkey1 != "")
	{
		strShort = strShort $ optionWndScript.GetUserReadableKeyName(commandItem.subkey1) $ "+";
	}
	if(commandItem.subkey2 != "")
	{
		strShort = strShort $ optionWndScript.GetUserReadableKeyName(commandItem.subkey2) $ "+";
	}
	if(commandItem.Key != "")
	{
		if(commandName == MENU_InventoryWnd)
		{
			strShort = strShort $ optionWndScript.GetUserReadableKeyName(commandItem.Key) $ ",";			
		}
		else
		{
			strShort = strShort $ optionWndScript.GetUserReadableKeyName(commandItem.Key) $ ">";
		}
	}
	if(commandName == MENU_InventoryWnd)
	{
		class'ShortcutAPI'.static.GetAssignedKeyFromCommand("GamingStateShortcut", "TabShowInventoryWindow", commandItem);
		if(commandItem.subkey1 != "")
		{
			strShort = strShort $ optionWndScript.GetUserReadableKeyName(commandItem.subkey1) $ "+";
		}
		if(commandItem.subkey2 != "")
		{
			strShort = strShort $ optionWndScript.GetUserReadableKeyName(commandItem.subkey2) $ "+";
		}
		if(commandItem.Key != "")
		{
			strShort = strShort $ optionWndScript.GetUserReadableKeyName(commandItem.Key) $ ">";
		}
	}
	return strShort;	
}

private function ShowDialogAskInit()
{
	DialogShow(DialogModalType_Modalless, DialogType_OKCancel, GetSystemMessage(13828), string(self));
	class'DialogBox'.static.Inst().SetDefaultAction(EDefaultCancel);
	class'DialogBox'.static.Inst().DelegateOnOK = HandleDialogOK;
	class'DialogBox'.static.Inst().DelegateOnHide = HandleDialogOnHide;	
}

private function HandleDialogOK()
{
	Debug("ok");
	nSystemMenuWndFocus = 1;
	bEditMode = false;
	setEditMode(false);
	setDefaultOptionIni();
	loadOptionIni();
	Menu(GetScript("Menu")).ShowHideMenus(true);
	refreshMenu();
	getInstanceL2Util().showGfxScreenMessage(GetSystemMessage(13805));	
}

private function HandleDialogOnHide()
{
	Debug("cancel");	
}

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