public void KeyDown(Keys k)
        {
            if (k == Keys.Back || k == Keys.Space)
            {
                this.keyBackSpaceDown = true;
                //remove the element under the mouse ////    supprimme l'élément sous la souris
                PointF    mvpos = this.MouseVirtualPos;
                MapObject mo    = this.Map.GetObjThatTouch(mvpos.X, mvpos.Y);              //return null if there's nothing
                if (mo != null)
                {
                    try
                    {
                        this.Map.listMO.Remove(mo);
                    }
                    catch { }
                    this.RefreshImage();
                }
            }
            if (k == Keys.Q)
            {
                //copy the element under the mouse ////    copie l'élément sous la souris
                if (!this.IsAddMode)
                {
                    PointF    mvpos = this.MouseVirtualPos;
                    MapObject mo    = this.Map.GetObjThatTouch(mvpos.X, mvpos.Y);                  //return null if there's nothing
                    if (mo != null)
                    {
                        try
                        {
                            MapObject copy = mo.GetCopy();
                            this.StartAddMode(copy);
                        }
                        catch { }
                        this.RefreshImage();
                    }
                }
                else                 //if the user is already in addmode, we want q to cancel addmode ////    si l'utilisateur est déjà en addmode, q va le faire quitter le addmode
                {
                    this.CancelAddMode();
                }
            }
            if (k == Keys.W)
            {             //copy the element under the mouse but it makes a copy for the other MOType ////    copie l'élément sous la souris, mais si c'est une machine, il va donner une belt avec le output de la machine et inversement
                if (!this.IsAddMode)
                {
                    PointF    mvpos = this.MouseVirtualPos;
                    MapObject mo    = this.Map.GetObjThatTouch(mvpos.X, mvpos.Y);                  //return null if there's nothing
                    if (mo != null)
                    {
                        try
                        {
                            if (mo.MapType == MOType.Machine)
                            {
                                oItem     ft   = mo.TheRecipe;
                                MapObject copy = new MapObject(MOType.Belt, ft);
                                this.StartAddMode(copy);
                            }
                            if (mo.MapType == MOType.Belt)
                            {
                                oItem     ft   = mo.BeltOutput;
                                MapObject copy = new MapObject(MOType.Machine, ft);
                                this.StartAddMode(copy);
                            }
                        }
                        catch { }
                        this.RefreshImage();
                    }
                }
            }
            if (k == Keys.F)
            {                                                                 //toggle NeedCoal
                PointF    mvpos = this.MouseVirtualPos;
                MapObject mo    = this.Map.GetObjThatTouch(mvpos.X, mvpos.Y); //return null if there's nothing
                if (mo != null)
                {
                    try
                    {
                        mo.NeedCoal = !mo.NeedCoal;
                    }
                    catch { }
                    this.RefreshImage();
                }
            }

            //alternative zoom control
            if (k == Keys.D1 || k == Keys.NumPad1)
            {
                this.VirtualWidth *= 1.5f;
                this.RefreshImage();
            }
            if (k == Keys.D2 || k == Keys.NumPad2)
            {
                this.VirtualWidth /= 1.5f;
                this.RefreshImage();
            }
        }
