S&box Wiki

Revision Difference

making_a_custom_pause_screen#562453

<title>Making a Custom Pause Screen</title> <cat>UI.GameMenu</cat> # Overriding s&box's default pause menu⤶ # Overriding s&box's Default Pause Menu⤶ By default, s&box gives every game a default pause menu, this lets people rebind and change settings even when the developer themselves hasn't created a menu for it. <upload src="b3f81/8dcabad07975c95.png" size="68183" name="image.png" /> <upload src="b3f81/8dcabb27923fbaa.png" size="19516" name="sbox_5iXD7x59uR.png" /> <note>Currently only Keybinds are able to changed with this pause menu</note> Not you though, or else you wouldn't be here. To override thie default menu put the following into your Update loop on whatever component handles turning the screen on and off⤶ Not you though, or else you wouldn't be here. This is an example of how to override it⤶ ```cs // In Update() on one of your components⤶ if ( Input.EscapePressed )⤶ {⤶ Input.EscapePressed = false;⤶ // handle escape pressed in your game⤶ }⤶ ```⤶ ⤶ An example would be ⤶ ```cs⤶ public bool Pause;⤶ //This assumes your pause screen is as simple as turning a GameObject with a screen panel on and off [Property] public GameObject PausePanel {get; set;} protected override void OnUpdate() { if ( Input.EscapePressed ) { Input.EscapePressed = false; Pause != Pause;⤶ } ⤶ if ( Pause == true ) ⤶ {⤶ PauseMenu.Enabled = true;⤶ //The ESC Key is now yours to control, so you could do the following⤶ PausePanel.Enabled != PausePanel.Enabled; } else⤶ {⤶ PauseMenu.Enabled = false;⤶ }⤶ } ``` ⤶ This is by no means the most *efficient* way to do this, but the verbosity should serve to help those that are less familiar with such means.⤶ ⤶ ## Using in-built Overlays for your menu⤶ If you wanted to use the default pause menu's Keybind Overlay, you can do so with ```html <div class="tab" @onclick="@(() => Game.Overlay.ShowBinds() )">Controls</div> ``` Same with the "About" screen ```html <div class="tab" @onclick="@(() => Game.Overlay.ShowPackageModal( [Indent Here ex: facepunch.test] ))">About</div> ```