public Scene jsonToScene(string sceneDir) { log.e("jsonToScene " + sceneDir); string jsonStr = TextFile.fileToText(Path.Combine(App.SceneDir, sceneDir, AD_CONFIG_JSON)); return(JsonConvert.DeserializeObject <Scene>(BluCodec.Decode(jsonStr))); }
public void sceneToJson(string sceneDir, Scene scene) { string json = JsonConvert.SerializeObject(scene, Formatting.Indented); Console.WriteLine(json); json = BluCodec.Encode(json); //Console.WriteLine(json); using (StreamWriter sw = new StreamWriter(File.Open(Path.Combine(App.SceneDir, sceneDir, AD_CONFIG_JSON), FileMode.Create))) { sw.WriteLine(json); } }
/// <summary> /// 文件夹名称就是场景名称, json 保存 video, subtitle, picture 位置等信息, /// 图片视频等资源拷贝进来即可 /// </summary> //private void doSaveScene(string sceneName) void doSaveScene(MarqueeProgress sender, DoWorkEventArgs e) { Toast("正在保存场景文件, 请稍候!", 3); string sceneName = (string)e.Argument; string dir = Path.Combine(App.SceneDir, sceneName); Scene scene = new Scene() { timing = AdScene.Timing_0000, name = sceneName, // + " (定时 " + SceneTiming.Replace(':', '.') + ")", }; for (int i = 0; i < CanvasMain.Kernel.getShapeList().Count; i++) { RectShape rect = CanvasMain.Kernel.getShapeList()[i] as RectShape; log.w("saveScene: " + rect.ItemType); scene.layers.Add(rect.ItemType); switch (rect.ItemType) { case AdItemType.Video: if (!App.VIDEO) { scene.video.Add(rect.Prop as Video); } else { Video video = rect.Prop as Video; if (video.filelist.Count == 0 && App.HDMI == false) { App.MsgBoxE("没有设置视频元素的视频源!"); Directory.Delete(dir, true); e.Result = false; return; } scene.video.Add(createVid(video, dir)); } break; case AdItemType.Picture: Picture picture = rect.Prop as Picture; if (picture.filelist.Count == 0) { App.MsgBoxE("没有设置图片元素的图片源!"); Directory.Delete(dir, true); e.Result = false; return; } scene.picture.Add(createPic(picture, dir)); break; case AdItemType.Subtitle: scene.subtitle.Add(rect.Prop as Subtitle); break; case AdItemType.Select: break; default: break; } } string json = JsonConvert.SerializeObject(scene, Formatting.Indented); log.t(json); json = BluCodec.Encode(json); //Console.WriteLine(json); using (StreamWriter sw = new StreamWriter(File.Open(Path.Combine(dir, AD_CONFIG_JSON), FileMode.Create))) { sw.WriteLine(json); } e.Result = true; //lbScene.Items.Add(scene.name); //endSceneEditing(); //App.MsgBox("保存成功!"); }
private void OpenScene() { CanvasMain.Kernel.EndShapeCreate -= new EPKernel.EndShapeCreateHandler(EndShapeCreate); Toast("正在打开场景文件"); string dir = Path.Combine(App.SceneDir, lbScene.GetItemText(lbScene.SelectedItem)); string json = Path.Combine(dir, AD_CONFIG_JSON); var scene = JsonConvert.DeserializeObject <Scene>(BluCodec.Decode(TextFile.fileToText(json))); // 重新画在虚拟屏幕区 CanvasMain.Kernel.DeleteAllShapse(); Console.WriteLine(JsonConvert.SerializeObject(scene, Formatting.Indented)); int i_vid = 0; int i_pic = 0; int i_sub = 0; foreach (var layer in scene.layers) { switch (layer) { case AdItemType.Video: tsVideo_Click(null, null); drawRect(scene.video[i_vid]); if (App.VIDEO) { Video v = scene.video[i_vid]; List <string> vlist = new List <string>(); foreach (var vfile in v.filelist) { vlist.Add(Path.Combine(dir, vfile)); } if (vlist.Count > 0) { displayScreenshot(vlist, v.intval); } } i_vid++; break; case AdItemType.Picture: Picture item = scene.picture[i_pic]; tsPic_Click(null, null); drawRect(item); List <string> list = new List <string>(); foreach (var picFile in item.filelist) { list.Add(Path.Combine(dir, picFile)); } showImageOnPic(list, item.intval); i_pic++; break; case AdItemType.Subtitle: tsSub_Click(null, null); drawRect(scene.subtitle[i_sub]); setSubtitleProp(scene.subtitle[i_sub]); i_sub++; break; default: break; } } //CanvasMain.reDraw(); //CanvasMain.Kernel.RefleshBitmap(); gbDrawTool.Enabled = true; txtSceneName.Text = lbScene.GetItemText(lbScene.SelectedItem); txtSceneName.Enabled = true; btSceneNewSave.Text = "保存场景"; btSceneNewSave.Enabled = true; sceneEditing = true; //SceneTiming = scene.timing; //恢复 CanvasMain.Kernel.EndShapeCreate += new EPKernel.EndShapeCreateHandler(EndShapeCreate); }