public static bool Prefix(ThingPart __instance) { var tuple = Main.GetThingPartStateTuple(__instance); if (Main.thingPartStateHistory.UndoCount(tuple) > 0) { ThingPartStateHistoryEntry saved = Main.thingPartStateHistory.Undo(tuple, new ThingPartStateHistoryEntry(__instance.states[__instance.currentState])); DebugLog.Log("Undoing to {0}", saved); __instance.transform.localPosition = saved.position; __instance.transform.localEulerAngles = saved.rotation; __instance.transform.localScale = saved.scale; __instance.material.color = saved.color; RewriteThingPartMemorizeForUndo.disableMemorize = true; __instance.SetStatePropertiesByTransform(false); RewriteThingPartMemorizeForUndo.disableMemorize = false; if (__instance.materialType == MaterialTypes.Transparent) { __instance.UpdateMaterial(); } } else { Managers.soundManager.Play("no", __instance.transform, 0.5f, false, false); } DebugLog.Log(String.Format("[U] UndoCount={0} RedoCount={1}", Main.thingPartStateHistory.UndoCount(tuple), Main.thingPartStateHistory.RedoCount(tuple))); return(false); }
public static void Postfix(ThingPartDialog __instance, string contextName) { if (contextName.Equals("redo")) { ThingPart tp = __instance.thingPart(); var tuple = Main.GetThingPartStateTuple(tp); if (Main.thingPartStateHistory.RedoCount(tuple) > 0) { ThingPartStateHistoryEntry saved = Main.thingPartStateHistory.Redo(tuple, new ThingPartStateHistoryEntry(tp.states[tp.currentState])); DebugLog.Log("Redoing to {0}", saved); tp.transform.localPosition = saved.position; tp.transform.localEulerAngles = saved.rotation; tp.transform.localScale = saved.scale; tp.material.color = saved.color; RewriteThingPartMemorizeForUndo.disableMemorize = true; tp.SetStatePropertiesByTransform(false); RewriteThingPartMemorizeForUndo.disableMemorize = false; if (tp.materialType == MaterialTypes.Transparent) { tp.UpdateMaterial(); } DebugLog.Log(String.Format("[R] UndoCount={0} RedoCount={1}", Main.thingPartStateHistory.UndoCount(tuple), Main.thingPartStateHistory.RedoCount(tuple))); } else { Managers.soundManager.Play("no", __instance.transform, 0.5f, false, false); } __instance.UpdateUndoButton(); } }