Skip to content

Commit

Permalink
Added Dvorak keyboard layout, cleaned up naming of layouts vs languages
Browse files Browse the repository at this point in the history
  • Loading branch information
John Luxford committed Jul 28, 2017
1 parent 7b94c37 commit c8df40d
Show file tree
Hide file tree
Showing 20 changed files with 146 additions and 93 deletions.
2 changes: 1 addition & 1 deletion Assets/VRKeys/Prefabs/VRKeys.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -3446,7 +3446,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
positionRelativeToUser: {x: 0, y: 1.35, z: 1.75}
language: 0
keyboardLayout: 0
placeholder: {fileID: 114000013633238574}
placeholderMessage: Tap the keys to begin typing
displayText: {fileID: 114000011935164620}
Expand Down
2 changes: 1 addition & 1 deletion Assets/VRKeys/Scripts/BackspaceKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public override void HandleTriggerEnter (Collider other) {
ActivateFor (0.3f);
}

public override void UpdateLanguage (Translation translation) {
public override void UpdateLayout (Layout translation) {
label.text = translation.backspaceButtonLabel;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/VRKeys/Scripts/ClearKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public override void HandleTriggerEnter (Collider other) {
ActivateFor (0.3f);
}

public override void UpdateLanguage (Translation translation) {
public override void UpdateLayout (Layout translation) {
label.text = translation.clearButtonLabel;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/VRKeys/Scripts/EnterKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public override void HandleTriggerEnter (Collider other) {
keyboard.Submit ();
}

public override void UpdateLanguage (Translation translation) {
public override void UpdateLayout (Layout translation) {
label.text = translation.enterButtonLabel;
}
}
Expand Down
10 changes: 6 additions & 4 deletions Assets/VRKeys/Scripts/Example/DemoScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private void OnDisable () {
/// <summary>
/// Press space to show/hide the keyboard.
///
/// Press E for English keyboard, F for French keyboard.
/// Press Q for Qwerty keyboard, D for Dvorak keyboard, and F for French keyboard.
/// </summary>
private void Update () {
if (Input.GetKeyDown (KeyCode.Space)) {
Expand All @@ -58,10 +58,12 @@ private void Update () {
return;
}

if (Input.GetKeyDown (KeyCode.E)) {
keyboard.SetLanguage (Language.English);
if (Input.GetKeyDown (KeyCode.Q)) {
keyboard.SetLayout (KeyboardLayout.Qwerty);
} else if (Input.GetKeyDown (KeyCode.F)) {
keyboard.SetLanguage (Language.French);
keyboard.SetLayout (KeyboardLayout.French);
} else if (Input.GetKeyDown (KeyCode.D)) {
keyboard.SetLayout (KeyboardLayout.Dvorak);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Assets/VRKeys/Scripts/Key.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public virtual void Enable () {
/// Update the key's label from a new language.
/// </summary>
/// <param name="translation">Translation object.</param>
public virtual void UpdateLanguage (Translation translation) {
public virtual void UpdateLayout (Layout translation) {
// Override me!
}
}
Expand Down
66 changes: 33 additions & 33 deletions Assets/VRKeys/Scripts/Keyboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class Keyboard : MonoBehaviour {

public Vector3 positionRelativeToUser = new Vector3 (0f, 1.35f, 2f);

public Language language = Language.English;
public KeyboardLayout keyboardLayout = KeyboardLayout.Qwerty;

[Space (15)]

Expand Down Expand Up @@ -141,13 +141,13 @@ public class KeyboardSubmitEvent : UnityEvent<string> { }

private KeyboardSize size;

private Translation translation;
private Layout layout;

/// <summary>
/// Initialization.
/// </summary>
IEnumerator Start () {
yield return StartCoroutine (DoSetLanguage (language));
yield return StartCoroutine (DoSetLanguage (keyboardLayout));

validationNotice.SetActive (false);
infoNotice.SetActive (false);
Expand Down Expand Up @@ -398,27 +398,27 @@ IEnumerator DelayEnableAfterResize () {
/// <summary>
/// Set the language of the keyboard.
/// </summary>
/// <param name="lang">New language.</param>
public void SetLanguage (Language lang) {
StartCoroutine (DoSetLanguage (lang));
/// <param name="layout">New language.</param>
public void SetLayout (KeyboardLayout layout) {
StartCoroutine (DoSetLanguage (layout));
}

IEnumerator DoSetLanguage (Language lang) {
language = lang;
translation = TranslationList.GetTranslation (language);
IEnumerator DoSetLanguage (KeyboardLayout lang) {
keyboardLayout = lang;
layout = LayoutList.GetLayout (keyboardLayout);

placeholderMessage = translation.placeholderMessage;
placeholderMessage = layout.placeholderMessage;

yield return StartCoroutine (SetupKeys ());

// Update extra keys
foreach (Key key in extraKeys) {
key.UpdateLanguage (translation);
key.UpdateLayout (layout);
}

// Update size keys
foreach (SizeInfo info in sizes) {
info.key.UpdateLanguage (translation);
info.key.UpdateLayout (layout);
}
}

Expand Down Expand Up @@ -513,21 +513,21 @@ IEnumerator SetupKeys () {
}
}

keys = new LetterKey[translation.TotalKeys ()];
keys = new LetterKey[layout.TotalKeys ()];
int keyCount = 0;

// Numbers row
for (int i = 0; i < translation.row1Keys.Length; i++) {
for (int i = 0; i < layout.row1Keys.Length; i++) {
GameObject obj = (GameObject) Instantiate (keyPrefab, keysParent);
obj.transform.localPosition += (Vector3.right * ((keyWidth * i) - translation.row1Offset));
obj.transform.localPosition += (Vector3.right * ((keyWidth * i) - layout.row1Offset));

LetterKey key = obj.GetComponent<LetterKey> ();
key.character = translation.row1Keys[i];
key.shiftedChar = translation.row1Shift[i];
key.character = layout.row1Keys[i];
key.shiftedChar = layout.row1Shift[i];
key.shifted = false;
key.Init (obj.transform.localPosition);

obj.name = "Key: " + translation.row1Keys[i];
obj.name = "Key: " + layout.row1Keys[i];
obj.SetActive (true);

keys[keyCount] = key;
Expand All @@ -537,18 +537,18 @@ IEnumerator SetupKeys () {
}

// QWERTY row
for (int i = 0; i < translation.row2Keys.Length; i++) {
for (int i = 0; i < layout.row2Keys.Length; i++) {
GameObject obj = (GameObject) Instantiate (keyPrefab, keysParent);
obj.transform.localPosition += (Vector3.right * ((keyWidth * i) - translation.row2Offset));
obj.transform.localPosition += (Vector3.right * ((keyWidth * i) - layout.row2Offset));
obj.transform.localPosition += (Vector3.back * keyHeight * 1);

LetterKey key = obj.GetComponent<LetterKey> ();
key.character = translation.row2Keys[i];
key.shiftedChar = translation.row2Shift[i];
key.character = layout.row2Keys[i];
key.shiftedChar = layout.row2Shift[i];
key.shifted = false;
key.Init (obj.transform.localPosition);

obj.name = "Key: " + translation.row2Keys[i];
obj.name = "Key: " + layout.row2Keys[i];
obj.SetActive (true);

keys[keyCount] = key;
Expand All @@ -558,18 +558,18 @@ IEnumerator SetupKeys () {
}

// ASDF row
for (int i = 0; i < translation.row3Keys.Length; i++) {
for (int i = 0; i < layout.row3Keys.Length; i++) {
GameObject obj = (GameObject) Instantiate (keyPrefab, keysParent);
obj.transform.localPosition += (Vector3.right * ((keyWidth * i) - translation.row3Offset));
obj.transform.localPosition += (Vector3.right * ((keyWidth * i) - layout.row3Offset));
obj.transform.localPosition += (Vector3.back * keyHeight * 2);

LetterKey key = obj.GetComponent<LetterKey> ();
key.character = translation.row3Keys[i];
key.shiftedChar = translation.row3Shift[i];
key.character = layout.row3Keys[i];
key.shiftedChar = layout.row3Shift[i];
key.shifted = false;
key.Init (obj.transform.localPosition);

obj.name = "Key: " + translation.row3Keys[i];
obj.name = "Key: " + layout.row3Keys[i];
obj.SetActive (true);

keys[keyCount] = key;
Expand All @@ -579,18 +579,18 @@ IEnumerator SetupKeys () {
}

// ZXCV row
for (int i = 0; i < translation.row4Keys.Length; i++) {
for (int i = 0; i < layout.row4Keys.Length; i++) {
GameObject obj = (GameObject) Instantiate (keyPrefab, keysParent);
obj.transform.localPosition += (Vector3.right * ((keyWidth * i) - translation.row4Offset));
obj.transform.localPosition += (Vector3.right * ((keyWidth * i) - layout.row4Offset));
obj.transform.localPosition += (Vector3.back * keyHeight * 3);

LetterKey key = obj.GetComponent<LetterKey> ();
key.character = translation.row4Keys[i];
key.shiftedChar = translation.row4Shift[i];
key.character = layout.row4Keys[i];
key.shiftedChar = layout.row4Shift[i];
key.shifted = false;
key.Init (obj.transform.localPosition);

obj.name = "Key: " + translation.row4Keys[i];
obj.name = "Key: " + layout.row4Keys[i];
obj.SetActive (true);

keys[keyCount] = key;
Expand Down
43 changes: 0 additions & 43 deletions Assets/VRKeys/Scripts/Languages.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ namespace VRKeys {
/// Base class for keyboard layouts to inherit from in order to support
/// additional languages.
///
/// See the VRKeys/Scripts/Translations folder for example translations.
/// To add a translation, you will need to register it in the Languages.cs
/// See the VRKeys/Scripts/Layouts folder for example layouts.
/// To add a translation, you will need to register it in the Layouts.cs
/// class too.
/// </summary>
public class Translation {
public class Layout {

public string placeholderMessage = "Tap the keys to begin typing";

Expand Down
File renamed without changes.
47 changes: 47 additions & 0 deletions Assets/VRKeys/Scripts/LayoutList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* Copyright (c) 2017 The Campfire Union Inc - All Rights Reserved.
*
* Unauthorized copying of this file, via any medium, is strictly prohibited.
* This source code is proprietary and confidential.
*
* Email: [email protected]
* Website: https://www.campfireunion.com
*/

using UnityEngine;
using VRKeys.Layouts;

namespace VRKeys {
/// <summary>
/// List of supported layouts.
/// </summary>
public enum KeyboardLayout {
Qwerty,
French,
Dvorak
}

/// <summary>
/// Fetches layouts.
/// </summary>
public static class LayoutList {

/// <summary>
/// Get a new keyboard layout object.
/// </summary>
/// <param name="layout">KeyboardLayout.</param>
/// <returns>Layout object.</returns>
public static Layout GetLayout (KeyboardLayout layout) {
switch (layout) {
case KeyboardLayout.French:
return new French ();

case KeyboardLayout.Dvorak:
return new Dvorak ();

default:
return new Layout ();
}
}
}
}
File renamed without changes.
File renamed without changes.
35 changes: 35 additions & 0 deletions Assets/VRKeys/Scripts/Layouts/Dvorak.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright (c) 2017 The Campfire Union Inc - All Rights Reserved.
*
* Unauthorized copying of this file, via any medium, is strictly prohibited.
* This source code is proprietary and confidential.
*
* Email: [email protected]
* Website: https://www.campfireunion.com
*/

namespace VRKeys.Layouts {
/// <summary>
/// Dvorak language keyboard.
/// </summary>
public class Dvorak : Layout {

public Dvorak () {
row1Keys = new string[] { "`", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "[", "]" };

row1Shift = new string[] { "~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "{", "}" };

row2Keys = new string[] { "'", ",", ".", "p", "y", "f", "g", "c", "r", "l", "/", "=", "\\" };

row2Shift = new string[] { "\"", "<", ">", "P", "Y", "F", "G", "C", "R", "L", "?", "+", "|" };

row3Keys = new string[] { "a", "o", "e", "u", "i", "d", "h", "t", "n", "s", "-" };

row3Shift = new string[] { "A", "O", "E", "U", "I", "D", "H", "T", "N", "S", "_" };

row4Keys = new string[] { ";", "q", "j", "k", "x", "b", "m", "w", "v", "z" };

row4Shift = new string[] { ":", "Q", "J", "K", "X", "B", "M", "W", "V", "Z" };
}
}
}
12 changes: 12 additions & 0 deletions Assets/VRKeys/Scripts/Layouts/Dvorak.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c8df40d

Please sign in to comment.