Skip to content

Commit

Permalink
Added Lessons 1
Browse files Browse the repository at this point in the history
  • Loading branch information
synoise committed Oct 10, 2024
1 parent 813de25 commit 8f44bf6
Show file tree
Hide file tree
Showing 104 changed files with 19,174 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Assets/_UI_Lesson1/Scenes.meta

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

13 changes: 13 additions & 0 deletions Assets/_UI_Lesson1/Scenes/.idea/.gitignore

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

8 changes: 8 additions & 0 deletions Assets/_UI_Lesson1/Scenes/.idea/indexLayout.xml

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

135 changes: 135 additions & 0 deletions Assets/_UI_Lesson1/Scenes/AddNameScene .cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;


using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using Button = UnityEngine.UI.Button;
using TMPro;

// using UnityEngine;

// namespace Scenes.Scripts
// {
public class AddNameScene : MonoBehaviour
{
#region Components
public GameObject AprooveButton;
public GameObject MaleAvatar;
public GameObject FemaleAvatar;
// public TMP_InputField UserNameInput;
public GameObject UserNameInput;
public Toggle FemaleToggle;
public Toggle MaleToggle;

#endregion Components

private Regex regex = new Regex(@"^[a-zA-ZąćęłńóśźżĄĆĘŁŃÓŚŹŻ]{3,25}$");
private string message = "test message";
public string PlayerName="";
public string Gender;
public bool ClearPrefs;
public Text female;
public Text male;

// #region Init

void Start()
{



PlayerPrefs.DeleteAll(); // TODO remove it.

PrepareView();


}

//
//
// private void GetData()
// {
// PlayerName = LoadData(Prefs.PlayerName);
// Gender = LoadData(Prefs.Gender);
// }
//
private void PrepareView()
{
ActiveButton(false);

if (string.IsNullOrEmpty(Gender))
Gender = "female";

if (Gender == "female")
FemaleToggle.isOn = true;
else
MaleToggle.isOn = true;

ToogleGender(Gender);

// UserNameInput.text = PlayerName;
UserNameInput.GetComponent<TMP_InputField>().text = PlayerName;
Validation();
}



public void UserTextChanged()
{
PlayerName = UserNameInput.GetComponent<TMP_InputField>().text;
Debug.Log(UserNameInput);
Validation();
}

void Validation()
{
if (regex.IsMatch(PlayerName) && Gender != "")
ActiveButton(true);
else
ActiveButton(false);
}

void ActiveButton(bool state)
{
Debug.Log(state);
//AprooveButton.interactable = state;
AprooveButton.gameObject.SetActive(state);
}

public void ToogleGender(string sex)
{
SetAvatar(sex);
Gender = sex;

if (Gender != "male")
{
male.fontStyle = FontStyle.Normal;
female.fontStyle = FontStyle.Bold;
}else {
male.fontStyle = FontStyle.Bold;
female.fontStyle = FontStyle.Normal;
}
}

void SetAvatar(string sex)
{
MaleAvatar.SetActive(sex == "male");
FemaleAvatar.SetActive(sex == "female");
}

public void PlayGame()
{
// SaveData(Prefs.PlayerName, PlayerName);
// SaveData(Prefs.Gender, Gender);
// SaveData(Prefs.Progress, "0");
SceneManager.LoadScene("MainMenu");

// PlayerPrefs.SetInt("PlayerSetup", 1);
PlayerPrefs.Save();
}
}
// }
11 changes: 11 additions & 0 deletions Assets/_UI_Lesson1/Scenes/AddNameScene .cs.meta

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

Loading

0 comments on commit 8f44bf6

Please sign in to comment.