Ejemplo n.º 1
0
	void CreateScrollableMenuWithPips()
	{
		m_scrollable = new UIScrollableHorizontalLayout( 20 );
		
		// we wrap the addition of all the sprites with a begin updates so it only lays out once when complete
		m_scrollable.beginUpdates();
		
			// if you plan on making the scrollable wider than the item width you need to set your edgeInsets so that the
			// left + right inset is equal to the extra width you set
			float itemWidth = 250f;
			float leftInset;
			float rightInset;
			leftInset = rightInset = (Screen.width - itemWidth) / 2;
			
			m_scrollable.edgeInsets = new UIEdgeInsets( 0, Mathf.RoundToInt(leftInset), 0, Mathf.RoundToInt(rightInset) );
			
			var scrollerHeight 	= UI.scaleFactor * itemWidth;
			var scrollerWidth 	= UI.scaleFactor * ( itemWidth + leftInset + rightInset ); // item width + 150 extra width
			m_scrollable.setSize( scrollerWidth, scrollerHeight );
			
			// paging will snap to the nearest page when scrolling
			m_scrollable.pagingEnabled = true;
			m_scrollable.pageWidth = itemWidth * UI.scaleFactor;
			
			// center the scrollable horizontally
			m_scrollable.position = new Vector3( ( Screen.width - scrollerWidth ) / 2, -Screen.height + scrollerHeight, 0 );
			
			for( var i = 0; i < 20; i++ )
			{
				var button = UIButton.create( "marioPanel.png", "marioPanel.png", 0, 0 );
				m_scrollable.addChild( button );
			}
			
		m_scrollable.endUpdates();
		m_scrollable.endUpdates(); // this is a bug. it shouldnt need to be called twice
		
		//pips
		var pips = new UIRadioButtonGroup(0, UIAbstractContainer.UILayoutType.Horizontal);
		
		int pageCount = Mathf.CeilToInt(20 * itemWidth / scrollerWidth);
		for (int i = 0; i < pageCount; i++)
		{		
			var toggle = UIToggleButton.create("emptyUp.png", "emptyDown.png", "emptyUp.png", 0, 0);
			
			pips.addChild(toggle);
		}
		
		pips.beginUpdates();
			float screenUnits = 1.0f / Screen.width;
			float halfWidth = 140 * pageCount / 2;
			float offset = halfWidth * screenUnits;
			pips.positionFromCenter(-50 * screenUnits, -offset);
		pips.endUpdates();
		
		pips.OnSelect += HandlePipsOnSelect;
		pips.IndexOfCurrentlySelected = 1;
	}
