/*------------------------------------------------------------------------------------------------------------------------

 제목     : 무기 옵션 부여 생성 빌더 UI
<예제 라이브> 
- 무기- 
A : 46824
S 이상: 
17416	[헬리오스 셰이퍼]
17417	[헬리오스 커터]
17418	[헬리오스 슬래셔]
17419	[헬리오스 어벤져]
17420	[헬리오스 파이터]
17421	[헬리오스 스토머]
17422	[헬리오스 스로워]
17423	[헬리오스 슈트제]
17424	[헬리오스 버스터]
17425	[헬리오스 캐스터]
17426	[헬리오스 레트리뷰터]
17427	[헬리오스 듀얼소드]
17428	[헬리오스 듀얼대거]
17429	[헬리오스 듀얼블런트]



- 방어구 -
A : 46922
S 이상 : 
19570	[아이디오스 헬멧]
19571	[아이디오스 흉갑]
19572	[아이디오스 각반]
19573	[아이디오스 건틀렛]
19574	[아이디오스 부츠]
19575	[아이디오스 실드]
19576	[아이디오스 레더 헬멧]
19577	[아이디오스 레더 아머]
19578	[아이디오스 레더 레깅스]
19579	[아이디오스 레더 글로브]
19580	[아이디오스 레더 부츠]
19581	[아이디오스 서클릿]
19582	[아이디오스 튜닉]
19583	[아이디오스 호즈]
19584	[아이디오스 글로브]
19585	[아이디오스 슈즈]


- 악세서리 -
A : 46984
S : 47004

- 헤어 악세서리 -
무 : 80418

<에제 클래식>
- 무기- 
A : 8688
S : 6364

- 방어구 -
A : 2382
S : 6373

- 악세서리 -
A : 858
S : 862

- 헤어 악세서리 -
무 : 5808

Ensoul 옵션 490 ~ 

버젼 별 특징 
- 라이브 버젼 S급 이상은
//summon_attribute 로 소환

- 클래식 S급 미만은 
//summon_option 으로 소환
------------------------------------------------------------------------------------------------------------------------*/



class GMFindTreeWndItem extends UICommonAPI;

var WindowHandle  Me;
//var array<String> m_ComboList;
var String m_WindowName;

var TextBoxHandle textBoxEnchant;
var EditBoxHandle editBoxEnchant;

var TextBoxHandle textBoxAttribute0;
var EditBoxHandle editBoxAttribute0;
var ComboBoxHandle comboAttribute0;

var TextBoxHandle textBoxAttribute1;
var EditBoxHandle editBoxAttribute1;
var ComboBoxHandle comboAttribute1;

var TextBoxHandle textBoxAttribute2;
var EditBoxHandle editBoxAttribute2;
var ComboBoxHandle comboAttribute2;

var TextBoxHandle textBoxOptioinNormal;
var EditBoxHandle editBoxOptioinNormal;

var TextBoxHandle textBoxOptioinRandom;
var EditBoxHandle editBoxOptioinRandom;

var TextBoxHandle textBoxEnsoul0;
var EditBoxHandle editBoxEnsoul0;

var TextBoxHandle textBoxEnsoul1;
var EditBoxHandle editBoxEnsoul1;

var TextBoxHandle textBoxEnsoul2;
var EditBoxHandle editBoxEnsoul2;
var CheckBoxHandle checkBoxBless;

var GMFindTreeWnd GMFindTreeWndScript;

var ButtonHandle summonButton;

var ListCtrlHandle summonList;

var int itemID;

var L2Util util;

enum ATTRIBUTECOMBOTYPE 
{
	ATTRIBUTE_NONE  ,
	ATTRIBUTE_FIRE  , 
	ATTRIBUTE_WATER , 
	ATTRIBUTE_WIND  , 
	ATTRIBUTE_EARTH , 
	ATTRIBUTE_HOLY  , 
	ATTRIBUTE_UNHOLY 
};

/*******************************************************************************************************
 * On
 * *****************************************************************************************************/
