public ResearchBodiesInstructor(string instructorName)
        {
            GameObject prefab = AssetBase.GetPrefab(instructorName);

            if (prefab == null)
            {
                throw new ArgumentException("Could not find instructor named '" + instructorName + "'");
            }

            if (instructorName == "Instructor_Wernher")
            {
                InstructorName = KSP.Localization.Localizer.Format("#autoLOC_RBodies_00102");
            }
            else if (instructorName == "Strategy_ScienceGuy")
            {
                InstructorName = KSP.Localization.Localizer.Format("#autoLOC_501659");
            }
            GameObject prefabInstance = UnityEngine.Object.Instantiate(prefab);

            _instructor = prefabInstance.GetComponent <KerbalInstructor>();

            _portrait = new RenderTexture(PortraitWidth, PortraitWidth, 8);
            _instructor.instructorCamera.targetTexture = _portrait;

            _responses = _instructor.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance)
                         .Where(fi => fi.FieldType == typeof(CharacterAnimationState))
                         .Where(fi => fi.GetValue(_instructor) != null)
                         .ToDictionary(fi => new GUIContent(fi.Name), fi => fi.GetValue(_instructor) as CharacterAnimationState);
        }
Example #2
0
        private StoryDialog(InstructorType instractorType, String instructorName, String message, Action callback)
        {
            this.instructorName = instructorName;
            this.message = message;
            this.callback = callback;

            var windowWidth = Math.Max(600, Screen.width / 2);
            var windowHeight = Math.Max(500, Screen.height / 2);
            this.windowPosition = new Rect((Screen.width / 2) - (windowWidth / 2), (Screen.height / 2) - (windowHeight / 2), windowWidth, windowHeight);

            this.labelStyle = new GUIStyle(HighLogic.Skin.label) {
                alignment = TextAnchor.MiddleCenter,
            };
            this.scrollStyle = new GUIStyle(HighLogic.Skin.scrollView);
            this.instructor = this.GetInstructor(instractorType);
            this.instructorTexture = new RenderTexture(this.instructorPortraitSize, this.instructorPortraitSize, 8);
            this.instructor.instructorCamera.targetTexture = this.instructorTexture;
            this.instructor.instructorCamera.ResetAspect();

            InputLockManager.SetControlLock(LOCK_ID);
            RenderingManager.AddToPostDrawQueue(144, this.OnDraw);
        }
            public override void OnGUI()
            {
                if (instructor == null)
                {
                    instructor = ((GameObject)UnityEngine.Object.Instantiate(AssetBase.GetPrefab(name))).GetComponent <KerbalInstructor>();

                    instructorTexture = new RenderTexture(128, 128, 8);
                    instructor.instructorCamera.targetTexture = instructorTexture;
                    instructor.instructorCamera.ResetAspect();

                    // Remove the lights for Gene/Wernher
                    Light mainlight = instructor.GetComponentsInChildren <Light>(true).Where(l => l.name == "mainlight").FirstOrDefault();
                    if (mainlight != null)
                    {
                        UnityEngine.Object.Destroy(mainlight);
                    }
                    Light backlight = instructor.GetComponentsInChildren <Light>(true).Where(l => l.name == "backlight").FirstOrDefault();
                    if (backlight != null)
                    {
                        UnityEngine.Object.Destroy(backlight);
                    }

                    offset += 25f;
                    instructor.gameObject.transform.Translate(offset, 0.0f, 0.0f);

                    // Add a light
                    lightGameObject = new GameObject("Dialog Box Light");
                    Light lightComp = lightGameObject.AddComponent <Light>();
                    lightComp.color = new Color(0.4f, 0.4f, 0.4f);
                    lightGameObject.transform.position = instructor.instructorCamera.transform.position;

                    if (string.IsNullOrEmpty(characterName))
                    {
                        characterName = Localizer.GetStringByTag(instructor.CharacterName);
                    }

                    instructor.SetupAnimations();

                    if (animation != null)
                    {
                        switch (animation.Value)
                        {
                        case Animation.idle:
                            animState = instructor.anim_idle;
                            break;

                        case Animation.idle_lookAround:
                            animState = instructor.anim_idle_lookAround;
                            break;

                        case Animation.idle_sigh:
                            animState = instructor.anim_idle_sigh;
                            break;

                        case Animation.idle_wonder:
                            animState = instructor.anim_idle_wonder;
                            break;

                        case Animation.true_thumbUp:
                            animState = instructor.anim_true_thumbUp;
                            break;

                        case Animation.true_thumbsUp:
                            animState = instructor.anim_true_thumbsUp;
                            break;

                        case Animation.true_nodA:
                            animState = instructor.anim_true_nodA;
                            break;

                        case Animation.true_nodB:
                            animState = instructor.anim_true_nodB;
                            break;

                        case Animation.true_smileA:
                            animState = instructor.anim_true_smileA;
                            break;

                        case Animation.true_smileB:
                            animState = instructor.anim_true_smileB;
                            break;

                        case Animation.false_disappointed:
                            animState = instructor.anim_false_disappointed;
                            break;

                        case Animation.false_disagreeA:
                            animState = instructor.anim_false_disagreeA;
                            break;

                        case Animation.false_disagreeB:
                            animState = instructor.anim_false_disagreeB;
                            break;

                        case Animation.false_disagreeC:
                            animState = instructor.anim_false_disagreeC;
                            break;

                        case Animation.false_sadA:
                            animState = instructor.anim_false_sadA;
                            break;
                        }

                        // Give a short delay before playing the animation
                        nextAnimTime = Time.fixedTime + 0.3f;
                    }
                }

                // Play the animation
                if (nextAnimTime <= Time.fixedTime)
                {
                    instructor.PlayEmote(animState);
                    animState.audioClip = null;
                    nextAnimTime        = Time.fixedTime + animState.clip.length;
                }

                GUILayout.BeginVertical(GUILayout.Width(128));
                GUILayout.Box("", GUILayout.Width(128), GUILayout.Height(128));
                if (Event.current.type == EventType.Repaint)
                {
                    Rect rect = GUILayoutUtility.GetLastRect();
                    rect = new Rect(rect.x + 1f, rect.y + 1f, rect.width - 2f, rect.height - 2f);
                    Graphics.DrawTexture(rect, instructorTexture, new Rect(0.0f, 0.0f, 1f, 1f), 124, 124, 124, 124, Color.white, PortraitRenderMaterial);
                }

                DisplayName(128);

                GUILayout.EndVertical();
            }
        private static DialogGUIImage makePictureOfAKerbal(int width, int height, bool isGoodNews)
        {
            if (instructor == null)
            {
                GameObject genesPrefab      = AssetBase.GetPrefab("Instructor_Gene");
                var        instantiatedGene = UnityEngine.Object.Instantiate(genesPrefab);
                instructor = instantiatedGene.GetComponent <KerbalInstructor>();

                // Remove the lights for Gene/Wernher
                Light mainlight = instructor.GetComponentsInChildren <Light>(true).Where(l => l.name == "mainlight").FirstOrDefault();
                if (mainlight != null)
                {
                    UnityEngine.Object.Destroy(mainlight);
                }
                Light backlight = instructor.GetComponentsInChildren <Light>(true).Where(l => l.name == "backlight").FirstOrDefault();
                if (backlight != null)
                {
                    UnityEngine.Object.Destroy(backlight);
                }

                instructor.gameObject.transform.Translate(25f, 0.0f, 0.0f);

                // Add a light
                GameObject lightGameObject = new GameObject("Dialog Box Light");
                Light      lightComp       = lightGameObject.AddComponent <Light>();
                lightComp.color = new Color(0.4f, 0.4f, 0.4f);
                lightGameObject.transform.position = instructor.instructorCamera.transform.position;

                instructor.SetupAnimations();
            }

            var instructorTexture = new RenderTexture(width, height, 8);

            instructor.instructorCamera.targetTexture = instructorTexture;
            instructor.instructorCamera.ResetAspect();

            var initialHappyAnimations = new List <CharacterAnimationState>()
            {
                instructor.anim_true_thumbsUp,
                instructor.anim_true_thumbUp,
                instructor.anim_true_nodA,
                instructor.anim_true_nodB,
                instructor.anim_true_smileA,
                instructor.anim_true_smileB,
            };
            var initialGrumpyAnimations = new List <CharacterAnimationState>()
            {
                instructor.anim_false_disagreeA,
                instructor.anim_false_disagreeB,
                instructor.anim_false_disagreeC,
            };
            var vampingAnimations = new List <CharacterAnimationState>()
            {
                instructor.anim_idle_lookAround,
                instructor.anim_idle_sigh,
                instructor.anim_idle_wonder,
                instructor.anim_true_nodA,
                instructor.anim_true_nodB,
                instructor.anim_true_smileA,
                instructor.anim_true_smileB,
            };

            // Give a short delay before playing the animation
            float nextAnimTime = Time.fixedTime + 0.3f;
            bool  doneFirstYet = false;
            var   random       = new System.Random();

            var guiImage = new DialogGUIImage(new Vector2(width, height), new Vector2(0, 0), Color.gray, instructorTexture);

            guiImage.OnUpdate = () =>
            {
                // Play the animation
                if (nextAnimTime <= Time.fixedTime)
                {
                    CharacterAnimationState nowPlaying;
                    if (!doneFirstYet)
                    {
                        List <CharacterAnimationState> animationSet = isGoodNews ? initialHappyAnimations : initialGrumpyAnimations;
                        nowPlaying = animationSet[random.Next(animationSet.Count)];
                        instructor.PlayEmote(nowPlaying);
                        doneFirstYet = true;
                    }
                    else
                    {
                        nowPlaying = vampingAnimations[random.Next(vampingAnimations.Count)];
                        instructor.PlayEmote(nowPlaying, instructor.anim_idle, playSound: false);
                    }
                    nextAnimTime = Time.fixedTime + nowPlaying.clip.length + 1.0f;
                }
            };

            return(guiImage);
        }
            public override void OnGUI()
            {
                if (instructor == null)
                {
                    instructor = ((GameObject)UnityEngine.Object.Instantiate(AssetBase.GetPrefab(name))).GetComponent<KerbalInstructor>();

                    instructorTexture = new RenderTexture(128, 128, 8);
                    instructor.instructorCamera.targetTexture = instructorTexture;
                    instructor.instructorCamera.ResetAspect();

                    // Remove the lights for Gene/Wernher
                    Light mainlight = instructor.GetComponentsInChildren<Light>(true).Where(l => l.name == "mainlight").FirstOrDefault();
                    if (mainlight != null)
                    {
                        UnityEngine.Object.Destroy(mainlight);
                    }
                    Light backlight = instructor.GetComponentsInChildren<Light>(true).Where(l => l.name == "backlight").FirstOrDefault();
                    if (backlight != null)
                    {
                        UnityEngine.Object.Destroy(backlight);
                    }

                    offset += 25f;
                    instructor.gameObject.transform.Translate(offset, 0.0f, 0.0f);

                    // Add a light
                    lightGameObject = new GameObject("Dialog Box Light");
                    Light lightComp = lightGameObject.AddComponent<Light>();
                    lightComp.color = new Color(0.4f, 0.4f, 0.4f);
                    lightGameObject.transform.position = instructor.instructorCamera.transform.position;

                    if (string.IsNullOrEmpty(characterName))
                    {
                        characterName = instructor.CharacterName;
                    }

                    instructor.SetupAnimations();

                    if (animation != null)
                    {
                        switch (animation.Value)
                        {
                            case Animation.idle:
                                animState = instructor.anim_idle;
                                break;
                            case Animation.idle_lookAround:
                                animState = instructor.anim_idle_lookAround;
                                break;
                            case Animation.idle_sigh:
                                animState = instructor.anim_idle_sigh;
                                break;
                            case Animation.idle_wonder:
                                animState = instructor.anim_idle_wonder;
                                break;
                            case Animation.true_thumbUp:
                                animState = instructor.anim_true_thumbUp;
                                break;
                            case Animation.true_thumbsUp:
                                animState = instructor.anim_true_thumbsUp;
                                break;
                            case Animation.true_nodA:
                                animState = instructor.anim_true_nodA;
                                break;
                            case Animation.true_nodB:
                                animState = instructor.anim_true_nodB;
                                break;
                            case Animation.true_smileA:
                                animState = instructor.anim_true_smileA;
                                break;
                            case Animation.true_smileB:
                                animState = instructor.anim_true_smileB;
                                break;
                            case Animation.false_disappointed:
                                animState = instructor.anim_false_disappointed;
                                break;
                            case Animation.false_disagreeA:
                                animState = instructor.anim_false_disagreeA;
                                break;
                            case Animation.false_disagreeB:
                                animState = instructor.anim_false_disagreeB;
                                break;
                            case Animation.false_disagreeC:
                                animState = instructor.anim_false_disagreeC;
                                break;
                            case Animation.false_sadA:
                                animState = instructor.anim_false_sadA;
                                break;
                        }

                        // Give a short delay before playing the animation
                        nextAnimTime = Time.fixedTime + 0.3f;
                    }
                }

                // Play the animation
                if (nextAnimTime <= Time.fixedTime)
                {
                    instructor.PlayEmote(animState);
                    animState.audioClip = null;
                    nextAnimTime = Time.fixedTime + animState.clip.length;
                }

                GUILayout.BeginVertical(GUILayout.Width(128));
                GUILayout.Box("", GUILayout.Width(128), GUILayout.Height(128));
                if (Event.current.type == EventType.Repaint)
                {
                    Rect rect = GUILayoutUtility.GetLastRect();
                    rect = new Rect(rect.x + 1f, rect.y + 1f, rect.width - 2f, rect.height - 2f);
                    Graphics.DrawTexture(rect, instructorTexture, new Rect(0.0f, 0.0f, 1f, 1f), 124, 124, 124, 124, Color.white, PortraitRenderMaterial);
                }

                DisplayName(128);

                GUILayout.EndVertical();
            }
