public void Render(RenderHelper renderHelper) { ComponentManager cm = ComponentManager.GetInstance(); bool anyActive = false; //Buttons foreach (var but in cm.GetComponentsOfType <MenuButtonComponent>()) { MenuButtonComponent button = (MenuButtonComponent)but.Value; if (button.IsActive) { if (button.Ishighlighted == false) { renderHelper.Draw(button.NormalTexture, button.Position, button.Layer); } else if (button.Ishighlighted == true) { renderHelper.Draw(button.HighlightTexture, button.Position, button.Layer); } anyActive = true; } } //Backgrounds foreach (var background in cm.GetComponentsOfType <MenuBackgroundComponent>()) { MenuBackgroundComponent backgroundComp = (MenuBackgroundComponent)background.Value; if (backgroundComp.IsActive) { if (backgroundComp.HasFadingEffect) { Rectangle containerRect = new Rectangle( backgroundComp.Position.X, backgroundComp.Position.Y, renderHelper.graphicsDevice.Viewport.TitleSafeArea.Width * 2, renderHelper.graphicsDevice.Viewport.TitleSafeArea.Width * 2 ); renderHelper.Draw(backgroundComp.Texture, containerRect, new Color(255f, 255f, 255f, (byte)MathHelper.Clamp(backgroundComp.mAlphaValue, 0, 255)), RenderLayer.Menubackground); } else if (backgroundComp.HasMovingEffect) { Rectangle containerRect = new Rectangle( backgroundComp.Position.X, backgroundComp.Position.Y, renderHelper.graphicsDevice.Viewport.TitleSafeArea.Width * 2, renderHelper.graphicsDevice.Viewport.TitleSafeArea.Width * 2 ); renderHelper.Draw(backgroundComp.Texture, containerRect, Color.White, RenderLayer.Menubackground); } anyActive = true; } } //Title foreach (var entity in cm.GetComponentsOfType <MenuTitleComponent>()) { if (anyActive) { renderHelper.Draw(((MenuTitleComponent)entity.Value).Texture, ((MenuTitleComponent)entity.Value).Position, ((MenuTitleComponent)entity.Value).Layer); } } }
private void ClearMenu() { if (GameStateManager.GetInstance().State != GameState.Menu) { ComponentManager cm = ComponentManager.GetInstance(); // Buttons foreach (var button in cm.GetComponentsOfType <MenuButtonComponent>()) { MenuButtonComponent buttonComp = (MenuButtonComponent)button.Value; buttonComp.IsActive = false; buttonComp.Ishighlighted = false; } //Backgrounds foreach (var background in cm.GetComponentsOfType <MenuButtonComponent>()) { MenuButtonComponent backgroundComp = (MenuButtonComponent)background.Value; backgroundComp.IsActive = false; } } }
public void CreateButton(MenuButtonItem item) { if (item == null) { return; } GameObject buttonObj = (GameObject)Instantiate(defaultButton); buttonObj.transform.SetParent(transform); buttonObj.SetActive(true); buttonObj.GetComponent <MenuButton>().onClick.AddListener(() => { item.GetClick(); menuButtonView.CloseWindow(); }); buttonObj.GetComponent <MenuButton>().action = () => { ClearChild(); if (item.GetChilds() != null && item.GetChilds().Count != 0) { GameObject viewObj = menuButtonView.CreateComponent(item, buttonObj.transform); childView = viewObj.GetComponent <MenuButtonComponent>(); viewObj.GetComponent <MenuButtonComponent>().SetPostion(new Vector2(buttonObj.GetComponent <RectTransform>().sizeDelta.x, 0)); } }; buttonObj.GetComponentInChildren <Text>().text = item.buttonName; buttonObj.name = item.buttonName; if (item.hasLine) { GameObject line = (GameObject)Instantiate(lineObj); line.transform.SetParent(transform); line.SetActive(true); } if (item.enableCheckEvent != null && !item.enableCheckEvent.Invoke()) { buttonObj.GetComponent <MenuButton>().interactable = false; } }
public void Load(ContentManager content) { ComponentManager cm = ComponentManager.GetInstance(); //Buttons foreach (var entity in cm.GetComponentsOfType <MenuButtonComponent>()) { MenuButtonComponent buttonComp = (MenuButtonComponent)entity.Value; buttonComp.NormalTexture = content.Load <Texture2D>(buttonComp.NormalTexturePath); buttonComp.HighlightTexture = content.Load <Texture2D>(buttonComp.HighlightTexturePath); } //Backgrounds foreach (var entity in cm.GetComponentsOfType <MenuBackgroundComponent>()) { MenuBackgroundComponent backComp = (MenuBackgroundComponent)entity.Value; backComp.Texture = content.Load <Texture2D>(backComp.TexturePath); } //Title foreach (var entity in cm.GetComponentsOfType <MenuTitleComponent>()) { ((MenuTitleComponent)entity.Value).Texture = content.Load <Texture2D>(((MenuTitleComponent)entity.Value).TexturePath); } }
// Initializes Menu buttons private void ActivateMenuButtons() { if (GameStateManager.GetInstance().State == GameState.Menu) { ComponentManager cm = ComponentManager.GetInstance(); ActiveButtonsList = new List <int>(); //Set buttons to "active" and add them to the buttonList var menuButtonComps = cm.GetComponentsOfType <MenuButtonComponent>(); foreach (var button in menuButtonComps) { MenuButtonComponent buttonComp = (MenuButtonComponent)button.Value; switch (MenuStateManager.GetInstance().State) { case MenuState.MainMenu: if (buttonComp.Type == MenuButtonType.MainMenuButton) { buttonComp.IsActive = true; } else { buttonComp.IsActive = false; } break; case MenuState.PauseMainMenu: if (buttonComp.Type == MenuButtonType.PauseMainMenuButton) { buttonComp.IsActive = true; } else { buttonComp.IsActive = false; } break; case MenuState.None: buttonComp.IsActive = false; break; } if (buttonComp.IsActive) { ActiveButtonsList.Add(button.Key); //ActiveButtonsList.Insert(buttonComp.OrderPosition, button.Key); } } if (ActiveButtonsList.Count > 0 && cm.GetComponentForEntity <MenuButtonComponent>(ActiveButtonsList[0]).OrderPosition != 0) { ActiveButtonsList.Reverse(); } int checkButtons = 0; foreach (var button in ActiveButtonsList) { if (cm.GetComponentForEntity <MenuButtonComponent>(button).Ishighlighted) { checkButtons++; } } if (ActiveButtonsList.Count > 0 && checkButtons <= 0) { SelectedButton = 0; cm.GetComponentForEntity <MenuButtonComponent>(ActiveButtonsList[0]).Ishighlighted = true; } } }