//Made by Antipindoc

var presets = ["Glow1", "Glow2", "Glow3", "Glow4", "Glow5"]

UI.AddSliderInt("",0,0);
UI.AddCheckbox("Show Materials")
UI.AddDropdown("Glowtypes", ["Glow1", "Glow2", "Glow3", "Glow4", "Glow5"])

UI.AddColorPicker("Glow Color");
UI.AddSliderFloat("Additional Brightness",0,1)
UI.AddSliderFloat("Glow Factor",1,20)
UI.AddSliderFloat("Glow Fill",1,10)
UI.AddCheckbox("Glow only")
UI.AddCheckbox("Wireframe")

UI.AddColorPicker("Glow Color\n");
UI.AddSliderFloat("Additional Brightness\n",0,1)
UI.AddSliderFloat("Glow Factor\n",1,20)
UI.AddSliderFloat("Glow Fill\n",1,10)
UI.AddCheckbox("Glow only\n")
UI.AddCheckbox("Wireframe\n")

UI.AddColorPicker("Glow Color\n\n");
UI.AddSliderFloat("Additional Brightness\n\n",0,1)
UI.AddSliderFloat("Glow Factor\n\n",1,20)
UI.AddSliderFloat("Glow Fill\n\n",1,10)
UI.AddCheckbox("Glow only\n\n")
UI.AddCheckbox("Wireframe\n\n")

UI.AddColorPicker("Glow Color\n\n\n");
UI.AddSliderFloat("Additional Brightness\n\n\n",0,1)
UI.AddSliderFloat("Glow Factor\n\n\n",1,20)
UI.AddSliderFloat("Glow Fill\n\n\n",1,10)
UI.AddCheckbox("Glow only\n\n\n")
UI.AddCheckbox("Wireframe\n\n\n")

UI.AddColorPicker("Glow Color\n\n\n\n");
UI.AddSliderFloat("Additional Brightness\n\n\n\n",0,1)
UI.AddSliderFloat("Glow Factor\n\n\n\n",1,20)
UI.AddSliderFloat("Glow Fill\n\n\n\n",1,10)
UI.AddCheckbox("Glow only\n\n\n\n")
UI.AddCheckbox("Wireframe\n\n\n\n")
UI.AddSliderInt("",0,0);

function updateMaterials()
{
	if(UI.GetValue("Script items", "Show Materials")){
		Material.Create("Glow1");
        Material.Create("Glow2");
        Material.Create("Glow3");
	    Material.Create("Glow4");
		Material.Create("Glow5");
	}else{
		Material.Destroy("Glow1")
		Material.Destroy("Glow2")
		Material.Destroy("Glow3")
		Material.Destroy("Glow4");
		Material.Destroy("Glow5");
	}
	
	vec1 = 0
	
	for(i=0;i<4;i++){
		mat_index = Material.Get(""+presets[i]);

		envmaptint = UI.GetColor("Script items", "Glow Color" + stupidstuff(i))
		brightness = UI.GetValue("Script items", "Additional Brightness" + stupidstuff(i))
		vec3 =       UI.GetValue("Script items", "Glow Factor" + stupidstuff(i))
		vec2 =       UI.GetValue("Script items", "Glow Fill" + stupidstuff(i))
		glowonly = UI.GetValue("Script items", "Glow only" + stupidstuff(i));
	    wireframe = UI.GetValue("Script items", "Wireframe" + stupidstuff(i));
		Material.SetKeyValue(mat_index, "$baseTexture", "vgui/white")
		Material.SetKeyValue(mat_index, "$additive", glowonly ? "1" : "0")
		Material.SetKeyValue(mat_index, "$color", "[0 0 0]");
		Material.SetKeyValue(mat_index, "$wireframe", wireframe ? "1" : "0")
		Material.SetKeyValue(mat_index, "$envmap", "models/effects/cube_white");
		Material.SetKeyValue(mat_index, "$envmapfresnel", "1");
        Material.SetKeyValue(mat_index, "$envmapfresnelminmaxexp", ""+vector(vec1,vec2,vec3));
        Material.SetKeyValue(mat_index, "$envmaptint", ""+standart(coloradd(envmaptint, brightness)));
        Material.Refresh(mat_index);
	}
}

function stupidstuff(num){
	switch(num){
		case 0:
		    return ""
			break;
		case 1:
		    return "\n"
			break;
		case 2:
		    return "\n\n"
			break;
		case 3:
		    return "\n\n\n"
			break;
		case 4:
		    return "\n\n\n\n"
	}
}

