public MapObject FindClosestBeltWithInput(MapObject mo, FOType ft) { MapObject mo1 = null; List <MapObject> lco = this.listMO.FindAll(x => x.MapType == MOType.Belt); lco.Remove(mo); //remove the object at 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(); bool canexit = false; foreach (MapObject submo in lco) { //after the if, it check it has the desired input //// après les if, vérifie s'il y a le input désiré if (submo.MapType == MOType.Belt) //always true because of the second line of this function { if (submo.BeltOutput == ft) { mo1 = submo; break; } } if (canexit) { break; } } } return(mo1); }
//return the closest belt with desired output public MapObject FindClosestBeltWithInput(MapObject mo, FOType ft) { MapObject mo1 = null; List <MapObject> lco = this.listMO.FindAll(x => x.MapType == MOType.Belt); //sort for belts lco.Remove(mo); //remove the object at the middle of the map if (lco.Count > 0) { //we sort by distance lco = lco.OrderBy(x => x.DistTo(mo.vpos.X, mo.vpos.Y)).ToList(); //find the closest belt foreach (MapObject submo in lco) { //after the if, it check it has the desired input if (submo.MapType == MOType.Belt) //always true because of the second line of this function { if (submo.BeltOutput == ft) //check the type { mo1 = submo; break; } } } } return(mo1); }
// //// retourne l'object le plus proche de lui avec un output compatible et le type de MapType spécifié // //// ici, mo sert seulement à connaitre la coordonné //return the closest object with a compatible output and a specified MapType //the only purpose of giving mo to the function is to know the coordinate. don't be confused public MapObject GetCompatibleBeltCloseTo(MapObject mo, FOType OutType) { MapObject mo1 = null; List <MapObject> lco = this.listMO.FindAll(x => (x.MapType == MOType.Belt) && (x.BeltOutput == OutType)); try { lco.Remove(mo); } catch { } if (lco.Count > 0) { lco = lco.OrderBy(x => x.DistTo(mo.vpos.X, mo.vpos.Y)).ToList(); //go through the list. the closest objects are at the beginning of the list. it find the first of compatible maptype foreach (MapObject submo in lco) { //if (submo.MapType == MapType) //{ mo1 = submo; break; //} } } return(mo1); }
private void CreateNewButtonBoth(FOType ft) { Bitmap img = Utilz.GetAssociatedIcon(ft); this.CreateNewButtonBelt(img, ft); this.CreateNewButtonMachine(img, ft); }
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); }
private void CreateNewButtonMachine(Bitmap img, FOType ft) { Button newb = new Button(); newb.Parent = this.panele; newb.Image = img; newb.ImageAlign = ContentAlignment.MiddleCenter; this.listButtonMachine.Add(newb); //newb.Click += new EventHandler(this.AnyButton_Click); newb.MouseDown += new MouseEventHandler(this.AnyButton_MosueDown); newb.Tag = new object[] { MOType.Machine, ft }; }
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); }
//public MapObject(MOType StartMapType, FOType[] StartOutputs) //{ // this.MapType = StartMapType; // this.SetOutput(StartOutputs); // if (this.MapType == MOType.Machine) // { // this.SetRecipe(StartOutputs[0]); // } //} //define inputs and outputs according to the recipe //// défini les input et output qui vont avec la recette spécifié public void SetRecipe(FOType Recipe) { if (this.MapType == MOType.Belt) { this.SetOutput(Recipe); } if (this.MapType == MOType.Machine) { this.TheRecipe = Recipe; this.Outputs = Utilz.GetRecipeOutputs(Recipe); this.Inputs = Utilz.GetRecipeInputs(Recipe); this.IsFurnace = Utilz.IsRecipeMadeInFurnace(Recipe); } }
//define inputs and outputs according to the recipe //// défini les input et output qui vont avec la recette spécifié public void SetRecipe(FOType Recipe) { if (this.MapType == MOType.Belt) //SetRecipe is usually not called for belts { this.BeltOutput = Recipe; } if (this.MapType == MOType.Machine) { //set the recipe and set everything this.TheRecipe = Recipe; this.Outputs = Utilz.GetRecipeOutputs(Recipe); this.Inputs = Utilz.GetRecipeInputs(Recipe); this.IsFurnace = Utilz.IsRecipeMadeInFurnace(Recipe); } }
public bool IsAllInputPresent = false; //used by RefreshImage. indicate if all inputs are present. it's reseted and recalculated every RefreshImage //// utilisé par RefreshImage. indique si tout les input sont présent public MapObject GetCopy() { //prepare the content to send to the constructor //// obtient les contenue à envoyer au constructeur FOType copyrecipe = this.BeltOutput; if (this.MapType == MOType.Machine) { copyrecipe = this.TheRecipe; } MapObject copy = new MapObject(this.MapType, copyrecipe); copy.NeedCoal = this.NeedCoal; return(copy); }
//not used anywhere public MapObject FindClosestMoWithInput(MapObject mo, FOType ft) { MapObject mo1 = null; List <MapObject> lco = new List <MapObject>(); lco.AddRange(this.listMO); lco.Remove(mo); //retire l'object qui est au centre if (lco.Count > 0) { lco = lco.OrderBy(x => x.DistTo(mo.vpos.X, mo.vpos.Y)).ToList(); bool canexit = false; foreach (MapObject submo in lco) { //after the if, it check it has the desired input //// après les if, vérifie s'il y a le input désiré if (submo.MapType == MOType.Belt) { if (submo.BeltOutput == ft) { mo1 = submo; break; } } if (submo.MapType == MOType.Machine) { //look through the inputs //// recherche dans les input de la machine foreach (FOType subft in submo.Inputs) { //check if they re the same type //// check s'il sont de même type if (subft == ft) { mo1 = submo; canexit = true; break; } } } if (canexit) { break; } } } return(mo1); }
//return the closest belt with a compatible output //the only purpose of giving mo to the function is to know the coordinate. don't be confused public MapObject GetCompatibleBeltCloseTo(MapObject mo, FOType OutType) { MapObject mo1 = null; List <MapObject> lco = this.listMO.FindAll(x => (x.MapType == MOType.Belt) && (x.BeltOutput == OutType)); //get belts of compatible output try { lco.Remove(mo); } catch { } if (lco.Count > 0) { //sort by distance lco = lco.OrderBy(x => x.DistTo(mo.vpos.X, mo.vpos.Y)).ToList(); //get the closest mo1 = lco[0]; } return(mo1); }
public FOParam(FOType type) { Type = type; }
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) { FOType ft = mo.TheRecipe; //if (mo.MapType == MOType.Machine) //{ // ft = mo.TheRecipe; //} MapObject copy = new MapObject(MOType.Belt, ft); this.StartAddMode(copy); } if (mo.MapType == MOType.Belt) { FOType 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(); } }
public void SetOutput(FOType newout) { this.Outputs = new FOType[] { newout }; }