Ejemplo n.º 1
0
 private void DrawVerticalListPixel(ProvinceDefinitionItem province, Color drawColor)
 {
     foreach (var pixel in province.Pixels.Where(pixel => pixel.XPos % 4 == 1))
     {
         BitmapMapOverlay.SetPixel(pixel.XPos, pixel.YPos, drawColor);
     }
 }
Ejemplo n.º 2
0
        public void MarkLocation(MarkerItem markerItem, int xPos, int yPos)
        {
            if (xPos <= m_mapProvinceDefinitionItem.GetLength(0) && yPos <= m_mapProvinceDefinitionItem.GetLength(1))
            {
                ProvinceDefinitionItem provinceDefinitionItem = m_mapProvinceDefinitionItem[xPos, yPos];

                if (markerItem.ListProvince.Contains(provinceDefinitionItem))
                {
                    if (markerItem.Location != provinceDefinitionItem.IdProvince)
                    {
                        ProvinceDefinitionItem oldProvinceDefinitionItem = markerItem.ListProvince.Find(findItem => (findItem.IdProvince == markerItem.Location));

                        if (oldProvinceDefinitionItem != null)
                        {
                            DrawCheckeredListPixel(oldProvinceDefinitionItem, markerItem.Color);
                        }

                        markerItem.Location = provinceDefinitionItem.IdProvince;

                        DrawCheckeredListPixel(provinceDefinitionItem, Color.Black);
                    }
                    else
                    {
                        // nothing todo
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void DrawVerticalListPixel(ProvinceDefinitionItem provinceDefinitionItem, Color drawColor)
        {
            foreach (Pixel pixel in provinceDefinitionItem.ListPixel)
            {
                int posX = pixel.XPos % 4;

                if (posX == 1)
                {
                    m_bitmapMapOverlay.SetPixel(pixel.XPos, pixel.YPos, drawColor);
                }
            }
        }
Ejemplo n.º 4
0
        public void MarkLocation()
        {
            foreach (MarkerItem markerItem in m_listMarkerItem)
            {
                ProvinceDefinitionItem provinceDefinitionItem = markerItem.ListProvince.Find(findItem => findItem.IdProvince == markerItem.Location);

                if (provinceDefinitionItem != null)
                {
                    DrawCheckeredListPixel(provinceDefinitionItem, Color.Black);
                }
            }
        }
Ejemplo n.º 5
0
        //------------------------------------------------------------------------
        // Helper
        //------------------------------------------------------------------------

        private void DrawCheckeredListPixel(ProvinceDefinitionItem provinceDefinitionItem, Color drawColor)
        {
            foreach (Pixel pixel in provinceDefinitionItem.ListPixel)
            {
                int posX = pixel.XPos % 3;
                int posY = pixel.YPos % 3;

                if ((posX == 1) && (posY == 1))
                {
                    m_bitmapMapOverlay.SetPixel(pixel.XPos, pixel.YPos, drawColor);
                }
            }
        }
Ejemplo n.º 6
0
        private void ReadProvinceDefinition()
        {
            m_listProvinceDefinition.Clear();

            String pathOfProvinceDefinition = String.Format(@"{0}\{1}", Application.StartupPath, "definition.csv");

            if (File.Exists(pathOfProvinceDefinition))
            {
                String[] listDefinition = File.ReadAllLines(pathOfProvinceDefinition, m_encoding1252);

                foreach (String definition in listDefinition)
                {
                    String[] listSplittedDefinition = definition.Split(';');

                    if (listSplittedDefinition.Length >= 5)
                    {
                        int idProvince, r, g, b;

                        String nameOf, x;

                        int.TryParse(listSplittedDefinition[0], out idProvince);
                        int.TryParse(listSplittedDefinition[1], out r);
                        int.TryParse(listSplittedDefinition[2], out g);
                        int.TryParse(listSplittedDefinition[3], out b);

                        nameOf = listSplittedDefinition[4];
                        x      = "";

                        ProvinceDefinitionItem provinceDefinitionItem = m_listProvinceDefinition.Find(searchItem => ((searchItem.R == r) && (searchItem.G == g) && (searchItem.B == b)));

                        if (provinceDefinitionItem == null)
                        {
                            m_listProvinceDefinition.Add(new ProvinceDefinitionItem(idProvince, r, g, b, nameOf, x));
                        }
                        else
                        {
                            int k = 4711;
                        }
                    }
                    else
                    {
                        int k = 4711;
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public void MarkOutgoing(MarkerItem markerItem, int xPos, int yPos)
        {
            if (xPos <= m_mapProvinceDefinitionItem.GetLength(0) && yPos <= m_mapProvinceDefinitionItem.GetLength(1))
            {
                ProvinceDefinitionItem markedProvinceDefinitionItem = m_mapProvinceDefinitionItem[xPos, yPos];

                MarkerItem outgoingMarkterItem = m_listMarkerItem.Find(findItem => findItem.ListProvince.Contains(markedProvinceDefinitionItem));

                if ((outgoingMarkterItem != null) && (outgoingMarkterItem != markerItem) && !outgoingMarkterItem.ListOutgoing.Contains(markerItem))
                {
                    if (markerItem.ListOutgoing.Contains(outgoingMarkterItem))
                    {
                        markerItem.ListOutgoing.Remove(outgoingMarkterItem);

                        foreach (ProvinceDefinitionItem provinceDefinitionItem in outgoingMarkterItem.ListProvince)
                        {
                            if (outgoingMarkterItem.Location != provinceDefinitionItem.IdProvince)
                            {
                                DrawHorizontalListPixel(provinceDefinitionItem, outgoingMarkterItem.Color);
                            }
                        }
                    }
                    else
                    {
                        markerItem.ListOutgoing.Add(outgoingMarkterItem);

                        foreach (ProvinceDefinitionItem provinceDefinitionItem in outgoingMarkterItem.ListProvince)
                        {
                            if (outgoingMarkterItem.Location != provinceDefinitionItem.IdProvince)
                            {
                                DrawHorizontalListPixel(provinceDefinitionItem, Color.White);
                            }
                        }
                    }
                }
                else
                {
                    // nothing todo
                }
            }
        }
Ejemplo n.º 8
0
        //------------------------------------------------------------------------

        public void Mark(MarkerItem markerItem, int xPos, int yPos)
        {
            if (xPos <= m_mapProvinceDefinitionItem.GetLength(0) && yPos <= m_mapProvinceDefinitionItem.GetLength(1))
            {
                ProvinceDefinitionItem provinceDefinitionItem = m_mapProvinceDefinitionItem[xPos, yPos];

                Color drawColor;

                if (markerItem.ListProvince.Contains(provinceDefinitionItem))
                {
                    markerItem.ListProvince.Remove(provinceDefinitionItem);

                    drawColor = Color.FromArgb(0, 0, 0, 0);
                }
                else
                {
                    foreach (MarkerItem clearMarkerItem in m_listMarkerItem)
                    {
                        clearMarkerItem.ListProvince.Remove(provinceDefinitionItem);
                    }

                    markerItem.ListProvince.Add(provinceDefinitionItem);

                    drawColor = markerItem.Color;
                }

                //------------------------------------------------------------------

                foreach (Pixel pixel in provinceDefinitionItem.ListPixel)
                {
                    m_bitmapMapOverlay.SetPixel(pixel.XPos, pixel.YPos, drawColor);
                }
            }
            else
            {
                int k = 4711;
            }
        }
Ejemplo n.º 9
0
        public void ReadMarker(String pathOfMarkerFile)
        {
            m_listMarkerItem.Clear();

            if (File.Exists(pathOfMarkerFile))
            {
                Dictionary <int, int> dictDuplicateIdProvince = new Dictionary <int, int> ();

                String[] listMarker = File.ReadAllLines(pathOfMarkerFile, m_encoding1252);

                foreach (String marker in listMarker)
                {
                    if (!marker.Contains('#'))
                    {
                        String[] listSplittedMarker = marker.Split('|');

                        if (listSplittedMarker.Length == 5)
                        {
                            int r, g, b;

                            String name;

                            name = listSplittedMarker[0];

                            int.TryParse(listSplittedMarker[1], out r);
                            int.TryParse(listSplittedMarker[2], out g);
                            int.TryParse(listSplittedMarker[3], out b);

                            String[] listIdProvince = listSplittedMarker[4].Split(',');

                            MarkerItem markerItem = m_listMarkerItem.Find(searchItem => ((searchItem.R == r) && (searchItem.G == g) && (searchItem.B == b)));

                            if (markerItem == null)
                            {
                                markerItem = new MarkerItem(name, r, g, b, 255, 0, "");

                                foreach (String stringIdProvince in listIdProvince)
                                {
                                    int idProvince = -1;

                                    int.TryParse(stringIdProvince.Trim(), out idProvince);

                                    if ((idProvince > 0) && !dictDuplicateIdProvince.ContainsKey(idProvince))
                                    {
                                        ProvinceDefinitionItem provinceDefinitionItem = m_listProvinceDefinition.Find(findItem => findItem.IdProvince == idProvince);

                                        if (provinceDefinitionItem != null)
                                        {
                                            dictDuplicateIdProvince.Add(idProvince, idProvince);

                                            markerItem.ListProvince.Add(provinceDefinitionItem);
                                        }
                                    }
                                }

                                m_listMarkerItem.Add(markerItem);
                            }
                        }
                        else if (listSplittedMarker.Length == 7)
                        {
                            int r = 0, g = 0, b = 0, location = 0;

                            String name;

                            name = listSplittedMarker[0];

                            int.TryParse(listSplittedMarker[1], out r);
                            int.TryParse(listSplittedMarker[2], out g);
                            int.TryParse(listSplittedMarker[3], out b);

                            int.TryParse(listSplittedMarker[4], out location);

                            String[] listIdProvince = listSplittedMarker[6].Split(',');

                            MarkerItem markerItem = m_listMarkerItem.Find(searchItem => ((searchItem.R == r) && (searchItem.G == g) && (searchItem.B == b)));

                            if (markerItem == null)
                            {
                                markerItem = new MarkerItem(name, r, g, b, 255, location, listSplittedMarker[5]);

                                foreach (String stringIdProvince in listIdProvince)
                                {
                                    int idProvince = -1;

                                    int.TryParse(stringIdProvince.Trim(), out idProvince);

                                    if ((idProvince > 0) && !dictDuplicateIdProvince.ContainsKey(idProvince))
                                    {
                                        ProvinceDefinitionItem provinceDefinitionItem = m_listProvinceDefinition.Find(findItem => findItem.IdProvince == idProvince);

                                        if (provinceDefinitionItem != null)
                                        {
                                            dictDuplicateIdProvince.Add(idProvince, idProvince);

                                            markerItem.ListProvince.Add(provinceDefinitionItem);
                                        }
                                    }
                                }

                                m_listMarkerItem.Add(markerItem);
                            }
                            else
                            {
                                int k = 4711;
                            }
                        }
                        else
                        {
                            int k = 4711;
                        }
                    }
                }

                //------------------------------------------------------------------

                foreach (MarkerItem markerItem in m_listMarkerItem)
                {
                    String[] listOutgoing = markerItem.Outgoing.Split(',');

                    foreach (String outgoing in listOutgoing)
                    {
                        if (outgoing.Length > 0)
                        {
                            markerItem.ListOutgoing.AddRange(m_listMarkerItem.FindAll(findItem => findItem.Name.Equals(outgoing)));
                        }
                    }
                }
            }
        }
Ejemplo n.º 10
0
        private void ReadPixel()
        {
            String pathOfBitmapMap = String.Format(@"{0}\{1}", Application.StartupPath, @"Gfx\provinces.bmp");

            if (File.Exists(pathOfBitmapMap))
            {
                int idProvince = GetMaxIdProvince();

                //------------------------------------------------------------------

                StringBuilder colorKey = new StringBuilder();

                Dictionary <String, ProvinceDefinitionItem> dictCache = new Dictionary <string, ProvinceDefinitionItem> ();

                foreach (ProvinceDefinitionItem provinceDefinitionItemCache in m_listProvinceDefinition)
                {
                    colorKey.Clear();

                    colorKey.Append(provinceDefinitionItemCache.R);
                    colorKey.Append(provinceDefinitionItemCache.G);
                    colorKey.Append(provinceDefinitionItemCache.B);

                    dictCache.Add(colorKey.ToString(), provinceDefinitionItemCache);
                }

                //------------------------------------------------------------------

                String colorKeyString = "";

                Color pixelColor;

                m_bitmapMap = new Bitmap(Bitmap.FromFile(pathOfBitmapMap));

                m_mapProvinceDefinitionItem = new ProvinceDefinitionItem[m_bitmapMap.Width, m_bitmapMap.Height];

                Rectangle rectangle = new Rectangle(0, 0, m_bitmapMap.Width, m_bitmapMap.Height);

                System.Drawing.Imaging.BitmapData bitmapData = m_bitmapMap.LockBits(rectangle, System.Drawing.Imaging.ImageLockMode.ReadOnly, m_bitmapMap.PixelFormat);

                int length = bitmapData.Stride * m_bitmapMap.Height;

                byte[] rawBytes = new byte[length];

                System.Runtime.InteropServices.Marshal.Copy(bitmapData.Scan0, rawBytes, 0, length);

                m_bitmapMap.UnlockBits(bitmapData);

                ProvinceDefinitionItem provinceDefinitionItem = new ProvinceDefinitionItem();

                for (int nXndex = 0; nXndex < m_bitmapMap.Width; nXndex++)
                {
                    for (int nYndex = 0; nYndex < m_bitmapMap.Height; nYndex++)
                    {
                        pixelColor = Color.FromArgb(rawBytes[nYndex * bitmapData.Stride + nXndex * 4 + 3], rawBytes[nYndex * bitmapData.Stride + nXndex * 4 + 2], rawBytes[nYndex * bitmapData.Stride + nXndex * 4 + 1], rawBytes[nYndex * bitmapData.Stride + nXndex * 4]);

                        if (!((provinceDefinitionItem.R == pixelColor.R) && (provinceDefinitionItem.G == pixelColor.G) && (provinceDefinitionItem.B == pixelColor.B)))
                        {
                            colorKey.Clear();

                            colorKey.Append(pixelColor.R);
                            colorKey.Append(pixelColor.G);
                            colorKey.Append(pixelColor.B);

                            colorKeyString = colorKey.ToString();

                            if (dictCache.ContainsKey(colorKeyString))
                            {
                                provinceDefinitionItem = dictCache[colorKeyString];
                            }
                            else
                            {
                                String name = String.Format("NewProvince_{0}", idProvince);

                                provinceDefinitionItem = new ProvinceDefinitionItem(++idProvince, pixelColor.R, pixelColor.G, pixelColor.B, name, "");
                            }
                        }

                        provinceDefinitionItem.ListPixel.Add(new Pixel(nXndex, nYndex));

                        m_mapProvinceDefinitionItem[nXndex, nYndex] = provinceDefinitionItem;
                    }
                }

                m_bitmapMapOverlay = new Bitmap(m_bitmapMap);
            }
        }
Ejemplo n.º 11
0
        private void ReadPixel()
        {
            string pathOfBitmapMap = $@"{Application.StartupPath}\{@"Gfx\provinces.bmp"}";

            if (File.Exists(pathOfBitmapMap) == false)
            {
                return;
            }

            int idProvince = GetMaxIdProvince();

            var dictCache = Provinces.ToDictionary(p => $"{p.R}{p.G}{p.B}");

            BitmapMap = new Bitmap(Image.FromFile(pathOfBitmapMap));

            m_mapProvinceDefinitionItem = new ProvinceDefinitionItem[BitmapMap.Width, BitmapMap.Height];

            Rectangle rectangle = new Rectangle(0, 0, BitmapMap.Width, BitmapMap.Height);

            BitmapData bitmapData = BitmapMap.LockBits(rectangle, ImageLockMode.ReadOnly, BitmapMap.PixelFormat);

            int length = bitmapData.Stride * BitmapMap.Height;

            byte[] rawBytes = new byte[length];

            System.Runtime.InteropServices.Marshal.Copy(bitmapData.Scan0, rawBytes, 0, length);

            BitmapMap.UnlockBits(bitmapData);

            var province = new ProvinceDefinitionItem();

            var colorKey = new StringBuilder();

            for (int nXndex = 0; nXndex < BitmapMap.Width; nXndex++)
            {
                for (int nYndex = 0; nYndex < BitmapMap.Height; nYndex++)
                {
                    var pixelColor = Color.FromArgb(rawBytes[nYndex * bitmapData.Stride + nXndex * 4 + 3], rawBytes[nYndex * bitmapData.Stride + nXndex * 4 + 2], rawBytes[nYndex * bitmapData.Stride + nXndex * 4 + 1], rawBytes[nYndex * bitmapData.Stride + nXndex * 4]);

                    if (!(province.R == pixelColor.R && province.G == pixelColor.G && province.B == pixelColor.B))
                    {
                        colorKey.Clear();

                        colorKey.Append(pixelColor.R);
                        colorKey.Append(pixelColor.G);
                        colorKey.Append(pixelColor.B);

                        var colorKeyString = colorKey.ToString();

                        province = dictCache.ContainsKey(colorKeyString) ?
                                   dictCache[colorKeyString] :
                                   new ProvinceDefinitionItem(++idProvince, pixelColor.R, pixelColor.G, pixelColor.B, $"NewProvince_{idProvince}", string.Empty);
                    }

                    province.Pixels.Add(new Pixel(nXndex, nYndex));

                    m_mapProvinceDefinitionItem[nXndex, nYndex] = province;
                }
            }

            BitmapMapOverlay = new Bitmap(BitmapMap);
        }