319 lines
11 KiB
C#
319 lines
11 KiB
C#
|
|
using System;
|
||
|
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using TMPro;
|
||
|
|
using UnityEngine;
|
||
|
|
using UnityEngine.UI;
|
||
|
|
|
||
|
|
public class SettingPopup : PopupBase
|
||
|
|
{
|
||
|
|
[Header("Music")]
|
||
|
|
[SerializeField] private Sprite MusicOnSprite;
|
||
|
|
[SerializeField] private Sprite MusicOffSprite;
|
||
|
|
[SerializeField] private Image MusicIcon;
|
||
|
|
[SerializeField] private Image MusicToggleHandle;
|
||
|
|
[SerializeField] private Image MusicToggleFill;
|
||
|
|
[Header("SFX")]
|
||
|
|
[SerializeField] private Sprite SFXOnSprite;
|
||
|
|
[SerializeField] private Sprite SFXOffSprite;
|
||
|
|
[SerializeField] private Image SFXIcon;
|
||
|
|
[SerializeField] private Image SFXToggleHandle;
|
||
|
|
[SerializeField] private Image SFXToggleFill;
|
||
|
|
[Header("Game Speed")]
|
||
|
|
[SerializeField] private RectTransform SpeedSlideBackRT;
|
||
|
|
[SerializeField] private Image[] SpeedDotImages;
|
||
|
|
[SerializeField] private RectTransform SpeedSlideHandle;
|
||
|
|
[Header("Game Speed")]
|
||
|
|
[SerializeField] private Image[] UploadButton;
|
||
|
|
[SerializeField] private RectTransform DownloadButton;
|
||
|
|
[Header("Account")]
|
||
|
|
[SerializeField] private TextMeshProUGUI AccountStateText;
|
||
|
|
[SerializeField] private GameObject SignoutButton;
|
||
|
|
|
||
|
|
private IEnumerator _eSlide;
|
||
|
|
private RenderMode _rootCanvasRenderMode;
|
||
|
|
private float _slideValue = 0f;
|
||
|
|
float _interval = 1f;
|
||
|
|
int _prevSlideImagesEnablenumber = 0;
|
||
|
|
|
||
|
|
protected override void Awake()
|
||
|
|
{
|
||
|
|
base.Awake();
|
||
|
|
|
||
|
|
GameManager.Account.OnAccountSignIn.AddListener(OnAccountSignIn);
|
||
|
|
GameManager.Account.OnAccountSignOut.AddListener(OnAccountSignOut);
|
||
|
|
GameManager.Account.OnUploadSaveData.AddListener(OnUploadSaveData);
|
||
|
|
GameManager.Account.OnDownloadSaveData.AddListener(OnDownloadSaveData);
|
||
|
|
GameManager.Account.OnOverWriteSaveData.AddListener(OnOverWriteSaveData);
|
||
|
|
|
||
|
|
SignoutButton.gameObject.SetActive(GameManager.Account.IsUserLogin);
|
||
|
|
}
|
||
|
|
|
||
|
|
public override void ShowPopup(int drawOrder)
|
||
|
|
{
|
||
|
|
base.ShowPopup(drawOrder);
|
||
|
|
this.UpdateMusicUI();
|
||
|
|
this.UpdateSFXUI();
|
||
|
|
|
||
|
|
_rootCanvasRenderMode = this.transform.root.GetComponent<Canvas>().renderMode;
|
||
|
|
|
||
|
|
//GamePanel.GameSpeed = 0f;
|
||
|
|
_slideValue = GameManager.DB.GameSpeed;
|
||
|
|
|
||
|
|
// Set Slide Images
|
||
|
|
_interval = 1f / SpeedDotImages.Length;
|
||
|
|
SpeedSlideHandle.anchoredPosition = Vector2.right * _slideValue * SpeedSlideBackRT.rect.width;
|
||
|
|
|
||
|
|
int num = (int)(_slideValue / _interval);
|
||
|
|
|
||
|
|
for (int i = 0; i < SpeedDotImages.Length; i++)
|
||
|
|
SpeedDotImages[i].color = i < num ? Color.yellow : Color.white;
|
||
|
|
_prevSlideImagesEnablenumber = num;
|
||
|
|
}
|
||
|
|
|
||
|
|
public override void HidePopup()
|
||
|
|
{
|
||
|
|
GameManager.Account.OnAccountSignIn.RemoveListener(OnAccountSignIn);
|
||
|
|
GameManager.Account.OnAccountSignOut.RemoveListener(OnAccountSignOut);
|
||
|
|
GameManager.Account.OnUploadSaveData.RemoveListener(OnUploadSaveData);
|
||
|
|
GameManager.Account.OnDownloadSaveData.RemoveListener(OnDownloadSaveData);
|
||
|
|
GameManager.Account.OnOverWriteSaveData.RemoveListener(OnOverWriteSaveData);
|
||
|
|
|
||
|
|
base.HidePopup();
|
||
|
|
|
||
|
|
if (_eSlide != null)
|
||
|
|
StopCoroutine(_eSlide);
|
||
|
|
|
||
|
|
GamePanel.GameSpeed = (1.8f * _slideValue) + 0.2f;
|
||
|
|
GameManager.DB.GameSpeed = _slideValue;
|
||
|
|
GameManager.DB.SaveDatas();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void ClickCloseButton()
|
||
|
|
{
|
||
|
|
if (GameManager.UI.IsOpendPopup(EPopupType.SettingPopup))
|
||
|
|
GameManager.UI.HideTopPopup();
|
||
|
|
GameManager.Sound.PlaySFX(ESFXType.Button_Hit);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void ClickMusicToggle()
|
||
|
|
{
|
||
|
|
GameManager.DB.BGMMute = !GameManager.DB.BGMMute;
|
||
|
|
GameManager.Sound.BGMMute(GameManager.DB.BGMMute);
|
||
|
|
this.UpdateMusicUI();
|
||
|
|
GameManager.DB.SaveDatas();
|
||
|
|
GameManager.Sound.PlaySFX(ESFXType.Button_Hit);
|
||
|
|
}
|
||
|
|
|
||
|
|
private void UpdateMusicUI()
|
||
|
|
{
|
||
|
|
if (GameManager.DB.BGMMute)
|
||
|
|
{
|
||
|
|
MusicToggleHandle.rectTransform.anchorMin = MusicToggleHandle.rectTransform.anchorMax = new Vector2(0, 0.5f);
|
||
|
|
MusicToggleHandle.rectTransform.anchoredPosition = Vector2.zero;
|
||
|
|
MusicToggleFill.enabled = false;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
MusicToggleHandle.rectTransform.anchorMin = MusicToggleHandle.rectTransform.anchorMax = new Vector2(1, 0.5f);
|
||
|
|
MusicToggleHandle.rectTransform.anchoredPosition = Vector2.zero;
|
||
|
|
MusicToggleFill.enabled = true;
|
||
|
|
}
|
||
|
|
|
||
|
|
MusicIcon.sprite = GameManager.DB.BGMMute ? MusicOffSprite : MusicOnSprite;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void ClickSFXToggle()
|
||
|
|
{
|
||
|
|
GameManager.DB.SFXMute = !GameManager.DB.SFXMute;
|
||
|
|
GameManager.Sound.SFXMute(GameManager.DB.SFXMute);
|
||
|
|
this.UpdateSFXUI();
|
||
|
|
GameManager.DB.SaveDatas();
|
||
|
|
GameManager.Sound.PlaySFX(ESFXType.Button_Hit);
|
||
|
|
}
|
||
|
|
|
||
|
|
private void UpdateSFXUI()
|
||
|
|
{
|
||
|
|
if (GameManager.DB.SFXMute)
|
||
|
|
{
|
||
|
|
SFXToggleHandle.rectTransform.anchorMin = SFXToggleHandle.rectTransform.anchorMax = new Vector2(0, 0.5f);
|
||
|
|
SFXToggleHandle.rectTransform.anchoredPosition = Vector2.zero;
|
||
|
|
SFXToggleFill.enabled = false;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
SFXToggleHandle.rectTransform.anchorMin = SFXToggleHandle.rectTransform.anchorMax = new Vector2(1, 0.5f);
|
||
|
|
SFXToggleHandle.rectTransform.anchoredPosition = Vector2.zero;
|
||
|
|
SFXToggleFill.enabled = true;
|
||
|
|
}
|
||
|
|
|
||
|
|
SFXIcon.sprite = GameManager.DB.SFXMute ? SFXOffSprite : SFXOnSprite;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void PointerDownSlide()
|
||
|
|
{
|
||
|
|
if (_eSlide != null)
|
||
|
|
StopCoroutine(_eSlide);
|
||
|
|
_eSlide = this.coroSlide();
|
||
|
|
StartCoroutine(_eSlide);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void PointerUpSlide()
|
||
|
|
{
|
||
|
|
if (_eSlide != null)
|
||
|
|
StopCoroutine(_eSlide);
|
||
|
|
}
|
||
|
|
|
||
|
|
private IEnumerator coroSlide()
|
||
|
|
{
|
||
|
|
while (true)
|
||
|
|
{
|
||
|
|
#if UNITY_EDITOR
|
||
|
|
if (Input.GetMouseButton(0))
|
||
|
|
#endif
|
||
|
|
#if !UNITY_EDITOR && UNITY_ANDROID
|
||
|
|
if(Input.touchCount > 0)
|
||
|
|
#endif
|
||
|
|
{
|
||
|
|
Vector2 localPoint;
|
||
|
|
#if UNITY_EDITOR
|
||
|
|
|
||
|
|
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(SpeedSlideBackRT, Input.mousePosition, _rootCanvasRenderMode == RenderMode.ScreenSpaceOverlay ? null :
|
||
|
|
Camera.main, out localPoint))
|
||
|
|
#endif
|
||
|
|
#if !UNITY_EDITOR && UNITY_ANDROID
|
||
|
|
if(RectTransformUtility.ScreenPointToLocalPointInRectangle(SpeedSlideBackRT, Input.GetTouch(0).position, _rootCanvasRenderMode == RenderMode.ScreenSpaceOverlay ? null :
|
||
|
|
Camera.main, out localPoint))
|
||
|
|
#endif
|
||
|
|
{
|
||
|
|
localPoint.x += SpeedSlideBackRT.sizeDelta.x * 0.5f;
|
||
|
|
localPoint.x = Mathf.Clamp(localPoint.x, 0, SpeedSlideBackRT.sizeDelta.x);
|
||
|
|
localPoint.y = 0;
|
||
|
|
SpeedSlideHandle.anchoredPosition = localPoint;
|
||
|
|
|
||
|
|
// Update Images
|
||
|
|
float normalizedValue = localPoint.x / SpeedSlideBackRT.sizeDelta.x;
|
||
|
|
_slideValue = normalizedValue;
|
||
|
|
int num = (int)(normalizedValue / _interval);
|
||
|
|
|
||
|
|
if (num != _prevSlideImagesEnablenumber)
|
||
|
|
{
|
||
|
|
for (int i = 0; i < SpeedDotImages.Length; i++)
|
||
|
|
{
|
||
|
|
SpeedDotImages[i].color = i < num ? Color.yellow : Color.white;
|
||
|
|
}
|
||
|
|
_prevSlideImagesEnablenumber = num;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
yield return null;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private void OnAccountSignIn(bool isSuccessed)
|
||
|
|
{
|
||
|
|
SignoutButton.gameObject.SetActive(isSuccessed);
|
||
|
|
if (isSuccessed == true)
|
||
|
|
{
|
||
|
|
AccountStateText.text = "로그인에 성공하였습니다.";
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
AccountStateText.text = "로그인에 실패하였습니다. 인터넷을 확인해 주시기를 바랍니다.";
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
private void OnAccountSignOut(bool isSuccessed)
|
||
|
|
{
|
||
|
|
SignoutButton.gameObject.SetActive(!isSuccessed);
|
||
|
|
if (isSuccessed == true)
|
||
|
|
{
|
||
|
|
AccountStateText.text = "로그아웃에 성공하였습니다.";
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
AccountStateText.text = "로그아웃에 실패하였습니다.";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private void OnUploadSaveData(bool isSuccessed)
|
||
|
|
{
|
||
|
|
if (isSuccessed == true)
|
||
|
|
{
|
||
|
|
AccountStateText.text = "서버에 저장파일 업로드를 성공하였습니다.";
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
AccountStateText.text = "업로드에 실패하였습니다. 인터넷을 확인해 주시기 바랍니다.";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private void OnDownloadSaveData(bool isSuccessed)
|
||
|
|
{
|
||
|
|
if (isSuccessed == true)
|
||
|
|
{
|
||
|
|
AccountStateText.text = "서버에 있는 저장파일 다운로드를 성공하였습니다.";
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
AccountStateText.text = "다운로드에 실패하였습니다. 인터넷을 확인해 주시기 바랍니다.";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private void OnOverWriteSaveData()
|
||
|
|
{
|
||
|
|
AccountStateText.text = "서버에 이미 저장파일이 존재합니다.";
|
||
|
|
}
|
||
|
|
|
||
|
|
public void ClickSaveButton()
|
||
|
|
{
|
||
|
|
GameManager.Sound.PlaySFX(ESFXType.Button_Hit);
|
||
|
|
GameManager.DB.SaveDatas();
|
||
|
|
|
||
|
|
if (GameManager.Account.IsUserLogin == false)
|
||
|
|
{
|
||
|
|
AgreeConditionsPopup popup = GameManager.UI.ShowNStackPopup<AgreeConditionsPopup>(EPopupType.AgreeConditionsPopup);
|
||
|
|
if (popup != null)
|
||
|
|
{
|
||
|
|
popup.InitAgreeConditionsPopup(AgreeConditionsPopup.EAgreeConditionsPopupType.Upload);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
GameManager.Account.SignInWithUploadSaveData(true);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void ClickDataLoadButton()
|
||
|
|
{
|
||
|
|
GameManager.Sound.PlaySFX(ESFXType.Button_Hit);
|
||
|
|
|
||
|
|
if (GameManager.Account.IsUserLogin == false)
|
||
|
|
{
|
||
|
|
AgreeConditionsPopup popup = GameManager.UI.ShowNStackPopup<AgreeConditionsPopup>(EPopupType.AgreeConditionsPopup);
|
||
|
|
if (popup != null)
|
||
|
|
{
|
||
|
|
popup.InitAgreeConditionsPopup(AgreeConditionsPopup.EAgreeConditionsPopupType.Download);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
GameManager.Account.SignInWithDownloadSaveData();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void ClickPrivacyPolicyButton()
|
||
|
|
{
|
||
|
|
GameManager.Sound.PlaySFX(ESFXType.Button_Hit);
|
||
|
|
// 개인정보 정책 팝업 출력
|
||
|
|
GameManager.UI.ShowNStackPopup(EPopupType.PrivacyPoilcyPopup);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void ClickSignOutButton()
|
||
|
|
{
|
||
|
|
GameManager.Sound.PlaySFX(ESFXType.Button_Hit);
|
||
|
|
GameManager.Account.SignOut();
|
||
|
|
}
|
||
|
|
}
|