Example #1
0
        static void Prefix(MainButtonWorker __instance, Rect rect, ref Rect?__state)
        {
            if (Multiplayer.Client == null)
            {
                return;
            }
            if (__instance.def != MainButtonDefOf.World)
            {
                return;
            }
            if (__instance.Disabled)
            {
                return;
            }
            if (Find.CurrentMap == null)
            {
                return;
            }
            if (!Multiplayer.GameComp.asyncTime)
            {
                return;
            }

            Rect button = new Rect(rect.xMax - TimeControls.TimeButSize.x - 5f, rect.y + (rect.height - TimeControls.TimeButSize.y) / 2f, TimeControls.TimeButSize.x, TimeControls.TimeButSize.y);

            __state = button;

            if (Event.current.type == EventType.MouseDown || Event.current.type == EventType.MouseUp)
            {
                TimeControl.TimeControlButton(__state.Value, ColonistBarTimeControl.normalBgColor, Multiplayer.WorldComp);
            }
        }
Example #2
0
        static void Postfix(MainButtonWorker __instance, Rect?__state)
        {
            if (__state == null)
            {
                return;
            }

            if (Event.current.type == EventType.Repaint)
            {
                TimeControl.TimeControlButton(__state.Value, ColonistBarTimeControl.normalBgColor, Multiplayer.WorldComp);
            }
        }
Example #3
0
        static void Postfix(ITickable __state, Rect timerRect)
        {
            if (__state == null)
            {
                return;
            }

            Rect  btn         = 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(btn.x + btn.width, btn.y + btn.height / 2f, btn.width * 3f);
            }
            else if (normalSpeed == fastSpeed)  // Slowed down
            {
                Widgets.DrawLineHorizontal(btn.x + btn.width * 2f, btn.y + btn.height / 2f, btn.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);
        }
Example #4
0
        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;
            }
        }