2025-01-02 10:44:51 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using BlueWater;
|
|
|
|
using BlueWater.Uis;
|
|
|
|
using PixelCrushers;
|
2024-12-26 20:14:15 +00:00
|
|
|
using UnityEngine;
|
2025-01-02 10:44:51 +00:00
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
using TMPro;
|
|
|
|
using UnityEngine.UI;
|
|
|
|
using UnityEngine.UIElements;
|
|
|
|
using Button = UnityEngine.UI.Button;
|
2024-12-26 20:14:15 +00:00
|
|
|
|
2025-01-02 10:44:51 +00:00
|
|
|
namespace BlueWater
|
2024-12-26 20:14:15 +00:00
|
|
|
{
|
2025-01-02 10:44:51 +00:00
|
|
|
public class RankUi : PausePopupUi
|
|
|
|
{
|
|
|
|
//현재 랭크에 스크롤이 위치하도록 하는 것
|
|
|
|
|
|
|
|
[SerializeField] private GameObject _panel;
|
|
|
|
|
|
|
|
[SerializeField] private GameObject rankRow;
|
|
|
|
|
|
|
|
[SerializeField] private FirebaseManager firebaseManager;
|
|
|
|
|
|
|
|
[SerializeField] private GameObject rankContents;
|
|
|
|
|
|
|
|
[SerializeField] private TextMeshProUGUI yourRank;
|
|
|
|
|
|
|
|
[SerializeField] private UIInputField nameTextField;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
public RectTransform content; // ScrollRect의 Content;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private Button _mainMenuButton;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private Button _restartButton;
|
|
|
|
|
|
|
|
private bool _rankOpen = false;
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
_panel.SetActive(false);
|
|
|
|
|
|
|
|
_mainMenuButton.onClick.AddListener(() => SceneController.Instance.LoadScene(SceneName.TycoonTile));
|
|
|
|
_restartButton.onClick.AddListener(SceneController.Instance.RestartCurrentScene);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Open()
|
|
|
|
{
|
|
|
|
_panel.SetActive(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Close()
|
|
|
|
{
|
|
|
|
_panel.SetActive(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
{
|
|
|
|
if (SceneController.Instance)
|
|
|
|
{
|
|
|
|
_mainMenuButton?.onClick.RemoveListener(() => SceneController.Instance.LoadScene(SceneName.TycoonTile));
|
|
|
|
_restartButton?.onClick.RemoveListener(SceneController.Instance.RestartCurrentScene);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Button("랭크저장+리더보드갱신")]
|
|
|
|
public void RunRank()
|
|
|
|
{
|
|
|
|
Open();
|
|
|
|
_rankOpen = false;
|
|
|
|
|
|
|
|
foreach (Transform child in rankContents.transform)
|
|
|
|
{
|
|
|
|
Destroy(child.gameObject); // 자식의 GameObject를 제거
|
|
|
|
}
|
|
|
|
|
|
|
|
firebaseManager.CreateRank(() =>
|
|
|
|
{
|
|
|
|
for (int i = 1 ; i < firebaseManager.UserDatas.Count ; i++) //Root제외 1부터 시작
|
|
|
|
{
|
|
|
|
var newObject = Instantiate(rankRow, rankContents.transform);
|
|
|
|
newObject.name = $"{i}";
|
|
|
|
newObject.GetComponent<RankRow>().SetValue(i.ToString() , firebaseManager.UserDatas[i].Name, firebaseManager.UserDatas[i].Round.ToString()
|
|
|
|
,firebaseManager.UserDatas[i].Gold.ToString()
|
|
|
|
,$"{firebaseManager.UserDatas[i].Time / 3600:D2}:{(firebaseManager.UserDatas[i].Time % 3600) / 60:D2}:{firebaseManager.UserDatas[i].Time % 60:D2}"
|
|
|
|
,firebaseManager.UserDatas[i].Tries.ToString());
|
|
|
|
|
|
|
|
if (firebaseManager.UserDatas[i] == firebaseManager.thisUser) yourRank.SetText(i.ToString());
|
|
|
|
}
|
|
|
|
|
|
|
|
_rankOpen = true;
|
|
|
|
|
|
|
|
StartCoroutine(CenterOnTarget());
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetName()
|
|
|
|
{
|
|
|
|
if (_rankOpen)
|
|
|
|
{
|
|
|
|
firebaseManager.WirteUserDataName(nameTextField.text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ValidateInput()
|
|
|
|
{
|
|
|
|
// 12글자 제한
|
|
|
|
if (nameTextField.text.Length > 14)
|
|
|
|
{
|
|
|
|
nameTextField.text = nameTextField.text.Substring(0, 12);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 영어 알파벳(a-z, A-Z)과 숫자(0-9)만 허용
|
|
|
|
string pattern = "^[a-zA-Z0-9]*$";
|
|
|
|
if (!Regex.IsMatch(nameTextField.text, pattern))
|
|
|
|
{
|
|
|
|
// 조건에 맞지 않는 문자 제거
|
|
|
|
nameTextField.text = Regex.Replace(nameTextField.text, "[^a-zA-Z0-9]", "");
|
|
|
|
}
|
|
|
|
|
|
|
|
rankContents.transform.Find(yourRank.text).GetComponent<RankRow>().SetValueName(nameTextField.text);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private IEnumerator CenterOnTarget()
|
|
|
|
{
|
|
|
|
float timer = 0f;
|
|
|
|
while (timer < 0.5f)
|
|
|
|
{
|
|
|
|
timer += Time.unscaledDeltaTime;
|
|
|
|
yield return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var rankrow = rankContents.transform.Find(yourRank.text).GetComponent<RankRow>();
|
|
|
|
var target = rankrow.transform;
|
|
|
|
//Debug.Log(target.position.y);
|
|
|
|
|
|
|
|
rankrow.StartAlpha();
|
|
|
|
|
|
|
|
content.offsetMin = new Vector2(0, content.offsetMin.y); // Left
|
|
|
|
content.offsetMax = new Vector2(0, content.offsetMax.y); // Right
|
|
|
|
|
|
|
|
Vector2 anchoredPosition = content.anchoredPosition;
|
|
|
|
anchoredPosition.y = Math.Abs(target.localPosition.y + 320); // 원하는 Y 값 (대강 보여지는 부분에서 350만큼 제거)
|
|
|
|
//anchoredPosition.y = 6000; // 원하는 Y 값
|
|
|
|
|
|
|
|
content.anchoredPosition = anchoredPosition;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|