Exemplo n.º 1
0
        private static bool DrawReplaced(DrawingInfo info)
        {
            // Don't override if currently patching
            if (DrawingDelegator._drawing)
            {
                return(false);
            }

            // Check if this texture is being tracked
            if (!DrawingDelegator._textureToTrackedTexture.TryGetValue(info.Texture, out TrackedTexture trackedTexture))
            {
                return(false);
            }

            // Check if any overrides handle this drawing call
            bool modified = false;

            foreach (EventHandler <IDrawingInfo> drawingHandler in trackedTexture.GetDrawingHandlers())
            {
                // Set the drawing info's Modified property to false, then execute the overrider
                info.Reset();
                drawingHandler(null, info);

                // Check if modified
                if (info.Modified)
                {
                    modified = true;
                }

                // Check if should continue propagating
                if (!info.Propagate || info.Cancelled)
                {
                    break;
                }
            }

            // Check if any handlers modified the drawing info
            if (!modified)
            {
                RaiseAfterDrawn();
                return(false);
            }

            // Call the native draw code if not cancelled
            if (!info.Cancelled)
            {
                DrawingDelegator._drawing = true;
                info.Draw();
                DrawingDelegator._drawing = false;
                RaiseAfterDrawn();
            }

            // Return whether it was handled
            return(true);

            void RaiseAfterDrawn()
            {
                ReadonlyDrawingInfo finalInfo = new ReadonlyDrawingInfo(info);

                foreach (EventHandler <IReadonlyDrawingInfo> drawnHandler in trackedTexture.GetDrawnHandlers())
                {
                    drawnHandler(null, finalInfo);
                }
            }
        }