public static PropSnapShot Clone(PropSnapShot s) { PropSnapShot newObj = new PropSnapShot(); foreach (MPN mpn in Enum.GetValues(typeof(MPN))) { MaidProp srcMaidProp = s.maidProps[mpn]; MaidProp newMaidProp = new MaidProp(); using (MemoryStream ms = new MemoryStream()) { BinaryWriter bw = new BinaryWriter(ms); srcMaidProp.Serialize(bw); bw.Flush(); ms.Position = 0; using (BinaryReader br = new BinaryReader(ms)) { newMaidProp.Deserialize(br); } } newObj.maidProps[mpn] = newMaidProp; } for (int i = 0; i < (int)MaidParts.PARTS_COLOR.MAX; i++) { MaidParts.PARTS_COLOR col = (MaidParts.PARTS_COLOR)i; var c = s.GetColor(col); newObj.SetColor(col, c); } return(newObj); }
void RedoHistory() { PropSnapShot his; if (history.Redo(out his)) { prev = PropSnapShot.Clone(his); StorePropSnapShot(his); } }
void RecordHistory() { PropSnapShot cur = CapturePropSnapShot(); if (prev != null && !cur.Equals(prev)) { history.Record(PropSnapShot.Clone(cur)); } history.Trim(HistoryMax); prev = PropSnapShot.Clone(cur); }
public void Update() { outputs.Clear(); outputs.Add(string.Format("Update")); SceneEdit sceneEdit = FindSceneEdit(); if (sceneEdit == null) { outputs.Add(string.Format("sceneEdit == null")); return; } PropSnapShot cur = CapturePropSnapShot(); if (!cur.Equals(prev)) { // マウス左ボタンがドラッグ中なら何もしない if (!Input.GetMouseButton(0)) { changeCount++; Log.WriteLine("--- : Record"); RecordHistory(); prev = PropSnapShot.Clone(cur); } } if (Input.GetKeyDown(KeyCode.Z)) { Log.WriteLine("^Z : Undo"); UndoHistory(); } if (Input.GetKeyDown(KeyCode.Y)) { Log.WriteLine("^Y : Redo"); RedoHistory(); } if (Input.GetKeyDown(KeyCode.C)) { tempShot = PropSnapShot.Clone(cur); } if (Input.GetKeyDown(KeyCode.V)) { StorePropSnapShot(tempShot); } outputs.Add(string.Format("historyCursor = {0}", history.historyCursor)); outputs.Add(string.Format("changeCount = {0}", changeCount)); }
void StorePropSnapShot(PropSnapShot s) { int maidNumber = 0; Maid maid = GameMain.Instance.CharacterMgr.GetMaid(maidNumber); if (maid == null) { return; } SceneEdit sceneEdit = FindSceneEdit(); if (sceneEdit == null) { return; } foreach (MPN mpn in Enum.GetValues(typeof(MPN))) { if (mpn == MPN.null_mpn) { continue; } try { MaidProp maidProp = s[mpn]; if (!string.IsNullOrEmpty(maidProp.strFileName)) { maid.SetProp(mpn, maidProp.strFileName, maidProp.nFileNameRID, false); } else { maid.SetProp(mpn, maidProp.value, false); } } catch (Exception) { } } foreach (KeyValuePair <MaidParts.PARTS_COLOR, MaidParts.PartsColor> kv in s.maidPartsColors) { maid.Parts.SetPartsColor(kv.Key, kv.Value); } // 値の更新 maid.AllProcProp(); sceneEdit.UpdateSliders(); }
PropSnapShot CapturePropSnapShot() { PropSnapShot s = new PropSnapShot(); int maidNumber = 0; Maid maid = GameMain.Instance.CharacterMgr.GetMaid(maidNumber); if (maid == null) { return(s); } foreach (MPN mpn in Enum.GetValues(typeof(MPN))) { try { MaidProp maidProp = maid.GetProp(mpn); if (maidProp != null) { s[mpn] = maidProp; } } catch (Exception) { } } MaidParts maidParts = maid.Parts; MaidParts.PartsColor[] newMaidParts = null; using (MemoryStream ms = new MemoryStream()) { BinaryWriter bw = new BinaryWriter(ms); maidParts.Serialize(bw); bw.Flush(); ms.Position = 0; using (BinaryReader br = new BinaryReader(ms)) { newMaidParts = MaidParts.DeserializePre(br); } } for (int i = 0; i < (int)MaidParts.PARTS_COLOR.MAX; i++) { MaidParts.PARTS_COLOR col = (MaidParts.PARTS_COLOR)i; s.SetColor(col, newMaidParts[i]); } return(s); }