Пример #1
0
        public static bool DoTimeControlsGUI(Rect timerRect)
        {
            TickManager tickManager = Find.TickManager;

            GUI.BeginGroup(timerRect);
            Vector2 timeButSize  = TimeControls.TimeButSize;
            float   x            = timeButSize.x;
            Vector2 timeButSize2 = TimeControls.TimeButSize;
            Rect    rect         = new Rect(0f, 0f, x, timeButSize2.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[(uint)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);
                }

                //}
            }
            return(false);
        }
        public static bool DoTimeControlsGUI(Rect timerRect)
        {
            TickManager tickManager = Find.TickManager;

            GUI.BeginGroup(timerRect);
            Rect rect = new Rect(0.0f, 0.0f, TimeControls.TimeButSize.x, TimeControls.TimeButSize.y);

            for (int index = 0; index < TimeControls.CachedTimeSpeedValues.Length; ++index)
            {
                TimeSpeed timeSpeed = TimeControls.CachedTimeSpeedValues[index];
                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, (Texture)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)
            {
                return(false);
            }
            if (KeyBindingDefOf.TogglePause.KeyDownEvent)
            {
                Find.TickManager.TogglePaused();
                TimeControls.PlaySoundOf(Find.TickManager.CurTimeSpeed);
                PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.Pause, KnowledgeAmount.SpecificInteraction);
                Event.current.Use();
            }
            if (KeyBindingDefOf.TimeSpeedNormal.KeyDownEvent)
            {
                Find.TickManager.CurTimeSpeed = TimeSpeed.Normal;
                TimeControls.PlaySoundOf(Find.TickManager.CurTimeSpeed);
                PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.TimeControls, KnowledgeAmount.SpecificInteraction);
                Event.current.Use();
            }
            if (KeyBindingDefOf.TimeSpeedFast.KeyDownEvent)
            {
                Find.TickManager.CurTimeSpeed = TimeSpeed.Fast;
                TimeControls.PlaySoundOf(Find.TickManager.CurTimeSpeed);
                PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.TimeControls, KnowledgeAmount.SpecificInteraction);
                Event.current.Use();
            }
            if (KeyBindingDefOf.TimeSpeedSuperfast.KeyDownEvent)
            {
                Find.TickManager.CurTimeSpeed = TimeSpeed.Superfast;
                TimeControls.PlaySoundOf(Find.TickManager.CurTimeSpeed);
                PlayerKnowledgeDatabase.KnowledgeDemonstrated(ConceptDefOf.TimeControls, KnowledgeAmount.SpecificInteraction);
                Event.current.Use();
            }

            //Removed to Allow Speed 4 Without Dev Mode.
            //if (!Prefs.DevMode)
            //    return false;
            if (KeyBindingDefOf.TimeSpeedUltrafast.KeyDownEvent)
            {
                Find.TickManager.CurTimeSpeed = TimeSpeed.Ultrafast;
                TimeControls.PlaySoundOf(Find.TickManager.CurTimeSpeed);
                Event.current.Use();
            }
            if (!KeyBindingDefOf.TickOnce.KeyDownEvent || tickManager.CurTimeSpeed != TimeSpeed.Paused)
            {
                return(false);
            }
            tickManager.DoSingleTick();
            SoundStarter.PlayOneShotOnCamera(SoundDef.Named(TimeControls.SpeedSounds[0]), (Map)null);

            return(false);
        }