function OnLoad()
{
	SetClosingOnESC();
	Me = GetWindowHandle( m_WindowName );		

	textBoxEnchant = GetTextBoxHandle(m_WindowName$".textBoxEnchant");
	editBoxEnchant = GetEditBoxHandle(m_WindowName$".editBoxEnchant");

	textBoxAttribute0 = GetTextBoxHandle(m_WindowName$".textBoxAttribute0");
	editBoxAttribute0 = GetEditBoxHandle(m_WindowName$".editBoxAttribute0");
	comboAttribute0 = GetComboBoxHandle(m_WindowName$".comboAttribute0");
	AddComboxStrings (comboAttribute0);

	textBoxAttribute1 = GetTextBoxHandle(m_WindowName$".textBoxAttribute1");
	editBoxAttribute1 = GetEditBoxHandle(m_WindowName$".editBoxAttribute1");
	comboAttribute1 = GetComboBoxHandle(m_WindowName$".comboAttribute1");
	AddComboxStrings (comboAttribute1);

	textBoxAttribute2 = GetTextBoxHandle(m_WindowName$".textBoxAttribute2");
	editBoxAttribute2 = GetEditBoxHandle(m_WindowName$".editBoxAttribute2");
	comboAttribute2 = GetComboBoxHandle(m_WindowName$".comboAttribute2");
	AddComboxStrings (comboAttribute2);	

	textBoxOptioinNormal = GetTextBoxHandle(m_WindowName$".textBoxOptioinNormal");
	editBoxOptioinNormal = GetEditBoxHandle(m_WindowName$".editBoxOptioinNormal");
	textBoxOptioinRandom = GetTextBoxHandle(m_WindowName$".textBoxOptioinRandom");
	editBoxOptioinRandom = GetEditBoxHandle(m_WindowName$".editBoxOptioinRandom");

	textBoxEnsoul0 = GetTextBoxHandle(m_WindowName$".textBoxEnsoul0");
	editBoxEnsoul0 = GetEditBoxHandle(m_WindowName$".editBoxEnsoul0");
	textBoxEnsoul1 = GetTextBoxHandle(m_WindowName$".textBoxEnsoul1");
	editBoxEnsoul1 = GetEditBoxHandle(m_WindowName$".editBoxEnsoul1");
	textBoxEnsoul2 = GetTextBoxHandle(m_WindowName$".textBoxEnsoul2");
	editBoxEnsoul2 = GetEditBoxHandle(m_WindowName$".editBoxEnsoul2");

	summonButton = GetButtonHandle ( m_WindowName$".btnSummon" ) ; 

	summonList = GetListCtrlHandle ( m_WindowName$".ListFindWnd" ) ;
	checkBoxBless = GetCheckBoxHandle(m_WindowName$".CheckBoxBless");

	GMFindTreeWndScript = GMFindTreeWnd ( GetScript( "GMFindTreeWnd" )) ;

	util = L2Util(GetScript("L2Util"));	

	// 상해에서 만든 api , 툴팁을 클릭 롤 오버만 해도 보이도록
	summonList.SetSelectedSelTooltip(false);	
	summonList.SetAppearTooltipAtMouseX(true);

	LoadLists();
}

function OnShow()
{
	//Debug( "OnShow") ;
	SetDisableAllHandles();
}

function OnClickButton( string strID )
{
	//local string summonCnt;

	switch( strID )
	{
	case "btnSummon":		
		HandleSummon (); 
		//summonCnt=m_hEdSummonCnt.GetString();
		//Summon(int(summonCnt));
		break;
	case "BtnEditUp" :
		LineUP();
		break;
	case "BtnEditDown" :
		LineDown();
		break;
	case "BtnEditAdd" :
		HandleAdd (); 
		break;
	case "BtnEditdel": 
		HandleDelete () ;
		break;	
	case "BtnEditAlldel" : 
		HandleDeleteAll();
		break;
	case "btnCopy" :
		HandleCopyBuildcommand() ;
		break;
	case "btnDetail":
		if ( GetWindowHandle("UIItemToolWnd").IsShowWindow() )
			GetWindowHandle("UIItemToolWnd").HideWindow();
		else
		{
			GetWindowHandle("UIItemToolWnd").ShowWindow();
			GetWindowHandle("UIItemToolWnd").SetFocus();
		}
		break;
	}
}

// 역 속성은 자동으로 붙지 않게 해 준다.
function OnComboBoxItemSelected(string StrID, int IndexID)
{	
	//EditBoxString = m_hEditBox.GetString();
	//Debug( "OnComboBoxItemSelected" @ EListType ( IndexID ) );
	switch(strID)
	{
		case "comboAttribute0" :
		case "comboAttribute1" :
		case "comboAttribute2" :
			CheckAtrributeTypeChanged ( StrID, IndexID ) ;
	//		ShowList( EditBoxString , EListType( IndexID ));			
		break;
	}
}

function OnDBClickListCtrlRecord( string ListCtrlID )
{
	local LVDataRecord record;
	local int selectedIdx ;	
	local array<String> params;

	selectedIdx = summonList.GetSelectedIndex () ;
	summonList.getRec( selectedIdx, record ) ;		

	GMFindTreeWndScript.ShowList ( String (record.nReserved1) , GMFindTreeWndScript.ELISTTYPE.LISTTYPE_ITEM ) ;	

	SetItemID ( int ( record.nReserved1 ) );

	Split( Record.LVDataList[1].szData, "/", params );
	
	/* 속성 값 ***************************************************************************************************/
	comboAttribute0.SetSelectedNum ( int ( params[0] ) + 1 );
	editBoxAttribute0.SetString ( params[1] );
	comboAttribute1.SetSelectedNum ( int ( params[2] ) + 1 );
	editBoxAttribute1.SetString ( params[3] );
	comboAttribute2.SetSelectedNum ( int ( params[4] ) + 1 );
	editBoxAttribute2.SetString ( params[5] );

	/* 인첸트 ***************************************************************************************************/
	editBoxEnchant.SetString ( params[6] );

	/* 제련 ***************************************************************************************************/
	editBoxOptioinNormal.SetString ( params[7] );
	editBoxOptioinRandom.SetString ( params[8] );
	
	/* 집혼 ***************************************************************************************************/
	editBoxEnsoul0.SetString ( params[9] );
	editBoxEnsoul1.SetString ( params[10] );
	editBoxEnsoul2.SetString ( params[11] );

	// Debug ( "OnDBClickListCtrlRecord" @ params[0] @ params.Length)  ;
}

