private void RefreshSize() { this.TextBelt.Top = 15; // 15 this.TextBelt.Left = 5; // 5 this.TextBelt.AutoSize = true; this.TextAssembler.Top = 55; // 55 this.TextAssembler.Left = 5; // 5 this.TextAssembler.AutoSize = true; int StartLeft = 70; // 70 Size buttonsize = new Size(40, 40); // 40 40 int actualleft = StartLeft; foreach (Button b in this.listButtonBelt) { MOType mt = (MOType)(((object[])(b.Tag))[0]); FOType ft = (FOType)(((object[])(b.Tag))[1]); b.Left = actualleft; b.Top = 1; b.Size = buttonsize; //back color //// couleur d'arrière plan b.BackColor = Color.Gainsboro; bool isbelt = Utilz.IsBeltable(ft); if (!isbelt) { b.BackColor = Color.Crimson; } //next iteration actualleft += b.Width + 1; } actualleft = StartLeft; foreach (Button b in this.listButtonMachine) { MOType mt = (MOType)(((object[])(b.Tag))[0]); FOType ft = (FOType)(((object[])(b.Tag))[1]); b.Left = actualleft; b.Top = 1 + buttonsize.Height + 2; b.Size = buttonsize; //back color //// couleur d'arrière plan b.BackColor = Color.Gainsboro; bool ismachine = Utilz.IsRecipe(ft); if (!ismachine) { b.BackColor = Color.Crimson; } //next iteration actualleft += b.Width + 1; } }
//return the closest object with specified output and maptype. //for machine, it's assumed it must search in every outputs. //return null if nothing found public MapObject FindClosestMoWithOutput(MapObject mo, MOType MapType, FOType ft) { MapObject mo1 = null; List <MapObject> lco = this.listMO.FindAll(x => x.MapType == MapType); //we first extract MapObject of the desired type lco.Remove(mo); //remove the object in the middle of the map if (lco.Count > 0) { //we sort items from their distance to mo lco = lco.OrderBy(x => x.DistTo(mo.vpos.X, mo.vpos.Y)).ToList(); if (MapType == MOType.Belt) { //research the closest belt of the desired output. lco is sorted by distance. going through the list from the beginning is going through the closest to the farthest foreach (MapObject submo in lco) { if (submo.MapType == MOType.Belt) //always true because of the second line of this function { if (submo.BeltOutput == ft) //check it has the desired output { mo1 = submo; break; } } } } if (MapType == MOType.Machine) { bool canexit = false; //research the closest machine with a desired output. lco is sorted by distance foreach (MapObject submo in lco) { if (submo.MapType == MOType.Machine) //always true because of the second line of this function { //search for an output of the desired type foreach (FOType subout in submo.Outputs) { //check if this output is ok if (subout == ft) { mo1 = submo; canexit = true; break; } } } if (canexit) { break; } } } } return(mo1); }
public MapObject(MOType StartMapType, oItem StartOut) { this.MapType = StartMapType; //must be define before calling SetRecipe if (this.MapType == MOType.Belt) { this.BeltOutput = StartOut; } if (this.MapType == MOType.Machine) { this.SetRecipe(StartOut); } }
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(); } }
//for a belt, StartOut is its content. for a machine, StartOut is the recipe public MapObject(MOType StartMapType = MOType.Belt, FOType StartOut = FOType.none) { this.MapType = StartMapType; if (this.MapType == MOType.Belt) { this.BeltOutput = StartOut; //define the output //// set la sortie/contenue de la belt sur l'élément spécifié } if (this.MapType == MOType.Machine) { this.SetRecipe(StartOut); } }
// //// retourne l'object le plus proche de lui avec un output spécifié et le type de MapType spécifié //return the closest object with specified output and maptype. //for machine, it's assumed it must search every outputs. public MapObject FindClosestMoWithOutput(MapObject mo, MOType MapType, FOType ft) { MapObject mo1 = null; List <MapObject> lco = this.listMO.FindAll(x => x.MapType == MapType); lco.Remove(mo); //remove the object in the middle of the map //// retire l'object qui est au centre if (lco.Count > 0) { lco = lco.OrderBy(x => x.DistTo(mo.vpos.X, mo.vpos.Y)).ToList(); if (MapType == MOType.Belt) { foreach (MapObject submo in lco) { if (submo.MapType == MOType.Belt) //always true { if (submo.BeltOutput == ft) //check it has the desired output { mo1 = submo; break; } } } } if (MapType == MOType.Machine) { bool canexit = false; foreach (MapObject submo in lco) { if (submo.MapType == MOType.Machine) //always true { //check every outputs foreach (FOType subout in submo.Outputs) { if (subout == ft) { mo1 = submo; canexit = true; break; } } } if (canexit) { break; } } } } return(mo1); }
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); } } } }