示例#2
0
        private void AnyButton_MosueDown(object sender, MouseEventArgs e)
        {
            Button btn = (Button)sender;

            btn.Focus();
            MOType mt = (MOType)(((object[])(btn.Tag))[0]);
            oItem  i  = (oItem)(((object[])(btn.Tag))[1]);

            if (e.Button == MouseButtons.Left)
            {
                if (mt == MOType.Belt)
                {
                    if (i.IsBelt)                     //we set addmode only if the item can be a belt
                    {
                        MapObject newmo = new MapObject(MOType.Belt, i);
                        this.Editer.StartAddMode(newmo);
                    }
                }
                if (mt == MOType.Machine)
                {
                    if (i.IsRecipe)                     //we set addmode only if the item can be a machine
                    {
                        MapObject newmo = new MapObject(MOType.Machine, i);
                        this.Editer.StartAddMode(newmo);
                    }
                }
            }
            if (e.Button == MouseButtons.Right)
            {
                //if this button is as machine, we show the user the inputs and outputs of the recipe
                if (mt == MOType.Machine)
                {
                    //if this button is as machine, i represents the recipe
                    oCraft       c  = Crafts.GetCraftFromRecipe(i);
                    oRightClick3 rc = new oRightClick3();
                    rc.AddChoice(i.Name);
                    if (c != null)
                    {
                        rc.AddSeparator();
                        rc.AddSeparator();
                        //add every outputs and inputs for the user
                        rc.AddChoice("Outputs :");
                        foreach (oItem subi in c.Outputs)
                        {
                            rc.AddChoice("-" + subi.Name);
                        }
                        rc.AddChoice("");
                        rc.AddChoice("Inputs :");
                        foreach (oItem subi in c.Inputs)
                        {
                            rc.AddChoice("-" + subi.Name);
                        }
                    }
                    string rep = rc.ShowDialog();                     //it simply show to the user what the inputs and outputs are
                }

                //if this button is a belt, we show the user every crafts that require this item as input
                if (mt == MOType.Belt)
                {
                    oRightClick3 rc = new oRightClick3();
                    rc.AddChoice(i.Name);
                    rc.AddSeparator();
                    rc.AddChoice("Used In Recipe :");
                    //run through every crafts and check their inputs to see if the actual item is used in that craft
                    foreach (oCraft c in Crafts.listCrafts)
                    {
                        //check the inputs and see if the item i is there
                        foreach (oItem i2 in c.Inputs)
                        {
                            //check if this is the item we are searching
                            if (i2.Name == i.Name)
                            {
                                //now that we have found the item in this craft, we add the craft recipe to the list and continue to the next item
                                rc.AddChoice("-" + c.Recipe.Name);

                                //now that we have found the item, we don't have to continue search in this craft
                                break;
                            }
                        }
                    }

                    string rep = rc.ShowDialog();
                    //if the user clicked on a recipe, we set the editer to add mode and with a machine of that recipe.
                    //we get the item from name
                    oItem therecipe = Crafts.GetItemFromName(rep.Replace("-", string.Empty));                     //the .Replace can be a little problem if - is truly part of the item name.
                    //if rep is not an item, GetItemFromName will not return null, it will return the none item.
                    if (therecipe.Name.ToLower() != "none")
                    {
                        MapObject newmo = new MapObject(MOType.Machine, therecipe);
                        this.Editer.StartAddMode(newmo);
                    }
                }
            }
        }
        public void RefreshImage()
        {
            //check are very usefull when minimizing the form.
            int imgWidth  = this.Width;
            int imgHeight = this.Height;

            if (imgWidth < 100)
            {
                imgWidth = 100;
            }
            if (imgHeight < 100)
            {
                imgHeight = 100;
            }
            Bitmap   img = new Bitmap(imgWidth, imgHeight);
            Graphics g   = Graphics.FromImage(img);

            g.Clear(Color.FromArgb(32, 32, 32));


            //if the grid is activated, we draw the grid
            if (this.ShowGrid)
            {
                //compute the graphical size of the cell. we make sure it's not too small. if it's too small, we don't draw them.
                float fUiGridCellSize = this.GridCellSize / this.VirtualWidth * (float)imgWidth;
                if (fUiGridCellSize >= 6f)
                {
                    Pen GridPen = Pens.Black;

                    //begins by converting the central pos into its closest grid coordinate
                    float RoundedCX = this.GridRoundAxisValue(this.vpos.X);
                    float RoundedCY = this.GridRoundAxisValue(this.vpos.Y);

                    int index = 0;                     //just for "safety" purpose. to be really sure that there never will be infinite loop

                    ////vertical line
                    //draw the first vertical line
                    int uiCX = this.ConvertVirtualToUi(RoundedCX, RoundedCY).X;
                    g.DrawLine(GridPen, uiCX, 0, uiCX, imgHeight - 1);
                    //vertical line to the right
                    float ActualVX = RoundedCX;                     //actual virtual horizontal position
                    while (true)
                    {
                        //move to the right
                        ActualVX += this.GridCellSize;
                        int uiLX = this.ConvertVirtualToUi(ActualVX, RoundedCY).X;

                        //if we've finished to the right
                        if (uiLX > imgWidth)
                        {
                            break;
                        }

                        //draw the line
                        g.DrawLine(GridPen, uiLX, 0, uiLX, imgHeight - 1);

                        //infinity loop check
                        index++;
                        if (index > 1000)
                        {
                            break;
                        }
                    }
                    //vertical line to the left
                    index    = 0;
                    ActualVX = RoundedCX;                     //we start again from the middle
                    while (true)
                    {
                        //move to the left
                        ActualVX -= this.GridCellSize;
                        int uiLX = this.ConvertVirtualToUi(ActualVX, RoundedCY).X;

                        //if we've finished the the left
                        if (uiLX < 0)
                        {
                            break;
                        }

                        //draw the line
                        g.DrawLine(GridPen, uiLX, 0, uiLX, imgHeight - 1);

                        //infinity loop check
                        index++;
                        if (index > 1000)
                        {
                            break;
                        }
                    }


                    ////horizontal line
                    //draw the first horizontal line
                    int uiCY = this.ConvertVirtualToUi(RoundedCX, RoundedCY).Y;
                    g.DrawLine(GridPen, 0, uiCY, imgWidth - 1, uiCY);
                    //horizontal line to the top
                    index = 0;
                    float ActualVY = RoundedCY;
                    while (true)
                    {
                        //move to the top
                        ActualVY += this.GridCellSize;
                        int uiLY = this.ConvertVirtualToUi(RoundedCX, ActualVY).Y;

                        //if we've finished to the top
                        if (uiLY < 0)
                        {
                            break;
                        }

                        //draw the line
                        g.DrawLine(GridPen, 0, uiLY, imgWidth - 1, uiLY);

                        //infinity loop check
                        index++;
                        if (index > 1000)
                        {
                            break;
                        }
                    }
                    //horizontal line to the bottom
                    index    = 0;
                    ActualVY = RoundedCY;                     //we start again from the middle
                    while (true)
                    {
                        //move down
                        ActualVY -= this.GridCellSize;
                        int uiLY = this.ConvertVirtualToUi(RoundedCX, ActualVY).Y;

                        //if we've finished moving down
                        if (uiLY > imgHeight)
                        {
                            break;
                        }

                        //draw the line
                        g.DrawLine(GridPen, 0, uiLY, imgWidth - 1, uiLY);

                        //infinity loop check
                        index++;
                        if (index > 1000)
                        {
                            break;
                        }
                    }
                }
            }


            //machine has the property IsAllInputPresent (belts too but it's only useful for machines). in the part of drawing the links, we "compute" is this property true or false. in the second part of refreshimage, this property defines the back color.

            //draw links between objects ////    dessine les lien entre les object
            foreach (MapObject mo in this.Map.listMO)
            {
                Point mouipos = this.ConvertVirtualToUi(mo.vpos.X, mo.vpos.Y);

                try
                {
                    if (mo.MapType == MOType.Belt)
                    {
                        MapObject[] twomo = this.Map.GetCompatible2BeltsCloseTo(mo);
                        if (twomo[0] != null)
                        {
                            Point mouipos2 = this.ConvertVirtualToUi(twomo[0].vpos.X, twomo[0].vpos.Y);
                            g.DrawLine(Pens.Silver, mouipos, mouipos2);
                        }
                        if (twomo[1] != null)
                        {
                            //i make sure the angle is not too small. it's just one of the check that makes the drawing of links not anoying. the purpose of the program is to draw somewhat useull links. i thought like 15 min about a program to help desing factories and i thought about how i would program the drawing of links and i come with these idea : 2 links per belt, angle not too small.
                            //check the angle with the cosine law ////    il doit checker l'angle avec la loi des cosinus
                            float a     = (float)(Math.Sqrt((twomo[1].vpos.X - mo.vpos.X) * (twomo[1].vpos.X - mo.vpos.X) + (twomo[1].vpos.Y - mo.vpos.Y) * (twomo[1].vpos.Y - mo.vpos.Y)));
                            float b     = (float)(Math.Sqrt((twomo[0].vpos.X - mo.vpos.X) * (twomo[0].vpos.X - mo.vpos.X) + (twomo[0].vpos.Y - mo.vpos.Y) * (twomo[0].vpos.Y - mo.vpos.Y)));
                            float c     = (float)(Math.Sqrt((twomo[1].vpos.X - twomo[0].vpos.X) * (twomo[1].vpos.X - twomo[0].vpos.X) + (twomo[1].vpos.Y - twomo[0].vpos.Y) * (twomo[1].vpos.Y - twomo[0].vpos.Y)));
                            float angle = (float)(Math.Acos(((a * a) + (b * b) - (c * c)) / 2f / a / b));
                            if (angle > 1f)                             //i tried 1, i was satisfied
                            {
                                Point mouipos2 = this.ConvertVirtualToUi(twomo[1].vpos.X, twomo[1].vpos.Y);
                                g.DrawLine(Pens.Silver, mouipos, mouipos2);
                            }
                        }
                    }
                    else if (mo.MapType == MOType.Machine)
                    {
                        //draw links of every output
                        foreach (oItem i in mo.Outputs)
                        {
                            MapObject closest = this.Map.GetCompatibleBeltCloseTo(mo, i);                             //this.Map.FindClosestBeltWithInput(mo, i);
                            if (closest != null)
                            {
                                Point mouipos2 = this.ConvertVirtualToUi(closest.vpos.X, closest.vpos.Y);
                                g.DrawLine(Pens.Orchid, mouipos, mouipos2);                                 // Orchid
                            }
                        }


                        //draw links of every inputs
                        mo.IsAllInputPresent = true;
                        foreach (oItem i in mo.Inputs)
                        {
                            MapObject closest = this.Map.GetCompatibleBeltCloseTo(mo, i);                             //get the closest one ////    obtien selui qui est le plus proche
                            if (closest != null)
                            {
                                Point mouipos2 = this.ConvertVirtualToUi(closest.vpos.X, closest.vpos.Y);
                                g.DrawLine(Pens.SkyBlue, mouipos, mouipos2);                                 // SkyBlue
                            }
                            else
                            {
                                mo.IsAllInputPresent = false;
                            }
                        }


                        //check if it's a furnace and if so, it draw coal if needed ////    check le charbon des four
                        if (mo.IsFurnace)
                        {
                            if (mo.NeedCoal)
                            {
                                MapObject close2 = this.Map.GetCompatibleBeltCloseTo(mo, Crafts.GetItemFromName("Coal"));                                 //get the closest coal belt ////    récupère la belt de charbon la plus près
                                if (close2 != null)
                                {
                                    Point mouipos2 = this.ConvertVirtualToUi(close2.vpos.X, close2.vpos.Y);
                                    g.DrawLine(Pens.SkyBlue, mouipos, mouipos2);
                                }
                                else
                                {
                                    mo.IsAllInputPresent = false;
                                }
                            }
                        }
                    }
                }
                catch { }
            }

            Brush brushMachineBackBrush = new SolidBrush(Color.FromArgb(64, 64, 64));

            //draw object
            foreach (MapObject mo in this.Map.listMO)
            {
                Point uipos = this.ConvertVirtualToUi(mo.vpos.X, mo.vpos.Y);

                //draw background
                int uiradius = (int)(mo.VirtualWidth * (float)(this.Width) / this.VirtualWidth / 2f + 0.5f);                 //graphical radius ////    rayon graphique de l'objet
                if (mo.MapType == MOType.Belt)
                {
                    Brush BackBrush = Brushes.DimGray;
                    if (!mo.BeltOutput.IsBelt)
                    {
                        BackBrush = Brushes.Red;
                    }
                    g.FillEllipse(BackBrush, uipos.X - uiradius, uipos.Y - uiradius, 2 * uiradius, 2 * uiradius);
                }
                if (mo.MapType == MOType.Machine)
                {
                    Brush moBackColor       = brushMachineBackBrush;               //Brushes.DimGray;
                    Brush FurnaceLabelColor = Brushes.White;
                    if (!mo.IsAllInputPresent)
                    {
                        moBackColor = Brushes.Crimson; FurnaceLabelColor = Brushes.White;
                    }
                    if (mo.TheCraft == null)
                    {
                        moBackColor = Brushes.Red;
                    }                                                                           //if it cannot be a recipe, we simlpy fill the background in pure and agressive red. when an item is not used as a recipe, no craft is found (obviously) so this property of the MapObject stay null and that's how we know that it's not a valid recipe.
                    g.FillRectangle(moBackColor, uipos.X - uiradius, uipos.Y - uiradius, 2 * uiradius, 2 * uiradius);
                    g.DrawRectangle(Pens.Silver, uipos.X - uiradius, uipos.Y - uiradius, 2 * uiradius, 2 * uiradius);
                    if (mo.IsFurnace && uiradius >= 25)
                    {
                        Font fonte = new Font("consolas", 10f);
                        g.DrawString("Furnace", fonte, FurnaceLabelColor, (float)(uipos.X - uiradius), (float)(uipos.Y - uiradius));
                        if (mo.NeedCoal)
                        {
                            g.DrawString("NeedCoal", fonte, FurnaceLabelColor, (float)(uipos.X - uiradius), (float)(uipos.Y - uiradius + 15));
                        }
                    }
                }

                //get and draw image
                Bitmap moimg = mo.GetImage();
                if (moimg != null)
                {
                    //draw the image only if the image is not too big compared to the graphical size of the object ////    dessine l'image seulement si elle n'est pas raisonnablement plus grande
                    if (moimg.Width <= uiradius * 8)
                    {
                        try
                        {
                            g.DrawImage(moimg, uipos.X - (moimg.Width / 2), uipos.Y - (moimg.Height / 2));
                        }
                        catch { }
                    }
                }
            }

            g.Dispose();
            if (this.ImageBox.Image != null)
            {
                this.ImageBox.Image.Dispose();
            }
            this.ImageBox.Image = img;
            this.ImageBox.Refresh();
            GC.Collect();
        }
        private void ImageBox_MouseUp(object sender, MouseEventArgs e)
        {
            PointF mvpos = this.MouseVirtualPos;             //this.ConvertUiToVirtual(this.MousePos.X, this.MousePos.Y);


            if (e.Button == MouseButtons.Left)
            {
                if (this.IsDragAndDrop)
                {
                    this.StopDragAndDrop();
                }
                if (this.IsDragAndDropMO)
                {
                    this.StopDragAndDropMO();
                }
                if (this.IsAddMode)
                {
                    this.StopAddMode();
                }
            }
            if (e.Button == MouseButtons.Right)
            {
                if (!this.IsAddMode && !this.IsDragAndDrop && !this.IsDragAndDropMO)
                {
                    MapObject mo = this.Map.GetObjThatTouch(mvpos.X, mvpos.Y);
                    if (mo != null)
                    {
                        string optToggleNeedCoal = "Toggle Need Coal";
                        string optRemove         = "Remove";

                        oRightClick3 rc = new oRightClick3();
                        //rc.Width = 300;
                        if (mo.MapType == MOType.Machine)
                        {
                            rc.AddChoice(mo.TheRecipe.Name);
                            rc.AddSeparator();
                            rc.AddChoice(optToggleNeedCoal);
                        }
                        else
                        {
                            rc.AddChoice(mo.BeltOutput.Name);
                            rc.AddSeparator();
                        }
                        rc.AddChoice(optRemove);

                        //add the inputs and outputs
                        if (mo.MapType == MOType.Machine)
                        {
                            rc.AddSeparator();
                            rc.AddSeparator();
                            rc.AddChoice("Outputs :");
                            foreach (oItem i in mo.Outputs)
                            {
                                rc.AddChoice("-" + i.Name);
                            }
                            rc.AddChoice("");
                            rc.AddChoice("Inputs :");
                            foreach (oItem i in mo.Inputs)
                            {
                                rc.AddChoice("-" + i.Name);
                            }
                        }

                        string rep = rc.GetChoice();
                        if (rep == optToggleNeedCoal)
                        {
                            mo.NeedCoal = !mo.NeedCoal;
                        }
                        if (rep == optRemove)
                        {
                            try
                            {
                                this.Map.listMO.Remove(mo);
                            }
                            catch { }
                        }

                        //check the one who correspond to the clicked item name, if there is one.
                        if (mo.MapType == MOType.Machine)
                        {
                            string okname = rep.Replace("-", string.Empty).Trim();
                            foreach (oItem i in Crafts.listItems)
                            {
                                if (i.Name == okname)
                                {
                                    MapObject newmo = new MapObject(MOType.Belt, i);
                                    this.StartAddMode(newmo);
                                    break;
                                }
                            }
                        }



                        this.RefreshImage();
                    }
                }
            }
        }
