Commit 0652cde1 authored by saad's avatar saad

add new ui in challenge mode

parent a5ccaa97
......@@ -196,6 +196,51 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::LoginPageAnimation
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
GameObject:
m_ObjectHideFlags: 0
......@@ -645,3 +690,4 @@ SceneRoots:
- {fileID: 1628372281}
- {fileID: 1093642342}
- {fileID: 2142479138}
- {fileID: 697923398}
This diff is collapsed.
This diff is collapsed.
......@@ -149,8 +149,16 @@ namespace com.al_arcade.cs
if (uiManager != null)
{
uiManager.ShowGameUI();
uiManager.SetScore(0);
uiManager.SetProgress(0, _questions.Length);
uiManager.EnableScore(IsChallengeMode);
if (IsChallengeMode && ChallengeManager.Instance != null)
{
uiManager.SetScore(ChallengeManager.Instance.TimeSaved);
}
else
{
uiManager.SetScore(0);
}
}
onGameStart?.Invoke();
......@@ -314,7 +322,6 @@ namespace com.al_arcade.cs
if (uiManager != null)
{
uiManager.ShowFeedback($"ممتاز! {points}+", true);
uiManager.SetScore(_score);
uiManager.SetStreak(_streak);
}
......
......@@ -20,7 +20,7 @@ namespace com.al_arcade.cs
[SerializeField] protected CanvasGroup _optionsPanel, _feedbackGroup;
[SerializeField] protected UniText _progressText;
[SerializeField] protected UniText _hintText, _scoreText, _streakText;
[SerializeField] protected UniText _hintText, _scoreText, _streakText , _scoreLbl;
[SerializeField] protected UniText _feedbackText;
[SerializeField] protected Image _feedbackBg, _timerFill;
......@@ -508,7 +508,19 @@ namespace com.al_arcade.cs
_timerSlider.value = time / 30f;
_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)
{
isTweening = true;
......@@ -548,6 +560,7 @@ namespace com.al_arcade.cs
TickPoints(0);
SetStreak(0);
ClearOptions();
_scoreLbl.enabled = false;
}
public void TickPoints(int count)
......
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using com.al_arcade.shared;
......@@ -7,10 +7,11 @@ using EasyTransition;
using Unity.VisualScripting;
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
{
// ✅ NEW: Singleton
public static ChallengeManager Instance { get; private set; }
[SerializeField] private List<string> gameSceneNames = new();
[SerializeField] private TransitionSettings transitionSettings;
......@@ -19,9 +20,7 @@ public class ChallengeManager : MonoBehaviour
[SerializeField] private List<int> penaltiesPerGame = new() { 200, 150, 100 };
// Time saved for bonus if won the challenge
private int timeSaved = 0;
private int currentGameIndex = 0;
private DateTime startTime;
......@@ -30,36 +29,53 @@ public class ChallengeManager : MonoBehaviour
[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);
}
[ContextMenu("Start Challenge")]
public void StartChallengeButton()
private void OnDestroy()
{
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")]
public void LoadNextButton()
{
LoadNextGameAndListen().Forget();
}
public void LoadNextButton() => LoadNextGameAndListen().Forget();
[ContextMenu("Fake win")]
public void Fakewin()
{
OnGameCompleted(true, 30, 100);
}
public void Fakewin() => OnGameCompleted(true, 30, 100);
// ─── Challenge flow ───────────────────────────────────────────────────
public async UniTask StartChallenge()
{
startTime = DateTime.UtcNow;
currentGameIndex = 0;
timeSaved = 0;
// ✅ NEW: reset last game time left at start of fresh challenge
_lastGameTimeLeft = 0f;
currentGame = null;
await LoadNextGameAndListen();
......@@ -77,14 +93,16 @@ public class ChallengeManager : MonoBehaviour
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);
currentGameIndex++;
if (currentGameIndex >= gameSceneNames.Count)
{
var pointsEarnedTotal = winningPoints + (timeSaved * timeSavedBonusMultiplier);
WonChallenge(timeSaved, pointsEarnedTotal).Forget();
return;
}
......@@ -94,17 +112,17 @@ public class ChallengeManager : MonoBehaviour
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(() => baseGameManager == null || baseGameManager.IsDestroyed());
await UniTask.WaitUntil(() =>
baseGameManager == null || baseGameManager.IsDestroyed());
await UniTask.WaitUntil(() =>
{
currentGame = FindObjectsByType<MonoBehaviour>(FindObjectsSortMode.None)
.OfType<IChallengeGame>()
.FirstOrDefault();
return currentGame != null;
});
......@@ -112,6 +130,9 @@ public class ChallengeManager : MonoBehaviour
print("Current game: " + baseGameManager.name);
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();
currentGame.OnGameCompleted += OnGameCompleted;
}
......@@ -119,24 +140,22 @@ public class ChallengeManager : MonoBehaviour
private async UniTask LostChallenge()
{
Debug.Log("Challenge failed.");
// Show results, reset challenge, etc.
challengeCanvas.ShowChallengeResult(false, 0, penaltiesPerGame[currentGameIndex]);
await ChallengeService.Instance.AddChallenge(false, 0, -penaltiesPerGame[currentGameIndex], startTime, DateTime.UtcNow);
challengeCanvas.ShowChallengeResult(
false, 0, penaltiesPerGame[currentGameIndex]);
await ChallengeService.Instance.AddChallenge(
false, 0, -penaltiesPerGame[currentGameIndex], startTime, DateTime.UtcNow);
}
private async UniTask WonChallenge(int timeSaved, int pointsEarned)
{
Debug.Log("Challenge completed! Total time saved: " + timeSaved);
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()
{
Destroy(gameObject, 5);
}
}
\ No newline at end of file
......@@ -167,10 +167,18 @@ namespace com.al_arcade.mcq
if (uiManager != null)
{
uiManager.SetScore(0);
// ✅ NEW: reset the points dots to 0
uiManager.TickPoints(0);
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)
......@@ -369,7 +377,6 @@ namespace com.al_arcade.mcq
if (uiManager != null)
{
uiManager.SetScore(_score);
uiManager.SetStreak(_streak);
// ✅ NEW: update the dots UI like CS
uiManager.TickPoints(_deltaChangeInSize);
......
......@@ -23,6 +23,7 @@ namespace com.al_arcade.mcq
[Header("Game UI")]
[SerializeField] private UniText _scoreText;
[SerializeField] private UniText _scoreLbl;
[SerializeField] private UniText _streakText;
[SerializeField] private UniText _progressText;
[SerializeField] private UniText _loadingText;
......@@ -115,6 +116,19 @@ namespace com.al_arcade.mcq
_scoreText.transform.DOPunchScale(Vector3.one * 0.2f, 0.3f, 6, 0.3f)
.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)
{
......@@ -348,6 +362,7 @@ namespace com.al_arcade.mcq
_isTweening = false;
SetStreak(0);
_scoreLbl.enabled = false;
}
// ─── Button functions ─────────────────────────────────────────────────
......
......@@ -102,7 +102,15 @@ namespace com.al_arcade.tf
{
uiManager.ShowGameUI();
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();
......@@ -226,7 +234,6 @@ namespace com.al_arcade.tf
if (uiManager != null)
{
uiManager.SetProgress(_progress, stepsToWin);
uiManager.SetScore(_score);
uiManager.SetStreak(_streak);
}
......
......@@ -15,7 +15,7 @@ namespace com.al_arcade.tf
{
[SerializeField] private Canvas _canvas;
[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 UniText _progressLabel;
[SerializeField] private UniText _resultTitle, _resultScore, _resultStats;
......@@ -338,7 +338,19 @@ namespace com.al_arcade.tf
.DOPunchScale(Vector3.one * 0.12f, 0.2f, 4, 0.2f)
.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)
{
if (_streakText == null) return;
......@@ -415,6 +427,7 @@ namespace com.al_arcade.tf
if (_loadingUI != null) _loadingUI.gameObject.SetActive(false);
if (_errorUI != null) _errorUI.gameObject.SetActive(false);
if (_resultsUI != null) _resultsUI.gameObject.SetActive(false);
// --- ADDED: Reset timer UI ---
if (_timerSlider != null)
_timerSlider.value = 1f;
......@@ -423,6 +436,7 @@ namespace com.al_arcade.tf
_timerFill.color = _timerDefaultColor;
_isTweening = false;
_scoreLbl.enabled = false;
}
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