public void SwitchMode() { switch (gameState.CurrentGameMode) { case GameState.GameMode.Add: modeLabel.Text = "Add Mode:"; modeRadio1.Text = "Single"; modeRadio2.Text = "Line"; modeRadio2.Enabled = true; modeStatusLabel = "Add "; gameState.ResetState(); break; case GameState.GameMode.Edit: modeLabel.Text = "Edit Mode:"; modeRadio1.Text = "Single"; modeRadio2.Text = "Multiple"; modeRadio2.Enabled = false; modeStatusLabel = "Edit "; gameState.ResetState(); break; case GameState.GameMode.Play: modeLabel.Text = "Play Mode:"; // Move the cross hair cursor to the center of the screen at the start of // the game play crossHairPoint = new Point(State.Width / 2, State.Height / 2); // Disable certain radio buttons during the Play mode ModeChoiceEnabled = false; modeRadio1.DoClick(); break; } }
/// <summary> /// Handles state changed events. /// </summary> /// <param name="source"></param> private void HandleStateChanged(object source) { G2DComponent comp = (G2DComponent)source; if (comp is G2DSlider) { sliderRadio.DoClick(); label = "Slider value is " + ((G2DSlider)comp).Value; rotationRate = ((G2DSlider)comp).Value * 0.2f; } }
public void Initialize(Scene scene, ActionPerformed gameListener, ActionPerformed modeListener) { // Create the main panel which holds all other GUI components frame = new G2DPanel(); frame.Bounds = new Rectangle(30, 305, 480, 280); frame.Border = GoblinEnums.BorderFactory.LineBorder; frame.Transparency = 0.7f; // Ranges from 0 (fully transparent) to 1 (fully opaque) frame.TextTransparency = 1.0f; uiFont = State.Content.Load <SpriteFont>("UIFont"); G2DLabel gameLabel = new G2DLabel("Game Mode:"); gameLabel.TextFont = uiFont; gameLabel.Bounds = new Rectangle(4, 4, 100, 48); // Create radio buttons for selecting the game mode gameAdd = new G2DRadioButton("Add"); gameAdd.TextFont = uiFont; gameAdd.Bounds = new Rectangle(18, 70, 150, 50); // Make the Addition mode as the selected one first gameAdd.DoClick(); gameEdit = new G2DRadioButton("Edit"); gameEdit.TextFont = uiFont; gameEdit.Bounds = new Rectangle(170, 70, 150, 50); gamePlay = new G2DRadioButton("Play"); gamePlay.TextFont = uiFont; gamePlay.Bounds = new Rectangle(310, 70, 150, 50); ButtonGroup gameGroup = new ButtonGroup(); gameGroup.Add(gameAdd); gameGroup.Add(gameEdit); gameGroup.Add(gamePlay); gameGroup.AddActionPerformedHandler(gameListener); frame.AddChild(gameLabel); frame.AddChild(gameAdd); frame.AddChild(gameEdit); frame.AddChild(gamePlay); G2DSeparator separator1 = new G2DSeparator(); separator1.Bounds = new Rectangle(5, 129, 470, 5); frame.AddChild(separator1); modeLabel = new G2DLabel("Add Mode:"); modeLabel.TextFont = uiFont; modeLabel.Bounds = new Rectangle(4, 140, 100, 48); modeRadio1 = new G2DRadioButton("Single"); modeRadio1.TextFont = uiFont; modeRadio1.Bounds = new Rectangle(20, 206, 200, 50); modeRadio1.DoClick(); modeRadio2 = new G2DRadioButton("Line"); modeRadio2.TextFont = uiFont; modeRadio2.Bounds = new Rectangle(220, 206, 250, 50); ButtonGroup addGroup = new ButtonGroup(); addGroup.Add(modeRadio1); addGroup.Add(modeRadio2); addGroup.AddActionPerformedHandler(modeListener); frame.AddChild(modeLabel); frame.AddChild(modeRadio1); frame.AddChild(modeRadio2); // Initially, make the GUI panel invisible frame.Visible = false; frame.Enabled = false; scene.UIRenderer.Add2DComponent(frame); }
private void Create2DGUI() { // Create the main panel which holds all other GUI components G2DPanel frame = new G2DPanel(); frame.Bounds = new Rectangle(325, State.Height - 180, 150, 170); frame.Border = GoblinEnums.BorderFactory.LineBorder; frame.Transparency = 0.7f; // Ranges from 0 (fully transparent) to 1 (fully opaque) label = "User Interfaces"; // Loads the fonts used for rendering UI labels and slider labels uiFont = Content.Load <SpriteFont>("UIFont"); sliderFont = Content.Load <SpriteFont>("SliderFont"); // Create four Radio Buttons G2DRadioButton radio1 = new G2DRadioButton("User Interfaces"); radio1.TextFont = uiFont; radio1.Bounds = new Rectangle(10, 5, 80, 20); radio1.DoClick(); // make this radio button selected initially radio1.ActionPerformedEvent += new ActionPerformed(HandleActionPerformed); G2DRadioButton radio2 = new G2DRadioButton("Computer Graphics"); radio2.TextFont = uiFont; radio2.Bounds = new Rectangle(10, 25, 80, 20); radio2.ActionPerformedEvent += new ActionPerformed(HandleActionPerformed); G2DRadioButton radio3 = new G2DRadioButton("Augmented Reality"); radio3.TextFont = uiFont; radio3.Bounds = new Rectangle(10, 45, 80, 20); radio3.ActionPerformedEvent += new ActionPerformed(HandleActionPerformed); sliderRadio = new G2DRadioButton("Slider Control"); sliderRadio.TextFont = uiFont; sliderRadio.Bounds = new Rectangle(10, 65, 80, 20); sliderRadio.ActionPerformedEvent += new ActionPerformed(HandleActionPerformed); // Create a slider G2DSlider slider = new G2DSlider(); slider.TextFont = sliderFont; slider.Bounds = new Rectangle(5, 100, 140, 30); slider.Maximum = 40; slider.MajorTickSpacing = 20; slider.MinorTickSpacing = 5; slider.PaintTicks = true; slider.PaintLabels = true; slider.StateChangedEvent += new StateChanged(HandleStateChanged); // Create a ButtonGroup object which controls the radio // button selections ButtonGroup group = new ButtonGroup(); group.Add(radio1); group.Add(radio2); group.Add(radio3); group.Add(sliderRadio); // Create a Button G2DButton button = new G2DButton("I Love"); button.TextFont = uiFont; button.Bounds = new Rectangle(50, 145, 50, 20); button.ActionPerformedEvent += new ActionPerformed(HandleActionPerformed); // Add all of the components to the main panel frame.AddChild(radio1); frame.AddChild(radio2); frame.AddChild(radio3); frame.AddChild(sliderRadio); frame.AddChild(button); frame.AddChild(slider); scene.UIRenderer.Add2DComponent(frame); }