private void AnyButton_MosueDown(object sender, MouseEventArgs e)
        {
            Button btn = (Button)sender;

            btn.Focus();
            MOType mt = (MOType)(((object[])(btn.Tag))[0]);
            FOType ft = (FOType)(((object[])(btn.Tag))[1]);

            if (e.Button == MouseButtons.Left)
            {
                if (mt == MOType.Belt)
                {
                    if (Utilz.IsBeltable(ft))                     //we set addmode only if the item can be a belt
                    {
                        MapObject newmo = new MapObject(mt, ft);
                        this.Editer.StartAddMode(newmo);
                    }
                }
                if (mt == MOType.Machine)                 //we set addmode only if the item can be a machine
                {
                    if (Utilz.IsRecipe(ft))
                    {
                        MapObject newmo = new MapObject(mt, ft);
                        this.Editer.StartAddMode(newmo);
                    }
                }
            }
            if (e.Button == MouseButtons.Right)
            {
                FOType[] arrayOutputs = Utilz.GetRecipeOutputs(ft);
                FOType[] arrayInputs  = Utilz.GetRecipeInputs(ft);

                oRightClick3 rc = new oRightClick3();
                //rc.Width = 200;
                rc.AddChoice(ft.ToString());
                rc.AddSeparator();
                rc.AddSeparator();
                //add every outputs and inputs for the user
                rc.AddChoice("Outputs :");
                foreach (FOType subft in arrayOutputs)
                {
                    rc.AddChoice("-" + subft.ToString());
                }
                rc.AddChoice("");
                rc.AddChoice("Inputs :");
                foreach (FOType subft in arrayInputs)
                {
                    rc.AddChoice("-" + subft.ToString());
                }
                rc.ShowDialog();
            }
        }
Example #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);
                    }
                }
            }
        }
Example #3
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();
                    }
                }
            }
        }