private Vector2 _GetAnchorMax(UiNode node) { float x; switch (node.XAnchor) { case XAnchorType.Left: x = 0; break; case XAnchorType.Center: x = 0.5f; break; case XAnchorType.Right: x = 1; break; case XAnchorType.Stretch: x = 1; break; default: x = 0.5f; break; } float y; switch (node.YAnchor) { case YAnchorType.Bottom: y = 0; break; case YAnchorType.Middle: y = 0.5f; break; case YAnchorType.Top: y = 1; break; case YAnchorType.Stretch: y = 1; break; default: y = 0.5f; break; } return(new Vector2(x, y)); }
public static Vector2 GetAnchorMaxValue(this UiNode uiNode) { float x = _GetAnchorMax(uiNode.XAnchor); float y = _GetAnchorMax(uiNode.YAnchor); return(new Vector2(x, y)); }
public UiNode(UiNode copySource) { Id = copySource.Id; Name = copySource.Name; IsVisible = copySource.IsVisible; IsSkipped = copySource.IsSkipped; Pivot = copySource.Pivot; XAnchor = copySource.XAnchor; YAnchor = copySource.YAnchor; Rect = copySource.Rect; }
private static UiNode _ParsePsdLayerRecursive(UiTreeRoot tree, PsdLayer layer) { int id = (int)layer.Resources["lyid.ID"]; string name = layer.Name; bool isVisible = layer.IsVisible; PsdLayerConfig config = tree.Configs.GetLayerConfig(id); bool isSkipped = config.GetLayerConfigAsBool(IsSkippedPropertyTag); Vector2 pivot = _GetPivot(config); XAnchorType xAnchor = _GetXAnchorType(config); YAnchorType yAnchor = _GetYAnchorType(config); var rect = new Rect { xMin = layer.Left, xMax = layer.Right, yMin = tree.Height - layer.Bottom, yMax = tree.Height - layer.Top }; bool isGroup = _IsGroupLayer(layer); bool isText = _IsTextLayer(layer); var baseUiNode = new UiNode { Id = id, Name = name, IsVisible = isVisible, IsSkipped = isSkipped, Pivot = pivot, XAnchor = xAnchor, YAnchor = yAnchor, Rect = rect }; if (isGroup) { var children = new List <UiNode>(); foreach (PsdLayer childLayer in layer.Childs) { children.Add(_ParsePsdLayerRecursive(tree, childLayer)); } return(new GroupNode(baseUiNode) { Children = children }); } else if (isText) { var engineData = (StructureEngineData)layer.Resources["TySh.Text.EngineData"]; var engineDict = (Properties)engineData["EngineDict"]; var styleRun = (Properties)engineDict["StyleRun"]; var runArray = (ArrayList)styleRun["RunArray"]; var firstRunArrayElement = (Properties)runArray[0]; var firstStyleSheet = (Properties)firstRunArrayElement["StyleSheet"]; var firstStyleSheetData = (Properties)firstStyleSheet["StyleSheetData"]; var fontIndex = (int)firstStyleSheetData["Font"]; var fontSize = _GetFontSizeFromStyleSheetData(firstStyleSheetData); // TODO: Fix this hack fontSize = fontSize / 75 * 18; var textColor = _GetTextColorFromStyleSheetData(firstStyleSheetData); var documentResources = (Properties)engineData["DocumentResources"]; var fontSet = (ArrayList)documentResources["FontSet"]; var font = (Properties)fontSet[fontIndex]; var fontName = (string)font["Name"]; var text = (string)layer.Resources["TySh.Text.Txt"]; return(new TextNode(baseUiNode) { FontSize = fontSize, FontName = fontName, Text = text, TextColor = textColor }); } else { WidgetType widgetType = config.GetLayerConfigAsWidgetType(WidgetTypePropertyTag); Texture2D texture2D = GetTexture2DFromPsdLayer(layer); return(new ImageNode(baseUiNode) { WidgetType = widgetType, SpriteSource = texture2D != null ? new InMemoryTextureSpriteSource { Texture2D = texture2D } : (ISpriteSource) new NullSpriteSource() }); } }
public void AddChild(UiNode node) { Children.Add(node); }
private static UiNode _ParsePsdLayerRecursive(UiTreeRoot tree, PsdLayer layer) { int id = (int)layer.Resources["lyid.ID"]; string name = layer.Name; bool isVisible = layer.IsVisible; var config = tree.Configs.GetLayerConfig(id); bool isSkipped = _GetLayerConfigAsBool(config, IsSkippedPropertyTag); Vector2 pivot = new Vector2(_GetLayerConfigAsFloat(config, XPivotPropertyTag, 0.5f), _GetLayerConfigAsFloat(config, YPivotPropertyTag, 0.5f)); XAnchorType xAnchor = _GetXAnchorType(config.GetValueOrDefault(XAnchorPropertyTag)); YAnchorType yAnchor = _GetYAnchorType(config.GetValueOrDefault(YAnchorPropertyTag)); var rect = new Rect { xMin = layer.Left, xMax = layer.Right, yMin = tree.Height - layer.Bottom, yMax = tree.Height - layer.Top }; bool isGroup = _IsGroupLayer(layer); bool isText = _IsTextLayer(layer); var baseUiNode = new UiNode { Id = id, Name = name, IsVisible = isVisible, IsSkipped = isSkipped, Pivot = pivot, XAnchor = xAnchor, YAnchor = yAnchor, Rect = rect }; if (isGroup) { bool hasScrollRect = _GetLayerConfigAsBool(config, HasScrollRectPropertyTag); bool isScrollRectHorizontal = _GetLayerConfigAsBool(config, IsScrollRectHorizontalPropertyTag); bool isScrollRectVertical = _GetLayerConfigAsBool(config, IsScrollRectVerticalPropertyTag); bool hasGrid = _GetLayerConfigAsBool(config, HasGridPropertyTag); Vector2 gridCellSize = Vector2.zero; Vector2 gridSpacing = Vector2.zero; if (hasGrid) { float gridCellSizeX = _GetLayerConfigAsFloat(config, GridCellSizeXPropertyTag); float gridCellSizeY = _GetLayerConfigAsFloat(config, GridCellSizeYPropertyTag); float gridSpacingX = _GetLayerConfigAsFloat(config, GridSpacingXPropertyTag); float gridSpacingY = _GetLayerConfigAsFloat(config, GridSpacingYPropertyTag); gridCellSize = new Vector2(gridCellSizeX, gridCellSizeY); gridSpacing = new Vector2(gridSpacingX, gridSpacingY); } var children = new List <UiNode>(); foreach (PsdLayer childlayer in layer.Childs) { children.Add(_ParsePsdLayerRecursive(tree, childlayer)); } return(new GroupNode(baseUiNode) { HasScrollRect = hasScrollRect, IsScrollRectHorizontal = isScrollRectHorizontal, IsScrollRectVertical = isScrollRectVertical, HasGrid = hasGrid, CellSize = gridCellSize, Spacing = gridSpacing, Children = children }); } else if (isText) { var engineData = (StructureEngineData)layer.Resources["TySh.Text.EngineData"]; var engineDict = (Properties)engineData["EngineDict"]; var styleRun = (Properties)engineDict["StyleRun"]; var runArray = (ArrayList)styleRun["RunArray"]; var firstRunArrayElement = (Properties)runArray[0]; var firstStyleSheet = (Properties)firstRunArrayElement["StyleSheet"]; var firstStyelSheetData = (Properties)firstStyleSheet["StyleSheetData"]; var fontIndex = (int)firstStyelSheetData["Font"]; var fontSize = _GetFontSizeFromStyelSheetData(firstStyelSheetData); // TODO: Fix this hack fontSize = fontSize / 75 * 18; var textColor = _GetTextColorFromStyelSheetData(firstStyelSheetData); var documentResources = (Properties)engineData["DocumentResources"]; var fontSet = (ArrayList)documentResources["FontSet"]; var font = (Properties)fontSet[fontIndex]; var fontName = (string)font["Name"]; var text = (string)layer.Resources["TySh.Text.Txt"]; return(new TextNode(baseUiNode) { FontSize = fontSize, FontName = fontName, Text = text, TextColor = textColor }); } else { string widgetTypeString = config.GetValueOrDefault(WidgetTypePropertyTag); WidgetType widgetType = _GetWidgetType(widgetTypeString); Texture2D texture2D = GetTexture2DFromPsdLayer(layer); return(new ImageNode(baseUiNode) { WidgetType = widgetType, SpriteSource = new InMemoryTextureSpriteSource { Texture2D = texture2D } }); } }
public ImageNode(UiNode baseNode) : base(baseNode) { }
public GroupNode(UiNode baseNode) : base(baseNode) { }
public TextNode(UiNode baseNode) : base(baseNode) { }