private static void UpdateMapItems(MapItem[] items) { foreach (MapItem item in items) { item.ID = int.Parse(item.Object.Name); } }
public void Delete(MapItem item) { if (item is MapObject) { MapObject o = (MapObject)item; if (objects.Contains(o)) { objects.Remove(o); layer.GetChild("obj").childs.Remove(o.Object.Name); Map.Pad(layer.GetChild("obj"), objects.ToArray()); } } else if (item is MapTile) { MapTile t = (MapTile)item; if (tiles.Contains(t)) { tiles.Remove(t); layer.GetChild("tile").childs.Remove(t.Object.Name); Map.Pad(layer.GetChild("tile"), tiles.ToArray()); } } else { Map.Instance.Delete(item); } }
public void Add(MapItem item) { if (item is MapObject) { MapObject o = (MapObject)item; int id = 0; while(layer.GetChild("obj").childs.Contains(id.ToString())) id++; o.ID = id; o.Object.Name = o.ID.ToString(); objects.Add(o); objects.Sort(Map.CompareItems); layer.GetChild("obj").Add(o.Object); OrderObjects(); } else if (item is MapTile) { MapTile t = (MapTile)item; string style = info.GetString("tS"); IMGFile tilesF = MapEditor.file.Directory.GetIMG("Tile/" + style + ".img"); if (tilesF.GetChild(t.Object.GetString("u") + "/" + t.Object.GetInt("no").ToString()) == null) { t.Object.SetInt("no", MapEditor.Instance.random.Next(tilesF.GetChild(t.Object.GetString("u")).childs.Count)); } IMGEntry image = MapEditor.file.Directory.GetIMG("Tile/" + style + ".img").GetChild(t.Object.GetString("u") + "/" + t.Object.GetInt("no").ToString()); if (t.Image != image) t.Image = image; int id = 0; while (layer.GetChild("tile").childs.Contains(id.ToString())) id++; t.ID = id; t.Object.Name = t.ID.ToString(); tiles.Add(t); tiles.Sort(Map.CompareItems); layer.GetChild("tile").Add(t.Object); OrderTiles(); } else { Map.Instance.Add(item); } }
public static void Pad(IMGEntry entry, MapItem[] items, int startID) { while (!IsPadded(entry, startID)) { foreach (IMGEntry e in entry.childs.Values) { int ID = int.Parse(e.Name); if (ID > startID) { if (!entry.childs.Contains((ID - 1).ToString())) { e.Rename((ID - 1).ToString()); break; } } } } UpdateMapItems(items); }
private void GraphicPanel_OnMouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (DrawMode.Checked) { if (!createdCurve.Close()) curves.Remove(createdCurve); else { try { createdCurve.Simplify(); } catch { curves.Remove(createdCurve); } } createdCurve = null; } else { MagnetDisable(); if (draggingSelection) { if (selectingX != e.X && selectingY != e.Y) { int x1 = (int)(selectingX / Zoom), x2 = (int)(e.X / Zoom); int y1 = (int)(selectingY / Zoom), y2 = (int)(e.Y / Zoom); if (x1 > x2) { x1 = (int)(e.X / Zoom); x2 = (int)(selectingX / Zoom); } if (y1 > y2) { y1 = (int)(e.Y / Zoom); y2 = (int)(selectingY / Zoom); } List<MapItem> items; if (EditFH.Checked) { items = Map.Instance.layers[(int)Layer.Value].GetConnectionsAt(new Rectangle(x1, y1, x2 - x1, y2 - y1)); } else { items = Map.Instance.layers[(int)Layer.Value].GetItemsAt(new Rectangle(x1, y1, x2 - x1, y2 - y1)); } foreach (MapItem item in items) { if (selected.Contains(item) && CtrlPressed) { selected.Remove(item); item.Selected = false; } else if (!selected.Contains(item)) { selected.Add(item); item.Selected = true; } } if (selected.Count == 1 && EditObj.Checked) toolStripStatusLabel1.Text = "Z: " + selected[0].Object.GetInt("z"); } draggingSelection = false; TempChanged.Clear(); } else { if (dragged && (sX != e.X || sY != e.Y)) { undo.Push(new ActionMove(new List<MapItem>(selected), e.X - sX, e.Y - sY)); redo.Clear(); } dragged = false; if (selectedDragged != null) { if (e.X == sX && e.Y == sY) { Deselect(); selected.Add(selectedDragged); selectedDragged.Selected = true; if (selectedDragged2 != null) { selected.Add(selectedDragged2); selectedDragged2.Selected = true; } if (EditObj.Checked) toolStripStatusLabel1.Text = "Z: " + selectedDragged.Object.GetInt("z"); } selectedDragged = null; selectedDragged2 = null; } } if (EditTile.Checked) Map.Instance.layers[(int)Layer.Value].OrderTiles(); } } else if (e.Button == MouseButtons.Middle) { wheelClicked = false; if (scrollingDragged) { scrolling = false; Cursor = Cursors.Default; } } }
private void GraphicPanel_OnMouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (DrawMode.Checked) { createdCurve = new MapCurve(); createdCurve.AddPoint(e.Location); curves.Add(createdCurve); } else { if (LinkToFH.Checked) { if (EditTile.Checked || EditObj.Checked) { MapFootholds group = Map.Instance.layers[(int)Layer.Value].GetFootholdGroupAt((int)(e.X / Zoom), (int)(e.Y / Zoom)); if (group != null) { foreach (MapItem s in selected) { s.Object.SetInt("zM", group.ID); if (s is ICached) (s as ICached).Cache(); } if (selectedGroup != null) { selectedGroup.Selected = false; } selectedGroup = group; selectedGroup.Selected = true; } } return; } else if (FootholdsCreator.Checked) { if (EditFH.Checked) { MapFootholdDesign fh = Map.Instance.layers[(int)Layer.Value].GetFootholdDesignAt((int)(e.X / Zoom), (int)(e.Y / Zoom)); if (fh != null) { if (!FHCreating.Contains(fh)) { FHCreating.Add(fh); } } else { if (FHCreating.Count > 0) { CreateFootholds(FHCreating); FHCreating.Clear(); } } } else if (EditLR.Checked) { MapLRDesign lr = Map.Instance.layers[(int)Layer.Value].GetLRDesignAt((int)(e.X / Zoom), (int)(e.Y / Zoom)); if (lr != null && !LRCreating.Contains(lr)) { if (LRCreating.Count > 0) { if (LRCreating[0].GetX() == lr.GetX() && LRCreating[0].ladder == lr.ladder) { LRCreating.Add(lr); CreateLRs(LRCreating); LRCreating.Clear(); } } else { LRCreating.Add(lr); } } else { LRCreating.Clear(); } } return; } //GraphicPanel.Focus(); if (EditMode.Checked && Map.Instance != null && !dragged) { if (EditTile.Checked || EditObj.Checked || EditLife.Checked || EditReactor.Checked || EditBack.Checked) { if (Map.Instance.layers[(int)Layer.Value].GetItemAt((int)(e.X / Zoom), (int)(e.Y / Zoom)) == null) { draggingSelection = true; selectingX = e.X; selectingY = e.Y; if (!CtrlPressed && !ShiftPressed) { Deselect(); } } else { if (CtrlPressed && selected.Count > 0) { MapItem at = Map.Instance.layers[(int)Layer.Value].GetItemAt((int)(e.X / Zoom), (int)(e.Y / Zoom)); if (at != null) { if (selected.Contains(at)) { selected.Remove(at); at.Selected = false; if (selected.Count == 0) Deselect(); else if (selected.Count == 1 && EditObj.Checked) toolStripStatusLabel1.Text = "Z: " + selected[0].Object.GetInt("z"); } else { selected.Add(at); at.Selected = true; toolStripStatusLabel1.Text = ""; } } } else { if (EditTile.Checked && selected.Count == 1 && selected[0].IsPointInArea((int)(e.X / Zoom), (int)(e.Y / Zoom))) { dragged = true; selectedDragged = selected[0]; sX = e.X; sY = e.Y; } else { MapItem at = Map.Instance.layers[(int)Layer.Value].GetItemAt((int)(e.X / Zoom), (int)(e.Y / Zoom)); if (selected.Count > 1 && at != null && (selected.Contains(at))) { dragged = true; selectedDragged = at; sX = e.X; sY = e.Y; } else { Deselect(); if (at != null) { selected.Add(at); at.Selected = true; if (EditObj.Checked) toolStripStatusLabel1.Text = "Z: " + at.Object.GetInt("z"); } } } } } if (EditTile.Checked) Map.Instance.layers[(int)Layer.Value].OrderTiles(); } else if (EditFH.Checked) { if (Map.Instance.layers[(int)Layer.Value].GetConnectionAt((int)(e.X / Zoom), (int)(e.Y / Zoom)).Count == 0) { draggingSelection = true; selectingX = e.X; selectingY = e.Y; if (!CtrlPressed && !ShiftPressed) { Deselect(); } } else { if (CtrlPressed && selected.Count > 0) { List<MapFootholdSide> list = Map.Instance.layers[(int)Layer.Value].GetConnectionAt((int)(e.X / Zoom), (int)(e.Y / Zoom)); if (list.Count > 0) { if (selected.Contains(list[0])) { foreach (MapFootholdSide f in list) { selected.Remove(f); f.Selected = false; } if (selected.Count == 0) Deselect(); } else { foreach (MapFootholdSide f in list) { selected.Add(f); f.Selected = true; } } } } else { List<MapFootholdSide> list = Map.Instance.layers[(int)Layer.Value].GetConnectionAt((int)(e.X / Zoom), (int)(e.Y / Zoom)); if (selected.Count > 2 && list.Count > 0 && selected.Contains(list[0])) { dragged = true; selectedDragged = list[0]; if (list.Count > 1) selectedDragged2 = list[1]; sX = e.X; sY = e.Y; } else { Deselect(); if (list.Count > 0) { foreach (MapFootholdSide f in list) { selected.Add(f); f.Selected = true; } } } } } } else if (EditLR.Checked) { MapLRSide lr = Map.Instance.layers[(int)Layer.Value].GetLRSideAt((int)(e.X / Zoom), (int)(e.Y / Zoom)); if (lr != null && selected.Contains(lr)) { dragged = true; selectedDragged = lr; sX = e.X; sY = e.Y; } else { Deselect(); if (lr != null) { selected.Add(lr); lr.Selected = true; } } } else if (EditSeat.Checked || EditPortal.Checked || EditToolTip.Checked || EditClock.Checked) { MapItem item = null; item = Map.Instance.GetItemAt((int)(e.X / Zoom), (int)(e.Y / Zoom)); if (item != null && selected.Contains(item)) { dragged = true; selectedDragged = item; sX = e.X; sY = e.Y; } else { Deselect(); if (item != null) { selected.Add(item); item.Selected = true; } } } } if (selected.Count > 0) { bool clickedIn = false; foreach (MapItem s in selected) { if (s.IsPointInArea((int)(e.X / Zoom), (int)(e.Y / Zoom))) { clickedIn = true; } } if (clickedIn) { dragged = true; sX = e.X; sY = e.Y; lastX = e.X; lastY = e.Y; } } if (selected.Count == 1) { toolStripStatusLabel1.Text = selected[0].ToString(); } } if (scrolling) { scrolling = false; Cursor = Cursors.Default; } } else if (e.Button == MouseButtons.Middle) { wheelClicked = true; scrolling = true; scrollingDragged = false; scrollPosition = new Point(e.X - ShiftX, e.Y - ShiftY); if (vScrollBar1.Visible && hScrollBar1.Visible) { Cursor = Cursors.NoMove2D; } else if (vScrollBar1.Visible) { Cursor = Cursors.NoMoveVert; } else if (hScrollBar1.Visible) { Cursor = Cursors.NoMoveHoriz; } else { scrolling = false; } } }
public void Add(MapItem item) { if (item is MapLife) { MapLife l = (MapLife)item; int id = 0; IMGEntry le = map.GetChild("life"); if (le == null) { le = new IMGEntry(); le.Name = "life"; Map.Instance.map.Add(le); } while (le.childs.Contains(id.ToString())) id++; l.ID = id; l.Object.Name = l.ID.ToString(); lifes.Add(l); lifes.Sort(Map.CompareItems); le.Add(l.Object); } else if (item is MapReactor) { MapReactor r = (MapReactor)item; int id = 0; IMGEntry re = map.GetChild("reactor"); if (re == null) { re = new IMGEntry(); re.Name = "reactor"; Map.Instance.map.Add(re); } while (re.childs.Contains(id.ToString())) id++; r.ID = id; r.Object.Name = r.ID.ToString(); reactors.Add(r); reactors.Sort(Map.CompareItems); re.Add(r.Object); } else if (item is MapLR) { MapLR l = (MapLR)item; int id = 1; IMGEntry lrse = map.GetChild("ladderRope"); if (lrse == null) { lrse = new IMGEntry(); lrse.Name = "ladderRope"; Map.Instance.map.Add(lrse); } while (lrse.childs.Contains(id.ToString())) id++; l.ID = id; l.Object.Name = l.ID.ToString(); lrs.Add(l); lrs.Sort(Map.CompareItems); lrse.Add(l.Object); } else if (item is MapSeat) { MapSeat s = (MapSeat)item; int id = 0; IMGEntry seate = map.GetChild("seat"); if (seate == null) { seate = new IMGEntry(); seate.Name = "seat"; Map.Instance.map.Add(seate); } while (seate.childs.Contains(id.ToString())) id++; s.ID = id; s.Object.Name = s.ID.ToString(); seats.Add(s); seats.Sort(Map.CompareItems); seate.Add(s.Object); } else if (item is MapPortal) { MapPortal p = (MapPortal)item; int id = 0; IMGEntry portalse = map.GetChild("portal"); if (portalse == null) { portalse = new IMGEntry(); portalse.Name = "portal"; Map.Instance.map.Add(portalse); } while (portalse.childs.Contains(id.ToString())) id++; p.ID = id; p.Object.Name = p.ID.ToString(); p.Image = MapEditor.file.Directory.GetIMG("MapHelper.img").GetChild("portal/game/pv/0"); portals.Add(p); portals.Sort(Map.CompareItems); portalse.Add(p.Object); } else if (item is MapToolTip) { MapToolTip t = (MapToolTip)item; int id = 0; IMGEntry ToolTips = map.GetChild("ToolTip"); if (ToolTips == null) { ToolTips = new IMGEntry(); ToolTips.Name = "ToolTip"; Map.Instance.map.Add(ToolTips); } while (ToolTips.childs.Contains(id.ToString())) id++; t.ID = id; t.Object.Name = t.ID.ToString(); tooltips.Add(t); tooltips.Sort(Map.CompareItems); ToolTips.Add(t.Object); } else if (item is MapClock) { if (clock == null) { clock = item as MapClock; clock.Object.Name = "clock"; clock.Image = MapEditor.file.Directory.GetIMG("Obj/etc.img").GetChild("clock/fontTime"); map.Add(clock.Object); } } else { layers[(int)MapEditor.Instance.Layer.Value].Add(item); } }
public void Delete(MapItem item) { if (item is MapLife) { MapLife l = (MapLife)item; if (lifes.Contains(l)) { lifes.Remove(l); map.GetChild("life").childs.Remove(l.Object.Name); Map.Pad(map.GetChild("life"), lifes.ToArray()); } } else if (item is MapReactor) { MapReactor r = (MapReactor)item; if (reactors.Contains(r)) { reactors.Remove(r); map.GetChild("reactor").childs.Remove(r.Object.Name); Map.Pad(map.GetChild("reactor"), reactors.ToArray()); } } else if (item is MapLR) { MapLR l = (MapLR)item; if (lrs.Contains(l)) { lrs.Remove(l); map.GetChild("ladderRope").childs.Remove(l.Object.Name); Map.Pad(map.GetChild("ladderRope"), lrs.ToArray(), 1); } } else if (item is MapSeat) { MapSeat s = (MapSeat)item; if (seats.Contains(s)) { seats.Remove(s); map.GetChild("seat").childs.Remove(s.Object.Name); Map.Pad(map.GetChild("seat"), seats.ToArray()); } } else if (item is MapPortal) { MapPortal p = (MapPortal)item; if (portals.Contains(p)) { portals.Remove(p); map.GetChild("portal").childs.Remove(p.Object.Name); Map.Pad(map.GetChild("portal"), portals.ToArray()); // TODO SORT } } else if (item is MapToolTip) { MapToolTip t = (MapToolTip)item; if (tooltips.Contains(t)) { tooltips.Remove(t); map.GetChild("ToolTip").childs.Remove(t.Object.Name); t.Image.parent.childs.Remove(t.Object.Name); Map.Pad(map.GetChild("ToolTip"), t.Image.parent, tooltips.ToArray()); } } else if (item is MapToolTipCorner) { Delete(((MapToolTipCorner)item).ToolTip); } else if (item is MapClock) { if (clock != null) { map.childs.Remove("clock"); clock = null; } } else { layers[(int)MapEditor.Instance.Layer.Value].Delete(item); } }
public static int CompareItems(MapItem o1, MapItem o2) { return o1.ID.CompareTo(o2.ID); }
public static void Pad(IMGEntry entry, MapItem[] items) { Pad(entry, items, 0); }