Example #1
0
        static void DrawTimelineWindow()
        {
            Rect rect = new Rect(0, 30f, UI.screenWidth - TimelineMargin * 2, TimelineHeight);

            Widgets.DrawBoxSolid(rect, new Color(0.6f, 0.6f, 0.6f, 0.8f));

            int timerStart = Multiplayer.session.replayTimerStart >= 0 ?
                             Multiplayer.session.replayTimerStart : Multiplayer.session.dataSnapshot.cachedAtTime;

            int timerEnd = Multiplayer.session.replayTimerEnd >= 0 ?
                           Multiplayer.session.replayTimerEnd : TickPatch.tickUntil;

            int timeLen = timerEnd - timerStart;

            MpUI.DrawRotatedLine(new Vector2(rect.xMin + 2f, rect.center.y), TimelineHeight, 20f, 90f, Color.white);
            MpUI.DrawRotatedLine(new Vector2(rect.xMax - 2f, rect.center.y), TimelineHeight, 20f, 90f, Color.white);

            float progress  = (TickPatch.Timer - timerStart) / (float)timeLen;
            float progressX = rect.xMin + progress * rect.width;

            MpUI.DrawRotatedLine(new Vector2((int)progressX, rect.center.y), TimelineHeight, 20f, 90f, Color.green);

            float       mouseX     = Event.current.mousePosition.x;
            ReplayEvent mouseEvent = null;

            foreach (var ev in Multiplayer.session.events)
            {
                if (ev.time < timerStart || ev.time > timerEnd)
                {
                    continue;
                }

                var pointX = rect.xMin + (ev.time - timerStart) / (float)timeLen * rect.width;

                //GUI.DrawTexture(new Rect(pointX - 12f, rect.yMin - 24f, 24f, 24f), texture);
                MpUI.DrawRotatedLine(new Vector2(pointX, rect.center.y), TimelineHeight, 20f, 90f, ev.color);

                if (Mouse.IsOver(rect) && Math.Abs(mouseX - pointX) < 10)
                {
                    mouseX     = pointX;
                    mouseEvent = ev;
                }
            }

            if (Mouse.IsOver(rect))
            {
                float mouseProgress = (mouseX - rect.xMin) / rect.width;
                int   mouseTimer    = timerStart + (int)(timeLen * mouseProgress);

                MpUI.DrawRotatedLine(new Vector2(mouseX, rect.center.y), TimelineHeight, 15f, 90f, Color.blue);

                if (Event.current.type == EventType.MouseUp)
                {
                    TickPatch.SetSimulation(mouseTimer, canESC: true);

                    if (mouseTimer < TickPatch.Timer)
                    {
                        ClientJoiningState.ReloadGame(Multiplayer.session.dataSnapshot.mapData.Keys.ToList(), false, Multiplayer.GameComp.asyncTime);
                    }
                }

                if (Event.current.isMouse)
                {
                    Event.current.Use();
                }

                string tooltip = $"Tick {mouseTimer}";
                if (mouseEvent != null)
                {
                    tooltip = $"{mouseEvent.name}\n{tooltip}";
                }

                const int TickTipId = 215462143;

                TooltipHandler.TipRegion(rect, new TipSignal(tooltip, TickTipId));
                // Remove delay between the mouseover and showing
                if (TooltipHandler.activeTips.TryGetValue(TickTipId, out ActiveTip tip))
                {
                    tip.firstTriggerTime = 0;
                }
            }

            if (TickPatch.Simulating)
            {
                float pct         = (TickPatch.simulating.target.Value - timerStart) / (float)timeLen;
                float simulateToX = rect.xMin + rect.width * pct;
                MpUI.DrawRotatedLine(new Vector2(simulateToX, rect.center.y), TimelineHeight, 15f, 90f, Color.yellow);
            }
        }
