private void OpenOptionsList() { var optionsScreen = new UIScreen(game1) { ScreenBelowVisible = true, EscapeCloses = true, BackgroundColor = Color.Black * 0.5f }; var optionsStack = new StackPanel(game1) { MainNavigation = true }; var scroller = new ScrollPanel(game1) { HAnchor = HorizontalAnchor.Middle, VAnchor = VerticalAnchor.Middle, Child = optionsStack }; optionsScreen.Children.Add(scroller); for (int i = 0; i < Options.Count; i++) { var optionPanel = new Button(game1) { Text = Options[i].DisplayText }; if (i == Selected) { optionPanel.HasFocus = true; optionsStack.Selection = i; } optionsStack.Children.Add(optionPanel); int num = i; optionPanel.OnClick += (sender, e) => { Selected = num; game1.UI.CloseTopScreen(); }; } optionsScreen.UpdateLayout(optionsScreen.Bounds); game1.UI.OpenScreen(optionsScreen); }
/// <summary> /// A screen for changing the options /// </summary> /// <param name="game"></param> /// <returns></returns> public static UIScreen DifficultySelectScreen(Game game) { Game1 g1 = (Game1)game; var retVal = new UIScreen(game) { Purpose = ScreenPurpose.Options }; retVal.Escape += (sender, e) => { g1.UI.CloseTopScreen(); }; var spLabel = new StackPanel(game) { HAnchor = HorizontalAnchor.Middle, VAnchor = VerticalAnchor.Middle, SpriteBackground = true, Border = 4 }; retVal.Children.Add(spLabel); var optionsLabel = new TextPanel(game) { Text = "New game", Width = 128, SpriteBackground = false }; spLabel.Children.Add(optionsLabel); var spMenu = new StackPanel(game) { HAnchor = HorizontalAnchor.Middle, VAnchor = VerticalAnchor.Middle, MainNavigation = true }; spLabel.Children.Add(spMenu); var difficulty = new StackPanel(game) { Direction = LayoutDirection.Horizontal, HAnchor = HorizontalAnchor.Middle, ChildrenShareFocus = true, SpriteBackground = true, Border = 4 }; spMenu.Children.Add(difficulty); var diffLabel = new TextPanel(game) { Text = "Difficulty", Width = 32, SpriteBackground = false }; difficulty.Children.Add(diffLabel); var diffSlide = new Slider(game) { Value = 0, Minimum = 0, Maximum = 20, IncrementSize = 1 }; diffSlide.ValueChanged += (sender, e) => { }; difficulty.Children.Add(diffSlide); // var speed = new StackPanel(game) { Direction = LayoutDirection.Horizontal, HAnchor = HorizontalAnchor.Left, ChildrenShareFocus = true, SpriteBackground = true, Border = 4, Width = 128 }; spMenu.Children.Add(speed); var speedLabel = new TextPanel(game) { Text = "Speed", Width = 32, SpriteBackground = false }; speed.Children.Add(speedLabel); var speedSlide = new Slider(game) { Width = 32, Value = 1, Minimum = 1, Maximum = 3, IncrementSize = 1 }; speedSlide.ValueChanged += (sender, e) => { }; speed.Children.Add(speedSlide); // var okCancelRow = new StackPanel(game) { HAnchor = HorizontalAnchor.Middle, Direction = LayoutDirection.Horizontal }; spMenu.Children.Add(okCancelRow); var cancel = new Button(game) { Text = "Back" }; okCancelRow.Children.Add(cancel); cancel.OnClick += (snder, e) => { retVal.InvokeEscape(); }; var newGame = new Button(game) { Text = "New Game" }; newGame.OnClick += (snder, e) => { g1.NewGame((int)diffSlide.Value, (int)speedSlide.Value); }; okCancelRow.Children.Add(newGame); retVal.UpdateLayout(retVal.Bounds); return(retVal); }
/// <summary> /// A screen for changing keybinds /// </summary> /// <param name="game"></param> /// <returns></returns> public static UIScreen ControllerOptionsScreen(Game game) { Game1 g1 = (Game1)game; g1.Input.SetRevertState(); var retVal = new UIScreen(game) { //EscapeCloses = true }; List <KeybindPanel> kbPanels = new List <KeybindPanel>(); retVal.Escape += (sender, e) => { foreach (var item in kbPanels) { if (item.Active) { return; } } if (g1.Input.UnsavedChanges) { g1.UI.OpenScreen(CloseKeybindsConfirmationScreen(game)); } else { g1.UI.CloseTopScreen(); } }; var spLabel = new StackPanel(game) { HAnchor = HorizontalAnchor.Middle, VAnchor = VerticalAnchor.Middle, SpriteBackground = true, Border = 4 }; var label = new TextPanel(game) { Text = "Controller settings", HAnchor = HorizontalAnchor.Middle, SpriteBackground = false }; spLabel.Children.Add(label); var spMenu = new StackPanel(game) { HAnchor = HorizontalAnchor.Middle, VAnchor = VerticalAnchor.Middle, MainNavigation = true }; spLabel.Children.Add(spMenu); foreach (var action in g1.Input.BindableActions) { var row = new StackPanel(game) { Direction = LayoutDirection.Horizontal, ChildrenShareFocus = true }; var actionName = new TextPanel(game) { Text = action.ToString(), SpriteBackground = false, Width = 48 }; var keythingy = new KeybindPanel(game) { //Input = g1.Input.GetKeybind(action), Action = action, Width = 80, Filter = new InputTypes[] { InputTypes.Controller } }; keythingy.SetText(); keythingy.KeyAssigned += (sender, e) => { foreach (var item in kbPanels) { item.SetText(); } }; kbPanels.Add(keythingy); row.Children.Add(actionName); row.Children.Add(keythingy); spMenu.Children.Add(row); } //var moveStickSP = new StackPanel(game) //{ // Direction = LayoutDirection.Horizontal, // SpriteBackground = false, // ChildrenShareFocus = true //}; //var moveStickLabel = new TextPanel(game) //{ // Text = "Move stick", // SpriteBackground = false //}; //moveStickSP.Children.Add(moveStickLabel); //var moveStickSelect = new SelectBox(game); //moveStickSelect.Options.Add(new SelectBoxOption("Left stick", Sticks.Left)); //moveStickSelect.Options.Add(new SelectBoxOption("Right stick", Sticks.Right)); //if (g1.Input.MovementStick == Sticks.Left) //{ // moveStickSelect.Selected = 0; //} //else //{ // moveStickSelect.Selected = 1; //} //moveStickSelect.SelectionChanged += (sender, e) => //{ // if (moveStickSelect.SelectedOption.Value is Sticks stick) // { // g1.Input.MovementStick = stick; // } //}; //moveStickSP.Children.Add(moveStickSelect); //spMenu.Children.Add(moveStickSP); //var aimStickSP = new StackPanel(game) //{ // Direction = LayoutDirection.Horizontal, // SpriteBackground = false, // ChildrenShareFocus = true //}; //var aimStickLabel = new TextPanel(game) //{ // Text = "Aim stick", // SpriteBackground = false //}; //aimStickSP.Children.Add(aimStickLabel); //var aimStickSelect = new SelectBox(game); //aimStickSelect.Options.Add(new SelectBoxOption("Left stick", Sticks.Left)); //aimStickSelect.Options.Add(new SelectBoxOption("Right stick", Sticks.Right)); //if (g1.Input.AimStick == Sticks.Left) //{ // aimStickSelect.Selected = 0; //} //else //{ // aimStickSelect.Selected = 1; //} //aimStickSelect.SelectionChanged += (sender, e) => //{ // if (aimStickSelect.SelectedOption.Value is Sticks stick) // { // g1.Input.AimStick = stick; // } //}; //aimStickSP.Children.Add(aimStickSelect); //spMenu.Children.Add(aimStickSP); var defaultButton = new Button(game) { Text = "Use defaults", HAnchor = HorizontalAnchor.Right }; defaultButton.OnClick += (sender, e) => { g1.Input.SetDefaultKeys(); foreach (var item in kbPanels) { item.SetText(); } }; spMenu.Children.Add(defaultButton); var closeButtons = new StackPanel(game) { Direction = LayoutDirection.Horizontal }; var saveButton = new Button(game) { Text = "Save & close" }; saveButton.OnClick += (sender, e) => { g1.Input.SaveKeybinds(g1.Config.KeysFilePath); g1.UI.CloseTopScreen(); }; var dontsaveButton = new Button(game) { Text = "Close without saving" }; dontsaveButton.OnClick += (sender, e) => { g1.Input.RevertChanges(); g1.UI.CloseTopScreen(); }; closeButtons.Children.Add(saveButton); closeButtons.Children.Add(dontsaveButton); spMenu.Children.Add(closeButtons); retVal.Children.Add(spLabel); retVal.UpdateLayout(retVal.Bounds); return(retVal); }
/// <summary> /// A screen for changing keybinds /// </summary> /// <param name="game"></param> /// <returns></returns> public static UIScreen KeybindsScreen(Game game) { Game1 g1 = (Game1)game; g1.Input.SetRevertState(); var retVal = new UIScreen(game) { //EscapeCloses = true }; List <KeybindPanel> kbPanels = new List <KeybindPanel>(); retVal.Escape += (sender, e) => { foreach (var item in kbPanels) { if (item.Active) { return; } } if (g1.Input.UnsavedChanges) { g1.UI.OpenScreen(CloseKeybindsConfirmationScreen(game)); } else { g1.UI.CloseTopScreen(); } }; var spLabel = new StackPanel(game) { HAnchor = HorizontalAnchor.Middle, VAnchor = VerticalAnchor.Middle, SpriteBackground = true, Border = 4 }; var label = new TextPanel(game) { Text = "Keybinds", HAnchor = HorizontalAnchor.Middle, SpriteBackground = false }; spLabel.Children.Add(label); var spMenu = new StackPanel(game) { HAnchor = HorizontalAnchor.Middle, VAnchor = VerticalAnchor.Middle, MainNavigation = true }; spLabel.Children.Add(spMenu); foreach (var action in g1.Input.BindableActions) { var row = new StackPanel(game) { Direction = LayoutDirection.Horizontal, ChildrenShareFocus = true }; var actionName = new TextPanel(game) { Text = action.ToString(), SpriteBackground = false, Width = 48 }; var keythingy = new KeybindPanel(game) { //Input = g1.Input.GetKeybind(action), Action = action, Width = 80, Filter = new InputTypes[] { InputTypes.Keyboard, InputTypes.Mouse } }; keythingy.SetText(); keythingy.KeyAssigned += (sender, e) => { foreach (var item in kbPanels) { item.SetText(); } }; kbPanels.Add(keythingy); row.Children.Add(actionName); row.Children.Add(keythingy); spMenu.Children.Add(row); } var defaultButton = new Button(game) { Text = "Use defaults", HAnchor = HorizontalAnchor.Right }; defaultButton.OnClick += (sender, e) => { g1.Input.SetDefaultKeys(); foreach (var item in kbPanels) { item.SetText(); } }; spMenu.Children.Add(defaultButton); var closeButtons = new StackPanel(game) { Direction = LayoutDirection.Horizontal }; var saveButton = new Button(game) { Text = "Save & close" }; saveButton.OnClick += (sender, e) => { g1.Input.SaveKeybinds(g1.Config.KeysFilePath); g1.UI.CloseTopScreen(); }; var dontsaveButton = new Button(game) { Text = "Close without saving" }; dontsaveButton.OnClick += (sender, e) => { g1.Input.RevertChanges(); g1.UI.CloseTopScreen(); }; closeButtons.Children.Add(saveButton); closeButtons.Children.Add(dontsaveButton); spMenu.Children.Add(closeButtons); retVal.Children.Add(spLabel); retVal.UpdateLayout(retVal.Bounds); return(retVal); }
/// <summary> /// A screen for changing the options /// </summary> /// <param name="game"></param> /// <returns></returns> public static UIScreen OptionsScreen(Game game) { Game1 g1 = (Game1)game; var retVal = new UIScreen(game) { Purpose = ScreenPurpose.Options }; retVal.Escape += (sender, e) => { if (g1.Config.UnappliedChanges) { g1.UI.OpenScreen(CloseOptionsConfirmationScreen(game)); } else { g1.UI.CloseTopScreen(); } }; var spLabel = new StackPanel(game) { HAnchor = HorizontalAnchor.Middle, VAnchor = VerticalAnchor.Middle, SpriteBackground = true, Border = 4 }; retVal.Children.Add(spLabel); var optionsLabel = new TextPanel(game) { Text = "Options", Width = 128, SpriteBackground = false }; spLabel.Children.Add(optionsLabel); var spMenu = new StackPanel(game) { HAnchor = HorizontalAnchor.Middle, VAnchor = VerticalAnchor.Middle, MainNavigation = true }; spLabel.Children.Add(spMenu); var volume = new StackPanel(game) { Direction = LayoutDirection.Horizontal, HAnchor = HorizontalAnchor.Middle, ChildrenShareFocus = true, SpriteBackground = true, Border = 4 }; spMenu.Children.Add(volume); var volLabel = new TextPanel(game) { Text = "Volume", Width = 32, SpriteBackground = false }; volume.Children.Add(volLabel); var volSlide = new Slider(game) { Value = g1.Config.Config.Volume, InputRepeatInterval = 1f / 40f }; volSlide.ValueChanged += (sender, e) => { g1.Config.NewConfig.Volume = (int)volSlide.Value; }; volume.Children.Add(volSlide); // resolution var res = new StackPanel(game) { Direction = LayoutDirection.Horizontal, HAnchor = HorizontalAnchor.Middle, ChildrenShareFocus = true, }; spMenu.Children.Add(res); var resLabel = new TextPanel(game) { Text = "Resolution", SpriteBackground = false }; res.Children.Add(resLabel); var resolutionSelect = new SelectBox(game); var dispModes = GraphicsAdapter.DefaultAdapter.SupportedDisplayModes.ToList(); for (int i = 0; i < dispModes.Count; i++) { resolutionSelect.Options.Add(new SelectBoxOption($"{dispModes[i].Width}x{dispModes[i].Height}", dispModes[i])); if (((Game1)game).Config.Config.Resolution == dispModes[i]) { resolutionSelect.Selected = i; } } resolutionSelect.SelectionChanged += (sender, e) => { if (resolutionSelect.SelectedOption.Value is DisplayMode newRes) { g1.Config.NewConfig.Resolution = newRes; } }; res.Children.Add(resolutionSelect); // fullscreen mode select var fullscreen = new StackPanel(game) { Direction = LayoutDirection.Horizontal, HAnchor = HorizontalAnchor.Middle, ChildrenShareFocus = true }; spMenu.Children.Add(fullscreen); var fullLabel = new TextPanel(game) { Text = "Fullscreen", SpriteBackground = false }; fullscreen.Children.Add(fullLabel); var fullscreenSelect = new SelectBox(game); fullscreenSelect.Options.Add(new SelectBoxOption("Full screen", WindowMode.Fullscreen)); fullscreenSelect.Options.Add(new SelectBoxOption("Window", WindowMode.Windowed)); fullscreenSelect.Options.Add(new SelectBoxOption("Borderless window", WindowMode.BorderlessWindow)); fullscreenSelect.SelectionChanged += (sender, e) => { if (fullscreenSelect.SelectedOption.Value is WindowMode newWindMode) { g1.Config.NewConfig.WindowMode = newWindMode; } }; var windMode = g1.Config.Config.WindowMode; switch (windMode) { case WindowMode.Fullscreen: fullscreenSelect.Selected = 0; break; case WindowMode.Windowed: fullscreenSelect.Selected = 1; break; case WindowMode.BorderlessWindow: fullscreenSelect.Selected = 2; break; default: break; } fullscreen.Children.Add(fullscreenSelect); // var keys = new Button(game) { Text = "Mouse & Keyboard", HAnchor = HorizontalAnchor.Middle, Width = 128 }; keys.OnClick += (sender, e) => { g1.UI.OpenScreen(KeybindsScreen(game)); }; spMenu.Children.Add(keys); var controller = new Button(game) { Text = "Controller", HAnchor = HorizontalAnchor.Middle, Width = 128 }; controller.OnClick += (sender, e) => { g1.UI.OpenScreen(ControllerOptionsScreen(game)); }; spMenu.Children.Add(controller); // var okCancelRow = new StackPanel(game) { HAnchor = HorizontalAnchor.Middle, Direction = LayoutDirection.Horizontal }; spMenu.Children.Add(okCancelRow); var apply = new Button(game) { Text = "Apply" }; apply.OnClick += (snder, e) => { //apply g1.Config.Save(); g1.ApplyGraphicsConfig(); //g1.Input.SaveKeybinds(g1.Config.KeysPath); }; okCancelRow.Children.Add(apply); var cancel = new Button(game) { Text = "Back" }; okCancelRow.Children.Add(cancel); cancel.OnClick += (snder, e) => { retVal.InvokeEscape(); }; retVal.UpdateLayout(retVal.Bounds); return(retVal); }
/// <summary> /// A screen that asks if you want to save changes when closing the keybinds screen. /// </summary> /// <param name="game"></param> /// <returns></returns> public static UIScreen CloseKeybindsConfirmationScreen(Game game) { Game1 g1 = (Game1)game; var retVal = new UIScreen(game) { EscapeCloses = true }; var sp = new StackPanel(game) { HAnchor = HorizontalAnchor.Middle, VAnchor = VerticalAnchor.Middle, SpriteBackground = true, Border = 4 }; retVal.Children.Add(sp); var label1 = new TextPanel(game) { Text = "Keybinds changed", SpriteBackground = false }; sp.Children.Add(label1); var label2 = new TextPanel(game) { Text = "Save changes?", SpriteBackground = false }; sp.Children.Add(label2); var buttonRow = new StackPanel(game) { Direction = LayoutDirection.Horizontal, MainNavigation = true }; sp.Children.Add(buttonRow); var saveButton = new Button(game) { Text = "Save", Width = 48 }; saveButton.OnClick += (snder, e) => { g1.Input.SaveKeybinds(g1.Config.KeysFilePath); g1.UI.CloseTopScreen(); g1.UI.CloseTopScreen(); }; buttonRow.Children.Add(saveButton); var discardButton = new Button(game) { Text = "Discard", Width = 48 }; discardButton.OnClick += (snder, e) => { g1.Input.RevertChanges(); g1.UI.CloseTopScreen(); g1.UI.CloseTopScreen(); }; buttonRow.Children.Add(discardButton); var cancelButton = new Button(game) { Text = "Cancel", Width = 48 }; cancelButton.OnClick += (snder, e) => { g1.UI.CloseTopScreen(); }; buttonRow.Children.Add(cancelButton); retVal.UpdateLayout(retVal.Bounds); return(retVal); }
/// <summary> /// A screen for viewing high scores /// </summary> /// <param name="game"></param> /// <returns></returns> public static UIScreen HighScoreScreen(Game game) { Game1 g1 = (Game1)game; var retVal = new UIScreen(game) { Purpose = ScreenPurpose.Options }; retVal.Escape += (sender, e) => { g1.UI.CloseTopScreen(); }; var mainsp = new StackPanel(game) { HAnchor = HorizontalAnchor.Middle, VAnchor = VerticalAnchor.Middle, SpriteBackground = true, Border = 4 }; retVal.Children.Add(mainsp); var scoreLabel = new TextPanel(game) { Text = "High score", Width = 128, SpriteBackground = false }; mainsp.Children.Add(scoreLabel); int rank = 0; foreach (var item in g1.Score.Scores) { rank++; var scoresp = new StackPanel(game) { Direction = LayoutDirection.Horizontal }; mainsp.Children.Add(scoresp); var rankText = new TextPanel(game) { Text = rank.ToString(), Height = 8, Width = 8, SpriteBackground = false }; scoresp.Children.Add(rankText); var name = new TextPanel(game) { Text = item.Item1, SpriteBackground = false, Height = 8 }; scoresp.Children.Add(name); var score = new TextPanel(game) { Text = item.Item2.ToString(), SpriteBackground = false, Height = 8 }; scoresp.Children.Add(score); } // var buttonRow = new StackPanel(game) { Direction = LayoutDirection.Vertical, MainNavigation = true }; mainsp.Children.Add(buttonRow); var back = new Button(game) { Text = "Back" }; buttonRow.Children.Add(back); back.OnClick += (snder, e) => { retVal.InvokeEscape(); }; retVal.UpdateLayout(retVal.Bounds); return(retVal); }
/// <summary> /// A screen for changing the options /// </summary> /// <param name="game"></param> /// <returns></returns> public static UIScreen GlobalVarsScreen(Game game) { Game1 g1 = (Game1)game; var retVal = new UIScreen(game) { Purpose = ScreenPurpose.Options, EscapeCloses = true }; retVal.Escape += (sender, e) => { }; var spLabel = new StackPanel(game) { HAnchor = HorizontalAnchor.Middle, VAnchor = VerticalAnchor.Middle, SpriteBackground = true, Border = 4 }; retVal.Children.Add(spLabel); var optionsLabel = new TextPanel(game) { Text = "stuff", Width = 128, SpriteBackground = false }; spLabel.Children.Add(optionsLabel); var spMenu = new StackPanel(game) { HAnchor = HorizontalAnchor.Middle, VAnchor = VerticalAnchor.Middle, MainNavigation = true }; spLabel.Children.Add(spMenu); var move = new StackPanel(game) { Direction = LayoutDirection.Horizontal, HAnchor = HorizontalAnchor.Middle, ChildrenShareFocus = true, SpriteBackground = true, Border = 4 }; spMenu.Children.Add(move); var moveLabel = new TextPanel(game) { Text = "move Speed", Width = 32, SpriteBackground = false }; move.Children.Add(moveLabel); var moveSlide = new Slider(game) { Value = GlobalVarsHolder.PlayerRunSpeed, Minimum = 50, Maximum = 1000 }; moveSlide.ValueChanged += (sender, e) => { GlobalVarsHolder.PlayerRunSpeed = moveSlide.Value; }; move.Children.Add(moveSlide); var jump = new StackPanel(game) { Direction = LayoutDirection.Horizontal, HAnchor = HorizontalAnchor.Middle, ChildrenShareFocus = true, SpriteBackground = true, Border = 4 }; spMenu.Children.Add(jump); var jumpLabel = new TextPanel(game) { Text = "jump Speed", Width = 32, SpriteBackground = false }; jump.Children.Add(jumpLabel); var jumpSlide = new Slider(game) { Value = -GlobalVarsHolder.PlayerJump, Minimum = 50, Maximum = 1000 }; jumpSlide.ValueChanged += (sender, e) => { GlobalVarsHolder.PlayerJump = -jumpSlide.Value; }; jump.Children.Add(jumpSlide); var gravity = new StackPanel(game) { Direction = LayoutDirection.Horizontal, HAnchor = HorizontalAnchor.Middle, ChildrenShareFocus = true, SpriteBackground = true, Border = 4 }; spMenu.Children.Add(gravity); var gravityLabel = new TextPanel(game) { Text = "gravity", Width = 32, SpriteBackground = false }; gravity.Children.Add(gravityLabel); var gravitySlide = new Slider(game) { Value = GlobalVarsHolder.Gravity, Minimum = 100, Maximum = 2000, IncrementSize = 50 }; gravitySlide.ValueChanged += (sender, e) => { GlobalVarsHolder.Gravity = gravitySlide.Value; }; gravity.Children.Add(gravitySlide); var terminalVelocity = new StackPanel(game) { Direction = LayoutDirection.Horizontal, HAnchor = HorizontalAnchor.Middle, ChildrenShareFocus = true, SpriteBackground = true, Border = 4 }; spMenu.Children.Add(terminalVelocity); var terminalVelocityLabel = new TextPanel(game) { Text = "terminalVelocity", Width = 32, SpriteBackground = false }; terminalVelocity.Children.Add(terminalVelocityLabel); var terminalVelocitySlide = new Slider(game) { Value = GlobalVarsHolder.TerminalVelocity, Minimum = 500, Maximum = 1000 }; terminalVelocitySlide.ValueChanged += (sender, e) => { GlobalVarsHolder.TerminalVelocity = terminalVelocitySlide.Value; }; terminalVelocity.Children.Add(terminalVelocitySlide); var foo3000 = new StackPanel(game) { Direction = LayoutDirection.Horizontal, HAnchor = HorizontalAnchor.Middle, ChildrenShareFocus = true, SpriteBackground = true, Border = 4 }; spMenu.Children.Add(foo3000); var foo3000Label = new TextPanel(game) { Text = "foo3000", Width = 32, SpriteBackground = false }; foo3000.Children.Add(foo3000Label); var foo3000Slide = new Slider(game) { Value = 50, Minimum = -100, Maximum = 100 }; foo3000Slide.ValueChanged += (sender, e) => { //GlobalVarsHolder.TerminalVelocity = foo3000Slide.Value; }; foo3000.Children.Add(foo3000Slide); retVal.UpdateLayout(retVal.Bounds); return(retVal); }