Ejemplo n.º 2
0
    // TODO: Placeholder code until implementation
    // TODO: Organize the games by your turn then their turn...
    private void findCurrentGames()
    {
        // TODO: The jsonRaw variable is temporary right now. Get it from the server and mantain MVC.
        GameInfo games = new GameInfo(jsonRaw.text);

        foreach (var pair in  games.currentGames)
        {
            Game game = pair.Value;

            // Create the button
            UIButton gameButton = UIButton.create(uiTools, "currentGame.png", "currentGame.png", 0, 0, 10);

            string turn = "Your Turn";
            if (!game.playerTurn)
            {
                turn = "Their Turn";
            }

            // Turn text
            UITextInstance gameTurn = graph15White.addTextInstance(turn, 0, 0);
            gameTurn.parentUIObject = gameButton;
            gameTurn.pixelsFromTop(2);

            // Opponent Name text
            UITextInstance opponentName = graph15White.addTextInstance(game.opponentName, 0, 0);
            opponentName.parentUIObject = gameButton;
            opponentName.pixelsFromBottom(2);

            // Score Text
            string         score     = game.playerScore + "/" + game.opponentScore;
            UITextInstance scoreText = graph26White.addTextInstance(score, 0, 0);
            scoreText.parentUIObject = gameButton;
            GUIUtils.centerText(scoreText);

            currentGamesLayout.addChild(gameButton);
        }
    }
    void Start()
    {
        // add two scrollables: one with pageing enabled
        var scrollable = new UIScrollableHorizontalLayout(10);

        // we wrap the addition of all the sprites with a begin updates so it only lays out once when complete
        scrollable.beginUpdates();

        var height = UI.instance.isHD ? 150 : 300;
        var width  = Screen.width / 1.4f;

        scrollable.setSize(width, height);
        scrollable.position = new Vector3((Screen.width - width) / 2, -Screen.height + height, 0);
        scrollable.zIndex   = 3;

        for (var i = 0; i < 20; i++)
        {
            UITouchableSprite touchable;
            if (i == 4)              // text sprite
            {
                touchable = UIButton.create("emptyUp.png", "emptyDown.png", 0, 0);
            }
            else if (i % 3 == 0)
            {
                touchable = UIToggleButton.create("cbUnchecked.png", "cbChecked.png", "cbDown.png", 0, 0);
            }
            else if (i % 2 == 0)
            {
                touchable = UIButton.create("playUp.png", "playDown.png", 0, 0);
            }
            else
            {
                touchable = UIButton.create("optionsUp.png", "optionsDown.png", 0, 0);
            }


            if (i == 1)
            {
                var ch = UIToggleButton.create("cbUnchecked.png", "cbChecked.png", "cbDown.png", 0, 0);
                ch.parentUIObject = touchable;
                ch.pixelsFromRight(0);
                ch.client.name = "TEST THINGY";
                ch.scale       = new Vector3(0.5f, 0.5f, 1);
            }
            else if (i == 4)
            {
                var text = new UIText(textManager, "prototype", "prototype.png");

                var helloText = text.addTextInstance("Child Text", 0, 0, 0.5f, -1, Color.blue, UITextAlignMode.Center, UITextVerticalAlignMode.Middle);
                helloText.parentUIObject = touchable;
                helloText.positionCenter();

                var ch = UIToggleButton.create("cbUnchecked.png", "cbChecked.png", "cbDown.png", 0, 0);
                ch.parentUIObject = helloText;
                ch.pixelsFromRight(-16);
                ch.client.name = "subsub";
                ch.scale       = new Vector3(0.25f, 0.25f, -2);
            }


            // only add a touchUpInside handler for buttons
            if (touchable is UIButton)
            {
                var button = touchable as UIButton;

                // store i locally so we can put it in the closure scope of the touch handler
                var j = i;
                button.onTouchUpInside += (sender) => Debug.Log("touched button: " + j);
            }


            scrollable.addChild(touchable);
        }
        scrollable.endUpdates();
        scrollable.endUpdates();         // this is a bug. it shouldnt need to be called twice



        // add another scrollable
        scrollable = new UIScrollableHorizontalLayout(0);

        // we wrap the addition of all the sprites with a begin updates so it only lays out once when complete
        scrollable.beginUpdates();

        var widthAndHeight = UI.instance.isHD ? 500 : 250;

        scrollable.setSize(widthAndHeight, widthAndHeight);
        scrollable.pagingEnabled = true;

        // paging will snap to the nearest page when scrolling
        scrollable.position = new Vector3((Screen.width - widthAndHeight) / 2, 0, 0);

        for (var i = 0; i < 5; i++)
        {
            var button = UIButton.create("marioPanel.png", "marioPanel.png", 0, 0);
            scrollable.addChild(button);
        }
        scrollable.endUpdates();
        scrollable.endUpdates();         // this is a bug. it shouldnt need to be called twice
    }