function OnDrawerHideFinished () 
{
	SaveLists();
}
/*******************************************************************************************************
 * 리스트 관리 
 * *****************************************************************************************************/
function LineUP ()
{
	local int selectedIdx  ;
	local LVDataRecord recordSelected, recordUp;

	selectedIdx = summonList.GetSelectedIndex ();
	if ( selectedIdx < 1 ) return;

	
	summonList.GetRec( selectedIdx, recordSelected ) ; 
	summonList.GetRec( selectedIdx - 1 , recordUp ) ; 

	summonList.ModifyRecord(selectedIdx, recordUp);
	summonList.ModifyRecord(selectedIdx - 1 , recordSelected);

	summonList.SetSelectedIndex ( selectedIdx - 1 , true ) ;
}

function LineDown () 
{
	local int selectedIdx, count ;
	local LVDataRecord recordSelected, recordDown;

	selectedIdx = summonList.GetSelectedIndex ();
	count = summonList.GetRecordCount ();
	if ( selectedIdx == -1 && selectedIdx == ( count - 1 )) return;

	summonList.GetRec( selectedIdx, recordSelected ) ; 
	summonList.GetRec( selectedIdx + 1, recordDown ) ; 

	summonList.ModifyRecord(selectedIdx, recordDown);
	summonList.ModifyRecord(selectedIdx + 1 , recordSelected);

	summonList.SetSelectedIndex ( selectedIdx + 1 , true ) ;
}

function HandleDelete() 
{
	local int selectedIdx ;
	selectedIdx = summonList.GetSelectedIndex ();
	if ( selectedIdx == -1 ) getInstanceL2Util().showGfxScreenMessage( "선택 된 아이템이 없습니다.");
	else 
	{
		RemoveINI( "GMSummon", String( summonList.GetRecordCount() - 1), "UIDEV.ini" );
		summonList.DeleteRecord ( selectedIdx );
		// 마지막 리스트를 삭제 하는 경우 
		if ( summonList.GetRecordCount() == selectedIdx ) 
			summonList.SetSelectedIndex ( selectedIdx - 1, true ) ;
	}
}

function HandleDeleteAll () 
{
	local int i, count ; 
	count = summonList.GetRecordCount() ;

	for ( i= 0 ; i < count ; i ++ ) 
		RemoveINI( "GMSummon", String( i ), "UIDEV.ini" );

	summonList.DeleteAllItem();
}


function HandleAdd () 
{
	local int selectedIndex; 
	selectedIndex = GetIsSameRecord ();
	if ( selectedIndex > -1 ) 
	{
		summonList.SetSelectedIndex ( selectedIndex, true ) ;		
		getInstanceL2Util().showGfxScreenMessage( "등록 된 아이템이 존재 합니다.");
		return;
	}
	
	if ( itemID > 0 ) 
	{
		summonList.InsertRecord ( MakeRecord () );
		summonList.SetSelectedIndex ( summonList.GetRecordCount() -1, true) ;
	}
}


function HandleSummon () 
{
	ExecuteCommand ( MakeSummonCommand () ) ;
}

function SaveLists()
{
	local int count, i  ;
	local string param ; 
	local LVDataRecord record;

	Debug( "OnHide count 00 " $ count ) ;

	count = summonList.GetRecordCount() ;

	for ( i = 0 ; i < count  ; i ++ ) 
	{	
		summonList.GetRec( i, record ) ;
		param = "";
		ParamAdd ( param, "itemID", string(record.nReserved1)) ;
		ParamAdd ( param, "params", record.LVDataList[1].szData) ;
		
		Debug( "OnHide count" $ count  ) ;
		SetINIString("GMSummon", String(i), param, "UIDEV.ini");
	}
}

function LoadLists () 
{
	local string param, params ;
	local bool bUseParam;
	local int i, tmpItemID ;	

	i = 0 ;
	bUseParam = GetINIString("GMSummon", String(i), param, "UIDEV.ini");

	while ( bUseParam )
	{			
		parseInt( param, "itemID", tmpItemID );
		parseString ( param, "params" , params ) ;

		summonList.InsertRecord ( MakeRecordByParmas (tmpItemID, params ));
		i++ ;
		
		bUseParam = GetINIString("GMSummon", String(i), param, "UIDEV.ini");
	//  Debug ( "bUseParam" @ i  @ bUseParam  ) ;
	}
}

// 빌드 명령어를 복사 함.
function HandleCopyBuildcommand ()
{
	local string buildcommand ;
	buildcommand = MakeSummonCommand ();
	getInstanceL2Util().showGfxScreenMessage ( "Copy...... <br>" $ buildcommand  ) ;
	ClipboardCopy( buildcommand );
}

/*******************************************************************************************************
 * 레코드  
 * *****************************************************************************************************/
function LVDataRecord MakeRecord () 
{
	return MakeRecordByParmas ( itemID , MakeParam() ) ; 
}

