116 lines
3.9 KiB
C#
116 lines
3.9 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class CharacterSettingPanel : SettingsPanelBase
|
|
{
|
|
[SerializeField] private List<EnemyData> botProfiles;
|
|
private int currentBotIndex = 0;
|
|
|
|
private List<Prize> prizes;
|
|
private int currentPrizeTypeIndex = 0;
|
|
|
|
|
|
// âèçóàëüíûå êîìïîíåíòû ïàíåëè
|
|
|
|
[SerializeField] private TMP_Text nickname;
|
|
[SerializeField] private Image avatarImage;
|
|
[SerializeField] private TMP_Text botNumberText;
|
|
[SerializeField] private TMP_Text prizeType;
|
|
[SerializeField] private TMP_Text prizeAmount;
|
|
|
|
public override void Initialize()
|
|
{
|
|
prizes = PrizeSerializer.GetPrizes();
|
|
var botProfile = botProfiles[currentBotIndex];
|
|
nickname.text = botProfile.nickname;
|
|
avatarImage.sprite = botProfile.characterSprite;
|
|
botNumberText.text = $"Óðîâåíü áîòà : {currentBotIndex + 1}";
|
|
|
|
prizeType.text = "Ïðèç : " + GetPrizeTypeString(prizes[currentBotIndex].PrizeType);
|
|
prizeAmount.text = "Êîëè÷åñòâî : " + prizes[currentBotIndex].Amount;
|
|
}
|
|
|
|
public override void SwitchVertical(int discreteDirection)
|
|
{
|
|
if(discreteDirection == 0)return;
|
|
|
|
currentBotIndex += discreteDirection;
|
|
if (currentBotIndex < 0)
|
|
currentBotIndex = botProfiles.Count - 1;
|
|
else if (currentBotIndex >= botProfiles.Count)
|
|
currentBotIndex = 0;
|
|
|
|
var botProfile = botProfiles[currentBotIndex];
|
|
nickname.text = botProfile.nickname;
|
|
avatarImage.sprite = botProfile.characterSprite;
|
|
botNumberText.text = $"Óðîâåíü áîòà : {currentBotIndex + 1}";
|
|
|
|
|
|
prizeType.text = "Ïðèç : " + GetPrizeTypeString(prizes[currentBotIndex].PrizeType);
|
|
prizeAmount.text = "Êîëè÷åñòâî : " + prizes[currentBotIndex].Amount;
|
|
}
|
|
|
|
public override void SwitchHorizontal(int discreteDirection, bool changeAmount = false)
|
|
{
|
|
if(discreteDirection == 0)return;
|
|
|
|
Prize prize = prizes[currentBotIndex];
|
|
|
|
if(changeAmount)prize.Amount = ValidatePrizeAmount(prize, discreteDirection);
|
|
else
|
|
{
|
|
currentPrizeTypeIndex += discreteDirection;
|
|
if (currentPrizeTypeIndex >= Enum.GetNames(typeof(PrizeType)).Length) currentPrizeTypeIndex = 0;
|
|
else if (currentPrizeTypeIndex < 0) currentPrizeTypeIndex = Enum.GetNames(typeof(PrizeType)).Length - 1;
|
|
prize.PrizeType = (PrizeType)currentPrizeTypeIndex;
|
|
prize.Amount = ValidatePrizeAmount(prize,-5);
|
|
Debug.Log(prize.PrizeType);
|
|
}
|
|
|
|
prizes[currentBotIndex] = prize;
|
|
|
|
prizeType.text = "Ïðèç : " + GetPrizeTypeString(prizes[currentBotIndex].PrizeType);
|
|
|
|
prizeAmount.text = "Êîëè÷åñòâî : " + prize.Amount;
|
|
|
|
}
|
|
|
|
private string GetPrizeTypeString(PrizeType type)
|
|
{
|
|
return type switch
|
|
{
|
|
PrizeType.None => "Íåò ïðèçà",
|
|
PrizeType.Hopper => "Õîïïåðû",
|
|
PrizeType.Marbles => "Øàðèêè",
|
|
PrizeType.Ticket => "Áèëåòû",
|
|
PrizeType.Special => "Ñïåöèàëüíûé ïðèç",
|
|
_ => "Íåèçâåñòíûé ïðèç"
|
|
};
|
|
}
|
|
|
|
|
|
private int ValidatePrizeAmount(Prize prize, int prizeDirection)
|
|
{
|
|
var newAmount = prize.Amount + prizeDirection;
|
|
return prize switch
|
|
{
|
|
{ PrizeType: PrizeType.None } => 0,
|
|
{ PrizeType: PrizeType.Hopper } => Mathf.Clamp(newAmount, 1, 2),
|
|
{ PrizeType: PrizeType.Marbles } => Mathf.Clamp(newAmount, 1, 5),
|
|
{ PrizeType: PrizeType.Ticket } => Mathf.Clamp(newAmount, 1, 5),
|
|
{ PrizeType: PrizeType.Special } => 1,
|
|
_ => prize.Amount
|
|
};
|
|
}
|
|
|
|
public override void Accept()
|
|
{
|
|
PrizeSerializer.SetPrizes(prizes);
|
|
}
|
|
|
|
}
|