Exemplo n.º 1
0
        public MultiOptionSelector(AssetManager assets, string themeName, Vector2 position, Anchor anchor, List<Option> options, MultiOptionArrangement arrangement, Cursor cursor, int initialValue)
            : base(themeName, position, initialValue)
        {
            //process arrangement
            if (arrangement == MultiOptionArrangement.ListX)
                arrangement = new MultiOptionArrangement(options.Count, 1);
            if (arrangement == MultiOptionArrangement.ListY)
                arrangement = new MultiOptionArrangement(1, options.Count);
            this.arrangement = arrangement;

            TextDictionary assetDictionary = new TextDictionary(assets.GetText("selector"));
            //load themes
            string cursorTheme = assetDictionary.LookupString(themeName, "cursorTheme");
            string optionTheme = assetDictionary.LookupString(themeName, "optionTheme");
            Anchor justify = Anchor.Center;
            bool justifySuccess = assetDictionary.CheckPropertyExists(themeName, "justify");
            if (justifySuccess)
            {
                string justifyString = assetDictionary.LookupString(themeName, "justify");
                if (justifyString == "Left")
                    justify = Anchor.CenterLeft;
                else if (justifyString == "Right")
                    justify = Anchor.CenterRight;
            }
            //position components
            cursor.Initialize(options, assets, cursorTheme);
            Vector2 individualSize = Vector2.Zero;
            for (int i = 0; i < options.Count; i++)
            {
                options[i].Initialize(assets, optionTheme);
                if (options[i].Dimensions.X > individualSize.X)
                    individualSize.X = options[i].Dimensions.X;
                if (options[i].Dimensions.Y > individualSize.Y)
                    individualSize.Y = options[i].Dimensions.Y;
            }
            for (int i = 0; i < options.Count; i++)
                options[i].Position = (individualSize + cursor.Spacing * Vector2.One) * arrangement.GetPosition(i);
            Vector2 overallSize = new Vector2(arrangement.Columns * (individualSize.X + cursor.Spacing) - cursor.Spacing, arrangement.Rows * (individualSize.Y + cursor.Spacing) - cursor.Spacing);
            for (int i = 0; i < options.Count; i++)
            {
                Vector2 p = options[i].Position;
                if (justify == Anchor.TopCenter || justify == Anchor.Center || justify == Anchor.BottomCenter)
                    p.X += (individualSize.X - options[i].Dimensions.X) / 2;
                else if (justify == Anchor.TopRight || justify == Anchor.CenterRight || justify == Anchor.BottomRight)
                    p.X += individualSize.X - options[i].Dimensions.X;
                if (justify == Anchor.CenterLeft || justify == Anchor.Center || justify == Anchor.CenterRight)
                    p.Y += (individualSize.Y - options[i].Dimensions.Y) / 2;
                else if (justify == Anchor.BottomLeft || justify == Anchor.BottomCenter || justify == Anchor.BottomRight)
                    p.Y += individualSize.Y - options[i].Dimensions.Y;
                options[i].Position = p;
            }
            this.Position -= GraphicsHelper.ComputeAnchorOrigin(anchor, overallSize / GraphicsConstants.VIEWPORT_DIMENSIONS);
            this.options = options;
            this.cursor = cursor;
            //initialize position
            Vector2 initialPosition = arrangement.GetPosition(IntValue);
            x = (int)initialPosition.X;
            y = (int)initialPosition.Y;
            cursor.Update(IntValue);
        }
Exemplo n.º 2
0
 public static MultiOptionSelector BuildMultiOptionSelector(AssetManager assets, string theme, string selectorName, List<Option> options, MultiOptionArrangement arrangement, Cursor cursor, int initialValue = 0)
 {
     TextDictionary assetDictionary = new TextDictionary(assets.GetText("selector"));
     string selectorTheme = assetDictionary.LookupString(theme, selectorName + "SelectorTheme");
     Vector2 selectorPosition = assetDictionary.LookupVector2(theme, selectorName + "SelectorPosition");
     Anchor selectorAnchor = Anchor.Center;
     if (assetDictionary.CheckPropertyExists(theme, selectorName + "SelectorAnchor"))
         Enum.TryParse<Anchor>(assetDictionary.LookupString(theme, selectorName + "SelectorAnchor"), out selectorAnchor);
     return new MultiOptionSelector(assets, selectorTheme, selectorPosition, selectorAnchor, options, arrangement, cursor, initialValue);
 }
Exemplo n.º 3
0
 public static MultiOptionSelector BuildMultiOptionSelector(AssetManager assets, string theme, string selectorName, List<Option> options, Cursor cursor, int initialValue = 0)
 {
     return BuildMultiOptionSelector(assets, theme, selectorName, options, MultiOptionArrangement.ListY, cursor, initialValue);
 }