void MakeBlendDropdown(Table table, Skin skin, string label, string propertyName) { FieldInfo fieldInfo = typeof(ParticleEmitterConfig).GetField(propertyName); Blend value = (Blend)fieldInfo.GetValue(_particleEmitterConfig); var dropdown = new SelectBox <string>(skin); var dropdownList = new List <string>() { "Zero", "One", "SourceColor", "InverseSourceColor", "SourceAlpha", "InverseSourceAlpha", "DestinationAlpha", "InverseDestinationAlpha", "DestinationColor", "InverseDestinationColor", "SourceAlphaSaturation" }; dropdown.SetItems(dropdownList); // Make a lookup table from string to blend function var nameLookup = new Dictionary <string, Blend>() { { "Zero", Blend.Zero }, { "One", Blend.One }, { "SourceColor", Blend.SourceColor }, { "InverseSourceColor", Blend.InverseSourceColor }, { "SourceAlpha", Blend.SourceAlpha }, { "InverseSourceAlpha", Blend.InverseSourceAlpha }, { "DestinationAlpha", Blend.DestinationAlpha }, { "InverseDestinationAlpha", Blend.InverseDestinationAlpha }, { "DestinationColor", Blend.DestinationColor }, { "InverseDestinationColor", Blend.InverseDestinationColor }, { "SourceAlphaSaturation", Blend.SourceAlphaSaturation } }; // Make a lookup table from blend function to string var functionLookup = new Dictionary <Blend, string>(); foreach (var str in nameLookup.Keys) { functionLookup.Add(nameLookup[str], str); } ; dropdown.SetSelectedIndex(dropdownList.IndexOf(functionLookup[value])); dropdown.OnChanged += (str) => { Blend newValue = nameLookup[str]; fieldInfo.SetValue(_particleEmitterConfig, newValue); ResetEmitter(); }; table.Add(dropdown); }
public override void Initialize(Table table, Skin skin, float leftCellWidth) { var label = CreateNameLabel(table, skin, leftCellWidth); // gotta get ugly here _selectBox = new SelectBox <string>(skin); var enumValues = Enum.GetValues(_valueType); var enumStringValues = new List <string>(); foreach (var e in enumValues) { enumStringValues.Add(e.ToString()); } _selectBox.SetItems(enumStringValues); _selectBox.OnChanged += selectedItem => { SetValue(Enum.Parse(_valueType, selectedItem)); }; table.Add(label); table.Add(_selectBox).SetFillX(); }
void MakeEmitterDropdown(Table table, Skin skin, string label) { ParticleEmitterType value = _particleEmitterConfig.EmitterType; var dropdown = new SelectBox <string>(skin); var dropdownList = new List <string>() { "Gravity", "Radial" }; dropdown.SetItems(dropdownList); if (_particleEmitterConfig.EmitterType == ParticleEmitterType.Gravity) { dropdown.SetSelectedIndex(0); } else { dropdown.SetSelectedIndex(1); } dropdown.OnChanged += (str) => { if (str == "Gravity") { _particleEmitterConfig.EmitterType = ParticleEmitterType.Gravity; } else { _particleEmitterConfig.EmitterType = ParticleEmitterType.Radial; } ResetEmitter(); ResetUi(); }; table.Add(label).Left().Width(140); table.Add("").Width(1); // This is a 3 column table table.Add(dropdown); }
public override void Initialize(Table table, Skin skin, float leftCellWidth) { var value = GetValue <Direction>(); var label = CreateNameLabel(table, skin, leftCellWidth); _selectBox = new SelectBox <string>(skin); //_selectBox.SetWidth(50); _textField = new UI.TextField(value.Value.ToString(CultureInfo.InvariantCulture), skin); _textField.SetTextFieldFilter(new DigitsOnlyFilter()).SetPreferredWidth(50); _textField.OnTextChanged += (field, str) => { int input; if (int.TryParse(str, NumberStyles.Integer, CultureInfo.InvariantCulture, out input)) { Direction newValue = new Direction(input); SetValue(newValue); } }; var directions = new List <string>() { "S", "SE", "E", "NE", "N", "NW", "W", "SW" }; _selectBox.SetItems(directions); _selectBox.OnChanged += selectedItem => { SetValue((Direction)directions.IndexOf(selectedItem)); }; var hBox = new HorizontalGroup(5); hBox.AddElement(_selectBox); hBox.AddElement(_textField); table.Add(label); table.Add(hBox); }