private REcanvas SingnInView() { string usernameText = ""; string passwordText = ""; User currentUser = null; string error = "Write your credentials"; bool rememberme = false; // Hooks var viweState = new UseState <int>(0); var errorTrigger = new UseTrigger(); return(new REcanvas { childs = () => { // Profile if (viweState.value == 1) { return new REbase[] { new REpanelVertical { propsRectTransform = () => REpanelVertical.TableRectTransform(20, 80, 20, 80), propsVerticalLayoutGroup = () => new REpanelVertical.VerticalLayoutGroupSetter { childAlignment = TextAnchor.MiddleCenter, }, childs = () => new REbase[] { new REtext { propsText = () => new REtext.TextSetter { text = "Welcome " + currentUser.username, } }, new REtext { propsText = () => new REtext.TextSetter { text = "Username: "******"Password: "******"Logout" }, propsButton = () => new REbutton.ButtonSetter { OnClickListener = (s) => { currentUser = null; error = "Write your credentials"; if (!rememberme) { usernameText = ""; passwordText = ""; } errorTrigger.Trigger(); viweState.SetState(0); } } }, new REtext { propsText = () => new REtext.TextSetter { text = error, }, useTrigger = new UseTrigger.Hook[] { new UseTrigger.Hook { hook = errorTrigger, OnTrigger = (s) => { REtext.CastSelector(s).textCmp.text = error; } } } }, new REbox { propsRectTransform = () => new REbox.RectTransformSetter { height = 400, width = 800, }, childs = () => new REbase[] { new REpanelVertical { childs = () => User.Find().Select(u => new REtext { propsText = () => new REtext.TextSetter { text = u.username, } } ), } } } } }, }; } // Sign Up Component else if (viweState.value == 3) { string newUsername = ""; string newPassword = ""; return new REbase[] { new REpanelVertical { propsRectTransform = () => REpanelVertical.TableRectTransform(20, 80, 20, 80), propsVerticalLayoutGroup = () => new REpanelVertical.VerticalLayoutGroupSetter { childAlignment = TextAnchor.MiddleCenter, }, childs = () => new REbase[] { new REtext { propsText = () => new REtext.TextSetter { text = "Sign Up" } }, new REtext { propsText = () => new REtext.TextSetter { text = "Username" } }, new REinputField { propsInputField = () => new REinputField.InputFieldSetter { text = newUsername, OnValueChangedListener = (v, s) => { newUsername = v; } } }, new REtext { propsText = () => new REtext.TextSetter { text = "Password" } }, new REinputField { propsInputField = () => new REinputField.InputFieldSetter { text = newPassword, OnValueChangedListener = (v, s) => { newPassword = v; } } }, new REbutton { propsText = () => new REbutton.TextSetter { text = "Create" }, propsButton = () => new REbutton.ButtonSetter { OnClickListener = (s) => { var newUser = new User { username = newUsername, password = newPassword, }.Save(); if (newUser) { error = "Succesfull Created"; newUsername = ""; newPassword = ""; errorTrigger.Trigger(); viweState.SetState(0); } else { error = "Cant create a user"; errorTrigger.Trigger(); } } } }, new REtext { propsText = () => new REtext.TextSetter { text = error, }, useTrigger = new UseTrigger.Hook[] { new UseTrigger.Hook { hook = errorTrigger, OnTrigger = (s) => { REtext.CastSelector(s).textCmp.text = error; } } } }, new REbutton { propsText = () => new REbutton.TextSetter { text = "Sign In" }, propsButton = () => new REbutton.ButtonSetter { OnClickListener = (s) => { error = "Write your credentials"; errorTrigger.Trigger(); viweState.SetState(0); } } }, } }, }; } // Sign In Component else { return new REbase[] { new REpanelVertical { propsRectTransform = () => REpanelVertical.TableRectTransform(20, 80, 20, 80), propsVerticalLayoutGroup = () => new REpanelVertical.VerticalLayoutGroupSetter { childAlignment = TextAnchor.MiddleCenter, }, childs = () => new REbase[] { new REtext { propsText = () => new REtext.TextSetter { text = "Sign In" } }, new REtext { propsText = () => new REtext.TextSetter { text = "Username" } }, new REinputField { propsInputField = () => new REinputField.InputFieldSetter { text = usernameText, OnValueChangedListener = (v, s) => { usernameText = v; } } }, new REtext { propsText = () => new REtext.TextSetter { text = "Password" } }, new REinputField { propsInputField = () => new REinputField.InputFieldSetter { text = passwordText, OnValueChangedListener = (v, s) => { passwordText = v; } } }, new REtoggle { propsText = () => new REtoggle.TextSetter { text = "Remember me" }, propsToggle = () => new REtoggle.ToggleSetter { isOn = rememberme, OnValueChangedListener = (v, s) => rememberme = v, } }, new REbutton { propsText = () => new REbutton.TextSetter { text = "Login" }, propsButton = () => new REbutton.ButtonSetter { OnClickListener = (s) => { var findUser = User.Find(usernameText, passwordText); currentUser = findUser; if (findUser != null) { Debug.Log("Username: "******" Password: "******"Succesfull sign In"; errorTrigger.Trigger(); viweState.SetState(1); } else { error = "Invalid credentials, try again"; errorTrigger.Trigger(); } } } }, new REtext { propsText = () => new REtext.TextSetter { text = error, }, useTrigger = new UseTrigger.Hook[] { new UseTrigger.Hook { hook = errorTrigger, OnTrigger = (s) => { REtext.CastSelector(s).textCmp.text = error; } } } }, new REbutton { propsText = () => new REbutton.TextSetter { text = "Sign Up" }, propsButton = () => new REbutton.ButtonSetter { OnClickListener = (s) => { error = "Create your credentials"; errorTrigger.Trigger(); viweState.SetState(3); } } }, } }, }; } }, useState = new IuseState[] { viweState, } }); }
private REcanvas ConsoleView() { var addChildToConsole = new UseAddChilds(); var textAddedTrigger = new UseTrigger(); var deleteAllTrigger = new UseTrigger(); var copyTextTrigger = new UseTrigger(); string inputText = ""; REbase TextChild(string text) { string displayText = text; var editMode = new UseState <bool>(false); return(new REbox { propsRectTransform = () => new REbox.RectTransformSetter { height = 200, width = 800, }, childs = () => new REbase[] { new REpanelHorizontal { childs = () => { return new REbase[] { new REbox { propsRectTransform = () => new REbox.RectTransformSetter { width = 400, height = 200, }, useState = new IuseState[] { editMode, }, childs = () => { if (editMode.value) { return new REbase[] { new REinputField { propsInputField = () => new REinputField.InputFieldSetter { text = displayText, OnValueChangedListener = (v, s) => { displayText = v; } }, }, }; } else { return new REbase[] { new RElabel { propsText = () => new RElabel.TextSetter { text = displayText, }, }, }; } } }, new REbutton { propsText = () => { if (editMode.value) { return new REbutton.TextSetter { text = "Save" } } ; else { return new REbutton.TextSetter { text = "Edit" } }; }, propsButton = () => new REbutton.ButtonSetter { OnClickListener = (s) => { editMode.SetState(!editMode.value); } }, useState = new IuseState[] { editMode, }, }, new REbutton { propsText = () => new REbutton.TextSetter { text = "Copy", }, propsButton = () => new REbutton.ButtonSetter { OnClickListener = (s) => { inputText = displayText; copyTextTrigger.Trigger(); } }, }, new REbutton { propsText = () => new REbutton.TextSetter { text = "Delete", }, propsButton = () => new REbutton.ButtonSetter { OnClickListener = (s) => { Debug.Log(s.parent.parent.elementId.elementType + " r " + s.parent.parent.parent.childs.Length); s.parent.parent.Erase(); } }, }, }; } }, } });
private REcanvas SingnInView() { string usernameText = ""; string passwordText = ""; User currentUser = null; string message = "Write your credentials"; bool rememberme = false; // Hooks var viweState = new UseState <int>(0); var errorTrigger = new UseTrigger(); var usersList = new UseState <User[]>(new User[0]); var userslistRequest = false; return(new REcanvas { childs = () => { // Profile if (viweState.value == 1) { return new REbase[] { new REpanelVertical { propsRectTransform = () => REpanelVertical.TableRectTransform(20, 80, 20, 80), propsVerticalLayoutGroup = () => new REpanelVertical.VerticalLayoutGroupSetter { childAlignment = TextAnchor.MiddleCenter, }, childs = () => new REbase[] { new REtext { propsText = () => new REtext.TextSetter { text = "Welcome " + currentUser.username, } }, new REtext { propsText = () => new REtext.TextSetter { text = "Username: "******"Password: "******"Logout" }, propsButton = () => new REbutton.ButtonSetter { OnClickListener = (s) => { currentUser = null; message = "Write your credentials"; if (!rememberme) { usernameText = ""; passwordText = ""; } errorTrigger.Trigger(); viweState.SetState(0); } } }, new REtext { propsText = () => new REtext.TextSetter { text = message, }, useTrigger = new UseTrigger.Hook[] { new UseTrigger.Hook { hook = errorTrigger, OnTrigger = (s) => { REtext.CastSelector(s).textCmp.text = message; } } } }, new REbox { propsRectTransform = () => new REbox.RectTransformSetter { height = 400, width = 800, }, childs = () => new REbase[] { new REpanelVertical { childs = () => usersList.value.Select(u => new REtext { propsText = () => new REtext.TextSetter { text = u.username, } }), } }, useState = new IuseState[] { usersList, }, useObjectEvents = new REbox.UseObjectEvents.Hook { onAwake = async(s) => { if (userslistRequest) { return; } Debug.Log("Requesting List ..."); try { var users = await User.Find(); userslistRequest = true; usersList.SetState(users); } catch (System.Exception) { } } }, } } , useObjectEvents = new REpanelVertical.UseObjectEvents.Hook { onDestroy = (s) => { userslistRequest = false; } }, }, }; } // Sign Up Component else if (viweState.value == 3) { string newUsername = ""; string newPassword = ""; return new REbase[] { new REpanelVertical { propsRectTransform = () => REpanelVertical.TableRectTransform(20, 80, 20, 80), propsVerticalLayoutGroup = () => new REpanelVertical.VerticalLayoutGroupSetter { childAlignment = TextAnchor.MiddleCenter, }, childs = () => new REbase[] { new REtext { propsText = () => new REtext.TextSetter { text = "Sign Up" } }, new REtext { propsText = () => new REtext.TextSetter { text = "Username" } }, new REinputField { propsInputField = () => new REinputField.InputFieldSetter { text = newUsername, OnValueChangedListener = (v, s) => { newUsername = v; } } }, new REtext { propsText = () => new REtext.TextSetter { text = "Password" } }, new REinputField { propsInputField = () => new REinputField.InputFieldSetter { text = newPassword, OnValueChangedListener = (v, s) => { newPassword = v; } } }, new REbutton { propsText = () => new REbutton.TextSetter { text = "Create" }, propsButton = () => new REbutton.ButtonSetter { OnClickListener = async(s) => { try { var newUser = await new User { username = newUsername, password = newPassword, }.Save(); if (newUser) { message = "Succesfull Created"; newUsername = ""; newPassword = ""; errorTrigger.Trigger(); viweState.SetState(0); } else { message = "Cant create a user"; errorTrigger.Trigger(); } } catch (System.Exception e) { message = e + ""; errorTrigger.Trigger(); } } } }, new REtext { propsText = () => new REtext.TextSetter { text = message, }, useTrigger = new UseTrigger.Hook[] { new UseTrigger.Hook { hook = errorTrigger, OnTrigger = (s) => { REtext.CastSelector(s).textCmp.text = message; } } } }, new REbutton { propsText = () => new REbutton.TextSetter { text = "Sign In" }, propsButton = () => new REbutton.ButtonSetter { OnClickListener = (s) => { message = "Write your credentials"; errorTrigger.Trigger(); viweState.SetState(0); } } }, } }, }; } // Sign In Component else { return new REbase[] { // Get request new REpanelVertical { propsRectTransform = () => REpanelVertical.TableRectTransform(20, 80, 20, 80), propsVerticalLayoutGroup = () => new REpanelVertical.VerticalLayoutGroupSetter { childAlignment = TextAnchor.MiddleCenter, }, childs = () => new REbase[] { new REtext { propsText = () => new REtext.TextSetter { text = "Sign In" } }, new REtext { propsText = () => new REtext.TextSetter { text = "Username" } }, new REinputField { propsInputField = () => new REinputField.InputFieldSetter { text = usernameText, OnValueChangedListener = (v, s) => { usernameText = v; } } }, new REtext { propsText = () => new REtext.TextSetter { text = "Password" } }, new REinputField { propsInputField = () => new REinputField.InputFieldSetter { text = passwordText, OnValueChangedListener = (v, s) => { passwordText = v; } } }, new REtoggle { propsText = () => new REtoggle.TextSetter { text = "Remember me" }, propsToggle = () => new REtoggle.ToggleSetter { isOn = rememberme, OnValueChangedListener = (v, s) => rememberme = v, } }, new REbutton { propsText = () => new REbutton.TextSetter { text = "Login" }, propsButton = () => new REbutton.ButtonSetter { OnClickListener = async(s) => { try { var findUser = await User.Find(usernameText, passwordText); currentUser = findUser; } catch (System.Exception e) { message = e + ""; currentUser = null; errorTrigger.Trigger(); return; } if (currentUser != null) { Debug.Log("Username: "******" Password: "******"Succesfull sign In"; errorTrigger.Trigger(); viweState.SetState(1); } else { message = "Bad credentials"; errorTrigger.Trigger(); } } } }, new REtext { propsText = () => new REtext.TextSetter { text = message, }, useTrigger = new UseTrigger.Hook[] { new UseTrigger.Hook { hook = errorTrigger, OnTrigger = (s) => { REtext.CastSelector(s).textCmp.text = message; } } } }, new REbutton { propsText = () => new REbutton.TextSetter { text = "Sign Up" }, propsButton = () => new REbutton.ButtonSetter { OnClickListener = (s) => { message = "Create your credentials"; errorTrigger.Trigger(); viweState.SetState(3); } } }, } }, }; } }, useState = new IuseState[] { viweState, } }); }