function LVDataRecord MakeRecordByParmas (int tmpItemID, string params ) 
{
	local LVDataRecord Record;
	local ItemInfo inItem;
	local string tooltipParam ; 
	
	Record.LVDataList.length = 2;		
	Record.nReserved1 = tmpItemID;
	
	inItem = MakeItemInfoWithParams ( tmpItemID, params ) ;

	// 툴팁을 저장하기 위해 param으로 분해 사용
	ItemInfoToParam(inItem, tooltipParam);
	// 툴팁 정보
	Record.szReserved = tooltipParam;	
		
	// 리스트 텍스트
	Record.LVDataList[0].szData = inItem.Name;
	Record.LVDataList[0].textAlignment = TA_Left;

	Record.LVDataList[1].szData = params;
	Record.LVDataList[1].textAlignment = TA_CENTER;

	return  Record ;
}

// 파람들이 적용 된 아이템info 를 만듬.
function ItemInfo MakeItemInfoWithParams (int tmpItemID, string params ) 
{
	local itemInfo inItem;
	local array<string> paramArray ;

	inItem = GetItemInfoByClassID ( tmpItemID ) ; 

	Split ( params, "/", paramArray ) ;

	switch (inItem.itemType) 
	{
		// 공격 무기인 경우 공격 속성
		// 속성, 인챈, 제련, 집혼
		case EItemType.ITEM_WEAPON :			
			// 속성
			inItem.AttackAttributeType = int ( paramArray[0 ] ); 
			inItem.AttackAttributeValue =  int ( paramArray[1 ] ); 
			
			break;
		// 속성 * 3, 인챈, 제련 
		case EItemType.ITEM_ARMOR : 
			// 속성
			GetItemWithAttribute ( int ( paramArray[0]), int (paramArray[1]), inItem )  ;
			GetItemWithAttribute ( int ( paramArray[2]), int (paramArray[3]), inItem )  ;
			GetItemWithAttribute ( int ( paramArray[4]), int (paramArray[5]), inItem )  ;
		break;
	}	

	// 인챈트
	inItem.Enchanted = int ( paramArray[6] );
	// 제련
	inItem.RefineryOp1 = int (paramArray[7]);
	inItem.RefineryOp2 = int (paramArray[8]);
	// 집혼
	inItem.EnsoulOption[0].OptionArray.Length = 3 ;// = 100;
	inItem.EnsoulOption[0].OptionArray[0] = int (paramArray[9]);
	inItem.EnsoulOption[0].OptionArray[1] = int (paramArray[10]);
	inItem.EnsoulOption[0].OptionArray[2] = int (paramArray[11]);	

	return inItem;
}


function String MakeParam () 
{
	local string    enchantNum, attributeType0, attributeType1, attributeType2, 
					attributeLvString0, attributeLvString1, attributeLvString2, 
					optionNormalID, optionRandomID, ensoul0, ensoul1, ensoul2,
					param;

	param = "";
	
	/* 속성 값 ***************************************************************************************************/
	attributeType0 = String(GetIntAttribute ( comboAttribute0 )  ); 
	attributeLvString0 = GetStringNumWithEditBox ( editBoxAttribute0 ) ; 
	attributeType1 = String(GetIntAttribute ( comboAttribute1 ) ); 
	attributeLvString1 = GetStringNumWithEditBox ( editBoxAttribute1 ) ; 
	attributeType2 = String(GetIntAttribute ( comboAttribute2 ) ); 
	attributeLvString2 = GetStringNumWithEditBox ( editBoxAttribute2 ) ; 

	/* 인첸트 ***************************************************************************************************/
	enchantNum = GetStringNumWithEditBox ( editBoxEnchant  ) ;	

	/* 제련 ***************************************************************************************************/
	optionNormalID = GetStringNumWithEditBox ( editBoxOptioinNormal );
	optionRandomID = GetStringNumWithEditBox ( editBoxOptioinRandom );
	
	/* 집혼 ***************************************************************************************************/
	ensoul0 = GetStringNumWithEditBox ( editBoxEnsoul0 );
    ensoul1 = GetStringNumWithEditBox ( editBoxEnsoul1 );
    ensoul2 = GetStringNumWithEditBox ( editBoxEnsoul2 );

	param = attributeType0 $ "/" ;
	param = param $ attributeLvString0 $ "/" ;
	param = param $ attributeType1 $ "/" ;
	param = param $ attributeLvString1 $ "/" ;
	param = param $ attributeType2 $ "/" ;
	param = param $ attributeLvString2 $ "/" ;
	param = param $ enchantNum $ "/";
	param = param $ optionNormalID $ "/" ;
	param = param $ optionRandomID $ "/" ;
	param = param $ ensoul0 $ "/" ;
	param = param $ ensoul1 $ "/" ;
	param = param $ ensoul2;

	return param ;
}

private function int GetFireAttribute()
{
	local int i;
	local EditBoxHandle editBoxAttribute;
	local ComboBoxHandle comboAttribute;

	for(i = 0; i < 3; i++)
	{
		comboAttribute = GetComboBoxHandle(m_WindowName $ ".comboAttribute" $ string(i));
		if((GetIntAttribute(comboAttribute)) != 0)
		{
			// [Explicit Continue]
			continue;
		}
		editBoxAttribute = GetEditBoxHandle(m_WindowName $ ".editBoxAttribute" $ string(i));
		return int(GetStringNumWithEditBox(editBoxAttribute));
	}
	return 0;	
}

