private void canvas_Drop(object sender, DragEventArgs e) { App.jatek.terkep.terkepAllapot = ETerkepAllapot.szabad; Point pointToWindow = e.GetPosition(canvas); CTerkepiImage img = (CTerkepiImage)e.Data.GetData(typeof(CTerkepiImage)); CTerkepiCella cella = getTerkepiCellaAtScreenPosition(pointToWindow); IMozgoTerkepiEgyseg tempMozgoEgyseg = null; tempMozgoEgyseg = (IMozgoTerkepiEgyseg)img.terkepiEgyseg; if (tempMozgoEgyseg != null) { if (cella.tulaj != null) { tempMozgoEgyseg.mozgasCellara(App.jatek.terkep, cella); } } terkeprajzolas(); }
public void terkeprajzolas() { m = App.jatek.terkep.magassag * (2 * offsetY()) + offsetY(); sz = App.jatek.terkep.szelesseg * (offsetX() + oldalhossz) + offsetX(); //if (sz>100 && sz<2000 && m>100 && m < 2000) { canvas.Height = m; canvas.Width = sz; //} canvas.Children.Clear(); //if (terkepAllapot == ETerkepAllapot.egysegmozgatas) //{ // Dijkstra(aktualisEgyseg.aktualisCella); //} //if (terkepAllapot == ETerkepAllapot.harc) // Dijkstra(aktualisEgyseg.aktualisCella); List <Line> lines = new List <Line>(); for (int j = 0; j < App.jatek.terkep.magassag; j++) { for (int i = 0; i < App.jatek.terkep.szelesseg; i++) { PointCollection curvePoints = getScreenCoords(App.jatek.terkep.sorok[j][i]); Polygon p = new Polygon(); RenderOptions.SetEdgeMode((DependencyObject)p, EdgeMode.Aliased); p.Stroke = Brushes.Black; if (App.jatek.terkep.sorok[j][i].tulaj != null) { p.Fill = getSzin(App.jatek.terkep.sorok[j][i].tulaj); } else { p.Fill = Brushes.Gray; } if (App.jatek.terkep.terkepAllapot == ETerkepAllapot.egysegmozgatas) { //if (Tavolsag(cellak[i][j], aktualisEgyseg.aktualisCella) <= ((CMozgoTerkepiEgyseg)aktualisEgyseg).range) //Console.WriteLine("Tavolsag:{0}", dist[j][i]); if (App.jatek.terkep.tavolsagTabla[j][i] <= ((CMozgoTerkepiEgyseg)aktualisEgyseg).range) { p.StrokeThickness = 2; p.Stroke = Brushes.Yellow; } else { //p.StrokeThickness = 0.8; p.Stroke = Brushes.Black; } } else { p.StrokeThickness = 1; } p.HorizontalAlignment = HorizontalAlignment.Left; p.VerticalAlignment = VerticalAlignment.Center; p.Points = curvePoints; canvas.Children.Add(p); //Line myLine = new Line(); //myLine.Stroke = System.Windows.Media.Brushes.LightSteelBlue; //myLine.X1 = 1; //myLine.X2 = 500; //myLine.Y1 = 1; //myLine.Y2 = 500; //myLine.HorizontalAlignment = HorizontalAlignment.Left; //myLine.VerticalAlignment = VerticalAlignment.Center; //myLine.StrokeThickness = 10; //canvas.Children.Add(myLine); if (App.jatek.terkep.sorok[j][i].extraSzomszed != null) { foreach (CTerkepiCella extra in App.jatek.terkep.sorok[j][i].extraSzomszed) { if (extra != null && extra.tulaj != null) { Line myLine1 = new Line(); myLine1.Stroke = getVonalszín(App.jatek.terkep.sorok[j][i].tulaj); Point from = getCanvasCoord(App.jatek.terkep.sorok[j][i]); myLine1.X1 = from.X + oldalhossz / 1.5; myLine1.Y1 = from.Y + oldalhossz / 2; Point to = getCanvasCoord(extra); myLine1.X2 = to.X + oldalhossz / 1.5; myLine1.Y2 = to.Y + oldalhossz / 2; //myLine1.HorizontalAlignment = HorizontalAlignment.Left; //myLine1.VerticalAlignment = VerticalAlignment.Center; myLine1.StrokeThickness = 1; lines.Add(myLine1); } } } //if (terkepAllapot == ETerkepAllapot.egysegmozgatas) //{ // if (tavolsagTabla[j][i] < 50000) // { // TextBlock textBlock = new TextBlock(); // textBlock.Text = tavolsagTabla[j][i].ToString(); // //textBlock.Foreground = new SolidColorBrush(Brushes.Black); // Canvas.SetLeft(textBlock, cellak[j][i].getScreenCoord().X + oldalhossz / 1.5); // Canvas.SetTop(textBlock, cellak[j][i].getScreenCoord().Y + oldalhossz / 2-5); // canvas.Children.Add(textBlock); // } //} //TextBlock textBlock1 = new TextBlock(); //textBlock1.Text = String.Format("{0},{1}",j,i); ////textBlock.Foreground = new SolidColorBrush(Brushes.Black); //Canvas.SetLeft(textBlock1, cellak[j][i].getScreenCoord().X + oldalhossz / 1.5); //Canvas.SetTop(textBlock1, cellak[j][i].getScreenCoord().Y - oldalhossz+2); //canvas.Children.Add(textBlock1); } } foreach (Line l in lines) { canvas.Children.Add(l); } CTerkepiImage myImage = null; ContextMenu contextMenu = new ContextMenu(); //contextMenu.Items.Add("Mozgás"); //contextMenu.Items.Add("Harc"); //if (App.jatek.aktualisallapot == EJatekAllapotok.egysegmozgatas) //{ // MenuItem item = new MenuItem(); // item.Header = "mozgás"; // item.Click += delegate { MyImage_Mozgas(); }; // contextMenu.Items.Add(item); //} if (App.jatek.aktualisallapot == EJatekAllapotok.harc) { MenuItem item1 = new MenuItem(); item1.Header = "harc"; item1.Click += delegate { MyImage_Harc(); }; contextMenu.Items.Add(item1); } int szamlalo = 0; foreach (CJatekos j in App.jatek.jatekosok) { szamlalo++; foreach (CTerkepiEgyseg te in j.egysegekLista) { if (te.aktualisCella == null) { break; } // Create Image Element myImage = new CTerkepiImage(te); myImage.Width = 20; // Create source BitmapImage myBitmapImage = new BitmapImage(); // BitmapImage.UriSource must be in a BeginInit/EndInit block myBitmapImage.BeginInit(); myBitmapImage.UriSource = new Uri(System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, te.bitmap + "_" + szamlalo.ToString() + ".png"), UriKind.Absolute); myBitmapImage.DecodePixelWidth = 20; myBitmapImage.EndInit(); //set image source myImage.Source = myBitmapImage; canvas.Children.Add(myImage); //myImage.MouseUp += MyImage_MouseUp; //myImage.MouseRightButtonDown += MyImage_RightMouseDown; myImage.MouseLeftButtonDown += MyImage_MouseLeftButtonDown; myImage.ContextMenu = contextMenu; Canvas.SetTop(myImage, getCanvasCoord(te.aktualisCella).Y - oldalhossz / 2); Canvas.SetLeft(myImage, getCanvasCoord(te.aktualisCella).X + oldalhossz / 2); TextBlock textBlockElet = new TextBlock(); textBlockElet.Text = String.Format("{0}", te.elet.ToString()); //textBlock.Foreground = new SolidColorBrush(Brushes.Black); Canvas.SetTop(textBlockElet, getCanvasCoord(te.aktualisCella).Y - oldalhossz / 2 - 12); Canvas.SetLeft(textBlockElet, getCanvasCoord(te.aktualisCella).X + oldalhossz / 2 + 12); canvas.Children.Add(textBlockElet); if (App.jatek.aktualisallapot == EJatekAllapotok.egysegmozgatas && ((CMozgoTerkepiEgyseg)te != null) && !((CMozgoTerkepiEgyseg)te).lepettMar) { Line myLine1 = new Line(); myLine1.Stroke = getVonalszín(j); Point from = getCanvasCoord(te.aktualisCella); from.Offset(oldalhossz / 1.5, oldalhossz / 3); myLine1.X1 = from.X; myLine1.Y1 = from.Y; Point to = from; to.Offset(oldalhossz / 2, 0); myLine1.X2 = to.X; myLine1.Y2 = to.Y; //myLine1.HorizontalAlignment = HorizontalAlignment.Left; //myLine1.VerticalAlignment = VerticalAlignment.Center; myLine1.StrokeThickness = 1; canvas.Children.Add(myLine1); } if (te.elet == 0) { Image myImage1 = new Image(); myImage1.Width = 20; // Create source BitmapImage myBitmapImage1 = new BitmapImage(); // BitmapImage.UriSource must be in a BeginInit/EndInit block myBitmapImage1.BeginInit(); myBitmapImage1.UriSource = new Uri(System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "megsemmisult.png"), UriKind.Absolute); myBitmapImage1.DecodePixelWidth = 20; myBitmapImage1.EndInit(); myImage1.Source = myBitmapImage1; canvas.Children.Add(myImage1); Canvas.SetTop(myImage1, getCanvasCoord(te.aktualisCella).Y - oldalhossz / 2); Canvas.SetLeft(myImage1, getCanvasCoord(te.aktualisCella).X + oldalhossz / 2); } } } canvas.InvalidateVisual(); }