/// <summary> /// Lisää kontrollin constrainien perusteella oikealle paikalle /// Asettelee komponentit uudelleen jos tulevat päällekkäin /// </summary> /// <param name="controlManager">Mihin controlmanageriin lisätään</param> /// <param name="controlToAdd">Mikä kontrolli lisätään</param> /// <param name="constraints">Mihin paikkaan layoutissa (Center, Left, Right, Up, Down)</param> public override void Add(ControlManager controlManager, Control controlToAdd, ILayoutConstraints constraints) { if (constraints != null && constraints is BorderLayoutConstraint) { BorderLayoutConstraint constraint = (constraints as BorderLayoutConstraint); invokeList[constraint.Direction].Invoke(controlToAdd, constraint); controlManager.AddControl(controlToAdd); ReAlignCenter(); } }
/// <summary> /// Lisää uuden kontrollin. /// </summary> /// <param name="control">kontrolli joka lisätään.</param> /// <param name="constraints">kontrollin paikka minne lisätään (jos layout käytössä).</param> public void AddControl(Control control, ILayoutConstraints constraints) { // Ei ole absolute. if (Layout != null) { Layout.Add(controlManager, control, constraints); } else { controlManager.AddControl(control); } }
public GameForm(Form parent) { parentForm = parent; //parent.Hide(); InitializeComponent(); level = new Level(this, new LevelDecoder(@"C:\Users\Markus_PC\Desktop\Lvl.jan", 512, 512)); controlManager = new ControlManager(level.RendererPanel); GameLabel label = new GameLabel(0, "Pac-Man", 50, Color.Gold); label.Location = new Point(10, 10); controlManager.OnControlClick += ControlManager_OnControlClick; controlManager.AddControl(label); controlManager.Initialize(); audioPlayer = new AudioPlayer(); audioPlayer.MusicPlayer.PlayNext(); Show(); }
public MainMenuState() : base() { _ControlManager = new ControlManagerComponent(this); SpriteFont font = CorvusGame.Instance.GlobalContent.Load <SpriteFont>("Fonts/MainMenuFont"); Image bgImg = new Image(CorvusGame.Instance.GlobalContent.Load <Texture2D>("Interface/TitleScreenBackground")); bgImg.Size = new Vector2(UIHelper.Viewport.Width, UIHelper.Viewport.Height); ControlManager.AddControl(bgImg); Image titleImg = new Image(CorvusGame.Instance.GlobalContent.Load <Texture2D>("Interface/TitleText")); titleImg.Position = UIHelper.AlignControl(titleImg.Size, HorizontalAlignment.Center, VerticalAlignment.Top) + new Vector2(0, (UIHelper.Viewport.Height / 2) * 0.1f);; ControlManager.AddControl(titleImg); var hackSize = new Vector2(175f, 50f); // a hack to align things. LinkButton continueBtn = new LinkButton(font); continueBtn.Text = "Continue"; continueBtn.Color = Color.Black; continueBtn.IsVisible = false; //TODO: Will need to hide this if there is no saved state. continueBtn.IsEnabled = false; continueBtn.Position = UIHelper.AlignControl(hackSize, HorizontalAlignment.Center, VerticalAlignment.Center) + new Vector2(0, 50f); continueBtn.Selected += continueBtn_Selected; ControlManager.AddControl(continueBtn); LinkButton newGameBtn = new LinkButton(font); newGameBtn.Text = "New Game"; newGameBtn.Color = Color.Black; newGameBtn.Position = UIHelper.AlignControl(hackSize, HorizontalAlignment.Center, VerticalAlignment.Center) + new Vector2(0, 100f); newGameBtn.Selected += newGameBtn_Selected; ControlManager.AddControl(newGameBtn); LinkButton arenaModeBtn = new LinkButton(font); arenaModeBtn.Text = "Arena Mode"; arenaModeBtn.Color = Color.Black; arenaModeBtn.Position = UIHelper.AlignControl(hackSize, HorizontalAlignment.Center, VerticalAlignment.Center) + new Vector2(0, 150f); arenaModeBtn.Selected += arenaModeBtn_Selected; ControlManager.AddControl(arenaModeBtn); LinkButton exitBtn = new LinkButton(font); exitBtn.Text = "Exit"; exitBtn.Color = Color.Black; exitBtn.Position = UIHelper.AlignControl(hackSize, HorizontalAlignment.Center, VerticalAlignment.Center) + new Vector2(0, 200f); exitBtn.Selected += exitBtn_Selected; ControlManager.AddControl(exitBtn); #if DEBUG LinkButton testModeBtn = new LinkButton(font); testModeBtn.Text = "Test Mode"; testModeBtn.Color = Color.Black; testModeBtn.IsEnabled = true; testModeBtn.Position = UIHelper.AlignControl(hackSize, HorizontalAlignment.Center, VerticalAlignment.Center) + new Vector2(0, 250f); testModeBtn.Selected += testModeBtn_Selected; ControlManager.AddControl(testModeBtn); #endif ControlManager.SetFocus(); this.AddComponent(_ControlManager); }
public void AddControl(string keyPress, string controlDirection) { _controlInputs += 1; // Add Controls _controlDisplay.SetNumberOfControls(_controlInputs - 1); if (controlDirection == "Down") { _controlManager.AddControl(keyPress, controlDirection); if (this.downInput != null) { this.downInputs.Add(keyPress); // Add to list } else { this.downInput = keyPress; // Set as current this.downInputs.Add(keyPress); } } if (controlDirection == "Right") { _controlManager.AddControl(keyPress, controlDirection); if (this.rightInput != null) { this.rightInputs.Add(keyPress); // Add to list } else { this.rightInput = keyPress; this.rightInputs.Add(keyPress); } } if (controlDirection == "Up") { _controlManager.AddControl(keyPress, controlDirection); if (this.upInput != null) { this.upInputs.Add(keyPress); // Add to list } else { this.upInput = keyPress; this.upInputs.Add(keyPress); } } if (controlDirection == "Left") { _controlManager.AddControl(keyPress, controlDirection); if (this.leftInput != null) { this.leftInputs.Add(keyPress); // Add to list } else { this.leftInput = keyPress; this.leftInputs.Add(keyPress); } } //Debug.Log(keyPress + controlDirection); }
private void SetUpUIControls() { // Manager Setup if (m_uiControlManager == null) { m_uiControlManager = new ControlManager(this); } else { m_uiControlManager.Clear(); } Vector2 viewArea = Game.Window.ClientBounds.Size(); Vector2 safeViewStart = viewArea * 0.1f; Vector2 safeViewEnd = viewArea * 0.9f; Vector2 safeViewSize = safeViewEnd - safeViewStart; Rectangle safeViewArea = new Rectangle( (int)safeViewStart.X, (int)safeViewStart.Y, (int)safeViewSize.X, (int)safeViewSize.Y); Vector2 titleSize = m_titleFont.MeasureString(m_titleText); m_titleLocation = safeViewArea.Position(); m_titleLocation.X += (safeViewArea.Width - titleSize.X) / 2f; m_uiControlManager.DrawArea = new Rectangle( (int)safeViewStart.X, (int)(safeViewStart.Y + titleSize.Y + 10), (int)safeViewSize.X, (int)(safeViewSize.Y - (titleSize.Y + 10))); // Set up race track selector m_raceTrackSelector = new FilmStripSelector(m_uiControlManager); m_raceTrackSelector.SelectionChanged += RaceTrackSelector_SelectionChanged; m_raceTrackSelector.ItemWidth = 175; m_raceTrackSelector.ItemHeight = 175; m_raceTrackSelector.Padding = 18; m_raceTrackSelector.MustHaveItemSelected = true; m_raceTrackSelector.ShiftLeftIndicator = m_leftPointerImage; foreach (var trackImage in m_raceTracks) { m_raceTrackSelector.AddItem(trackImage.Tag.ToString(), trackImage); } m_uiControlManager.AddControl(m_raceTrackSelector); // Set up the race cars selector m_raceCarSelector = new FilmStripSelector(m_uiControlManager); m_raceCarSelector.SelectionChanged += RaceCarSelector_SelectionChanged; m_raceCarSelector.ItemWidth = 175; m_raceCarSelector.ItemHeight = 175; m_raceCarSelector.Padding = 18; m_raceCarSelector.MustHaveItemSelected = true; m_raceCarSelector.ShiftLeftIndicator = m_leftPointerImage; foreach (var carType in CarTypes) { m_raceCarSelector.AddItem(carType, m_carImages[carType] as Texture2D, -MathHelper.PiOver2); } m_uiControlManager.AddControl(m_raceCarSelector); // Set up player action selector m_actionSelector = new FilmStripSelector(m_uiControlManager); m_actionSelector.ItemWidth = 175; m_actionSelector.ItemHeight = 80; m_actionSelector.Padding = 8; m_actionSelector.MustHaveItemSelected = true; m_actionSelector.ShiftLeftIndicator = m_leftPointerImage; m_actionSelector.TextFont = m_uiFont; m_actionSelector.AddItem("Play", "Start Racing"); m_actionSelector.AddItem("Exit", "Exit Game"); m_actionSelector.AddItem("Credits", "Roll Credits"); m_uiControlManager.AddControl(m_actionSelector); }