public void Update() { if (uuidsbackup != BP.GetUsedUuids()) { blockstoreplace = new JArray(); replacebyblocks = new JArray(); foreach (string uuid in BP.GetUsedUuids()) { if (Database.blocks.ContainsKey(uuid)) { dynamic blok = new JObject(); blok.name = Database.blocks[uuid].Name; blok.bounds = (Database.blocks[uuid] is Part)? ((Part)Database.blocks[uuid]).GetBoundsDynamic() : null; blok.uuid = uuid; blockstoreplace.Add(blok); } } this.Dispatcher.Invoke((Action)(() => {//this refer to form in WPF application comboBox_old.Items.Clear(); comboBox_new.Items.Clear(); })); foreach (dynamic blok in blockstoreplace) { this.Dispatcher.Invoke((Action)(() => {//this refer to form in WPF application comboBox_old.Items.Add(blok.name); })); } } uuidsbackup = BP.GetUsedUuids(); }
private void CenterMass_Click(object sender, RoutedEventArgs e) { try { if (CenterMass.Content == null) { Point3D point = BP.GetCenterOffMass().Item1; Material material = new DiffuseMaterial(new SolidColorBrush(Color.FromArgb(255, 230, 30, 30))); var meshBuilder = new MeshBuilder(false, false); meshBuilder.AddSphere(point, 0.3); var Mesh = meshBuilder.ToMesh(true); CenterMass.Content = new GeometryModel3D { Geometry = Mesh, Material = material }; } else { CenterMass.Content = null; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button_swap_Click(object sender, RoutedEventArgs e) { if (comboBox_new.SelectedIndex > -1 && comboBox_old.SelectedIndex > -1) { dynamic blocktoreplace = blockstoreplace[comboBox_old.SelectedIndex]; dynamic replacebyblock = replacebyblocks[comboBox_new.SelectedIndex]; int amountchanged = 0; dynamic blueprint = BP.Blueprint; foreach (dynamic body in blueprint.bodies) { foreach (dynamic child in body.childs) { if (child.shapeId == blocktoreplace.uuid && (textBox_color1.Text.ToString().ToLower() == child.color.ToString().ToLower() || textBox_color1.Text.ToString().ToLower() == "#" + child.color.ToString().ToLower() || textBox_color1.Text == "" || textBox_color1.Text == "#")) { if (child.bounds == null) { child.bounds = blocktoreplace.bounds; } child.shapeId = replacebyblock.uuid; amountchanged++; } } } string message = "++ " + amountchanged + " " + blocktoreplace.name + " are now changed to " + replacebyblock.name; MessageBox.Show(message); if (amountchanged > 0) { BP.setblueprint(blueprint); BP.Description.description = BP.Description.description + "\n" + message; window.RenderBlueprint(); } } }
public void Update() { if (uuidsbackup != BP.GetUsedUuids()) { connectable_UUIDS.Clear(); foreach (string uuid in BP.GetUsedUuids()) { if (Database.blocks.ContainsKey(uuid) && Database.blocks[uuid] is Part && (Database.blocks[uuid] as Part).IsConnectable) { connectable_UUIDS.Add(new Connectable(uuid.ToString(), ((Part)Database.blocks[uuid]).GetBoundsDynamic(), Database.blocks[uuid].Name)); } } this.Dispatcher.Invoke((Action)(() => {//this refer to form in WPF application comboBox_items1.Items.Clear(); comboBox_items2.Items.Clear(); })); foreach (Connectable i in connectable_UUIDS) { this.Dispatcher.Invoke((Action)(() => {//this refer to form in WPF application comboBox_items1.Items.Add(i); comboBox_items2.Items.Add(i); })); } } uuidsbackup = BP.GetUsedUuids(); }
public void Update()//new bp, items replaced, ... whatever { disableAll(); if (filter_x1.Text == "" || uuidsbackup != BP.GetUsedUuids()) { dynamic bounds = BP.GetBounds(); filter_x1.Text = bounds.minx.ToString(); filter_y1.Text = bounds.miny.ToString(); filter_z1.Text = bounds.minz.ToString(); filter_x2.Text = bounds.maxx.ToString(); filter_y2.Text = bounds.maxy.ToString(); filter_z2.Text = bounds.maxz.ToString(); } if (uuidsbackup != BP.GetUsedUuids() | true)//fill the combobox once { filter_type.Items.Clear(); filter_type.Items.Add(new Item("any", "*")); foreach (string uuid in BP.GetUsedUuids()) { if (Database.blocks.ContainsKey(uuid)) { filter_type.Items.Add(new Item(Database.blocks[uuid].Name.ToString(), uuid)); } } uuidsbackup.Clear(); uuidsbackup.UnionWith(BP.GetUsedUuids()); filter_type.SelectedIndex = 0; } filterupdate(); }
private void button_render_Click(object sender, RoutedEventArgs e) { //string blueprintstr = blueprint.ToString(); //string child = ((dynamic)filter_output.SelectedItem).child.ToString(); Loadwindow w = new Loadwindow(); try { w.Show(); dynamic child = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(Edit_child.Text); int i = 0; int index = ((dynamic)filter_output.SelectedItem).index; for (int j = 0; j < blueprint.bodies.Count; j++) { for (int k = 0; k < blueprint.bodies[j].childs.Count; k++) { if (index == i) { blueprint.bodies[j].childs[k] = child; BP.setblueprint(blueprint); BP.Description.description = BP.Description.description + "\n++Applied RAW changes"; mainwindow.RenderBlueprint(); //Update(); w.Close(); MessageBox.Show("edit successful"); filterupdate(); return; } i++; } } for (int j = 0; j < blueprint.joints.Count; j++) { if (index == i) { blueprint.joints[j] = child; BP.setblueprint(blueprint); BP.Description.description = BP.Description.description + "\n++Applied RAW changes"; mainwindow.RenderBlueprint(); //Update(); w.Close(); MessageBox.Show("edit successful"); filterupdate(); return; } i++; } w.Close(); MessageBox.Show("edit UNsuccessfull :("); } catch (Exception exc) { w.Close(); MessageBox.Show(exc.Message); } }
private void Click_mirrormode(object sender, RoutedEventArgs e)//needs work { dynamic blueprint = BP.Blueprint; if (blueprint.joints == null) { foreach (dynamic body in blueprint.bodies) { foreach (dynamic block in body.childs) { { dynamic realpos = BP.getposandbounds(block); int xaxis = Convert.ToInt32(block.xaxis); int zaxis = Convert.ToInt32(block.zaxis); if (!((xaxis == 1 && zaxis == -2) || (Math.Abs(xaxis) == 1 && Math.Abs(zaxis) == 3) || (xaxis == -1 && zaxis == 2))) { realpos.xaxis = -xaxis; realpos.zaxis = Math.Abs(zaxis) == 1? -zaxis : zaxis; } //Bounds bounds = Blockobject.BoundsByRotation(new Bounds(realpos.bounds),1,3); realpos.pos.x = -Convert.ToInt32(block.pos.x) - ((realpos.pos.x == block.pos.x)? Convert.ToInt32(realpos.bounds.x) :0); //realpos.pos.y = Convert.ToInt32(block.pos.y) - Convert.ToInt32(block.bounds.y); block.pos = BP.calcbppos(realpos).pos; block.xaxis = BP.calcbppos(realpos).xaxis; block.zaxis = BP.calcbppos(realpos).zaxis; //block.pos.x = -Convert.ToInt32(block.pos.x); //works thus far for blocks, not parts tho /* * if(Math.Abs(Convert.ToInt32(block.zaxis)) == 3 || Math.Abs(Convert.ToInt32(block.zaxis)) == 2) * { * block.xaxis = -Convert.ToInt32(block.xaxis); * } * if(Math.Abs(Convert.ToInt32(block.zaxis)) == 1) * { * block.zaxis = -Convert.ToInt32(block.zaxis); * }*/ /*block.pos.x = -Convert.ToInt32(block.pos.x); * if(Convert.ToInt32(block.xaxis) == 1 || Convert.ToInt32(block.xaxis) == -1) * block.xaxis = -Convert.ToInt32(block.xaxis); * else * block.zaxis = -Convert.ToInt32(block.zaxis);*/ } } } BP.setblueprint(blueprint); this.RenderBlueprint(); } else { MessageBox.Show("Mirror mode can't mirror blueprints with joints inside yet!"); } MessageBox.Show("Mirror mode did it's best to mirror things though there may be some parts that didn't turn out great."); }
private void Button_Create_Click(object sender, RoutedEventArgs e) { float X = Convert.ToInt32(TextBox_X.Text); float Y = Convert.ToInt32(TextBox_Y.Text); //float Z = Convert.ToInt32(TextBox_Z.Text); float t = 0.4f + (float)Convert.ToDouble(TextBox_thickness.Text); dynamic circle = new JObject(); HashSet <Point3D> points = new HashSet <Point3D>(); double precision = 0.95; double pp = 0; for (float x = -X; x < X; x++) { for (float y = -Y; y < Y; y++) { if ((Math.Pow(x / X, 2) + Math.Pow(y / Y, 2)) < precision && (Math.Pow((x) / (X - t), 2) + Math.Pow((y) / (Y - t), 2)) > (precision - pp)) { points.Add(new Point3D(x, y, 1)); } } } circle = BlueprintOptimizer.CreateBlueprintFromPoints(points); if (circle.bodies[0].childs.Count > 0) { string message = "++ An ellipse/circle with " + circle.bodies[0].childs.Count + " shapes has been generated!"; Random r = new Random(); string blueprintpath = Database.User_ + "\\Blueprints\\Generatedellipse-" + r.Next() + r.Next(); dynamic description = new JObject(); description.description = "generated ellipsoid"; description.name = "generated ellipse/circle" + r.Next(); description.type = "Blueprint"; description.version = 0; if (BP.Blueprintpath == null) {//no blueprint exists, initialize new one new BP(blueprintpath, circle, description); } else {//overwrite current blueprint BP.setblueprint(circle); BP.Description.description += message; } mainwindow.RenderBlueprint(); } else { MessageBox.Show("no circle has been generated"); } }
private void button_overwrite_click(object sender, RoutedEventArgs e)//save/overwrite { if (BP.Blueprint != null) { newtumbnail(); BP.Description.name = TextBox_Name.Text; BP.Description.description = TextBox_Description.Text; BP.Save(); } }
private void button_save_click(object sender, RoutedEventArgs e)//save as { if (BP.Blueprint != null) { newtumbnail(); BP.Description.name = TextBox_Name.Text; BP.Description.description = TextBox_Description.Text; Random r = new Random(); //GENERATE NEW UUID AND CHANGE DESCRIPTION LOCALID --todo BP.SaveAs("Blueprint" + r.Next() + "-" + r.Next()); } }
public void Update() { if (uuidsbackup != BP.GetUsedUuids()) { ItemList = new List <Item> { new Item("any", "*") }; foreach (string uuid in BP.GetUsedUuids()) { if (Database.blocks.ContainsKey(uuid)) { ItemList.Add(new Item(Database.blocks[uuid].Name, uuid)); } } dynamic colorlist = new JObject(); foreach (dynamic body in BP.Blueprint.bodies) { foreach (dynamic child in body.childs) { if (child.color.ToString().StartsWith("#")) { child.color = child.color.ToString().Substring(1); } if (colorlist[child.color.ToString().ToLower()] == null) { colorlist[child.color.ToString().ToLower()] = true; string c = child.color.ToString(); Button b = new Button(); var bc = new BrushConverter(); b.Background = (Brush)bc.ConvertFrom("#" + c); color_list.Items.Add(b); } } } this.Dispatcher.Invoke((Action)(() => {//this refer to form in WPF application comboBox_old.Items.Clear(); })); foreach (Item item in ItemList) { this.Dispatcher.Invoke((Action)(() => {//this refer to form in WPF application comboBox_old.Items.Add(item); })); } } uuidsbackup = BP.GetUsedUuids(); }
public void RenderBlueprint() { try { TextBox_Name.Text = BP.Description.name; TextBox_Description.Text = BP.Description.description; Tuple <Model3DGroup, Model3DGroup> renders = BP.RenderBlocks();//backgroundtask ? this.Model = renders.Item1; this.Glass = renders.Item2; this.Marker = null; CenterMass.Content = null; this.Marker2 = new Model3DGroup(); RenderWires(); if (listBox_parts.Visibility == Visibility.Visible) { fillparts(); } Image_blueprint.DataContext = null; Image_blueprint.DataContext = this; helix.ResetCamera(); helix_wires.Camera = helix.Camera; //Model.Children[5].Transform = new ScaleTransform3D(2,2,2); if (connections.IsEnabled == false) { connections.IsEnabled = true; blockproperties.IsEnabled = true; paint.IsEnabled = true; fixcreation.IsEnabled = true; areaproperties.IsEnabled = true; swapblocks.IsEnabled = true; paintpicker.IsEnabled = true; mirrorcreation.IsEnabled = true; requiredmods.IsEnabled = true; } if (!Properties.Settings.Default.safemode) { blockpropertiesRAW.IsEnabled = true; } else { blockpropertiesRAW.IsEnabled = false; } } catch (Exception e) { MessageBox.Show(e.Message + "\nin most cases the creation should be fine, something just went wrong while rendering", "failed to render"); } }
public void fillparts() { var parts = BP.GetUsedPartsList(); if (parts != null) { if (!parts.Equals(this.parts) || true) { new Thread(() => { List <Part_listitem> part_Listitems = new List <Part_listitem>(); foreach (var uuid in parts.Keys) { part_Listitems.Add(new Part_listitem() { name = parts[uuid].Item1, amount = parts[uuid].Item3.ToString(), uuid = uuid }); } this.Dispatcher.Invoke((Action)(() => { //listBox_parts.ItemsSource = null; listBox_parts.ItemsSource = part_Listitems; })); ImageToBitmapSourceConverter converter = new ImageToBitmapSourceConverter(); foreach (Part_listitem item in part_Listitems) { var bmp = Database.blocks[item.uuid].GetIcon(item.uuid); if (bmp != null) { item.icon = (BitmapSource)converter.Convert(bmp.Clone(), null, typeof(BitmapSource), null); item.emptysurface = 0; item.iconheight = 100; } } this.Dispatcher.Invoke((Action)(() => { listBox_parts.ItemsSource = null; listBox_parts.ItemsSource = part_Listitems; })); } ).Start(); this.parts = parts; } } }
private void Button_Create_Click(object sender, RoutedEventArgs e) { int thickness = Convert.ToInt32(TextBox_thickness.Text); int sizeX = Convert.ToInt32(TextBox_X.Text); int sizeY = Convert.ToInt32(TextBox_Y.Text); int sizeZ = Convert.ToInt32(TextBox_Z.Text) - thickness; dynamic Cuboid = new JObject(); Cuboid.bodies = new JArray(); Cuboid.bodies.Add(new JObject()); Cuboid.bodies[0].childs = new JArray(); Cuboid.bodies[0].childs.Add(block(0, 0, 0, sizeX, sizeY, thickness)); Cuboid.bodies[0].childs.Add(block(0, 0, thickness, sizeX, thickness, sizeZ)); Cuboid.bodies[0].childs.Add(block(0, 0, thickness, thickness, sizeY, sizeZ)); Cuboid.bodies[0].childs.Add(block(sizeX - thickness, thickness, thickness, thickness, sizeY - thickness, sizeZ - thickness)); Cuboid.bodies[0].childs.Add(block(thickness, sizeY - thickness, thickness, sizeX - thickness, thickness, sizeZ - thickness)); Cuboid.bodies[0].childs.Add(block(thickness, thickness, sizeZ, sizeX - thickness, sizeY - thickness, thickness)); string message = "++ A Cuboid has been generated!"; Random r = new Random(); string blueprintdir = Database.User_ + "\\Blueprints" + "\\GeneratedCuboid-" + r.Next() + r.Next(); dynamic description = new JObject(); description.description = "generated cuboid"; description.name = "generated cuboid" + r.Next(); description.type = "Blueprint"; description.version = 0; if (BP.Blueprintpath == null) {//no blueprint exists, initialize new one new BP(blueprintdir, Cuboid, description); } else {//a blueprint exists, overwrite it BP.setblueprint(Cuboid); BP.Description.description += message; } mainWindow.RenderBlueprint(); }
private void Click_fixcreation(object sender, RoutedEventArgs e) { dynamic blueprint = new JObject(); blueprint.bodies = new JArray(); blueprint.version = 1; blueprint.bodies.Add(new JObject()); blueprint.bodies[0].childs = new JArray(); //BP.Blueprint.joints = null; foreach (dynamic body in BP.Blueprint.bodies) { //remove bearings/springs/pistons foreach (dynamic child in body.childs) { if (child.joints != null) { child.joints = null; } if (child.controller != null) { if (child.controller.joints != null) { child.controller.joints = null; } if (child.controller.controllers != null) { child.controller.controllers = null; } } blueprint.bodies[0].childs.Add(child); } } BP.Description.description = BP.Description.description + "\n++ removed joints & glitchwelded"; BP.setblueprint(blueprint); this.RenderBlueprint(); }
public void RenderWires() { this.Wires = new Model3DGroup(); if (Properties.Settings.Default.wires) { var wires = BP.GetWires(); foreach (dynamic wire in wires.Values) { Addblob(wire.pos, wire.color.ToString()); if (wire.connections != null) { foreach (dynamic connid in wire.connections) { if (wires.ContainsKey(Convert.ToInt32(connid.id.ToString()))) { Addwire(wire.pos, wires[Convert.ToInt32(connid.id.ToString())].pos, wire.color.ToString()); } } } } Image_blueprint.DataContext = null; Image_blueprint.DataContext = this; } }
private void Convertobj(object sender, DoWorkEventArgs e) { Scene scene = new AssimpImporter().ImportFile(file, PostProcessSteps.Triangulate); //List<Triangle> splittriangles = new List<Triangle>(); pointlist = new HashSet <Point3D>(); //pointlist.ToDictionary<> int progress = 0; int total = 0; try { foreach (Mesh m in scene.Meshes) { foreach (Face face in m.Faces) { total++; } } foreach (Mesh m in scene.Meshes) { foreach (Face face in m.Faces) { IList <Point3D> vertices = new List <Point3D>(); foreach (uint i in face.Indices) { double x = m.Vertices[i].X * scale; double y = m.Vertices[i].Y * scale; double z = m.Vertices[i].Z * scale; Point3D point; if (flipyz) { if (flipxz) { point = new Point3D(y, z, flipz * x); } else { point = new Point3D(x, z, flipz * y); } } else { if (flipxz) { point = new Point3D(z, y, flipz * x); } else { point = new Point3D(x, y, flipz * z); } } vertices.Add(point); pointlist.Add(new Point3D((int)Math.Floor(point.X), (int)Math.Floor(point.Y), (int)Math.Floor(point.Z))); } if (vertices.Count == 3) { Triangle triangle = new Triangle(vertices); if (!triangle.BoundsSmallerThan(bounds)) { Splittriangles(triangle); } } else { } progress++; backgroundWorker.ReportProgress((progress * 100) / total); if (backgroundWorker.CancellationPending) { e.Cancel = true; } } } } catch (Exception ex) { if (!(ex is OperationCanceledException)) { System.Windows.MessageBox.Show(ex.Message, "Something went wrong converting the obj"); } else { e.Cancel = true; } } try { if (backgroundWorker.CancellationPending) { throw new OperationCanceledException(); } dynamic blueprint = new JObject(); try { blueprint = BlueprintOptimizer.CreateBlueprintFromPoints(pointlist); } catch (Exception bpex) { System.Windows.MessageBox.Show(bpex.Message, "Something went wrong building the blueprint"); } int amountgenerated = blueprint.bodies[0].childs.Count; string message = "converted obj to blueprint with " + amountgenerated + " blocks !"; //MessageBox.Show(message+"\n\nOptimized to: "+count+" shapes"); Random r = new Random(); string blueprintpath = Database.User_ + "\\Blueprints\\Generatedblueprintobj-" + r.Next() + r.Next(); dynamic description = new JObject(); description.description = "generated obj blueprint with " + amountgenerated + " block"; description.name = "generated blueprint" + r.Next(); description.type = "Blueprint"; description.version = 0; new Task(() => { System.Windows.MessageBox.Show(message + "\nPLEASE WAIT for the rendering to complete"); }).Start(); if (BP.Blueprintpath == null) {//no blueprint exists, initialize new one new BP(blueprintpath, blueprint, description); } else {//overwrite current blueprint BP.setblueprint(blueprint); BP.Description.description += message; } } catch (Exception exc) { System.Windows.MessageBox.Show(exc.Message, "error"); } }
private void Convertobjwtexture(object sender, DoWorkEventArgs e) { try { Scene scene = new AssimpImporter().ImportFile(file, PostProcessSteps.Triangulate); coloredpoints = new Dictionary <Point3D, Point3D>(); //List<Triangle> splittriangles = new List<Triangle>(); //pointlist = new HashSet<Point3D>(); //pointlist.ToDictionary<> int progress = 0; int total = 0; foreach (Mesh m in scene.Meshes) { foreach (Face face in m.Faces) { total++; } } foreach (Mesh m in scene.Meshes) { var texturecoords = m.GetTextureCoords(0); foreach (Face face in m.Faces) { IList <Point3D> vertices = new List <Point3D>(); IList <Point3D> texturepoints = new List <Point3D>(); foreach (uint i in face.Indices) { double x = m.Vertices[i].X * scale; double y = m.Vertices[i].Y * scale; double z = m.Vertices[i].Z * scale; Point3D point; Assimp.Vector3D texturep = texturecoords[i]; Point3D texturepoint = new Point3D(texturep.X, 1 - texturep.Y, texturep.Z); if (flipyz) { if (flipxz) { point = new Point3D(y, z, flipz * x); } else { point = new Point3D(x, z, flipz * y); } } else { if (flipxz) { point = new Point3D(z, y, flipz * x); } else { point = new Point3D(x, y, flipz * z); } } vertices.Add(point); texturepoints.Add(texturepoint); Point3D flooredpoint = new Point3D((int)Math.Floor(point.X), (int)Math.Floor(point.Y), (int)Math.Floor(point.Z)); if (!coloredpoints.ContainsKey(flooredpoint)) { coloredpoints.Add(flooredpoint, texturepoint); } } if (vertices.Count == 3) { ColorTriangle triangle = new ColorTriangle(vertices, texturepoints); if (!triangle.BoundsSmallerThan(bounds)) { Splitcolortriangles(triangle); } } else { } progress++; backgroundWorker.ReportProgress((progress * 100) / total); if (backgroundWorker.CancellationPending) { e.Cancel = true; } } } } catch (Exception ex) { if (!(ex is OperationCanceledException)) { System.Windows.MessageBox.Show(ex.Message, "Something went wrong converting the obj+texture"); } else { e.Cancel = true; } } try { if (backgroundWorker.CancellationPending) { throw new OperationCanceledException(); } dynamic blueprint = new JObject(); try { Bitmap texturemap = new Bitmap(this.texture); HashSet <Tuple <Point3D, string> > pointswithcolor = new HashSet <Tuple <Point3D, string> >(); int width = texturemap.Width; int height = texturemap.Height; foreach (var pair in coloredpoints) { int x = (int)(pair.Value.X * width); int y = (int)(pair.Value.Y * height); if (pair.Value.Y > 1) { } while (y < 0) { y++; } while (x < 0) { x++; } if (Math.Abs(x) > width / 2) { } while (x >= width) { x -= width; } while (y >= height) { y -= height; } System.Drawing.Color color = texturemap.GetPixel(x, y); string c = color.Name.Substring(2); pointswithcolor.Add(new Tuple <Point3D, string>(pair.Key, c)); } coloredpoints.Clear(); blueprint = BlueprintOptimizer.CreateBlueprintFromPointsAndColor(pointswithcolor); } catch (Exception bpex) { System.Windows.MessageBox.Show(bpex.Message, "Something went wrong building the blueprint"); } int amountgenerated = blueprint.bodies[0].childs.Count; string message = "converted obj to blueprint with " + amountgenerated + " blocks !"; //MessageBox.Show(message+"\n\nOptimized to: "+count+" shapes"); Random r = new Random(); string blueprintpath = Database.User_ + "\\Blueprints\\Generatedblueprintobj-" + r.Next() + r.Next(); dynamic description = new JObject(); description.description = "generated obj blueprint with " + amountgenerated + " block"; description.name = "generated blueprint" + r.Next(); description.type = "Blueprint"; description.version = 0; new Task(() => { System.Windows.MessageBox.Show(message + "\nPLEASE WAIT for the rendering to complete"); }).Start(); if (BP.Blueprintpath == null) {//no blueprint exists, initialize new one new BP(blueprintpath, blueprint, description); } else {//overwrite current blueprint BP.setblueprint(blueprint); BP.Description.description += message; } } catch (Exception exc) { System.Windows.MessageBox.Show(exc.Message, "error"); } }
private void button_render_Click(object sender, RoutedEventArgs e) { //blueprintIndex foreach (dynamic body in BP.Blueprint.bodies) { foreach (dynamic child in body.childs) { if (Convert.ToInt32(child.blueprintIndex) == selectedchildindex) { if (Edit_controller.IsVisible) { child.controller.joints.Clear(); foreach (dynamic item in (dynamic)new_controllercontrolls.Items) { item.startAngle = Convert.ToInt32(item.startAngle); item.frames[0].targetAngle = Convert.ToInt32(item.controller0); item.frames[1].targetAngle = Convert.ToInt32(item.controller1); item.frames[2].targetAngle = Convert.ToInt32(item.controller2); item.frames[3].targetAngle = Convert.ToInt32(item.controller3); item.frames[4].targetAngle = Convert.ToInt32(item.controller4); item.frames[5].targetAngle = Convert.ToInt32(item.controller5); item.frames[6].targetAngle = Convert.ToInt32(item.controller6); item.frames[7].targetAngle = Convert.ToInt32(item.controller7); item.frames[8].targetAngle = Convert.ToInt32(item.controller8); item.frames[9].targetAngle = Convert.ToInt32(item.controller9); child.controller.joints.Add(item); } } if (Edit_gate.IsVisible) { child.controller.mode = new_gatemode.SelectedIndex; } if (Edit_general.IsVisible) { child.pos.x = Convert.ToInt32(new_x.Text); child.pos.y = Convert.ToInt32(new_y.Text); child.pos.z = Convert.ToInt32(new_z.Text); child.color = new_color.Text; child.xaxis = Convert.ToInt32(new_xaxis.Text); child.zaxis = Convert.ToInt32(new_zaxis.Text); dynamic selectedblock = ((dynamic)filter_output.SelectedItem); selectedblock.pos.x = child.pos.x; selectedblock.pos.y = child.pos.y; selectedblock.pos.z = child.pos.z; selectedblock.xaxis = child.xaxis; selectedblock.zaxis = child.zaxis; } if (Edit_sensor.IsVisible) { child.controller.colorMode = new_sensorcolormode.IsChecked; child.controller.range = Convert.ToInt32(new_sensorrange.Text); child.controller.color = new_sensorcolor.Text; } if (Edit_lamp.IsVisible) { child.controller.coneAngle = Convert.ToInt32(new_coneangle.Text); child.controller.luminance = Convert.ToInt32(new_luminance.Text); } if (Edit_Timer.IsVisible) { child.controller.seconds = Convert.ToInt32(new_timerseconds.Text); child.controller.ticks = Convert.ToInt32(new_timerticks.Text); } } } } Loadwindow w = new Loadwindow(); w.Show(); BP.Description.description = BP.Description.description += "++ Applied some block property changes "; BP.setblueprint(BP.Blueprint); this.mainwindow.RenderBlueprint(); //Update(); dynamic bounds = BP.GetBounds(); int x1 = bounds.minx, y1 = bounds.maxx, z1 = bounds.miny, x2 = bounds.maxy, y2 = bounds.minz, z2 = bounds.maxz; this.Dispatcher.Invoke((Action)(() => {//this refer to form in WPF application if (filter_x1.Text != "") { x1 = Convert.ToInt32(filter_x1.Text); } if (filter_y1.Text != "") { y1 = Convert.ToInt32(filter_y1.Text); } if (filter_z1.Text != "") { z1 = Convert.ToInt32(filter_z1.Text); } if (filter_x2.Text != "") { x2 = Convert.ToInt32(filter_x2.Text); } if (filter_y2.Text != "") { y2 = Convert.ToInt32(filter_y2.Text); } if (filter_z2.Text != "") { z2 = Convert.ToInt32(filter_z2.Text); //0.1! = any } this.mainwindow.setMarker2((x1 + x2 + 0.0f) / 2, (y1 + y2 + 0.0f) / 2, (z1 + z2 + 0.0f) / 2, (x2 - x1), (y2 - y1), (z2 - z1)); })); w.Close(); }
private void filterupdate() { var l = new Loadwindow(); l.Show(); disableAll(); filter_output.Items.Clear(); if (Convert.ToInt32(filter_x1.Text) > Convert.ToInt32(filter_x2.Text)) { string h = filter_x1.Text; filter_x1.Text = filter_x2.Text; filter_x2.Text = h; } if (Convert.ToInt32(filter_y1.Text) > Convert.ToInt32(filter_y2.Text)) { string h = filter_y1.Text; filter_y1.Text = filter_y2.Text; filter_y2.Text = h; } if (Convert.ToInt32(filter_z1.Text) > Convert.ToInt32(filter_z2.Text)) { string h = filter_z1.Text; filter_z1.Text = filter_z2.Text; filter_z2.Text = h; } int x1 = Convert.ToInt32(filter_x1.Text); int y1 = Convert.ToInt32(filter_y1.Text); int z1 = Convert.ToInt32(filter_z1.Text); int x2 = Convert.ToInt32(filter_x2.Text); int y2 = Convert.ToInt32(filter_y2.Text); int z2 = Convert.ToInt32(filter_z2.Text); this.mainwindow.setMarker2((x1 + x2 + 0.0f) / 2, (y1 + y2 + 0.0f) / 2, (z1 + z2 + 0.0f) / 2, (x2 - x1), (y2 - y1), (z2 - z1)); string targetuuid = null; if (filter_type.SelectedIndex < 0) { filter_type.SelectedIndex = 0; } if (filter_type.SelectedIndex > 0) { targetuuid = ((Item)filter_type.SelectedItem).UUID; } //thread: if (filter != null && filter.IsAlive) { filter.Abort(); } filter = new Thread(() => { //filter correct blocks: int i = 0; foreach (dynamic body in blueprint.bodies) { foreach (dynamic child in body.childs) { if (child.color.ToString().StartsWith("#")) { child.color = child.color.ToString().Substring(1, 6).ToLower(); } dynamic realpos = BP.getposandbounds(child); if ((filtercolor == null || filtercolor == child.color.ToString()) && (targetuuid == null || targetuuid == child.shapeId.ToString()) && (x1 <= (int)realpos.pos.x && (int)realpos.pos.x + (int)realpos.bounds.x <= x2) && (y1 <= (int)realpos.pos.y && (int)realpos.pos.y + (int)realpos.bounds.y <= y2) && (z1 <= (int)realpos.pos.z && (int)realpos.pos.z + (int)realpos.bounds.z <= z2)) { dynamic listitem = new JObject(); listitem.pos = new JObject(); listitem.pos.x = (int)realpos.pos.x; listitem.pos.y = (int)realpos.pos.y; listitem.pos.z = (int)realpos.pos.z; listitem.bounds = new JObject(); listitem.bounds.x = (int)realpos.bounds.x; listitem.bounds.y = (int)realpos.bounds.y; listitem.bounds.z = (int)realpos.bounds.z; listitem.blockname = "unnamed shape" + child.shapeId.ToString(); listitem.index = i; if (Database.blocks.ContainsKey(child.shapeId.ToString())) { listitem.blockname = Database.blocks[child.shapeId.ToString()].Name; } listitem.color = child.color.ToString(); listitem.child = child.ToString(); this.Dispatcher.Invoke((Action)(() => { filter_output.Items.Add(listitem); })); } i++; } } if (blueprint.joints != null) { foreach (dynamic child in blueprint.joints) { if (child.color.ToString().StartsWith("#")) { child.color = child.color.ToString().Substring(1, 6).ToLower(); } dynamic c = child; c.pos = child.posA; c.xaxis = child.xaxisA; c.zaxis = child.zaxisA; dynamic realpos = BP.getposandbounds(c); realpos.pos = child.posA; if (!(Convert.ToInt32(child.zaxis.ToString()) > 0 || !(realpos.bounds.x != 1 || realpos.bounds.y != 1 || realpos.bounds.z != 1))) { int zaxis = Convert.ToInt32(child.zaxis.ToString()); if (zaxis == -1) { realpos.pos.x -= realpos.bounds.x - 1; } if (zaxis == -2) { realpos.pos.y -= realpos.bounds.y - 1; } if (zaxis == -3) { realpos.pos.z -= realpos.bounds.z - 1; } } if ((filtercolor == null || filtercolor == child.color.ToString()) && (targetuuid == null || targetuuid == child.shapeId.ToString()) && (x1 <= (int)realpos.pos.x && (int)realpos.pos.x + (int)realpos.bounds.x <= x2) && (y1 <= (int)realpos.pos.y && (int)realpos.pos.y + (int)realpos.bounds.y <= y2) && (z1 <= (int)realpos.pos.z && (int)realpos.pos.z + (int)realpos.bounds.z <= z2)) { dynamic listitem = new JObject(); listitem.pos = new JObject(); listitem.pos.x = (int)realpos.pos.x; listitem.pos.y = (int)realpos.pos.y; listitem.pos.z = (int)realpos.pos.z; listitem.bounds = new JObject(); listitem.bounds.x = (int)realpos.bounds.x; listitem.bounds.y = (int)realpos.bounds.y; listitem.bounds.z = (int)realpos.bounds.z; listitem.blockname = "unnamed shape" + child.shapeId.ToString(); if (Database.blocks.ContainsKey(child.shapeId.ToString())) { listitem.blockname = Database.blocks[child.shapeId.ToString()].Name; } listitem.color = child.color.ToString(); listitem.child = child.ToString(); listitem.index = i; this.Dispatcher.Invoke((Action)(() => { filter_output.Items.Add(listitem); })); } i++; } } }); filter.IsBackground = true; filter.Start(); l.Close(); }
public void Update() { if (uuidsbackup != BP.GetUsedUuids()) { usedblocks = new List <Item> { new Item("any", "*") }; foreach (string uuid in BP.GetUsedUuids()) { if (Database.blocks.ContainsKey(uuid)) { usedblocks.Add(new Item(Database.blocks[uuid].Name.ToString(), uuid)); // fill the combobox! only runs once! } } filter_type.Items.Clear(); foreach (Item useditem in usedblocks) { filter_type.Items.Add(useditem); } } uuidsbackup = BP.GetUsedUuids(); filter_type.SelectedIndex = 0; int i = 0; { backuplist = new JObject(); //fill 'backup'list with all childs! foreach (dynamic body in BP.Blueprint.bodies) { foreach (dynamic child in body.childs) { if (child.color.ToString().StartsWith("#")) { child.color = child.color.ToString().Substring(1); } child.blueprintIndex = i; child.blockname = Database.blocks[child.shapeId.ToString()].Name; dynamic realpos = BP.getposandbounds(child); if (backuplist[realpos.pos.x.ToString()] == null) { backuplist[realpos.pos.x.ToString()] = new JObject(); } if (backuplist[realpos.pos.x.ToString()][realpos.pos.y.ToString()] == null) { backuplist[realpos.pos.x.ToString()][realpos.pos.y.ToString()] = new JObject(); } if (backuplist[realpos.pos.x.ToString()][realpos.pos.y.ToString()][realpos.pos.z.ToString()] == null) { backuplist[realpos.pos.x.ToString()][realpos.pos.y.ToString()][realpos.pos.z.ToString()] = new JObject(); } if (backuplist[realpos.pos.x.ToString()][realpos.pos.y.ToString()][realpos.pos.z.ToString()][realpos.color.ToString().ToLower()] == null) { backuplist[realpos.pos.x.ToString()][realpos.pos.y.ToString()][realpos.pos.z.ToString()][realpos.color.ToString().ToLower()] = new JObject(); } if (backuplist[realpos.pos.x.ToString()][realpos.pos.y.ToString()][realpos.pos.z.ToString()][realpos.color.ToString().ToLower()][realpos.shapeId.ToString().ToLower()] == null) { backuplist[realpos.pos.x.ToString()][realpos.pos.y.ToString()][realpos.pos.z.ToString()][realpos.color.ToString().ToLower()][realpos.shapeId.ToString().ToLower()] = new JObject(); } backuplist[realpos.pos.x.ToString()][realpos.pos.y.ToString()][realpos.pos.z.ToString()][realpos.color.ToString().ToLower()][realpos.shapeId.ToString().ToLower()][i.ToString()] = child; i++; } } } //fill xyz: dynamic bounds = BP.GetBounds(); filter_x1.Text = bounds.minx.ToString(); filter_y1.Text = bounds.miny.ToString(); filter_z1.Text = bounds.minz.ToString(); filter_x2.Text = bounds.maxx.ToString(); filter_y2.Text = bounds.maxy.ToString(); filter_z2.Text = bounds.maxz.ToString(); filterupdate(); }
private void filter_output_SelectionChanged(object sender, SelectionChangedEventArgs e) { disableAll(); if (filter_output.SelectedIndex != -1) { var bc = new BrushConverter(); string selectedcolor = ((dynamic)filter_output.SelectedItem).color; string color = "#FF" + (selectedcolor.StartsWith("#") == true? selectedcolor.Substring(1): selectedcolor); //filter_output_color.Fill = (Brush)bc.ConvertFrom(color); //clear other options, enable/disable several dynamic selectedblock = ((dynamic)filter_output.SelectedItem); dynamic realpos = BP.getposandbounds(selectedblock); this.mainwindow.setMarker(Convert.ToInt32(realpos.pos.x) + (Convert.ToDouble(realpos.bounds.x) / 2), Convert.ToInt32(realpos.pos.y) + (Convert.ToDouble(realpos.bounds.y) / 2), Convert.ToDouble(realpos.pos.z) + (Convert.ToDouble(realpos.bounds.z) / 2)); selectedchildindex = selectedblock.blueprintIndex; Edit_general.Visibility = Visibility.Visible; new_x.Text = selectedblock.pos.x; new_y.Text = selectedblock.pos.y; new_z.Text = selectedblock.pos.z; new_color.Text = "#" + selectedblock.color; new_xaxis.Text = selectedblock.xaxis; new_zaxis.Text = selectedblock.zaxis; if (selectedblock.controller != null) // { if (selectedblock.controller.mode != null) //logic gate! { new_gatemode.SelectedIndex = selectedblock.controller.mode; Edit_gate.Visibility = Visibility.Visible; //mode 0-5 } if (selectedblock.controller.buttonMode != null)//sensor! { // colorMode & range & color new_sensorcolormode.IsChecked = selectedblock.controller.colorMode; if (selectedblock.controller.colorMode == null) { new_sensorcolormode.IsChecked = false; } new_sensorrange.Text = selectedblock.controller.range; new_sensorcolor.Text = "#" + selectedblock.controller.color; if (selectedblock.controller.color == null) { new_sensorcolor.Text = "#eeeeee"; } Edit_sensor.Visibility = Visibility.Visible; } if (selectedblock.controller.luminance != null)//light! { //coneAngle & luminance new_coneangle.Text = selectedblock.controller.coneAngle; new_luminance.Text = selectedblock.controller.luminance; Edit_lamp.Visibility = Visibility.Visible; } if (selectedblock.controller.seconds != null)//timer { //seconds ticks new_timerseconds.Text = selectedblock.controller.seconds; new_timerticks.Text = selectedblock.controller.ticks; Edit_Timer.Visibility = Visibility.Visible; } if (selectedblock.controller.timePerFrame != null)//controller! { //playMode timePerFrame joints new_controllerloopmode.IsChecked = selectedblock.controller.playMode; new_controllertimeperframe.Text = selectedblock.controller.timePerFrame; new_controllercontrolls.Items.Clear(); if (selectedblock.controller.joints != null) { foreach (dynamic joint in selectedblock.controller.joints) { joint.controller0 = joint.frames[0].targetAngle.ToString(); joint.controller1 = joint.frames[1].targetAngle.ToString(); joint.controller2 = joint.frames[2].targetAngle.ToString(); joint.controller3 = joint.frames[3].targetAngle.ToString(); joint.controller4 = joint.frames[4].targetAngle.ToString(); joint.controller5 = joint.frames[5].targetAngle.ToString(); joint.controller6 = joint.frames[6].targetAngle.ToString(); joint.controller7 = joint.frames[7].targetAngle.ToString(); joint.controller8 = joint.frames[8].targetAngle.ToString(); joint.controller9 = joint.frames[9].targetAngle.ToString(); new_controllercontrolls.Items.Add(joint); } } /* * if (selectedblock.controller.controllers != null) * foreach (dynamic joint in selectedblock.controller.frames) * { * joint.controller0 = joint.frames[0].targetAngle.ToString(); * joint.controller1 = joint.frames[1].targetAngle.ToString(); * joint.controller2 = joint.frames[2].targetAngle.ToString(); * joint.controller3 = joint.frames[3].targetAngle.ToString(); * joint.controller4 = joint.frames[4].targetAngle.ToString(); * joint.controller5 = joint.frames[5].targetAngle.ToString(); * joint.controller6 = joint.frames[6].targetAngle.ToString(); * joint.controller7 = joint.frames[7].targetAngle.ToString(); * joint.controller8 = joint.frames[8].targetAngle.ToString(); * joint.controller9 = joint.frames[9].targetAngle.ToString(); * new_controllercontrolls.Items.Add(joint); * * }*/ Edit_controller.Visibility = Visibility.Visible; } } button_render.IsEnabled = true; } }
//Thread filter; private void filter_output_update() { { dynamic bounds = BP.GetBounds(); int x1 = bounds.minx, y1 = bounds.maxx, z1 = bounds.miny, x2 = bounds.maxy, y2 = bounds.minz, z2 = bounds.maxz; string type = "*";//nullable! = any this.Dispatcher.Invoke((Action)(() => {//this refer to form in WPF application if (filter_output.Items.Count > 0) { filter_output.Items.Clear(); } if (filter_x1.Text != "") { x1 = Convert.ToInt32(filter_x1.Text); } if (filter_y1.Text != "") { y1 = Convert.ToInt32(filter_y1.Text); } if (filter_z1.Text != "") { z1 = Convert.ToInt32(filter_z1.Text); } if (filter_x2.Text != "") { x2 = Convert.ToInt32(filter_x2.Text); } if (filter_y2.Text != "") { y2 = Convert.ToInt32(filter_y2.Text); } if (filter_z2.Text != "") { z2 = Convert.ToInt32(filter_z2.Text); //0.1! = any } if (filter_type.SelectedIndex < 0) { filter_type.SelectedIndex = 0; } if (filter_type.SelectedIndex >= 0) { type = ((Item)filter_type.SelectedItem).UUID; } this.mainwindow.setMarker2((x1 + x2 + 0.0f) / 2, (y1 + y2 + 0.0f) / 2, (z1 + z2 + 0.0f) / 2, (x2 - x1), (y2 - y1), (z2 - z1)); })); string color = filtercolor;//nullable! = any for (int x = x1; x <= x2; x++) { if (backuplist[x.ToString()] != null) { for (int y = y1; y < y2; y++) { if (backuplist[x.ToString()][y.ToString()] != null) { for (int z = z1; z < z2; z++) { if (backuplist[x.ToString()][y.ToString()][z.ToString()] != null) { if (color == null) { foreach (dynamic xyzcolor in backuplist[x.ToString()][y.ToString()][z.ToString()]) { if (type == "*") { foreach (dynamic childuuid in xyzcolor.Value) { foreach (dynamic child in childuuid.Value) { this.Dispatcher.Invoke((Action)(() => { //this refer to form in WPF application filter_output.Items.Add(child.Value); //any color any type })); } } } else { if (xyzcolor.Value[type.ToLower()] != null) { foreach (dynamic child in xyzcolor.Value[type.ToLower()]) { this.Dispatcher.Invoke((Action)(() => { //this refer to form in WPF application filter_output.Items.Add(child.Value); //any color , one type })); } } } } } else { if (color.StartsWith("#")) { color = color.Substring(1).ToLower(); } if (backuplist[x.ToString()][y.ToString()][z.ToString()][color] != null) { if (type == "*") { foreach (dynamic childuuid in backuplist[x.ToString()][y.ToString()][z.ToString()][color]) { foreach (dynamic child in childuuid.Value) { this.Dispatcher.Invoke((Action)(() => { //this refer to form in WPF application filter_output.Items.Add(child.Value); //one color , any type })); } } } else { if (backuplist[x.ToString()][y.ToString()][z.ToString()][color][type] != null) { foreach (dynamic child in backuplist[x.ToString()][y.ToString()][z.ToString()][color][type]) { this.Dispatcher.Invoke((Action)(() => { //this refer to form in WPF application filter_output.Items.Add(child.Value); //one color, one type })); } } } } } } } } } } } try { this.Dispatcher.Invoke((Action)(() => {//this refer to form in WPF application disableAll(); })); } catch { } } }
private void Click_requiredmods(object sender, RoutedEventArgs e) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://scrapmechanic.xesau.eu/uuidservice/get_mods"); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; string postData = ""; foreach (string uuid in BP.GetUsedUuids()) { postData += "&uuid[]=" + uuid; } postData = postData.Substring(1); byte[] bytes = Encoding.UTF8.GetBytes(postData); request.ContentLength = bytes.Length; Stream requestStream = request.GetRequestStream(); requestStream.Write(bytes, 0, bytes.Length); WebResponse response = request.GetResponse(); Stream stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream); var result = reader.ReadToEnd(); dynamic Mods = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(result); foreach (dynamic missingmod in Mods.missing) { if (Database.blocks.ContainsKey(missingmod.ToString())) { string modid = System.IO.Path.GetFileName(Database.blocks[missingmod.ToString()].id.ToString()); dynamic mod = new JObject(); mod.name = Database.blocks[missingmod.ToString()].Mod; mod.ok = "✔"; mod.author = "Unavailable, service couldn't find it"; mod.url = "http://steamcommunity.com/workshop/filedetails/?id=" + modid; if (!((JArray)Mods.mods).Contains(mod)) { Mods.mods.Add(mod); } } else { MessageBox.Show("couldn't find required mod for: " + missingmod.ToString()); } } foreach (dynamic mod in Mods.mods) { string fileId = mod.url.ToString().Substring(51); if (Database.usedmods.ContainsKey(fileId)) { mod.ok = "✔"; } else if (mod.ok == null) { mod.ok = "X"; } } new required_mods(Mods).Show(); stream.Dispose(); reader.Dispose(); }
private void button_render_Click(object sender, RoutedEventArgs e) { //apply changes if (Convert.ToInt32(filter_x1.Text) > Convert.ToInt32(filter_x2.Text)) { string h = filter_x1.Text; filter_x1.Text = filter_x2.Text; filter_x2.Text = h; } if (Convert.ToInt32(filter_y1.Text) > Convert.ToInt32(filter_y2.Text)) { string h = filter_y1.Text; filter_y1.Text = filter_y2.Text; filter_y2.Text = h; } if (Convert.ToInt32(filter_z1.Text) > Convert.ToInt32(filter_z2.Text)) { string h = filter_z1.Text; filter_z1.Text = filter_z2.Text; filter_z2.Text = h; } int x1 = Convert.ToInt32(filter_x1.Text); int y1 = Convert.ToInt32(filter_y1.Text); int z1 = Convert.ToInt32(filter_z1.Text); int x2 = Convert.ToInt32(filter_x2.Text); int y2 = Convert.ToInt32(filter_y2.Text); int z2 = Convert.ToInt32(filter_z2.Text); string targetuuid = null; if (filter_type.SelectedIndex < 0) { filter_type.SelectedIndex = 0; } if (filter_type.SelectedIndex > 0) { targetuuid = ((Item)filter_type.SelectedItem).UUID; } dynamic blueprint = BP.Blueprint; if (filtercolor != null && filtercolor.StartsWith("#")) { filtercolor = filtercolor.Substring(1, 6).ToLower(); } foreach (dynamic body in blueprint.bodies) { foreach (dynamic child in body.childs) { if (child.color.ToString().StartsWith("#")) { child.color = child.color.ToString().Substring(1, 6).ToLower(); } dynamic realpos = BP.getposandbounds(child); if ((filtercolor == null || filtercolor == child.color.ToString()) && (targetuuid == null || targetuuid == child.shapeId.ToString()) && (x1 <= (int)realpos.pos.x && (int)realpos.pos.x + (int)realpos.bounds.x <= x2) && (y1 <= (int)realpos.pos.y && (int)realpos.pos.y + (int)realpos.bounds.y <= y2) && (z1 <= (int)realpos.pos.z && (int)realpos.pos.z + (int)realpos.bounds.z <= z2)) { child.pos.x = child.pos.x + Convert.ToInt32(new_x.Text); child.pos.y = child.pos.y + Convert.ToInt32(new_y.Text); child.pos.z = child.pos.z + Convert.ToInt32(new_z.Text); if (new_color.Text != "") { child.color = new_color.Text.ToString().Substring(1, 6); } if (Edit_gate.IsVisible && new_gatemode.SelectedIndex > 0) { child.controller.mode = new_gatemode.SelectedIndex - 1; } if (Edit_lamp.IsVisible) { if (new_luminance.Text != "") { child.controller.luminance = Convert.ToInt32(new_luminance.Text); } if (new_coneangle.Text != "") { child.controller.coneAngle = Convert.ToInt32(new_coneangle.Text); } if (new_lampcolor.Text != "") { child.controller.color = new_lampcolor.Text; } } if (Edit_sensor.IsVisible && (new_sensorrange.Text != "" || new_sensorcolormode.IsChecked == true)) { if (new_sensorrange.Text != "") { child.controller.range = Convert.ToInt32(new_sensorrange.Text); } child.controller.colorMode = new_sensorcolormode.IsChecked == true?true:false; child.controller.color = new_sensorcolor.Text; } if (Edit_Timer.IsVisible && new_timerseconds.Text != null) { child.controller.seconds = Convert.ToInt32(new_timerseconds); child.controller.ticks = Convert.ToInt32(new_timerticks); } } } } if (blueprint.joints != null) { foreach (dynamic child in blueprint.joints) { if (child.color.ToString().StartsWith("#")) { child.color = child.color.ToString().Substring(1, 6); } dynamic c = child; c.pos = child.posA; c.xaxis = child.xaxisA; c.zaxis = child.zaxisA; dynamic realpos = BP.getposandbounds(c); realpos.pos = child.posA; if (!(Convert.ToInt32(child.zaxis.ToString()) > 0 || !(realpos.bounds.x != 1 || realpos.bounds.y != 1 || realpos.bounds.z != 1))) { int zaxis = Convert.ToInt32(child.zaxis.ToString()); if (zaxis == -1) { realpos.pos.x -= realpos.bounds.x - 1; } if (zaxis == -2) { realpos.pos.y -= realpos.bounds.y - 1; } if (zaxis == -3) { realpos.pos.z -= realpos.bounds.z - 1; } } if ((filtercolor == null || filtercolor == child.color.ToString()) && (targetuuid == null || targetuuid == child.shapeId.ToString()) && (x1 <= (int)realpos.pos.x && (int)realpos.pos.x + (int)realpos.bounds.x <= x2) && (y1 <= (int)realpos.pos.y && (int)realpos.pos.y + (int)realpos.bounds.y <= y2) && (z1 <= (int)realpos.pos.z && (int)realpos.pos.z + (int)realpos.bounds.z <= z2)) { child.posA.x = child.posA.x + Convert.ToInt32(new_x.Text); child.posA.y = child.posA.y + Convert.ToInt32(new_y.Text); child.posA.z = child.posA.z + Convert.ToInt32(new_z.Text); if (new_color.Text != "") { child.color = new_color.Text.ToString().Substring(1, 6); } } } } Loadwindow w = new Loadwindow(); w.Show(); BP.Description.description = BP.Description.description += "++ Applied some area property changes "; BP.setblueprint(BP.Blueprint); this.mainwindow.RenderBlueprint(); //Update(); filterupdate(); w.Close(); }
private void WireIt(dynamic a, string sourcecolor, string destinationcolor, string sourcetype, string destinationtype, int offsetx, int offsety, int offsetz, string offsetcolor) { Dictionary <int, Controller> controllers = new Dictionary <int, Controller>(); bool dirx = checkBox_X.IsChecked == true; bool diry = checkBox_Y.IsChecked == true; bool dirz = checkBox_Z.IsChecked == true; bool self = checkBox_0.IsChecked == true; bool matchoffset = MatchOffset.IsChecked == true; //safemode enable? Dictionary <string, List <int> > filtercrap = new Dictionary <string, List <int> >(); //can be glitchwelded //x.y.z = int foreach (dynamic body in BP.Blueprint.bodies) { foreach (dynamic child in body.childs) { if (child.controller != null) { dynamic rpos = BP.getposandbounds(child); int x = Convert.ToInt32(rpos.pos.x.ToString()); int y = Convert.ToInt32(rpos.pos.y.ToString()); int z = Convert.ToInt32(rpos.pos.z.ToString()); string color = child.color.ToString().ToLower(); if (color.StartsWith("#")) { color = color.Substring(1, 6); } int id = Convert.ToInt32(child.controller.id.ToString()); controllers.Add(id, new Controller { id = id, x = x, y = y, z = z, color = color, uuid = child.shapeId.ToString(), connections = new List <int>() }); string key = x.ToString() + "." + y.ToString() + "." + z.ToString(); if (!filtercrap.ContainsKey(key)) { filtercrap.Add(key, new List <int> { id }); } else { filtercrap[key].Add(id); } } } } if (matchoffset) {//filter only the block with color,type,offset from source foreach (Controller source in controllers.Values) { if ((sourcecolor == null || sourcecolor == source.color) && (sourcetype == source.uuid)) { foreach (Controller destination in controllers.Values) { if ((destinationcolor == null || destinationcolor == destination.color) && (destinationtype == null || destinationtype == destination.uuid) && (self || !source.Equals(destination)) && (dirx || source.x + offsetx == destination.x) && (diry || source.y + offsety == destination.y) && (dirz || source.z + offsetz == destination.z)) { source.connections.Add(destination.id); } } } } } else//filter all blocks no offset with col&type, then get the ones offset from them (any color, any type) { foreach (Controller source in controllers.Values) { if ((sourcecolor == null || sourcecolor == source.color) && (sourcetype == source.uuid)) { foreach (Controller destination in controllers.Values) { if ((destinationcolor == null || destinationcolor == destination.color) && (destinationtype == null || destinationtype == destination.uuid) && (self || !source.Equals(destination)) && (dirx || source.x == destination.x) && (diry || source.y == destination.y) && (dirz || source.z == destination.z)) { string key = (offsetx + destination.x).ToString() + "." + (offsety + destination.y).ToString() + "." + (offsetz + destination.z).ToString(); //get block offset from destination if (filtercrap.ContainsKey(key)) { source.connections.AddRange(filtercrap[key]); } //source.connections.Add(destination.id); } } } } } //apply controllers to bp: int amountwired = 0; foreach (dynamic body in BP.Blueprint.bodies) { foreach (dynamic child in body.childs) { if (child.controller != null && controllers.ContainsKey(Convert.ToInt32(child.controller.id.ToString()))) { int id = Convert.ToInt32(child.controller.id.ToString()); if (child.controller.controllers == null) { child.controller.controllers = new JArray(); } if (controllers[id].connections != null) { foreach (int destid in controllers[id].connections) { child.controller.controllers.Add(new JObject { ["id"] = destid }); amountwired++; } } } } } new System.Threading.Thread(new System.Threading.ThreadStart(() => { MessageBox.Show("Successfully made " + amountwired + " connections! :D"); })).Start(); if (amountwired > 0) { mainwindow.TextBox_Description.Text += "\n--> " + amountwired + " connections made\n"; BP.Description.description = BP.Description.description + "\n--> " + amountwired + " connections made\n"; } mainwindow.RenderWires(); #region somecode /* * dynamic controllersold = new JObject(); * * dynamic sources = new JObject(); * * foreach (dynamic body in blueprint.bodies) * foreach (dynamic child in body.childs) * { * if (child.controller != null) * { * dynamic rpos = BP.getposandbounds(child); * string x = rpos.pos.x.ToString(); * string y = rpos.pos.y.ToString(); * string z = rpos.pos.z.ToString(); * string color = child.color.ToString(); * if (color.StartsWith("#")) * color = color.Substring(1, 6); * //child.shapeId.ToString() * // Convert.ToInt32(child.controller.id.ToString()) * dynamic controller = new JObject { [x] = new JObject { [y] = new JObject { [z] = new JObject { [child.color.ToString()] = new JObject { [child.shapeId.ToString()] = new JObject { [color] = Convert.ToInt32(child.controller.id.ToString()) } } } } } }; * controllersold.Merge(controller); * if ((sourcecolor == null || sourcecolor == color) && (sourcetype == null || sourcetype == child.shapeId.ToString())) * sources.Merge(controller); * } * } * * * dynamic result = new JObject();//result.DeepClone(); * //Newtonsoft.Json.Linq.JProperty // keypair * * if (matchoffset) //ON * {//filter only the block with color,type,offset from source * dynamic searchfrom = controllersold.DeepClone(); * if (dirx) * { * result = searchfrom; * } * else * { * foreach(JProperty Jprop in sources) //Jprop.Name = "X" * { * string coord = (Convert.ToInt32(Jprop.Name) + offsetx).ToString(); * if (searchfrom[coord] != null) * { * result.Merge(new JObject { [coord] = searchfrom[coord] }); * } * } * } * * searchfrom = result.DeepClone(); * result = new JObject(); * if (diry) * { * result = searchfrom; * } * else * { * foreach (JProperty JpropSource in sources) * { * string coord = (Convert.ToInt32(JpropSource.Name) + offsetx).ToString(); * if (searchfrom[coord] != null) * { * result.Merge(new JObject { [coord] = searchfrom[coord] }); * } * } * } * } * else * {//filter all blocks no offset with col&type, then get the ones offset from them (any color, any type) * * } * * * foreach (dynamic body in blueprint.bodies) * foreach(dynamic child in body.childs) * { * if(child.controller != null && (sourcetype == null || sourcetype == child.shapeId.ToString())) * { * string color = child.color.ToString(); if (color.StartsWith("#")) color = color.Substring(1, 6); * if(sourcecolor == null || color == sourcecolor) * { * dynamic rpos = BP.getposandbounds(child); * int x = Convert.ToInt32(rpos.pos.x.ToString()); * int y = Convert.ToInt32(rpos.pos.y.ToString()); * int z = Convert.ToInt32(rpos.pos.z.ToString()); * * * * } * } * } * * * * * if (blueprint == "")//false * using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.scrapshitConnectionString)) * { * //conn.ConnectionString = "MyDB";c * int i = 0; * conn.Open(); * using (SqlCommand insertCommand = new SqlCommand("DELETE FROM Connections", conn)) * { * insertCommand.ExecuteNonQuery(); * } * foreach (dynamic body in blueprint.bodies) * foreach (dynamic child in body.childs) * { * if(child.controller != null) * { * dynamic rpos = BP.getposandbounds(child); * string x = rpos.pos.x.ToString(); * string y = rpos.pos.y.ToString(); * string z = rpos.pos.z.ToString(); * string color = child.color.ToString(); * if (color.StartsWith("#")) * color = color.Substring(1, 6); * * using (SqlCommand insertCommand = new SqlCommand("INSERT INTO Connections (Controller_Id, posx, posy, posz, color, uuid) VALUES (@controllerid, @x, @y, @z, @color, @uuid)", conn)) * { * insertCommand.Parameters.AddWithValue("@controllerid", Convert.ToInt32(child.controller.id.ToString())); * insertCommand.Parameters.AddWithValue("@x", x); * insertCommand.Parameters.AddWithValue("@y", y); * insertCommand.Parameters.AddWithValue("@z", z); * insertCommand.Parameters.AddWithValue("@color", color); * insertCommand.Parameters.AddWithValue("@uuid", child.shapeId.ToString()); * try * { * i+= insertCommand.ExecuteNonQuery(); * } * catch (Exception e) * { * MessageBox.Show(e.Message); * } * * } * } * } * * * * //SqlCommand cmd = new SqlCommand("SELECT * FROM Connections WHERE login = @login", conn); * * //find all sources "SELECT * AS 'Sources' FROM Connections" + "WHERE color = @sourcecolor AND uuid = @sourceuuid" * //find all dests? * * * //string cmd = "SELECT * FROM Description" * //cmd+= "Where uuid = @uuid" * //cmd+= @"AND color = @color" * * //all with uuid x / other / all other (match offset block color) * //all with color / all other / all other (match offset block color) * //all with x + offsetx / other(all in this dir) /x * //all with y + offsety / other / y * //all with z + offsetz /other / z * //exclude self wire? * //if match offset block color search offset from x y z found blocks (from all, check all current found + offset with color x and type x) * * } * * * * //<x, y, z, color, shapeId>, controllerid * Dictionary<Tuple<int, int, int, string, string>, int> dict = new Dictionary<Tuple<int, int, int, string, string>, int>(); * * Dictionary<int, Dictionary<int, Dictionary<int, int>>> testdict = new Dictionary<int, Dictionary<int, Dictionary<int, int>>>(); * //testdict[5][2][3] = 5; * */ #endregion }
private void Button_Create_Click(object sender, RoutedEventArgs e) { float X = Convert.ToInt32(TextBox_X.Text); float Y = Convert.ToInt32(TextBox_Y.Text); float Z = Convert.ToInt32(TextBox_Z.Text); float t = Convert.ToInt32(TextBox_thickness.Text); dynamic Sphere = new JObject(); Sphere.bodies = new JArray(); Sphere.bodies.Add(new JObject() as dynamic); Sphere.bodies[0].childs = new JArray(); dynamic blocksXYZ = new JObject(); int amountgenerated = 0; for (float x = -X; x < X; x++) { for (float y = -Y; y < Y; y++) { for (float z = -Z; z < Z; z++) { if ((Math.Pow(x / X, 2) + Math.Pow(y / Y, 2) + Math.Pow(z / Z, 2)) < 0.95 && (Math.Pow(x / (X - t), 2) + Math.Pow((y) / (Y - t), 2) + Math.Pow(z / (Z - t), 2)) > 0.95) { if (blocksXYZ[x.ToString()] == null) { blocksXYZ[x.ToString()] = new JObject(); } if (blocksXYZ[x.ToString()][y.ToString()] == null) { blocksXYZ[x.ToString()][y.ToString()] = new JObject(); } if (blocksXYZ[x.ToString()][y.ToString()][z.ToString()] == null) { blocksXYZ[x.ToString()][y.ToString()][z.ToString()] = new JObject(); } dynamic bounds = new JObject(); bounds.x = 1; bounds.y = 1; bounds.z = 1; blocksXYZ[x.ToString()][y.ToString()][z.ToString()].bounds = bounds; amountgenerated++; } } } } foreach (dynamic x in blocksXYZ) { foreach (dynamic y in x.Value) { foreach (dynamic z in y.Value) { dynamic bounds = z.Value.bounds; if (bounds != null) { for (int i = Convert.ToInt32(z.Name) + 1; i < 64; i++) { if (blocksXYZ[x.Name][y.Name][i.ToString()] != null && blocksXYZ[x.Name][y.Name][i.ToString()].bounds != null) { blocksXYZ[x.Name][y.Name][i.ToString()].bounds = null; blocksXYZ[x.Name][y.Name][z.Name].bounds.z = Convert.ToInt32(blocksXYZ[x.Name][y.Name][z.Name].bounds.z) + 1; } else { break; } } } } } } foreach (dynamic x in blocksXYZ) { foreach (dynamic y in x.Value) { foreach (dynamic z in y.Value) { dynamic bounds = z.Value.bounds; if (bounds != null) { for (int i = Convert.ToInt32(y.Name) + 1; i < 64; i++) { if (blocksXYZ[x.Name][i.ToString()] != null && blocksXYZ[x.Name][i.ToString()][z.Name] != null && blocksXYZ[x.Name][i.ToString()][z.Name].bounds != null && blocksXYZ[x.Name][i.ToString()][z.Name].bounds.z == blocksXYZ[x.Name][y.Name][z.Name].bounds.z) { blocksXYZ[x.Name][i.ToString()][z.Name].bounds = null; blocksXYZ[x.Name][y.Name][z.Name].bounds.y = Convert.ToInt32(blocksXYZ[x.Name][y.Name][z.Name].bounds.y) + 1; } else { break; } } } } } } foreach (dynamic x in blocksXYZ) { foreach (dynamic y in x.Value) { foreach (dynamic z in y.Value) { dynamic bounds = z.Value.bounds; if (bounds != null) { for (int i = Convert.ToInt32(x.Name) + 1; i < 64; i++) { if (blocksXYZ[i.ToString()] != null && blocksXYZ[i.ToString()][y.Name] != null && blocksXYZ[i.ToString()][y.Name][z.Name] != null && blocksXYZ[i.ToString()][y.Name][z.Name].bounds != null && blocksXYZ[i.ToString()][y.Name][z.Name].bounds.z == blocksXYZ[x.Name][y.Name][z.Name].bounds.z && blocksXYZ[i.ToString()][y.Name][z.Name].bounds.y == blocksXYZ[x.Name][y.Name][z.Name].bounds.y) { blocksXYZ[i.ToString()][y.Name][z.Name].bounds = null; blocksXYZ[x.Name][y.Name][z.Name].bounds.x = Convert.ToInt32(blocksXYZ[x.Name][y.Name][z.Name].bounds.x) + 1; } else { break; } } } } } } foreach (dynamic x in blocksXYZ) { foreach (dynamic y in x.Value) { foreach (dynamic z in y.Value) { if (z.Value.bounds != null) { Sphere.bodies[0].childs.Add(block(Convert.ToInt32(x.Name), Convert.ToInt32(y.Name), Convert.ToInt32(z.Name), z.Value.bounds)); } } } } if (amountgenerated > 0) { string message = "++ An ellipsoid with " + amountgenerated + " blocks has been generated!"; //MessageBox.Show(message+"\n\nOptimized to: "+count+" shapes"); Random r = new Random(); string blueprintpath = Database.User_ + "\\Blueprints\\GeneratedEllipsoid-" + r.Next() + r.Next(); dynamic description = new JObject(); description.description = "generated ellipsoid"; description.name = "generated sphere" + r.Next(); description.type = "Blueprint"; description.version = 0; if (BP.Blueprintpath == null) {//no blueprint exists, initialize new one new BP(blueprintpath, Sphere, description); } else {//overwrite current blueprint BP.setblueprint(Sphere); BP.Description.description += message; } mainwindow.RenderBlueprint(); } else { MessageBox.Show("no ellipsoid has been generated"); } }
//Wire it! private void Button1_Click(object sender, RoutedEventArgs e) {//WIRE IT! if (comboBox_items1.SelectedIndex != -1 && comboBox_items2.SelectedIndex != -1 && BP.Blueprint != null) { dynamic backupbp = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(BP.Blueprint.ToString()); string sourcecolor = textBox_color1.Text.ToLower(); string destinationcolor = textBox_color2.Text.ToLower(); Connectable sourceblock = (Connectable)comboBox_items1.SelectedItem; Connectable destinationblock = (Connectable)comboBox_items2.SelectedItem; int offsetx = Convert.ToInt32(textBox_X.Text); int offsety = Convert.ToInt32(textBox_Y.Text); int offsetz = Convert.ToInt32(textBox_Z.Text); if (sourcecolor.Length == 7) { sourcecolor = sourcecolor.Substring(1, 6); } else { sourcecolor = null; } if (destinationcolor.Length == 7) { destinationcolor = destinationcolor.Substring(1, 6); } else { destinationcolor = null; } //try { WireIt(null, sourcecolor, destinationcolor, sourceblock.UUID, destinationblock.UUID, offsetx, offsety, offsetz, destinationcolor); } //catch (Exception ex) { // MessageBox.Show(ex.Message + "\n\n Blueprint connections abrupted\nrestoring blueprint", "ERROR"); //BP.setblueprint(backupbp); } if (false) { #region oldcode //list all destionationblocks and their ID's dynamic destids = new JObject(); int minx = 10000, maxx = -10000, miny = 10000, maxy = -10000, minz = 10000, maxz = -10000; //loop over all blocks: foreach (dynamic body in BP.Blueprint.bodies) { foreach (dynamic child in body.childs) { if (child.shapeId.Value.ToLower() == destinationblock.UUID.ToLower() /*&& (child.color.Value.ToLower() == destinationcolor.ToLower() || "#"+child.color.Value.ToLower() == destinationcolor.ToLower() || destinationcolor == "" || destinationcolor == "#")*/) { dynamic dest = BP.getposandbounds(child);//outputs corrected child (default rotation, correct position) string x = dest.pos.x.ToString(); string y = dest.pos.y.ToString(); string z = dest.pos.z.ToString(); if (destids[x] == null) { destids[x] = new JObject(); } if (destids[x][y] == null) { destids[x][y] = new JObject(); } if (destids[x][y][z] == null) { destids[x][y][z] = new JObject(); } if (destids[x][y][z].ids == null) { destids[x][y][z].ids = new JArray(); } dynamic id = new JObject(); id.id = child.controller.id; destids[x][y][z].ids.Add(id); destids[x][y][z].color = child.color; //get whole creation bounds: if (dest.pos.x < minx) { minx = dest.pos.x; } if (dest.pos.x > maxx) { maxx = dest.pos.x; } if (dest.pos.y < miny) { miny = dest.pos.y; } if (dest.pos.y > maxy) { maxy = dest.pos.y; } if (dest.pos.z < minz) { minz = dest.pos.z; } if (dest.pos.z > maxz) { maxz = dest.pos.z; } /* {//test * if (destids[x + "." + y + "." + z] == null) destids[x + "." + y + "." + z] = new JArray(); * dynamic blockproperties = new JObject(); * blockproperties.id = new JObject(); * blockproperties.id.id = child.controller.id; * blockproperties.uuid = child.shapeId; * if (child.color.ToString().StartsWith("#")) child.color = child.color.ToString().subString(1); * blockproperties.color = child.color; * destids[x + "." + y + "." + z].Add(blockproperties); * }*/ } } } if (BP.Blueprint.joints != null) { foreach (dynamic child in BP.Blueprint.joints) { if (child.shapeId.Value.ToLower() == destinationblock.UUID.ToLower() /*&& (child.color.Value.ToLower() == destinationcolor.ToLower() || "#"+child.color.Value.ToLower() == destinationcolor.ToLower() || destinationcolor == "" || destinationcolor == "#")*/) { dynamic dest = (child);//outputs corrected child (default rotation, correct position) string x = dest.pos.x.ToString(); string y = dest.pos.y.ToString(); string z = dest.pos.z.ToString(); if (destids[x] == null) { destids[x] = new JObject(); } if (destids[x][y] == null) { destids[x][y] = new JObject(); } if (destids[x][y][z] == null) { destids[x][y][z] = new JObject(); } if (destids[x][y][z].ids == null) { destids[x][y][z].ids = new JArray(); } dynamic id = new JObject(); id.id = child.controller.id; destids[x][y][z].ids.Add(id); destids[x][y][z].color = child.color; //get whole creation bounds: if (dest.pos.x < minx) { minx = dest.pos.x; } if (dest.pos.x > maxx) { maxx = dest.pos.x; } if (dest.pos.y < miny) { miny = dest.pos.y; } if (dest.pos.y > maxy) { maxy = dest.pos.y; } if (dest.pos.z < minz) { minz = dest.pos.z; } if (dest.pos.z > maxz) { maxz = dest.pos.z; } } } } int amountwired = 0; try { //can be improved! foreach (dynamic body in BP.Blueprint.bodies) { foreach (dynamic child in body.childs) { if (child.shapeId.Value.ToLower() == sourceblock.UUID.ToLower() && (child.color.Value.ToLower() == sourcecolor.ToLower() || "#" + child.color.Value.ToLower() == sourcecolor.ToLower() || sourcecolor == "" || sourcecolor == "#")) { //COLOR AND UUID CORRECT, FURTHER WIRING PROCESS: dynamic source = BP.getposandbounds(child); //outputs corrected child (default rotation, correct position) string x = source.pos.x.ToString(); string y = source.pos.y.ToString(); string z = source.pos.z.ToString(); if (checkBox_X.IsChecked == false) { minx = source.pos.x; maxx = source.pos.x;//bounds? } if (checkBox_Y.IsChecked == false) { miny = source.pos.y; maxy = source.pos.y; } if (checkBox_Z.IsChecked == false) { minz = source.pos.z; maxz = source.pos.z; } string color = child.color.ToString(); if (color.StartsWith("#")) { color.Substring(1, 6); } for (int i = minx; i <= maxx; i++) { if (destids[i.ToString()] != null) { for (int j = miny; j <= maxy; j++) { if (destids[i.ToString()][j.ToString()] != null) { for (int k = minz; k <= maxz; k++) { if (destids[i.ToString()][j.ToString()][k.ToString()] != null) { if (destids[i.ToString()][j.ToString()][k.ToString()].color.ToString().ToLower() == destinationcolor.ToLower() || "#" + destids[i.ToString()][j.ToString()][k.ToString()].color.ToString().ToLower() == destinationcolor.ToLower() || destinationcolor == "" || destinationcolor == "#") { if (destids[(i + Convert.ToInt32(textBox_X.Text)).ToString()] != null && destids[(i + Convert.ToInt32(textBox_X.Text)).ToString()][(j + Convert.ToInt32(textBox_Y.Text)).ToString()] != null && destids[(i + Convert.ToInt32(textBox_X.Text)).ToString()][(j + Convert.ToInt32(textBox_Y.Text)).ToString()][(k + Convert.ToInt32(textBox_Z.Text)).ToString()] != null) { foreach (dynamic id in destids[(i + Convert.ToInt32(textBox_X.Text)).ToString()][(j + Convert.ToInt32(textBox_Y.Text)).ToString()][(k + Convert.ToInt32(textBox_Z.Text)).ToString()].ids) { if (!(checkBox_0.IsChecked == false && child.controller.id == id.id)) { if (child.controller.controllers == null) { child.controller.controllers = new JArray(); } child.controller.controllers.Add(id); amountwired++; } } } } } } } } } } /* * for (int i = minx; i <= maxx; i++) * for (int j = miny; j <= maxy; j++) * for (int k = minz; k <= maxz; k++) * if ( * destids[i.ToString() + "." + j.ToString() + "." + k.ToString()] != null && * destids[(i + Convert.ToInt32(textBox_X.Text)).ToString() + "." + * (j + Convert.ToInt32(textBox_Y.Text)).ToString() + "." + * (k + Convert.ToInt32(textBox_Z.Text)).ToString()] != null * ) * foreach ( dynamic destblocknooffset in destids[i.ToString() + "." + j.ToString() + "." + k.ToString()]) * if((destblocknooffset.color.ToLower() == destinationcolor.ToLower() || destinationcolor == "" || destinationcolor == "#")) * foreach(dynamic blockoffset in destids[(i + Convert.ToInt32(textBox_X.Text)).ToString() + "." + (j + Convert.ToInt32(textBox_Y.Text)).ToString() + "." + (k + Convert.ToInt32(textBox_Z.Text)).ToString()]) * if(!(checkBox_0.IsChecked == false && child.controller.id == blockoffset.id.id)) * { * if (child.controller.controllers == null) * child.controller.controllers = new JArray(); * child.controller.controllers.Add(blockoffset.id); * amountwired++; * } */ mainwindow.Image_blueprint.DataContext = null; mainwindow.Image_blueprint.DataContext = mainwindow; } } } new System.Threading.Thread(new System.Threading.ThreadStart(() => { if (Properties.Settings.Default.wires) { MessageBox.Show("Successfully made " + amountwired + " connections! :D\n\n'Wires'-feature will render wires upon load from openwindow->needs work"); } else { MessageBox.Show("Successfully made " + amountwired + " connections! :D"); } })).Start(); //window.UpdateOpenedBlueprint(); if (amountwired > 0) { BP.Description.description = BP.Description.description + "\n--> " + amountwired + " connections made between " + sourcecolor + " " + sourceblock.name + " and " + destinationcolor + " " + destinationblock.name; } } catch (Exception exception) { MessageBox.Show(exception.Message + "\n\n Blueprint connections abrupted\nrestoring blueprint", "ERROR"); BP.setblueprint(backupbp); } #endregion } } else { MessageBox.Show("Something went wrong!\nno harm done"); } }
private void Button_Click(object sender, RoutedEventArgs e) { TextBox t1 = (TextBox)textBox_color1; Brush b = t1.Background; string oldcolor = "#" + (b as SolidColorBrush).Color.ToString().Substring(3); TextBox t2 = (TextBox)textBox_color2; Brush b1 = t2.Background; string newcolor = "#" + (b1 as SolidColorBrush).Color.ToString().Substring(3); int amountcolored = 0; foreach (dynamic body in BP.Blueprint.bodies) { foreach (dynamic child in body.childs) { string token = "#"; string color = child.color.ToString(); if (color[0] == '#') { token = ""; } if ((token + child.color.ToString().ToLower() == oldcolor.ToLower() || textBox_color1.Text == "#" || textBox_color1.Text == "") && ((comboBox_old.SelectedIndex <= 0) || child.shapeId.ToString() == ((Item)comboBox_old.SelectedItem).UUID.ToLower())) { amountcolored++; child.color = newcolor; } } } if (BP.Blueprint.joints != null) { foreach (dynamic child in BP.Blueprint.joints) { string token = "#"; string color = child.color.ToString(); if (color[0] == '#') { token = ""; } if ((token + child.color.ToString().ToLower() == oldcolor.ToLower() || textBox_color1.Text == "#" || textBox_color1.Text == "") && ((comboBox_old.SelectedIndex <= 0) || child.shapeId.ToString() == ((Item)comboBox_old.SelectedItem).UUID.ToLower())) { amountcolored++; child.color = newcolor.Substring(1); } } } if (comboBox_old.SelectedIndex < 0) { comboBox_old.SelectedIndex = 0; } string message = "++ " + amountcolored + " " + oldcolor + " " + ((Item)comboBox_old.SelectedItem).Name + " are now painted " + newcolor + " color"; if (textBox_color1.Text == "#" || textBox_color1.Text == "") { message = "++ " + amountcolored + ((Item)comboBox_old.SelectedItem).Name + " are now painted " + newcolor + " color"; } new System.Threading.Thread(new System.Threading.ThreadStart(() => { MessageBox.Show(message); })).Start(); if (amountcolored > 0) { BP.setblueprint(BP.Blueprint); BP.Description.description = BP.Description.description + "\n" + message; window.RenderBlueprint(); } }