class BuilderCmdWnd extends UICommonAPI;

var string m_WindowName;
var WindowHandle Me;

var ButtonHandle collision_button;
var ButtonHandle npcinfo_button;
var ButtonHandle stat_button;
var ButtonHandle rmode_button;
var ButtonHandle init_button;
var CheckBoxHandle m_CheckBoxBoneName;
var ComboBoxHandle m_ComboBoneName;
var ComboBoxHandle Reload_ComboBox;
var ButtonHandle Reload_button;

var ButtonHandle AVE_addButton;
var ButtonHandle AVE_delButton;
var ButtonHandle AVE_clearButton;
var ButtonHandle NpcSummon_Button;
var ButtonHandle UseSkill_button;
var ButtonHandle DefaultNpc_button;
var ButtonHandle ComeOn_button;
var ButtonHandle KillNpc_button;
var ButtonHandle SetParam_button;

var ButtonHandle SetSpeed_button;
var ButtonHandle SetRace_button;
var ButtonHandle Clone_button;
var ButtonHandle JobTree_button;
var ButtonHandle Search_button;

var ButtonHandle distance_button;
var ButtonHandle skillMaster_button;
var ButtonHandle itemMaster_button;
var ButtonHandle dex_1_button;
var ButtonHandle dex_2_button;
var ButtonHandle dex_3_button;
var ButtonHandle resetSkill_button;
var ButtonHandle allSkill_button;
var ButtonHandle yebis_button;
var EditBoxHandle AveId_EditBox;
var EditBoxHandle NpcId_EditBox;
var EditBoxHandle SkillId_EditBox;
var EditBoxHandle Param_EditBox;

var EditBoxHandle Speed_EditBox;
var SliderCtrlHandle sliderShowRange;
var TextBoxHandle txtShowRange;
var SliderCtrlHandle sliderSetTime;
var TextBoxHandle txtSetTime;
var CheckBoxHandle checkBoxRange;
var CheckBoxHandle checkBoxSetTime;