Example #6
0
        void WindowFunction(int windowID)
        {
            if (windowStyle == null)
            {
                windowStyle                     = new GUIStyle(HighLogic.Skin.window);
                windowStyle.alignment           = TextAnchor.UpperLeft;
                windowStyle.active.textColor    = Color.white;
                windowStyle.focused.textColor   = Color.white;
                windowStyle.hover.textColor     = Color.white;
                windowStyle.normal.textColor    = Color.white;
                windowStyle.onActive.textColor  = Color.white;
                windowStyle.onFocused.textColor = Color.white;
                windowStyle.onHover.textColor   = Color.white;
                windowStyle.onNormal.textColor  = Color.white;
            }

            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            GUILayout.Space(8);

            if (instructor == null && !string.IsNullOrEmpty(instructorName))
            {
                instructor = ((GameObject)UnityEngine.Object.Instantiate(AssetBase.GetPrefab(instructorName))).GetComponent <KerbalInstructor>();

                instructorTexture = new RenderTexture(128, 128, 8);
                instructor.instructorCamera.targetTexture = instructorTexture;
                instructor.instructorCamera.ResetAspect();

                offset += 25f;
                instructor.gameObject.transform.Translate(offset, 0.0f, 0.0f);

                // Add a light
                lightGameObject = new GameObject("Dialog Box Light");
                Light lightComp = lightGameObject.AddComponent <Light>();
                lightComp.color = new Color(0.4f, 0.4f, 0.4f);
                lightGameObject.transform.position = instructor.instructorCamera.transform.position;

                if (string.IsNullOrEmpty(characterName))
                {
                    characterName = Localizer.GetStringByTag(instructor.CharacterName);
                }

                instructor.SetupAnimations();

                if (animation != null)
                {
                    switch (animation.Value)
                    {
                    case Animation.idle:
                        animState = instructor.anim_idle;
                        break;

                    case Animation.idle_lookAround:
                        animState = instructor.anim_idle_lookAround;
                        break;

                    case Animation.idle_sigh:
                        animState = instructor.anim_idle_sigh;
                        break;

                    case Animation.idle_wonder:
                        animState = instructor.anim_idle_wonder;
                        break;

                    case Animation.true_thumbUp:
                        animState = instructor.anim_true_thumbUp;
                        break;

                    case Animation.true_thumbsUp:
                        animState = instructor.anim_true_thumbsUp;
                        break;

                    case Animation.true_nodA:
                        animState = instructor.anim_true_nodA;
                        break;

                    case Animation.true_nodB:
                        animState = instructor.anim_true_nodB;
                        break;

                    case Animation.true_smileA:
                        animState = instructor.anim_true_smileA;
                        break;

                    case Animation.true_smileB:
                        animState = instructor.anim_true_smileB;
                        break;

                    case Animation.false_disappointed:
                        animState = instructor.anim_false_disappointed;
                        break;

                    case Animation.false_disagreeA:
                        animState = instructor.anim_false_disagreeA;
                        break;

                    case Animation.false_disagreeB:
                        animState = instructor.anim_false_disagreeB;
                        break;

                    case Animation.false_disagreeC:
                        animState = instructor.anim_false_disagreeC;
                        break;

                    case Animation.false_sadA:
                        animState = instructor.anim_false_sadA;
                        break;
                    }

                    // Give a short delay before playing the animation
                    nextAnimTime = Time.fixedTime + 0.3f;
                }
            }

            if (instructor != null)
            {
                // Play the animation
                if (nextAnimTime <= Time.fixedTime)
                {
                    instructor.PlayEmote(animState);
                    animState.audioClip = null;
                    nextAnimTime        = Time.fixedTime + animState.clip.length;
                }

                GUILayout.BeginVertical(GUILayout.Width(128));
                GUILayout.Box("", GUILayout.Width(128), GUILayout.Height(128));
                if (Event.current.type == EventType.Repaint)
                {
                    Rect rect = GUILayoutUtility.GetLastRect();
                    rect = new Rect(rect.x + 1f, rect.y + 1f, rect.width - 2f, rect.height - 2f);
                    Graphics.DrawTexture(rect, instructorTexture, new Rect(0.0f, 0.0f, 1f, 1f), 124, 124, 124, 124, Color.white, PortraitRenderMaterial);
                }

                DisplayName(128);

                GUILayout.EndVertical();
                GUILayout.Space(8);
            }

            // Display text
            if (text != null)
            {
                if (labelStyle == null)
                {
                    labelStyle                  = new GUIStyle(UnityEngine.GUI.skin.label);
                    labelStyle.alignment        = TextAnchor.UpperLeft;
                    labelStyle.richText         = true;
                    labelStyle.normal.textColor = new Color(0.9f, 0.9f, 0.9f);
                    labelStyle.fontSize         = 16;
                }

                GUILayout.Label(text, labelStyle, GUILayout.ExpandWidth(true));
            }

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("OK", GUILayout.MinWidth(80)))
            {
                visible = false;
                Destroy(this);
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();

            UnityEngine.GUI.DragWindow();
        }