private function int GetWaterAttribute()
{
	local int i;
	local EditBoxHandle editBoxAttribute;
	local ComboBoxHandle comboAttribute;

	for(i = 0; i < 3; i++)
	{
		comboAttribute = GetComboBoxHandle(m_WindowName $ ".comboAttribute" $ string(i));
		if((GetIntAttribute(comboAttribute)) != 1)
		{
			// [Explicit Continue]
			continue;
		}
		editBoxAttribute = GetEditBoxHandle(m_WindowName $ ".editBoxAttribute" $ string(i));
		return int(GetStringNumWithEditBox(editBoxAttribute));
	}
	return 0;	
}

function SetDefaultAttribute(int Index, int defaultAttribute, int defaultAttributeLv, out int oAttribute, out int oAttributeLv)
{
	local int attribute;
	local ComboBoxHandle comboAttribute;

	comboAttribute = GetComboBoxHandle(m_WindowName $ ".comboAttribute" $ string(Index));
	attribute = GetIntAttribute(comboAttribute);
	if(attribute == -1)
	{
		oAttribute = defaultAttribute;
		defaultAttributeLv = oAttributeLv;		
	}
	else
	{
		oAttribute = attribute;
	}
	oAttributeLv = int(GetStringNumWithEditBox(GetEditBoxHandle(m_WindowName $ ".editBoxAttribute" $ string(Index))));	
}

/*******************************************************************************************************
 * 빌드 명령어  
 * *****************************************************************************************************/
function string MakeSummonCommand () 
{
	local int i;
	local string enchantNum, attributeType0, attributeType1, attributeType2, attributeLvString0, attributeLvString1, attributeLvString2, optionNormalID, optionRandomID, ensoul0, ensoul1, ensoul2;
	local int attribute0, attribute1, attribute2, attributeLv0, attributeLv1, attributeLv2, waterAttribtueLv, fireAttributeLv;
	local int isBless, defaultAttribute, defaultAttributeLv;

	/* 인첸트 ***************************************************************************************************/
	enchantNum = GetStringNumWithEditBox ( editBoxEnchant  ) ;	
	
	fireAttributeLv = GetFireAttribute();
	waterAttribtueLv = GetWaterAttribute();
	if(waterAttribtueLv > 0)
	{
		defaultAttribute = 1;
		defaultAttributeLv = waterAttribtueLv;		
	}
	else
	{
		defaultAttribute = 0;
		defaultAttributeLv = fireAttributeLv;
	}
	SetDefaultAttribute(0, defaultAttribute, defaultAttributeLv, attribute0, attributeLv0);
	SetDefaultAttribute(1, defaultAttribute, defaultAttributeLv, attribute1, attributeLv1);
	SetDefaultAttribute(2, defaultAttribute, defaultAttributeLv, attribute2, attributeLv2);

	attributeType0 = string (attribute0) ;
	attributeLvString0 = string ( attributeLv0 ) ;
	attributeType1 = string (attribute1);
	attributeLvString1 = string ( attributeLv1 ) ;
	attributeType2 = string (attribute2);
	attributeLvString2 = string ( attributeLv2 ) ;


	/* 제련 ***************************************************************************************************/
	optionNormalID = GetStringNumWithEditBox ( editBoxOptioinNormal );
	optionRandomID = GetStringNumWithEditBox ( editBoxOptioinRandom );
	
	/* 집혼 ***************************************************************************************************/
	ensoul0 = GetStringNumWithEditBox ( editBoxEnsoul0 );
    ensoul1 = GetStringNumWithEditBox ( editBoxEnsoul1 );
    ensoul2 = GetStringNumWithEditBox ( editBoxEnsoul2 );

	if ( checkBoxBless.IsChecked() )
		isBless = 1;
	else
		isBless = 0;

	if(attributeType0 != "0" || attributeType1 != "0" || attributeType2 != "0" || optionNormalID != "0" || optionRandomID != "0" || ensoul0 != "0" 
		|| ensoul1 != "0" || ensoul2 != "0" || isBless == 1)
	{
		if(IsHairAccessary())
		{
			if(isBless == 1)
			{
				getInstanceL2Util().showGfxScreenMessage("S급 부터 축복+제련이 가능 합니다.");
				Debug(("//summon_bless" @ string(ItemID)) @ enchantNum);
				return ("//summon_bless" @ string(ItemID)) @ enchantNum;				
			}
			else
			{
				Debug(((("//summon_option" @ string(ItemID)) @ optionNormalID) @ optionRandomID) @ enchantNum);
				return ((("//summon_option" @ string(ItemID)) @ optionNormalID) @ optionRandomID) @ enchantNum;
			}			
		}
		else
		{
			Debug(((((((((((((("HandleSummon : //summon_attribute" @ string(ItemID)) @ attributeType0) @ attributeLvString0) @ attributeType1) @ attributeLvString1) @ attributeType2) @ attributeLvString2) @ enchantNum) @ optionNormalID) @ optionRandomID) @ ensoul0) @ ensoul1) @ ensoul2) @ string(isBless));
			return ((((((((((((("//summon_attribute" @ string(ItemID)) @ attributeType0) @ attributeLvString0) @ attributeType1) @ attributeLvString1) @ attributeType2) @ attributeLvString2) @ enchantNum) @ optionNormalID) @ optionRandomID) @ ensoul0) @ ensoul1) @ ensoul2) @ string(isBless);
		}
	}
	if(enchantNum != "0")
	{
		return ("//summon2" @ enchantNum) @ string(ItemID);
	}
	return ("//summon" @ string(ItemID)) @ "1";
}

