Commit 0652cde1 authored by saad's avatar saad

add new ui in challenge mode

parent a5ccaa97
...@@ -196,6 +196,51 @@ MonoBehaviour: ...@@ -196,6 +196,51 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: Assembly-CSharp::LoginPageAnimation m_EditorClassIdentifier: Assembly-CSharp::LoginPageAnimation
loginPage: {fileID: 1971829438} loginPage: {fileID: 1971829438}
--- !u!1 &697923396
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 697923398}
- component: {fileID: 697923397}
m_Layer: 0
m_Name: Transition manager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &697923397
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 697923396}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 61430b0086307cc4da3ccc8d39ae88da, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::EasyTransition.TransitionManager
transitionTemplate: {fileID: 5276914992623515724, guid: 616d511151a6c554caddf1c754e4f91d, type: 3}
--- !u!4 &697923398
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 697923396}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -4.15541, y: 2.46558, z: 2.22055}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &951503749 --- !u!1 &951503749
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
...@@ -645,3 +690,4 @@ SceneRoots: ...@@ -645,3 +690,4 @@ SceneRoots:
- {fileID: 1628372281} - {fileID: 1628372281}
- {fileID: 1093642342} - {fileID: 1093642342}
- {fileID: 2142479138} - {fileID: 2142479138}
- {fileID: 697923398}
This diff is collapsed.
This diff is collapsed.
...@@ -149,8 +149,16 @@ namespace com.al_arcade.cs ...@@ -149,8 +149,16 @@ namespace com.al_arcade.cs
if (uiManager != null) if (uiManager != null)
{ {
uiManager.ShowGameUI(); uiManager.ShowGameUI();
uiManager.SetScore(0);
uiManager.SetProgress(0, _questions.Length); uiManager.SetProgress(0, _questions.Length);
uiManager.EnableScore(IsChallengeMode);
if (IsChallengeMode && ChallengeManager.Instance != null)
{
uiManager.SetScore(ChallengeManager.Instance.TimeSaved);
}
else
{
uiManager.SetScore(0);
}
} }
onGameStart?.Invoke(); onGameStart?.Invoke();
...@@ -314,7 +322,6 @@ namespace com.al_arcade.cs ...@@ -314,7 +322,6 @@ namespace com.al_arcade.cs
if (uiManager != null) if (uiManager != null)
{ {
uiManager.ShowFeedback($"ممتاز! {points}+", true); uiManager.ShowFeedback($"ممتاز! {points}+", true);
uiManager.SetScore(_score);
uiManager.SetStreak(_streak); uiManager.SetStreak(_streak);
} }
......
...@@ -20,7 +20,7 @@ namespace com.al_arcade.cs ...@@ -20,7 +20,7 @@ namespace com.al_arcade.cs
[SerializeField] protected CanvasGroup _optionsPanel, _feedbackGroup; [SerializeField] protected CanvasGroup _optionsPanel, _feedbackGroup;
[SerializeField] protected UniText _progressText; [SerializeField] protected UniText _progressText;
[SerializeField] protected UniText _hintText, _scoreText, _streakText; [SerializeField] protected UniText _hintText, _scoreText, _streakText , _scoreLbl;
[SerializeField] protected UniText _feedbackText; [SerializeField] protected UniText _feedbackText;
[SerializeField] protected Image _feedbackBg, _timerFill; [SerializeField] protected Image _feedbackBg, _timerFill;
...@@ -508,7 +508,19 @@ namespace com.al_arcade.cs ...@@ -508,7 +508,19 @@ namespace com.al_arcade.cs
_timerSlider.value = time / 30f; _timerSlider.value = time / 30f;
_timerFill.color = time > 4f ? _timerDefaultColor : SSColorPalette.Danger; _timerFill.color = time > 4f ? _timerDefaultColor : SSColorPalette.Danger;
} }
public void EnableScore(bool value)
{
_scoreText.enabled = value;
_scoreLbl.enabled = value;
if (value)
{
_scoreLbl.Text = "الوقت الموفر";
}
else
{
_scoreLbl.Text = "النقاط";
}
}
public void UpdateTimer(float time, bool pos) public void UpdateTimer(float time, bool pos)
{ {
isTweening = true; isTweening = true;
...@@ -548,6 +560,7 @@ namespace com.al_arcade.cs ...@@ -548,6 +560,7 @@ namespace com.al_arcade.cs
TickPoints(0); TickPoints(0);
SetStreak(0); SetStreak(0);
ClearOptions(); ClearOptions();
_scoreLbl.enabled = false;
} }
public void TickPoints(int count) public void TickPoints(int count)
......
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using com.al_arcade.shared; using com.al_arcade.shared;
...@@ -7,10 +7,11 @@ using EasyTransition; ...@@ -7,10 +7,11 @@ using EasyTransition;
using Unity.VisualScripting; using Unity.VisualScripting;
using UnityEngine; using UnityEngine;
// Spawns three games one after the other.
// Move to next game when the current game is won, if lost end the challenge and show results.
public class ChallengeManager : MonoBehaviour public class ChallengeManager : MonoBehaviour
{ {
// ✅ NEW: Singleton
public static ChallengeManager Instance { get; private set; }
[SerializeField] private List<string> gameSceneNames = new(); [SerializeField] private List<string> gameSceneNames = new();
[SerializeField] private TransitionSettings transitionSettings; [SerializeField] private TransitionSettings transitionSettings;
...@@ -19,9 +20,7 @@ public class ChallengeManager : MonoBehaviour ...@@ -19,9 +20,7 @@ public class ChallengeManager : MonoBehaviour
[SerializeField] private List<int> penaltiesPerGame = new() { 200, 150, 100 }; [SerializeField] private List<int> penaltiesPerGame = new() { 200, 150, 100 };
// Time saved for bonus if won the challenge
private int timeSaved = 0; private int timeSaved = 0;
private int currentGameIndex = 0; private int currentGameIndex = 0;
private DateTime startTime; private DateTime startTime;
...@@ -30,36 +29,53 @@ public class ChallengeManager : MonoBehaviour ...@@ -30,36 +29,53 @@ public class ChallengeManager : MonoBehaviour
[SerializeField] private ChallengeCanvas challengeCanvas; [SerializeField] private ChallengeCanvas challengeCanvas;
// ✅ NEW: public read-only accessor so any game can read time saved
public int TimeSaved => timeSaved;
// ✅ NEW: time bonus from the PREVIOUS game to give to the NEXT game
// this is the timeLeft value passed from OnGameCompleted
private float _lastGameTimeLeft = 0f;
public float LastGameTimeLeft => _lastGameTimeLeft;
void Awake() // ─── Singleton ────────────────────────────────────────────────────────
private void Awake()
{ {
// ✅ NEW: singleton guard — only one ChallengeManager ever exists
if (Instance != null && Instance != this)
{
Destroy(gameObject);
return;
}
Instance = this;
DontDestroyOnLoad(gameObject); DontDestroyOnLoad(gameObject);
} }
[ContextMenu("Start Challenge")] private void OnDestroy()
public void StartChallengeButton()
{ {
StartChallenge().Forget(); // ✅ NEW: clear singleton ref when destroyed
if (Instance == this)
Instance = null;
} }
// ─── Context Menu helpers ─────────────────────────────────────────────
[ContextMenu("Start Challenge")]
public void StartChallengeButton() => StartChallenge().Forget();
[ContextMenu("Load Next")] [ContextMenu("Load Next")]
public void LoadNextButton() public void LoadNextButton() => LoadNextGameAndListen().Forget();
{
LoadNextGameAndListen().Forget();
}
[ContextMenu("Fake win")] [ContextMenu("Fake win")]
public void Fakewin() public void Fakewin() => OnGameCompleted(true, 30, 100);
{
OnGameCompleted(true, 30, 100);
}
// ─── Challenge flow ───────────────────────────────────────────────────
public async UniTask StartChallenge() public async UniTask StartChallenge()
{ {
startTime = DateTime.UtcNow; startTime = DateTime.UtcNow;
currentGameIndex = 0; currentGameIndex = 0;
timeSaved = 0; timeSaved = 0;
// ✅ NEW: reset last game time left at start of fresh challenge
_lastGameTimeLeft = 0f;
currentGame = null; currentGame = null;
await LoadNextGameAndListen(); await LoadNextGameAndListen();
...@@ -77,14 +93,16 @@ public class ChallengeManager : MonoBehaviour ...@@ -77,14 +93,16 @@ public class ChallengeManager : MonoBehaviour
return; return;
} }
// Add time left to the saved time for the next game // ✅ NEW: store timeLeft so the next game can use it as a bonus
_lastGameTimeLeft = timeLeft;
// Add time left to total saved time
timeSaved += Mathf.RoundToInt(timeLeft); timeSaved += Mathf.RoundToInt(timeLeft);
currentGameIndex++; currentGameIndex++;
if (currentGameIndex >= gameSceneNames.Count) if (currentGameIndex >= gameSceneNames.Count)
{ {
var pointsEarnedTotal = winningPoints + (timeSaved * timeSavedBonusMultiplier); var pointsEarnedTotal = winningPoints + (timeSaved * timeSavedBonusMultiplier);
WonChallenge(timeSaved, pointsEarnedTotal).Forget(); WonChallenge(timeSaved, pointsEarnedTotal).Forget();
return; return;
} }
...@@ -94,17 +112,17 @@ public class ChallengeManager : MonoBehaviour ...@@ -94,17 +112,17 @@ public class ChallengeManager : MonoBehaviour
private async UniTask LoadNextGameAndListen() private async UniTask LoadNextGameAndListen()
{ {
TransitionManager.Instance().Transition(gameSceneNames[currentGameIndex], transitionSettings, 0); TransitionManager.Instance().Transition(
gameSceneNames[currentGameIndex], transitionSettings, 0);
// Wait until the old game is destroyed and the new game is loaded and ready await UniTask.WaitUntil(() =>
await UniTask.WaitUntil(() => baseGameManager == null || baseGameManager.IsDestroyed()); baseGameManager == null || baseGameManager.IsDestroyed());
await UniTask.WaitUntil(() => await UniTask.WaitUntil(() =>
{ {
currentGame = FindObjectsByType<MonoBehaviour>(FindObjectsSortMode.None) currentGame = FindObjectsByType<MonoBehaviour>(FindObjectsSortMode.None)
.OfType<IChallengeGame>() .OfType<IChallengeGame>()
.FirstOrDefault(); .FirstOrDefault();
return currentGame != null; return currentGame != null;
}); });
...@@ -112,6 +130,9 @@ public class ChallengeManager : MonoBehaviour ...@@ -112,6 +130,9 @@ public class ChallengeManager : MonoBehaviour
print("Current game: " + baseGameManager.name); print("Current game: " + baseGameManager.name);
await UniTask.WaitForSeconds(0.5f); await UniTask.WaitForSeconds(0.5f);
// ✅ NEW: pass the saved time bonus to the game before starting it
// each game type checks ChallengeManager.Instance.LastGameTimeLeft
// in their own BeginGameplay() — no casting needed here
baseGameManager.StartGame(); baseGameManager.StartGame();
currentGame.OnGameCompleted += OnGameCompleted; currentGame.OnGameCompleted += OnGameCompleted;
} }
...@@ -119,24 +140,22 @@ public class ChallengeManager : MonoBehaviour ...@@ -119,24 +140,22 @@ public class ChallengeManager : MonoBehaviour
private async UniTask LostChallenge() private async UniTask LostChallenge()
{ {
Debug.Log("Challenge failed."); Debug.Log("Challenge failed.");
// Show results, reset challenge, etc. challengeCanvas.ShowChallengeResult(
false, 0, penaltiesPerGame[currentGameIndex]);
challengeCanvas.ShowChallengeResult(false, 0, penaltiesPerGame[currentGameIndex]); await ChallengeService.Instance.AddChallenge(
await ChallengeService.Instance.AddChallenge(false, 0, -penaltiesPerGame[currentGameIndex], startTime, DateTime.UtcNow); false, 0, -penaltiesPerGame[currentGameIndex], startTime, DateTime.UtcNow);
} }
private async UniTask WonChallenge(int timeSaved, int pointsEarned) private async UniTask WonChallenge(int timeSaved, int pointsEarned)
{ {
Debug.Log("Challenge completed! Total time saved: " + timeSaved); Debug.Log("Challenge completed! Total time saved: " + timeSaved);
challengeCanvas.ShowChallengeResult(true, timeSaved, pointsEarned); challengeCanvas.ShowChallengeResult(true, timeSaved, pointsEarned);
await ChallengeService.Instance.AddChallenge(true, timeSaved, pointsEarned, startTime, DateTime.UtcNow); await ChallengeService.Instance.AddChallenge(
true, timeSaved, pointsEarned, startTime, DateTime.UtcNow);
} }
public void EndChallenge() public void EndChallenge()
{ {
Destroy(gameObject, 5); Destroy(gameObject, 5);
} }
} }
\ No newline at end of file
...@@ -167,10 +167,18 @@ namespace com.al_arcade.mcq ...@@ -167,10 +167,18 @@ namespace com.al_arcade.mcq
if (uiManager != null) if (uiManager != null)
{ {
uiManager.SetScore(0);
// ✅ NEW: reset the points dots to 0 // ✅ NEW: reset the points dots to 0
uiManager.TickPoints(0); uiManager.TickPoints(0);
uiManager.ShowGameUI(); uiManager.ShowGameUI();
uiManager.EnableScore(IsChallengeMode);
if (IsChallengeMode && ChallengeManager.Instance != null)
{
uiManager.SetScore(ChallengeManager.Instance.TimeSaved);
}
else
{
uiManager.SetScore(0);
}
} }
questionDisplay.transform.DOScale(Vector3.one, 0.5f) questionDisplay.transform.DOScale(Vector3.one, 0.5f)
...@@ -369,7 +377,6 @@ namespace com.al_arcade.mcq ...@@ -369,7 +377,6 @@ namespace com.al_arcade.mcq
if (uiManager != null) if (uiManager != null)
{ {
uiManager.SetScore(_score);
uiManager.SetStreak(_streak); uiManager.SetStreak(_streak);
// ✅ NEW: update the dots UI like CS // ✅ NEW: update the dots UI like CS
uiManager.TickPoints(_deltaChangeInSize); uiManager.TickPoints(_deltaChangeInSize);
......
...@@ -23,6 +23,7 @@ namespace com.al_arcade.mcq ...@@ -23,6 +23,7 @@ namespace com.al_arcade.mcq
[Header("Game UI")] [Header("Game UI")]
[SerializeField] private UniText _scoreText; [SerializeField] private UniText _scoreText;
[SerializeField] private UniText _scoreLbl;
[SerializeField] private UniText _streakText; [SerializeField] private UniText _streakText;
[SerializeField] private UniText _progressText; [SerializeField] private UniText _progressText;
[SerializeField] private UniText _loadingText; [SerializeField] private UniText _loadingText;
...@@ -115,6 +116,19 @@ namespace com.al_arcade.mcq ...@@ -115,6 +116,19 @@ namespace com.al_arcade.mcq
_scoreText.transform.DOPunchScale(Vector3.one * 0.2f, 0.3f, 6, 0.3f) _scoreText.transform.DOPunchScale(Vector3.one * 0.2f, 0.3f, 6, 0.3f)
.SetId("scorePunch"); .SetId("scorePunch");
} }
public void EnableScore(bool value)
{
_scoreText.enabled = value;
_scoreLbl.enabled = value;
if (value)
{
_scoreLbl.Text = "الوقت الموفر";
}
else
{
_scoreLbl.Text = "النقاط";
}
}
public void SetStreak(int streak) public void SetStreak(int streak)
{ {
...@@ -348,6 +362,7 @@ namespace com.al_arcade.mcq ...@@ -348,6 +362,7 @@ namespace com.al_arcade.mcq
_isTweening = false; _isTweening = false;
SetStreak(0); SetStreak(0);
_scoreLbl.enabled = false;
} }
// ─── Button functions ───────────────────────────────────────────────── // ─── Button functions ─────────────────────────────────────────────────
......
...@@ -102,7 +102,15 @@ namespace com.al_arcade.tf ...@@ -102,7 +102,15 @@ namespace com.al_arcade.tf
{ {
uiManager.ShowGameUI(); uiManager.ShowGameUI();
uiManager.SetProgress(0, stepsToWin); uiManager.SetProgress(0, stepsToWin);
uiManager.SetScore(0); uiManager.EnableScore(IsChallengeMode);
if (IsChallengeMode && ChallengeManager.Instance != null)
{
uiManager.SetScore(ChallengeManager.Instance.TimeSaved);
}
else
{
uiManager.SetScore(0);
}
} }
onGameStart?.Invoke(); onGameStart?.Invoke();
...@@ -226,7 +234,6 @@ namespace com.al_arcade.tf ...@@ -226,7 +234,6 @@ namespace com.al_arcade.tf
if (uiManager != null) if (uiManager != null)
{ {
uiManager.SetProgress(_progress, stepsToWin); uiManager.SetProgress(_progress, stepsToWin);
uiManager.SetScore(_score);
uiManager.SetStreak(_streak); uiManager.SetStreak(_streak);
} }
......
...@@ -15,7 +15,7 @@ namespace com.al_arcade.tf ...@@ -15,7 +15,7 @@ namespace com.al_arcade.tf
{ {
[SerializeField] private Canvas _canvas; [SerializeField] private Canvas _canvas;
[SerializeField] private CanvasGroup _gameUI, _loadingUI, _errorUI, _resultsUI; [SerializeField] private CanvasGroup _gameUI, _loadingUI, _errorUI, _resultsUI;
[SerializeField] private UniText _scoreText, _streakText; [SerializeField] private UniText _scoreText, _streakText , _scoreLbl;
[SerializeField] private ArabicTextMeshProUGUI _loadingText, _errorText; [SerializeField] private ArabicTextMeshProUGUI _loadingText, _errorText;
[SerializeField] private UniText _progressLabel; [SerializeField] private UniText _progressLabel;
[SerializeField] private UniText _resultTitle, _resultScore, _resultStats; [SerializeField] private UniText _resultTitle, _resultScore, _resultStats;
...@@ -338,7 +338,19 @@ namespace com.al_arcade.tf ...@@ -338,7 +338,19 @@ namespace com.al_arcade.tf
.DOPunchScale(Vector3.one * 0.12f, 0.2f, 4, 0.2f) .DOPunchScale(Vector3.one * 0.12f, 0.2f, 4, 0.2f)
.SetId("sp"); .SetId("sp");
} }
public void EnableScore(bool value)
{
_scoreText.enabled = value;
_scoreLbl.enabled = value;
if (value)
{
_scoreLbl.Text = "الوقت الموفر";
}
else
{
_scoreLbl.Text = "النقاط";
}
}
public void SetStreak(int s) public void SetStreak(int s)
{ {
if (_streakText == null) return; if (_streakText == null) return;
...@@ -415,6 +427,7 @@ namespace com.al_arcade.tf ...@@ -415,6 +427,7 @@ namespace com.al_arcade.tf
if (_loadingUI != null) _loadingUI.gameObject.SetActive(false); if (_loadingUI != null) _loadingUI.gameObject.SetActive(false);
if (_errorUI != null) _errorUI.gameObject.SetActive(false); if (_errorUI != null) _errorUI.gameObject.SetActive(false);
if (_resultsUI != null) _resultsUI.gameObject.SetActive(false); if (_resultsUI != null) _resultsUI.gameObject.SetActive(false);
// --- ADDED: Reset timer UI --- // --- ADDED: Reset timer UI ---
if (_timerSlider != null) if (_timerSlider != null)
_timerSlider.value = 1f; _timerSlider.value = 1f;
...@@ -423,6 +436,7 @@ namespace com.al_arcade.tf ...@@ -423,6 +436,7 @@ namespace com.al_arcade.tf
_timerFill.color = _timerDefaultColor; _timerFill.color = _timerDefaultColor;
_isTweening = false; _isTweening = false;
_scoreLbl.enabled = false;
} }
private GameObject MkPanel(Transform p, string n) private GameObject MkPanel(Transform p, string n)
......
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