public static void DoTimespeedControls(float leftX, float width, ref float curBaseY) { leftX += Mathf.Max(0f, width - 150f); width = Mathf.Min(width, 150f); float y = TimeControls.TimeButSize.y; Rect timerRect = new Rect(leftX + 16f, curBaseY - y, width, y); TimeControls.DoTimeControlsGUI(timerRect); curBaseY -= timerRect.height; }
public static void DoTimeControlsGUI(Rect timerRect) { TickManager tickManager = Find.TickManager; GUI.BeginGroup(timerRect); Rect rect = new Rect(0f, 0f, TimeControls.TimeButSize.x, TimeControls.TimeButSize.y); for (int i = 0; i < TimeControls.CachedTimeSpeedValues.Length; i++) { TimeSpeed timeSpeed = TimeControls.CachedTimeSpeedValues[i]; if (timeSpeed != TimeSpeed.Ultrafast) { if (Widgets.ButtonImage(rect, TexButton.SpeedButtonTextures[(int)timeSpeed])) { if (timeSpeed == TimeSpeed.Paused) { tickManager.TogglePaused(); PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.Pause, KnowledgeAmount.SpecificInteraction); } else { tickManager.CurTimeSpeed = timeSpeed; PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.TimeControls, KnowledgeAmount.SpecificInteraction); } TimeControls.PlaySoundOf(tickManager.CurTimeSpeed); } if (tickManager.CurTimeSpeed == timeSpeed) { GUI.DrawTexture(rect, TexUI.HighlightTex); } rect.x += rect.width; } } if (Find.TickManager.slower.ForcedNormalSpeed) { Widgets.DrawLineHorizontal(rect.width * 2f, rect.height / 2f, rect.width * 2f); } GUI.EndGroup(); GenUI.AbsorbClicksInRect(timerRect); UIHighlighter.HighlightOpportunity(timerRect, "TimeControls"); if (Event.current.type == EventType.KeyDown) { if (KeyBindingDefOf.TogglePause.KeyDownEvent) { Find.TickManager.TogglePaused(); TimeControls.PlaySoundOf(Find.TickManager.CurTimeSpeed); PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.Pause, KnowledgeAmount.SpecificInteraction); Event.current.Use(); } if (KeyBindingDefOf.TimeSpeed_Normal.KeyDownEvent) { Find.TickManager.CurTimeSpeed = TimeSpeed.Normal; TimeControls.PlaySoundOf(Find.TickManager.CurTimeSpeed); PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.TimeControls, KnowledgeAmount.SpecificInteraction); Event.current.Use(); } if (KeyBindingDefOf.TimeSpeed_Fast.KeyDownEvent) { Find.TickManager.CurTimeSpeed = TimeSpeed.Fast; TimeControls.PlaySoundOf(Find.TickManager.CurTimeSpeed); PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.TimeControls, KnowledgeAmount.SpecificInteraction); Event.current.Use(); } if (KeyBindingDefOf.TimeSpeed_Superfast.KeyDownEvent) { Find.TickManager.CurTimeSpeed = TimeSpeed.Superfast; TimeControls.PlaySoundOf(Find.TickManager.CurTimeSpeed); PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.TimeControls, KnowledgeAmount.SpecificInteraction); Event.current.Use(); } if (Prefs.DevMode) { if (KeyBindingDefOf.TimeSpeed_Ultrafast.KeyDownEvent) { Find.TickManager.CurTimeSpeed = TimeSpeed.Ultrafast; TimeControls.PlaySoundOf(Find.TickManager.CurTimeSpeed); Event.current.Use(); } if (KeyBindingDefOf.Dev_TickOnce.KeyDownEvent && tickManager.CurTimeSpeed == TimeSpeed.Paused) { tickManager.DoSingleTick(); SoundDefOf.Clock_Stop.PlayOneShotOnCamera(null); } } } }