/*******************************************************************************************************
 * 윈도우 세팅 
 * *****************************************************************************************************/
function SetDisableAllHandles()
{
	// 인챈트
	SetEnchant ( false ) ;
	// 속성
	SetAttribute( false, 0 ) ;
	SetAttribute( false, 1 ) ;
	SetAttribute( false, 2 ) ;
	// 제련
	SetOptions ( false ) ;
	// 집혼
	SetEnsoul ( false ) ;
	
	SetBless(False);

	// 소환 버튼
	summonButton.DisableWindow();
}


function SetItemID ( int ID )  
{
	local itemInfo infItem ;			
	
	itemID = ID ;
	infItem = GetItemInfoByClassID ( itemID ) ;	
	
	SetDisableAllHandles();
	
	switch (infItem.itemType) 
	{
		case EItemType.ITEM_WEAPON :			
			// 인챈트
			SetEnchant ( true ) ;				
			// 속성 s 급 이상만 사용 할 수 있습니다.
			if ( !getInstanceUIData().getIsClassicServer() && IsSGradeMoreThan())
				SetAttribute ( true , 0 ) ;
			// 제련
			SetOptions ( true ) ;				
			// 집혼
			if ( IsSGradeMoreThan() ) SetEnsoul ( true ) ;

			if ( CanBless() )
				SetBless(True);

			summonButton.EnableWindow();
			Me.ShowWindow();
		break;
		// 일반 방어구인 경우 제련이 안 됨.
		case EItemType.ITEM_ARMOR :
			SetEnchant ( true ) ;						
			// 헤어 악세사리 인 경우 제련만 가능 ( 실제 제련 안되는 헤어 악세서리도 있다. 스크립트에서 누락 된 것 ... ) 
			if ( IsHairAccessary ())  
				SetOptions ( true );
			// 클래식 서버인 경우 속성이 다름. s 급 이상만 가능
			else if ( !getInstanceUIData().getIsClassicServer() && IsSGradeMoreThan() ) 
			{
				SetAttribute ( true , 0 ) ;
				SetAttribute ( true , 1 ) ;
				SetAttribute ( true , 2 ) ;
			}

			summonButton.EnableWindow(); 
			Me.ShowWindow();
		break;
		case EItemType.ITEM_ACCESSARY :
			SetEnchant ( true ) ;
			SetOptions ( true ) ;
			summonButton.EnableWindow();
			Me.ShowWindow();
		break;	
		default:
			if(EEtcItemType(infItem.EtcItemType) == ITEME_PET_COLLAR)
			{
				SetEnchant(true);
				summonButton.EnableWindow();
				Me.ShowWindow();
			}
			break;
	}
}



/*******************************************************************************************************
 * 활성 비활성
 * 1. 인첸트                           : SetEnchant
 * 2. 속성 1~3 ( 무기는 1, 방어구는 3 ): SetAttribute  -> s급 이상만 가능 
 * 3. 제련                             : SetOptions    -> c급 이상만 가능
 * 4. 집혼                             : SetEnsoul     -> c급 이상만 가능
 * *****************************************************************************************************/
function SetEnchant( bool bEnable ) 
{
	if ( bEnable ) 
	{
		textBoxEnchant.SetTextColor ( util.Gold ) ;
		editBoxEnchant.EnableWindow();
	}
	else 
	{
		textBoxEnchant.SetTextColor ( util.Gray ) ;
		editBoxEnchant.DisableWindow();
	}
}

function SetAttribute ( bool bEnable, int Index  ) 
{
	local TextBoxHandle textBox ; 
	local EditBoxHandle editBox ;
	local ComboBoxHandle comboBox ; 

	textBox = GetTextBoxHandle ( m_WindowName$".textBoxAttribute" $ String( Index ) );
	editBox = GetEditBoxHandle(m_WindowName$".editBoxAttribute" $ String( Index ));
	comboBox = GetComboBoxHandle(m_WindowName$".comboAttribute" $ String( Index ));

	if ( bEnable ) 
	{
		textBox.SetTextColor ( util.Gold ) ;
		editBox.EnableWindow();
		comboBox.EnableWindow();
	}
	else 
	{
		textBox.SetTextColor ( util.Gray ) ;
		editBox.DisableWindow();
		comboBox.DisableWindow();
	}

}

