Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animate red flash for blocking pause dialogs #430

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion Source/Client/AsyncTime/TimeControlUI.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using HarmonyLib;
Expand Down Expand Up @@ -283,6 +283,10 @@ public static class ColonistBarTimeControl
public static float btnWidth = TimeControls.TimeButSize.x;
public static float btnHeight = TimeControls.TimeButSize.y;

private static Dictionary<Vector2, float> flashDict = new Dictionary<Vector2, float>();
private static float flashInterval = 6f;
private static Color flashColor = Color.red;

static void Prefix(ref bool __state)
{
if (Event.current.type is EventType.MouseDown or EventType.MouseUp)
Expand Down Expand Up @@ -316,6 +320,7 @@ static void DrawButtons()
Rect groupBar = bar.drawer.GroupFrameRect(entry.group);
float drawXPos = groupBar.x;
Color bgColor = (entryTickable.ActualRateMultiplier(TimeSpeed.Normal) == 0f) ? pauseBgColor : normalBgColor;
Vector2 flashPos = new Vector2(drawXPos + btnWidth / 2, groupBar.yMax + btnHeight / 2);

if (Multiplayer.GameComp.asyncTime)
{
Expand All @@ -337,6 +342,24 @@ static void DrawButtons()
Rect button = new Rect(drawXPos, groupBar.yMax, btnWidth, btnHeight);
MpTimeControls.TimeIndicateBlockingPause(button, bgColor);
drawXPos += TimeControls.TimeButSize.x;

float pauseTime = flashDict.GetValueOrDefault(flashPos);
if (flashDict.ContainsKey(flashPos))
{
// Draw flash for ongoing blocking pause
DrawPauseFlash(flashPos);
}
else
{
// There is a new blocking pause
flashDict.Add(flashPos, Time.time);
}
}

if (entryTickable.ActualRateMultiplier(TimeSpeed.Normal) != 0f && flashDict.ContainsKey(flashPos))
{
// No longer any blocking pauses, stop flashing here
flashDict.Remove(flashPos);
}

List<FloatMenuOption> options = GetBlockingWindowOptions(entry, entryTickable);
Expand Down Expand Up @@ -424,6 +447,18 @@ static void SwitchToMapOrWorld(Map map)
Current.Game.CurrentMap = map;
}
}

static void DrawPauseFlash(Vector2 pos)
{
float pauseTime = flashDict.GetValueOrDefault(pos);
float pauseDuration = Time.time - pauseTime;

// Only flash at flashInterval from the time the blocking pause began
if (pauseDuration > 0f && pauseDuration % flashInterval < 1f)
{
GenUI.DrawFlash(pos.x, pos.y, UI.screenWidth * 0.6f, Pulser.PulseBrightness(1f, 1f, pauseDuration) * 0.4f, flashColor);
}
}
}

[HarmonyPatch(typeof(MainButtonWorker), nameof(MainButtonWorker.DoButton))]
Expand Down
Loading