Skip to content

Commit

Permalink
Add TextInputDialogGUI
Browse files Browse the repository at this point in the history
  • Loading branch information
vanjac committed Mar 30, 2018
1 parent d3caca7 commit 3315c90
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 12 deletions.
16 changes: 4 additions & 12 deletions Assets/Menu/MenuGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public class MenuGUI : GUIPanel
public TextAsset defaultMap;

private List<string> mapFiles = new List<string>();
private TouchScreenKeyboard nameKeyboard;

public override Rect GetRect(float width, float height)
{
Expand All @@ -30,18 +29,11 @@ void Start()

public override void WindowGUI()
{
if (nameKeyboard != null)
if (GUILayout.Button("New..."))
{
if (nameKeyboard.status == TouchScreenKeyboard.Status.Done)
NewMap(nameKeyboard.text);
if (nameKeyboard.status != TouchScreenKeyboard.Status.Visible)
nameKeyboard = null;
}
if (GUILayout.Button("New...") && nameKeyboard == null)
{
nameKeyboard = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.ASCIICapable,
false, false, false, false, // autocorrect, multiline, password, alert mode
"Enter new map name...");
TextInputDialogGUI inputDialog = gameObject.AddComponent<TextInputDialogGUI>();
inputDialog.prompt = "Enter new map name...";
inputDialog.handler = NewMap;
}
scroll = GUILayout.BeginScrollView(scroll);
foreach (string fileName in mapFiles)
Expand Down
47 changes: 47 additions & 0 deletions Assets/VoxelEditor/GUI/DialogGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,51 @@ public override void WindowGUI()
}
GUILayout.EndHorizontal();
}
}


public class TextInputDialogGUI : GUIPanel
{
public delegate void TextHandler(string text);

public TextHandler handler;
public string prompt;

private TouchScreenKeyboard keyboard;

public override Rect GetRect(float width, float height)
{
return new Rect(0, 0, 0, 0);
}

public override GUIStyle GetStyle()
{
return GUIStyle.none;
}

public override void OnEnable()
{
holdOpen = true;
base.OnEnable();
}

void Start()
{
keyboard = TouchScreenKeyboard.Open("", TouchScreenKeyboardType.ASCIICapable,
false, false, false, false, // autocorrect, multiline, password, alert mode
prompt);
}

public override void WindowGUI()
{
if (keyboard == null)
Destroy(this);
else if (keyboard.status == TouchScreenKeyboard.Status.Done)
{
handler(keyboard.text);
Destroy(this);
}
else if (keyboard.status != TouchScreenKeyboard.Status.Visible)
Destroy(this);
}
}

0 comments on commit 3315c90

Please sign in to comment.