/// <inheritdoc/> public void RegisterImportersAndProcessors(IEnumerable <Assembly> additionalAssemblies) { Contract.EnsureNot(registered, UltravioletStrings.ContentHandlersAlreadyRegistered); var asmUltravioletCore = typeof(UltravioletContext).Assembly; var asmUltravioletImpl = Ultraviolet.GetType().Assembly; var asmUltravioletPlatform = Ultraviolet.GetPlatform().GetType().Assembly; var asmUltravioletContent = Ultraviolet.GetContent().GetType().Assembly; var asmUltravioletGraphics = Ultraviolet.GetGraphics().GetType().Assembly; var asmUltravioletAudio = Ultraviolet.GetAudio().GetType().Assembly; var asmUltravioletInput = Ultraviolet.GetInput().GetType().Assembly; var asmUltravioletUI = Ultraviolet.GetUI().GetType().Assembly; var assemblies = new[] { asmUltravioletCore, asmUltravioletImpl, asmUltravioletPlatform, asmUltravioletContent, asmUltravioletGraphics, asmUltravioletAudio, asmUltravioletInput, asmUltravioletUI }.Union(additionalAssemblies ?? Enumerable.Empty <Assembly>()).Where(x => x != null).Distinct(); foreach (var asm in assemblies) { importers.RegisterAssembly(asm); processors.RegisterAssembly(asm); } registered = true; }
/// <summary> /// Called when the application is loading content. /// </summary> protected override void OnLoadingContent() { this.content = ContentManager.Create("Content"); if (Ultraviolet.IsRunningInServiceMode) { LoadPresentation(); CompileContent(); CompileBindingExpressions(); Environment.Exit(0); } else { LoadLocalizationDatabases(content); LoadContentManifests(content); LoadPresentation(); GC.Collect(2); var screenService = new UIScreenService(content); var screen = screenService.Get <GameMenuScreen>(); Ultraviolet.GetUI().GetScreens().Open(screen); } base.OnLoadingContent(); }
/// <summary> /// Loads the screen's panel definition from the specified asset. /// </summary> /// <param name="asset">The name of the asset that contains the panel definition.</param> /// <returns>The panel definition that was loaded from the specified asset.</returns> protected virtual WatchedAsset <UIPanelDefinition> LoadPanelDefinition(String asset) { if (String.IsNullOrEmpty(asset)) { return(null); } var display = Window?.Display ?? Ultraviolet.GetPlatform().Displays.PrimaryDisplay; var density = display.DensityBucket; Scale = display.DensityScale; var watch = Ultraviolet.GetUI().WatchingViewFilesForChanges; if (watch) { var definition = new WatchedAsset <UIPanelDefinition>(LocalContent, asset, density, OnValidatingUIPanelDefinition, OnReloadingUIPanelDefinition); return(definition); } else { var definition = LocalContent.Load <UIPanelDefinition>(asset, density); return(new WatchedAsset <UIPanelDefinition>(LocalContent, definition)); } }
/// <summary> /// Compiles the game's binding expressions. /// </summary> private void CompileBindingExpressions() { #if !IMGUI if (ShouldCompileBindingExpressions()) { var upf = Ultraviolet.GetUI().GetPresentationFoundation(); var flags = CompileExpressionsFlags.None; if (resolveContent) { flags |= CompileExpressionsFlags.ResolveContentFiles; } if (compileExpressions) { flags |= CompileExpressionsFlags.IgnoreCache; } var sw = System.Diagnostics.Stopwatch.StartNew(); upf.CompileExpressionsIfSupported("Content", flags); sw.Stop(); Console.WriteLine(sw.Elapsed); } #endif }
/// <summary> /// Called when the application is loading content. /// </summary> protected override void OnLoadingContent() { ContentManager.GloballySuppressDependencyTracking = !ShouldDynamicallyReloadContent(); this.content = ContentManager.Create("Content"); if (Ultraviolet.IsRunningInServiceMode) { LoadPresentation(); CompileContent(); CompileBindingExpressions(); Environment.Exit(0); } else { LoadLocalizationPlugins(); LoadLocalizationDatabases(); LoadInputBindings(); LoadContentManifests(); LoadPresentation(); this.screenService = new UIScreenService(content); var surface = content.Load <Ultraviolet.Graphics.Surface3D>("Textures/test_0"); GC.Collect(2); var screen = screenService.Get <GameMenuScreen>(); Ultraviolet.GetUI().GetScreens().Open(screen); } base.OnLoadingContent(); }
private void LoadPresentation() { var upf = Ultraviolet.GetUI().GetPresentationFoundation(); var globalStylesheet = content.Load <UvssDocument>("UI/DefaultUIStyles"); upf.SetGlobalStyleSheet(globalStylesheet); upf.CompileExpressionsIfSupported("Content"); upf.LoadCompiledExpressions(); }
/// <inheritdoc/> protected override void OnValidationComplete(String path, UvssDocument asset, Boolean validated) { if (validated) { return; } var upf = Ultraviolet.GetUI().GetPresentationFoundation(); upf.TrySetGlobalStyleSheet(this); }
/// <inheritdoc/> protected override void Dispose(Boolean disposing) { if (disposing && !Ultraviolet.Disposed) { Ultraviolet.GetUI().Updating -= StoryboardClockPool_Updating; SafeDispose.DisposeRef(ref pool); } base.Dispose(disposing); }
protected override void OnLoadingContent() { this.content = ContentManager.Create("Content"); LoadContentManifests(); var screenService = new UIScreenService(content); var screen = screenService.Get <SampleScreen1>(); Ultraviolet.GetUI().GetScreens().Open(screen, TimeSpan.Zero); base.OnLoadingContent(); }
private void LoadPresentation() { var upf = Ultraviolet.GetUI().GetPresentationFoundation(); var globalStylesheet = GlobalStyleSheet.Create(); globalStylesheet.Append(content, "UI/DefaultUIStyles"); upf.SetGlobalStyleSheet(globalStylesheet); upf.CompileExpressionsIfSupported("Content"); upf.LoadCompiledExpressions(); }
/// <summary> /// Finds all of the compiled binding expressions on the current data /// source and adds them to the context's registry. /// </summary> private void FindCompiledBindingExpressions() { var wrapperName = default(String); var wrapperType = DataSource is PresentationFoundationView ? DataSourceType : null; if (wrapperType == null) { for (var templateType = TemplatedParent.GetType(); templateType != null; templateType = templateType.BaseType) { wrapperName = PresentationFoundationView.GetDataSourceWrapperNameForComponentTemplate(templateType); wrapperType = Ultraviolet.GetUI().GetPresentationFoundation().GetDataSourceWrapperTypeByName(wrapperName); if (wrapperType != null) { break; } } if (wrapperType == null) { wrapperName = PresentationFoundationView.GetDataSourceWrapperNameForComponentTemplate(TemplatedParent.GetType()); throw new UvmlException(PresentationStrings.CannotFindViewModelWrapper.Format(wrapperName)); } } var properties = wrapperType.GetProperties().Where(x => x.Name.StartsWith("__UPF_Expression")).ToList(); var propertiesWithExpressions = from prop in properties let attr = (CompiledBindingExpressionAttribute)prop.GetCustomAttributes(typeof(CompiledBindingExpressionAttribute), false).Single() let expr = attr.Expression select new { Property = prop, Expression = expr, }; foreach (var prop in propertiesWithExpressions) { var key = new CompiledBindingExpressionKey(prop.Property.PropertyType, prop.Expression); compiledBindingExpressions.Add(key, prop.Property); } var uniques = compiledBindingExpressions.GroupBy(x => x.Key).Where(x => x.Count() == 1).ToList(); foreach (var unique in uniques) { var key = new CompiledBindingExpressionKey(null, unique.Key.Expression); compiledBindingExpressions[key] = unique.Single().Value; } }
/// <summary> /// Updates the Presentation Foundation's pool of storyboard instances when the UI subsystem is updated. /// </summary> private void StoryboardInstancePool_Updating(IUltravioletSubsystem subsystem, UltravioletTime time) { if (pool == null) { return; } var upf = Ultraviolet.GetUI().GetPresentationFoundation(); upf.PerformanceStats.BeginUpdate(); pool.Update(); upf.PerformanceStats.EndUpdate(); }
/// <summary> /// Updates the state of the out-of-band renderer. /// </summary> public void Update() { if (renderTargetPool == null) { return; } var upf = Ultraviolet.GetUI().GetPresentationFoundation(); upf.PerformanceStats.BeginUpdate(); renderTargetPool.Update(); upf.PerformanceStats.EndUpdate(); }
/// <summary> /// Loads the control's component root from the control's associated template. /// </summary> private void LoadComponentRoot() { if (componentRoot != null) { throw new InvalidOperationException(PresentationStrings.ComponentRootAlreadyLoaded); } var template = Ultraviolet.GetUI().GetPresentationFoundation().ComponentTemplates.Get(this); if (template == null) { return; } this.ComponentRoot = UvmlLoader.LoadComponentTemplate(this, template); }
private void LoadPresentation() { var upf = Ultraviolet.GetUI().GetPresentationFoundation(); upf.RegisterKnownTypes(GetType().Assembly); if (!ShouldRunInServiceMode()) { globalStyleSheet = GlobalStyleSheet.Create(); globalStyleSheet.Append(content, "UI/DefaultUIStyles"); upf.SetGlobalStyleSheet(globalStyleSheet); CompileBindingExpressions(); upf.LoadCompiledExpressions(); } }
protected override void OnLoadingContent() { this.content = ContentManager.Create("Content"); LoadContentManifests(this.content); LoadLocalizationDatabases(this.content); LoadPresentation(); GC.Collect(2); var screenService = new UIScreenService(content); var screen = screenService.Get <ExampleScreen>(); Ultraviolet.GetUI().GetScreens().Open(screen); base.OnLoadingContent(); }
/// <summary> /// Updates the active clock instances when the UI subsystem is updated. /// </summary> private void StoryboardClockPool_Updating(IUltravioletSubsystem subsystem, UltravioletTime time) { if (pool == null) { return; } var upf = Ultraviolet.GetUI().GetPresentationFoundation(); upf.PerformanceStats.BeginUpdate(); pool.Update(time, (value, state) => { value.Value.Update((UltravioletTime)state); }); upf.PerformanceStats.EndUpdate(); }
/// <inheritdoc/> protected override void Dispose(Boolean disposing) { if (Disposed) { return; } if (disposing) { if (Window != null && !Window.Disposed) { Ultraviolet.GetUI().GetScreens(Window).Close(this, TimeSpan.Zero); } } SafeDispose.Dispose(pendingView); base.Dispose(disposing); }
/// <summary> /// Loads files necessary for the Presentation Foundation. /// </summary> private void LoadPresentation() { var upf = Ultraviolet.GetUI().GetPresentationFoundation(); upf.RegisterKnownTypes(GetType().Assembly); if (!ShouldRunInServiceMode()) { var globalStyleSheet = new UvssDocument(Ultraviolet); globalStyleSheet.Append(content.Load <UvssDocument>("UI/DefaultUIStyles")); globalStyleSheet.Append(content.Load <UvssDocument>("UI/GameStyles")); upf.SetGlobalStyleSheet(globalStyleSheet); CompileBindingExpressions(); upf.LoadCompiledExpressions(); Diagnostics.DrawDiagnosticsVisuals = true; } }
private void CompileBindingExpressions() { if (!ShouldCompileBindingExpressions()) { return; } var compilationFlags = CompileExpressionsFlags.None; if ((this.flags & GameFlags.CompileExpressions) == GameFlags.CompileExpressions) { compilationFlags |= CompileExpressionsFlags.ResolveContentFiles; compilationFlags |= CompileExpressionsFlags.IgnoreCache; } var upf = Ultraviolet.GetUI().GetPresentationFoundation(); upf.CompileExpressionsIfSupported("Content", compilationFlags); }
/// <summary> /// Loads files necessary for the Presentation Foundation. /// </summary> protected void LoadPresentation() { var upf = Ultraviolet.GetUI().GetPresentationFoundation(); upf.RegisterKnownTypes(GetType().Assembly); if (!ShouldRunInServiceMode()) { var reloadGlobalStyleSheet = new WatchedAssetReloadingHandler(() => Ultraviolet.GetUI().GetPresentationFoundation().TrySetGlobalStyleSheet(globalStyleSheet.ToUvssDocument())); globalStyleSheet = new CompositeUvssDocument(Ultraviolet, reloadGlobalStyleSheet); globalStyleSheet.Append(content, "UI/DefaultUIStyles"); globalStyleSheet.Append(content, "UI/GameStyles"); reloadGlobalStyleSheet(); CompileBindingExpressions(); upf.LoadCompiledExpressions(); } }
/// <summary> /// Appends a child document to the composite document. /// </summary> /// <param name="content"></param> /// <param name="asset"></param> public void Append(ContentManager content, String asset) { if (Ultraviolet.GetUI().WatchingViewFilesForChanges) { var child = content.LoadWatched <UvssDocument>(asset, () => { if (onReloading != null) { return(onReloading()); } return(true); }); children.Add(child); } else { var child = content.Load <UvssDocument>(asset); children.Add(child); } }
/// <summary> /// Compiles the game's binding expressions. /// </summary> private void CompileBindingExpressions() { if (ShouldCompileBindingExpressions()) { var upf = Ultraviolet.GetUI().GetPresentationFoundation(); var flags = CompileExpressionsFlags.None; if (resolveContent) { flags |= CompileExpressionsFlags.ResolveContentFiles; } if (compileExpressions) { flags |= CompileExpressionsFlags.IgnoreCache; } upf.CompileExpressionsIfSupported("Content", flags); } }
protected override void OnLoadingContent() { this.content = ContentManager.Create("Content"); LoadContentManifests(); LoadPresentation(); if (Ultraviolet.IsRunningInServiceMode) { CompileBindingExpressions(); Environment.Exit(0); } else { this.screenService = new UIScreenService(content); var screen = screenService.Get <ExampleScreen>(); Ultraviolet.GetUI().GetScreens().Open(screen); } base.OnLoadingContent(); }
protected override void OnLoadingContent() { this.content = ContentManager.Create("Content"); LoadContentManifests(); var screenService = new UIScreenService(content); var screen = screenService.Get <LoadingScreen>(); screen.SetContentManager(this.content); screen.AddLoadingStep("Loading, please wait..."); screen.AddLoadingStep(Ultraviolet.GetContent().Manifests["Global"]); screen.AddLoadingDelay(2500); screen.AddLoadingStep("Loading interface..."); screen.AddLoadingStep(screenService.Load); screen.AddLoadingDelay(2500); screen.AddLoadingStep("Reticulating splines..."); screen.AddLoadingDelay(2500); Ultraviolet.GetUI().GetScreens().Open(screen, TimeSpan.Zero); base.OnLoadingContent(); }
/// <summary> /// Draws out-of-band elements to their render buffers. /// </summary> /// <param name="time">Time elapsed since the last call to <see cref="UltravioletContext.Draw(UltravioletTime)"/>.</param> public void DrawRenderTargets(UltravioletTime time) { Contract.EnsureNotDisposed(this, Disposed); if (registeredElements.Count == 0) { return; } var graphics = Ultraviolet.GetGraphics(); var upf = Ultraviolet.GetUI().GetPresentationFoundation(); upf.PerformanceStats.BeginDraw(); try { isDrawingRenderTargets = true; foreach (var registeredElement in registeredElements) { var element = (UIElement)registeredElement.Target; if (element != null && element.OutOfBandRenderTarget != null) { element.OutOfBandRenderTarget.Value.IsReady = false; } if (element.View != null && !element.View.LayoutRoot.IsLoaded) { viewsNeedingLoading.Add(element.View); } } foreach (var view in viewsNeedingLoading) { view.EnsureIsLoaded(); } viewsNeedingLoading.Clear(); registeredElements.Sort(uiElementComparer); foreach (var registeredElement in registeredElements) { var element = (UIElement)registeredElement.Target; if (element == null) { deadReferences.Add(registeredElement); continue; } if (element.View == null) { continue; } var bounds = default(RectangleD); var effect = element.Effect; var rtarget = element.OutOfBandRenderTarget.Value; if (rtarget.ResizeForElement(element, out bounds)) { for (var current = rtarget.Next; current != null; current = current.Next) { current.Resize(rtarget.Width, rtarget.Height); } } var popup = element as Popup; if (popup != null) { if (!popup.IsOpen) { continue; } element = popup.Root; } if (!element.TransformedVisualBounds.IsEmpty && !IsVisuallyDisconnectedFromRoot(element)) { graphics.SetRenderTarget(rtarget.RenderTarget, Color.Transparent); drawingContext.Reset(element.View.Display); var visualParent = VisualTreeHelper.GetParent(element) as UIElement; var visualTransformOfParent = (visualParent == null) ? popup.PopupTransformToView : visualParent.GetVisualTransformMatrix(); var visualTransformOfElement = element.GetVisualTransformMatrix(ref visualTransformOfParent); rtarget.VisualTransform = visualTransformOfElement; rtarget.VisualBounds = bounds; currentElementDrawingRenderTarget = element; element.DrawToRenderTarget(time, drawingContext, rtarget.RenderTarget, (popup != null) ? popup.PopupTransformToViewInDevicePixels : visualTransformOfParent); if (rtarget.Next != null) { if (effect != null) { effect.DrawRenderTargets(drawingContext, element, rtarget); } } currentElementDrawingRenderTarget = null; rtarget.IsReady = true; } } foreach (var deadReference in deadReferences) { registeredElements.Remove(deadReference); } } finally { isDrawingRenderTargets = false; currentElementDrawingRenderTarget = null; } deadReferences.Clear(); graphics.SetRenderTarget(null, Color.Transparent); upf.PerformanceStats.EndDraw(); }
/// <inheritdoc/> protected override bool OnValidating(String path, UvssDocument asset) { var upf = Ultraviolet.GetUI().GetPresentationFoundation(); return(upf.TrySetGlobalStyleSheet(this)); }
/// <summary> /// Loads the screen's panel definition from the specified asset. /// </summary> /// <param name="asset">The name of the asset that contains the panel definition.</param> /// <returns>The panel definition that was loaded from the specified asset.</returns> protected virtual UIPanelDefinitionWrapper LoadPanelDefinition(String asset) { if (String.IsNullOrEmpty(asset)) { return(null); } var watch = Ultraviolet.GetUI().WatchingViewFilesForChanges; if (watch) { var definition = LocalContent.LoadWatched <UIPanelDefinition>(asset, () => { if (State == UIPanelState.Open) { var currentViewModel = View?.ViewModel; var currentView = View; if (currentView != null) { currentView.OnClosing(); currentView.OnClosed(); UnloadView(); } FinishLoadingView(); var updatedView = View; if (updatedView != null) { try { if (currentViewModel != null) { updatedView.SetViewModel(currentViewModel); } updatedView.OnOpening(); updatedView.OnOpened(); } catch (Exception e) { UnloadView(); Debug.WriteLine(UltravioletStrings.ExceptionDuringViewReloading); Debug.WriteLine(e); return(false); } } } return(true); }); foreach (var styleSheetAsset in definition.Value.StyleSheetAssets) { LocalContent.AddWatchedDependency(asset, styleSheetAsset); } return(new UIPanelDefinitionWrapper(definition)); } else { var definition = LocalContent.Load <UIPanelDefinition>(asset); return(new UIPanelDefinitionWrapper(definition)); } }
/// <summary> /// Draws the diagnostics panel to the current window. /// </summary> public void Draw() { LoadContentIfNecessary(); var window = Ultraviolet.GetPlatform().Windows.GetCurrent(); if (window == null) { throw new InvalidOperationException(); } var upf = Ultraviolet.GetUI().GetPresentationFoundation(); var panelWidth = 400; var panelHeight = 16f + (7.5f * font.Regular.LineSpacing); var panelArea = new RectangleF((window.Compositor.Width - panelWidth) / 2, 0, panelWidth, panelHeight); var colorHeader = Color.Yellow; var colorSubheader = new Color(200, 200, 0); var colWidth = (panelWidth - 24) / 3; var xCol1 = panelArea.X + 8f; var xCol2 = xCol1 + colWidth + 8f; var xCol3 = xCol2 + colWidth + 8f; var yLine = 8f; spriteBatch.Begin(); spriteBatch.Draw(blankTexture, panelArea, Color.Black * 0.5f); spriteBatch.DrawString(font, "MEMORY", new Vector2(xCol1, yLine), colorHeader); spriteBatch.DrawString(font, "UPDATE", new Vector2(xCol2, yLine), colorHeader); spriteBatch.DrawString(font, "DRAW", new Vector2(xCol3, yLine), colorHeader); yLine += font.Regular.LineSpacing; formatter.Reset(); formatter.AddArgument(GC.GetTotalMemory(false) / 1024.0); formatter.Format("{0:decimals:2} Kb", buffer); spriteBatch.DrawString(font, buffer, new Vector2(xCol1, yLine), Color.White); formatter.Reset(); formatter.AddArgument(upf.PerformanceStats.TimeInUpdateLastFrame.TotalMilliseconds); formatter.Format("{0:decimals:2} ms", buffer); spriteBatch.DrawString(font, buffer, new Vector2(xCol2, yLine), Color.White); formatter.Reset(); formatter.AddArgument(upf.PerformanceStats.TimeInDrawLastFrame.TotalMilliseconds); formatter.Format("{0:decimals:2} ms", buffer); spriteBatch.DrawString(font, buffer, new Vector2(xCol3, yLine), Color.White); yLine += font.Regular.LineSpacing * 1.5f; spriteBatch.DrawString(font, "POOLS", new Vector2(xCol1, yLine), colorHeader); yLine += font.Regular.LineSpacing; spriteBatch.DrawString(font, "Simple Clock", new Vector2(xCol1, yLine), colorSubheader); spriteBatch.DrawString(font, "Storyboard Instance", new Vector2(xCol2, yLine), colorSubheader); spriteBatch.DrawString(font, "Storyboard Clock", new Vector2(xCol3, yLine), colorSubheader); yLine += font.Regular.LineSpacing; formatter.Reset(); formatter.AddArgument(SimpleClockPool.Instance.Active); formatter.AddArgument(SimpleClockPool.Instance.Available); formatter.AddArgument(SimpleClockPool.Instance.Active + SimpleClockPool.Instance.Available); formatter.Format("{0} / {1} [{2}]", buffer); spriteBatch.DrawString(font, buffer, new Vector2(xCol1, yLine), Color.White); formatter.Reset(); formatter.AddArgument(StoryboardInstancePool.Instance.Active); formatter.AddArgument(StoryboardInstancePool.Instance.Available); formatter.AddArgument(StoryboardInstancePool.Instance.Active + StoryboardInstancePool.Instance.Available); formatter.Format("{0} / {1} [{2}]", buffer); spriteBatch.DrawString(font, buffer, new Vector2(xCol2, yLine), Color.White); formatter.Reset(); formatter.AddArgument(StoryboardClockPool.Instance.Active); formatter.AddArgument(StoryboardClockPool.Instance.Available); formatter.AddArgument(StoryboardClockPool.Instance.Active + StoryboardClockPool.Instance.Available); formatter.Format("{0} / {1} [{2}]", buffer); spriteBatch.DrawString(font, buffer, new Vector2(xCol3, yLine), Color.White); yLine += font.Regular.LineSpacing; spriteBatch.DrawString(font, "OOB Render Target", new Vector2(xCol1, yLine), colorSubheader); spriteBatch.DrawString(font, "Weak Refs", new Vector2(xCol2, yLine), colorSubheader); yLine += font.Regular.LineSpacing; formatter.Reset(); formatter.AddArgument(upf.OutOfBandRenderer.ActiveRenderTargets); formatter.AddArgument(upf.OutOfBandRenderer.AvailableRenderTargets); formatter.AddArgument(upf.OutOfBandRenderer.ActiveRenderTargets + upf.OutOfBandRenderer.AvailableRenderTargets); formatter.Format("{0} / {1} [{2}]", buffer); spriteBatch.DrawString(font, buffer, new Vector2(xCol1, yLine), Color.White); formatter.Reset(); formatter.AddArgument(WeakReferencePool.Instance.Active); formatter.AddArgument(WeakReferencePool.Instance.Available); formatter.AddArgument(WeakReferencePool.Instance.Active + WeakReferencePool.Instance.Available); formatter.Format("{0} / {1} [{2}]", buffer); spriteBatch.DrawString(font, buffer, new Vector2(xCol2, yLine), Color.White); spriteBatch.End(); }