protected override void Initialize() { base.Initialize(); // MouseHoverUpdatesOnly = true; representativeGameObject = new GameObject(); representativeGameObject.Sprite.TextureCellsPerRow = 1; c = new SimplexCore.OrthographicCamera(Editor.graphics); cam.Camera = c; cam.Position = Vector2.Zero; cam.TransformSpeed = 0.1f; vertexBuffer = new DynamicVertexBuffer(GraphicsDevice, typeof(VertexPositionColor), 1000, BufferUsage.WriteOnly); basicEffect = new BasicEffect(GraphicsDevice); msPrev = Mouse.GetState(); GraphicsDevice.PresentationParameters.RenderTargetUsage = RenderTargetUsage.PreserveContents; m = Matrix.CreateOrthographicOffCenter(0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 0, -1); Sgml.GraphicsDevice = GraphicsDevice; pixel = new Texture2D(GraphicsDevice, 1, 1); pixel.SetData(new[] { Color.White }); Rsize(); UpdateGrid(); previewGrid = Sgml.surface_create(80, 80); }
private void loadToolStripMenuItem_Click(object sender, EventArgs e) { // load last game Root dataDump = Sgml.game_load(Path.Combine(Environment.CurrentDirectory, @"Data/" + activeRoom.Text), false); sr.drawTest1.LastRoomState = dataDump; }
public void AaToggled() { if (parentForm == null) { if (selectedXIndex != -1 && selectedYIndex != -1) { selectedImageIndex = 1; // imageOverlay = Sgml.surface_create((int)parentForm.darkNumericUpDown1.Value, (int)parentForm.darkNumericUpDown2.Value); Sgml.surface_set_target(imageOverlay); Sgml.draw_clear_transparent(); Sgml.surface_reset_target(); } return; } if (parentForm.drawModeOn) { if (selectedXIndex != -1 && selectedYIndex != -1) { selectedImageIndex = 1; // imageOverlay = Sgml.surface_create((int)parentForm.darkNumericUpDown1.Value, (int)parentForm.darkNumericUpDown2.Value); Sgml.surface_set_target(imageOverlay); Sgml.draw_clear_transparent(); Sgml.surface_reset_target(); } } }
private void saveToolStripMenuItem1_Click(object sender, EventArgs e) { string mapContent = Path.Combine(currentProject.RootPath, @"Data\" + r.dtv.SelectedNodes[0].Text); toolStripStatusLabel3.Text = "Room saved"; Sgml.game_save(mapContent); }
private void SetTagToolStripMenuItem_Click(object sender, EventArgs e) { canShow = true; string tag = Sgml.get_string("", "New tag", lastNode.SuffixText); lastNode.SuffixText = tag; }
public void ScaleToFit(int percent) { if (selectedFrame != null) { cam.TargetZoom = (Sgml.min(Width, Height) / (float)Sgml.max(selectedFrame.previewLayer.texture.Width, selectedFrame.previewLayer.texture.Height) / 100f) * percent; cam.TargetPosition = new Vector2(-Width / 2f + selectedFrame.layers[0].texture.Width / 2f, -Height / 2f + selectedFrame.layers[0].texture.Height / 2f); } }
private void saveToolStripMenuItem_Click(object sender, EventArgs e) { if (activeRoom == null) { // activeRoom = treeView2.TopNode; } Sgml.game_save(Path.Combine(Environment.CurrentDirectory, @"Data/" + activeRoom.Text)); }
public void SaveChanges() { RenderTarget2D finalSurface = Sgml.surface_create(imageOverlay.Width, imageOverlay.Height); Sgml.surface_set_target(finalSurface); Sgml.draw_sprite(selectedImage, -2, Vector2.Zero); // Sgml.draw_surface(Vector2.Zero, imageOverlay); Sgml.surface_reset_target(); Sgml.surface_save(finalSurface, parentForm.owner.currentProject.RootPath + "/Content/Sprites/texture"); finalSurface.Dispose(); }
private void renameToolStripMenuItem_Click(object sender, EventArgs e) { canShow = true; // Rename object ! string name = Sgml.get_string("", "New name"); /* * 1) Rename object in savefiles * */ if (name != "") { string corePath = Path.GetFullPath(Path.Combine(form1.currentProject.RootPath + "/Data", "")); string[] paths = Directory.GetFiles(corePath); // Rename object in savefiles foreach (string s in paths) { // update each file string f = File.ReadAllText(s); f = f.Replace(lastNode.Text, name); File.WriteAllText(s, f); } // Also in the actual project string[] allfiles = Directory.GetFiles(form1.currentProject.RootPath, "*.cs", SearchOption.AllDirectories).Union(Directory.GetFiles(form1.currentProject.RootPath, "*.sproject")).Union(Directory.GetFiles(form1.currentProject.RootPath, "*.projitems")).ToArray(); foreach (string f in allfiles) { string text = File.ReadAllText(f); text = text.Replace(lastNode.Text, name); File.WriteAllText(f, text); } // Last step is to rename actual file allfiles = Directory.GetFiles(form1.currentProject.RootPath, lastNode.Text + ".cs", SearchOption.AllDirectories); foreach (string f in allfiles) { string k = f.Replace(lastNode.Text, name); File.Move(f, k); } lastNode.Text = name; } }
void UpdateGrid() { int cellSize = 16; int x = 0; int y = 0; RectangleF rect = RectangleF.Empty; Color c1 = Color.FromNonPremultiplied(68, 68, 68, 255); Color c2 = Color.FromNonPremultiplied(77, 77, 77, 255); bool flag = true; bool lastFlag = flag; gridSurface = Sgml.surface_create(Width, Height); Sgml.surface_set_target(gridSurface); for (var i = 0; i < Height / cellSize + 1; i++) { for (var j = 0; j < Width / cellSize + 1; j++) { if (j == 0) { lastFlag = flag; } rect.Size = new Size2(cellSize, cellSize); rect.Position = new Point2(x, y); if (flag) { Sgml.draw_set_color(c1); } else { Sgml.draw_set_color(c2); } Sgml.draw_rectangle(rect, false); x += cellSize; flag = !flag; } x = 0; y += cellSize; lastFlag = !lastFlag; flag = lastFlag; } Sgml.surface_reset_target(); }
public void AddEmptyFrame() { AnimationFrame af = new AnimationFrame(); RenderTarget2D s = Sgml.surface_create(selectedImage.Width, selectedImage.Height); af.previewLayer = new AnimationLayer(); af.previewLayer.texture = Sgml.surface_create(selectedImage.Width, selectedImage.Height); af.layers.Add(new AnimationLayer() { texture = s }); Frames.Add(af); }
// Change active room here private void treeView2_AfterSelect(object sender, TreeViewEventArgs e) { if (activeRoom != null) { Sgml.game_save(Path.Combine(Environment.CurrentDirectory, @"Data/" + activeRoom.Text)); } // activeRoom = treeView2.SelectedNode; if (File.Exists(Path.Combine(Environment.CurrentDirectory, @"Data/" + activeRoom.Text))) { Sgml.game_load(Path.Combine(Environment.CurrentDirectory, @"Data/" + activeRoom.Text)); } else { drawTest1.ClearAll(); } }
public void SaveChanges() { // Save physical images RenderTarget2D finalSurface = null; int index = 0; foreach (AnimationFrame af in Frames) { finalSurface = Sgml.surface_create(selectedFrame.previewLayer.texture.Width, selectedFrame.previewLayer.texture.Height); Sgml.surface_set_target(finalSurface); Sgml.draw_surface(Vector2.Zero, af.layers[0].texture); Sgml.surface_reset_target(); Sgml.surface_save(finalSurface, parentForm.owner.currentProject.RootPath + "/Content/Sprites/texture" + "_frame" + index); index++; } finalSurface?.Dispose(); }
public void UpdatePreview(int index) { // later /* RenderTarget2D finalSurface = Sgml.surface_create(selectedFrame.layers[0].texture.Width, selectedFrame.layers[0].texture.Height); * Sgml.surface_set_target(finalSurface); * Sgml.draw_surface(Vector2.Zero, selectedFrame.layers[0].texture); * Sgml.surface_reset_target();*/ MemoryStream ms = Sgml.surface_save_ext_memory(selectedFrame.layers[0].texture, 80, 80); Bitmap b = (Bitmap)Image.FromStream(ms); if (parentForm.darkImageIndex1.Frames.Count > index) { parentForm.darkImageIndex1.Frames[index].bmp = b; } parentForm.darkImageIndex1.Invalidate(); }
public void AddFrameFromTexture(Texture2D texture) { AnimationFrame af = new AnimationFrame(); af.texture = texture; af.previewLayer = new AnimationLayer(); af.previewLayer.texture = Sgml.surface_create(texture.Width, texture.Height); RenderTarget2D surf = Sgml.surface_create(texture.Width, texture.Height); Sgml.surface_set_target(surf); Sgml.draw_sprite(texture, -2, Vector2.Zero); Sgml.surface_reset_target(); af.layers.Add(new AnimationLayer() { texture = surf }); selectedFrame = af; Frames.Add(af); }
private void DarkTreeView1_MouseDoubleClick(object sender, MouseEventArgs e) { // node double clicked if (darkTreeView1.SelectedNodes.Count > 0 && e.Button == MouseButtons.Left) { DarkTreeNode dtn = darkTreeView1.SelectedNodes[0]; if (dtn.RootNodeName == "Sprites") { // open sprites editor Sprites_manager sm = new Sprites_manager(); sm.DockText = "Sprites Editor - " + dtn.Text; sm.owner = form1; // find him a sprite Texture2D s = form1.sr.drawTest1.Sprites.FirstOrDefault(x => x.Name == dtn.Text)?.Texture; if (s != null) { sm.spritesEditorRenderer1.selectedImage = s; sm.lastImage = Sgml.convert_to_bitmap(s, s.Width, s.Height); sm.darkImageIndex1.Frames.Add(new ImageIndex() { }); sm.spritesEditorRenderer1.AddFrameFromTexture(s); } form1.darkDockPanel1.AddContent(sm); sm.Invalidate(); sm.spritesEditorRenderer1.UpdatePreview(0); // sm.darkDockPanel2.AssureMePlase(); } if (dtn.RootNodeName == "Objects") { // open sprites editor Sgml.show_debug_message("Double clicked an object"); } } }
private void darkTreeView1_SelectedNodesChanged(object sender, EventArgs e) { if (dtv.SelectedNodes.Count > 0) { Debug.WriteLine(dtv.SelectedNodes[0].Text); } if (dtv.SelectedNodes.Count > 0 && execute) { if ((string)dtv.SelectedNodes[0].Tag != "folder") { if (Form1.activeRoom != null) { Sgml.game_save(Path.Combine(Environment.CurrentDirectory, @"Data/" + Form1.activeRoom.Text)); } Form1.activeRoom = dtv.SelectedNodes[0]; form1.setStatusBottom("Editing " + Form1.activeRoom.Text); if (File.Exists(Path.Combine(Environment.CurrentDirectory, @"Data/" + Form1.activeRoom.Text))) { drawTest1.LoadGame(Path.Combine(Environment.CurrentDirectory, @"Data/" + Form1.activeRoom.Text)); } else { drawTest1.ClearAll(); } } } if (!execute) { // execute = true; } }
private void darkTreeView1_SelectedNodesChanged(object sender, EventArgs e) { if (dtv.SelectedNodes.Count > 0) { Debug.WriteLine(dtv.SelectedNodes[0].Text); } if (dtv.SelectedNodes.Count > 0 && execute) { if ((string)dtv.SelectedNodes[0].Tag != "folder") { string mapContent = Path.Combine(form1.currentProject.RootPath, @"Data\" + dtv.SelectedNodes[0].Text); if (Form1.activeRoom != null) { Sgml.game_save(mapContent, true); } Form1.activeRoom = dtv.SelectedNodes[0]; form1.setStatusBottom("Editing " + Form1.activeRoom.Text); if (File.Exists(mapContent)) { Root dataDump = Sgml.game_load(mapContent, false); drawTest1.LastRoomState = dataDump; } else { Sgml.currentRoom = (GameRoom)Activator.CreateInstance(Type.GetType("SimplexResources.Rooms." + Form1.activeRoom.Text)); Sgml.game_save(mapContent); drawTest1.ClearAll(); } } } }
private void ToolDraw(Color penColor) { Sgml.surface_set_target(selectedFrame.layers[0].texture); Sgml.draw_set_aa(false); Sgml.draw_set_color(penColor); int x1 = 0; int y1 = 0; if (activeTool == Tools.Pixel) { if (PixelFree(Sgml.mouse.X, Sgml.mouse.Y)) { Sgml.draw_sprite(pixel, -2, tempVector); occupiedPositions.Add(tempVector); } if (size == 1) { num = 0; } if (size == 2) { num = 11; } if (size == 3) { num = 31; } if (size == 4) { num = 75; } if (size == 5) { num = 147; } if (size == 6) { num = 207; } for (int i = 0; i < num; i++) { if (PixelFree(Sgml.mouse.X + sizesx[i], Sgml.mouse.Y + sizesy[i])) { Sgml.draw_sprite(pixel, -2, tempVector); } } } else if (activeTool == Tools.Ellipse) { Sgml.draw_ellipse(new Vector2(Sgml.mouse.X - toolOrigin.X, Sgml.mouse.Y - toolOrigin.Y), toolOrigin, 1); } else if (activeTool == Tools.Fill) { // flood fill var data = new Color[selectedFrame.layers[0].texture.Width * selectedFrame.layers[0].texture.Height]; selectedFrame.layers[0].texture.GetData(data); var x = (int)Sgml.round(Sgml.mouse.X - .5f); var y = (int)Sgml.round(Sgml.mouse.Y - .5f); int w = Math.Max(selectedFrame.layers[0].texture.Height, selectedFrame.layers[0].texture.Width); if (inTexture(x, y) && inTextureP(x, y)) { var pixels = new Stack <Point>(); var used = new List <Point>(); var targetColor = data[w * y + x]; pixels.Push(new Point(x, y)); var i = 0; var max = data.Length - 1; var flag = !(data[w * y + x] == penColor); if (flag) { while (pixels.Count > 0 && i < max) { var a = pixels.Pop(); var xx = a.X; if (!inTextureP(a.X, a.Y)) { break; } while (xx >= 0 && data[w * a.Y + xx] == targetColor) { xx--; } xx++; var spanAbove = false; var spanBelow = false; while (xx < selectedFrame.layers[0].texture.Width && data[w * a.Y + xx] == targetColor) { data[w * a.Y + xx] = penColor; if (!spanAbove && a.Y > 0 && data[w * (a.Y - 1) + xx] == targetColor) { if (!used.Contains(new Point(xx, a.Y - 1))) { pixels.Push(new Point(xx, a.Y - 1)); used.Add(new Point(xx, a.Y - 1)); spanAbove = true; } } else if (spanAbove && a.Y > 0 && data[w * (a.Y - 1) + xx] != targetColor) { spanAbove = false; } if (!spanBelow && a.Y < selectedFrame.layers[0].texture.Height - 1 && data[w * (a.Y + 1) + xx] == targetColor) { if (!used.Contains(new Point(xx, a.Y + 1))) { pixels.Push(new Point(xx, a.Y + 1)); used.Add(new Point(xx, a.Y + 1)); spanBelow = true; } } else if (spanBelow && a.Y < selectedFrame.layers[0].texture.Height - 1 && data[w * (a.Y + 1) + xx] != targetColor) { spanBelow = false; } xx++; } i++; } selectedFrame.layers[0].texture.SetData(data); } } } else if (activeTool == Tools.Dropper) { } else if (activeTool == Tools.Line) { Sgml.draw_rectangle(new Vector2((float)Sgml.round(toolOriginINP.X - .5f), (float)Sgml.round(toolOriginINP.Y - .5f)), new Vector2((float)Sgml.round(toolOriginINP.X + .5f), (float)Sgml.round(toolOriginINP.Y + .5f)), false); Sgml.draw_line(mouseSubpixel, toolOriginSubpixel); } else if (activeTool == Tools.Polygon) { } else if (activeTool == Tools.Rectangle) { float my = Sgml.mouse.Y; my = (float)Sgml.floor(my) + .5f; Sgml.draw_rectangle(toolOrigin, new Vector2(Sgml.mouse.X, my), true); } else if (activeTool == Tools.RoundedRectangle) { Sgml.draw_roundrect(toolOrigin, new Vector2(Sgml.mouse.X, Sgml.mouse.Y), true, 1); } else if (activeTool == Tools.Rubber) { Color[] data = new Color[selectedFrame.layers[0].texture.Width * selectedFrame.layers[0].texture.Height]; selectedFrame.layers[0].texture.GetData(data); int x = (int)Sgml.round(Sgml.mouse.X - .5f); int y = (int)Sgml.round(Sgml.mouse.Y - .5f); int w = Math.Max(selectedFrame.layers[0].texture.Height, selectedFrame.layers[0].texture.Width); if (inTextureP(x, y)) { if (selectedFrame.layers[0].texture.Height * y + x >= 0 && selectedFrame.layers[0].texture.Height * y + x < selectedFrame.layers[0].texture.Width * selectedFrame.layers[0].texture.Height) { data[w * y + x] = Color.Transparent; selectedFrame.layers[0].texture.SetData(data); } occupiedPositions.Add(new Vector2((float)Sgml.round(Sgml.mouse.X - .5f) - x1, (float)Sgml.round(Sgml.mouse.Y - .5f) - y1)); } } else if (activeTool == Tools.Spray) { } else if (activeTool == Tools.SprayPaint) { } else if (activeTool == Tools.Star) { } else if (activeTool == Tools.Text) { } Sgml.surface_reset_target(); Sgml.draw_set_color(Color.White); UpdatePreview(selectedImageIndex); }
private void saveToolStripMenuItem1_Click(object sender, EventArgs e) { Sgml.game_save("Data/" + activeRoom.Text); }
protected override void Update(GameTime gameTime) { base.Update(gameTime); cam.UpdatePosition(); var originalPos = cam.Camera.Position; var originalZoom = cam.Camera.Zoom; Matrix view = cam.Camera.GetViewMatrix(); cam.Camera.Position = new Vector2(0, 0); cam.Camera.Zoom = 1; Matrix normalizedMatrix = cam.Camera.GetViewMatrix(); cam.Camera.Position = originalPos; cam.Camera.Zoom = originalZoom; Sgml.world = world; Sgml.view = view; Sgml.normalizedMatrix = normalizedMatrix; if (selectedFrame != null) { if (ms.LeftButton == ButtonState.Pressed ^ ms.RightButton == ButtonState.Pressed) { if (activeTool == Tools.Pixel || activeTool == Tools.Rubber || activeTool == Tools.Fill) { ToolDraw(ms.LeftButton == ButtonState.Pressed ? penColor : penColorRight); } } if ((ms.LeftButton == ButtonState.Released && msPrev.LeftButton == ButtonState.Pressed && toolPreview) ^ (ms.RightButton == ButtonState.Released && msPrev.RightButton == ButtonState.Pressed && toolPreview)) { if (activeTool == Tools.Ellipse || activeTool == Tools.Rectangle || activeTool == Tools.Line || activeTool == Tools.RoundedRectangle) { ToolDraw(msPrev.LeftButton == ButtonState.Pressed ? penColor : penColorRight); over = true; } toolPreview = false; } Sgml.draw_set_color(ms.LeftButton == ButtonState.Pressed ? penColor : penColorRight); // render preview toolOriginSubpixel.X = toolOrigin.X; //(float)Math.Floor(toolOrigin.X >= Sgml.mouse.X ? toolOrigin.X + .5f : toolOrigin.X - .5f); toolOriginSubpixel.Y = toolOrigin.Y; //(float)Math.Floor(toolOrigin.Y >= Sgml.mouse.Y ? toolOrigin.Y + .5f : toolOrigin.Y - .5f); mouseSubpixel.X = (float)Math.Floor(Sgml.mouse.X); mouseSubpixel.Y = (float)Math.Floor(Sgml.mouse.Y); mouseSubpixel.X += mouseSubpixel.X > toolOriginSubpixel.X ? 1 : 0; mouseSubpixel.Y += mouseSubpixel.Y > toolOriginSubpixel.Y ? 1 : 0; Sgml.surface_set_target(selectedFrame.previewLayer.texture); Sgml.draw_clear_transparent(); Sgml.draw_set_color(ms.LeftButton == ButtonState.Pressed ? penColor : penColorRight); if (activeTool == Tools.Pixel) { Sgml.draw_rectangle(new Vector2((float)Sgml.round(Sgml.mouse.X - .5f), (float)Sgml.round(Sgml.mouse.Y - .5f)), new Vector2((float)Sgml.round(Sgml.mouse.X + .5f), (float)Sgml.round(Sgml.mouse.Y + .5f)), false); } if (toolPreview) { if (activeTool == Tools.Ellipse) { Sgml.draw_ellipse(new Vector2(Sgml.mouse.X - toolOrigin.X, Sgml.mouse.Y - toolOrigin.Y), toolOrigin, 1); } else if (activeTool == Tools.Rectangle) { float my = Sgml.mouse.Y; my = (float)Sgml.floor(my) + .5f; Sgml.draw_rectangle(toolOrigin, new Vector2(Sgml.mouse.X, my), true); } else if (activeTool == Tools.Line) { Sgml.draw_rectangle(new Vector2((float)Sgml.round(toolOriginINP.X - .5f), (float)Sgml.round(toolOriginINP.Y - .5f)), new Vector2((float)Sgml.round(toolOriginINP.X + .5f), (float)Sgml.round(toolOriginINP.Y + .5f)), false); Sgml.draw_line(mouseSubpixel, toolOriginSubpixel); } else if (activeTool == Tools.RoundedRectangle) { Sgml.draw_roundrect(toolOrigin, new Vector2(Sgml.mouse.X, Sgml.mouse.Y), true, 1); } } Sgml.surface_reset_target(); if ((ms.LeftButton == ButtonState.Pressed && !toolPreview) ^ (ms.RightButton == ButtonState.Pressed && !toolPreview)) { if (!over) { toolOriginINP = new Vector2(Sgml.mouse.X, Sgml.mouse.Y); toolOrigin.X = (float)Sgml.round(Sgml.mouse.X - 0.5f) + .5f; toolOrigin.Y = (float)Sgml.round(Sgml.mouse.Y - 0.5f) + .5f; toolPreview = true; } else { over = false; } } } // Update frame if user pushed autoplay btn if (parentForm.darkButton33.Pushed) { animateIn--; if (animateIn <= 0) { animateIn = (int)parentForm.darkNumericUpDown5.Value; selectedImageIndex++; if (selectedImageIndex >= Frames.Count) { selectedImageIndex = 0; } selectedFrame = Frames[selectedImageIndex]; parentForm.darkImageIndex1.SelectedFrame = selectedImageIndex; parentForm.darkImageIndex1.Invalidate(); } } msPrev = ms; }
private void loadToolStripMenuItem_Click(object sender, EventArgs e) { // load last game Sgml.game_load(Path.Combine(Environment.CurrentDirectory, @"Data/" + activeRoom.Text)); }
public void GameClicked(MouseEventArgs e, MouseButtons mb) { KeyboardState ks = Keyboard.GetState(); if ((mb & MouseButtons.Left) != 0) { Input.PressedButtonsOnce[0] = 1; Sgml.LastButton = Sgml.MouseButtons.Left; } if ((mb & MouseButtons.Right) != 0) { Input.PressedButtonsOnce[1] = 1; Sgml.LastButton = Sgml.MouseButtons.mb_right; } if ((mb & MouseButtons.Middle) != 0) { Input.PressedButtonsOnce[2] = 1; Sgml.LastButton = Sgml.MouseButtons.Middle; } if ((mb & MouseButtons.None) != 0) { Input.PressedButtonsOnce[3] = 1; } if ((mb & MouseButtons.XButton1) != 0) { Input.PressedButtonsOnce[5] = 1; Sgml.LastButton = Sgml.MouseButtons.mb_x1; } if ((mb & MouseButtons.XButton2) != 0) { Input.PressedButtonsOnce[6] = 1; Sgml.LastButton = Sgml.MouseButtons.mb_x2; } Input.CheckAnyPressed(); MousePositionTranslated = cam.Camera.ScreenToWorld(MousePosition); if (mb == MouseButtons.Left) { goodBoy = true; Vector2 vec = MousePositionTranslated; if (DrawGrid) { vec = new Vector2((int)vec.X / 32 * 32, (int)vec.Y / 32 * 32); } if (ks.IsKeyDown(Keys.LeftControl)) { selectionRectangle.Width = -selectionRectangle.X + vec.X; selectionRectangle.Height = -selectionRectangle.Y + vec.Y; } else if (clickedObject == null) { if (currentAutotile == null) { if (selectedRectangleObjects.Count > 0) { bool flag = true; if (flag) { if (selectedRectangleObjects.Count > 0) { foreach (GameObject o in selectedRectangleObjects) { o.Position += new Vector2(vec.X - MousePrevious.X, vec.Y - MousePrevious.Y); } } } else { selectedRectangleObjects.Clear(); } } else { if (!ks.IsKeyDown(Keys.LeftShift) || Sgml.PlaceEmpty(vec)) { if (Sgml.PlaceEmpty(vec)) { if (SelectedObject != null && selectedLayer.GetType() == typeof(ObjectLayer)) { GameObject o = (GameObject)Activator.CreateInstance(SelectedObject); Spritesheet s = new Spritesheet(); if (o.Sprite != null) { s = Sprites.FirstOrDefault(x => x.Name == o.Sprite.TextureSource); } if (!cmsOpen && SelectedObject != null) { if (stackedSteps.Count > 31) { stackedSteps.Pop(); } stackedSteps.Push(SceneObjects.ToList()); editorForm.updateStack(stackedSteps.Count); o.OriginalType = SelectedObject; o.TypeString = SelectedObject.ToString(); if (s == null) { Texture2D tx = ConvertToTexture(Properties.Resources.Question_16x, GraphicsDevice); o.Sprite = new Sprite(); o.Sprite.Texture = tx; o.Sprite.ImageRectangle = new Microsoft.Xna.Framework.Rectangle(0, 0, 16, 16); } else { o.Sprite.Texture = s.Texture; o.Sprite.ImageRectangle = new Microsoft.Xna.Framework.Rectangle(0, 0, s.CellWidth, s.CellHeight); } o.Sprite.TextureRows = s.Rows; o.Sprite.TextureCellsPerRow = s.Texture.Width / s.CellWidth; o.Sprite.ImageSize = new Vector2(s.CellWidth, s.CellHeight); o.Sprite.FramesCount = Math.Max((s.Texture.Width / s.CellWidth) * (s.Texture.Height / s.CellHeight) - 1, 1); o.FramesCount = Math.Max(o.Sprite.FramesCount - 1, 1); o.Sprite.cellW = s.CellHeight; o.Sprite.cellH = s.CellWidth; o.Position = new Vector2(vec.X - s.CellWidth / 2f, vec.Y - s.CellHeight / 2f); o.Sprite.ImageRectangle = new Microsoft.Xna.Framework.Rectangle(0, 0, s.CellWidth, s.CellHeight); o.LayerName = selectedLayer.Name; o.Layer = (ObjectLayer)selectedLayer; Sgml.currentObject = o; o.EvtCreate(); o.Layer.Objects.Add(o); SceneObjects.Add(o); sh.RegisterObject(o); } if (!ks.IsKeyDown(Keys.LeftShift)) { clickedObject = o; } } } } if (!Sgml.PlaceEmpty(vec) && !ks.IsKeyDown(Keys.LeftShift)) { // there's something cool at the position already, time to grab it GameObject collidingObject = Sgml.instance_place(vec); if (collidingObject != null) { clickedObject = collidingObject; helpVec = new Vector2(-MousePositionTranslated.X + collidingObject.Position.X, -MousePositionTranslated.Y + collidingObject.Position.Y); clickedVec = MousePositionTranslated; } } } } else { Vector2 m = MousePositionTranslated; Tile alreadyT = currentTileLayer.Tiles.FirstOrDefault(x => x.PosX == (int)m.X / 32 && x.PosY == (int)m.Y / 32); if (alreadyT == null) { Tile t = new Tile(); t.Bits = 16; t.DrawRectangle = new Microsoft.Xna.Framework.Rectangle(0, 0, 32, 32); t.SourceTexture = currentAutotile.Texture; t.PosX = (int)m.X / 32; t.PosY = (int)m.Y / 32; t.TileLayer = currentTileLayer; t.TileLayerName = t.TileLayer.Name; currentTileLayer.Tiles.Add(t); t = Autotile.UpdateTile(t, currentTileLayer); // basic 4 Tile t1 = currentTileLayer.Tiles.FirstOrDefault(x => x.PosX == t.PosX && x.PosY == t.PosY - 1); // N // 2 Tile t2 = currentTileLayer.Tiles.FirstOrDefault(x => x.PosX == t.PosX && x.PosY == t.PosY + 1); // S // 64 Tile t3 = currentTileLayer.Tiles.FirstOrDefault(x => x.PosX == t.PosX + 1 && x.PosY == t.PosY); // W // 16 Tile t4 = currentTileLayer.Tiles.FirstOrDefault(x => x.PosX == t.PosX - 1 && x.PosY == t.PosY); // S // 8 // extended 4 Tile t5 = currentTileLayer.Tiles.FirstOrDefault(x => x.PosX == t.PosX - 1 && x.PosY == t.PosY - 1); // EN // 1 Tile t6 = currentTileLayer.Tiles.FirstOrDefault(x => x.PosX == t.PosX + 1 && x.PosY == t.PosY - 1); // WN // 4 Tile t7 = currentTileLayer.Tiles.FirstOrDefault(x => x.PosX == t.PosX - 1 && x.PosY == t.PosY + 1); // ES // 32 Tile t8 = currentTileLayer.Tiles.FirstOrDefault(x => x.PosX == t.PosX + 1 && x.PosY == t.PosY + 1); // WS // 128 if (t1 != null) { Autotile.UpdateTile(t1, currentTileLayer); } if (t2 != null) { Autotile.UpdateTile(t2, currentTileLayer); } if (t3 != null) { Autotile.UpdateTile(t3, currentTileLayer); } if (t4 != null) { Autotile.UpdateTile(t4, currentTileLayer); } if (t5 != null) { Autotile.UpdateTile(t5, currentTileLayer); } if (t6 != null) { Autotile.UpdateTile(t6, currentTileLayer); } if (t7 != null) { Autotile.UpdateTile(t7, currentTileLayer); } if (t8 != null) { Autotile.UpdateTile(t8, currentTileLayer); } } } } else { vec = MousePositionTranslated; vec = new Vector2(vec.X + helpVec.X, vec.Y + helpVec.Y); if (DrawGrid) { vec = MousePositionTranslated; vec.X -= (int)(clickedObject.Sprite.ImageRectangle.Width - 32) / 2;//16; vec.Y -= (int)(clickedObject.Sprite.ImageRectangle.Height - 32) / 2; vec = new Vector2((int)vec.X / 32 * 32, (int)vec.Y / 32 * 32); } if (!cmsOpen) { clickedObject.Position = vec; } } } else if (mb == MouseButtons.Right) { // Debug.WriteLine("----"); Vector2 vec = MousePositionTranslated; if (DrawGrid) { vec = new Vector2((int)vec.X / 32 * 32, (int)vec.Y / 32 * 32); } foreach (RoomLayer rl in roomLayers) { if (rl.Visible) { if (rl is ObjectLayer) { ObjectLayer ol = (ObjectLayer)rl; for (var i = ol.Objects.Count - 1; i >= 0; i--) { Microsoft.Xna.Framework.Rectangle r = new Microsoft.Xna.Framework.Rectangle((int)ol.Objects[i].Position.X, (int)ol.Objects[i].Position.Y, ol.Objects[i].Sprite.ImageRectangle.Width, ol.Objects[i].Sprite.ImageRectangle.Height); if (ks.IsKeyDown(Keys.LeftShift) && r.Contains(vec)) { SceneObjects.Remove(ol.Objects[i]); ol.Objects[i].EvtDelete(); ol.Objects.Remove(ol.Objects[i]); } } } } } } MousePrevious = MousePositionTranslated; }
bool PixelFree(float x, float y) { tempVector.X = (float)Sgml.round(x - .5f); tempVector.Y = (float)Sgml.round(y - .5f); return(!occupiedPositions.Contains(tempVector)); }
/// <summary> /// Busca y asigna los nodos hijos al valor por referencia childs /// </summary> /// <param name="model">Grupo en el cual encontramos los nodos hijos</param> /// <param name="childs">Volar por referencia donde se alamacenaran los nodos hijos</param> private void setChilds(Sgml.Group model, ref List<String> childs) { String childName = null; foreach (Object child in model.CurrentMembers) { if (child.GetType().Namespace + "." + child.GetType().Name == "Sgml.Group") { this.setChilds((Sgml.Group)child, ref childs); } else { childName = child.ToString().ToLower(); /*Si el nodo no existe en la lista lo agregamos ademas tambien verificamos que exista tambien en el diccionario*/ if (!childs.Contains(childName)) { childs.Add(childName); } if (!this.tag.ContainsKey(childName)) { try { this.tag.Add(childName, new TagStruct()); } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.Message); } } /*Verificamos si el nodo tiene hijos y si es asi lo marcamos*/ if (this.dtd.FindElement(childName).ContentModel.CurrentModel.CurrentMembers.Count > 0) { this.tag[childName].ChildNodes = true; } } } }
protected override void Draw() { if (parentForm != null) { ms = Mouse.GetState(); if (ttl < 10) { if (ttl == 9) { ScaleToFit(90); } ttl++; } base.Draw(); double framerate = Editor.GetFrameRate; Matrix transformMatrix = cam.Camera.GetViewMatrix(); MousePositionTranslated = cam.Camera.ScreenToWorld(new Vector2(ms.X, ms.Y)); BackgroundColor = Color.Black; Editor.graphics.Clear(BackgroundColor); Input.MousePosition = MousePositionTranslated; MousePosition = new Vector2(ms.X, ms.Y); Sgml.sb = Editor.spriteBatch; Sgml.vb = vertexBuffer; Sgml.be = basicEffect; Sgml.m = transformMatrix; Sgml.currentObject = representativeGameObject; Matrix view = cam.Camera.GetViewMatrix(); Matrix projection = m; basicEffect.World = world; basicEffect.View = view; basicEffect.Projection = projection; basicEffect.VertexColorEnabled = true; Sgml.mouse = MousePositionTranslated; // Actual logic int cellSize = 16; int x = 0; int y = 0; RectangleF rect = RectangleF.Empty; Color c1 = Color.FromNonPremultiplied(68, 68, 68, 255); Color c2 = Color.FromNonPremultiplied(77, 77, 77, 255); bool flag = true; bool lastFlag = flag; cam.Camera.Origin = new Vector2(Width / 2f, Height / 2f); basicEffect.View = Matrix.Identity; Sgml.m = Matrix.Identity; Vector2 origin = Vector2.Zero; Sgml.draw_surface(origin, gridSurface); basicEffect.View = view; Sgml.m = transformMatrix; if (selectedFrame != null) { Sgml.draw_set_aa(!parentForm.drawModeOn); if (selectedFrame.layers[0].texture != null) { Sgml.draw_surface(origin, selectedFrame.layers[selectedLayer].texture); Sgml.draw_surface(origin, selectedFrame.previewLayer.texture); } Sgml.draw_set_aa(true); // draw cells int xx = 0; int yy = 0; int xIndex = 0; int yIndex = 0; RectangleF temp = RectangleF.Empty; float x1 = origin.X; float y1 = origin.Y; float x2 = x1 + (int)parentForm.darkNumericUpDown1.Value; float y2 = y1 + (int)parentForm.darkNumericUpDown2.Value; Sgml.draw_set_alpha(0.8); Sgml.draw_set_color(Color.Black); for (var i = 0; i < parentForm.darkNumericUpDown1.Value + 1; i++) { Sgml.draw_line(x1, y1 + i, x2, y1 + i); } for (var i = 0; i < parentForm.darkNumericUpDown2.Value + 1; i++) { Sgml.draw_line(x1 + i, y1, x1 + i, y2); } Sgml.draw_set_alpha(1); Sgml.draw_set_color(Color.White); Sgml.draw_set_aa(false); if (selectedFrame.layers.Count > 0) { if (selectedFrame.layers[0].texture != null) { Sgml.draw_rectangle(origin, new Vector2(selectedFrame.layers[0].texture.Width, selectedFrame.layers[0].texture.Height), true); } } } basicEffect.View = Matrix.Identity; Sgml.m = Matrix.Identity; Sgml.draw_set_color(Color.White); Sgml.draw_text(new Vector2(10, 10), framerate.ToString()); Sgml.draw_text(new Vector2(10, 30), "[X: " + Sgml.round(Sgml.mouse.X - 0.5f) + " Y: " + Sgml.round(Sgml.mouse.Y - 0.5f) + "]"); // Sgml.draw_text(new Vector2(10, 50), parentForm.darkNumericUpDown1.Value.ToString()); Sgml.draw_text(new Vector2(10, 70), cam.Zoom.ToString()); Sgml.draw_text(new Vector2(10, 90), "DIR: " + Sgml.point_direction(toolOriginSubpixel, mouseSubpixel)); Sgml.draw_text(new Vector2(10, 110), "CLICK: " + toolOriginSubpixel.X + "x " + toolOriginSubpixel.Y + "y"); } }
private void toolStripButton1_Click(object sender, EventArgs e) { if (dtv.SelectedNodes.Count > 0) { string editorPath = dtv.SelectedNodes[0].FullPath; string currentFolder = Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.FullName + @"\SimplexCore\Prefabs\PrefabObject.cs"; // get prefab class string[] prefabText = File.ReadAllLines(currentFolder); string className = Sgml.get_string("", "Object name"); // generate actual class currentFolder = Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.FullName + @"\SimplexResources\Objects\" + className + ".cs"; using (StreamWriter sw = new StreamWriter(currentFolder)) { foreach (string line in prefabText) { string ll = line; ll = ll.Replace("{editorPath}", editorPath.Replace("\\", "/")); ll = ll.Replace("PrefabObject", className); ll = ll.Replace("SimplexCore.Prefabs", "SimplexResources.Objects"); sw.WriteLine(ll); } sw.Close(); } // add new object // 1) locate projitems currentFolder = Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.FullName + @"\SimplexResources\SimplexResources.projitems"; XDocument doc = XDocument.Load(currentFolder); XElement root = new XElement("Compile"); root.Add(new XAttribute("Include", @"$(MSBuildThisFileDirectory)Objects\" + className + ".cs")); var v = doc.Root.Nodes().ToList(); foreach (XElement xx in v) { if (xx.Name.LocalName == "ItemGroup") { // good boi we can write here xx.Add(root); break; // prevent from adding to each root } } doc.Save(currentFolder); // add new object to the sproject SimplexProjectItem spi = new SimplexProjectItem(); spi.name = className; spi.path = editorPath; form1.currentProject.Objects.Add(spi); // finally save sproject string json = JsonConvert.SerializeObject(form1.currentProject, Formatting.Indented); File.WriteAllText(form1.currentProject.ProjectPath, json); DarkMessageBox.Show("Object was created, please restart the engine for changes to take effect.", "New object wizard"); } }