public static float TimePerTick(this ITickable tickable, TimeSpeed speed) { if (tickable.ActualRateMultiplier(speed) == 0f) { return(0f); } return(1f / tickable.ActualRateMultiplier(speed)); }
static void Postfix(ITickable __state, Rect timerRect) { if (__state == null) { return; } Rect rect = new Rect(timerRect.x, timerRect.y, TimeControls.TimeButSize.x, TimeControls.TimeButSize.y); float normalSpeed = __state.ActualRateMultiplier(TimeSpeed.Normal); float fastSpeed = __state.ActualRateMultiplier(TimeSpeed.Fast); if (normalSpeed == 0f) // Completely paused { Widgets.DrawLineHorizontal(rect.x + rect.width, rect.y + rect.height / 2f, rect.width * 3f); } else if (normalSpeed == fastSpeed) // Slowed down { Widgets.DrawLineHorizontal(rect.x + rect.width * 2f, rect.y + rect.height / 2f, rect.width * 2f); } TimeSpeed newSpeed = Find.TickManager.CurTimeSpeed; Find.TickManager.CurTimeSpeed = savedSpeed; if (prevSpeed == newSpeed) { return; } if (Multiplayer.IsReplay) { TickPatch.replayTimeSpeed = newSpeed; } // Prevent multiple players changing the speed too quickly if (keyPressed && Time.realtimeSinceStartup - MultiplayerWorldComp.lastSpeedChange < 0.4f) { return; } TimeControl.SendTimeChange(__state, newSpeed); }
private static float ReplayMultiplier() { if (!Multiplayer.IsReplay || Skipping) { return(1f); } if (replayTimeSpeed == TimeSpeed.Paused) { return(0f); } ITickable tickable = CurrentTickable(); if (tickable.TimePerTick(tickable.TimeSpeed) == 0f) { return(1 / 100f); // So paused sections of the timeline are skipped through } return(tickable.ActualRateMultiplier(tickable.TimeSpeed) / tickable.ActualRateMultiplier(replayTimeSpeed)); }
public static void TimeControlButton(Rect button, Color bgColor, ITickable tickable) { int speed = (int)tickable.TimeSpeed; if (tickable.ActualRateMultiplier(TimeSpeed.Normal) == 0f) { speed = 0; } Widgets.DrawRectFast(button, bgColor); if (Widgets.ButtonImage(button, TexButton.SpeedButtonTextures[speed])) { int dir = Event.current.button == 0 ? 1 : -1; SendTimeChange(tickable, (TimeSpeed)GenMath.PositiveMod(speed + dir, (int)TimeSpeed.Ultrafast)); Event.current.Use(); } }
static void DrawButtons() { if (Multiplayer.Client == null) { return; } ColonistBar bar = Find.ColonistBar; if (bar.Entries.Count == 0) { return; } int curGroup = -1; foreach (var entry in bar.Entries) { if (curGroup == entry.group) { continue; } ITickable entryTickable = entry.map?.AsyncTime(); if (entryTickable == null) { entryTickable = Multiplayer.WorldComp; } Rect groupBar = bar.drawer.GroupFrameRect(entry.group); float drawXPos = groupBar.x; Color bgColor = (entryTickable.ActualRateMultiplier(TimeSpeed.Normal) == 0f) ? pauseBgColor : normalBgColor; if (Multiplayer.GameComp.asyncTime) { Rect button = new Rect(drawXPos, groupBar.yMax, btnWidth, btnHeight); if (entry.map != null) { TimeControl.TimeControlButton(button, bgColor, entryTickable); drawXPos += TimeControls.TimeButSize.x; } else if (entryTickable.ActualRateMultiplier(TimeSpeed.Normal) == 0f) { TimeControl.TimeIndicateBlockingPause(button, bgColor); drawXPos += TimeControls.TimeButSize.x; } } else if (entryTickable.TickRateMultiplier(TimeSpeed.Normal) == 0f) { Rect button = new Rect(drawXPos, groupBar.yMax, btnWidth, btnHeight); TimeControl.TimeIndicateBlockingPause(button, bgColor); drawXPos += TimeControls.TimeButSize.x; } List <FloatMenuOption> options = GetBlockingWindowOptions(entry, entryTickable); if (!options.NullOrEmpty()) { DrawWindowShortcuts(new Rect(drawXPos, groupBar.yMax, 70, btnHeight), bgColor, options); } curGroup = entry.group; } }