Skip to content

Commit

Permalink
Added a settings window.
Browse files Browse the repository at this point in the history
  • Loading branch information
lilSander committed Nov 9, 2023
1 parent e694489 commit 37c93fc
Show file tree
Hide file tree
Showing 5 changed files with 2,249 additions and 1 deletion.
22 changes: 21 additions & 1 deletion Assets/SEE/Controls/KeyBindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace SEE.Controls
/// <summary>
/// Defines the key codes for all interaction based on the keyboard in SEE.
/// </summary>
internal static class KeyBindings
public static class KeyBindings
{
// IMPORTANT NOTES:
// (1) Keep in mind that KeyCodes in Unity map directly to a
Expand Down Expand Up @@ -74,6 +74,21 @@ internal static void PrintBindings()
Debug.Log(sb.ToString());
}

/// <summary>
/// Creates a string of the current key bindings along
/// with their help message.
/// </summary>
public static string ShowBindings()
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (var binding in bindings)
{
sb.Append($"Key {binding.Key}:\n {binding.Value}\n");
sb.Append("\n");
}
return sb.ToString();
}

//-----------------------------------------------------
#region General key bindings
//-----------------------------------------------------
Expand Down Expand Up @@ -101,6 +116,11 @@ internal static void PrintBindings()
/// </summary>
internal static readonly KeyCode ToggleMenu = Register(KeyCode.Space, Scope.Always, "Turns on/off the player-action menu.");

/// <summary>
/// Turns on the settings menu.
/// </summary>
internal static readonly KeyCode ActivateSettings = Register(KeyCode.Escape, Scope.Always, "Turns on the settings menu.");

/// <summary>
/// Turns on/off the browser.
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions Assets/SEE/Controls/SEEInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ public static bool ToggleMenu()
return KeyboardShortcutsEnabled && Input.GetKeyDown(KeyBindings.ToggleMenu);
}

/// <summary>
/// Turns on the settings menu.
/// </summary>
/// <returns>true if the user requests this action and <see cref="KeyboardShortcutsEnabled"/></returns>
public static bool ActivateSettings()
{
return KeyboardShortcutsEnabled && Input.GetKeyDown(KeyBindings.ActivateSettings);
}

/// <summary>
/// Turns on/off the browser.
/// </summary>
Expand Down
47 changes: 47 additions & 0 deletions Assets/SEE/Controls/SettingsMenue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

namespace SEE.Controls
{
/// <summary>
/// Handles the actions in the
/// settings canvas.
/// </summary>
public class SettingsMenue : MonoBehaviour
{
//The text box, which will display the text
public TMP_Text keybindingsText;

//The settings panel which will be activated
public GameObject settings;

// Start is called before the first frame update
//Sets the text of the textbox
void Start()
{
keybindingsText.text = KeyBindings.ShowBindings();
}

// Update is called once per frame
//Activates the settings panel with the esc button
void Update()
{
if(SEEInput.ActivateSettings())
{
settings.SetActive(true);
}
}

//When this method is called, the application will be terminated
public void ExitGame()
{
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
}
}
}
11 changes: 11 additions & 0 deletions Assets/SEE/Controls/SettingsMenue.cs.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ecd882add9e68744a83afa8a7c94ba90
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Loading

0 comments on commit 37c93fc

Please sign in to comment.