function SetOptions ( bool bEnable ) 
{
	if ( bEnable ) 
	{
		textBoxOptioinNormal.SetTextColor ( util.Gold ) ;
		editBoxOptioinNormal.EnableWindow();
		textBoxOptioinRandom.SetTextColor ( util.Gold ) ;
		editBoxOptioinRandom.EnableWindow();

	}
	else 
	{
		textBoxOptioinNormal.SetTextColor ( util.Gray ) ;
		editBoxOptioinNormal.DisableWindow();
		textBoxOptioinRandom.SetTextColor ( util.Gray ) ;
		editBoxOptioinRandom.DisableWindow();
	}
}

function SetEnsoul ( bool bEnable ) 
{
	if ( bEnable ) 
	{
		textBoxEnsoul0.SetTextColor ( util.Gold );
		editBoxEnsoul0.EnableWindow();

		textBoxEnsoul1.SetTextColor ( util.Gold );
		editBoxEnsoul1.EnableWindow();

		textBoxEnsoul2.SetTextColor ( util.Gold );
		editBoxEnsoul2.EnableWindow();
	}
	else 
	{
		textBoxEnsoul0.SetTextColor ( util.Gray );
		editBoxEnsoul0.DisableWindow();

		textBoxEnsoul1.SetTextColor ( util.Gray );
		editBoxEnsoul1.DisableWindow();

		textBoxEnsoul2.SetTextColor ( util.Gray );
		editBoxEnsoul2.DisableWindow();
	}
}

function SetBless (bool bEnable)
{
	if ( bEnable )
		checkBoxBless.EnableWindow();
	else
		checkBoxBless.DisableWindow();
}

/*******************************************************************************************************
 * 체크
 * *****************************************************************************************************/
// 저장할 레코드와, 저장 된 레코드를 비교 같은 게 있는지 확인 한다.
function int GetIsSameRecord () 
{
	local LVDataRecord record;
	local ItemInfo inItem;
	local string tooltipParam;
	local int i ;
	
	inItem = MakeItemInfoWithParams (itemID,  MakeParam() ) ;
	//inItem = GetItemInfoByClassID( itemID ) ;
	ItemInfoToParam (inItem, tooltipParam);

	// params = MakeParam();

	for ( i = 0 ; i < summonList.GetRecordCount() ; i ++ ) 
	{
		summonList.GetRec( i, record );
		// 파람을 합친 아이템 정보와 비교, 있는 경우 return 
		if ( Record.szReserved == tooltipParam  ) 
		{
			return i ; 
		}
	}
	return -1 ; 
}

// 속성 값이 변경 됐는지 체크 반대 속성이나, 같은 속성을 걸러 냄
function CheckAtrributeTypeChanged ( string StrID , int IndexID ) 
{
	local int tmpInt, i ;
	local ComboBoxHandle combobox;
	
	if ( IndexID == ATTRIBUTECOMBOTYPE.ATTRIBUTE_NONE ) return ;

	for ( i = 0 ; i < 3 ; i ++ ) 
	{
		if ( ( "comboAttribute" $ i ) == StrID ) continue ;

		combobox = GetComboBoxHandle ( m_WindowName $ ".comboAttribute" $ i  ) ;
		
		tmpInt = combobox.GetSelectedNum() ;
		if ( tmpInt == IndexID ) 
			combobox.SetSelectedNum( 0 ) ;
		else if ( IsAttributeOpposite ( IndexID, tmpInt )  ) 
		{
			combobox.SetSelectedNum( 0 );
			getInstanceL2Util().showGfxScreenMessage ( tmpInt $ "번 상성 속성을 초기화 했습니다." ) ;
		}
	}
}


// 상성 체크 불<->물, 대지<->바람, 신성<->암흑
function bool IsAttributeOpposite ( int indexMine, int indexTarget ) 
{	
	switch ( indexMine ) 
	{
		case ATTRIBUTECOMBOTYPE.ATTRIBUTE_FIRE : 
			if ( indexTarget == ATTRIBUTECOMBOTYPE.ATTRIBUTE_WATER ) return true;
			break;
		case ATTRIBUTECOMBOTYPE.ATTRIBUTE_WATER : 
			if ( indexTarget == ATTRIBUTECOMBOTYPE.ATTRIBUTE_FIRE ) return true;
			break;
		case ATTRIBUTECOMBOTYPE.ATTRIBUTE_WIND : 
			if ( indexTarget == ATTRIBUTECOMBOTYPE.ATTRIBUTE_EARTH ) return true;
			break;
		case ATTRIBUTECOMBOTYPE.ATTRIBUTE_EARTH : 
			if ( indexTarget == ATTRIBUTECOMBOTYPE.ATTRIBUTE_WIND ) return true;
			break;
		case ATTRIBUTECOMBOTYPE.ATTRIBUTE_HOLY : 
			if ( indexTarget == ATTRIBUTECOMBOTYPE.ATTRIBUTE_UNHOLY ) return true;
			break;
		case ATTRIBUTECOMBOTYPE.ATTRIBUTE_UNHOLY : 
			if ( indexTarget == ATTRIBUTECOMBOTYPE.ATTRIBUTE_HOLY ) return true;
			break;
	}	
}
// 아이템 타입이 무기, 방어, 헤어 악세서리 만 가능
function bool GetCanSummon () 
{
	local itemInfo infItem ;
	infItem = GetItemInfoByClassID ( itemID ) ;

	// 무기, 방어구( 헤어 악세서리 포함 ), 악세서리
	switch (infItem.itemType) 
	{
		case EItemType.ITEM_WEAPON:
		case EItemType.ITEM_ARMOR:
		case EItemType.ITEM_ACCESSARY:
		break;
		default: return false; 
	}

	// 라이브 서버
	// 1. s 급 이상
	// 2. 헤어 악세사리 ( 일부 스크립트에 정의 되어 있지 않은 악세서리는 제련 되지 않는다. ) 
	if ( getInstanceUIData().getIsLiveServer() ) 
	{
		if (!IsSGradeMoreThan() ) return IsHairAccessary() ;
		return true;
	}
	
	// s급 이상만 summon_attribute를 사용 할 수 있으나, 클래식은 속성이 달라, 의미가 없음.
	// summon_option, summon_ensoul 둘 중에 하나만 사용, 그러나 summon_option 을 주로 사용 하다고 함. 
	else if ( getInstanceUIData().getIsClassicServer() )
	{	
		return true; 
	}

	return false;
}

