Пример #1
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();
                    }
                }
            }
        }
        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();
                    }
                }
            }
        }