示例#5
0
 private MapObject addmodeMO = null;     //the object to add
 public void StartAddMode(MapObject mo)
 {
     this.IsAddMode = true;
     this.addmodeMO = mo;
 }
示例#6
0
        public void RefreshImage()
        {
            int imgWidth  = this.Width;
            int imgHeight = this.Height;

            if (imgWidth < 100)
            {
                imgWidth = 100;
            }
            if (imgHeight < 100)
            {
                imgHeight = 100;
            }
            Bitmap   img = new Bitmap(imgWidth, imgHeight);
            Graphics g   = Graphics.FromImage(img);

            g.Clear(Color.FromArgb(32, 32, 32));



            //draw links between objects ////    dessine les lien entre les object
            foreach (MapObject mo in this.Map.listMO)
            {
                Point mouipos = this.ConvertVirtualToUi(mo.vpos.X, mo.vpos.Y);

                try
                {
                    if (mo.MapType == MOType.Belt)
                    {
                        MapObject[] twomo = this.Map.GetCompatible2ObjsCloseTo(mo);
                        if (twomo[0] != null)
                        {
                            Point mouipos2 = this.ConvertVirtualToUi(twomo[0].vpos.X, twomo[0].vpos.Y);
                            g.DrawLine(Pens.Silver, mouipos, mouipos2);
                        }
                        if (twomo[1] != null)
                        {
                            //i make sure the angle is not too small. it's just one of the check that makes the drawing of links not anoying. the purpose of the program is to draw somewhat useull links. i thought like 15 min about a program to help desing factories and i thought about how i would program the drawing of links and i come with these idea : 2 links per belt, angle not too small.
                            //check the angle with the cosine law ////    il doit checker l'angle avec la loi des cosinus
                            float a     = (float)(Math.Sqrt((twomo[1].vpos.X - mo.vpos.X) * (twomo[1].vpos.X - mo.vpos.X) + (twomo[1].vpos.Y - mo.vpos.Y) * (twomo[1].vpos.Y - mo.vpos.Y)));
                            float b     = (float)(Math.Sqrt((twomo[0].vpos.X - mo.vpos.X) * (twomo[0].vpos.X - mo.vpos.X) + (twomo[0].vpos.Y - mo.vpos.Y) * (twomo[0].vpos.Y - mo.vpos.Y)));
                            float c     = (float)(Math.Sqrt((twomo[1].vpos.X - twomo[0].vpos.X) * (twomo[1].vpos.X - twomo[0].vpos.X) + (twomo[1].vpos.Y - twomo[0].vpos.Y) * (twomo[1].vpos.Y - twomo[0].vpos.Y)));
                            float angle = (float)(Math.Acos(((a * a) + (b * b) - (c * c)) / 2f / a / b));
                            if (angle > 1f)                             //i tried 1, i was satisfied
                            {
                                Point mouipos2 = this.ConvertVirtualToUi(twomo[1].vpos.X, twomo[1].vpos.Y);
                                g.DrawLine(Pens.Silver, mouipos, mouipos2);
                            }
                        }
                    }
                    else if (mo.MapType == MOType.Machine)
                    {
                        //draw links of every output
                        foreach (FOType ft in mo.Outputs)
                        {
                            MapObject closest = this.Map.FindClosestBeltWithInput(mo, ft);
                            if (closest != null)
                            {
                                Point mouipos2 = this.ConvertVirtualToUi(closest.vpos.X, closest.vpos.Y);
                                g.DrawLine(Pens.Orchid, mouipos, mouipos2);                                 // Crimson
                            }
                        }
                        //MapObject closemo = this.Map.FindClosestMoWithOutput(mo, MOType.Belt, mo.Outputs[0]);
                        //if (closemo != null)
                        //{
                        //	Point mouipos2 = this.ConvertVirtualToUi(closemo.vpos.X, closemo.vpos.Y);
                        //	g.DrawLine(Pens.Red, mouipos, mouipos2);
                        //}


                        //draw links of every inputs
                        mo.IsAllInputPresent = true;
                        foreach (FOType ft in mo.Inputs)
                        {
                            MapObject closest = this.Map.GetCompatibleBeltCloseTo(mo, ft);                             //get the closest one ////    obtien selui qui est le plus proche
                            if (closest != null)
                            {
                                Point mouipos2 = this.ConvertVirtualToUi(closest.vpos.X, closest.vpos.Y);
                                g.DrawLine(Pens.SkyBlue, mouipos, mouipos2);
                            }
                            else
                            {
                                mo.IsAllInputPresent = false;
                            }
                        }

                        //check if it's a furnace and if so, it draw coal if needed ////    check le charbon des four
                        if (mo.IsFurnace)
                        {
                            if (mo.NeedCoal)
                            {
                                MapObject close2 = this.Map.GetCompatibleBeltCloseTo(mo, FOType.Coal);                                 //get the closest coal belt ////    récupère la belt de charbon la plus près
                                if (close2 != null)
                                {
                                    Point mouipos2 = this.ConvertVirtualToUi(close2.vpos.X, close2.vpos.Y);
                                    g.DrawLine(Pens.SkyBlue, mouipos, mouipos2);
                                }
                                else
                                {
                                    mo.IsAllInputPresent = false;
                                }
                            }
                        }
                    }
                }
                catch { }
            }

            Brush brushMachineBackBrush = new SolidBrush(Color.FromArgb(64, 64, 64));

            //draw object
            foreach (MapObject mo in this.Map.listMO)
            {
                Point uipos = this.ConvertVirtualToUi(mo.vpos.X, mo.vpos.Y);

                //draw background
                int uiradius = (int)(mo.VirtualWidth * (float)(this.Width) / this.VirtualWidth / 2f + 0.5f);                 //graphical radius ////    rayon graphique de l'objet
                if (mo.MapType == MOType.Belt)
                {
                    g.FillEllipse(Brushes.DimGray, uipos.X - uiradius, uipos.Y - uiradius, 2 * uiradius, 2 * uiradius);
                }
                if (mo.MapType == MOType.Machine)
                {
                    Brush moBackColor       = brushMachineBackBrush;               //Brushes.DimGray;
                    Brush FurnaceLabelColor = Brushes.White;
                    if (!mo.IsAllInputPresent)
                    {
                        moBackColor = Brushes.Crimson; FurnaceLabelColor = Brushes.White;
                    }
                    g.FillRectangle(moBackColor, uipos.X - uiradius, uipos.Y - uiradius, 2 * uiradius, 2 * uiradius);
                    g.DrawRectangle(Pens.Silver, uipos.X - uiradius, uipos.Y - uiradius, 2 * uiradius, 2 * uiradius);
                    if (mo.IsFurnace && uiradius >= 25)
                    {
                        Font fonte = new Font("consolas", 10f);
                        g.DrawString("Furnace", fonte, FurnaceLabelColor, (float)(uipos.X - uiradius), (float)(uipos.Y - uiradius));
                        if (mo.NeedCoal)
                        {
                            g.DrawString("NeedCoal", fonte, FurnaceLabelColor, (float)(uipos.X - uiradius), (float)(uipos.Y - uiradius + 15));
                        }
                    }
                }

                //get and draw image
                Bitmap moimg = mo.GetImage();
                if (moimg != null)
                {
                    //draw the image only if the image is not too big compared to the graphical size of the object ////    dessine l'image seulement si elle n'est pas raisonnablement plus grande
                    if (moimg.Width <= uiradius * 8)
                    {
                        try
                        {
                            g.DrawImage(moimg, uipos.X - (moimg.Width / 2), uipos.Y - (moimg.Height / 2));
                        }
                        catch { }
                    }
                }
            }

            g.Dispose();
            if (this.ImageBox.Image != null)
            {
                this.ImageBox.Image.Dispose();
            }
            this.ImageBox.Image = img;
            this.ImageBox.Refresh();
            GC.Collect();
        }
