コード例 #1
0
        private void _WindowOnGUI()
        {
            TryPruneFields();
            WindowFields fields;
            var          windowHash = GetHashCode();

            windowFields.TryGetValue(windowHash, out fields);
            if (fields == null)
            {
                fields = new WindowFields();
                windowFields.Add(windowHash, fields);
            }

            // ===== Vanilla begin ===
            if (this.resizeable)
            {
                if (fields.resizer == null)
                {
                    fields.resizer = new WindowResizer();
                }
                if (fields.resizeLater)
                {
                    fields.resizeLater = false;
                    this.windowRect    = fields.resizeLaterRect;
                }
            }
            Rect winRect = this.windowRect.AtZero();

            this.windowRect = GUI.Window(this.ID, this.windowRect, delegate(int x) {
                Find.WindowStack.currentlyDrawnWindow = this;
                if (this.doWindowBackground)
                {
                    Widgets.DrawWindowBackground(winRect);
                }
                if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape)
                {
                    Find.WindowStack.Notify_PressedEscape();
                }
                if (Event.current.type == EventType.MouseDown)
                {
                    Find.WindowStack.Notify_ClickedInsideWindow(this);
                }
                if (Event.current.type == EventType.KeyDown && !Find.WindowStack.GetsInput(this))
                {
                    Event.current.Use();
                }
                if (!this.optionalTitle.NullOrEmpty())
                {
                    GUI.Label(new Rect(this.Margin, this.Margin, this.windowRect.width, 25f), this.optionalTitle);
                }
                if (this.doCloseX && Widgets.CloseButtonFor(winRect))
                {
                    this.Close(true);
                }
                if (this.resizeable && Event.current.type != EventType.Repaint)
                {
                    Rect lhs = fields.resizer.DoResizeControl(this.windowRect);
                    if (lhs != this.windowRect)
                    {
                        fields.resizeLater     = true;
                        fields.resizeLaterRect = lhs;
                    }
                }
                Rect rect = winRect.ContractedBy(this.Margin);
                if (!this.optionalTitle.NullOrEmpty())
                {
                    rect.yMin += this.Margin + 25f;
                }
                GUI.BeginGroup(rect);
                // ===== Vanilla end ===
                var inRect       = rect.AtZero();
                var injectionSet = WindowInjectionManager.GetSetForWindowType(GetType());
                if (injectionSet != null && injectionSet.beforeContents != null)
                {
                    InvokeCallbackList(injectionSet.beforeContents, this, inRect);
                }
                if (injectionSet != null && injectionSet.replaceContents != null)
                {
                    InvokeCallbackList(injectionSet.replaceContents, this, inRect);
                }
                else
                {
                    // ===== Vanilla begin ===
                    try {
                        this.DoWindowContents(inRect);
                    } catch (Exception ex) {
                        Log.Error(string.Concat(new object[] {
                            "Exception filling window for ",
                            this.GetType().ToString(),
                            ": ",
                            ex
                        }));
                    }
                    // ===== Vanilla end ===
                }
                if (injectionSet != null && injectionSet.afterContents != null)
                {
                    InvokeCallbackList(injectionSet.afterContents, this, inRect);
                }
                // ===== Vanilla begin ===
                GUI.EndGroup();
                if (this.resizeable && Event.current.type == EventType.Repaint)
                {
                    fields.resizer.DoResizeControl(this.windowRect);
                }
                if (this.doCloseButton)
                {
                    Text.Font  = GameFont.Small;
                    Rect rect2 = new Rect(winRect.width / 2f - this.CloseButSize.x / 2f, winRect.height - 55f, this.CloseButSize.x, this.CloseButSize.y);
                    if (Widgets.ButtonText(rect2, "CloseButton".Translate(), true, false, true))
                    {
                        this.Close(true);
                    }
                }
                if (this.closeOnEscapeKey && Event.current.type == EventType.KeyDown && (Event.current.keyCode == KeyCode.Escape || Event.current.keyCode == KeyCode.Return))
                {
                    this.Close(true);
                    Event.current.Use();
                }
                if (this.draggable)
                {
                    GUI.DragWindow();
                }
                else if (Event.current.type == EventType.MouseDown)
                {
                    Event.current.Use();
                }
                ScreenFader.OverlayOnGUI(winRect.size);
                Find.WindowStack.currentlyDrawnWindow = null;
            }, string.Empty, Widgets.EmptyStyle);

            // ===== Vanilla end ===
        }
コード例 #2
0
        public override void WindowOnGUI()
        {
            if (this.resizeable)
            {
                if (this.resizer == null)
                {
                    this.resizer = new WindowResizer();
                }
                if (this.resizeLater)
                {
                    this.resizeLater = false;
                    this.windowRect  = this.resizeLaterRect;
                }
            }
            this.windowRect = this.windowRect.Rounded();
            Rect winRect = this.windowRect.AtZero();

            this.windowRect = GUI.Window(this.ID, this.windowRect, delegate(int x)
            {
                UnityGUIBugsFixer.OnGUI();
                Find.WindowStack.currentlyDrawnWindow = this;
                if (this.doWindowBackground)
                {
                    //DrawWindowBackground(winRect);
                }
                if (KeyBindingDefOf.Accept.KeyDownEvent)
                {
                    Find.WindowStack.Notify_PressedAccept();
                }
                if (UnityEngine.Event.current.type == UnityEngine.EventType.KeyDown && !Find.WindowStack.GetsInput(this))
                {
                    UnityEngine.Event.current.Use();
                }
                if (!this.optionalTitle.NullOrEmpty())
                {
                    GUI.Label(new Rect(this.Margin, this.Margin, this.windowRect.width, 25f), this.optionalTitle);
                }
                if (this.resizeable && UnityEngine.Event.current.type != UnityEngine.EventType.Repaint)
                {
                    Rect lhs = this.resizer.DoResizeControl(this.windowRect);
                    if (lhs != this.windowRect)
                    {
                        this.resizeLater     = true;
                        this.resizeLaterRect = lhs;
                    }
                }
                Rect rect = winRect;
                if (!this.optionalTitle.NullOrEmpty())
                {
                    rect.yMin += this.Margin + 25f;
                }
                GUI.BeginGroup(rect);
                try
                {
                    this.DoWindowContents(rect.AtZero());
                }
                catch (Exception ex)
                {
                    Log.Error(string.Concat(new object[]
                    {
                        "Exception filling window for ",
                        this.GetType(),
                        ": ",
                        ex
                    }), false);
                }
                GUI.EndGroup();
                if (this.resizeable && UnityEngine.Event.current.type == UnityEngine.EventType.Repaint)
                {
                    this.resizer.DoResizeControl(this.windowRect);
                }
                if (this.doCloseButton)
                {
                    Text.Font  = GameFont.Small;
                    Rect rect2 = new Rect(winRect.width / 2f - this.CloseButSize.x / 2f, winRect.height - 55f, this.CloseButSize.x, this.CloseButSize.y);
                    if (Widgets.ButtonText(rect2, "CloseButton".Translate(), true, false, true))
                    {
                        this.Close(true);
                    }
                }
                if (this.draggable)
                {
                    GUI.DragWindow();
                }
                else if (UnityEngine.Event.current.type == UnityEngine.EventType.MouseDown)
                {
                    UnityEngine.Event.current.Use();
                }
                ScreenFader.OverlayOnGUI(winRect.size);
                Find.WindowStack.currentlyDrawnWindow = null;
            }, string.Empty, Widgets.EmptyStyle);
        }