rendered paste bodyusing 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
/// <summary>
/// Image with selected "field"
/// </summary>
/// <param name="mouseLoc">Mouse location (on control)</param>
/// <param name="hSCBarValue">Horizontal scrollbar value</param>
/// <param name="vSCBarValue">Vertical scrollbar value</param>
/// <param name="mapDBFieldSelectedList">List of selected fields</param>
/// <returns></returns>
public BitmapLayer MapDBFieldSelector(Point mouseLoc, int hSCBarValue,
int vSCBarValue, ref List<String> 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;
}
/// <summary>
/// Returns image presenting selected fields from certain map database region
/// </summary>
/// <param name="mapDBFieldSelectedList">List of selected fields</param>
/// <returns></returns>
public BitmapLayer MapDBFieldOnMapLoad(List<String> 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<String> mapDBSelectedFieldsOnRegion = new List<String>();
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;
}
/// <summary>
/// Checks weather the chosen path can be followed
/// </summary>
/// <param name="mapDBFieldSelectedList">The list with selected fields</param>
public void MapPathValidator(List<String> mapDBFieldSelectedList)
{
if (mapDBFieldSelectedList.Count > 1)
{
String[] someValueStr = mapDBFieldSelectedList[0].Split(".".ToCharArray());
int xCoordO = int.Parse(someValueStr[0]);
int yCoordO = int.Parse(someValueStr[1]);
int xCoordN;
int yCoordN;
int[] tmpInt = new int[2];
for (int i = 1; i < mapDBFieldSelectedList.Count; i++)
{
someValueStr = mapDBFieldSelectedList[i].Split(".".ToCharArray());
xCoordN = int.Parse(someValueStr[0]);
yCoordN = int.Parse(someValueStr[1]);
if (((Math.Abs(xCoordO - xCoordN) == 1) && (yCoordO == yCoordN)) ||
((Math.Abs(yCoordO - yCoordN) == 1) && (xCoordO == xCoordN)))
{
xCoordO = xCoordN;
yCoordO = yCoordN;
}
else
{
tmpInt[0] = i-1;
tmpInt[1] = i;
List<String> possibleCheckL = CloseFieldSearcher(ref mapDBFieldSelectedList,
xCoordO, yCoordO, tmpInt);
if (possibleCheckL.Count > 0)
{
//show on program dialog with available choice(s)
}
}
}
}
}
#endregion
#region Private Methods
/// <summary>
/// Resets the x, y coordinates of field (extended format)
/// </summary>
/// <param name="dbNum">Name of database</param>
/// <param name="xCoord">X coordinate of field</param>
/// <param name="yCoord">Y coordinate of field</param>
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;
}
/// <summary>
/// Image with selected fields generated on map reload.
/// </summary>
/// <param name="mapDBFieldSelectedList">The list with selected fields to paint on map.</param>
/// <returns></returns>
private BitmapLayer MapDBFieldSelectorExtended(List<String> 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;
}
/// <summary>
/// Search for the nearest selected/to select field
/// </summary>
/// <param name="mapDBFieldSelectedList">The list with path fields</param>
/// <param name="xCoord">X coordinate of based field</param>
/// <param name="yCoord">Y coordinate of based field</param>
/// <param name="fieldPos">Numbers of position excluded, eg. field before, actual</param>
private List<String> CloseFieldSearcher(ref List<String> mapDBFieldSelectedList,
int xCoord, int yCoord, int[] fieldPos)
{
List<String> possibleCheckFields = new List<String>();
String[] xyValue;
int xCoordN;
int yCoordN;
Boolean searchState = true;
for (int i = 0; i < mapDBFieldSelectedList.Count; i++)
{
if ((i != fieldPos[0]) && (i != fieldPos[1]))
{
xyValue = mapDBFieldSelectedList[i].Split(".".ToCharArray());
xCoordN = int.Parse(xyValue[0]);
yCoordN = int.Parse(xyValue[1]);
if (((Math.Abs(xCoord - xCoordN) == 1) && (yCoord == yCoordN)) ||
((Math.Abs(yCoord - yCoordN) == 1) && (xCoord == xCoordN)))
{
mapDBFieldSelectedList.Insert(fieldPos[1], mapDBFieldSelectedList[i]);
searchState = false;
break;
//possibleCheckFields.Add(xCoordN + "." + yCoordN);
}
}
}
if (searchState == true)
{
for (int j = 0; j < mapDBFieldSelectedList.Count; j++)
{
xyValue = mapDBFieldSelectedList[j].Split(".".ToCharArray());
xCoordN = int.Parse(xyValue[0]);
yCoordN = int.Parse(xyValue[1]);
if ((xCoord - xCoordN == 0) &&
(Math.Abs(yCoord - yCoordN) == 2))
{
possibleCheckFields.Add(xCoordN + "." + (yCoordN - 1).ToString());
}
else if ((Math.Abs(xCoord - xCoordN) == 2) &&
(yCoord - yCoordN == 0))
{
possibleCheckFields.Add((xCoordN - 1).ToString() + "." + yCoordN);
}
else if ((Math.Abs(xCoord - xCoordN) == 1) &&
(Math.Abs(yCoord - yCoordN) == 1))
{
possibleCheckFields.Add(xCoordN + "." + (yCoordN - 1).ToString());
possibleCheckFields.Add((xCoord - 1).ToString() + "." + yCoordN);
}
}
}
return possibleCheckFields;
}
#endregion
}
}