Skip to content

Commit

Permalink
Update UiInputBox 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
veblush committed Jul 13, 2016
1 parent 1f3640f commit 6404798
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/TalkClient.Unity3D/Assets/Scene/ChatScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -3518,7 +3518,7 @@ RectTransform:
m_RootOrder: 0
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0.0000038146973}
m_AnchoredPosition: {x: 0, y: 0.0000076293945}
m_SizeDelta: {x: -10, y: 0}
m_Pivot: {x: 0.5, y: 0}
--- !u!114 &1018795984
Expand Down
6 changes: 3 additions & 3 deletions src/TalkClient.Unity3D/Assets/Scripts/ChatScene/ChatScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private IEnumerator ProcessSelectRoomAndEnter()

if (t1.Exception != null)
{
UiMessageBox.ShowMessageBox("GetRoomList error:\n" + t1.Exception.Message);
UiMessageBox.Show("GetRoomList error:\n" + t1.Exception.Message);
yield break;
}

Expand Down Expand Up @@ -173,7 +173,7 @@ private IEnumerator ProcessEnterRoom(UserRef user, string roomName)
{
G.Communicator.ObserverRegistry.Remove(observer);
DestroyObject(go);
UiMessageBox.ShowMessageBox("Enter room error:\n" + t1.Exception);
UiMessageBox.Show("Enter room error:\n" + t1.Exception);
yield break;
}

Expand Down Expand Up @@ -244,7 +244,7 @@ private IEnumerator ProcessExitFromRoom(UserRef user, string roomName)
yield return t1.WaitHandle;
if (t1.Status != TaskStatus.RanToCompletion)
{
UiMessageBox.ShowMessageBox("Exit room error:\n" + t1.Exception.ToString());
UiMessageBox.Show("Exit room error:\n" + t1.Exception.ToString());
yield break;
}

Expand Down
10 changes: 5 additions & 5 deletions src/TalkClient.Unity3D/Assets/Scripts/ChatScene/LoginDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private IEnumerator ProcessLogin(string server, ChannelType type, string id, str
}
catch (Exception e)
{
UiMessageBox.ShowMessageBox("Server address error:\n" + e.ToString());
UiMessageBox.Show("Server address error:\n" + e.ToString());
yield break;
}

