250 lines
9.0 KiB
C#
250 lines
9.0 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using PixelCrushers.QuestMachine;
|
|
using Sirenix.OdinInspector;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Beyond
|
|
{
|
|
public class JudgementMenuController : MonoBehaviour
|
|
{
|
|
[SerializeField] private GuiltSlot guiltSlotPrefab;
|
|
[SerializeField] private List<GuiltSlot> guiltSlots;
|
|
[SerializeField] private GuiltSlot selectedSlot;
|
|
[SerializeField] private List<Quest> quiltQuests;
|
|
[SerializeField] private RectTransform guiltsRect, descriptionRect;
|
|
[SerializeField] private PlayerConfessionController playerConfessionController;
|
|
[SerializeField] private Image guiltImage;
|
|
[SerializeField] private TMP_Text descriptionOffenceCategory, descriptionChargedWith, descriptionPenaltyConsequences, descriptionPlaceOfCrime, guiltTitle;
|
|
[SerializeField] private Button agreeButton, disagreeButton;
|
|
[SerializeField] private Button quitButton, warningQuitButton;
|
|
[SerializeField] private Slider descriptionSlider;
|
|
[SerializeField] private Sprite noGuiltsImage;
|
|
[SerializeField] private MenuScroll menuScroll;
|
|
[SerializeField] private GameObject guiltsWindow, warningWindow;
|
|
|
|
public UnityEvent onAllGuiltsAgreed;
|
|
public UnityEvent onNotAllGuiltsAgreed;
|
|
|
|
private int disagreedQuests = 0;
|
|
|
|
public void OpenJudgementWindow()
|
|
{
|
|
//probably not needed
|
|
guiltsWindow.gameObject.SetActive(true);
|
|
warningWindow.gameObject.SetActive(false);
|
|
descriptionRect.gameObject.SetActive(true);
|
|
LoadGuilts();
|
|
if (guiltSlots.Count > 0)
|
|
{
|
|
disagreedQuests = 0;
|
|
quitButton.gameObject.SetActive(false);
|
|
warningQuitButton.gameObject.SetActive(false);
|
|
guiltSlots.ForEach(slot => slot.SetAsDeselected());
|
|
SelectGuilt(guiltSlots[0]);
|
|
}
|
|
else
|
|
{
|
|
SelectEmptyGuilt();
|
|
quitButton.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
|
|
[Button]
|
|
private void LoadGuilts()
|
|
{
|
|
playerConfessionController.LoadGuilts();
|
|
quiltQuests = playerConfessionController.Guilts;
|
|
// playerConfessionController.SetGuilts();
|
|
//not needed probably
|
|
while (guiltSlots.Count > 0)
|
|
{
|
|
Destroy(guiltSlots[0].gameObject);
|
|
guiltSlots.RemoveAt(0);
|
|
}
|
|
quiltQuests.ForEach(quest =>
|
|
{
|
|
GuiltSlot slot = guiltSlots.Find(slot => slot.id == quest.id.text);
|
|
if (slot != null)
|
|
{
|
|
slot.count++;
|
|
slot.title.text = quest.title.text + " " + slot.count;
|
|
}
|
|
else
|
|
{
|
|
GuiltSlot clone = Instantiate(guiltSlotPrefab, guiltsRect); //add pooling if issues with performance arise
|
|
clone.title.text = quest.title.text;
|
|
clone.id = quest.id.text;
|
|
if (quest.GetState() != QuestState.Active)
|
|
{
|
|
quest.SetState(QuestState.Active);//desc. info is stored in active part
|
|
}
|
|
var contents = quest.GetContentList(QuestContentCategory.Journal);
|
|
List<BodyTextQuestContent> descriptionContents = contents.FindAll(content => content is BodyTextQuestContent).Cast<BodyTextQuestContent>().ToList();
|
|
// List<BodyTextQuestContent> descriptionContent = contents.Cast<BodyTextQuestContent>().FindAll(content => content is BodyTextQuestContent).ToList();
|
|
|
|
clone.descriptionOffenceCategory = descriptionContents[0].bodyText.text;
|
|
clone.descriptionChargedWith = descriptionContents[1].bodyText.text;
|
|
clone.descriptionPenaltyConsequences = descriptionContents[2].bodyText.text;
|
|
clone.descriptionPlaceOfCrime = descriptionContents[3].bodyText.text;
|
|
clone.image.sprite = quest.icon;
|
|
clone.Clicked += () => SelectGuilt(clone);
|
|
guiltSlots.Add(clone);
|
|
}
|
|
});
|
|
}
|
|
|
|
private void SelectGuilt(GuiltSlot guiltSlot)
|
|
{
|
|
if (selectedSlot)
|
|
{
|
|
selectedSlot.SetAsDeselected();
|
|
}
|
|
selectedSlot = guiltSlot;
|
|
selectedSlot.SetAsSelected();
|
|
guiltImage.sprite = guiltSlot.image.sprite;
|
|
descriptionOffenceCategory.text = guiltSlot.descriptionOffenceCategory;
|
|
descriptionChargedWith.text = guiltSlot.descriptionChargedWith;
|
|
descriptionPenaltyConsequences.text = guiltSlot.descriptionPenaltyConsequences;
|
|
descriptionPlaceOfCrime.text = guiltSlot.descriptionPlaceOfCrime;
|
|
|
|
if (guiltTitle)
|
|
{
|
|
guiltTitle.text = guiltSlot.title.text;
|
|
}
|
|
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(descriptionRect);
|
|
agreeButton.onClick.RemoveAllListeners();
|
|
agreeButton.onClick.AddListener(() => AgreeOnGuilt(guiltSlot));
|
|
if (guiltSlot.disagreed)
|
|
{
|
|
disagreeButton.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
disagreeButton.gameObject.SetActive(true);
|
|
disagreeButton.onClick.RemoveAllListeners();
|
|
disagreeButton.onClick.AddListener(() => DisagreeOnGuilt(guiltSlot));
|
|
}
|
|
}
|
|
|
|
private void SelectEmptyGuilt()
|
|
{
|
|
descriptionRect.gameObject.SetActive(false);
|
|
if (guiltTitle)
|
|
{
|
|
guiltTitle.text = "";
|
|
}
|
|
|
|
//agreeButton.gameObject.SetActive(false);
|
|
//disagreeButton.gameObject.SetActive(false);
|
|
//guiltImage.sprite = noGuiltsImage;
|
|
//descriptionOffenceCategory.text = "";
|
|
//descriptionChargedWith.text = "";
|
|
//descriptionPenaltyConsequences.text = "";
|
|
//descriptionPlaceOfCrime.text = "";
|
|
}
|
|
|
|
private void AgreeOnGuilt(GuiltSlot guiltSlot)
|
|
{
|
|
while (guiltSlot.count > 0)
|
|
{
|
|
playerConfessionController.RedeemGuilt(guiltSlot.id);
|
|
guiltSlot.count--;
|
|
}
|
|
if (guiltSlot.disagreed)
|
|
{
|
|
disagreedQuests--;
|
|
}
|
|
|
|
guiltSlots.Remove(guiltSlot);
|
|
if (guiltSlots.Count > 0)
|
|
{
|
|
guiltSlots[0].Clicked();
|
|
EnableQuitIfOnlyDisagreedQuestsLeft();
|
|
}
|
|
else if (disagreedQuests == 0)
|
|
{
|
|
SelectEmptyGuilt();
|
|
quitButton.gameObject.SetActive(true);
|
|
warningQuitButton.gameObject.SetActive(false);
|
|
}
|
|
Player.Instance.PlayAcceptGuiltSound();
|
|
Destroy(guiltSlot.gameObject);
|
|
}
|
|
|
|
private void EnableQuitIfOnlyDisagreedQuestsLeft()
|
|
{
|
|
if (disagreedQuests == guiltSlots.Count)
|
|
{
|
|
warningQuitButton.gameObject.SetActive(true);
|
|
quitButton.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
private void DisagreeOnGuilt(GuiltSlot guiltSlot)
|
|
{
|
|
playerConfessionController.RememberGuilt(guiltSlot.id);
|
|
guiltSlot.SetAsDisagreedOn();
|
|
disagreedQuests++;
|
|
|
|
if (guiltSlots.Count == disagreedQuests)
|
|
{
|
|
warningQuitButton.gameObject.SetActive(true);
|
|
}
|
|
disagreeButton.gameObject.SetActive(false);
|
|
Player.Instance.PlayDeclineGuiltSound();
|
|
}
|
|
|
|
public void OpenWarningWindow()
|
|
{
|
|
StartCoroutine(menuScroll.ChangeVisibleCanvaCoroutine(guiltsWindow, warningWindow));
|
|
}
|
|
|
|
public void ReopenGuiltsWindow()
|
|
{
|
|
StartCoroutine(menuScroll.ChangeVisibleCanvaCoroutine(warningWindow, guiltsWindow));
|
|
quitButton.gameObject.SetActive(true);
|
|
warningQuitButton.gameObject.SetActive(false);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (guiltSlots.Count == 0 || !guiltSlots[0])
|
|
return;
|
|
guiltSlots.ForEach(button =>
|
|
{
|
|
button.Clicked -= () => SelectGuilt(button);
|
|
});
|
|
|
|
if (disagreeButton)
|
|
{
|
|
disagreeButton.onClick.RemoveAllListeners();
|
|
}
|
|
|
|
if (agreeButton)
|
|
{
|
|
agreeButton.onClick.RemoveAllListeners();
|
|
}
|
|
}
|
|
|
|
public void FinishJudgement()
|
|
{
|
|
playerConfessionController.SummarizeGuilts();
|
|
|
|
if (disagreedQuests > 0)
|
|
{
|
|
onNotAllGuiltsAgreed?.Invoke();
|
|
}
|
|
else
|
|
{
|
|
onAllGuiltsAgreed?.Invoke();
|
|
}
|
|
}
|
|
}
|
|
} |