示例#7
0
        private void ImageBox_MouseUp(object sender, MouseEventArgs e)
        {
            PointF mvpos = this.MouseVirtualPos;             //this.ConvertUiToVirtual(this.MousePos.X, this.MousePos.Y);


            if (e.Button == MouseButtons.Left)
            {
                if (this.IsDragAndDrop)
                {
                    this.StopDragAndDrop();
                }
                if (this.IsDragAndDropMO)
                {
                    this.StopDragAndDropMO();
                }
                if (this.IsAddMode)
                {
                    this.StopAddMode();
                }
            }
            if (e.Button == MouseButtons.Right)
            {
                if (!this.IsAddMode && !this.IsDragAndDrop && !this.IsDragAndDropMO)
                {
                    MapObject mo = this.Map.GetObjThatTouch(mvpos.X, mvpos.Y);
                    if (mo != null)
                    {
                        string optToggleNeedCoal = "Toggle Need Coal";
                        string optRemove         = "Remove";

                        oRightClick3 rc = new oRightClick3();
                        //rc.Width = 300;
                        rc.AddChoice(optToggleNeedCoal);
                        rc.AddSeparator();
                        rc.AddChoice(optRemove);

                        //ajoute les inputs et output
                        if (mo.MapType == MOType.Machine)
                        {
                            rc.AddSeparator();
                            rc.AddSeparator();
                            rc.AddChoice("Outputs :");
                            foreach (FOType ft in mo.Outputs)
                            {
                                rc.AddChoice("-" + ft.ToString());
                            }
                            rc.AddChoice("");
                            rc.AddChoice("Inputs :");
                            foreach (FOType ft in mo.Inputs)
                            {
                                rc.AddChoice("-" + ft.ToString());
                            }
                        }

                        string rep = rc.GetChoice();
                        if (rep == optToggleNeedCoal)
                        {
                            mo.NeedCoal = !mo.NeedCoal;
                        }
                        if (rep == optRemove)
                        {
                            try
                            {
                                this.Map.listMO.Remove(mo);
                            }
                            catch { }
                        }

                        //check the one who correspond to the click FOType, if there is one ////    check si ca correspond à un FOType
                        if (mo.MapType == MOType.Machine)
                        {
                            List <FOType> allft = Utilz.GetListOfAllFOType();
                            foreach (FOType ft in allft)
                            {
                                if (ft.ToString() == rep.Replace("-", string.Empty).Trim())
                                {
                                    MapObject newmo = new MapObject(MOType.Belt, ft);
                                    this.StartAddMode(newmo);
                                    break;
                                }
                            }
                        }



                        this.RefreshImage();
                    }
                }
            }
        }