private static void AddWindowInjectorByAttribute(MemberInfo info, Attribute attrib)
        {
            var injectionAttribute = attrib as WindowInjectionAttribute;
            var destination        = info as MethodInfo;

            if (destination == null || injectionAttribute == null)
            {
                throw new Exception("Null or unexpected argument types!");
            }
            if (!destination.IsStatic || !destination.MethodMatchesSignature(typeof(void), typeof(Window), typeof(Rect)))
            {
                HugsLibController.Logger.Error("Window injection method ({0}) must be static and match the following signature: {1}", info, WindowInjectionAttribute.ExpectedSignature);
            }
            try {
                var callback          = (WindowInjectionManager.DrawInjectedContents)Delegate.CreateDelegate(typeof(WindowInjectionManager.DrawInjectedContents), destination);
                var declaringTypeName = destination.DeclaringType != null ? destination.DeclaringType.FullName : "";
                var injectionId       = declaringTypeName + "." + destination.Name;
                WindowInjectionManager.AddInjection(injectionAttribute.WindowType, callback, injectionId, injectionAttribute.Mode);
            } catch (Exception e) {
                HugsLibController.Logger.ReportException(e);
            }
        }
Ejemplo n.º 2
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 ===
        }