public static void LoadReplay(string name, bool toEnd = false, Action after = null) { var session = Multiplayer.session = new MultiplayerSession(); session.client = new ReplayConnection(); session.client.State = ConnectionStateEnum.ClientPlaying; session.replay = true; var replay = ForLoading(name); replay.LoadInfo(); replay.LoadCurrentData(0); // todo ensure everything is read correctly session.myFactionId = replay.info.playerFaction; session.replayTimerStart = replay.info.sections[0].start; int tickUntil = replay.info.sections[0].end; session.replayTimerEnd = tickUntil; TickPatch.tickUntil = tickUntil; TickPatch.skipTo = toEnd ? tickUntil : session.replayTimerStart; TickPatch.afterSkip = after; ClientJoiningState.ReloadGame(OnMainThread.cachedMapData.Keys.ToList()); }
public static void LoadReplay(FileInfo file, bool toEnd = false, Action after = null, Action cancel = null, string simTextKey = null) { var session = Multiplayer.session = new MultiplayerSession(); session.client = new ReplayConnection(); session.client.State = ConnectionStateEnum.ClientPlaying; session.replay = true; var replay = ForLoading(file); replay.LoadInfo(); var sectionIndex = toEnd ? (replay.info.sections.Count - 1) : 0; replay.LoadCurrentData(sectionIndex); // todo ensure everything is read correctly session.myFactionId = replay.info.playerFaction; session.replayTimerStart = replay.info.sections[sectionIndex].start; int tickUntil = replay.info.sections[sectionIndex].end; session.replayTimerEnd = tickUntil; TickPatch.tickUntil = tickUntil; TickPatch.SkipTo(toEnd ? tickUntil : session.replayTimerStart, onFinish: after, onCancel: cancel, simTextKey: simTextKey); ClientJoiningState.ReloadGame(OnMainThread.cachedMapData.Keys.ToList()); }
public override void DoWindowContents(Rect inRect) { Text.Font = GameFont.Small; Text.Anchor = TextAnchor.UpperCenter; Widgets.Label(new Rect(0, 0, inRect.width, 40), $"{"MpDesynced".Translate()}\n{text}"); Text.Anchor = TextAnchor.UpperLeft; float buttonWidth = 120 * 4 + 10 * 3; var buttonRect = new Rect((inRect.width - buttonWidth) / 2, 40, buttonWidth, 35); GUI.BeginGroup(buttonRect); float x = 0; if (Widgets.ButtonText(new Rect(x, 0, 120, 35), "MpTryResync".Translate())) { Multiplayer.session.resyncing = true; TickPatch.SkipTo( toTickUntil: true, onFinish: () => { Multiplayer.session.resyncing = false; Multiplayer.Client.Send(Packets.Client_WorldReady); }, cancelButtonKey: "Quit", onCancel: GenScene.GoToMainMenu ); Multiplayer.session.desynced = false; ClientJoiningState.ReloadGame(OnMainThread.cachedMapData.Keys.ToList(), false); } x += 120 + 10; if (Widgets.ButtonText(new Rect(x, 0, 120, 35), "Save".Translate())) { Find.WindowStack.Add(new Dialog_SaveReplay()); } x += 120 + 10; if (Widgets.ButtonText(new Rect(x, 0, 120, 35), "MpChatButton".Translate())) { Find.WindowStack.Add(new ChatWindow() { closeOnClickedOutside = true, absorbInputAroundWindow = true }); } x += 120 + 10; if (Widgets.ButtonText(new Rect(x, 0, 120, 35), "Quit".Translate())) { MainMenuPatch.AskQuitToMainMenu(); } GUI.EndGroup(); }
static void DrawTimelineWindow() { if (Multiplayer.Client == null) { return; } 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 : OnMainThread.cachedAtTime; int timerEnd = Multiplayer.session.replayTimerEnd >= 0 ? Multiplayer.session.replayTimerEnd : TickPatch.tickUntil; int timeLen = timerEnd - timerStart; Widgets.DrawLine(new Vector2(rect.xMin + 2f, rect.yMin), new Vector2(rect.xMin + 2f, rect.yMax), Color.white, 4f); Widgets.DrawLine(new Vector2(rect.xMax - 2f, rect.yMin), new Vector2(rect.xMax - 2f, rect.yMax), Color.white, 4f); float progress = (TickPatch.Timer - timerStart) / (float)timeLen; float progressX = rect.xMin + progress * rect.width; Widgets.DrawLine(new Vector2(progressX, rect.yMin), new Vector2(progressX, rect.yMax), Color.green, 7f); 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); Widgets.DrawLine(new Vector2(pointX, rect.yMin), new Vector2(pointX, rect.yMax), ev.color, 5f); 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); Widgets.DrawLine(new Vector2(mouseX, rect.yMin), new Vector2(mouseX, rect.yMax), Color.blue, 3f); if (Event.current.type == EventType.MouseUp) { TickPatch.skipTo = mouseTimer; if (mouseTimer < TickPatch.Timer) { ClientJoiningState.ReloadGame(OnMainThread.cachedMapData.Keys.ToList(), false); } } if (Event.current.isMouse) { Event.current.Use(); } string tooltip = $"Tick {mouseTimer}"; if (mouseEvent != null) { tooltip = $"{mouseEvent.name}\n{tooltip}"; } TooltipHandler.TipRegion(rect, new TipSignal(tooltip, 215462143)); // No delay between the mouseover and showing if (TooltipHandler.activeTips.TryGetValue(215462143, out ActiveTip tip)) { tip.firstTriggerTime = 0; } } if (TickPatch.skipTo >= 0) { float pct = (TickPatch.skipTo - timerStart) / (float)timeLen; float skipToX = rect.xMin + rect.width * pct; Widgets.DrawLine(new Vector2(skipToX, rect.yMin), new Vector2(skipToX, rect.yMax), Color.yellow, 4f); } }
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); } }