private void UpdateElements(InputHandler handler) { if (draggedElement == null) { #region If Mouse Pressed if (handler.CheckLeftMouseJustPressed()) { #region Check if an Element was Clicked for (int i = 0;i < elements.Count; i++) { var element = elements[elements.Count - i - 1]; if (handler.CheckMouseIn(element)) { #region Set as Dragged Object draggedElement = element; originalPoint = element.GetPoint(); elements.Remove(element); elements.Add(element); #endregion break; } } #endregion } #endregion } else { if (dragging) { if (handler.CheckLeftMouseJustReleased()) { //Just in case stuff needs to be done. #region Release Dragged Object UpdateInteraction(handler); if (draggedElement != null && draggedElement.GetX() < widthOfMenu) { RemoveElement(draggedElement); } draggedElement = null; dragging = false; #endregion } else { #region Set the X and Y of the Dragged Object draggedElement.SetX(originalPoint.X + handler.LeftMouseDraggedBy().X); draggedElement.SetY(originalPoint.Y + handler.LeftMouseDraggedBy().Y); #endregion } } else { #region Detect if Dragged Piece was actually moved. if (!(handler.LeftMouseDraggedBy().X == 0 && handler.LeftMouseDraggedBy().Y == 0)) { dragging = true; #region Removes the element from a slot. if (draggedElement.GetElement() is DragDropVariablePlaceholder) { if (((DragDropVariablePlaceholder)draggedElement.GetElement()).HasVariable()) { elements.Add(((DragDropVariablePlaceholder)draggedElement.GetElement()).PopVariable()); draggedElement = elements[elements.Count - 1]; originalPoint = handler.GetMouseXY(); } } #endregion else #region Removes the element from a slot that is contained in another piece if (draggedElement.GetElement().GetTopInteracting(handler) is DragDropVariablePlaceholder) { DragDropVariablePlaceholder slot = (DragDropVariablePlaceholder)((DragDropVariablePlaceholder)draggedElement.GetElement().GetTopInteracting(handler)).GetInnerMostDragDrop(handler); if ((slot).HasVariable()) { elements.Add((slot).PopVariable()); draggedElement = elements[elements.Count - 1]; originalPoint = handler.GetMouseXY(); } } #endregion } #endregion else #region If the piece is released, select it. if (handler.CheckLeftMouseJustReleased()) { if (selectedElement != null && selectedElement != draggedElement) selectedElement.GetElement().TellSelected(false); draggedElement.GetElement().GetInteracting(handler).TellSelected(true); selectedElement = draggedElement; draggedElement = null; } #endregion } } }
private void UpdateSuggestions(InputHandler handler) { if (draggedElement != null) return; if(handler.CheckLeftMouseJustPressed()) foreach(LooseDragDropLink link in suggestions) { if(handler.CheckMouseIn(link)) { suggestedElement = link; break; } } if (handler.CheckLeftMouseJustReleased()) { suggestedElement = null; } if(suggestedElement != null) if (!(handler.LeftMouseDraggedBy().X == 0 && handler.LeftMouseDraggedBy().Y == 0)) { elements.Add(new LooseDragDropLink(suggestedElement.GetElement().Clone())); draggedElement = elements[elements.Count - 1]; Point XY = handler.GetMouseXY(); originalPoint = XY; elements[elements.Count - 1].SetPoint(ref XY); } }
public void Update(InputHandler handler) { try { if (textBox.GetSelected()) { DragDropInterface.UpdateTextBox(textBox, handler); return; } if (fileMode != 0) { if (fileMode == 1) { SaveFileSystem.SaveObjectToFile(new World(objects.ToArray()), "Levels" + Path.DirectorySeparatorChar + textBox.GetText() + ".taj"); textBox.SetText(""); } else if (fileMode == 2) { World n = SaveFileSystem.LoadObjectFromFile<World>("Levels" + Path.DirectorySeparatorChar + textBox.GetText() + ".taj", new GameLoader()); objects.Clear(); objects.AddRange(n.GetObjects()); } else if (fileMode == 3) { ((LevelPerson)couldDrag).SetBodyAnimation(textBox.GetText() + ".taj"); ((LevelPerson)couldDrag).SetLoop(true); ((LevelPerson)couldDrag).SetPlaying(true); } else if (fileMode == 4) { ((LevelPerson)couldDrag).SetName(textBox.GetText()); } else if (fileMode ==5) { SaveFileSystem.SaveObjectToFile(new World(objects.ToArray()), "Levels" + Path.DirectorySeparatorChar + textBox.GetText() + ".taj"); fileName = "Levels" + Path.DirectorySeparatorChar + textBox.GetText() + ".taj"; safeFileName = textBox.GetText() + ".taj"; finished = true; } textBox.SetText(""); fileMode = 0; } if (animationMode) { tool.Update(handler); if (tool.GetDone()) animationMode = false; return; } if (!modifyingOne) foreach (LevelObject o in objects) { o.Update(handler); o.SetEditing(!hideEditing); if (o.Modifying()) { modifying = o; modifyingOne = true; break; } if (!dragging && o.CheckInside(handler)) { if (o is LightLevelCircle) { if (handler.CheckPressedKey(Keys.L)) { couldDrag = o; } } else couldDrag = o; } } else { modifying.Update(handler); if (!modifying.Modifying()) { modifying = null; modifyingOne = false; } } if (handler.CheckJustPressedKey(Keys.H)) { hideEditing = !hideEditing; } if (handler.CheckJustPressedKey(Keys.K)) { cullMode = !cullMode; } if (handler.CheckJustPressedKey(Keys.F)) { bringToFront = !bringToFront; } if (handler.CheckJustPressedKey(Keys.Delete)) { textBox.TellSelected(true); fileMode = 1; } if (handler.CheckJustPressedKey(Keys.Insert)) { textBox.TellSelected(true); fileMode = 2; } if (handler.CheckJustPressedKey(Keys.Q)) { if (handler.CheckPressedKey(Keys.L)) { LightLevelCircle c = new LightLevelCircle(400, 10, 110); c.SetColor(Color.White); c.SetBorderColor(Color.Black); objects.Add(c); } else { LevelCircle c = new LevelCircle(300, 0, 10); c.SetColor(Color.Red); c.SetBorderColor(Color.Black); objects.Add(c); } } if (couldDrag != null && !couldDrag.CheckInside(handler)) { couldDrag = null; } if (colorize != null) { if (handler.CheckJustPressedKey(Keys.C)) { colorize = null; r.SetX(-15); r.SetY(-15); g.SetX(-15); g.SetY(-15); b.SetX(-15); b.SetY(-15); originX = originY = -15; } } else { if (handler.CheckJustPressedKey(Keys.A)) { if (couldDrag != null && couldDrag is LevelPerson) { tool.Use(couldDrag.GetX(), couldDrag.GetY(), couldDrag.GetWidth(), couldDrag.GetHeight()); animationMode = true; return; } } if (handler.CheckPressedKey(Keys.D3) && handler.CheckPressedKey(Keys.D4)) { textBox.TellSelected(true); fileMode = 5; } if (handler.CheckJustPressedKey(Keys.O)) { if (couldDrag != null && couldDrag is LevelPerson) { ((LevelPerson)couldDrag).MoveTo(couldDrag.GetX() + 200, couldDrag.GetY(), 60); } } if (handler.CheckJustPressedKey(Keys.N)) { if (couldDrag != null && couldDrag is LevelPerson) { fileMode = 4; textBox.TellSelected(true); } } if (handler.CheckJustPressedKey(Keys.G)) { //Load an animation onto a person. //loop it to test. if (couldDrag != null && couldDrag is LevelPerson) { fileMode = 3; textBox.TellSelected(true); } } if (handler.CheckJustPressedKey(Keys.C)) if (!modifyingOne && couldDrag != null && !dragging && colorize == null) { originX = handler.GetMouseX(); originY = handler.GetMouseY(); r.SetX(originX); g.SetX(originX); b.SetX(originX); r.SetY(originY); g.SetY(originY); b.SetY(originY); colorize = couldDrag; } } if (handler.CheckLeftMouseJustPressed()) { if (handler.CheckMouseIn(r)) { draggingColor = 1; original = r.GetPoint(); } else if (handler.CheckMouseIn(g)) { draggingColor = 2; original = g.GetPoint(); } else if (handler.CheckMouseIn(b)) { draggingColor = 3; original = b.GetPoint(); } else if (!modifyingOne && couldDrag != null && !dragging && draggingColor == 0 && colorize == null) { dragging = true; original = couldDrag.GetPoint(); dragged = couldDrag; if (bringToFront) { objects.Remove(dragged); objects.Add(dragged); } dragged.SetEditing(!hideEditing); } } if (handler.CheckRightMouseJustPressed()) if (!modifyingOne && couldDrag != null && !dragging) { objects.Remove(couldDrag); couldDrag = null; } if (handler.CheckLeftMouseJustReleased()) { draggingColor = 0; if (dragged != null) { dragged.SetEditing(!hideEditing); dragging = false; dragged = null; couldDrag = null; original = Point.Zero; } } if (draggingColor != 0 && colorize != null) { Point n = handler.GetMouseXY(); original = new Point(originX, originY); n -= original; if (n.X >= 130) { n.X = 130; } if (n.Y >= 130) { n.Y = 130; } if (n.Y <= -130) { n.Y = -130; } if (n.X <= -130) { n.X = -130; } if (draggingColor == 1) { //r r.SetPoint(original + n); } else if (draggingColor == 2) { //g g.SetPoint(original + n); } else { //b b.SetPoint(original + n); } int rc = (int)Math.Sqrt((r.GetX() - originX) * (r.GetX() - originX) + (r.GetY() - originY) * (r.GetY() - originY)); int gc = (int)Math.Sqrt((g.GetX() - originX) * (g.GetX() - originX) + (g.GetY() - originY) * (g.GetY() - originY)); int bc = (int)Math.Sqrt((b.GetX() - originX) * (b.GetX() - originX) + (b.GetY() - originY) * (b.GetY() - originY)); colorize.SetColor(new Color(rc, gc, bc)); } else if (dragging) { dragged.SetPoint(original + handler.LeftMouseDraggedBy()); } if (handler.CheckJustPressedKey(Keys.R)) { LevelRectangle n = new LevelRectangle(300, 10, 100, 100); n.SetBorderColor(Color.Black); objects.Add(n); } if (handler.CheckJustPressedKey(Keys.P)) { LevelRectangle n = new LevelPerson(300, 10, 100, 100, "X"); n.SetBorderColor(Color.Black); objects.Add(n); } } catch(Exception ex) { Logger.WriteLine(ex.ToString()); fileMode = 0; } }