Ejemplo n.º 4
0
    void CreateScrollableMenuWithPips()
    {
        m_scrollable = new UIScrollableHorizontalLayout(20);

        // we wrap the addition of all the sprites with a begin updates so it only lays out once when complete
        m_scrollable.beginUpdates();

        // if you plan on making the scrollable wider than the item width you need to set your edgeInsets so that the
        // left + right inset is equal to the extra width you set
        float itemWidth = 250f;
        float leftInset;
        float rightInset;

        leftInset = rightInset = (Screen.width - itemWidth) / 2;

        m_scrollable.edgeInsets = new UIEdgeInsets(0, Mathf.RoundToInt(leftInset), 0, Mathf.RoundToInt(rightInset));

        var scrollerHeight = UI.scaleFactor * itemWidth;
        var scrollerWidth  = UI.scaleFactor * (itemWidth + leftInset + rightInset);                        // item width + 150 extra width

        m_scrollable.setSize(scrollerWidth, scrollerHeight);

        // paging will snap to the nearest page when scrolling
        m_scrollable.pagingEnabled = true;
        m_scrollable.pageWidth     = itemWidth * UI.scaleFactor;

        // center the scrollable horizontally
        m_scrollable.position = new Vector3((Screen.width - scrollerWidth) / 2, -Screen.height + scrollerHeight, 0);

        for (var i = 0; i < 20; i++)
        {
            var button = UIButton.create("marioPanel.png", "marioPanel.png", 0, 0);
            m_scrollable.addChild(button);
        }

        m_scrollable.endUpdates();
        m_scrollable.endUpdates();         // this is a bug. it shouldnt need to be called twice

        //pips
        var pips = new UIRadioButtonGroup(0, UIAbstractContainer.UILayoutType.Horizontal);

        int pageCount = Mathf.CeilToInt(20 * itemWidth / scrollerWidth);

        for (int i = 0; i < pageCount; i++)
        {
            var toggle = UIToggleButton.create("emptyUp.png", "emptyDown.png", "emptyUp.png", 0, 0);

            pips.addChild(toggle);
        }

        pips.beginUpdates();
        float screenUnits = 1.0f / Screen.width;
        float halfWidth   = 140 * pageCount / 2;
        float offset      = halfWidth * screenUnits;

        pips.positionFromCenter(-50 * screenUnits, -offset);
        pips.endUpdates();

        pips.OnSelect += HandlePipsOnSelect;
        pips.IndexOfCurrentlySelected = 1;
    }
    void Start()
    {
        // add two scrollables: one with paging enabled and one without
        var scrollable = new UIScrollableHorizontalLayout(10);

        // we wrap the addition of all the sprites with a begin updates so it only lays out once when complete
        scrollable.beginUpdates();

        var height = UI.scaleFactor * 50f;
        var width  = Screen.width / 1.4f;

        scrollable.setSize(width, height);
        scrollable.position = new Vector3((Screen.width - width) / 2, -Screen.height + height, 0);
        scrollable.zIndex   = 3;

        for (var i = 0; i < 20; i++)
        {
            UITouchableSprite touchable;
            if (i == 4)              // text sprite
            {
                touchable = UIButton.create("emptyUp.png", "emptyDown.png", 0, 0);
            }
            else if (i % 3 == 0)
            {
                touchable = UIToggleButton.create("cbUnchecked.png", "cbChecked.png", "cbDown.png", 0, 0);
            }
            else if (i % 2 == 0)
            {
                touchable = UIButton.create("playUp.png", "playDown.png", 0, 0);
            }
            else
            {
                touchable = UIButton.create("optionsUp.png", "optionsDown.png", 0, 0);
            }

            if (i == 1)
            {
                var ch = UIToggleButton.create("cbUnchecked.png", "cbChecked.png", "cbDown.png", 0, 0);
                ch.parentUIObject = touchable;
                ch.pixelsFromRight(0);
                ch.client.name = "TEST THINGY";
                ch.scale       = new Vector3(0.5f, 0.5f, 1);
            }
            else if (i == 4)
            {
                var text = new UIText(textManager, "prototype", "prototype.png");

                var helloText = text.addTextInstance("Child Text", 0, 0, 0.5f, -1, Color.blue, UITextAlignMode.Center, UITextVerticalAlignMode.Middle);
                helloText.parentUIObject = touchable;
                helloText.positionCenter();

                var ch = UIToggleButton.create("cbUnchecked.png", "cbChecked.png", "cbDown.png", 0, 0);
                ch.parentUIObject = helloText;
                ch.pixelsFromRight(-16);
                ch.client.name = "subsub";
                ch.scale       = new Vector3(0.25f, 0.25f, -2);
            }


            // only add a touchUpInside handler for buttons
            if (touchable is UIButton)
            {
                var button = touchable as UIButton;

                // store i locally so we can put it in the closure scope of the touch handler
                var j = i;
                button.onTouchUpInside += (sender) => Debug.Log("touched button: " + j);
            }

            // add random spacers every so often
            if (i % 3 == 0)
            {
                scrollable.addChild(new UISpacer(Random.Range(10, 100), 40));
            }

            scrollable.addChild(touchable);
        }
        scrollable.endUpdates();
        scrollable.endUpdates();         // this is a bug. it shouldnt need to be called twice



        // add another scrollable, this one with paging enabled.
        scrollable = new UIScrollableHorizontalLayout(20);

        // we wrap the addition of all the sprites with a begin updates so it only lays out once when complete
        scrollable.beginUpdates();

        height = UI.scaleFactor * 250f;

        // if you plan on making the scrollable wider than the item width you need to set your edgeInsets so that the
        // left + right inset is equal to the extra width you set
        scrollable.edgeInsets = new UIEdgeInsets(0, 75, 0, 75);
        width = UI.scaleFactor * (250f + 150f);           // item width + 150 extra width
        scrollable.setSize(width, height);

        // paging will snap to the nearest page when scrolling
        scrollable.pagingEnabled = true;
        scrollable.pageWidth     = 250f * UI.scaleFactor;

        // center the scrollable horizontally
        scrollable.position = new Vector3((Screen.width - width) / 2, 0, 0);

        for (var i = 0; i < 5; i++)
        {
            var button = UIButton.create("marioPanel.png", "marioPanel.png", 0, 0);
            scrollable.addChild(button);
        }

        scrollable.endUpdates();
        scrollable.endUpdates();         // this is a bug. it shouldnt need to be called twice
    }
    void Start()
    {
        // add two scrollables: one with paging enabled and one without
        var scrollable = new UIScrollableHorizontalLayout( 10 );

        // we wrap the addition of all the sprites with a begin updates so it only lays out once when complete
        scrollable.beginUpdates();

        var height = UI.scaleFactor * 50f;
        var width = Screen.width / 1.4f;
        scrollable.setSize( width, height );
        scrollable.position = new Vector3( ( Screen.width - width ) / 2, -Screen.height + height, 0 );
        scrollable.zIndex = 3;

        for( var i = 0; i < 20; i++ )
        {
            UITouchableSprite touchable;
            if( i == 4 ) // text sprite
            {
                touchable = UIButton.create( "emptyUp.png", "emptyDown.png", 0, 0 );
            }
            else if( i % 3 == 0 )
            {
                touchable = UIToggleButton.create( "cbUnchecked.png", "cbChecked.png", "cbDown.png", 0, 0 );
            }
            else if( i % 2 == 0 )
            {
                touchable = UIButton.create( "playUp.png", "playDown.png", 0, 0 );
            }
            else
            {
                touchable = UIButton.create( "optionsUp.png", "optionsDown.png", 0, 0 );
            }

            if( i == 1 )
            {
                var ch = UIToggleButton.create( "cbUnchecked.png", "cbChecked.png", "cbDown.png", 0, 0 );
                ch.parentUIObject = touchable;
                ch.pixelsFromRight( 0 );
                ch.client.name = "TEST THINGY";
                ch.scale = new Vector3( 0.5f, 0.5f, 1 );
            }
            else if( i % 4==0 )
            {
                var text = new UIText( textManager, "prototype", "prototype.png" );

                var helloText = text.addTextInstance( "Child Text", 0, 0,0.5f,-1,Color.blue,UITextAlignMode.Center,UITextVerticalAlignMode.Middle );
                helloText.parentUIObject = touchable;
                helloText.positionCenter();

                var ch = UIToggleButton.create( "cbUnchecked.png", "cbChecked.png", "cbDown.png", 0, 0 );
                ch.parentUIObject = helloText;
                ch.pixelsFromRight( -16 );
                ch.client.name = "subsub";
                ch.scale = new Vector3( 0.25f, 0.25f, -2 );
            }

            // only add a touchUpInside handler for buttons
            if( touchable is UIButton )
            {
                var button = touchable as UIButton;

                // store i locally so we can put it in the closure scope of the touch handler
                var j = i;
                button.onTouchUpInside += ( sender ) => Debug.Log( "touched button: " + j );
            }

            // add random spacers every so often
            if( i % 3 == 0 )
                scrollable.addChild( new UISpacer( Random.Range( 10, 100 ), 40 ) );

            scrollable.addChild( touchable );
        }
        scrollable.endUpdates();
        scrollable.endUpdates(); // this is a bug. it shouldnt need to be called twice

        // add another scrollable, this one with paging enabled.
        scrollable = new UIScrollableHorizontalLayout( 20 );

        // we wrap the addition of all the sprites with a begin updates so it only lays out once when complete
        scrollable.beginUpdates();

        height = UI.scaleFactor * 250f;

        // if you plan on making the scrollable wider than the item width you need to set your edgeInsets so that the
        // left + right inset is equal to the extra width you set
        scrollable.edgeInsets = new UIEdgeInsets( 0, 75, 0, 75 );
        width = UI.scaleFactor * ( 250f + 150f ); // item width + 150 extra width
        scrollable.setSize( width, height );

        // paging will snap to the nearest page when scrolling
        scrollable.pagingEnabled = true;
        scrollable.pageWidth = 250f * UI.scaleFactor;

        // center the scrollable horizontally
        scrollable.position = new Vector3( ( Screen.width - width ) / 2, 0, 0 );

        for( var i = 0; i < 5; i++ )
        {
            var button = UIButton.create( "marioPanel.png", "marioPanel.png", 0, 0 );
            scrollable.addChild( button );
        }

        scrollable.endUpdates();
        scrollable.endUpdates(); // this is a bug. it shouldnt need to be called twice
    }
    void Start()
    {
        // add two scrollables: one with pageing enabled
        var scrollable = new UIScrollableHorizontalLayout( 10 );

        // we wrap the addition of all the sprites with a begin updates so it only lays out once when complete
        scrollable.beginUpdates();

        var height = UI.instance.isHD ? 150 : 300;
        var width = Screen.width / 1.4f;
        scrollable.setSize( width, height );
        scrollable.position = new Vector3( ( Screen.width - width ) / 2, -Screen.height + height, 0 );
        scrollable.zIndex = 3;

        for( var i = 0; i < 20; i++ )
        {
            UITouchableSprite touchable;
            if( i == 4 ) // text sprite
            {
                touchable = UIButton.create( "emptyUp.png", "emptyDown.png", 0, 0 );
            }
            else if( i % 3 == 0 )
            {
                touchable = UIToggleButton.create( "cbUnchecked.png", "cbChecked.png", "cbDown.png", 0, 0 );
            }
            else if( i % 2 == 0 )
            {
                touchable = UIButton.create( "playUp.png", "playDown.png", 0, 0 );
            }
            else
            {
                touchable = UIButton.create( "optionsUp.png", "optionsDown.png", 0, 0 );
            }

            if( i == 1 )
            {
                var ch = UIToggleButton.create( "cbUnchecked.png", "cbChecked.png", "cbDown.png", 0, 0 );
                ch.parentUIObject = touchable;
                ch.pixelsFromRight( 0 );
                ch.client.name = "TEST THINGY";
                ch.scale = new Vector3( 0.5f, 0.5f, 1 );
            }
            else if( i == 4 )
            {
                var text = new UIText( textManager, "prototype", "prototype.png" );

                var helloText = text.addTextInstance( "Child Text", 0, 0,0.5f,-1,Color.blue,UITextAlignMode.Center,UITextVerticalAlignMode.Middle );
                helloText.parentUIObject = touchable;
                helloText.positionCenter();

                var ch = UIToggleButton.create( "cbUnchecked.png", "cbChecked.png", "cbDown.png", 0, 0 );
                ch.parentUIObject = helloText;
                ch.pixelsFromRight( -16 );
                ch.client.name = "subsub";
                ch.scale = new Vector3( 0.25f, 0.25f, -2 );
            }

            // only add a touchUpInside handler for buttons
            if( touchable is UIButton )
            {
                var button = touchable as UIButton;

                // store i locally so we can put it in the closure scope of the touch handler
                var j = i;
                button.onTouchUpInside += ( sender ) => Debug.Log( "touched button: " + j );
            }

            scrollable.addChild( touchable );
        }
        scrollable.endUpdates();
        scrollable.endUpdates(); // this is a bug. it shouldnt need to be called twice

        // add another scrollable
        scrollable = new UIScrollableHorizontalLayout( 0 );

        // we wrap the addition of all the sprites with a begin updates so it only lays out once when complete
        scrollable.beginUpdates();

        var widthAndHeight = UI.instance.isHD ? 500 : 250;
        scrollable.setSize( widthAndHeight, widthAndHeight );
        scrollable.pagingEnabled = true;

        // paging will snap to the nearest page when scrolling
        scrollable.position = new Vector3( ( Screen.width - widthAndHeight ) / 2, 0, 0 );

        for( var i = 0; i < 5; i++ )
        {
            var button = UIButton.create( "marioPanel.png", "marioPanel.png", 0, 0 );
            scrollable.addChild( button );
        }
        scrollable.endUpdates();
        scrollable.endUpdates(); // this is a bug. it shouldnt need to be called twice
    }