Beispiel #1
0
        public void Initialize(ScreenLayer initialLayer = null)
        {
            ResourceContainer = new AssemblyResourceContainer(Assembly.GetEntryAssembly(), $"{nameof(StorybrewEditor)}.Resources", "resources");

            DrawState.Initialize(ResourceContainer, Window.Width, Window.Height);
            drawContext = new DrawContext();
            drawContext.Register(this, false);
            drawContext.Register <TextureContainer>(new TextureContainerAtlas(ResourceContainer), true);
            drawContext.Register <QuadRenderer>(new QuadRendererBuffered(), true);
            drawContext.Register <LineRenderer>(new LineRendererBuffered(), true);

            try
            {
                var brewLibAssembly = Assembly.GetAssembly(typeof(Drawable));
                Skin = new Skin(drawContext.Get <TextureContainer>())
                {
                    ResolveDrawableType = (drawableTypeName) =>
                                          brewLibAssembly.GetType($"{nameof(BrewLib)}.{nameof(BrewLib.Graphics)}.{nameof(BrewLib.Graphics.Drawables)}.{drawableTypeName}", true, true),
                    ResolveWidgetType = (widgetTypeName) =>
                                        Type.GetType($"{nameof(StorybrewEditor)}.{nameof(UserInterface)}.{widgetTypeName}", false, true) ??
                                        brewLibAssembly.GetType($"{nameof(BrewLib)}.{nameof(UserInterface)}.{widgetTypeName}", true, true),
                    ResolveStyleType = (styleTypeName) =>
                                       Type.GetType($"{nameof(StorybrewEditor)}.{nameof(UserInterface)}.{nameof(UserInterface.Skinning)}.{nameof(UserInterface.Skinning.Styles)}.{styleTypeName}", false, true) ??
                                       brewLibAssembly.GetType($"{nameof(BrewLib)}.{nameof(UserInterface)}.{nameof(UserInterface.Skinning)}.{nameof(UserInterface.Skinning.Styles)}.{styleTypeName}", true, true),
                };
                Skin.Load("skin.json", ResourceContainer);
            }
            catch (Exception e)
            {
                Trace.WriteLine($"Failed to load skin: {e}");
                Skin = new Skin(drawContext.Get <TextureContainer>());
            }

            var inputDispatcher = new InputDispatcher();

            InputManager = new InputManager(Window, inputDispatcher);

            ScreenLayerManager = new ScreenLayerManager(Window, clock, this);
            inputDispatcher.Add(createOverlay(ScreenLayerManager));
            inputDispatcher.Add(ScreenLayerManager.InputHandler);

            Restart(initialLayer);

            Window.Resize  += window_Resize;
            Window.Closing += window_Closing;

            resizeToWindow();
        }