private void UpdateMapViewer_MouseMove(object sender, MouseEventArgs e) { if (!m_fileOpen) { return; } lock (lockObject) { //update logic below int x, y; int zf = (int)(mapViewer1.TileSize * mapViewer1.ZoomFactor); x = e.X - (e.X % zf) + ((int)mapViewer1.Offset.X % zf); y = e.Y - (e.Y % zf) + ((int)mapViewer1.Offset.Y % zf); if (x < mapViewer1.Offset.X) { x = (int)mapViewer1.Offset.X; } else if (x > mapViewer1.Area.Width + mapViewer1.Offset.X - zf) { x = mapViewer1.Area.Width + (int)mapViewer1.Offset.X - zf; } if (y < mapViewer1.Offset.Y) { y = (int)mapViewer1.Offset.Y; } else if (y > mapViewer1.Area.Height + mapViewer1.Offset.Y - zf) { y = mapViewer1.Area.Height + (int)mapViewer1.Offset.Y - zf; } mapViewer1.SelectorPosition = new Vector2((float)x, (float)y); x = (int)(x - mapViewer1.Offset.X) / zf; y = (int)(y - mapViewer1.Offset.Y) / zf; if (shiftKeyPressed && prevShift && e.Button == MouseButtons.Left) { if (dragdir == DragState.NoDrag) { if (y == orig_y && x != orig_x) { dragdir = DragState.Horizontal; //horizontal } else if (x == orig_x && y != orig_y) { dragdir = DragState.Vertical; //vertical } } switch (dragdir) { //force coordinates to be what the originals were case DragState.Horizontal: y = orig_y; break; case DragState.Vertical: x = orig_x; break; } } tsLblSelX.Text = x.ToString(); tsLblSelY.Text = y.ToString(); switch (currentState) { case PlaceState.SINGLEFILL: if (e.Button == System.Windows.Forms.MouseButtons.Left) { Tile toAdd; switch (tabs.SelectedIndex) { case (int)LAYERS.Graphic: if (lvTiles.SelectedIndices.Count == 0) { break; } //if (tileset.Tiles[lvTiles.SelectedIndices[0]] is AnimatedTile) //{ // int index = tileset.CorrectedTileIndex(lvTiles.SelectedIndices[0], TileType.Animated); // toAdd = new AnimatedTile(x, y, index); //} //else //{ toAdd = new GraphicTile(x, y); (toAdd as GraphicTile).Graphic = tileset.CorrectedTileIndex <GraphicTile>(lvTiles.SelectedIndices[0]); //} m_openMap.AddTile(x, y, LAYERS.Graphic, toAdd); break; case (int)LAYERS.Special: float density = 0.0f; if (!CreateSpecialTile(out toAdd) || ((toAdd as SpecialTile).Type == SpecialTileSpec.WALL && !float.TryParse(txtDensity.Text, out density))) { break; } (toAdd as SpecialTile).Type = (SpecialTileSpec)cmbSpecialType.SelectedIndex; if ((toAdd as SpecialTile).Type == SpecialTileSpec.WALL) { (toAdd as SpecialTile).Density = density; } (toAdd as SpecialTile).Graphic = tileset.CorrectedTileIndex <SpecialTile>(lvTiles2.SelectedIndices[0]); m_openMap.AddTile(toAdd.X, toAdd.Y, LAYERS.Special, toAdd); break; case (int)LAYERS.NPC: //first check if there is an NPC spawn. if there is, open up a dialog to edit it // otherwise, create a new spawn int ID; uint speed = 0; if (!int.TryParse(txtNPCId.Text, out ID) || (chkNPCMoves.Checked && !uint.TryParse(txtNPCMoveSpeed.Text, out speed))) { MessageBox.Show("Please enter valid NPC id (integer)"); break; } if (chkNPCMoves.Checked) { toAdd = new NPCTile(x, y, ID, speed); } else { toAdd = new NPCTile(x, y, ID); } m_openMap.AddTile(x, y, LAYERS.NPC, toAdd); break; case (int)LAYERS.Interactive: //using this as item layer for now //first check if there is an Item spawn. if there is, open up a dialog to edit it // otherwise, create a new spawn break; } } break; case PlaceState.MULTIFILL: if (e.Button == System.Windows.Forms.MouseButtons.Left) { //the previous mouse state recorded the left button clicked if (tabs.SelectedIndex == (int)LAYERS.Special) { Tile based = m_openMap.GetTile(x, y, LAYERS.Special), spec; if (based != null) { break; } if (!CreateSpecialTile(out spec)) { break; } FillTileSpecial(based, spec); } else if (tabs.SelectedIndex == (int)LAYERS.Graphic) { Tile toAdd, current = m_openMap.GetTile(x, y, LAYERS.Graphic); if (lvTiles.SelectedItems.Count == 0) { return; } if (tileset.Tiles[tileset.CorrectedTileIndex <AnimatedTile>(lvTiles.SelectedIndices[0])] is AnimatedTile) { int index = tileset.CorrectedTileIndex <AnimatedTile>(lvTiles.SelectedIndices[0]); toAdd = new AnimatedTile(x, y, index); } else { toAdd = new GraphicTile(x, y); (toAdd as GraphicTile).Graphic = tileset.CorrectedTileIndex <GraphicTile>(lvTiles.SelectedIndices[0]); } FillTileGraphic(current, toAdd); } m_buffer.AddState(m_openMap); UpdateUndoRedo(); } break; case PlaceState.ERASER: if (e.Button == MouseButtons.Left) { m_openMap.EraseTile(int.Parse(tsLblSelX.Text), int.Parse(tsLblSelY.Text), (LAYERS)tabs.SelectedIndex); } else if (prevMousePressed && e.Button != MouseButtons.Left) { m_buffer.AddState(m_openMap); UpdateUndoRedo(); } break; case PlaceState.PAN: if (e.Button == System.Windows.Forms.MouseButtons.Left) { using (MemoryStream mem = new MemoryStream(Properties.Resources.hand_closed)) { mapViewer1.Cursor = new Cursor(mem); } if (!prevMousePressed) { originalLocation.X = e.X; originalLocation.Y = e.Y; originalAdjustment.X = mapViewer1.Offset.X; originalAdjustment.Y = mapViewer1.Offset.Y; } else { mapViewer1.Offset = new Vector2(originalAdjustment.X + (e.X - originalLocation.X), originalAdjustment.Y + (e.Y - originalLocation.Y)); } } else { using (MemoryStream mem = new MemoryStream(Properties.Resources.hand_cur)) { mapViewer1.Cursor = new Cursor(mem); } } break; } prevMousePressed = (e.Button == System.Windows.Forms.MouseButtons.Left); if (shiftKeyPressed && !prevShift && prevMousePressed) { dragdir = DragState.NoDrag; prevShift = true; orig_x = x; orig_y = y; } mapViewer1.State = currentState; mapViewer1.ShowGrid = mnuGrid.Checked; tsLblNumTiles.Text = ""; foreach (SortedList <string, Tile> sublist in m_openMap.Layers) { //show the number of tiles in each layer in the appropriate TS label tsLblNumTiles.Text += sublist.Count.ToString(); if (sublist != m_openMap.Layers.Last()) { tsLblNumTiles.Text += " / "; } } mapViewer1.Refresh(); //force the control to redraw after updating } }