function bool IsSGradeMoreThan() 
{
	local itemInfo infItem ;
	infItem = GetItemInfoByClassID ( itemID ) ;

	switch ( infItem.CrystalType )
	{
		case CrystalType.CRT_S :
		case CrystalType.CRT_S80 :
		case CrystalType.CRT_S84 :
		case CrystalType.CRT_R :
		case CrystalType.CRT_R95 :
		case CrystalType.CRT_R99 :
		case CrystalType.CRT_R110 :
		return true;
	}
	return false ; 
}

function bool IsHairAccessary ( ) 
{
	local itemInfo infItem ;	
	infItem = GetItemInfoByClassID ( itemID ) ;
	if (infItem.itemType == EItemType.ITEM_ARMOR)  	
		if (infItem.SlotBitType == 65536 || infItem.SlotBitType == 524288 || infItem.SlotBitType == 262144) 
			return true;
	return false;
}

function bool CanBless ()
{
	local ItemInfo infItem;

	infItem = GetItemInfoByClassID(ItemID);
	return infItem.EnchantBlessGroupID > 0;
}

/*******************************************************************************************************
 * util 
 * *****************************************************************************************************/
// 타입에 따라 속성 값이 적용 된 아이템 info 설정
function GetItemWithAttribute ( int index ,int value,  out ItemInfo inItem) 
{
	switch ( index ) 
	{
		case ATTRIBUTECOMBOTYPE.ATTRIBUTE_NONE :
			break;
		case ATTRIBUTECOMBOTYPE.ATTRIBUTE_FIRE :
			inItem.DefenseAttributeValueFire = value;
			break;
		case ATTRIBUTECOMBOTYPE.ATTRIBUTE_WATER :
			inItem.DefenseAttributeValueWater = value;
			break;
		case ATTRIBUTECOMBOTYPE.ATTRIBUTE_WIND:
			inItem.DefenseAttributeValueWind = value;
			break;
		case ATTRIBUTECOMBOTYPE.ATTRIBUTE_EARTH:
			inItem.DefenseAttributeValueEarth = value;
			break;
		case ATTRIBUTECOMBOTYPE.ATTRIBUTE_HOLY:
			inItem.DefenseAttributeValueHoly = value;
			break;
		case ATTRIBUTECOMBOTYPE.ATTRIBUTE_UNHOLY :
			inItem.DefenseAttributeValueUnholy = value;
			break;		
	}
}


// 에디트 박스 값 가져 오기 ( 활성 비활성에 따라 다름. 
function string GetStringNumWithEditBox ( EditBoxHandle editbox ) 
{
	if ( editbox.IsEnableWindow () )  return String ( int (editbox.GetString () )) ;
	return "0";
}

// 콤보 박스 값 가져 오기, ( 활성 비활성 비교 후 ) 
function int GetIntAttribute ( ComboBoxHandle comboBox ) 
{
	if(! comboBox.IsEnableWindow())
	{
		return -1;
	}
	return comboBox.GetSelectedNum() - 1;
}


/*******************************************************************************************************
 * etc
 * *****************************************************************************************************/
// 없음, 불, 물, 바람, 대지, 신성, 암훅
function AddComboxStrings ( ComboBoxHandle comboxHandle ) 
{
	comboxHandle.AddString(GetSystemString(27));
	comboxHandle.AddString(GetSystemString(1622));
	comboxHandle.AddString(GetSystemString(1623));
	comboxHandle.AddString(GetSystemString(1624));
	comboxHandle.AddString(GetSystemString(1625));
	comboxHandle.AddString(GetSystemString(1626));
	comboxHandle.AddString(GetSystemString(1627));
}

/**
 * 윈도우 ESC 키로 닫기 처리 
 * "Esc" Key
 ***/
function OnReceivedCloseUI()
{
	PlayConsoleSound(IFST_WINDOW_CLOSE);
	GetWindowHandle( m_WindowName ).HideWindow();
}


defaultproperties
{
    m_WindowName="GMFindTreeWndItem"
}