Example #2
0
        public void HandleWorldData(ByteReader data)
        {
            connection.State = ConnectionStateEnum.ClientPlaying;
            Log.Message("Game data size: " + data.Length);

            int factionId = data.ReadInt32();

            Multiplayer.session.myFactionId = factionId;

            int tickUntil = data.ReadInt32();

            var dataSnapshot = new GameDataSnapshot();

            byte[] worldData = GZipStream.UncompressBuffer(data.ReadPrefixedBytes());
            dataSnapshot.gameData = worldData;

            byte[] semiPersistentData = GZipStream.UncompressBuffer(data.ReadPrefixedBytes());
            dataSnapshot.semiPersistentData = semiPersistentData;

            List <int> mapsToLoad = new List <int>();

            int mapCmdsCount = data.ReadInt32();

            for (int i = 0; i < mapCmdsCount; i++)
            {
                int mapId = data.ReadInt32();

                int mapCmdsLen = data.ReadInt32();
                List <ScheduledCommand> mapCmds = new List <ScheduledCommand>(mapCmdsLen);
                for (int j = 0; j < mapCmdsLen; j++)
                {
                    mapCmds.Add(ScheduledCommand.Deserialize(new ByteReader(data.ReadPrefixedBytes())));
                }

                dataSnapshot.mapCmds[mapId] = mapCmds;
            }

            int mapDataCount = data.ReadInt32();

            for (int i = 0; i < mapDataCount; i++)
            {
                int    mapId      = data.ReadInt32();
                byte[] rawMapData = data.ReadPrefixedBytes();

                byte[] mapData = GZipStream.UncompressBuffer(rawMapData);
                dataSnapshot.mapData[mapId] = mapData;
                mapsToLoad.Add(mapId);
            }

            Session.dataSnapshot           = dataSnapshot;
            Multiplayer.session.localCmdId = data.ReadInt32();
            TickPatch.shouldPause          = data.ReadBool();
            TickPatch.tickUntil            = tickUntil;

            TickPatch.SetSimulation(
                toTickUntil: true,
                onFinish: () => Multiplayer.Client.Send(Packets.Client_WorldReady),
                cancelButtonKey: "Quit",
                onCancel: GenScene.GoToMainMenu // Calls StopMultiplayer through a patch
                );

            ReloadGame(mapsToLoad, true, false);
        }
Example #3
0
        static void DoButtons()
        {
            float x = UI.screenWidth - btnWidth - btnMargin;
            float y = btnMargin;

            var session = Multiplayer.session;

            if (session != null && !Multiplayer.IsReplay)
            {
                var btnRect   = new Rect(x, y, btnWidth, btnHeight);
                var chatColor = session.players.Any(p => p.status == PlayerStatus.Desynced) ? "#ff5555" : "#dddddd";
                var hasUnread = session.hasUnread ? "*" : "";
                var chatLabel = $"{"MpChatButton".Translate()} <color={chatColor}>({session.players.Count})</color>{hasUnread}";

                TooltipHandler.TipRegion(btnRect, "MpChatHotkeyInfo".Translate() + " " + MultiplayerStatic.ToggleChatDef.MainKeyLabel);

                if (Widgets.ButtonText(btnRect, chatLabel))
                {
                    ChatWindow.OpenChat();
                }

                if (!TickPatch.Simulating)
                {
                    IndicatorInfo(out Color color, out string text, out bool slow);

                    var indRect    = new Rect(btnRect.x - 25f - 5f + 6f / 2f, btnRect.y + 6f / 2f, 19f, 19f);
                    var biggerRect = new Rect(btnRect.x - 25f - 5f + 2f / 2f, btnRect.y + 2f / 2f, 23f, 23f);

                    if (slow && Widgets.ButtonInvisible(biggerRect))
                    {
                        TickPatch.SetSimulation(toTickUntil: true, canESC: true);
                    }

                    Widgets.DrawRectFast(biggerRect, new Color(color.r * 0.6f, color.g * 0.6f, color.b * 0.6f));
                    Widgets.DrawRectFast(indRect, color);
                    TooltipHandler.TipRegion(indRect, new TipSignal(text, 31641624));
                }

                y += btnHeight;
            }

            if (Multiplayer.ShowDevInfo && Multiplayer.WriterLog != null)
            {
                if (Widgets.ButtonText(new Rect(x, y, btnWidth, btnHeight), $"Write ({Multiplayer.WriterLog.NodeCount})"))
                {
                    Find.WindowStack.Add(Multiplayer.WriterLog);
                }

                y += btnHeight;
                if (Widgets.ButtonText(new Rect(x, y, btnWidth, btnHeight), $"Read ({Multiplayer.ReaderLog.NodeCount})"))
                {
                    Find.WindowStack.Add(Multiplayer.ReaderLog);
                }

                y += btnHeight;
            }

            if (Multiplayer.Client != null && Multiplayer.GameComp.debugMode)
            {
                Text.Font   = GameFont.Tiny;
                Text.Anchor = TextAnchor.MiddleCenter;
                Widgets.Label(new Rect(x, y, btnWidth, 30f), $"Debug mode");
                Text.Anchor = TextAnchor.UpperLeft;
                Text.Font   = GameFont.Small;
            }
        }