Expand All @@ -88,7 +88,7 @@ private IEnumerator ProcessLogin(string server, ChannelType type, string id, str
yield return t0.WaitHandle;
if (t0.Exception != null)
{
UiMessageBox.ShowMessageBox("Connect error:\n" + t0.Exception.Message);
UiMessageBox.Show("Connect error:\n" + t0.Exception.Message);
yield break;
}

Expand All @@ -103,9 +103,9 @@ private IEnumerator ProcessLogin(string server, ChannelType type, string id, str
communicator.ObserverRegistry.Remove(observer);
var re = t1.Exception as ResultException;
if (re != null)
UiMessageBox.ShowMessageBox("Login error:\n" + re.ResultCode.ToString());
UiMessageBox.Show("Login error:\n" + re.ResultCode.ToString());
else
UiMessageBox.ShowMessageBox("Login error:\n" + t1.Exception.ToString());
UiMessageBox.Show("Login error:\n" + t1.Exception.ToString());
channel.Close();
yield break;
}
Expand All @@ -117,7 +117,7 @@ private IEnumerator ProcessLogin(string server, ChannelType type, string id, str
yield return t2.WaitHandle;
if (t2.Exception != null)
{
UiMessageBox.ShowMessageBox("ConnectToUser error:\n" + t2.Exception.ToString());
UiMessageBox.Show("ConnectToUser error:\n" + t2.Exception.ToString());
channel.Close();
yield break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Id": "UiManager",
"Version": "1.0.0",
"Version": "1.1.0",
"Authors": [
"Esun Kim"
],
Expand All @@ -23,6 +23,7 @@
"Assets/UnityPackages/UiManager/UiDialog.cs",
"Assets/UnityPackages/UiManager/UiDialogHandle.cs",
"Assets/UnityPackages/UiManager/UiHelper.cs",
"Assets/UnityPackages/UiManager/UiInputBox.cs",
"Assets/UnityPackages/UiManager/UiManager.cs",
"Assets/UnityPackages/UiManager/UiMessageBox.cs",
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using UnityEngine;
using UnityEngine.UI;

public class UiInputBox : UiDialog
{
public delegate void InputResultDelegate(string input);

public enum ButtonType
{
Ok,
OkCancel,
}

public Text MessageText;
public InputField ValueInput;
public Button[] Buttons;

public static UiDialogHandle Show(
string msg, string value = null, ButtonType buttonType = ButtonType.Ok,
InputResultDelegate callback = null, string customOkName = null)
{
UiDialogHandle handle;
{
var builtin = UiManager.Instance.FindFromDialogRoot("InputBox");
if (builtin != null)
{
handle = UiManager.Instance.ShowModalTemplate(builtin.gameObject);
}
else
{
var msgBoxPrefab = Resources.Load("InputBox") as GameObject;
handle = UiManager.Instance.ShowModalPrefab(msgBoxPrefab);
}
}

if (callback != null)
handle.Hidden += (dlg, returnValue) => callback((string)returnValue);

var msgBox = (UiInputBox)handle.Dialog;
msgBox.MessageText.text = msg;
msgBox.ValueInput.text = value ?? "";

var b0 = msgBox.Buttons[0];
var b0Text = b0.transform.Find("Text").GetComponent<Text>();
var b1 = msgBox.Buttons[1];
var b1Text = b1.transform.Find("Text").GetComponent<Text>();

b1.gameObject.SetActive(buttonType != ButtonType.Ok);

switch (buttonType)
{
case ButtonType.Ok:
b0Text.text = customOkName ?? "Ok";
b0.onClick.AddListener(() => msgBox.OnButtonClick(true));
break;

case ButtonType.OkCancel:
b0Text.text = customOkName ?? "Ok";
b0.onClick.AddListener(() => msgBox.OnButtonClick(true));
b1Text.text = "Cancel";
b1.onClick.AddListener(() => msgBox.OnButtonClick(false));
break;
}

return handle;
}

private void OnButtonClick(bool ok)
{
Hide(ok ? ValueInput.text : null);
}

public void OnInputSubmit()
{
OnButtonClick(true);
}
}

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

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public enum QuestionResult
public Text MessageText;
public Button[] Buttons;

public static UiDialogHandle ShowMessageBox(string msg, QuestionResultDelegate callback = null)
public static UiDialogHandle Show(string msg, QuestionResultDelegate callback = null)
{
UiDialogHandle handle;
{
Expand Down Expand Up @@ -60,7 +60,7 @@ private void OnMessageBoxOkButtonClick()
Hide(QuestionResult.Ok);
}

public static UiDialogHandle ShowQuestionBox(
public static UiDialogHandle Show(
string msg, QuestionType questionType,
QuestionResultDelegate callback = null, string customOkName = null)
{
Expand Down Expand Up @@ -89,15 +89,18 @@ public static UiDialogHandle ShowQuestionBox(
var b1 = msgBox.Buttons[1];
var b1Text = b1.transform.Find("Text").GetComponent<Text>();

b1.gameObject.SetActive(questionType != QuestionType.Ok);

switch (questionType)
{
case QuestionType.Ok:
b0Text.text = customOkName ?? "Ok";
b0.onClick.AddListener(() => msgBox.OnQuestionBoxButtonClick(QuestionResult.Ok));
b1.gameObject.SetActive(false);
break;

case QuestionType.OkCancel:
b0Text.text = "Ok";
b0Text.text = customOkName ?? "Ok";
b0.onClick.AddListener(() => msgBox.OnQuestionBoxButtonClick(QuestionResult.Ok));
b1Text.text = "Cancel";
b1.onClick.AddListener(() => msgBox.OnQuestionBoxButtonClick(QuestionResult.Cancel));
Expand Down

0 comments on commit 6404798

Please sign in to comment.