public static Scene LoadScene(string path) { if (File.Exists(path) == false) { return(null); } Scene scene = new Scene(); FileStream fs = new FileStream(path, FileMode.Open); GZipStream zipStream = new GZipStream(fs, CompressionMode.Decompress); BinaryReader reader = new BinaryReader(zipStream); int count = reader.ReadInt32(); for (int i = 0; i <= count - 1; i += 1) { SceneFrame newFrame = new SceneFrame(); newFrame.BGFileName = reader.ReadString(); int c = reader.ReadInt32(); for (int j = 0; j <= c - 1; j += 1) { newFrame.Characters.Add(new CharImage(reader.ReadString(), new System.Drawing.Rectangle(reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32()))); } newFrame.Name = reader.ReadString(); newFrame.Text = reader.ReadString(); newFrame.Script = reader.ReadString(); newFrame.JumpTo = reader.ReadInt32(); newFrame.JumpCondition = reader.ReadString(); newFrame.IsSelection = reader.ReadBoolean(); c = reader.ReadInt32(); for (int j = 0; j <= c - 1; j += 1) { newFrame.Selections.Add(reader.ReadString()); } c = reader.ReadInt32(); for (int j = 0; j <= c - 1; j += 1) { newFrame.JumpAfterSelect.Add(reader.ReadInt32()); } c = reader.ReadInt32(); for (int j = 0; j <= c - 1; j += 1) { newFrame.Sounds.Add(reader.ReadString()); } scene.Frames.Add(newFrame); } reader.Close(); reader.Dispose(); zipStream.Close(); zipStream.Dispose(); fs.Close(); fs.Dispose(); return(scene); }
public void DrawToPB() { Bitmap newBM = new Bitmap(Game.GameWindow.Width, Game.GameWindow.Height); Graphics g = Graphics.FromImage(newBM); SceneFrame frame = scene.Frames[scene.CurFrame]; Image BG = Image.FromFile(BGDir + frame.BGFileName + ".png"); g.DrawImage(BG, new Rectangle(0, 0, newBM.Width, newBM.Height)); BG.Dispose(); foreach (CharImage c in frame.Characters) { Image tmpImage = Image.FromFile(CharDir + c.FileName + ".png"); if (c.Position.Width == 0 && c.Position.Height == 0) { g.DrawImage(tmpImage, new Rectangle(c.Position.X - tmpImage.Width / 2, c.Position.Y, tmpImage.Width, tmpImage.Height)); } else { g.DrawImage(tmpImage, new Rectangle(c.Position.X - c.Position.Width / 2, c.Position.Y, c.Position.Width, c.Position.Height)); } tmpImage.Dispose(); } //Vẽ các lựa chọn (Selection) if (PB.Image != null) { PB.Image.Dispose(); } PB.Image = newBM; g.Dispose(); }
public static Scene LoadFromTextFile(string path) { if (!File.Exists(path)) { return(null); } Scene newScene = new Scene(); string[] str; using (StreamReader sr = new StreamReader(path)) { str = sr.ReadToEnd().Split('$'); } foreach (string line in str) { string[] part = line.Split('`'); string[] info = part[0].Split('|'); SceneFrame frame = new SceneFrame(); if (part[1].Substring(0, part[1].Length - 1).Split('\\').Length > 1) { frame.Text = part[1].Substring(0, part[1].Length - 1).Split('\\')[0]; frame.Text = frame.Text.Substring(0, frame.Text.Length - 1); } else { frame.Text = part[1].Substring(0, part[1].Length - 1); } if (frame.Text.Length > 0) { frame.Text = frame.Text.Substring(0, part[1].Length - 1); } frame.BGFileName = info[1]; frame.Sounds.AddRange(info[2].Split('/')); if (!Int32.TryParse(info[3], out frame.JumpTo)) { frame.JumpTo = -1; } frame.JumpCondition = info[4]; frame.Script = info[5]; for (int i = 0; i < info.Length; i += 1) { if (info[i].Length > 0) { string[] character = info[i].Split(','); CharImage ci; if (character.Length < 4) { ci = new CharImage(character[0], new System.Drawing.Rectangle(Int32.Parse(character[1]), Int32.Parse(character[2]), 0, 0)); } else { ci = new CharImage(character[0], new System.Drawing.Rectangle(Int32.Parse(character[1]), Int32.Parse(character[2]), Int32.Parse(character[3]), Int32.Parse(character[4]))); } frame.Characters.Add(ci); } } newScene.Frames.Add(frame); } return(newScene); }