Commit 7e7f8246 authored by Mahmoud Aglan's avatar Mahmoud Aglan

Update : Fixed If there is no questions Play buttons are disabled

parent 5f4e8e15
using System.Linq;
using com.al_arcade.shared;
using Cysharp.Threading.Tasks;
using DG.Tweening;
using UnityEngine;
......@@ -8,6 +9,7 @@ public class HomeController : MonoBehaviour
{
[SerializeField] private UIDocument mainMenuDocument;
[SerializeField] private GameObject challengePrefab;
[SerializeField] private int minQuestionsPerType = 5;
private Label username;
private Label xp;
......@@ -16,6 +18,7 @@ public class HomeController : MonoBehaviour
private CustomProgressBar nextRankProgressBar;
private Button challengeButton;
private Button practiceButton;
private Label nameMenuPanel;
private Label xpMenuPanel;
......@@ -43,6 +46,9 @@ public class HomeController : MonoBehaviour
challengeButton = root.Q<Button>("Challenge");
challengeButton.clicked += OnChallengeButtonClicked;
practiceButton = root.Q<Button>("OpenPracticeButton");
SetPlayButtonsEnabled(false);
OnUserChange(UserService.Instance.CurrentUser);
}
......@@ -58,6 +64,45 @@ public class HomeController : MonoBehaviour
nextRankProgressBar.Value = Rank.FromXP(user.Points).Progress(user.Points);
nextRankProgressBar.LeftText = Rank.FromXP(user.Points).StartXP.ToString() + " " + Rank.FromXP(user.Points).ArabicName;
nextRankProgressBar.RightText = Rank.FromXP(user.Points).Next?.StartXP.ToString() + " " + Rank.FromXP(user.Points).Next?.ArabicName;
CheckQuestionAvailability(user);
}
private void CheckQuestionAvailability(User user)
{
StartCoroutine(SSApiManager.EnsureInstance().GetChapters(
chapters =>
{
int mcq = 0, tf = 0, cs = 0;
foreach (var ch in chapters)
{
mcq += ch.mcq_count;
tf += ch.tf_count;
cs += ch.cs_count;
}
bool enough = mcq >= minQuestionsPerType
&& tf >= minQuestionsPerType
&& cs >= minQuestionsPerType;
SetPlayButtonsEnabled(enough);
},
_ => SetPlayButtonsEnabled(false),
gradeId: user.Grade,
termId: user.Term
));
}
private void SetPlayButtonsEnabled(bool enabled)
{
if (challengeButton != null)
{
challengeButton.SetEnabled(enabled);
challengeButton.style.opacity = enabled ? 1f : 0.35f;
}
if (practiceButton != null)
{
practiceButton.SetEnabled(enabled);
practiceButton.style.opacity = enabled ? 1f : 0.35f;
}
}
// private void OnNewActivityReceived(Activity activity)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment