private State getCubeState(Shape shape) { Programme p = programmeLV.SelectedItem as Programme; if (p == null) { return(null); } char[] s = { '_' }; string[] sname = shape.Name.Substring(5).Split(s); State state = p.Cubes[int.Parse(sname[0]) - 1].States[int.Parse(sname[1]) - 1]; return(state); }
private void select_programme(object sender, SelectionChangedEventArgs e) { if (editing_programme != programmeLV.SelectedItem as Programme && null != programmeLV.SelectedItem as Programme) { editing_programme = programmeLV.SelectedItem as Programme; reset_cube(); resize_cube(); if (editing_programme.Cubes.Length < 7) { MessageBox.Show("不合法的方案,请删除重建"); } foreach (var c in editing_programme.Cubes) { for (int i = 0; i < c.States.Count; ++i) { string name = "cube_" + c.Type.ToString() + "_" + (i + 1).ToString(); rotate_dict[name].Angle = c.States[i].R; Shape shape = mainCanvas.FindName(name) as Shape; Canvas.SetLeft(shape, c.States[i].X); Canvas.SetTop(shape, c.States[i].Y); if (c.States[i].IsFliped) { scale_dict[shape.Name].ScaleX = -scale_dict[shape.Name].ScaleX; shape.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF007ACC")); shape.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFFFFF")); } else { shape.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFFFFFFF")); shape.Stroke = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF007ACC")); } } } } }
private void Window_KeyDown(object sender, KeyEventArgs e) { Programme p = programmeLV.SelectedItem as Programme; if (null != cur_selected_cube && null != p) { Shape shape = mainCanvas.FindName(cur_selected_cube) as Shape; State state = getCubeState(shape); if (state == null) { return; } switch (e.Key) { case Key.W: state.Y -= 1; Canvas.SetTop(shape, state.Y); break; case Key.S: state.Y += 1; Canvas.SetTop(shape, state.Y); break; case Key.A: state.X -= 1; Canvas.SetLeft(shape, state.X); break; case Key.D: state.X += 1; Canvas.SetLeft(shape, state.X); break; } } }
private void add_programme(object sender, RoutedEventArgs e) { if (sectionCBB.SelectedItem == null || musicCBB.SelectedItem == null || sceneCBB.SelectedItem == null || backgroundCBB.SelectedItem == null || resolutionCBB.SelectedItem == null || sizeCBB.SelectedItem == null) { MessageBox.Show("请先检查补全以下信息:章节、配乐、场景、背景、分辨率和尺寸"); return; } string section = sectionCBB.SelectedItem.ToString(); string music = musicCBB.SelectedItem.ToString(); string scene = sceneCBB.SelectedItem.ToString(); string background = backgroundCBB.SelectedItem.ToString(); Resolution resolution = resolutionCBB.SelectedItem as Resolution; object size = sizeCBB.SelectedItem; Section res_section = null; foreach (var sec in PuzzleXMLResource.GameRes.Sections) { if (sec.Name.Equals(section)) { res_section = sec; break; } } if (null == res_section) { res_section = new Section(); res_section.Name = section; res_section.Music = music; PuzzleXMLResource.GameRes.Sections.Add(res_section); } Scene res_scene = null; foreach (var sce in res_section.Scenes) { if (sce.Name.Equals(scene)) { res_scene = sce; break; } } if (null == res_scene) { res_scene = new Scene(); res_scene.Name = scene; res_scene.Background = background; res_section.Scenes.Add(res_scene); } SceneResol res_sceneResol = null; foreach (var sr in res_scene.SceneResols) { if (sr.Resolution.Equals(resolution)) { res_sceneResol = sr; break; } } if (null == res_sceneResol) { res_sceneResol = new SceneResol(); res_sceneResol.Resolution = resolution; res_sceneResol.Size = (int)size; res_scene.SceneResols.Add(res_sceneResol); } if (null == res_sceneResol.Programmes) { res_sceneResol.Programmes = new List <Programme>(); } List <Programme> pgrs = res_sceneResol.Programmes; Programme p = new Programme(); p.Cubes = new Cube[7]; for (int i = 0; i < 7; ++i) { p.Cubes[i] = new Cube(); p.Cubes[i].Type = i + 1; p.Cubes[i].States = new List <State>(); if (i + 1 == 1) { p.Cubes[i].States.Add(new State()); } else if (i + 1 == 6) { p.Cubes[i].States.Add(new State()); p.Cubes[i].States.Add(new State()); p.Cubes[i].States.Add(new State()); p.Cubes[i].States.Add(new State()); } else { p.Cubes[i].States.Add(new State()); p.Cubes[i].States.Add(new State()); } } p.ID = pgrs.Count + 1; pgrs.Add(p); programmeLV.DataContext = pgrs; programmeLV.Items.Refresh(); }
public static bool Load(string xml_file) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(xml_file); // 加载资源 XmlNodeList nodelist = xmlDoc.SelectNodes("//SectionRes/String"); for (int i = 0; i < nodelist.Count; i++) { XmlElement e = (XmlElement)nodelist.Item(i); PuzzleRes.AddResource("Section", e.InnerText); } nodelist = xmlDoc.SelectNodes("//MusicRes/String"); for (int i = 0; i < nodelist.Count; i++) { XmlElement e = (XmlElement)nodelist.Item(i); PuzzleRes.AddResource("Music", e.InnerText); } nodelist = xmlDoc.SelectNodes("//SceneRes/String"); for (int i = 0; i < nodelist.Count; i++) { XmlElement e = (XmlElement)nodelist.Item(i); PuzzleRes.AddResource("Scene", e.InnerText); } nodelist = xmlDoc.SelectNodes("//ResolutionRes/Resolution"); for (int i = 0; i < nodelist.Count; i++) { XmlElement e = (XmlElement)nodelist.Item(i); Resolution r = new Resolution(); r.Width = int.Parse(e.GetAttribute("width")); r.Height = int.Parse(e.GetAttribute("height")); r.Device = e.InnerText; PuzzleRes.AddResource("Resolution", r); } nodelist = xmlDoc.SelectNodes("//SizeRes/Int"); for (int i = 0; i < nodelist.Count; i++) { XmlElement e = (XmlElement)nodelist.Item(i); PuzzleRes.AddResource("Size", int.Parse(e.InnerText)); } nodelist = xmlDoc.SelectNodes("//BackgroundRes/String"); for (int i = 0; i < nodelist.Count; i++) { XmlElement e = (XmlElement)nodelist.Item(i); PuzzleRes.AddResource("Background", e.InnerText); } // 加载场景资源 nodelist = xmlDoc.SelectNodes("//GameRes/Section"); for (int i = 0; i < nodelist.Count; ++i) { XmlElement e = (XmlElement)nodelist.Item(i); Section section = new Section(); section.Name = e.GetAttribute("name"); section.Music = e.GetAttribute("music"); XmlNodeList sceneNodeList = e.ChildNodes; for (int j = 0; j < sceneNodeList.Count; ++j) { XmlElement ee = (XmlElement)sceneNodeList.Item(j); Scene scene = new Scene(); scene.Name = ee.GetAttribute("name"); scene.Background = ee.GetAttribute("background"); XmlNodeList resolNodeList = ee.ChildNodes; for (int k = 0; k < resolNodeList.Count; ++k) { XmlElement eee = (XmlElement)resolNodeList.Item(k); Resolution r = new Resolution(); SceneResol resol = new SceneResol(); r.Width = int.Parse(eee.GetAttribute("width")); r.Height = int.Parse(eee.GetAttribute("height")); r.Device = eee.GetAttribute("device"); resol.Resolution = r; resol.Size = int.Parse(eee.GetAttribute("size")); XmlNodeList progmNodeList = eee.ChildNodes; for (int m = 0; m < progmNodeList.Count; ++m) { XmlElement eeee = (XmlElement)progmNodeList.Item(m); Programme programme = new Programme(); programme.ID = int.Parse(eeee.GetAttribute("id")); XmlNodeList cubeNodeList = eeee.ChildNodes; for (int n = 0; n < cubeNodeList.Count; ++n) { XmlElement eeeee = (XmlElement)cubeNodeList.Item(n); Cube cube = new Cube(); cube.Type = int.Parse(eeeee.GetAttribute("type")); string content = eeeee.InnerText; char[] separator = { '#' }; string[] st = content.Split(separator); foreach (string s in st) { State state = new State(); if (s.Contains("f")) { state.IsFliped = true; } else { state.IsFliped = false; } string tmp; if (state.IsFliped) { tmp = s.Substring(1, s.Length - 3); } else { tmp = s.Substring(1, s.Length - 2); } char[] septr = { ',' }; string[] temps = tmp.Split(septr); state.X = double.Parse(temps[0]); state.Y = double.Parse(temps[1]); state.R = double.Parse(temps[2]); cube.States.Add(state); } programme.Cubes[cube.Type - 1] = cube; } resol.Programmes.Add(programme); } scene.SceneResols.Add(resol); } section.Scenes.Add(scene); } GameRes.Sections.Add(section); } return(true); }