public void ApplyThemeToScript_SingleBlockDifferentComponentName_DoesNotReplaceColour() { // Arrange var testInputBlockItem = new TextColorBlockItem(); var testInputBlock = new ItemFilterBlock(); testInputBlock.BlockItems.Add(testInputBlockItem); var testInputScript = new ItemFilterScript(); testInputScript.ItemFilterBlocks.Add(testInputBlock); var testInputTheme = new Theme(); var testInputThemeComponentColor = new Color { R = 255, G = 0, B = 1 }; var testInputThemeComponent = new ThemeComponent(ThemeComponentType.TextColor, "Test Component 1", testInputThemeComponentColor); var testInputBlockItemThemeComponent = new ThemeComponent(ThemeComponentType.TextColor, "Different Component", testInputThemeComponentColor); testInputTheme.Components.Add(testInputThemeComponent); testInputBlockItem.ThemeComponent = testInputBlockItemThemeComponent; var mockMessageBoxService = new Mock <IMessageBoxService>(); var service = new ThemeService(mockMessageBoxService.Object); // Act service.ApplyThemeToScript(testInputTheme, testInputScript); // Assert Assert.AreNotEqual(testInputThemeComponentColor, testInputBlockItem.Color); }
private void OnDeleteThemeComponentCommand(ThemeComponent themeComponent) { if (themeComponent == null) { return; } themeComponent.TerminateComponent(); Components.Remove(themeComponent); }
/// <summary> /// Draws the specified <see cref="ThemeComponent" /> in the specified state. /// </summary> /// <param name="componentID"></param> /// <param name="stateID"></param> public void DrawThemeComponent(ThemeComponentReference paramz, Control component, Dictionary <string, object> variables = null) { if (variables == null) { variables = new Dictionary <string, object>(); } ThemeComponent tc = ThemeManager.CurrentTheme.GetComponent(paramz.ComponentID); DrawThemeComponent(tc, component, paramz.StateID, variables); }
public void DrawThemeComponent(ThemeComponent tc, Control component, Guid stateID, Dictionary<string, object> variables = null) { if (tc == null) return; if (tc.InheritsComponent != null) { DrawThemeComponent(tc.InheritsComponent, component, stateID, variables); } foreach (Rendering rendering in tc.Renderings) { if (rendering.States.Count == 0 || rendering.States.Contains(stateID)) { // we can use this rendering DrawRendering(rendering, component, variables); } } }
public void DrawThemeComponent(ThemeComponent tc, Control component, Guid stateID, Dictionary <string, object> variables = null) { if (tc == null) { return; } if (tc.InheritsComponent != null) { DrawThemeComponent(tc.InheritsComponent, component, stateID, variables); } foreach (Rendering rendering in tc.Renderings) { if (rendering.States.Count == 0 || rendering.States.Contains(stateID)) { // we can use this rendering DrawRendering(rendering, component, variables); } } }
// This method converts a string into a ItemFilterBlock. This is used for pasting ItemFilterBlocks // and reading ItemFilterScripts from a file. public IItemFilterBlock TranslateStringToItemFilterBlock(string inputString, IItemFilterScript parentItemFilterScript, string originalString = "", bool initialiseBlockGroupHierarchyBuilder = false) { if (initialiseBlockGroupHierarchyBuilder) { _blockGroupHierarchyBuilder.Initialise(parentItemFilterScript.ItemFilterBlockGroups.First()); } _masterComponentCollection = parentItemFilterScript.ItemFilterScriptSettings.ThemeComponentCollection; var block = new ItemFilterBlock(parentItemFilterScript); var showHideFound = false; block.OriginalText = originalString; foreach (var line in new LineReader(() => new StringReader(inputString))) { if (line.StartsWith(@"#")) { if (!showHideFound) { block.Description = line.TrimStart('#').TrimStart(' '); } else { if (block.BlockItems.Count > 1) { block.BlockItems.Last().Comment += Environment.NewLine + line.TrimStart('#'); } else { block.ActionBlockItem.Comment += Environment.NewLine + line.TrimStart('#'); } } continue; } var fullLine = line.Trim(); var trimmedLine = fullLine; var blockComment = ""; var themeComponentType = -1; if (trimmedLine.IndexOf('#') > 0) { blockComment = trimmedLine.Substring(trimmedLine.IndexOf('#') + 1); trimmedLine = trimmedLine.Substring(0, trimmedLine.IndexOf('#')).Trim(); } var spaceOrEndOfLinePos = trimmedLine.IndexOf(" ", StringComparison.Ordinal) > 0 ? trimmedLine.IndexOf(" ", StringComparison.Ordinal) : trimmedLine.Length; var lineOption = trimmedLine.Substring(0, spaceOrEndOfLinePos); switch (lineOption) { case "Show": case "Hide": case "ShowDisabled": case "HideDisabled": { showHideFound = true; block.Action = lineOption.StartsWith("Show") ? BlockAction.Show : BlockAction.Hide; block.Enabled = !lineOption.EndsWith("Disabled"); // If block groups are enabled for this script, the comment after Show/Hide is parsed as a block // group hierarchy, if block groups are disabled it is preserved as a simple text comment. if (parentItemFilterScript.ItemFilterScriptSettings.BlockGroupsEnabled) { AddBlockGroupToBlock(block, fullLine); } else { block.ActionBlockItem.Comment = GetTextAfterFirstComment(fullLine); } break; } case "ItemLevel": { AddNumericFilterPredicateItemToBlockItems <ItemLevelBlockItem>(block, trimmedLine); break; } case "DropLevel": { AddNumericFilterPredicateItemToBlockItems <DropLevelBlockItem>(block, trimmedLine); break; } case "Quality": { AddNumericFilterPredicateItemToBlockItems <QualityBlockItem>(block, trimmedLine); break; } case "Rarity": { RemoveExistingBlockItemsOfType <RarityBlockItem>(block); var blockItemValue = new RarityBlockItem(); var result = Regex.Match(trimmedLine, @"^\w+\s+([><!=]{0,2})\s*(\w+)$"); if (result.Groups.Count == 3) { blockItemValue.FilterPredicate.PredicateOperator = EnumHelper.GetEnumValueFromDescription <FilterPredicateOperator>(string.IsNullOrEmpty(result.Groups[1].Value) ? "=" : result.Groups[1].Value); blockItemValue.FilterPredicate.PredicateOperand = (int)EnumHelper.GetEnumValueFromDescription <ItemRarity>(result.Groups[2].Value); } block.BlockItems.Add(blockItemValue); break; } case "Class": { AddStringListItemToBlockItems <ClassBlockItem>(block, trimmedLine); break; } case "BaseType": { AddStringListItemToBlockItems <BaseTypeBlockItem>(block, trimmedLine); break; } case "Prophecy": { AddStringListItemToBlockItems <ProphecyBlockItem>(block, trimmedLine); break; } case "Corrupted": { AddBooleanItemToBlockItems <CorruptedBlockItem>(block, trimmedLine); break; } case "Identified": { AddBooleanItemToBlockItems <IdentifiedBlockItem>(block, trimmedLine); break; } case "ElderItem": { AddBooleanItemToBlockItems <ElderItemBlockItem>(block, trimmedLine); break; } case "ShaperItem": { AddBooleanItemToBlockItems <ShaperItemBlockItem>(block, trimmedLine); break; } case "ShapedMap": { AddBooleanItemToBlockItems <ShapedMapBlockItem>(block, trimmedLine); break; } case "Sockets": { AddNumericFilterPredicateItemToBlockItems <SocketsBlockItem>(block, trimmedLine); break; } case "LinkedSockets": { AddNumericFilterPredicateItemToBlockItems <LinkedSocketsBlockItem>(block, trimmedLine); break; } case "Width": { AddNumericFilterPredicateItemToBlockItems <WidthBlockItem>(block, trimmedLine); break; } case "Height": { AddNumericFilterPredicateItemToBlockItems <HeightBlockItem>(block, trimmedLine); break; } case "SocketGroup": { AddStringListItemToBlockItems <SocketGroupBlockItem>(block, trimmedLine); break; } case "SetTextColor": { // Only ever use the last SetTextColor item encountered as multiples aren't valid. RemoveExistingBlockItemsOfType <TextColorBlockItem>(block); var result = Regex.Matches(trimmedLine, @"([\w\s]*)"); var blockItem = new TextColorBlockItem { Color = GetColorFromString(result[0].Groups[1].Value) }; block.BlockItems.Add(blockItem); themeComponentType = (int)ThemeComponentType.TextColor; break; } case "SetBackgroundColor": { // Only ever use the last SetBackgroundColor item encountered as multiples aren't valid. RemoveExistingBlockItemsOfType <BackgroundColorBlockItem>(block); var result = Regex.Matches(trimmedLine, @"([\w\s]*)"); var blockItem = new BackgroundColorBlockItem { Color = GetColorFromString(result[0].Groups[1].Value) }; block.BlockItems.Add(blockItem); themeComponentType = (int)ThemeComponentType.BackgroundColor; break; } case "SetBorderColor": { // Only ever use the last SetBorderColor item encountered as multiples aren't valid. RemoveExistingBlockItemsOfType <BorderColorBlockItem>(block); var result = Regex.Matches(trimmedLine, @"([\w\s]*)"); var blockItem = new BorderColorBlockItem { Color = GetColorFromString(result[0].Groups[1].Value) }; block.BlockItems.Add(blockItem); themeComponentType = (int)ThemeComponentType.BorderColor; break; } case "SetFontSize": { // Only ever use the last SetFontSize item encountered as multiples aren't valid. RemoveExistingBlockItemsOfType <FontSizeBlockItem>(block); var match = Regex.Matches(trimmedLine, @"(\s+(\d+)\s*)"); if (match.Count > 0) { var blockItem = new FontSizeBlockItem(Convert.ToInt16(match[0].Groups[2].Value)); block.BlockItems.Add(blockItem); themeComponentType = (int)ThemeComponentType.FontSize; } break; } case "PlayAlertSound": case "PlayAlertSoundPositional": { // Only ever use the last PlayAlertSound item encountered as multiples aren't valid. RemoveExistingBlockItemsOfType <SoundBlockItem>(block); RemoveExistingBlockItemsOfType <PositionalSoundBlockItem>(block); RemoveExistingBlockItemsOfType <CustomSoundBlockItem>(block); var match = Regex.Match(trimmedLine, @"\S+\s+(\S+)\s?(\d+)?"); if (match.Success) { string firstValue = match.Groups[1].Value; var secondValue = match.Groups[2].Success ? Convert.ToInt16(match.Groups[2].Value) : 79; if (lineOption == "PlayAlertSound") { var blockItemValue = new SoundBlockItem { Value = firstValue, SecondValue = secondValue }; block.BlockItems.Add(blockItemValue); } else { var blockItemValue = new PositionalSoundBlockItem { Value = firstValue, SecondValue = secondValue }; block.BlockItems.Add(blockItemValue); } themeComponentType = (int)ThemeComponentType.AlertSound; } break; } case "GemLevel": { AddNumericFilterPredicateItemToBlockItems <GemLevelBlockItem>(block, trimmedLine); break; } case "StackSize": { AddNumericFilterPredicateItemToBlockItems <StackSizeBlockItem>(block, trimmedLine); break; } case "HasExplicitMod": { AddStringListItemToBlockItems <HasExplicitModBlockItem>(block, trimmedLine); break; } case "ElderMap": { AddBooleanItemToBlockItems <ElderMapBlockItem>(block, trimmedLine); break; } case "DisableDropSound": { // Only ever use the last DisableDropSound item encountered as multiples aren't valid. RemoveExistingBlockItemsOfType <DisableDropSoundBlockItem>(block); AddNilItemToBlockItems <DisableDropSoundBlockItem>(block, trimmedLine); break; } case "MinimapIcon": { // Only ever use the last Icon item encountered as multiples aren't valid. RemoveExistingBlockItemsOfType <MapIconBlockItem>(block); // TODO: Get size, color, shape values programmatically var match = Regex.Match(trimmedLine, @"\S+\s+(0|1|2)\s+(Red|Green|Blue|Brown|White|Yellow)\s+(Circle|Diamond|Hexagon|Square|Star|Triangle)\s*([#]?)(.*)", RegexOptions.IgnoreCase); if (match.Success) { var blockItemValue = new MapIconBlockItem { Size = (IconSize)short.Parse(match.Groups[1].Value), Color = EnumHelper.GetEnumValueFromDescription <IconColor>(match.Groups[2].Value), Shape = EnumHelper.GetEnumValueFromDescription <IconShape>(match.Groups[3].Value) }; block.BlockItems.Add(blockItemValue); themeComponentType = (int)ThemeComponentType.Icon; } break; } case "PlayEffect": { // Only ever use the last BeamColor item encountered as multiples aren't valid. RemoveExistingBlockItemsOfType <PlayEffectBlockItem>(block); // TODO: Get colors programmatically var match = Regex.Match(trimmedLine, @"\S+\s+(Red|Green|Blue|Brown|White|Yellow)\s*(Temp)?", RegexOptions.IgnoreCase); if (match.Success) { var blockItemValue = new PlayEffectBlockItem { Color = EnumHelper.GetEnumValueFromDescription <EffectColor>(match.Groups[1].Value), Temporary = match.Groups[2].Value.Trim().ToLower() == "temp" }; block.BlockItems.Add(blockItemValue); themeComponentType = (int)ThemeComponentType.Effect; } break; } case "CustomAlertSound": { // Only ever use the last CustomSoundBlockItem item encountered as multiples aren't valid. RemoveExistingBlockItemsOfType <CustomSoundBlockItem>(block); RemoveExistingBlockItemsOfType <SoundBlockItem>(block); RemoveExistingBlockItemsOfType <PositionalSoundBlockItem>(block); var match = Regex.Match(trimmedLine, @"\S+\s+""([^\*\<\>\?|]+)"""); if (match.Success) { var blockItemValue = new CustomSoundBlockItem { Value = match.Groups[1].Value }; block.BlockItems.Add(blockItemValue); themeComponentType = (int)ThemeComponentType.CustomSound; } break; } case "MapTier": { AddNumericFilterPredicateItemToBlockItems <MapTierBlockItem>(block, trimmedLine); break; } } if (!string.IsNullOrWhiteSpace(blockComment) && block.BlockItems.Count > 1) { if (!(block.BlockItems.Last() is IBlockItemWithTheme blockItemWithTheme)) { block.BlockItems.Last().Comment = blockComment; } else { switch ((ThemeComponentType)themeComponentType) { case ThemeComponentType.AlertSound: { ThemeComponent themeComponent; if (blockItemWithTheme is SoundBlockItem item) { themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.AlertSound, blockComment.Trim(), item.Value, item.SecondValue); } else { themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.AlertSound, blockComment.Trim(), ((PositionalSoundBlockItem)blockItemWithTheme).Value, ((PositionalSoundBlockItem)blockItemWithTheme).SecondValue); } blockItemWithTheme.ThemeComponent = themeComponent; break; } case ThemeComponentType.BackgroundColor: { ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.BackgroundColor, blockComment.Trim(), ((BackgroundColorBlockItem)blockItemWithTheme).Color); blockItemWithTheme.ThemeComponent = themeComponent; break; } case ThemeComponentType.BorderColor: { ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.BorderColor, blockComment.Trim(), ((BorderColorBlockItem)blockItemWithTheme).Color); blockItemWithTheme.ThemeComponent = themeComponent; break; } case ThemeComponentType.CustomSound: { ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.CustomSound, blockComment.Trim(), ((CustomSoundBlockItem)blockItemWithTheme).Value); blockItemWithTheme.ThemeComponent = themeComponent; break; } case ThemeComponentType.Effect: { ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.Effect, blockComment.Trim(), ((EffectColorBlockItem)blockItemWithTheme).Color, ((EffectColorBlockItem)blockItemWithTheme).Temporary); blockItemWithTheme.ThemeComponent = themeComponent; break; } case ThemeComponentType.FontSize: { ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.FontSize, blockComment.Trim(), ((FontSizeBlockItem)blockItemWithTheme).Value); blockItemWithTheme.ThemeComponent = themeComponent; break; } case ThemeComponentType.Icon: { ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.Icon, blockComment.Trim(), ((IconBlockItem)blockItemWithTheme).Size, ((IconBlockItem)blockItemWithTheme).Color, ((IconBlockItem)blockItemWithTheme).Shape); blockItemWithTheme.ThemeComponent = themeComponent; break; } case ThemeComponentType.TextColor: { ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.TextColor, blockComment.Trim(), ((TextColorBlockItem)blockItemWithTheme).Color); blockItemWithTheme.ThemeComponent = themeComponent; break; } } } } }
protected override void AfterLoadInternal(Stack<ObjectModel> objectModels) { base.AfterLoadInternal(objectModels); MarkupObjectModel mom = (objectModels.Pop() as MarkupObjectModel); ThemeObjectModel themes = (objectModels.Pop() as ThemeObjectModel); MarkupTagElement tagThemes = (mom.FindElement("AwesomeControls", "Theming", "Themes") as MarkupTagElement); if (tagThemes != null) { foreach (MarkupElement elTheme in tagThemes.Elements) { MarkupTagElement tagTheme = (elTheme as MarkupTagElement); if (tagTheme == null) continue; MarkupAttribute attThemeID = tagTheme.Attributes["ID"]; if (attThemeID == null) continue; Theme theme = new Theme(); UniversalEditor.Accessors.FileAccessor fa = (this.Accessor as UniversalEditor.Accessors.FileAccessor); if (fa != null) theme.BasePath = System.IO.Path.GetDirectoryName(fa.FileName); theme.ID = new Guid(attThemeID.Value); MarkupAttribute attInheritsThemeID = tagTheme.Attributes["InheritsThemeID"]; if (attInheritsThemeID != null) theme.InheritsThemeID = new Guid(attInheritsThemeID.Value); MarkupTagElement tagInformation = (tagTheme.Elements["Information"] as MarkupTagElement); if (tagInformation != null) { MarkupTagElement tagInformationTitle = (tagInformation.Elements["Title"] as MarkupTagElement); if (tagInformationTitle != null) theme.Title = tagInformationTitle.Value; } MarkupTagElement tagMetrics = (tagTheme.Elements["Metrics"] as MarkupTagElement); if (tagMetrics != null) { foreach (MarkupElement elMetric in tagMetrics.Elements) { MarkupTagElement tagMetric = (elMetric as MarkupTagElement); if (tagMetric == null) continue; MarkupAttribute attMetricName = tagMetric.Attributes["Name"]; if (attMetricName == null) continue; switch (tagMetric.FullName.ToLower()) { case "paddingmetric": { PaddingMetric metric = new PaddingMetric(); metric.Name = attMetricName.Value; MarkupAttribute attMetricLeft = tagMetric.Attributes["Left"]; if (attMetricLeft != null) metric.Left = Single.Parse(attMetricLeft.Value); MarkupAttribute attMetricTop = tagMetric.Attributes["Top"]; if (attMetricTop != null) metric.Top = Single.Parse(attMetricTop.Value); MarkupAttribute attMetricBottom = tagMetric.Attributes["Bottom"]; if (attMetricBottom != null) metric.Bottom = Single.Parse(attMetricBottom.Value); MarkupAttribute attMetricRight = tagMetric.Attributes["Right"]; if (attMetricRight != null) metric.Right = Single.Parse(attMetricRight.Value); theme.Metrics.Add(metric); break; } } } } MarkupTagElement tagColors = (tagTheme.Elements["Colors"] as MarkupTagElement); if (tagColors != null) { foreach (MarkupElement elColor in tagColors.Elements) { MarkupTagElement tagColor = (elColor as MarkupTagElement); if (tagColor == null) continue; if (tagColor.FullName != "Color") continue; MarkupAttribute attColorID = tagColor.Attributes["ID"]; MarkupAttribute attColorName = tagColor.Attributes["Name"]; if (attColorID == null && attColorName == null) continue; MarkupAttribute attColorValue = tagColor.Attributes["Value"]; if (attColorValue == null) continue; ThemeColor color = new ThemeColor(); if (attColorID != null) color.ID = new Guid(attColorID.Value); if (attColorName != null) color.Name = attColorName.Value; if (attColorValue != null) color.Value = attColorValue.Value; theme.Colors.Add(color); } } MarkupTagElement tagFonts = (tagTheme.Elements["Fonts"] as MarkupTagElement); if (tagFonts != null) { foreach (MarkupElement elFont in tagFonts.Elements) { MarkupTagElement tagFont = (elFont as MarkupTagElement); if (tagFont == null) continue; if (tagFont.FullName != "Font") continue; MarkupAttribute attFontName = tagFont.Attributes["Name"]; if (attFontName == null) continue; MarkupAttribute attFontValue = tagFont.Attributes["Value"]; if (attFontValue == null) continue; ThemeFont font = new ThemeFont(); font.Name = attFontName.Value; font.Value = attFontValue.Value; theme.Fonts.Add(font); } } MarkupTagElement tagStockImages = (tagTheme.Elements["StockImages"] as MarkupTagElement); if (tagStockImages != null) { foreach (MarkupElement elStockImage in tagStockImages.Elements) { MarkupTagElement tagStockImage = (elStockImage as MarkupTagElement); if (tagStockImage == null) continue; if (tagStockImage.FullName != "StockImage") continue; MarkupAttribute attStockImageName = tagStockImage.Attributes["Name"]; if (attStockImageName == null) continue; MarkupAttribute attStockImageFileName = tagStockImage.Attributes["FileName"]; if (attStockImageFileName == null) continue; ThemeStockImage stockImage = new ThemeStockImage(); stockImage.Name = attStockImageName.Value; stockImage.ImageFileName = attStockImageFileName.Value; theme.StockImages.Add(stockImage); } } MarkupTagElement tagProperties = (tagTheme.Elements["Properties"] as MarkupTagElement); if (tagProperties != null) { foreach (MarkupElement elProperty in tagProperties.Elements) { MarkupTagElement tagProperty = (elProperty as MarkupTagElement); if (tagProperty == null) continue; if (tagProperty.FullName != "Property") continue; MarkupAttribute attName = tagProperty.Attributes["Name"]; if (attName == null) continue; ThemeProperty property = new ThemeProperty(); property.Name = attName.Value; MarkupAttribute attValue = tagProperty.Attributes["Value"]; if (attValue != null) property.Value = attValue.Value; theme.Properties.Add(property); } } MarkupTagElement tagComponents = (tagTheme.Elements["Components"] as MarkupTagElement); if (tagComponents != null) { foreach (MarkupElement elComponent in tagComponents.Elements) { MarkupTagElement tagComponent = (elComponent as MarkupTagElement); if (tagComponent == null) continue; if (tagComponent.FullName != "Component") continue; MarkupAttribute attComponentID = tagComponent.Attributes["ID"]; if (attComponentID == null) continue; ThemeComponent component = new ThemeComponent(); component.ID = new Guid(attComponentID.Value); MarkupAttribute attInheritsComponentID = tagComponent.Attributes["InheritsComponentID"]; if (attInheritsComponentID != null) component.InheritsComponentID = new Guid(attInheritsComponentID.Value); MarkupTagElement tagComponentStates = (tagComponent.Elements["States"] as MarkupTagElement); if (tagComponentStates != null) { // if States is specified, only apply to specific states foreach (MarkupElement elState in tagComponentStates.Elements) { MarkupTagElement tagState = (elState as MarkupTagElement); if (tagState == null) continue; if (tagState.FullName != "State") continue; MarkupAttribute attStateID = tagState.Attributes["ID"]; if (attStateID == null) continue; ThemeComponentState state = new ThemeComponentState(); state.ID = new Guid(attStateID.Value); MarkupAttribute attStateName = tagState.Attributes["Name"]; if (attStateName != null) state.Name = attStateName.Value; component.States.Add(state); } } MarkupTagElement tagRenderings = (tagComponent.Elements["Renderings"] as MarkupTagElement); if (tagRenderings != null) { foreach (MarkupElement elRendering in tagRenderings.Elements) { MarkupTagElement tagRendering = (elRendering as MarkupTagElement); if (tagRendering == null) continue; if (tagRendering.FullName != "Rendering") continue; MarkupTagElement tagRenderingActions = (tagRendering.Elements["Actions"] as MarkupTagElement); if (tagRenderingActions == null) continue; Rendering rendering = new Rendering(); foreach (MarkupElement elRenderingAction in tagRenderingActions.Elements) { MarkupTagElement tagRenderingAction = (elRenderingAction as MarkupTagElement); if (tagRenderingAction == null) continue; switch (tagRenderingAction.FullName) { case "Rectangle": { MarkupAttribute attX = tagRenderingAction.Attributes["X"]; MarkupAttribute attY = tagRenderingAction.Attributes["Y"]; MarkupAttribute attWidth = tagRenderingAction.Attributes["Width"]; MarkupAttribute attHeight = tagRenderingAction.Attributes["Height"]; RectangleRenderingAction item = new RectangleRenderingAction(); item.X = RenderingExpression.Parse(attX.Value); item.Y = RenderingExpression.Parse(attY.Value); item.Width = RenderingExpression.Parse(attWidth.Value); item.Height = RenderingExpression.Parse(attHeight.Value); item.Outline = OutlineFromTag(tagRenderingAction.Elements["Outline"] as MarkupTagElement); item.Fill = FillFromTag(tagRenderingAction.Elements["Fill"] as MarkupTagElement); rendering.Actions.Add(item); break; } case "Line": { LineRenderingAction item = new LineRenderingAction(); MarkupAttribute attX1 = tagRenderingAction.Attributes["X1"]; if (attX1 != null) { item.X1 = RenderingExpression.Parse(attX1.Value); } MarkupAttribute attX2 = tagRenderingAction.Attributes["X2"]; if (attX2 != null) { item.X2 = RenderingExpression.Parse(attX2.Value); } MarkupAttribute attY1 = tagRenderingAction.Attributes["Y1"]; if (attY1 != null) { item.Y1 = RenderingExpression.Parse(attY1.Value); } MarkupAttribute attY2 = tagRenderingAction.Attributes["Y2"]; if (attY2 != null) { item.Y2 = RenderingExpression.Parse(attY2.Value); } item.Outline = OutlineFromTag(tagRenderingAction.Elements["Outline"] as MarkupTagElement); rendering.Actions.Add(item); break; } case "Text": { MarkupAttribute attX = tagRenderingAction.Attributes["X"]; MarkupAttribute attY = tagRenderingAction.Attributes["Y"]; MarkupAttribute attWidth = tagRenderingAction.Attributes["Width"]; MarkupAttribute attHeight = tagRenderingAction.Attributes["Height"]; if (attX == null || attY == null) continue; MarkupAttribute attHorizontalAlignment = tagRenderingAction.Attributes["HorizontalAlignment"]; MarkupAttribute attVerticalAlignment = tagRenderingAction.Attributes["VerticalAlignment"]; TextRenderingAction item = new TextRenderingAction(); item.X = RenderingExpression.Parse(attX.Value); item.Y = RenderingExpression.Parse(attY.Value); if (attWidth != null) item.Width = RenderingExpression.Parse(attWidth.Value); if (attWidth != null) item.Height = RenderingExpression.Parse(attHeight.Value); if (attHorizontalAlignment != null) { switch (attHorizontalAlignment.Value.ToLower()) { case "center": { item.HorizontalAlignment = HorizontalAlignment.Center; break; } case "justify": { item.HorizontalAlignment = HorizontalAlignment.Justify; break; } case "left": { item.HorizontalAlignment = HorizontalAlignment.Left; break; } case "right": { item.HorizontalAlignment = HorizontalAlignment.Right; break; } } } if (attVerticalAlignment != null) { switch (attVerticalAlignment.Value.ToLower()) { case "bottom": { item.VerticalAlignment = VerticalAlignment.Bottom; break; } case "middle": { item.VerticalAlignment = VerticalAlignment.Middle; break; } case "top": { item.VerticalAlignment = VerticalAlignment.Top; break; } } } MarkupAttribute attColor = tagRenderingAction.Attributes["Color"]; if (attColor != null) item.Color = attColor.Value; MarkupAttribute attFont = tagRenderingAction.Attributes["Font"]; if (attFont != null) item.Font = attFont.Value; MarkupAttribute attValue = tagRenderingAction.Attributes["Value"]; if (attValue != null) item.Value = attValue.Value; rendering.Actions.Add(item); break; } } } MarkupTagElement tagRenderingStates = (tagRendering.Elements["States"] as MarkupTagElement); if (tagRenderingStates != null) { // if States is specified, only apply to specific states foreach (MarkupElement elState in tagRenderingStates.Elements) { MarkupTagElement tagState = (elState as MarkupTagElement); if (tagState == null) continue; if (tagState.FullName != "State") continue; MarkupAttribute attStateID = tagState.Attributes["ID"]; if (attStateID == null) continue; ThemeComponentStateReference state = new ThemeComponentStateReference(); state.StateID = new Guid(attStateID.Value); rendering.States.Add(state); } } component.Renderings.Add(rendering); } } theme.Components.Add(component); } } themes.Themes.Add(theme); } } }
protected override void AfterLoadInternal(Stack <ObjectModel> objectModels) { base.AfterLoadInternal(objectModels); MarkupObjectModel mom = (objectModels.Pop() as MarkupObjectModel); ThemeObjectModel themes = (objectModels.Pop() as ThemeObjectModel); MarkupTagElement tagThemes = (mom.FindElement("AwesomeControls", "Theming", "Themes") as MarkupTagElement); if (tagThemes != null) { foreach (MarkupElement elTheme in tagThemes.Elements) { MarkupTagElement tagTheme = (elTheme as MarkupTagElement); if (tagTheme == null) { continue; } MarkupAttribute attThemeID = tagTheme.Attributes["ID"]; if (attThemeID == null) { continue; } Theme theme = new Theme(); UniversalEditor.Accessors.FileAccessor fa = (this.Accessor as UniversalEditor.Accessors.FileAccessor); if (fa != null) { theme.BasePath = System.IO.Path.GetDirectoryName(fa.FileName); } theme.ID = new Guid(attThemeID.Value); MarkupAttribute attInheritsThemeID = tagTheme.Attributes["InheritsThemeID"]; if (attInheritsThemeID != null) { theme.InheritsThemeID = new Guid(attInheritsThemeID.Value); } MarkupTagElement tagInformation = (tagTheme.Elements["Information"] as MarkupTagElement); if (tagInformation != null) { MarkupTagElement tagInformationTitle = (tagInformation.Elements["Title"] as MarkupTagElement); if (tagInformationTitle != null) { theme.Title = tagInformationTitle.Value; } } MarkupTagElement tagMetrics = (tagTheme.Elements["Metrics"] as MarkupTagElement); if (tagMetrics != null) { foreach (MarkupElement elMetric in tagMetrics.Elements) { MarkupTagElement tagMetric = (elMetric as MarkupTagElement); if (tagMetric == null) { continue; } MarkupAttribute attMetricName = tagMetric.Attributes["Name"]; if (attMetricName == null) { continue; } switch (tagMetric.FullName.ToLower()) { case "paddingmetric": { PaddingMetric metric = new PaddingMetric(); metric.Name = attMetricName.Value; MarkupAttribute attMetricLeft = tagMetric.Attributes["Left"]; if (attMetricLeft != null) { metric.Left = Single.Parse(attMetricLeft.Value); } MarkupAttribute attMetricTop = tagMetric.Attributes["Top"]; if (attMetricTop != null) { metric.Top = Single.Parse(attMetricTop.Value); } MarkupAttribute attMetricBottom = tagMetric.Attributes["Bottom"]; if (attMetricBottom != null) { metric.Bottom = Single.Parse(attMetricBottom.Value); } MarkupAttribute attMetricRight = tagMetric.Attributes["Right"]; if (attMetricRight != null) { metric.Right = Single.Parse(attMetricRight.Value); } theme.Metrics.Add(metric); break; } } } } MarkupTagElement tagColors = (tagTheme.Elements["Colors"] as MarkupTagElement); if (tagColors != null) { foreach (MarkupElement elColor in tagColors.Elements) { MarkupTagElement tagColor = (elColor as MarkupTagElement); if (tagColor == null) { continue; } if (tagColor.FullName != "Color") { continue; } MarkupAttribute attColorID = tagColor.Attributes["ID"]; MarkupAttribute attColorName = tagColor.Attributes["Name"]; if (attColorID == null && attColorName == null) { continue; } MarkupAttribute attColorValue = tagColor.Attributes["Value"]; if (attColorValue == null) { continue; } ThemeColor color = new ThemeColor(); if (attColorID != null) { color.ID = new Guid(attColorID.Value); } if (attColorName != null) { color.Name = attColorName.Value; } if (attColorValue != null) { color.Value = attColorValue.Value; } theme.Colors.Add(color); } } MarkupTagElement tagFonts = (tagTheme.Elements["Fonts"] as MarkupTagElement); if (tagFonts != null) { foreach (MarkupElement elFont in tagFonts.Elements) { MarkupTagElement tagFont = (elFont as MarkupTagElement); if (tagFont == null) { continue; } if (tagFont.FullName != "Font") { continue; } MarkupAttribute attFontName = tagFont.Attributes["Name"]; if (attFontName == null) { continue; } MarkupAttribute attFontValue = tagFont.Attributes["Value"]; if (attFontValue == null) { continue; } ThemeFont font = new ThemeFont(); font.Name = attFontName.Value; font.Value = attFontValue.Value; theme.Fonts.Add(font); } } MarkupTagElement tagStockImages = (tagTheme.Elements["StockImages"] as MarkupTagElement); if (tagStockImages != null) { foreach (MarkupElement elStockImage in tagStockImages.Elements) { MarkupTagElement tagStockImage = (elStockImage as MarkupTagElement); if (tagStockImage == null) { continue; } if (tagStockImage.FullName != "StockImage") { continue; } MarkupAttribute attStockImageName = tagStockImage.Attributes["Name"]; if (attStockImageName == null) { continue; } MarkupAttribute attStockImageFileName = tagStockImage.Attributes["FileName"]; if (attStockImageFileName == null) { continue; } ThemeStockImage stockImage = new ThemeStockImage(); stockImage.Name = attStockImageName.Value; stockImage.ImageFileName = attStockImageFileName.Value; theme.StockImages.Add(stockImage); } } MarkupTagElement tagProperties = (tagTheme.Elements["Properties"] as MarkupTagElement); if (tagProperties != null) { foreach (MarkupElement elProperty in tagProperties.Elements) { MarkupTagElement tagProperty = (elProperty as MarkupTagElement); if (tagProperty == null) { continue; } if (tagProperty.FullName != "Property") { continue; } MarkupAttribute attName = tagProperty.Attributes["Name"]; if (attName == null) { continue; } ThemeProperty property = new ThemeProperty(); property.Name = attName.Value; MarkupAttribute attValue = tagProperty.Attributes["Value"]; if (attValue != null) { property.Value = attValue.Value; } theme.Properties.Add(property); } } MarkupTagElement tagComponents = (tagTheme.Elements["Components"] as MarkupTagElement); if (tagComponents != null) { foreach (MarkupElement elComponent in tagComponents.Elements) { MarkupTagElement tagComponent = (elComponent as MarkupTagElement); if (tagComponent == null) { continue; } if (tagComponent.FullName != "Component") { continue; } MarkupAttribute attComponentID = tagComponent.Attributes["ID"]; if (attComponentID == null) { continue; } ThemeComponent component = new ThemeComponent(); component.ID = new Guid(attComponentID.Value); MarkupAttribute attInheritsComponentID = tagComponent.Attributes["InheritsComponentID"]; if (attInheritsComponentID != null) { component.InheritsComponentID = new Guid(attInheritsComponentID.Value); } MarkupTagElement tagComponentStates = (tagComponent.Elements["States"] as MarkupTagElement); if (tagComponentStates != null) { // if States is specified, only apply to specific states foreach (MarkupElement elState in tagComponentStates.Elements) { MarkupTagElement tagState = (elState as MarkupTagElement); if (tagState == null) { continue; } if (tagState.FullName != "State") { continue; } MarkupAttribute attStateID = tagState.Attributes["ID"]; if (attStateID == null) { continue; } ThemeComponentState state = new ThemeComponentState(); state.ID = new Guid(attStateID.Value); MarkupAttribute attStateName = tagState.Attributes["Name"]; if (attStateName != null) { state.Name = attStateName.Value; } component.States.Add(state); } } MarkupTagElement tagRenderings = (tagComponent.Elements["Renderings"] as MarkupTagElement); if (tagRenderings != null) { foreach (MarkupElement elRendering in tagRenderings.Elements) { MarkupTagElement tagRendering = (elRendering as MarkupTagElement); if (tagRendering == null) { continue; } if (tagRendering.FullName != "Rendering") { continue; } MarkupTagElement tagRenderingActions = (tagRendering.Elements["Actions"] as MarkupTagElement); if (tagRenderingActions == null) { continue; } Rendering rendering = new Rendering(); foreach (MarkupElement elRenderingAction in tagRenderingActions.Elements) { MarkupTagElement tagRenderingAction = (elRenderingAction as MarkupTagElement); if (tagRenderingAction == null) { continue; } switch (tagRenderingAction.FullName) { case "Rectangle": { MarkupAttribute attX = tagRenderingAction.Attributes["X"]; MarkupAttribute attY = tagRenderingAction.Attributes["Y"]; MarkupAttribute attWidth = tagRenderingAction.Attributes["Width"]; MarkupAttribute attHeight = tagRenderingAction.Attributes["Height"]; RectangleRenderingAction item = new RectangleRenderingAction(); item.X = RenderingExpression.Parse(attX.Value); item.Y = RenderingExpression.Parse(attY.Value); item.Width = RenderingExpression.Parse(attWidth.Value); item.Height = RenderingExpression.Parse(attHeight.Value); item.Outline = OutlineFromTag(tagRenderingAction.Elements["Outline"] as MarkupTagElement); item.Fill = FillFromTag(tagRenderingAction.Elements["Fill"] as MarkupTagElement); rendering.Actions.Add(item); break; } case "Line": { LineRenderingAction item = new LineRenderingAction(); MarkupAttribute attX1 = tagRenderingAction.Attributes["X1"]; if (attX1 != null) { item.X1 = RenderingExpression.Parse(attX1.Value); } MarkupAttribute attX2 = tagRenderingAction.Attributes["X2"]; if (attX2 != null) { item.X2 = RenderingExpression.Parse(attX2.Value); } MarkupAttribute attY1 = tagRenderingAction.Attributes["Y1"]; if (attY1 != null) { item.Y1 = RenderingExpression.Parse(attY1.Value); } MarkupAttribute attY2 = tagRenderingAction.Attributes["Y2"]; if (attY2 != null) { item.Y2 = RenderingExpression.Parse(attY2.Value); } item.Outline = OutlineFromTag(tagRenderingAction.Elements["Outline"] as MarkupTagElement); rendering.Actions.Add(item); break; } case "Text": { MarkupAttribute attX = tagRenderingAction.Attributes["X"]; MarkupAttribute attY = tagRenderingAction.Attributes["Y"]; MarkupAttribute attWidth = tagRenderingAction.Attributes["Width"]; MarkupAttribute attHeight = tagRenderingAction.Attributes["Height"]; if (attX == null || attY == null) { continue; } MarkupAttribute attHorizontalAlignment = tagRenderingAction.Attributes["HorizontalAlignment"]; MarkupAttribute attVerticalAlignment = tagRenderingAction.Attributes["VerticalAlignment"]; TextRenderingAction item = new TextRenderingAction(); item.X = RenderingExpression.Parse(attX.Value); item.Y = RenderingExpression.Parse(attY.Value); if (attWidth != null) { item.Width = RenderingExpression.Parse(attWidth.Value); } if (attWidth != null) { item.Height = RenderingExpression.Parse(attHeight.Value); } if (attHorizontalAlignment != null) { switch (attHorizontalAlignment.Value.ToLower()) { case "center": { item.HorizontalAlignment = HorizontalAlignment.Center; break; } case "justify": { item.HorizontalAlignment = HorizontalAlignment.Justify; break; } case "left": { item.HorizontalAlignment = HorizontalAlignment.Left; break; } case "right": { item.HorizontalAlignment = HorizontalAlignment.Right; break; } } } if (attVerticalAlignment != null) { switch (attVerticalAlignment.Value.ToLower()) { case "bottom": { item.VerticalAlignment = VerticalAlignment.Bottom; break; } case "middle": { item.VerticalAlignment = VerticalAlignment.Middle; break; } case "top": { item.VerticalAlignment = VerticalAlignment.Top; break; } } } MarkupAttribute attColor = tagRenderingAction.Attributes["Color"]; if (attColor != null) { item.Color = attColor.Value; } MarkupAttribute attFont = tagRenderingAction.Attributes["Font"]; if (attFont != null) { item.Font = attFont.Value; } MarkupAttribute attValue = tagRenderingAction.Attributes["Value"]; if (attValue != null) { item.Value = attValue.Value; } rendering.Actions.Add(item); break; } } } MarkupTagElement tagRenderingStates = (tagRendering.Elements["States"] as MarkupTagElement); if (tagRenderingStates != null) { // if States is specified, only apply to specific states foreach (MarkupElement elState in tagRenderingStates.Elements) { MarkupTagElement tagState = (elState as MarkupTagElement); if (tagState == null) { continue; } if (tagState.FullName != "State") { continue; } MarkupAttribute attStateID = tagState.Attributes["ID"]; if (attStateID == null) { continue; } ThemeComponentStateReference state = new ThemeComponentStateReference(); state.StateID = new Guid(attStateID.Value); rendering.States.Add(state); } } component.Renderings.Add(rendering); } } theme.Components.Add(component); } } themes.Themes.Add(theme); } } }
private bool ApplyIntegerTheme(IEnumerable <ItemFilterBlock> blocks, Type type, ThemeComponent component) { var componentMatched = false; foreach (var block in blocks) { foreach (var blockItem in block.BlockItems.Where(i => i.GetType() == type)) { var colorBlockItem = (IntegerBlockItem)blockItem; if (colorBlockItem.ThemeComponent != null && colorBlockItem.ThemeComponent.ComponentName == component.ComponentName) { colorBlockItem.Value = ((IntegerThemeComponent)component).Value; componentMatched = true; } } } return(!componentMatched); }
public void ReplaceAudioVisualBlockItemsFromString(ObservableCollection <IItemFilterBlockItem> blockItems, string inputString) { // Reverse iterate to remove existing IAudioVisualBlockItems for (var idx = blockItems.Count - 1; idx >= 0; idx--) { if (blockItems[idx] is IAudioVisualBlockItem) { blockItems.RemoveAt(idx); } } foreach (var line in new LineReader(() => new StringReader(inputString))) { var matches = Regex.Match(line, @"(\w+)"); var blockComment = ""; var trimmedLine = line.Trim(); if (trimmedLine.IndexOf('#') > 0) { blockComment = trimmedLine.Substring(trimmedLine.IndexOf('#') + 1); trimmedLine = trimmedLine.Substring(0, trimmedLine.IndexOf('#')).Trim(); } switch (matches.Value) { case "PlayAlertSound": { var match = Regex.Match(trimmedLine, @"\s+(\S+) (\d+)"); if (!match.Success) { break; } var blockItem = new SoundBlockItem(match.Groups[1].Value, Convert.ToInt16(match.Groups[2].Value)); if (_masterComponentCollection != null && !string.IsNullOrWhiteSpace(blockComment)) { ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.AlertSound, blockComment, blockItem.Value, blockItem.SecondValue); blockItem.ThemeComponent = themeComponent; } blockItems.Add(blockItem); break; } case "SetTextColor": { var result = Regex.Matches(trimmedLine, @"([\w\s]*)"); var blockItem = new TextColorBlockItem(); blockItem.Color = GetColorFromString(result[0].Groups[1].Value); if (_masterComponentCollection != null && !string.IsNullOrWhiteSpace(blockComment)) { ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.TextColor, blockComment, blockItem.Color); blockItem.ThemeComponent = themeComponent; } blockItems.Add(blockItem); break; } case "SetBackgroundColor": { var result = Regex.Matches(trimmedLine, @"([\w\s]*)"); var blockItem = new BackgroundColorBlockItem(); blockItem.Color = GetColorFromString(result[0].Groups[1].Value); if (_masterComponentCollection != null && !string.IsNullOrWhiteSpace(blockComment)) { ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.BackgroundColor, blockComment, blockItem.Color); blockItem.ThemeComponent = themeComponent; } blockItems.Add(blockItem); break; } case "SetBorderColor": { var result = Regex.Matches(trimmedLine, @"([\w\s]*)"); var blockItem = new BorderColorBlockItem(); blockItem.Color = GetColorFromString(result[0].Groups[1].Value); if (_masterComponentCollection != null && !string.IsNullOrWhiteSpace(blockComment)) { ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.BorderColor, blockComment, blockItem.Color); blockItem.ThemeComponent = themeComponent; } blockItems.Add(blockItem); break; } case "SetFontSize": { var match = Regex.Match(trimmedLine, @"\s+(\d+)"); if (!match.Success) { break; } var blockItem = new FontSizeBlockItem(Convert.ToInt16(match.Value)); if (_masterComponentCollection != null && !string.IsNullOrWhiteSpace(blockComment)) { ThemeComponent themeComponent = _masterComponentCollection.AddComponent(ThemeComponentType.FontSize, blockComment, blockItem.Value); blockItem.ThemeComponent = themeComponent; } blockItems.Add(blockItem); break; } } } }