//ZScript Note interface example
//***********************************************************************************************

//[IConfig,3.1]//uncomment this for ZBrush 3.1 and above
//[IConfig,2]//uncomment this for ZBrush 2.0 and above

//*********************************
//Variables definition
//*********************************

[VarDef,result,0]
[VarDef,hSize,20]
[VarDef,vSize,18]
[VarDef,vPos,87]
[VarDef,hPos,23]
[VarDef,space,12]
[VarDef,choice(5),0]
[VarDef,choiceImage(5),""]
[VarDef,choiceText(5),""]
[VarDef,cupPic,""]
[VarDef,message,""]
[VarDef,init,1]

//********Routines*********

[RoutineDef,Initialize,//initialization
[VarSet,init,0]
[VarSet,cupPic,"ZCoffeeData\expresso.jpg"]
[VarSet,message,"\Cc0c0c0Enjoy your \Cffa000expresso\Cc0c0c0 !"]
[VarSet,choiceImage(0),"ZCoffeeData\expresso.jpg"]
[VarSet,choiceImage(1),"ZCoffeeData\cappuccino.jpg"]
[VarSet,choiceImage(2),"ZCoffeeData\latte.jpg"]
[VarSet,choiceImage(3),"ZCoffeeData\mocha.jpg"]
[VarSet,choiceImage(4),"ZCoffeeData\flat white.jpg"]
[VarSet,choice(0),1]
[VarSet,choiceText(0),"X"]
]//end routine


[RoutineDef,NoteInterface,//main interface
		
[IFreeze,//makes operation smooth
[Loop,1000,//loop for selections, until Serve Now or Cancel choice ends loop
//draw the interface 

//background image - the other buttons are positioned relative to this
[NoteIButton,/*text*/	,	"ZCoffeeData\ZCoffeeBack.jpg" /*image*/	,	/*pressed?*/	,1	/*disabled?*/,1 /*HPos*/,	1 /*VPos*/	,	305 /*HSize*/	,	320 /*VSize*/	, /*color*/	,	/*text color*/	,	0 /*opacity*/, /*text opacity*/	,1	/*image opacity*/	]

[Loop,5,//draw the selection buttons
[NoteIButton,choiceText(x) /*text*/	,	/*image*/	,choice(x)	/*pressed?*/	,	/*disabled?*/,hPos /*HPos*/,vPos+((vSize+space)*x) /*VPos*/	,	hSize /*HSize*/	,	vSize /*VSize*/	, /*color*/	,0xffa000	/*text color*/,	/*opacity*/, /*text opacity*/	,	/*image opacity*/	]
,x]

[NoteIButton,/*text*/	,cupPic	/*image*/	,	/*pressed?*/	,1	/*disabled?*/,149 /*HPos*/,135	/*VPos*/	,	/*HSize*/	,	/*VSize*/	,  /*color*/	,	/*text color*/	,	/*opacity*/, /*text opacity*/	,1	/*image opacity*/	]

[NoteIButton,"Cancel" /*text*/,/*image*/	,	/*pressed?*/	,/*disabled?*/,170 /*HPos*/,260	/*VPos*/	,100	/*HSize*/	,25 /*VSize*/	, /*color*/	,	/*text color*/	,	/*opacity*/, /*text opacity*/	,	/*image opacity*/	]

[NoteIButton,"Serve Now" /*text*/,/*image*/	,	/*pressed?*/	,/*disabled?*/,30 /*HPos*/,260	/*VPos*/	,100	/*HSize*/	,25	/*VSize*/	, /*color*/	,0xffa000	/*text color*/	,	/*opacity*/, /*text opacity*/	,	/*image opacity*/	]


[VarSet,result,[Note,""]]//get result

//process result
[If, (result>=2)&&(result<=6),//choice results
	[If,choice(result-2),//uncheck if same selection
	[VarSet,choice(result-2),0]
	[VarSet,choiceText(result-2),""]
	[VarSet,cupPic,"ZCoffeeData\ZCoffeeEmpty.jpg"]//set image
	[VarSet,message,"\Cffa000\n  What, no coffee?!\n"]
	[VarSet,init,1]
		,//else check selection, uncheck the rest
	[Loop,5,//uncheck all first
		[VarSet,choice(n),0]
		[VarSet,choiceText(n),""]
	,n]
	[VarSet,choice(result-2),1]//then check selection
	[VarSet,choiceText(result-2),"X"]
	[VarSet,cupPic,[Var,choiceImage(result-2)]]//set image	
	]//end if	
]//end choice results

[If,result=8,//Cancel button
[VarSet,message,"\Cffa000\n  What, no coffee?!\n"]
[LoopExit]//exits loop and interface
]// end Cancel result	
	
[If,(result<2)||(result>8),//Serve Now button or press Spacebar
	[If,(choice(0)=0)&&(choice(1)=0)&&(choice(2)=0)&&(choice(3)=0)&&(choice(4)=0),
		//all choices are unchecked, so no coffee selected
		[Note,"\Cc0c0c0\n  Sorry, we do not serve empty cups.\n  Please make a choice or
			 press \Cffa000Cancel\Cc0c0c0.\n",,3,4737096,,320]
		[RoutineCall,Initialize]//resets interface
	,//else process coffee choice
		[VarSet,message,[FileNameExtract,[FileNameResolvePath,[Var,cupPic]],2]]
		[VarSet,message,[StrMerge,"\Cc0c0c0\n   Enjoy your \Cffa000",message,"\Cc0c0c0 !\n"]]
		[LoopExit]//exits loop and interface
	]//end if
]//end Serve Now result

]//end loop
]//end freeze

]//end routine

//*****end of routines********

//Button for launching interface

[IButton,"Launch Note Interface",,
	[If,init, //initialize if necessary
		[RoutineCall,Initialize]
	]//end if
	[RoutineCall,NoteInterface]//call interface
	[Note,#message,,2,4737096,,220]//end message is displayed
]//end button
