public void SetRecipe(oItem Recipe)
 {
     if (this.MapType == MOType.Belt)
     {
         this.BeltOutput = Recipe;
     }
     if (this.MapType == MOType.Machine)
     {
         this.TheRecipe = Recipe;
         oCraft c = Crafts.GetCraftFromRecipe(Recipe);                 //gets the craft
         this.TheCraft = c;
         //if (c != null)
         //{
         //	this.Outputs = c.Outputs;
         //	this.Inputs = c.Inputs;
         //	this.IsFurnace = c.IsMadeInFurnace;
         //}
     }
 }
Exemplo n.º 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);
                    }
                }
            }
        }