/// //////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Called at the Onstart() and override it. <see cref="TRR_Reflection"/> /// And do the reflection stuff /// </summary> /// <param name="state"></param> /// //////////////////////////////////////////////////////////////////////////////////////// public override void OnStart(StartState state) { //Util.log("++++ 'OnStart()' ++++"); Reflections reflections = Reflections.instance; Shader reflectiveShader = shader.Length == 0 ? null : TextureReplacerReplaced.GetShader(shader); Color reflectionColour = new Color(0.5f, 0.5f, 0.5f); int updateInterval = 1; Util.parse(ReflectionColor, ref reflectionColour); Util.parse(colour, ref reflectionColour); Util.parse(interval, ref updateInterval); updateInterval = Math.Max(updateInterval, 1); List <string> meshNames = Util.splitConfigValue(meshes).ToList(); if (MeshesToChange != "all") { meshNames.AddUniqueRange(Util.splitConfigValue(MeshesToChange)); } if (reflections.reflectionType == Reflections.Type.NONE) { return; } if (reflections.reflectionType == Reflections.Type.REAL) { script = new Reflections.Script(part, updateInterval, reflectionColour); } if (reflections.logReflectiveMeshes) { Util.log("Part \"{0}\"", part.name); } bool success = false; foreach (MeshFilter meshFilter in part.FindModelComponents <MeshFilter>()) { if (meshFilter.GetComponent <Renderer>() == null) { continue; } Material material = meshFilter.GetComponent <Renderer>().material; if (reflections.logReflectiveMeshes) { Util.log("+ {0} [{1}]", meshFilter.name, material.shader.name); } if (meshNames.Count == 0 || meshNames.Contains(meshFilter.name)) { success |= script == null? reflections.applyStatic(material, reflectiveShader, reflectionColour) : script.apply(material, reflectiveShader, reflectionColour); } } if (!success) { if (script != null) { script.destroy(); script = null; } Util.log("Failed to replace any shader on \"{0}\" with its reflective counterpart", part.name); } }
/// //////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// The method that populate the GUI window /// </summary> /// <param name="id"></param> /// //////////////////////////////////////////////////////////////////////////////////////// private void windowHandler(int id) { Reflections reflections = Reflections.instance; Personaliser personaliser = Personaliser.instance; GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.BeginVertical(GUILayout.Width(200)); // Roster area. rosterScroll = GUILayout.BeginScrollView(rosterScroll); GUILayout.BeginVertical(); foreach (ProtoCrewMember kerbal in HighLogic.CurrentGame.CrewRoster.Crew) { switch (kerbal.rosterStatus) { case ProtoCrewMember.RosterStatus.Assigned: GUI.contentColor = Color.cyan; break; case ProtoCrewMember.RosterStatus.Dead: continue; case ProtoCrewMember.RosterStatus.Missing: GUI.contentColor = Color.yellow; break; default: GUI.contentColor = Color.white; break; } if (GUILayout.Button(kerbal.name)) { selectedKerbal = kerbal; selectedClass = null; } } foreach (ProtoCrewMember kerbal in HighLogic.CurrentGame.CrewRoster.Unowned) { switch (kerbal.rosterStatus) { case ProtoCrewMember.RosterStatus.Dead: GUI.contentColor = Color.cyan; break; default: continue; } if (GUILayout.Button(kerbal.name)) { selectedKerbal = kerbal; selectedClass = null; } } GUI.contentColor = Color.white; GUI.color = CLASS_COLOUR; // Class suits. foreach (string clazz in classes) { if (GUILayout.Button(clazz)) { selectedKerbal = null; selectedClass = clazz; } } GUI.color = Color.white; GUILayout.EndVertical(); GUILayout.EndScrollView(); if (GUILayout.Button("Reset to Defaults")) { personaliser.resetKerbals(); } GUILayout.EndVertical(); // Textures. Personaliser.Head defaultHead = personaliser.defaulMaleAndFemaleHeads[0]; Personaliser.Suit defaultSuit = personaliser.defaultSuit; Personaliser.KerbalData kerbalData = null; Personaliser.Head head = null; Personaliser.Suit suit = null; int headIndex = -1; int suitIndex = -1; if (selectedKerbal != null) { kerbalData = personaliser.getKerbalData(selectedKerbal); defaultHead = personaliser.defaulMaleAndFemaleHeads[(int)selectedKerbal.gender]; head = personaliser.getKerbalHead(selectedKerbal, kerbalData); suit = personaliser.getKerbalSuit(selectedKerbal, kerbalData); headIndex = personaliser.KerbalHeadsDB_full.IndexOf(head); suitIndex = personaliser.KerbalSuitsDB_full.IndexOf(suit); } else if (selectedClass != null) { personaliser.classSuitsDB.TryGetValue(selectedClass, out suit); if (suit != null) { suitIndex = personaliser.KerbalSuitsDB_full.IndexOf(suit); } } GUILayout.Space(10); GUILayout.BeginVertical(); if (head != null) { GUILayout.Box(head.head, GUILayout.Width(200), GUILayout.Height(200)); GUILayout.Label(head.name); } if (suit != null) { Texture2D suitTex = suit == defaultSuit && kerbalData != null && kerbalData.isVeteran ? defaultSuit.suitVeteran : (suit.suit ?? defaultSuit.suit); Texture2D helmetTex = suit.helmet ?? defaultSuit.helmet; Texture2D evaSuitTex = suit.evaSuit ?? defaultSuit.evaSuit; Texture2D evaHelmetTex = suit.evaHelmet ?? defaultSuit.evaHelmet; GUILayout.BeginHorizontal(); GUILayout.Box(suitTex, GUILayout.Width(100), GUILayout.Height(100)); GUILayout.Space(10); GUILayout.Box(helmetTex, GUILayout.Width(100), GUILayout.Height(100)); GUILayout.EndHorizontal(); GUILayout.Space(10); GUILayout.BeginHorizontal(); GUILayout.Box(evaSuitTex, GUILayout.Width(100), GUILayout.Height(100)); GUILayout.Space(10); GUILayout.Box(evaHelmetTex, GUILayout.Width(100), GUILayout.Height(100)); GUILayout.EndHorizontal(); GUILayout.Label(suit.name); } GUILayout.EndVertical(); GUILayout.BeginVertical(GUILayout.Width(120)); if (kerbalData != null) { GUILayout.BeginHorizontal(); GUI.enabled = personaliser.KerbalHeadsDB_full.Count != 0; if (GUILayout.Button("<")) { headIndex = headIndex == -1 ? 0 : headIndex; headIndex = (personaliser.KerbalHeadsDB_full.Count + headIndex - 1) % personaliser.KerbalHeadsDB_full.Count; kerbalData.head = personaliser.KerbalHeadsDB_full[headIndex]; } if (GUILayout.Button(">")) { headIndex = (headIndex + 1) % personaliser.KerbalHeadsDB_full.Count; kerbalData.head = personaliser.KerbalHeadsDB_full[headIndex]; } GUI.enabled = true; GUILayout.EndHorizontal(); GUI.color = kerbalData.head == defaultHead ? SELECTED_COLOUR : Color.white; if (GUILayout.Button("Default")) { kerbalData.head = defaultHead; } GUI.color = kerbalData.head == null ? SELECTED_COLOUR : Color.white; if (GUILayout.Button("Unset/Generic")) { kerbalData.head = null; } GUI.color = Color.white; } if (kerbalData != null || selectedClass != null) { GUILayout.Space(130); GUILayout.BeginHorizontal(); GUI.enabled = personaliser.KerbalSuitsDB_full.Count != 0; if (GUILayout.Button("<")) { suitIndex = suitIndex == -1 ? 0 : suitIndex; suitIndex = (personaliser.KerbalSuitsDB_full.Count + suitIndex - 1) % personaliser.KerbalSuitsDB_full.Count; if (kerbalData != null) { kerbalData.suit = personaliser.KerbalSuitsDB_full[suitIndex]; kerbalData.cabinSuit = null; } else { personaliser.classSuitsDB[selectedClass] = personaliser.KerbalSuitsDB_full[suitIndex]; } } if (GUILayout.Button(">")) { suitIndex = (suitIndex + 1) % personaliser.KerbalSuitsDB_full.Count; if (kerbalData != null) { kerbalData.suit = personaliser.KerbalSuitsDB_full[suitIndex]; kerbalData.cabinSuit = null; } else { personaliser.classSuitsDB[selectedClass] = personaliser.KerbalSuitsDB_full[suitIndex]; } } GUI.enabled = true; GUILayout.EndHorizontal(); GUI.color = suit == defaultSuit && (kerbalData == null || kerbalData.suit != null) ? SELECTED_COLOUR : Color.white; if (GUILayout.Button("Default")) { if (kerbalData != null) { kerbalData.suit = defaultSuit; kerbalData.cabinSuit = null; } else { personaliser.classSuitsDB[selectedClass] = defaultSuit; } } GUI.color = suit == null || (kerbalData != null && kerbalData.suit == null) ? SELECTED_COLOUR : Color.white; if (GUILayout.Button("Unset/Generic")) { if (kerbalData != null) { kerbalData.suit = null; kerbalData.cabinSuit = null; } else { personaliser.classSuitsDB[selectedClass] = null; } } GUI.color = Color.white; } GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.Space(10); personaliser.isHelmetRemovalEnabled = GUILayout.Toggle( personaliser.isHelmetRemovalEnabled, "Remove helmets in safe situations"); personaliser.isAtmSuitEnabled = GUILayout.Toggle( personaliser.isAtmSuitEnabled, "Spawn Kerbals in IVA suits when in breathable atmosphere"); personaliser.isNewSuitStateEnabled = GUILayout.Toggle( personaliser.isNewSuitStateEnabled, "Kerbals use another EVA suit when on the ground and with no air"); Reflections.Type reflectionType = reflections.reflectionType; GUILayout.BeginHorizontal(); GUILayout.Label("Reflections", GUILayout.Width(120)); reflectionType = (Reflections.Type)GUILayout.SelectionGrid((int)reflectionType, REFLECTION_TYPES, 3); GUILayout.EndHorizontal(); if (reflectionType != reflections.reflectionType) { reflections.setReflectionType(reflectionType); } GUILayout.EndVertical(); GUI.DragWindow(new Rect(0, 0, Screen.width, 30)); }