function OnLoad()
{
	SetClosingOnESC();
	Me = GetWindowHandle("BuilderCmdWnd");
	if(getInstanceUIData().getIsLiveServer())
	{
		setWindowTitleByString("BuilderCommand" @ "(Live)");		
	}
	else if(getInstanceUIData().IsAdenServer())
	{
		setWindowTitleByString("BuilderCommand" @ "(Aden)");			
	}
	else
	{
		setWindowTitleByString("BuilderCommand" @ "(Classic)");
	}
	collision_button = GetButtonHandle(m_WindowName $ ".collision_button");
	npcinfo_button = GetButtonHandle(m_WindowName $ ".npcinfo_button");
	stat_button = GetButtonHandle(m_WindowName $ ".stat_button");
	rmode_button = GetButtonHandle(m_WindowName $ ".rmode_button");
	init_button = GetButtonHandle(m_WindowName $ ".init_button");
	distance_button = GetButtonHandle(m_WindowName $ ".distance_button");
	m_CheckBoxBoneName = GetCheckBoxHandle(m_WindowName $ ".BoneName_CheckBox");
	m_ComboBoneName = GetComboBoxHandle(m_WindowName $ ".BoneName_ComboBox");
	Reload_ComboBox = GetComboBoxHandle(m_WindowName $ ".Reload_ComboBox");
	Reload_ComboBox.AddString("AVE");
	Reload_ComboBox.AddString("AdditionalEffect");
	Reload_ComboBox.AddString("ArmorGrp");
	Reload_ComboBox.AddString("WeaponGrp");
	Reload_ComboBox.AddString("EtcItemGrp");
	Reload_ComboBox.AddString("SkillGrp");
	Reload_ComboBox.AddString("NpcGrp");
	Reload_ComboBox.AddString("HairExGrp");
	Reload_ComboBox.AddString("FaceExGrp");
	Reload_ComboBox.AddString("----------------");
	Reload_ComboBox.AddString("Effect");
	Reload_ComboBox.AddString("SkillEffect");
	Reload_ComboBox.AddString("LineageNpc");
	Reload_ComboBox.AddString("LineageMonster");
	Reload_ComboBox.AddString("LineageWarrior");
	Reload_ComboBox.AddString("----------------");
	Reload_ComboBox.AddString("Skill_Data");
	Reload_ComboBox.AddString("Item_Data");
	Reload_ComboBox.AddString("Npc_Data");
	AVE_addButton = GetButtonHandle(m_WindowName $ ".AVE_addButton");
	AVE_delButton = GetButtonHandle(m_WindowName $ ".AVE_delButton");
	AVE_clearButton = GetButtonHandle(m_WindowName $ ".AVE_delButton");
	AveId_EditBox = GetEditBoxHandle(m_WindowName $ ".AveId_EditBox");
	AveId_EditBox.SetString("17");
	NpcSummon_Button = GetButtonHandle(m_WindowName $ ".NpcSummon_Button");
	NpcId_EditBox = GetEditBoxHandle(m_WindowName $ ".NpcId_EditBox");
	if(getInstanceUIData().getIsLiveServer())
	{
		NpcId_EditBox.SetString("18912");		
	}
	else if(getInstanceUIData().IsAdenServer())
	{
		NpcId_EditBox.SetString("18002");			
	}
	else
	{
		NpcId_EditBox.SetString("18002");
	}
	UseSkill_button = GetButtonHandle(m_WindowName $ ".UseSkill_button");
	SkillId_EditBox = GetEditBoxHandle(m_WindowName $ ".SkillId_EditBox");
	SkillId_EditBox.SetString("129 1 0");
	DefaultNpc_button = GetButtonHandle(m_WindowName $ ".DefaultNpc_button");
	ComeOn_button = GetButtonHandle(m_WindowName $ ".ComeOn_button");
	KillNpc_button = GetButtonHandle(m_WindowName $ ".KillNpc_button");
	SetParam_button = GetButtonHandle(m_WindowName $ ".SetParam_button");
	SetSpeed_button = GetButtonHandle(m_WindowName $ ".SetSpeed_button");
	Search_button = GetButtonHandle(m_WindowName $ ".search_button");
	Param_EditBox = GetEditBoxHandle(m_WindowName $ ".Param_EditBox");
	Param_EditBox.SetString("lv 85");
	Speed_EditBox = GetEditBoxHandle(m_WindowName $ ".Speed_EditBox");
	Speed_EditBox.SetString("2");
	Clone_button = GetButtonHandle(m_WindowName $ ".Clone_button");
	JobTree_button = GetButtonHandle(m_WindowName $ ".JobTree_button");
	sliderShowRange = GetSliderCtrlHandle(m_WindowName $ ".sliderShowRange");
	txtShowRange = GetTextBoxHandle(m_WindowName $ ".txtShowRange");
	checkBoxRange = GetCheckBoxHandle(m_WindowName $ ".checkBoxRange");
	sliderSetTime = GetSliderCtrlHandle(m_WindowName $ ".sliderSetTime");
	txtSetTime = GetTextBoxHandle(m_WindowName $ ".txtSetTime");
	checkBoxSetTime = GetCheckBoxHandle(m_WindowName $ ".checkBoxSetTime");
	skillMaster_button = GetButtonHandle(m_WindowName $ ".skillMaster_button");
	itemMaster_button = GetButtonHandle(m_WindowName $ ".itemMaster_button");
	dex_1_button = GetButtonHandle(m_WindowName $ ".dex_1_button");
	dex_2_button = GetButtonHandle(m_WindowName $ ".dex_2_button");
	dex_3_button = GetButtonHandle(m_WindowName $ ".dex_3_button");
}

