public override void OnStart(StartState state) { StringCollectionParser parser = new StringCollectionParser(); //Comma seperated list parser.SetFromString(toggle); //Actions to be triggered _toggle = parser; //list of actions //Find a Type where the name matches the targeted PartModule and the module is assignable from the assembly t Type type = Parser.ModTypes.Find(t => t.Name == module && typeof(PartModule).IsAssignableFrom(t)); for (Int32 i = 0; i < part.Modules.Count; i++) //Iterate through all modules on this part { PartModule partModule = part.Modules[i]; //if type is not an instance of this partmodule, skip the rest of this block and continue the loop if (!type.IsInstanceOfType(partModule)) { continue; } BaseField field = partModule.Fields[key]; //field = the field named the same as key String fieldValue = field.GetValue(partModule).ToString(); //get the value of that field if (fieldValue != value) //if that value isnt what we want, continue { continue; } _targetModule = partModule; //we found the right module break; //stop the loop } }
public override void OnStart(StartState state) { StringCollectionParser parser = new StringCollectionParser(); parser.SetFromString(toggle); _toggle = parser; Type type = Parser.ModTypes.Find(t => t.Name == module && typeof(PartModule).IsAssignableFrom(t)); for (Int32 i = 0; i < part.Modules.Count; i++) { PartModule partModule = part.Modules[i]; if (!type.IsInstanceOfType(partModule)) { continue; } BaseField field = partModule.Fields[key]; String fieldValue = field.GetValue(partModule).ToString(); if (fieldValue != value) { continue; } _targetModule = partModule; break; } }
protected override void BuildDialog() { // Skin Skin = KittopiaTech.Skin; // Build a list of collection elements StringCollectionParser collectionParser = (StringCollectionParser)GetValue(); // Display a scroll area GUIScrollList(new Vector2(290, 400), false, true, () => { GUIVerticalLayout(true, false, 2f, new RectOffset(8, 26, 8, 8), TextAnchor.UpperLeft, () => { GUIContentSizer(ContentSizeFitter.FitMode.Unconstrained, ContentSizeFitter.FitMode.PreferredSize, true); // Use a box as a seperator GUISpace(5f); GUIBox(-1f, 1f, () => { }); GUISpace(5f); // Display all elements for (Int32 j = 0; j < collectionParser.Value.Count; j++) { Int32 i = j; // Add / Remove Buttons GUIHorizontalLayout(() => { GUIFlexibleSpace(); GUIButton("V", () => { String tmp = collectionParser.Value[i]; collectionParser.Value[i] = collectionParser.Value[i - 1]; collectionParser.Value[i - 1] = tmp; SetValue(collectionParser); }, 25f, 25f, false, () => { }, Enabled <DialogGUIButton>(() => i != 0).And(Rotation <DialogGUIButton>(180, 0, 0)) .And(Scale <DialogGUIButton>(0.7f))); GUIButton("V", () => { String tmp = collectionParser.Value[i]; collectionParser.Value[i] = collectionParser.Value[i + 1]; collectionParser.Value[i + 1] = tmp; SetValue(collectionParser); }, 25f, 25f, false, () => { }, Enabled <DialogGUIButton>(() => i != collectionParser.Value.Count - 1) .And(Scale <DialogGUIButton>(0.7f))); GUIButton("+", () => { collectionParser.Value.Insert(i, ""); SetValue(collectionParser); Redraw(); }, 25f, 25f, false, () => { }); GUIButton("x", () => { collectionParser.Value.RemoveAt(i); SetValue(collectionParser); Redraw(); }, 25f, 25f, false, () => { }); }); // Display the editor Integrate(new StringEditor(_name + " - I:" + i, () => Reference, () => collectionParser.Value[i], s => { collectionParser.Value[i] = (String)s; SetValue(collectionParser); } )); // Use a box as a seperator GUISpace(5f); GUIBox(-1f, 1f, () => { }); GUISpace(5f); } if (collectionParser.Value.Count == 0) { // Add / Remove Buttons GUIHorizontalLayout(() => { GUIButton("+", () => { collectionParser.Value.Insert(collectionParser.Value.Count, ""); SetValue(collectionParser); Redraw(); }, 25f, 25f, false, () => { }); }); // Use a box as a seperator GUISpace(5f); GUIBox(-1f, 1f, () => { }); GUISpace(5f); } }); }); }