public void MakeHistory(string id = null) { using (MemoryStream mem = new MemoryStream()) { if (id == null) id = ""; if (id == "" || id != lastid) { byte[] port = Player.Portrait; byte[] fac = Player.FactionImage; Player.Portrait = null; Player.FactionImage = null; Player.Serializer.Serialize(mem, Player); mem.Seek(0, SeekOrigin.Begin); UndoBuffer.AddLast((Player)Player.Serializer.Deserialize(mem)); Player.Portrait = port; Player.FactionImage = fac; UndoBuffer.Last.Value.Portrait = port; UndoBuffer.Last.Value.FactionImage = fac; foreach (Possession pos in UndoBuffer.Last.Value.Possessions) if (pos.Description != null) pos.Description = pos.Description.Replace("\n", Environment.NewLine); for (int i = 0; i < UndoBuffer.Last.Value.Journal.Count; i++) UndoBuffer.Last.Value.Journal[i] = UndoBuffer.Last.Value.Journal[i].Replace("\n", Environment.NewLine); for (int i = 0; i < UndoBuffer.Last.Value.ComplexJournal.Count; i++) if (UndoBuffer.Last.Value.ComplexJournal[i].Text != null) UndoBuffer.Last.Value.ComplexJournal[i].Text = UndoBuffer.Last.Value.ComplexJournal[i].Text.Replace("\n", Environment.NewLine); UndoBuffer.Last.Value.Allies = UndoBuffer.Last.Value.Allies.Replace("\n", Environment.NewLine); UndoBuffer.Last.Value.Backstory = UndoBuffer.Last.Value.Backstory.Replace("\n", Environment.NewLine); RedoBuffer.Clear(); HistoryButtonChange?.Invoke(Player, true, false); if (UndoBuffer.Count > MaxBuffer) UndoBuffer.RemoveFirst(); UnsavedChanges++; } lastid = id; Player.ChoiceCounter.Clear(); Player.ChoiceTotal.Clear(); } }
public bool Redo() { if (RedoBuffer.Count > 0) { lastid = ""; UndoBuffer.AddLast(Player); Player = RedoBuffer.Last.Value; RedoBuffer.RemoveLast(); UnsavedChanges++; HistoryButtonChange?.Invoke(Player, true, RedoBuffer.Count > 0); return(true); } return(false); }
public bool Undo() { if (UndoBuffer.Count > 0) { lastid = ""; RedoBuffer.AddLast(Player); Player = UndoBuffer.Last.Value; UndoBuffer.RemoveLast(); if (UnsavedChanges > 0) UnsavedChanges--; HistoryButtonChange?.Invoke(Player, UndoBuffer.Count > 0, true); return true; } return false; }
public void FireUndoChanged() { HistoryButtonChange?.Invoke(Player, UndoBuffer.Count > 0, RedoBuffer.Count > 0); }