CapersProject/Assets/02.Scripts/Ui/Tycoon/TycoonResultUi.cs

585 lines
19 KiB
C#
Raw Normal View History

2024-12-03 06:08:15 +00:00
using System;
2024-11-15 07:28:13 +00:00
using System.Collections;
2024-11-07 12:02:00 +00:00
using System.Collections.Generic;
2024-12-10 06:49:15 +00:00
using BlueWater.Audios;
2024-12-17 12:54:30 +00:00
using BlueWater.Npcs.Customers;
2024-11-07 12:02:00 +00:00
using BlueWater.Tycoons;
2024-11-15 07:28:13 +00:00
using BlueWater.Utility;
2024-11-07 12:02:00 +00:00
using UnityEngine;
using Sirenix.OdinInspector;
2024-11-11 09:50:41 +00:00
using TMPro;
2024-11-17 04:29:57 +00:00
using UnityEngine.InputSystem;
2024-12-17 12:54:30 +00:00
using UnityEngine.Serialization;
2024-11-28 23:07:50 +00:00
using UnityEngine.UI;
2024-11-07 12:02:00 +00:00
namespace BlueWater.Uis
{
2024-12-18 16:00:39 +00:00
public class TycoonResultUi : PausePopupUi
2024-11-07 12:02:00 +00:00
{
2024-11-15 07:28:13 +00:00
[Title("결과 카드")]
[SerializeField]
private TycoonResultCard _cardObject;
[SerializeField]
private Transform _cardLocation;
2024-11-07 12:02:00 +00:00
2024-11-15 07:28:13 +00:00
[Title("컴포넌트")]
[SerializeField]
2024-11-07 12:02:00 +00:00
private GameObject _panel;
2024-11-15 07:28:13 +00:00
[Title("타이틀")]
[SerializeField]
private GameObject _titlePanel;
[Title("카드")]
[SerializeField]
private GameObject _cardTitlePanel;
[SerializeField]
private GameObject _resultCardPanel;
[SerializeField]
private GameObject _resultCardContents;
[Title("라운드")]
[SerializeField]
private GameObject _roundPanel;
[SerializeField]
private TMP_Text _roundText;
[Title("플레이 타임")]
[SerializeField]
private GameObject _playTimePanel;
[SerializeField]
private TMP_Text _playTimeText;
2024-11-28 23:07:50 +00:00
[Title("텍스트 패널")]
[SerializeField]
private GameObject _textPanel;
[Title("손님")]
[SerializeField]
private GameObject _customerPanel;
[SerializeField]
private GameObject _customerContents;
2024-12-17 12:54:30 +00:00
[SerializeField]
private GameObject _bigCatPanel;
[SerializeField]
private TMP_Text _bigCatText;
private int _bigCatCount;
2024-11-28 23:07:50 +00:00
[SerializeField]
private GameObject _casperPanel;
[SerializeField]
private TMP_Text _casperText;
private int _casperCount;
2024-12-17 12:54:30 +00:00
[SerializeField]
private GameObject _casperBlackPanel;
[SerializeField]
private TMP_Text _casperBlackText;
private int _casperBlackCount;
[SerializeField]
private GameObject _catPanel;
[SerializeField]
private TMP_Text _catText;
private int _catCount;
2024-11-28 23:07:50 +00:00
[SerializeField]
private GameObject _pumpkinPanel;
[SerializeField]
private TMP_Text _pumpkinText;
private int _pumpkinCount;
2024-11-15 07:28:13 +00:00
2024-12-17 12:54:30 +00:00
[SerializeField]
private GameObject _reaperPanel;
[SerializeField]
private TMP_Text _reaperText;
private int _reaperCount;
[SerializeField]
private GameObject _witchPanel;
[SerializeField]
private TMP_Text _witchText;
private int _witchCount;
2024-11-15 07:28:13 +00:00
[Title("서비스")]
[SerializeField]
private GameObject _serviceTitlePanel;
[SerializeField]
private GameObject _serviceContents;
[Title("Good 서빙")]
[SerializeField]
private GameObject _goodServingPanel;
[SerializeField]
private TMP_Text _goodServingText;
private int _goodServingCount;
[Title("Fail 서빙")]
[SerializeField]
private GameObject _failServingPanel;
[SerializeField]
private TMP_Text _failedServingText;
private int _failedServingCount;
[Title("Miss 서빙")]
[SerializeField]
private GameObject _missServingPanel;
[SerializeField]
private TMP_Text _missServingText;
private int _missServingCount;
[Title("Good 청소")]
[SerializeField]
private GameObject _goodCleaningPanel;
[SerializeField]
private TMP_Text _goodCleaningText;
private int _goodCleaningCount;
[Title("Fail 청소")]
[SerializeField]
private GameObject _failedCleaningPanel;
[SerializeField]
private TMP_Text _failedCleaningText;
private int _failedCleaningCount;
2024-11-28 23:07:50 +00:00
2024-11-15 07:28:13 +00:00
[Title("골드")]
2024-11-28 23:07:50 +00:00
[SerializeField]
private GameObject _goldPanel;
2024-11-15 07:28:13 +00:00
[SerializeField]
private GameObject _goldTitlePanel;
[SerializeField]
private GameObject _goldContents;
[Title("획득한 골드")]
[SerializeField]
private GameObject _goldGainedPanel;
[SerializeField]
private TMP_Text _goldGainedText;
private int _goldGained;
[SerializeField]
private GameObject _plusObject;
[Title("획득한 팁")]
[SerializeField]
private GameObject _tipGainedPanel;
[SerializeField]
private TMP_Text _tipGainedText;
private int _tipGained;
2024-11-11 09:50:41 +00:00
2024-11-15 07:28:13 +00:00
[SerializeField]
private GameObject _minusObject;
[Title("사용한 골드")]
[SerializeField]
private GameObject _goldSpentPanel;
[SerializeField]
private TMP_Text _goldSpentText;
2025-01-02 10:44:51 +00:00
public int _goldSpent;
2024-11-15 07:28:13 +00:00
[Title("총 획득 골드")]
[SerializeField]
private GameObject _totalGoldPanel;
[SerializeField]
private TMP_Text _totalGoldText;
[SerializeField]
private TMP_Text _minusPercentText;
2024-11-11 09:50:41 +00:00
2024-11-28 23:07:50 +00:00
[Title("버튼")]
2024-11-15 07:28:13 +00:00
[SerializeField]
2025-01-02 10:44:51 +00:00
private Button _nextButton;
2024-11-07 12:02:00 +00:00
2024-11-15 07:28:13 +00:00
[Title("연출 효과")]
[SerializeField]
2024-11-28 23:07:50 +00:00
private float _panelWaitingTime = 0.3f;
2024-11-15 07:28:13 +00:00
[SerializeField]
private float _totalGoldDuration = 1f;
2024-12-10 06:49:15 +00:00
[Title("사운드")]
private string _bgmName = "TycoonResult";
2024-11-11 09:50:41 +00:00
2024-11-15 07:28:13 +00:00
private Coroutine _showResultInstance;
2024-11-17 04:29:57 +00:00
private InputAction _pressAnyKeyAction;
2024-11-15 07:28:13 +00:00
2025-01-02 10:44:51 +00:00
public float _playTime;
2024-12-17 11:25:53 +00:00
private bool _isSetData;
2024-11-15 07:28:13 +00:00
2025-01-02 10:44:51 +00:00
[Title("[다음]")]
[SerializeField]
private RankUi _rankUi;
2024-11-15 07:28:13 +00:00
private void Awake()
{
2024-11-17 04:29:57 +00:00
EventManager.OnShowResult += Open;
2024-11-28 23:07:50 +00:00
EventManager.OnCheckedSkin += AddCustomerCount;
2024-12-03 06:08:15 +00:00
EventManager.OnSucceedServing += AddServingCount;
2024-11-15 07:28:13 +00:00
EventManager.OnMissedServing += AddMissedServingCount;
EventManager.OnCleaningResult += AddCleaningCount;
EventManager.OnAddedGold += AddGoldCount;
}
2024-11-07 12:02:00 +00:00
public void Start()
{
2024-11-18 10:07:19 +00:00
_pressAnyKeyAction = PlayerInputKeyManager.Instance.GetAction(InputActionMaps.TycoonUi, TycoonUiActions.PressAnyKey);
2024-11-17 04:29:57 +00:00
2024-11-15 07:28:13 +00:00
foreach (Transform element in _resultCardContents.transform)
{
Destroy(element.gameObject);
}
2025-01-02 10:44:51 +00:00
_nextButton.onClick.AddListener(() => _rankUi.RunRank());
2024-11-28 23:07:50 +00:00
2024-12-17 12:54:30 +00:00
_bigCatCount = 0;
2024-11-28 23:07:50 +00:00
_casperCount = 0;
2024-12-17 12:54:30 +00:00
_casperBlackCount = 0;
_catCount = 0;
2024-11-28 23:07:50 +00:00
_pumpkinCount = 0;
2024-12-17 12:54:30 +00:00
_reaperCount = 0;
_witchCount = 0;
2024-11-28 23:07:50 +00:00
_goodServingCount = 0;
_failedServingCount = 0;
_missServingCount = 0;
_goodCleaningCount = 0;
_failedServingCount = 0;
2024-11-15 07:28:13 +00:00
SetActiveUi(false);
2024-11-07 12:02:00 +00:00
}
public void Update()
{
2024-11-15 07:28:13 +00:00
_playTime += Time.deltaTime; //플레이타임 측정 (일시정지나 메뉴얼보는 시간은 제외)
}
private void OnDestroy()
{
2024-11-17 04:29:57 +00:00
EventManager.OnShowResult -= Open;
2024-11-28 23:07:50 +00:00
EventManager.OnCheckedSkin -= AddCustomerCount;
2024-12-03 06:08:15 +00:00
EventManager.OnSucceedServing -= AddServingCount;
2024-11-15 07:28:13 +00:00
EventManager.OnMissedServing -= AddMissedServingCount;
EventManager.OnCleaningResult -= AddCleaningCount;
EventManager.OnAddedGold -= AddGoldCount;
2024-11-28 23:07:50 +00:00
if (SceneController.Instance)
{
2025-01-02 10:44:51 +00:00
_nextButton?.onClick.RemoveListener(() => _rankUi.RunRank());
2024-11-28 23:07:50 +00:00
}
2024-11-15 07:28:13 +00:00
2024-11-28 23:07:50 +00:00
_pressAnyKeyAction.performed -= OnShowImmediately;
2024-11-15 07:28:13 +00:00
}
2024-11-17 04:29:57 +00:00
2024-11-15 07:28:13 +00:00
[Button("결과 연출 테스트")]
2024-11-17 04:29:57 +00:00
public override void Open()
2024-11-15 07:28:13 +00:00
{
2024-12-18 16:00:39 +00:00
OpenSwitch(InputActionMaps.TycoonUi);
2024-12-17 11:25:53 +00:00
AudioManager.Instance.StopSfx("TycoonGameOver");
2024-12-10 06:49:15 +00:00
AudioManager.Instance.PlayBgm(_bgmName);
2024-11-17 04:29:57 +00:00
2024-11-15 07:28:13 +00:00
Utils.StartUniqueCoroutine(this, ref _showResultInstance, ShowResultCoroutine());
2024-11-07 12:02:00 +00:00
}
2024-11-17 04:29:57 +00:00
public override void Close()
{
}
public override void EnableInput()
{
2024-11-28 23:07:50 +00:00
_pressAnyKeyAction.performed += OnShowImmediately;
2024-11-17 04:29:57 +00:00
}
public override void DisableInput()
{
2024-11-28 23:07:50 +00:00
_pressAnyKeyAction.performed -= OnShowImmediately;
2024-11-17 04:29:57 +00:00
}
2024-11-28 23:07:50 +00:00
private void OnShowImmediately(InputAction.CallbackContext context)
2024-11-17 04:29:57 +00:00
{
2024-11-28 23:07:50 +00:00
_pressAnyKeyAction.performed -= OnShowImmediately;
2024-11-17 04:29:57 +00:00
ShowImmediately();
}
2024-11-15 07:28:13 +00:00
private IEnumerator ShowResultCoroutine()
2024-11-07 12:02:00 +00:00
{
2024-11-15 07:28:13 +00:00
SetResultData();
2024-11-28 23:07:50 +00:00
WaitForSecondsRealtime panelWaitingTime = new WaitForSecondsRealtime(_panelWaitingTime);
2024-11-15 07:28:13 +00:00
2024-11-07 12:02:00 +00:00
_panel.SetActive(true);
2024-11-15 07:28:13 +00:00
_titlePanel.SetActive(true);
2024-11-28 23:07:50 +00:00
yield return panelWaitingTime;
2024-11-15 07:28:13 +00:00
_cardTitlePanel.SetActive(true);
_resultCardPanel.SetActive(true);
2024-11-28 23:07:50 +00:00
yield return panelWaitingTime;
2024-11-15 07:28:13 +00:00
_resultCardContents.SetActive(true);
2024-11-28 23:07:50 +00:00
yield return panelWaitingTime;
2024-11-15 07:28:13 +00:00
_roundPanel.SetActive(true);
_playTimePanel.SetActive(true);
2024-11-28 23:07:50 +00:00
yield return panelWaitingTime;
2024-11-11 09:50:41 +00:00
2024-11-28 23:07:50 +00:00
_textPanel.SetActive(true);
_customerPanel.SetActive(true);
_customerContents.SetActive(true);
2024-12-17 12:54:30 +00:00
_bigCatPanel.SetActive(true);
2024-11-28 23:07:50 +00:00
_casperPanel.SetActive(true);
2024-12-17 12:54:30 +00:00
_casperBlackPanel.SetActive(true);
_catPanel.SetActive(true);
2024-11-28 23:07:50 +00:00
_pumpkinPanel.SetActive(true);
2024-12-17 12:54:30 +00:00
_reaperPanel.SetActive(true);
_witchPanel.SetActive(true);
2024-11-28 23:07:50 +00:00
yield return panelWaitingTime;
2024-11-15 07:28:13 +00:00
_serviceTitlePanel.SetActive(true);
_serviceContents.SetActive(true);
_goodServingPanel.SetActive(true);
_failServingPanel.SetActive(true);
_missServingPanel.SetActive(true);
_goodCleaningPanel.SetActive(true);
_failedCleaningPanel.SetActive(true);
2024-11-28 23:07:50 +00:00
yield return panelWaitingTime;
2024-11-15 07:28:13 +00:00
2024-11-28 23:07:50 +00:00
_goldPanel.SetActive(true);
2024-11-15 07:28:13 +00:00
_goldTitlePanel.SetActive(true);
_goldContents.SetActive(true);
_goldGainedPanel.SetActive(true);
_plusObject.SetActive(true);
_tipGainedPanel.SetActive(true);
_minusObject.SetActive(true);
_goldSpentPanel.SetActive(true);
2024-11-28 23:07:50 +00:00
yield return panelWaitingTime;
2024-11-15 07:28:13 +00:00
float elapsedTime = 0f;
int currentGold = TycoonManager.Instance.TycoonStatus.CurrentGold;
2024-11-19 13:32:43 +00:00
int targetGold = ES3.Load(SaveData.EndGold, 0);
2024-11-15 07:28:13 +00:00
string totalGoldLocalized = Utils.GetLocalizedString("TotalGold");
_totalGoldText.text = $"{totalGoldLocalized} : {currentGold:N0}";
_totalGoldPanel.SetActive(true);
2024-11-28 23:07:50 +00:00
yield return panelWaitingTime;
2024-11-15 07:28:13 +00:00
_minusPercentText.enabled = true;
2024-11-28 23:07:50 +00:00
yield return panelWaitingTime;
2024-11-07 12:02:00 +00:00
2024-11-15 07:28:13 +00:00
while (elapsedTime <= _totalGoldDuration)
2024-11-07 12:02:00 +00:00
{
2024-11-15 07:28:13 +00:00
var newGold = (int)Mathf.Lerp(currentGold, targetGold, elapsedTime / _totalGoldDuration);
_totalGoldText.text = $"{totalGoldLocalized} : {newGold:N0}";
elapsedTime += Time.unscaledDeltaTime;
yield return null;
2024-11-07 12:02:00 +00:00
}
2024-11-15 07:28:13 +00:00
_totalGoldText.text = $"{totalGoldLocalized} : {targetGold:N0}";
2024-11-28 23:07:50 +00:00
yield return panelWaitingTime;
2024-11-15 07:28:13 +00:00
2025-01-02 10:44:51 +00:00
_nextButton.gameObject.SetActive(true);
2024-11-11 11:11:10 +00:00
2024-11-28 23:07:50 +00:00
_pressAnyKeyAction.performed -= OnShowImmediately;
2024-11-17 04:29:57 +00:00
yield return null;
2024-11-07 12:02:00 +00:00
}
2024-11-15 07:28:13 +00:00
private void SetActiveUi(bool isActive)
{
_panel.SetActive(isActive);
_titlePanel.SetActive(isActive);
_cardTitlePanel.SetActive(isActive);
_resultCardPanel.SetActive(isActive);
_resultCardContents.SetActive(isActive);
_roundPanel.SetActive(isActive);
_playTimePanel.SetActive(isActive);
2024-11-28 23:07:50 +00:00
_textPanel.SetActive(isActive);
_customerPanel.SetActive(isActive);
_customerContents.SetActive(isActive);
2024-12-17 12:54:30 +00:00
_bigCatPanel.SetActive(isActive);
2024-11-28 23:07:50 +00:00
_casperPanel.SetActive(isActive);
2024-12-17 12:54:30 +00:00
_casperBlackPanel.SetActive(isActive);
_catPanel.SetActive(isActive);
2024-11-28 23:07:50 +00:00
_pumpkinPanel.SetActive(isActive);
2024-12-17 12:54:30 +00:00
_reaperPanel.SetActive(isActive);
_witchPanel.SetActive(isActive);
2024-11-15 07:28:13 +00:00
_serviceTitlePanel.SetActive(isActive);
_serviceContents.SetActive(isActive);
_goodServingPanel.SetActive(isActive);
_failServingPanel.SetActive(isActive);
_missServingPanel.SetActive(isActive);
_goodCleaningPanel.SetActive(isActive);
_failedCleaningPanel.SetActive(isActive);
2024-11-28 23:07:50 +00:00
_goldPanel.SetActive(isActive);
2024-11-15 07:28:13 +00:00
_goldTitlePanel.SetActive(isActive);
_goldContents.SetActive(isActive);
_goldGainedPanel.SetActive(isActive);
_plusObject.SetActive(isActive);
_tipGainedPanel.SetActive(isActive);
_minusObject.SetActive(isActive);
_goldSpentPanel.SetActive(isActive);
_totalGoldPanel.SetActive(isActive);
_minusPercentText.enabled = isActive;
2025-01-02 10:44:51 +00:00
_nextButton.gameObject.SetActive(isActive);
2024-11-15 07:28:13 +00:00
}
private void SetResultData()
{
2024-12-20 05:11:56 +00:00
int currentGold = TycoonManager.Instance.TycoonStatus.CurrentGold;
float endGoldMultiplier = -0.5f + TycoonManager.Instance.TycoonStatus.EndGoldMultiplier;
int addedGold = Mathf.RoundToInt(currentGold * endGoldMultiplier);
int saveGold = currentGold + addedGold;
ES3.Save(SaveData.EndGold, saveGold);
ES3.Save(SaveData.CompleteFirstGame, true);
2025-01-02 10:44:51 +00:00
int tries = ES3.Load(SaveData.Tries, 0);
ES3.Save(SaveData.Tries, ++tries);
2024-12-20 05:11:56 +00:00
2024-11-28 23:07:50 +00:00
Dictionary<string, int> selectedCards = TycoonManager.Instance.TycoonCardController.SelectedCard;
2024-11-15 07:28:13 +00:00
foreach (var element in selectedCards)
{
TycoonResultCard newCard = Instantiate(_cardObject, _cardLocation);
2024-11-28 23:07:50 +00:00
newCard.SetImage(TycoonManager.Instance.TycoonCardController.CardDataSo.GetDataByIdx(element.Key).Sprite);
newCard.SetText(TycoonManager.Instance.TycoonCardController.CardDataSo.GetDataByIdx(element.Key).ScriptText);
2024-11-15 07:28:13 +00:00
newCard.SetCount(element.Value);
newCard.name = element.Key;
}
_roundText.text = $"{Utils.GetLocalizedString("Round")} : {TycoonManager.Instance.GetCurrentLevelData().Idx}";
_playTimeText.text = $"{Utils.GetLocalizedString("PlayTime")} : {Mathf.FloorToInt(_playTime / 60f):D2} : {Mathf.FloorToInt(_playTime % 60f):D2}";
2024-12-17 12:54:30 +00:00
_bigCatText.text = _bigCatCount.ToString();
2024-11-28 23:07:50 +00:00
_casperText.text = _casperCount.ToString();
2024-12-17 12:54:30 +00:00
_casperBlackText.text = _casperBlackCount.ToString();
_catText.text = _catCount.ToString();
2024-11-28 23:07:50 +00:00
_pumpkinText.text = _pumpkinCount.ToString();
2024-12-17 12:54:30 +00:00
_reaperText.text = _reaperCount.ToString();
_witchText.text = _witchCount.ToString();
2024-11-15 07:28:13 +00:00
_goodServingText.text = _goodServingCount.ToString();
_failedServingText.text = _failedServingCount.ToString();
_missServingText.text = _missServingCount.ToString();
_goodCleaningText.text = _goodCleaningCount.ToString();
_failedCleaningText.text = _failedCleaningCount.ToString();
_goldGainedText.text = _goldGained.ToString("N0");
_tipGainedText.text = _tipGained.ToString("N0");
_goldSpentText.text = _goldSpent.ToString("N0");
2024-11-19 14:38:45 +00:00
_totalGoldText.text = $"{Utils.GetLocalizedString("TotalGold")} : {ES3.Load(SaveData.EndGold, 0):N0}";
2024-12-06 13:20:10 +00:00
int percent = Mathf.RoundToInt(endGoldMultiplier * 100);
char sign = percent >= 0 ? '+' : '-';
_minusPercentText.color = percent >= 0 ? Color.blue : Color.red;
2024-12-17 11:25:53 +00:00
_minusPercentText.text = $"{sign} {Mathf.Abs(percent)}%";
_isSetData = true;
2024-11-15 07:28:13 +00:00
}
[Button("결과 즉시 테스트")]
private void ShowImmediately()
{
if (_showResultInstance != null)
{
StopCoroutine(_showResultInstance);
_showResultInstance = null;
}
2024-12-17 11:25:53 +00:00
if (!_isSetData)
{
SetResultData();
}
2024-11-15 07:28:13 +00:00
SetActiveUi(true);
2024-11-28 23:07:50 +00:00
}
2024-12-17 12:54:30 +00:00
private void AddCustomerCount(CustomerSkin skinIndex)
2024-11-28 23:07:50 +00:00
{
switch (skinIndex)
{
2024-12-17 12:54:30 +00:00
case CustomerSkin.BigCat:
_bigCatCount++;
break;
case CustomerSkin.Casper:
2024-11-28 23:07:50 +00:00
_casperCount++;
break;
2024-12-17 12:54:30 +00:00
case CustomerSkin.CasperBlack:
_casperBlackCount++;
break;
case CustomerSkin.Cat:
_catCount++;
break;
case CustomerSkin.PumkinHead:
2024-11-28 23:07:50 +00:00
_pumpkinCount++;
break;
2024-12-17 12:54:30 +00:00
case CustomerSkin.Reaper:
_reaperCount++;
break;
case CustomerSkin.Witch:
_witchCount++;
break;
default:
2024-12-03 06:08:15 +00:00
throw new Exception("손님 스킨 인덱스 오류");
2024-11-28 23:07:50 +00:00
}
2024-11-15 07:28:13 +00:00
}
2024-12-03 06:08:15 +00:00
private void AddServingCount(bool orderedCorrected)
2024-11-15 07:28:13 +00:00
{
if (orderedCorrected)
{
_goodServingCount++;
}
else
{
_failedServingCount++;
}
}
2024-12-03 06:08:15 +00:00
private void AddMissedServingCount() => _missServingCount++;
2024-11-15 07:28:13 +00:00
private void AddCleaningCount(bool isSucceed)
{
if (isSucceed)
{
_goodCleaningCount++;
}
else
{
_failedCleaningCount++;
}
}
private void AddGoldCount(int addedGold, bool isTip)
{
if (addedGold < 0)
{
_goldSpent += Mathf.Abs(addedGold);
return;
}
if (isTip)
{
_tipGained += addedGold;
}
else
{
_goldGained += addedGold;
}
}
2024-11-07 12:02:00 +00:00
}
}