Inheritance: AcTools.Render.Wrapper.LiteShowroomWrapper
Exemplo n.º 1
0
        public static async Task StartLiteAsync(string kn5, string skinId = null) {
            if (_starting) return;
            _starting = true;

            _last?.Stop();
            _last = null;

            ForwardKn5ObjectRenderer renderer = null;
            Logging.Write("Custom Showroom: Magick.NET IsSupported=" + ImageUtils.IsMagickSupported);
            RenderLogging.Initialize(Logging.Filename, true);

            try {
                var carDirectory = Path.GetDirectoryName(kn5);
                if (Path.GetFileName(Path.GetDirectoryName(carDirectory)) == @"..") {
                    carDirectory = Path.GetDirectoryName(Path.GetDirectoryName(carDirectory));
                }

                var carObject = CarsManager.Instance.GetById(Path.GetFileName(carDirectory) ?? "");
                var toolboxMode = IsSameDirectories(carObject?.Location, carDirectory);

                LiteShowroomWrapper wrapper;
                using (var waiting = new WaitingDialog()) {
                    waiting.Report(ControlsStrings.CustomShowroom_Loading);

                    if (toolboxMode) {
                        renderer = await Task.Run(() => new ToolsKn5ObjectRenderer(kn5, carDirectory));
                        wrapper = new LiteShowroomWrapperWithTools((ToolsKn5ObjectRenderer)renderer, carObject, skinId);
                    } else {
                        Logging.Warning($"Can’t find CarObject for “{carDirectory}”");
                        Logging.Warning($"Found location: “{carObject?.Location ?? @"NULL"}”");

                        renderer = await Task.Run(() => new ForwardKn5ObjectRenderer(kn5, carDirectory));
                        wrapper = new LiteShowroomWrapper(renderer);

                        if (skinId != null) {
                            renderer.SelectSkin(skinId);
                        }
                    }

                    renderer.UseMsaa = SettingsHolder.CustomShowroom.LiteUseMsaa;
                    renderer.UseFxaa = SettingsHolder.CustomShowroom.LiteUseFxaa;
                    renderer.UseBloom = SettingsHolder.CustomShowroom.LiteUseBloom;

                    _last = wrapper;
                    SetProperties(wrapper, renderer);

                    wrapper.Form.Icon = AppIconService.GetAppIcon();
                }

                wrapper.Run(() => _starting = false);
                GC.Collect();
            } catch (Exception e) {
                NonfatalError.Notify(ControlsStrings.CustomShowroom_CannotStart, e);
            } finally {
                renderer?.Dispose();
                _last = null;
                _starting = false;
            }
        }
Exemplo n.º 2
0
        public static async Task StartLiteAsync(string kn5, string skinId = null)
        {
            if (_starting)
            {
                return;
            }
            _starting = true;

            _last?.Stop();
            _last = null;

            ForwardKn5ObjectRenderer renderer = null;

            Logging.Write("Custom Showroom: Magick.NET IsSupported=" + ImageUtils.IsMagickSupported);
            RenderLogging.Initialize(Logging.Filename, true);

            try {
                var carDirectory = Path.GetDirectoryName(kn5);
                if (Path.GetFileName(Path.GetDirectoryName(carDirectory)) == @"..")
                {
                    carDirectory = Path.GetDirectoryName(Path.GetDirectoryName(carDirectory));
                }

                var carObject   = CarsManager.Instance.GetById(Path.GetFileName(carDirectory) ?? "");
                var toolboxMode = IsSameDirectories(carObject?.Location, carDirectory);

                LiteShowroomWrapper wrapper;
                using (var waiting = new WaitingDialog()) {
                    waiting.Report(ControlsStrings.CustomShowroom_Loading);

                    var description = new CarDescription(kn5, carDirectory, carObject?.AcdData);
                    if (toolboxMode)
                    {
                        ExtraModelProvider.Initialize();

                        var toolsRenderer = await Task.Run(() => SettingsHolder.CustomShowroom.UseOldLiteShowroom?
                                                           new ToolsKn5ObjectRenderer(description) {
                            VisibleUi = false,
                            UseSprite = false,
                            UseMsaa   = SettingsHolder.CustomShowroom.LiteUseMsaa,
                            UseFxaa   = SettingsHolder.CustomShowroom.LiteUseFxaa,
                            UseBloom  = SettingsHolder.CustomShowroom.LiteUseBloom
                        } :
                                                           new DarkKn5ObjectRenderer(description)
                        {
                            VisibleUi = false,
                            UseSprite = false
                        });

                        wrapper  = new LiteShowroomWrapperWithTools(toolsRenderer, carObject, skinId);
                        renderer = toolsRenderer;
                    }
                    else
                    {
                        Logging.Warning($"Can’t find CarObject for “{carDirectory}”");
                        Logging.Warning($"Found location: “{carObject?.Location ?? @"NULL"}”");

                        renderer = await Task.Run(() => SettingsHolder.CustomShowroom.UseOldLiteShowroom?
                                                  new ForwardKn5ObjectRenderer(description) {
                            UseMsaa  = SettingsHolder.CustomShowroom.LiteUseMsaa,
                            UseFxaa  = SettingsHolder.CustomShowroom.LiteUseFxaa,
                            UseBloom = SettingsHolder.CustomShowroom.LiteUseBloom
                        } :
                                                  new DarkKn5ObjectRenderer(description)
                        {
                            FlatMirror = true,
                            VisibleUi  = true,
                            UseSprite  = true
                        });

                        wrapper = new LiteShowroomWrapper(renderer);

                        if (skinId != null)
                        {
                            renderer.SelectSkin(skinId);
                        }
                    }

                    _last = wrapper;
                    SetProperties(wrapper, renderer);

                    wrapper.Form.Icon = AppIconService.GetAppIcon();
                }

                wrapper.Run(() => _starting = false);
                GC.Collect();
            } catch (Exception e) {
                NonfatalError.Notify(ControlsStrings.CustomShowroom_CannotStart, e);
            } finally {
                renderer?.Dispose();
                _last     = null;
                _starting = false;
            }
        }