public Cockpit(FContext context) { PositionMode = MovementMode.TrackPosition; GrabFocus = false; bStaticUpdated = false; this.context = context; vUIElements = new List <SceneUIElement> (); UIElementLayer = FPlatform.HUDLayer; Layouts = new Dictionary <string, ICockpitLayout>(); defaultLayout = null; vKeyHandlers = new List <IShortcutKeyHandler>(); InputBehaviors = new InputBehaviorSet() { DefaultSource = this }; OverrideBehaviors = new InputBehaviorSet() { DefaultSource = this }; HUDAnimator = new GenericAnimator(); TiltAngle = ShiftAngle = 0.0f; DefaultCursorDepth = -1; }
public void SetDefaultLayout(string name) { ICockpitLayout setdefault = null; if (Layouts.TryGetValue(name, out setdefault) == false) { throw new Exception("Cockpit.SetDefaultLayout: could not find layout named " + name); } defaultLayout = setdefault; }
/// <summary> /// Find Layout with given name, or default layout if no argument /// </summary> public ICockpitLayout Layout(string name = "") { if (name == "") { return(defaultLayout); } ICockpitLayout r = null; if (Layouts.TryGetValue(name, out r) == false) { throw new Exception("Cockpit.Layout: could not find layout named " + name); } return(r); }
/// <summary> /// Register a layout /// </summary> public void AddLayout(ICockpitLayout e, string name, bool bSetAsDefault = false) { if (Layouts.ContainsKey(name)) { throw new Exception("Cockpit.AddLayout: tried to register duplicate name " + name); } // always set first layout as default, until another default comes along if (Layouts.Count == 0) { bSetAsDefault = true; } Layouts[name] = e; if (bSetAsDefault) { defaultLayout = e; } }
/// <summary> /// Remove named layout. /// If bRemoveAllElements, then layout.RemoveAll() is called to clean up contents /// (otherwise you must do yourself). /// Note: if default layout is removed, we set default to null. You need to call SetDefaultLayout in this case. /// </summary> public void RemoveLayout(string name, bool bRemoveAllElements = true) { ICockpitLayout remove = null; if (Layouts.TryGetValue(name, out remove) == false) { throw new Exception("Cockpit.RemoveLayout: could not find layout named " + name); } Layouts.Remove(name); if (bRemoveAllElements) { remove.RemoveAll(true); } if (defaultLayout == remove) { defaultLayout = null; } // [TODO] can we auto-update default layout?? }