using System; using System.Collections.Generic; using System.Text; using System.Drawing; using PaintDotNet; using PaintDotNet.Data; using PaintDotNet.SystemLayer; namespace Wealth_Wars { class MapLayerSelectedFields : MapLayerUserLoc { #region Public Methods /// /// Image with selected "field" /// /// Mouse location (on control) /// Horizontal scrollbar value /// Vertical scrollbar value /// List of selected fields /// public BitmapLayer MapDBFieldSelector(Point mouseLoc, int hSCBarValue, int vSCBarValue, ref List mapDBFieldSelectedList, BitmapLayer mapDBFieldSelected) { int dbNum = 0; hSCBarValue = (hSCBarValue + mouseLoc.X) / XLengthField; vSCBarValue = (vSCBarValue + mouseLoc.Y) / YLengthField; String userCLoc = hSCBarValue + "." + vSCBarValue; MapDBFieldLocation(ref dbNum, ref hSCBarValue, ref vSCBarValue); int xCoord = dbParamsLength[dbNum].Width - hSCBarValue; int yCoord = dbParamsLength[dbNum].Height - vSCBarValue; ColorBgra fieldBColor = ColorBgra.YellowGreen; XYCoordResetter(dbNum, ref xCoord, ref yCoord); for (int i = 0; i < mapDBFieldSelectedList.Count; i++) { if (userCLoc == mapDBFieldSelectedList[i]) { fieldBColor = ColorBgra.Zero; mapDBFieldSelectedList.RemoveAt(i); break; } } if (fieldBColor == ColorBgra.YellowGreen) { mapDBFieldSelectedList.Add(userCLoc); } //paint on map fieldBColor.A = 120; mapDBFieldSelected.Surface.Clear(fieldBColor, new Rectangle(xCoord, yCoord, XLengthField, YLengthField)); return mapDBFieldSelected; } /// /// Returns image presenting selected fields from certain map database region /// /// List of selected fields /// public BitmapLayer MapDBFieldOnMapLoad(List mapDBFieldSelectedList) { BitmapLayer mapDBFieldsSelected = MapDBLayerConverter(new Bitmap(ImageDimX, ImageDimY)); String[] tempValueStr = new String[2]; int xVal = 0; int yVal = 0; //Acquiring xVal and yVal poing on map dimension eg. 0-1560. MapDBUserLocXYExec(MapForm.mdbLoc[0], int.Parse(MapForm.mdbLoc[1]), int.Parse(MapForm.mdbLoc[2]), ref xVal, ref yVal); Point xCoordRange = new Point(); //x - the min, y - the max of range Point yCoordRange = new Point(); //x - the min, y - the max of range //checking the range (if the middle point is in the middle of image, if not //calculate the lenght to borders xCoordRange.X = xVal / XLengthField; xCoordRange.Y = (ImageDimX - xVal) / XLengthField; yCoordRange.X = yVal / YLengthField; yCoordRange.Y = (ImageDimY - yVal) / YLengthField; //parsing the center load map field location coordinates int xValEx = int.Parse(MapForm.mdbLoc[1]); int yValEx = int.Parse(MapForm.mdbLoc[2]); //converting to extended format location MapDBFieldLocationInv(MapForm.mdbLoc[0], ref xValEx, ref yValEx); //making the ranges (for further check) xCoordRange.X = xValEx - xCoordRange.X; xCoordRange.Y = xValEx + xCoordRange.Y; yCoordRange.X = yValEx - yCoordRange.X; yCoordRange.Y = yValEx + yCoordRange.Y; List mapDBSelectedFieldsOnRegion = new List(); for (int i = 0; i < mapDBFieldSelectedList.Count; i++) { tempValueStr = mapDBFieldSelectedList[i].Split(".".ToCharArray()); xVal = int.Parse(tempValueStr[0]); yVal = int.Parse(tempValueStr[1]); if ((xCoordRange.X <= xVal) && (xCoordRange.Y >= xVal)) { if ((yCoordRange.X <= yVal) && (yCoordRange.Y >= yVal)) { mapDBSelectedFieldsOnRegion.Add(mapDBFieldSelectedList[i].ToString()); //paint field with coordinates (extended) xVal, yVal) } } } if (mapDBSelectedFieldsOnRegion.Count > 0) { mapDBFieldsSelected = MapDBFieldSelectorExtended(mapDBSelectedFieldsOnRegion); } return mapDBFieldsSelected; } #endregion #region Private Methods /// /// Resets the x, y coordinates of field (extended format) /// /// Name of database /// X coordinate of field /// Y coordinate of field private void XYCoordResetter(int dbNum, ref int xCoord, ref int yCoord) { switch (dbNum) { case 0: xCoord = dbParamsLength[0].Width - xCoord + dbParamsLength[1].Width; yCoord += -1; break; case 1: xCoord += -1; yCoord += -1; break; case 2: xCoord = dbParamsLength[2].Width - xCoord + dbParamsLength[3].Width; yCoord = dbParamsLength[2].Height - yCoord + dbParamsLength[0].Height; break; case 3: xCoord += -1; yCoord = dbParamsLength[3].Height - yCoord + dbParamsLength[1].Height; break; } xCoord = xCoord * XLengthField; yCoord = yCoord * YLengthField; } /// /// Image with selected fields generated on map reload. /// /// The list with selected fields to paint on map. /// private BitmapLayer MapDBFieldSelectorExtended(List mapDBFieldSelectedList) { BitmapLayer mapDBFieldSelected = MapDBLayerConverter(new Bitmap(ImageDimX, ImageDimY)); ColorBgra fieldBColor = ColorBgra.YellowGreen; int dbNum; int xCoord; int yCoord; String[] tempValue; for (int i = 0; i < mapDBFieldSelectedList.Count; i++) { tempValue = mapDBFieldSelectedList[i].Split(".".ToCharArray()); dbNum = 0; xCoord = int.Parse(tempValue[0]); yCoord = int.Parse(tempValue[1]); MapDBFieldLocation(ref dbNum, ref xCoord, ref yCoord); xCoord = dbParamsLength[dbNum].Width - xCoord; yCoord = dbParamsLength[dbNum].Height - yCoord; XYCoordResetter(dbNum, ref xCoord, ref yCoord); fieldBColor.A = 120; mapDBFieldSelected.Surface.Clear(fieldBColor, new Rectangle(xCoord, yCoord, XLengthField, YLengthField)); } return mapDBFieldSelected; } #endregion } }