public void RemoveChild(CCMenuItem menuItem, bool cleanup) { if (SelectedMenuItem == menuItem) { SelectedMenuItem = null; } base.RemoveChild(menuItem, cleanup); menuItems.Remove(menuItem); }
protected override void AddedToScene() { base.AddedToScene(); var label = new CCLabelBMFont("Enable AtlasItem", "fonts/bitmapFontTest3.fnt"); var item1 = new CCMenuItemLabelBMFont(label, this.menuCallback2); CCMenuItemFont.FontSize = 28; CCMenuItemFont.FontName = "arial"; var item2 = new CCMenuItemFont("--- Go Back ---", this.menuCallback); // We do not have an HD version of the menuitemsprite so internally CocosSharp tries to convert our // rectangle coordinates passed to work with HD images so the coordinates are off. We will just // modify this here to make sure we have the correct sizes when they are passed. var spriteNormal = new CCSprite(s_MenuItem, new CCRect(0, 23 * 2, 115, 23)); var spriteSelected = new CCSprite(s_MenuItem, new CCRect(0, 23 * 1, 115, 23)); var spriteDisabled = new CCSprite(s_MenuItem, new CCRect(0, 23 * 0, 115, 23)); var item3 = new CCMenuItemImage(spriteNormal, spriteSelected, spriteDisabled, this.menuCallback3); m_disabledItem = item3; m_disabledItem.Enabled = false; var menu = new CCMenu(item1, item2, item3); menu.Position = new CCPoint(0, 0); var s = Layer.VisibleBoundsWorldspace.Size; item1.Position = new CCPoint(s.Width / 2 - 150, s.Height / 2); item2.Position = new CCPoint(s.Width / 2 - 200, s.Height / 2); item3.Position = new CCPoint(s.Width / 2, s.Height / 2 - 100); var jump = new CCJumpBy (3, new CCPoint(400, 0), 50, 4); item2.RepeatForever(jump, jump.Reverse()); var spin1 = new CCRotateBy (3, 360); item1.RepeatForever(spin1); item2.RepeatForever(spin1); item3.RepeatForever(spin1); AddChild(menu); }
public TestController() { // Add close menu closeMenuItem = new CCMenuItemImage(TestResource.s_pPathClose, TestResource.s_pPathClose, CloseCallback); closeMenu = new CCMenu(closeMenuItem); CCMenuItemFont.FontName = "MarkerFelt"; CCMenuItemFont.FontSize = 22; #if !PSM && !WINDOWS_PHONE #if NETFX_CORE versionLabel = new CCLabel("v" + this.GetType().GetAssemblyName().Version.ToString(), "arial", 30); #else versionLabel = new CCLabel("v" + this.GetType().Assembly.GetName().Version.ToString(), "fonts/arial", 24, CCLabelFormat.SpriteFont); #endif AddChild(versionLabel, 20000); #endif // Add test list menu testListMenu = new CCMenu(); var i = 0; foreach (var test in testCases.Keys) { var label = new CCLabel(test, "fonts/arial", 24, CCLabelFormat.SpriteFont); var menuItem = new CCMenuItemLabel(label, MenuCallback); testListMenu.AddChild(menuItem, i++ + MENU_ITEM_Z_ORDER); testListMenuItems.Add(menuItem); } LINE_SPACE = (int)(testListMenuItems[0].ContentSize.Height * 1.5f); #if XBOX || OUYA CCSprite sprite = new CCSprite("Images/aButton"); AddChild(sprite, 10001); menuIndicator = sprite; #endif AddChild(testListMenu); AddChild(closeMenu, 1); }
void TouchMoved(CCTouch touch, CCEvent touchEvent) { Debug.Assert(MenuState == CCMenuState.TrackingTouch, "[Menu TouchMoved] -- invalid state"); CCMenuItem currentItem = ItemForTouch(touch); if (currentItem != SelectedMenuItem) { if (SelectedMenuItem != null) { SelectedMenuItem.Selected = false; } if (currentItem != null) { currentItem.Selected = true; } SelectedMenuItem = currentItem; } }
public TestController() { // Add close menu closeMenuItem = new CCMenuItemImage(TestResource.s_pPathClose, TestResource.s_pPathClose, CloseCallback); closeMenu = new CCMenu(closeMenuItem); CCMenuItemFont.FontName = "MarkerFelt"; CCMenuItemFont.FontSize = 22; #if !PSM && !WINDOWS_PHONE #if NETFX_CORE versionLabel = new CCLabelTtf("v" + this.GetType().GetAssemblyName().Version.ToString(), "arial", 30); #else versionLabel = new CCLabelTtf("v" + this.GetType().Assembly.GetName().Version.ToString(), "arial", 30); #endif AddChild(versionLabel, 20000); #endif // Add test list menu testListMenu = new CCMenu(); for (int i = 0; i < (int)(TestCases.TESTS_COUNT); ++i) { CCLabelTtf label = new CCLabelTtf(Tests.g_aTestNames[i], "arial", 50); CCMenuItem menuItem = new CCMenuItemLabelTTF(label, MenuCallback); testListMenu.AddChild(menuItem, i + MENU_ITEM_Z_ORDER); testListMenuItems.Add(menuItem); } #if XBOX || OUYA CCSprite sprite = new CCSprite("Images/aButton"); AddChild(sprite, 10001); menuIndicator = sprite; #endif AddChild(testListMenu); AddChild(closeMenu, 1); }
public TestNavigationLayer() { TitleLabel = new CCLabel(Title, "arial", 32, CCLabelFormat.SpriteFont); AddChild(TitleLabel, TestScene.TITLE_LEVEL); string subtitleStr = Subtitle; if (!string.IsNullOrEmpty(subtitleStr)) { SubtitleLabel = new CCLabel(subtitleStr, "arial", 16, CCLabelFormat.SpriteFont); SubtitleLabel.AnchorPoint = CCPoint.AnchorMiddleTop; SubtitleLabel.HorizontalAlignment = CCTextAlignment.Center; AddChild(SubtitleLabel, TestScene.TITLE_LEVEL); } backMenuItem = new CCMenuItemImage(TestResource.s_pPathB1, TestResource.s_pPathB2, BackCallback); restartMenuItem = new CCMenuItemImage(TestResource.s_pPathR1, TestResource.s_pPathR2, RestartCallback); nextMenuItem = new CCMenuItemImage(TestResource.s_pPathF1, TestResource.s_pPathF2, NextCallback); navigationMenu = new CCMenu(backMenuItem, restartMenuItem, nextMenuItem); AddChild(navigationMenu, TestScene.MENU_LEVEL); }
public TestNavigationLayer() { TitleLabel = new CCLabelTtf(Title, "arial", 60); TitleLabel.AnchorPoint = new CCPoint(0.5f, 0.5f); AddChild(TitleLabel, TestScene.TITLE_LEVEL); string subtitleStr = Subtitle; if (!string.IsNullOrEmpty(subtitleStr)) { SubtitleLabel = new CCLabelTtf(subtitleStr, "arial", 30); SubtitleLabel.AnchorPoint = new CCPoint(0.5f, 0.5f); AddChild(SubtitleLabel, TestScene.TITLE_LEVEL); } backMenuItem = new CCMenuItemImage(TestResource.s_pPathB1, TestResource.s_pPathB2, BackCallback); restartMenuItem = new CCMenuItemImage(TestResource.s_pPathR1, TestResource.s_pPathR2, RestartCallback); nextMenuItem = new CCMenuItemImage(TestResource.s_pPathF1, TestResource.s_pPathF2, NextCallback); navigationMenu = new CCMenu(backMenuItem, restartMenuItem, nextMenuItem); AddChild(navigationMenu, TestScene.MENU_LEVEL); }
public override void OnEnter() { base.OnEnter(); if (Parent.Tag == Tags.Client) { var label = new CCLabelTtf("Store", "kongtext", 8) { Color = CCColor3B.White, PositionY = 30, PositionX = -5, IsAntialiased = false }; AddChild(label, 10); } // adding shop GUI upgradeHp = new CCMenuItemImage(Resources.GuiIncrease, Resources.GuiIncreaseActive, Resources.GuiIncreaseInactive, UpgradeHp); upgradeHp.AddChild(labelHp); upgradeAttack = new CCMenuItemImage(Resources.GuiIncrease, Resources.GuiIncreaseActive, Resources.GuiIncreaseInactive, UpgradeAttack); upgradeAttack.AddChild(labelAttack); upgradeSpeed = new CCMenuItemImage(Resources.GuiIncrease, Resources.GuiIncreaseActive, Resources.GuiIncreaseInactive, UpgradeSpeed); upgradeSpeed.AddChild(labelSpeed); upgradeClass = new CCMenuItemImage(Resources.GuiIncrease, Resources.GuiIncreaseActive, Resources.GuiIncreaseInactive, UpgradeClass); upgradeClass.AddChild(labelClass); var upgradeMenu = new CCMenu(upgradeHp, upgradeAttack, upgradeSpeed, upgradeClass) { Position = new CCPoint(70, 30), }; upgradeMenu.AlignItemsVertically(); AddChild(upgradeMenu); }
protected virtual CCMenuItem ItemForTouch(CCTouch touch) { CCMenuItem touchedMenuItem = null; CCPoint touchLocation = touch.Location; if (menuItems != null && menuItems.Count > 0) { foreach (CCMenuItem menuItem in menuItems) { if (menuItem != null && menuItem.Visible && menuItem.Enabled) { CCRect r = menuItem.BoundingBoxTransformedToWorld; if (r.ContainsPoint(touchLocation)) { touchedMenuItem = menuItem; break; } } } } return(touchedMenuItem); }
public CCMenu GetMenu(float scale, CCMenuItemLabel[] items) { int position = (int)((1f / items.Length) * .5); int first = position; CCMenuItem[] createdItems = new CCMenuItem[items.Length]; for (int i = 0; i < items.Length; i++) { items[i].Scale = scale; items[i].Position = new CCPoint(wSize.Width / 2, wSize.Height * position); position -= first; } return new CCMenu(createdItems); }
public void AddChild(CCMenuItem menuItem, int zOrder, int tag = 0) { base.AddChild(menuItem, zOrder); menuItems.Add(menuItem); }
public void AddChild(CCMenuItem menuItem) { this.AddChild(menuItem, menuItem.ZOrder); }
public void AddChild(CCMenuItem menuItem, int zOrder, int tag=0) { base.AddChild(menuItem, zOrder); menuItems.Add(menuItem); }