function OnClickReloadButton()
{
	local int Selected;
	Selected = Reload_ComboBox.GetSelectedNum();
	switch(Selected)
	{
		case 0:
		//AbnormalDefaultEffect
		//AbnormalEdgeEffectData
		//EventLookChange
			ExecuteCommand("///ave_reload");
			break;
		case 1:
			ExecuteCommand("///additionaleffect_reload");
			break;
		case 2:
			ExecuteCommand("///armorgrp_reload");
			break;
		case 3:
			ExecuteCommand("///weapongrp_reload");
			break;
		case 4:
			ExecuteCommand("///etcitemgrp_reload");
			break;
		case 5:
			ExecuteCommand("///skillgrp_reload");
			break;
		case 6:
			ExecuteCommand("///npcgrp_reload");
			break;
		case 7:
			ExecuteCommand("///hairexgrp_reload");
			break;
		case 8:
			ExecuteCommand("///faceexgrp_reload");
			break;
		case 9:
			break;
		case 10:
			ExecuteCommand("///reloade");
			break;
		case 11:
			ExecuteCommand("///reloadse");
			break;
		case 12:
			ExecuteCommand("///reloadnpc");
			break;
		case 13:
			ExecuteCommand("///reloadmonster");
			break;
		case 14:
			ExecuteCommand("///reloadwarrior");
			break;
		case 15:
			break;
		case 16:
			ExecuteCommand("//reload_skill_data");
			break;
		case 17:
			ExecuteCommand("//reload_item_data");
			break;
		case 18:
			ExecuteCommand("//reload_npc_data");
			break;
	}
}

function OnClickButton(string a_ButtonID)
{
	switch(a_ButtonID)
	{
		case "Reload_button":
			OnClickReloadButton();
			break;
		case "collision_button":
			ExecuteCommand("///show radii");
			break;
		case "npcinfo_button":
			ExecuteCommand("//debug .");
			break;
		case "nameTag_button":
			ExecuteCommand("///show name");
			break;
		case "stat_button":
			ExecuteCommand("///stat l2");
			break;
		case "rmode_button":
			if(rmode_button.GetButtonName() == "Wireframe")
			{
				ExecuteCommand("///rmode 1");
				rmode_button.SetNameText("Lighting");
			}
			else
			{
				ExecuteCommand("///rmode 5");
				rmode_button.SetNameText("Wireframe");
			}
			break;
		case "init_button":
			ExecuteCommand("//hide off");
			ExecuteCommand("//undying on");
			ExecuteCommand("///autocom");
			break;
		case "AVE_addButton":
			ExecuteCommand("///aa type=" @ AveId_EditBox.GetString());
			break;
		case "AVE_delButton":
			ExecuteCommand("///da type=" @ AveId_EditBox.GetString());
			break;
		case "AVE_clearButton":
			ExecuteCommand("///aa type=none");
			break;
		case "NpcSummon_Button":
			ExecuteCommand("//summon 10" $ NpcId_EditBox.GetString());
			break;
		case "UseSkill_Button":
			ExecuteCommand("//npc_use_skill" @ SkillId_EditBox.GetString());
			break;
		case "DefaultNpc_button":
			ExecuteCommand("//setai default_npc");
			break;
		case "ComeOn_Button":
			ExecuteCommand("//come_to_me 1");
			break;
		case "KillNpc_Button":
			ExecuteCommand("//killnpc");
			break;
		case "SetParam_button":
			ExecuteCommand("//setparam " @ Param_EditBox.GetString());
			break;
		case "dex_1_button":
			ExecuteCommand("//setparam_me dex 50");
			break;
		case "dex_2_button":
			ExecuteCommand("//setparam_me dex 100");
			break;
		case "dex_3_button":
			ExecuteCommand("//setparam_me dex 200");
			break;
		case "SetSpeed_button":
			ExecuteCommand("//gmspeed" @ Speed_EditBox.GetString());
			break;
		case "Clone_button":
			ExecuteCommand("///spawnpc copy num=1");
			break;
		case "JobTree_button":
			ExecuteCommand("/target %self");
			ShowWindow("JobTreeWnd");
			break;
		case "Search_button":
			ExecuteCommand("///searchobject");
			break;
		case "Distance_button":
			ExecuteCommand("//distance");
			break;
		case "resetSkill_button":
			ExecuteCommand("/target %self");
			ExecuteCommand("//reset_skill");
			break;
		case "allSkill_button":
			ExecuteCommand("//set_skill_all_me");
			break;
		case "skillMaster_button":
			if(skillMaster_button.GetButtonName() == "SkillMaster On")
			{
				ExecuteCommand("//skill_master on");
				skillMaster_button.SetNameText("SkillMaster Off");
				break;				
			}
			else
			{
				ExecuteCommand("//skill_master off");
				skillMaster_button.SetNameText("SkillMaster On");
				break;
			}
		case "itemMaster_button":
			if(itemMaster_button.GetButtonName() == "ItemMaster On")
			{
				ExecuteCommand("//item_master on");
				itemMaster_button.SetNameText("ItemMaster Off");
				break;				
			}
			else
			{
				ExecuteCommand("//item_master off");
				itemMaster_button.SetNameText("ItemMaster On");
				break;
			}
		case "yebis_button":
			ExecuteCommand("///sw name=YebisCmdWnd");
			break;
	}
}

