public AlloyArgumentToken(string field, AlloyFieldLexer currentLexer) : base(field, currentLexer) { int index = field.IndexOf(':'); ArgumentName = field.Substring(0, index); string valueStr = field.Substring(index + 1); int outInd; ArgumentToken = currentLexer.GenerateToken(valueStr, 0, out outInd); }
private static void SetMinOption(AlloyFieldDrawer retDrawer, AlloyToken argToken) { var floatDrawer = retDrawer as AlloyFloatDrawer; var minValToken = argToken as AlloyValueToken; if (floatDrawer != null) { floatDrawer.HasMin = true; if (minValToken != null) { floatDrawer.MinValue = minValToken.FloatValue; } } }
private Color ParseColor(AlloyToken argToken) { var colCollection = argToken as AlloyCollectionToken; if (colCollection != null) { var r = colCollection.SubTokens[0] as AlloyValueToken; var g = colCollection.SubTokens[1] as AlloyValueToken; var b = colCollection.SubTokens[2] as AlloyValueToken; if (r != null && g != null && b != null) { return(new Color32((byte)r.FloatValue, (byte)g.FloatValue, (byte)b.FloatValue, 255)); } } return(Color.white); }
private static void SetDropdownOption(AlloyFieldDrawer retDrawer, AlloyToken argToken) { var drawer = retDrawer as AlloyDropdownDrawer; if (drawer == null) { return; } var options = argToken as AlloyCollectionToken; if (options == null) { return; } var dropOptions = new List <AlloyDropdownOption>(); for (int i = 0; i < options.SubTokens.Count; i++) { AlloyArgumentToken arg = (AlloyArgumentToken)options.SubTokens[i]; var collection = arg.ArgumentToken as AlloyCollectionToken; if (collection == null) { continue; } // Split PascalCase name into words separated by spaces while skipping acronyms. var dropOption = new AlloyDropdownOption { Name = Regex.Replace(arg.ArgumentName, @"(?<=[A-Za-z])(?=[A-Z][a-z])|(?<=[a-z0-9])(?=[0-9]?[A-Z])", " "), HideFields = collection.SubTokens.Select(alloyToken => alloyToken.Token).ToArray() }; dropOptions.Add(dropOption); } drawer.DropOptions = dropOptions.ToArray(); }
private static void SetToggleOption(AlloyFieldDrawer retDrawer, AlloyToken argToken) { var drawer = retDrawer as AlloyToggleDrawer; if (drawer == null) { return; } var collectionToken = argToken as AlloyCollectionToken; if (collectionToken == null) { return; } foreach (var token in collectionToken.SubTokens) { var arg = token as AlloyArgumentToken; if (arg != null && arg.ArgumentName == "On") { var onToken = arg.ArgumentToken as AlloyCollectionToken; if (onToken != null) { drawer.OnHideFields = onToken.SubTokens.Select(colToken => colToken.Token).ToArray(); } } else if (arg != null && arg.ArgumentName == "Off") { var offToken = arg.ArgumentToken as AlloyCollectionToken; if (offToken != null) { drawer.OffHideFields = offToken.SubTokens.Select(colToken => colToken.Token).ToArray(); } } } }
private static void SetDropdownOption(AlloyFieldDrawer retDrawer, AlloyToken argToken) { var drawer = retDrawer as AlloyDropdownDrawer; if (drawer == null) { return; } var options = argToken as AlloyCollectionToken; if (options == null) { return; } var dropOptions = new List <AlloyDropdownOption>(); for (int i = 0; i < options.SubTokens.Count; i++) { AlloyArgumentToken arg = (AlloyArgumentToken)options.SubTokens[i]; var collection = arg.ArgumentToken as AlloyCollectionToken; if (collection == null) { continue; } // Split name at capital letters, then insert spaces between words. var dropOption = new AlloyDropdownOption { Name = string.Join(" ", Regex.Split(arg.ArgumentName, @"(?<!^)(?=[A-Z])")), HideFields = collection.SubTokens.Select(alloyToken => alloyToken.Token).ToArray() }; dropOptions.Add(dropOption); } drawer.DropOptions = dropOptions.ToArray(); }
void SetSectionOption(AlloyFieldDrawer retDrawer, AlloyToken argToken) { var sectionDrawer = retDrawer as AlloyTabDrawer; if (sectionDrawer != null) { var collectionToken = argToken as AlloyCollectionToken; if (collectionToken == null) { sectionDrawer.Color = c_defaultSectionColor; } else { foreach (var token in collectionToken.SubTokens) { var arg = token as AlloyArgumentToken; if (arg != null && arg.ArgumentName == "Color") { var value = arg.ArgumentToken as AlloyValueToken; // Calculate color from section index and HSV scale factor. if (value != null) { var hueIndex = value.FloatValue; if (hueIndex > -0.1f) { sectionDrawer.Color = Color.HSVToRGB((hueIndex / AlloyUtils.SectionColorMax) * 0.6f, 0.75f, 0.5f); } } else { // Manually specify color. var colCollection = arg.ArgumentToken as AlloyCollectionToken; if (colCollection != null) { var r = colCollection.SubTokens[0] as AlloyValueToken; var g = colCollection.SubTokens[1] as AlloyValueToken; var b = colCollection.SubTokens[2] as AlloyValueToken; if (r != null && g != null && b != null) { sectionDrawer.Color = new Color32((byte)r.FloatValue, (byte)g.FloatValue, (byte)b.FloatValue, 255); } } } } else if (arg != null && arg.ArgumentName == "Hide") { var featureDrawer = sectionDrawer as AlloyFeatureDrawer; var offToken = arg.ArgumentToken as AlloyCollectionToken; if (offToken != null) { featureDrawer.HideFields = offToken.SubTokens.Select(colToken => colToken.Token).ToArray(); } } } } } }
private Color ParseColor(AlloyToken argToken) { var colCollection = argToken as AlloyCollectionToken; if (colCollection != null) { var r = colCollection.SubTokens[0] as AlloyValueToken; var g = colCollection.SubTokens[1] as AlloyValueToken; var b = colCollection.SubTokens[2] as AlloyValueToken; if (r != null && g != null && b != null) { return new Color32((byte)r.FloatValue, (byte)g.FloatValue, (byte)b.FloatValue, 255); } } return Color.white; }
private static void SetDropdownOption(AlloyFieldDrawer retDrawer, AlloyToken argToken) { var drawer = retDrawer as AlloyDropdownDrawer; if (drawer == null) { return; } var options = argToken as AlloyCollectionToken; if (options == null) { return; } var dropOptions = new List<AlloyDropdownOption>(); for (int i = 0; i < options.SubTokens.Count; i++) { AlloyArgumentToken arg = (AlloyArgumentToken)options.SubTokens[i]; var collection = arg.ArgumentToken as AlloyCollectionToken; if (collection == null) { continue; } var dropOption = new AlloyDropdownOption { Name = arg.ArgumentName, HideFields = collection.SubTokens.Select(alloyToken => alloyToken.Token).ToArray() }; dropOptions.Add(dropOption); } drawer.DropOptions = dropOptions.ToArray(); }