function UI_check(){
	if(UI.GetValue("Script items", "Glowtypes") == 0){
		UI.SetEnabled("Script items", "Glow Color", true);
		UI.SetEnabled("Script items", "Additional Brightness", true);
		UI.SetEnabled("Script items", "Glow Factor", true);
		UI.SetEnabled("Script items", "Glow Fill", true);
		UI.SetEnabled("Script items", "Glow only", true);
		UI.SetEnabled("Script items", "Wireframe", true);
	}else{
		UI.SetEnabled("Script items", "Glow Color", false);
		UI.SetEnabled("Script items", "Additional Brightness", false);
		UI.SetEnabled("Script items", "Glow Factor", false);
		UI.SetEnabled("Script items", "Glow Fill", false);
		UI.SetEnabled("Script items", "Glow only", false);
		UI.SetEnabled("Script items", "Wireframe", false);
	}
	
	if(UI.GetValue("Script items", "Glowtypes") == 1){
		UI.SetEnabled("Script items", "Glow Color\n", true);
		UI.SetEnabled("Script items", "Additional Brightness\n", true);
		UI.SetEnabled("Script items", "Glow Factor\n", true);
		UI.SetEnabled("Script items", "Glow Fill\n", true);
		UI.SetEnabled("Script items", "Glow only\n", true);
		UI.SetEnabled("Script items", "Wireframe\n", true);
	}else{
		UI.SetEnabled("Script items", "Glow Color\n", false);
		UI.SetEnabled("Script items", "Additional Brightness\n", false);
		UI.SetEnabled("Script items", "Glow Factor\n", false);
		UI.SetEnabled("Script items", "Glow Fill\n", false);
		UI.SetEnabled("Script items", "Glow only\n", false);
		UI.SetEnabled("Script items", "Wireframe\n", false);
	}
	
	if(UI.GetValue("Script items", "Glowtypes") == 2){
		UI.SetEnabled("Script items", "Glow Color\n\n", true);
		UI.SetEnabled("Script items", "Additional Brightness\n\n", true);
		UI.SetEnabled("Script items", "Glow Factor\n\n", true);
		UI.SetEnabled("Script items", "Glow Fill\n\n", true);
		UI.SetEnabled("Script items", "Glow only\n\n", true);
		UI.SetEnabled("Script items", "Wireframe\n\n", true);
	}else{
		UI.SetEnabled("Script items", "Glow Color\n\n", false);
		UI.SetEnabled("Script items", "Additional Brightness\n\n", false);
		UI.SetEnabled("Script items", "Glow Factor\n\n", false);
		UI.SetEnabled("Script items", "Glow Fill\n\n", false);
		UI.SetEnabled("Script items", "Glow only\n\n", false);
		UI.SetEnabled("Script items", "Wireframe\n\n", false);
	}
	
	if(UI.GetValue("Script items", "Glowtypes") == 3){
		UI.SetEnabled("Script items", "Glow Color\n\n\n", true);
		UI.SetEnabled("Script items", "Additional Brightness\n\n\n", true);
		UI.SetEnabled("Script items", "Glow Factor\n\n\n", true);
		UI.SetEnabled("Script items", "Glow Fill\n\n\n", true);
		UI.SetEnabled("Script items", "Glow only\n\n\n", true);
		UI.SetEnabled("Script items", "Wireframe\n\n\n", true);
	}else{
		UI.SetEnabled("Script items", "Glow Color\n\n\n", false);
		UI.SetEnabled("Script items", "Additional Brightness\n\n\n", false);
		UI.SetEnabled("Script items", "Glow Factor\n\n\n", false);
		UI.SetEnabled("Script items", "Glow Fill\n\n\n", false);
		UI.SetEnabled("Script items", "Glow only\n\n\n", false);
		UI.SetEnabled("Script items", "Wireframe\n\n\n", false);
	}
	
	if(UI.GetValue("Script items", "Glowtypes") == 4){
		UI.SetEnabled("Script items", "Glow Color\n\n\n\n", true);
		UI.SetEnabled("Script items", "Additional Brightness\n\n\n\n", true);
		UI.SetEnabled("Script items", "Glow Factor\n\n\n\n", true);
		UI.SetEnabled("Script items", "Glow Fill\n\n\n\n", true);
		UI.SetEnabled("Script items", "Glow only\n\n\n\n", true);
		UI.SetEnabled("Script items", "Wireframe\n\n\n\n", true);
	}else{
		UI.SetEnabled("Script items", "Glow Color\n\n\n\n", false);
		UI.SetEnabled("Script items", "Additional Brightness\n\n\n\n", false);
		UI.SetEnabled("Script items", "Glow Factor\n\n\n\n", false);
		UI.SetEnabled("Script items", "Glow Fill\n\n\n\n", false);
		UI.SetEnabled("Script items", "Glow only\n\n\n\n", false);
		UI.SetEnabled("Script items", "Wireframe\n\n\n\n", false);
	}
	
}

function vector(vec1,vec2,vec3){
	result = "[";
	result += vec1 + " ";
	result += vec2 + " ";
	result += (20-vec3) + "]";
	return result;
}
function standart(ar){
	result = "["
	result += ar[0]/255 + " ";
	result += ar[1]/255 + " ";
	result += ar[2]/255 + "\]";
	return result
}

function coloradd(ar,val){
	val = 1/val;
	temp1 = ar[0] + ((255-ar[0])/val)
	temp2 = ar[1] + ((255-ar[1])/val)
	temp3 = ar[2] + ((255-ar[2])/val)
	return [temp1, temp2, temp3, 255]
}
Cheat.RegisterCallback("Draw","UI_check")
Cheat.RegisterCallback("Material", "updateMaterials")