function OnModifyCurrentTickSliderCtrl(string strID, int iCurrentTick)
{
	local float ftime;
	local int Range;

	switch(strID)
	{
		case "sliderShowRange":
			Range = (sliderShowRange.GetCurrentTick() * 10) + 10;
			txtShowRange.SetText(string(Range));
			if(checkBoxRange.IsChecked())
			{
				ExecuteCommand("///show_range" @ string(Range));
			}
			break;
		case "sliderSetTime":
			if(checkBoxSetTime.IsChecked())
			{
				ftime = float(sliderSetTime.GetCurrentTick()) / 10.f;
				SetEnvTime(ftime);
				txtSetTime.SetText(string(ftime));
			}
			break;
	}
}
function OnComboBoxItemSelected(string strID, int IndexID)
{
	switch(strID)
	{
		case "BoneName_ComboBox":
			if(IndexID == 0)
			{
				if(m_CheckBoxBoneName.IsChecked())
				{
					ExecuteCommand("///rend reset");
					ExecuteCommand("///rend bone");
					ExecuteCommand("///rend bonename");
				}
			}
			else
			{
				class'UIDATA_PAWNVIEWER'.static.ShowSelectedBone(m_ComboBoneName.GetString(IndexID));
			}
			break;
	}
}

function OnClickCheckBox(string strID)
{
	switch(strID)
	{
		case "BoneName_CheckBox":
			if(m_CheckBoxBoneName.IsChecked())
			{
				ExecuteCommand("///rend bone");
				ExecuteCommand("///rend bonename");
			}
			else
			{
				ExecuteCommand("///rend reset");
			}
			SetBoneList();
			break;
		case "checkBoxRange":
			if(checkBoxRange.IsChecked())
			{
				ExecuteCommand("///show_range" @ txtShowRange.GetText());				
			}
			else
			{
				ExecuteCommand("///show_range none");
			}
			break;
	}
}

function SetBoneList()
{
	local array<string> BoneNameList;
	local int Index;

	m_ComboBoneName.Clear();
	m_ComboBoneName.AddString("Show All Bones");
	if(m_CheckBoxBoneName.IsChecked())
	{
		class'UIDATA_PAWNVIEWER'.static.GetBoneNameList(BoneNameList);
		for(Index = 0; index < BoneNameList.Length; Index++)
		{
			m_ComboBoneName.AddString(BoneNameList[Index]);
		}
	}
}

function OnReceivedCloseUI()
{
	PlayConsoleSound(IFST_WINDOW_CLOSE);
	GetWindowHandle(m_WindowName).HideWindow();
}

defaultproperties
{
	m_WindowName="BuilderCmdWnd"
}
