public void Remove(SceneUIElement element, bool bDestroy) { LayoutItem item; bool bFound = find_item(element, out item); if (bFound == false) { throw new Exception("BoxModelLayoutEngine.Remove: element is not in layout"); } if (element is HUDStandardItem == false) { throw new Exception("BoxModelLayoutEngine.Add: element must be a HUDStandardItem"); } remove_item(element); Solver.RemoveLayoutItem(element); // this will remove from cockpit after transition if ((item.flags & LayoutFlags.AnimatedDismiss) != 0) { HUDUtil.AnimatedDimiss_Cockpit(element as HUDStandardItem, this.Cockpit, bDestroy); } else { this.Cockpit.RemoveUIElement(element, bDestroy); } }
/// <summary> /// Show the Toast widget with an animated fade in. The widget will fade out /// after Duration seconds, unless the user hovers over it, in which case it /// will stay until they end the hover. /// </summary> public void Show(Cockpit cockpit, float fDuration, float fFadeInOut = 0.25f) { AlphaFade = 0.0f; hovering = false; disappear = false; // if this goes true, toast will begin animated-fade on next frame dismiss = false; // we register a basic animator that just watches for dismiss=true and // when that happens we fade out and remove the toast cockpit.HUDAnimator.Register( new GenericAnimatable(() => { if (dismiss) { HUDUtil.AnimatedDimiss_Cockpit(this, cockpit, (disappear) ? 0.001f : fFadeInOut); dismiss_timer.Dispose(); return(true); } return(false); }) ); // timer event that is called after the initial duration, and then ever // couple hundred MS to check that hover ended. // This is called from a Timer, which runs in a separate thread, and hence // we cannot manipulate the scene in this function // TODO: couldn't we just do this in animator above?? Action timer_elapsed = () => { if (hovering) { dismiss_timer.Interval = 300; dismiss_timer.Start(); } else { dismiss = true; } }; // ok, this kicks everything off - we do animated transition to show ourself, // and then start a timer that waits the initial duration HUDUtil.AnimatedShow(this, fFadeInOut, () => { dismiss_timer = new Timer(fDuration * 1000); dismiss_timer.Elapsed += (o, e) => { timer_elapsed(); }; dismiss_timer.Enabled = true; }); }