using System; using Robust.Client.AutoGenerated; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.XAML; using Robust.Shared.Input; using Robust.Shared.Maths; using Robust.Shared.Timing; namespace Robust.Client.UserInterface.CustomControls { /// /// The default debug console that drops down from the top of the screen. /// [GenerateTypedNameReferences] public sealed partial class DropDownDebugConsole : Control { private bool _targetVisible; public DropDownDebugConsole() { RobustXamlLoader.Load(this); LayoutContainer.SetAnchorPreset(MainControl, LayoutContainer.LayoutPreset.TopWide); LayoutContainer.SetAnchorBottom(MainControl, 0.35f); MainControl.CommandBarPub.OnKeyBindDown += CommandBarPubOnOnKeyBindDown; } private void CommandBarPubOnOnKeyBindDown(GUIBoundKeyEventArgs args) { if (args.Function == EngineKeyFunctions.ShowDebugConsole) { Toggle(); args.Handle(); } else if (args.Function == EngineKeyFunctions.TextReleaseFocus) { Toggle(); args.Handle(); } } protected override void FrameUpdate(FrameEventArgs args) { base.FrameUpdate(args); if (!Visible) { return; } var targetLocation = _targetVisible ? 0 : -MainControl.Height; var (posX, posY) = MainControl.Position; if (Math.Abs(targetLocation - posY) <= 1) { if (!_targetVisible) { Visible = false; } posY = targetLocation; } else { posY = MathHelper.Lerp(posY, targetLocation, args.DeltaSeconds * 20); } LayoutContainer.SetPosition(MainControl, (posX, posY)); } public void Toggle() { var bar = MainControl.CommandBarPub; _targetVisible = !_targetVisible; if (_targetVisible) { Visible = true; bar.IgnoreNext = true; bar.GrabKeyboardFocus(); } else { bar.ReleaseKeyboardFocus(); } } } }