void OnGUI()
            {
                if (visible && MissionControl.Instance == null)
                {
                    DialogBox.DialogDetail detail = dialogBox.displayQueue.FirstOrDefault();
                    if (detail == null)
                    {
                        visible = false;
                        Destroy(this);
                        return;
                    }

                    float multiplier = (4.0f / 3.0f) / ((float)Screen.width / Screen.height);
                    float w          = multiplier * Screen.width * detail.width - 32;

                    if (windowPos.width == 0 && windowPos.height == 0)
                    {
                        firstPositioning = true;
                        float h = Screen.height * detail.height - 144f;
                        float x = detail.position == Position.LEFT ? 16f : detail.position == Position.CENTER ? (Screen.width - w) / 2.0f : (Screen.width - w - 16f);
                        windowPos = new Rect(x, 72f, w, h);
                    }
                    else if (firstPositioning && windowPos.width != 0 && Event.current.type == EventType.Layout)
                    {
                        firstPositioning = false;
                        windowPos.xMin   = detail.position == Position.LEFT ? 16f : detail.position == Position.CENTER ?
                                           (Screen.width - windowPos.width) / 2.0f : (Screen.width - windowPos.width - 16f);
                    }

                    UnityEngine.GUI.skin = HighLogic.Skin;
                    windowPos            = GUILayout.Window(GetType().FullName.GetHashCode(),
                                                            windowPos, DrawMessageBox, detail.title, windowStyle ?? HighLogic.Skin.window, GUILayout.Width(w));
                }
            }
 public void OnPreCull()
 {
     DialogBox.DialogDetail detail = dialogBox.displayQueue.FirstOrDefault();
     if (detail == null)
     {
         return;
     }
     foreach (Section section in detail.sections)
     {
         section.OnPreCull();
     }
 }
            void DrawMessageBox(int windowID)
            {
                DialogBox.DialogDetail detail = dialogBox.displayQueue.FirstOrDefault();

                if (windowStyle == null)
                {
                    windowStyle                     = new GUIStyle(HighLogic.Skin.window);
                    windowStyle.alignment           = TextAnchor.UpperLeft;
                    windowStyle.active.textColor    = detail.titleColor;
                    windowStyle.focused.textColor   = detail.titleColor;
                    windowStyle.hover.textColor     = detail.titleColor;
                    windowStyle.normal.textColor    = detail.titleColor;
                    windowStyle.onActive.textColor  = detail.titleColor;
                    windowStyle.onFocused.textColor = detail.titleColor;
                    windowStyle.onHover.textColor   = detail.titleColor;
                    windowStyle.onNormal.textColor  = detail.titleColor;
                }

                GUILayout.BeginVertical();

                GUILayout.BeginHorizontal();
                GUILayout.Space(8);
                foreach (Section section in detail.sections)
                {
                    section.OnGUI();
                    GUILayout.Space(8);
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (GUILayout.Button(Localizer.GetStringByTag("#autoLOC_211274"), GUILayout.MinWidth(80)))
                {
                    windowPos   = new Rect(0, 0, 0, 0);
                    windowStyle = null;
                    foreach (Section section in detail.sections)
                    {
                        section.OnDestroy();
                    }
                    dialogBox.displayQueue.Dequeue();
                    dialogBox.details.Remove(detail);
                }
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();

                GUILayout.EndVertical();

                UnityEngine.GUI.DragWindow();
            }
        public override bool Load(ConfigNode configNode)
        {
            // Load base class
            bool valid = base.Load(configNode);

            int index = 0;
            foreach (ConfigNode child in ConfigNodeUtil.GetChildNodes(configNode, "DIALOG_BOX"))
            {
                string dialogBoxNode = "DIALOG_BOX_" + index++;
                DataNode childDataNode = new DataNode(dialogBoxNode, dataNode, this);
                try
                {
                    ConfigNodeUtil.SetCurrentDataNode(childDataNode);
                    DialogBox.DialogDetail detail = new DialogBox.DialogDetail();
                    details.Add(detail);

                    valid &= ConfigNodeUtil.ParseValue<DialogBox.TriggerCondition>(child, "condition", x => detail.condition = x, this);
                    valid &= ConfigNodeUtil.ParseValue<DialogBox.Position>(child, "position", x => detail.position = x, this, DialogBox.Position.LEFT);
                    valid &= ConfigNodeUtil.ParseValue<float>(child, "width", x => detail.width = x, this, 0.8f, x => Validation.Between(x, 0.0f, 1.0f));
                    valid &= ConfigNodeUtil.ParseValue<float>(child, "height", x => detail.height = x, this, 0.0f, x => Validation.Between(x, 0.0f, 1.0f));
                    valid &= ConfigNodeUtil.ParseValue<string>(child, "title", x => detail.title = x, this, "");
                    valid &= ConfigNodeUtil.ParseValue<Color>(child, "titleColor", x => detail.titleColor = x, this, Color.white);
                    valid &= ConfigNodeUtil.ParseValue<string>(child, "parameter", x => detail.parameter = x, this, (string)null,
                        x => ValidateMandatoryParameter(x, detail.condition));

                    int sectionIndex = 0;
                    foreach (ConfigNode sectionNode in child.GetNodes())
                    {
                        DataNode sectionDataNode = new DataNode(dialogBoxNode + "_" + sectionIndex++, childDataNode, this);
                        ConfigNodeUtil.SetCurrentDataNode(sectionDataNode);

                        if (sectionNode.name == "TEXT")
                        {
                            DialogBox.TextSection section = new DialogBox.TextSection();
                            detail.sections.Add(section);

                            // Parse the text twice, once to ensure parsability, the other to get the unexpanded text
                            valid &= ConfigNodeUtil.ParseValue<string>(sectionNode, "text", x => { }, this);
                            if (valid)
                            {
                                section.text = ConfigNodeUtil.ParseValue<string>(sectionNode, "text");
                            }

                            valid &= ConfigNodeUtil.ParseValue<Color>(sectionNode, "textColor", x => section.textColor = x, this, new Color(0.8f, 0.8f, 0.8f));
                            valid &= ConfigNodeUtil.ParseValue<int>(sectionNode, "fontSize", x => section.fontSize = x, this, 20);
                        }
                        else if (sectionNode.name == "IMAGE")
                        {
                            DialogBox.ImageSection section = new DialogBox.ImageSection();
                            detail.sections.Add(section);

                            valid &= ConfigNodeUtil.ParseValue<string>(sectionNode, "url", x => section.imageURL = x, this, ValidateImageURL);
                            valid &= ConfigNodeUtil.ParseValue<string>(sectionNode, "characterName",
                                x => { section.characterName = x; section.showName = !string.IsNullOrEmpty(x); }, this, "");
                             
                            valid &= ConfigNodeUtil.ParseValue<Color>(sectionNode, "textColor", x => section.textColor = x, this, new Color(0.729f, 0.855f, 0.333f));
                        }
                        else if (sectionNode.name == "INSTRUCTOR")
                        {
                            DialogBox.InstructorSection section = new DialogBox.InstructorSection();
                            detail.sections.Add(section);

                            valid &= ConfigNodeUtil.ParseValue<string>(sectionNode, "name", x => section.name = x, this);
                            valid &= ConfigNodeUtil.ParseValue<bool>(sectionNode, "showName", x => section.showName = x, this, true);
                            valid &= ConfigNodeUtil.ParseValue<string>(sectionNode, "characterName", x => section.characterName = x, this, "");
                            valid &= ConfigNodeUtil.ParseValue<Color>(sectionNode, "textColor", x => section.textColor = x, this, new Color(0.729f, 0.855f, 0.333f));
                            valid &= ConfigNodeUtil.ParseValue<DialogBox.InstructorSection.Animation?>(sectionNode, "animation", x => section.animation = x, this,
                                (DialogBox.InstructorSection.Animation?)null);
                        }
                        else if (sectionNode.name == "KERBAL")
                        {
                            DialogBox.KerbalSection section = new DialogBox.KerbalSection();
                            detail.sections.Add(section);

                            valid &= ConfigNodeUtil.ParseValue<bool>(sectionNode, "showName", x => section.showName = x, this, true);
                            valid &= ConfigNodeUtil.ParseValue<string>(sectionNode, "characterName", x => section.characterName = x, this, "");
                            valid &= ConfigNodeUtil.ParseValue<ProtoCrewMember.Gender>(sectionNode, "gender", x => section.gender = x, this, ProtoCrewMember.Gender.Male);
                            valid &= ConfigNodeUtil.ParseValue<Color>(sectionNode, "textColor", x => section.textColor = x, this, new Color(0.729f, 0.855f, 0.333f));

                            valid &= ConfigNodeUtil.ParseValue<int>(sectionNode, "crewIndex", x => section.crewIndex = x, this, 0);
                            valid &= ConfigNodeUtil.ParseValue<List<string>>(sectionNode, "excludeName", x => section.excludeName = x, this, new List<string>());
                        }
                        else if (sectionNode.name == "BREAK")
                        {
                            DialogBox.BreakSection section = new DialogBox.BreakSection();
                            detail.sections.Add(section);
                        }
                    }
                }
                finally
                {
                    ConfigNodeUtil.SetCurrentDataNode(dataNode);
                }
            }
            valid &= ConfigNodeUtil.ValidateMandatoryChild(configNode, "DIALOG_BOX", this);

            return valid;
        }
Esempio n. 5
0
        public override bool Load(ConfigNode configNode)
        {
            // Load base class
            bool valid = base.Load(configNode);

            int index = 0;

            foreach (ConfigNode child in ConfigNodeUtil.GetChildNodes(configNode, "DIALOG_BOX"))
            {
                string   dialogBoxNode = "DIALOG_BOX_" + index++;
                DataNode childDataNode = new DataNode(dialogBoxNode, dataNode, this);
                try
                {
                    ConfigNodeUtil.SetCurrentDataNode(childDataNode);
                    DialogBox.DialogDetail detail = new DialogBox.DialogDetail();
                    details.Add(detail);

                    valid &= ConfigNodeUtil.ParseValue <DialogBox.TriggerCondition>(child, "condition", x => detail.condition = x, this);
                    valid &= ConfigNodeUtil.ParseValue <DialogBox.Position>(child, "position", x => detail.position = x, this, DialogBox.Position.LEFT);
                    valid &= ConfigNodeUtil.ParseValue <float>(child, "width", x => detail.width = x, this, 0.8f, x => Validation.Between(x, 0.0f, 1.0f));
                    valid &= ConfigNodeUtil.ParseValue <float>(child, "height", x => detail.height = x, this, 0.0f, x => Validation.Between(x, 0.0f, 1.0f));
                    valid &= ConfigNodeUtil.ParseValue <string>(child, "title", x => detail.title = x, this, "");
                    valid &= ConfigNodeUtil.ParseValue <Color>(child, "titleColor", x => detail.titleColor = x, this, Color.white);
                    valid &= ConfigNodeUtil.ParseValue <string>(child, "parameter", x => detail.parameter = x, this, (string)null,
                                                                x => ValidateMandatoryParameter(x, detail.condition));

                    int sectionIndex = 0;
                    foreach (ConfigNode sectionNode in child.GetNodes())
                    {
                        DataNode sectionDataNode = new DataNode(dialogBoxNode + "_" + sectionIndex++, childDataNode, this);
                        ConfigNodeUtil.SetCurrentDataNode(sectionDataNode);

                        if (sectionNode.name == "TEXT")
                        {
                            DialogBox.TextSection section = new DialogBox.TextSection();
                            detail.sections.Add(section);

                            // Parse the text twice, once to ensure parsability, the other to get the unexpanded text
                            valid &= ConfigNodeUtil.ParseValue <string>(sectionNode, "text", x => { }, this);
                            if (valid)
                            {
                                section.text = ConfigNodeUtil.ParseValue <string>(sectionNode, "text");
                            }

                            valid &= ConfigNodeUtil.ParseValue <Color>(sectionNode, "textColor", x => section.textColor = x, this, new Color(0.8f, 0.8f, 0.8f));
                            valid &= ConfigNodeUtil.ParseValue <int>(sectionNode, "fontSize", x => section.fontSize = x, this, 20);
                        }
                        else if (sectionNode.name == "IMAGE")
                        {
                            DialogBox.ImageSection section = new DialogBox.ImageSection();
                            detail.sections.Add(section);

                            valid &= ConfigNodeUtil.ParseValue <string>(sectionNode, "url", x => section.imageURL = x, this, ValidateImageURL);
                            valid &= ConfigNodeUtil.ParseValue <string>(sectionNode, "characterName",
                                                                        x => { section.characterName = x; section.showName = !string.IsNullOrEmpty(x); }, this, "");

                            valid &= ConfigNodeUtil.ParseValue <Color>(sectionNode, "textColor", x => section.textColor = x, this, new Color(0.729f, 0.855f, 0.333f));
                        }
                        else if (sectionNode.name == "INSTRUCTOR")
                        {
                            DialogBox.InstructorSection section = new DialogBox.InstructorSection();
                            detail.sections.Add(section);

                            valid &= ConfigNodeUtil.ParseValue <string>(sectionNode, "name", x => section.name = x, this);
                            valid &= ConfigNodeUtil.ParseValue <bool>(sectionNode, "showName", x => section.showName = x, this, true);
                            valid &= ConfigNodeUtil.ParseValue <string>(sectionNode, "characterName", x => section.characterName = x, this, "");
                            valid &= ConfigNodeUtil.ParseValue <Color>(sectionNode, "textColor", x => section.textColor = x, this, new Color(0.729f, 0.855f, 0.333f));
                            valid &= ConfigNodeUtil.ParseValue <DialogBox.InstructorSection.Animation?>(sectionNode, "animation", x => section.animation = x, this,
                                                                                                        (DialogBox.InstructorSection.Animation?)null);
                        }
                        else if (sectionNode.name == "KERBAL")
                        {
                            DialogBox.KerbalSection section = new DialogBox.KerbalSection();
                            detail.sections.Add(section);

                            valid &= ConfigNodeUtil.ParseValue <bool>(sectionNode, "showName", x => section.showName = x, this, true);
                            valid &= ConfigNodeUtil.ParseValue <string>(sectionNode, "characterName", x => section.characterName = x, this, "");
                            valid &= ConfigNodeUtil.ParseValue <ProtoCrewMember.Gender>(sectionNode, "gender", x => section.gender = x, this, ProtoCrewMember.Gender.Male);
                            valid &= ConfigNodeUtil.ParseValue <Color>(sectionNode, "textColor", x => section.textColor = x, this, new Color(0.729f, 0.855f, 0.333f));

                            valid &= ConfigNodeUtil.ParseValue <int>(sectionNode, "crewIndex", x => section.crewIndex = x, this, 0);
                            valid &= ConfigNodeUtil.ParseValue <List <string> >(sectionNode, "excludeName", x => section.excludeName = x, this, new List <string>());
                        }
                        else if (sectionNode.name == "BREAK")
                        {
                            DialogBox.BreakSection section = new DialogBox.BreakSection();
                            detail.sections.Add(section);
                        }
                    }
                }
                finally
                {
                    ConfigNodeUtil.SetCurrentDataNode(dataNode);
                }
            }
            valid &= ConfigNodeUtil.ValidateMandatoryChild(configNode, "DIALOG_BOX", this);

            return(valid);
        }