示例#1
0
        /// <summary>
        /// Draws the window if it is visible.
        /// </summary>
        public void Draw( )
        {
            if (!IsVisible)
            {
                return;
            }
            if (!GameHelper.WindowVisibility( ))
            {
                IsVisible = false;
                OnCloseEvent(this, EventArgs.Empty);
            }


            if (_skin == null)
            {
                // Initialize our skin and styles.
                _skin = GameObject.Instantiate(HighLogic.Skin) as GUISkin;

                _skin.horizontalScrollbarThumb.fixedHeight = 13;
                _skin.horizontalScrollbar.fixedHeight      = 13;

                _labelStyle = new GUIStyle(_skin.label)
                {
                    fontSize  = 11,
                    fontStyle = FontStyle.Italic,
                };

                _progressLabelStyle = new GUIStyle(_skin.label)
                {
                    fontStyle = FontStyle.BoldAndItalic,
                    alignment = TextAnchor.MiddleCenter,
                    fontSize  = 11,
                    normal    =
                    {
                        textColor = new Color(0.322f, 0.298f, 0.004f),
                    },
                };

                _situationStyle = new GUIStyle(_progressLabelStyle)
                {
                    fontSize      = 13,
                    alignment     = TextAnchor.MiddleLeft,
                    fontStyle     = FontStyle.Normal,
                    fixedHeight   = 25,
                    contentOffset = new Vector2(0, 6),
                    normal        =
                    {
                        textColor = new Color(0.7f, 0.8f, 0.8f),
                    },
                };

                _experimentProgressLabelStyle = new GUIStyle(_skin.label)
                {
                    padding = new RectOffset(0, 0, 4, 0),
                };

                _horizontalScrollbarOnboardStyle = new GUIStyle(_skin.horizontalScrollbar)
                {
                    normal =
                    {
                        background = _emptyTexture,
                    },
                };

                _compactWindowStyle = new GUIStyle(_skin.window)
                {
                    padding = new RectOffset(0, 4, 4, 4),
                };

                _compactLabelStyle = new GUIStyle(_labelStyle)
                {
                    fontSize = 9,
                };

                _compactSituationStyle = new GUIStyle(_situationStyle)
                {
                    fontSize      = 11,
                    contentOffset = new Vector2(0, -3),
                };

                _compactButtonStyle = new GUIStyle(_skin.button)
                {
                    padding     = new RectOffset(),
                    fixedHeight = 16
                };
                _closeButtonStyle = new GUIStyle(_skin.button)
                {
                    // int left, int right, int top, int bottom
                    padding = new RectOffset(2, 2, 6, 2),
                };
            }

            var oldSkin = GUI.skin;

            GUI.skin = _skin;

            if (_compactMode)
            {
                _rect3 = GUILayout.Window(_window3Id, _rect3, DrawCompactControls, string.Empty, _compactWindowStyle);
            }
            else
            {
                _rect = GUILayout.Window(_windowId, _rect, DrawControls, "[x] Science!");
                var ClosePos = new Rect(_rect.xMin + _rect.width - 20, _rect.yMin + 2, 18, 18);
                --GUI.depth;
                if (GUI.Button(ClosePos, "X", _closeButtonStyle))
                {
                    IsVisible = false;
                    OnCloseEvent(this, EventArgs.Empty);
                }
            }



            if (!string.IsNullOrEmpty(_lastTooltip))
            {
                _tooltipStyle = _tooltipStyle ?? new GUIStyle(_skin.window)
                {
                    normal =
                    {
                        background = _emptyTexture,
                    },
                };
                GUI.Window(_window2Id, new Rect(Mouse.screenPos.x + 15, Mouse.screenPos.y + 15, 500, 30), x => {
                    GUI.Label(new Rect(), _lastTooltip);
                }, string.Empty, _tooltipStyle);
            }

            GUI.skin = oldSkin;
        }