private void createStartScreen() { int buttonsBottomOffset = 130; // Single Player Button UIButton singlePlayerButton = UIButton.create(uiTools, "dieButtonLarge.png", "dieButtonLargeDown.png", 0, 0, 10); singlePlayerButton.pixelsFromBottomLeft(buttonsBottomOffset, 13); UITextInstance singlePlayerText = graph20.addTextInstance("Single\nPlayer", 0, 0); singlePlayerText.parentUIObject = singlePlayerButton; singlePlayerText.pixelsFromTopRight(45, 24); // Multi Player Button UIButton multiPlayerButton = UIButton.create(uiTools, "dieButtonLarge.png", "dieButtonLargeDown.png", 0, 0, 10); multiPlayerButton.pixelsFromBottomRight(buttonsBottomOffset, 50); UITextInstance multiPlayerText = graph20.addTextInstance("Multi\nPlayer", 0, 0); multiPlayerText.parentUIObject = multiPlayerButton; multiPlayerText.pixelsFromTopRight(45, 24); // How To Play Button UIButton howToPlayButton = UIButton.create(uiTools, "howToPlayButton.png", "howToPlayButton.png", 0, 0, 10); howToPlayButton.pixelsFromBottomLeft(0, 5); // Stats Button UIButton statsButton = UIButton.create(uiTools, "statsButton.png", "statsButton.png", 0, 0, 10); statsButton.pixelsFromBottomRight(-10, 0); // Current Games UISprite currentGamesBG = uiTools.addSprite("currentGamesBG.png", 0, 0, 15); currentGamesBG.pixelsFromTop(45); // Current Games Scroller currentGamesLayout = new UIScrollableHorizontalLayout(10); currentGamesLayout.setSize(Screen.width, GUIUtils.hdReturn(90)); currentGamesLayout.parentUIObject = currentGamesBG; currentGamesLayout.pixelsFromBottom(8); // TODO: Add temp games findCurrentGames(); // Parent everything to the startScreenParent UIObject[] objects = { singlePlayerButton, singlePlayerText, multiPlayerButton, multiPlayerText, howToPlayButton, statsButton, currentGamesBG, currentGamesLayout }; foreach (UIObject item in objects) { item.parentUIObject = startScreenParent; } // Move the panel off screen startScreenParent.positionFromTopLeft(0, 1); }
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 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 }
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 }
private void createStartScreen() { int buttonsBottomOffset = 130; // Single Player Button UIButton singlePlayerButton = UIButton.create( uiTools, "dieButtonLarge.png", "dieButtonLargeDown.png", 0, 0, 10 ); singlePlayerButton.pixelsFromBottomLeft( buttonsBottomOffset, 13 ); UITextInstance singlePlayerText = graph20.addTextInstance( "Single\nPlayer", 0, 0 ); singlePlayerText.parentUIObject = singlePlayerButton; singlePlayerText.pixelsFromTopRight( 45, 24 ); // Multi Player Button UIButton multiPlayerButton = UIButton.create( uiTools, "dieButtonLarge.png", "dieButtonLargeDown.png", 0, 0, 10 ); multiPlayerButton.pixelsFromBottomRight( buttonsBottomOffset, 50 ); UITextInstance multiPlayerText = graph20.addTextInstance( "Multi\nPlayer", 0, 0 ); multiPlayerText.parentUIObject = multiPlayerButton; multiPlayerText.pixelsFromTopRight( 45, 24 ); // How To Play Button UIButton howToPlayButton = UIButton.create( uiTools, "howToPlayButton.png", "howToPlayButton.png", 0, 0, 10 ); howToPlayButton.pixelsFromBottomLeft( 0, 5 ); // Stats Button UIButton statsButton = UIButton.create( uiTools, "statsButton.png", "statsButton.png", 0, 0, 10 ); statsButton.pixelsFromBottomRight( -10, 0 ); // Current Games UISprite currentGamesBG = uiTools.addSprite( "currentGamesBG.png", 0, 0, 15 ); currentGamesBG.pixelsFromTop( 45 ); // Current Games Scroller currentGamesLayout = new UIScrollableHorizontalLayout( 10 ); currentGamesLayout.setSize( Screen.width, GUIUtils.hdReturn( 90 ) ); currentGamesLayout.parentUIObject = currentGamesBG; currentGamesLayout.pixelsFromBottom( 8 ); // TODO: Add temp games findCurrentGames(); // Parent everything to the startScreenParent UIObject[] objects = { singlePlayerButton, singlePlayerText, multiPlayerButton, multiPlayerText, howToPlayButton, statsButton, currentGamesBG, currentGamesLayout }; foreach (UIObject item in objects) { item.parentUIObject = startScreenParent; } // Move the panel off screen startScreenParent.positionFromTopLeft( 0, 1 ); }