UI update 02
This commit is contained in:
@@ -16,6 +16,7 @@ public class DailyTaskSaveData
|
||||
public string dateKey;
|
||||
public int dateStamp;
|
||||
public int refreshUsedCount;
|
||||
public bool loginReportedToday;
|
||||
public int trustedDateStamp;
|
||||
public int lastRefreshDateStamp;
|
||||
public long lastRefreshLocalTicks;
|
||||
|
||||
@@ -17,6 +17,8 @@ public sealed class DailyTaskService : MonoBehaviour
|
||||
}
|
||||
|
||||
private const float OnlineDurationFlushStepSeconds = 5f;
|
||||
private const string GameplaySceneName = "gameplay_gameplay";
|
||||
private const string MainUiSceneName = "UI_UI";
|
||||
|
||||
private readonly Queue<DailyTaskEventData> pendingEvents = new Queue<DailyTaskEventData>();
|
||||
private readonly Dictionary<string, userTasksPool.TaskDefinition> definitionById = new Dictionary<string, userTasksPool.TaskDefinition>(StringComparer.Ordinal);
|
||||
@@ -28,6 +30,8 @@ public sealed class DailyTaskService : MonoBehaviour
|
||||
private bool initialized;
|
||||
private bool appFocused = true;
|
||||
private float pendingOnlineDurationSeconds;
|
||||
private bool isGameplayDurationTracking;
|
||||
private float gameplayDurationRealtimeStart;
|
||||
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
|
||||
private static void Bootstrap()
|
||||
@@ -90,6 +94,7 @@ public sealed class DailyTaskService : MonoBehaviour
|
||||
if (!hasFocus)
|
||||
{
|
||||
FlushPendingOnlineDuration();
|
||||
FlushGameplayDuration();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,12 +103,14 @@ public sealed class DailyTaskService : MonoBehaviour
|
||||
if (pauseStatus)
|
||||
{
|
||||
FlushPendingOnlineDuration();
|
||||
FlushGameplayDuration();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnApplicationQuit()
|
||||
{
|
||||
FlushPendingOnlineDuration();
|
||||
FlushGameplayDuration();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
@@ -111,6 +118,7 @@ public sealed class DailyTaskService : MonoBehaviour
|
||||
if (Instance == this)
|
||||
{
|
||||
FlushPendingOnlineDuration();
|
||||
FlushGameplayDuration();
|
||||
SceneManager.sceneLoaded -= OnSceneLoaded;
|
||||
}
|
||||
}
|
||||
@@ -327,9 +335,18 @@ public sealed class DailyTaskService : MonoBehaviour
|
||||
|
||||
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
||||
{
|
||||
if (string.Equals(scene.name, "UI_UI", StringComparison.OrdinalIgnoreCase))
|
||||
if (string.Equals(scene.name, MainUiSceneName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
DailyTaskEventHub.ReportLogin();
|
||||
TryReportDailyLogin();
|
||||
}
|
||||
|
||||
if (string.Equals(scene.name, GameplaySceneName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
BeginGameplayDurationTracking();
|
||||
}
|
||||
else
|
||||
{
|
||||
FlushGameplayDuration();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -382,6 +399,7 @@ public sealed class DailyTaskService : MonoBehaviour
|
||||
saveData.dateKey = todayKey;
|
||||
saveData.dateStamp = effectiveTodayStamp;
|
||||
saveData.refreshUsedCount = 0;
|
||||
saveData.loginReportedToday = false;
|
||||
saveData.accumulatedProgress = new List<DailyTaskAccumulatedProgress>();
|
||||
saveData.uniqueIntProgress = new List<DailyTaskUniqueIntProgress>();
|
||||
GenerateDailyTasks();
|
||||
@@ -524,6 +542,57 @@ public sealed class DailyTaskService : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private void TryReportDailyLogin()
|
||||
{
|
||||
EnsureTodayTasks();
|
||||
if (saveData == null || saveData.loginReportedToday)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
saveData.loginReportedToday = true;
|
||||
ReportEvent(new DailyTaskEventData
|
||||
{
|
||||
taskType = userTasksPool.TaskType.Login,
|
||||
amount = 1f
|
||||
});
|
||||
}
|
||||
|
||||
private void BeginGameplayDurationTracking()
|
||||
{
|
||||
if (isGameplayDurationTracking)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
isGameplayDurationTracking = true;
|
||||
gameplayDurationRealtimeStart = Time.realtimeSinceStartup;
|
||||
}
|
||||
|
||||
private void FlushGameplayDuration()
|
||||
{
|
||||
if (!isGameplayDurationTracking)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float now = Time.realtimeSinceStartup;
|
||||
float elapsed = Mathf.Max(0f, now - gameplayDurationRealtimeStart);
|
||||
isGameplayDurationTracking = false;
|
||||
gameplayDurationRealtimeStart = 0f;
|
||||
|
||||
if (elapsed <= 0f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ReportEvent(new DailyTaskEventData
|
||||
{
|
||||
taskType = userTasksPool.TaskType.GameDuration,
|
||||
amount = elapsed
|
||||
});
|
||||
}
|
||||
|
||||
private bool ApplyEventToTrackedProgress(DailyTaskEventData eventData)
|
||||
{
|
||||
switch (eventData.taskType)
|
||||
|
||||
@@ -284,7 +284,7 @@ public class dailyTaskManager : MonoBehaviour
|
||||
{
|
||||
if (taskService.GetRemainingRefreshCount() <= 0)
|
||||
{
|
||||
gNotice.warning.display(LocalizationService.Get("daily.refresh_limit_reached", "已达到今日刷新上限"));
|
||||
gNotice.warning.display("今日刷新次数已用尽");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -295,6 +295,7 @@ public class dailyTaskManager : MonoBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
gNotice.message.display($"刷新成功,剩余刷新次数:{taskService.GetRemainingRefreshCount()}");
|
||||
RefreshTaskUi();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user