protected ButtonWidget MakeBack(string text, Font font, ClickHandler onClick) { int width = game.UseClassicOptions ? 400 : 200; return(ButtonWidget.Create(game, width, text, font, onClick) .SetLocation(Anchor.Centre, Anchor.Max, 0, 25)); }
protected ButtonWidget MakeTitle(int dir, int y, string text, ClickHandler onClick) { ButtonWidget widget = ButtonWidget.Create(game, 160 * dir, y, 301, 41, text, Anchor.Centre, Anchor.Centre, titleFont, onClick); return(widget); }
void MakeNormal() { widgets = new Widget[] { Make(-1, -50, "Options", (g, w) => g.Gui.SetNewScreen(new OptionsGroupScreen(g))), Make(1, -50, "Generate level", (g, w) => g.Gui.SetNewScreen(new GenLevelScreen(g))), Make(1, 0, "Load level", (g, w) => g.Gui.SetNewScreen(new LoadLevelScreen(g))), Make(1, 50, "Save level", (g, w) => g.Gui.SetNewScreen(new SaveLevelScreen(g))), Make(-1, 0, "Select texture pack", (g, w) => g.Gui.SetNewScreen(new TexturePackScreen(g))), #if !ANDROID Make(-1, 50, "Hotkeys", (g, w) => g.Gui.SetNewScreen(new HotkeyListScreen(g))), #else null, #endif // Other ButtonWidget.Create(game, 120, "Quit game", titleFont, LeftOnly((g, w) => g.Exit())) .SetLocation(Anchor.BottomOrRight, Anchor.BottomOrRight, 5, 5), MakeBack(true, titleFont, (g, w) => g.Gui.SetNewScreen(null)), }; }
public override void Init() { game.Keyboard.KeyRepeat = true; base.Init(); titleFont = new Font(game.FontName, 16, FontStyle.Bold); regularFont = new Font(game.FontName, 16, FontStyle.Regular); inputs = new [] { MakeInput(-80, false, game.World.Width.ToString()), MakeInput(-40, false, game.World.Height.ToString()), MakeInput(0, false, game.World.Length.ToString()), MakeInput(40, true, "") }; labels = new [] { MakeLabel(-150, -80, "Width:"), MakeLabel(-150, -40, "Height:"), MakeLabel(-150, 0, "Length:"), MakeLabel(-140, 40, "Seed:"), ChatTextWidget.Create(game, 0, -130, "Generate new level", Anchor.Centre, Anchor.Centre, regularFont), }; widgets = new [] { ButtonWidget.Create(game, -120, 100, 201, 40, "Flatgrass", Anchor.Centre, Anchor.Centre, titleFont, GenFlatgrassClick), ButtonWidget.Create(game, 120, 100, 201, 40, "Vanilla", Anchor.Centre, Anchor.Centre, titleFont, GenNotchyClick), MakeBack(false, titleFont, (g, w) => g.Gui.SetNewScreen(new PauseScreen(g))), }; }
void InitStandardButtons() { base.ContextLost(); alwaysIndex = 100; if (confirmingMode) { widgets = new ButtonWidget[2]; widgets[0] = ButtonWidget.Create(game, 160, "I'm sure", titleFont, OnNoClick) .SetLocation(Anchor.Centre, Anchor.Centre, -110, 30); widgets[1] = ButtonWidget.Create(game, 160, "Go back", titleFont, GoBackClick) .SetLocation(Anchor.Centre, Anchor.Centre, 110, 30); return; } widgets = new ButtonWidget[showAlways ? 4 : 2]; widgets[0] = ButtonWidget.Create(game, 160, "Yes", titleFont, OnYesClick) .SetLocation(Anchor.Centre, Anchor.Centre, -110, 30); widgets[1] = ButtonWidget.Create(game, 160, "No", titleFont, OnNoClick) .SetLocation(Anchor.Centre, Anchor.Centre, 110, 30); if (!showAlways) { return; } alwaysIndex = 2; widgets[2] = ButtonWidget.Create(game, 160, "Always yes", titleFont, OnYesClick) .SetLocation(Anchor.Centre, Anchor.Centre, -110, 85); widgets[3] = ButtonWidget.Create(game, 160, "Always no", titleFont, OnNoClick) .SetLocation(Anchor.Centre, Anchor.Centre, 110, 85); }
public override void MakeButtons() { DisposeWidgets(widgets); alwaysIndex = 100; if (confirmingMode) { widgets = new ButtonWidget[2]; widgets[0] = ButtonWidget.Create(game, 160, "I'm sure", titleFont, OnNoClick) .SetLocation(Anchor.Centre, Anchor.Centre, -110, 30); widgets[1] = ButtonWidget.Create(game, 160, "Go back", titleFont, GoBackClick) .SetLocation(Anchor.Centre, Anchor.Centre, 110, 30); return; } widgets = new ButtonWidget[showAlways ? 4 : 2]; widgets[0] = ButtonWidget.Create(game, 160, "Yes", titleFont, OnYesClick) .SetLocation(Anchor.Centre, Anchor.Centre, -110, 30); widgets[1] = ButtonWidget.Create(game, 160, "No", titleFont, OnNoClick) .SetLocation(Anchor.Centre, Anchor.Centre, 110, 30); if (!showAlways) { return; } alwaysIndex = 2; widgets[2] = ButtonWidget.Create(game, 160, "Always yes", titleFont, OnYesClick) .SetLocation(Anchor.Centre, Anchor.Centre, -110, 85); widgets[3] = ButtonWidget.Create(game, 160, "Always no", titleFont, OnNoClick) .SetLocation(Anchor.Centre, Anchor.Centre, 110, 85); }
void Make(int i, int x, ref int y) { string text = ButtonText(i); widgets[index++] = ButtonWidget.Create(game, btnWidth, text, titleFont, OnBindingClick) .SetLocation(Anchor.Centre, Anchor.Centre, x, y); y += btnDistance; }
protected override void ContextRecreated() { MakeLabels(); widgets[4] = ButtonWidget.Create(game, 160, "Yes", titleFont, OpenUrl) .SetLocation(Anchor.Centre, Anchor.Centre, -110, 30); widgets[5] = ButtonWidget.Create(game, 160, "No", titleFont, AppendUrl) .SetLocation(Anchor.Centre, Anchor.Centre, 110, 30); }
protected override void ContextRecreated() { MakeLabels(); widgets[4] = ButtonWidget.Create(game, 160, "I'm sure", titleFont, ConfirmNoClick) .SetLocation(Anchor.Centre, Anchor.Centre, -110, 30); widgets[5] = ButtonWidget.Create(game, 160, "Go back", titleFont, GoBackClick) .SetLocation(Anchor.Centre, Anchor.Centre, 110, 30); }
public override void MakeButtons() { DisposeWidgets(widgets); widgets[0] = ButtonWidget.Create(game, 160, "Yes", titleFont, OpenUrl) .SetLocation(Anchor.Centre, Anchor.Centre, -110, 30); widgets[1] = ButtonWidget.Create(game, 160, "No", titleFont, AppendUrl) .SetLocation(Anchor.Centre, Anchor.Centre, 110, 30); }
public override void MakeButtons() { DisposeWidgets(widgets); widgets[0] = ButtonWidget.Create(game, 160, "I'm sure", titleFont, ConfirmNoClick) .SetLocation(Anchor.Centre, Anchor.Centre, -110, 30); widgets[1] = ButtonWidget.Create(game, 160, "Go back", titleFont, GoBackClick) .SetLocation(Anchor.Centre, Anchor.Centre, 110, 30); }
void Make(string desc, KeyBind bind, int x, ref int y) { string text = desc + ": " + keyNames[(int)game.Mapping(bind)]; widgets[index++] = ButtonWidget.Create(game, x, y, btnWidth, btnHeight, text, Anchor.Centre, Anchor.Centre, keyFont, OnBindingClick); y += btnDistance; }
protected override void ContextRecreated() { IServerConnection network = game.Server; widgets = new Widget[] { // Column 1 MakeBool(-1, -150, "Music", OptionsKey.UseMusic, OnWidgetClick, g => g.UseMusic, (g, v) => { g.UseMusic = v; g.AudioPlayer.SetMusic(g.UseMusic); }), MakeBool(-1, -100, "Invert mouse", OptionsKey.InvertMouse, OnWidgetClick, g => g.InvertMouse, (g, v) => g.InvertMouse = v), MakeOpt(-1, -50, "View distance", OnWidgetClick, g => g.ViewDistance.ToString(), (g, v) => g.SetViewDistance(Int32.Parse(v), true)), !network.IsSinglePlayer ? null : MakeBool(-1, 0, "Block physics", OptionsKey.SingleplayerPhysics, OnWidgetClick, g => ((SinglePlayerServer)network).physics.Enabled, (g, v) => ((SinglePlayerServer)network).physics.Enabled = v), // Column 2 MakeBool(1, -150, "Sound", OptionsKey.UseSound, OnWidgetClick, g => g.UseSound, (g, v) => { g.UseSound = v; g.AudioPlayer.SetSound(g.UseSound); }), MakeBool(1, -100, "Show FPS", OptionsKey.ShowFPS, OnWidgetClick, g => g.ShowFPS, (g, v) => g.ShowFPS = v), MakeBool(1, -50, "View bobbing", OptionsKey.ViewBobbing, OnWidgetClick, g => g.ViewBobbing, (g, v) => g.ViewBobbing = v), MakeOpt(1, 0, "FPS mode", OnWidgetClick, g => g.FpsLimit.ToString(), (g, v) => { }), !game.ClassicHacks ? null : MakeBool(0, 60, "Hacks enabled", OptionsKey.HacksEnabled, OnWidgetClick, g => g.LocalPlayer.Hacks.Enabled, (g, v) => { g.LocalPlayer.Hacks.Enabled = v; g.LocalPlayer.CheckHacksConsistency(); }), ButtonWidget.Create(game, 400, "Controls", titleFont, LeftOnly((g, w) => g.Gui.SetNewScreen(new ClassicKeyBindingsScreen(g)))) .SetLocation(Anchor.Centre, Anchor.BottomOrRight, 0, 95), MakeBack(400, "Done", 25, titleFont, (g, w) => g.Gui.SetNewScreen(new PauseScreen(g))), null, null, }; // NOTE: we need to override the default setter here, because changing FPS limit method // recreates the graphics context on some backends (such as Direct3D9) ButtonWidget btn = (ButtonWidget)widgets[7]; btn.SetValue = SetFPSLimitMethod; }
ButtonWidget MakeText(int i) { string text = Get(currentIndex + i); ButtonWidget btn = ButtonWidget.Create(game, 300, "", font, EntryClick) .SetLocation(Anchor.Centre, Anchor.Centre, 0, (i - 2) * 50); UpdateEntry(btn, text); return(btn); }
public override void Init() { base.Init(); IServerConnection network = game.Server; widgets = new Widget[] { // Column 1 MakeBool(-1, -150, "Music", OptionsKey.UseMusic, OnWidgetClick, g => g.UseMusic, (g, v) => { g.UseMusic = v; g.AudioPlayer.SetMusic(g.UseMusic); }), MakeBool(-1, -100, "Invert mouse", OptionsKey.InvertMouse, OnWidgetClick, g => g.InvertMouse, (g, v) => g.InvertMouse = v), MakeOpt(-1, -50, "View distance", OnWidgetClick, g => g.ViewDistance.ToString(), (g, v) => g.SetViewDistance(Int32.Parse(v), true)), !network.IsSinglePlayer ? null : MakeBool(-1, 0, "Block physics", OptionsKey.SingleplayerPhysics, OnWidgetClick, g => ((SinglePlayerServer)network).physics.Enabled, (g, v) => ((SinglePlayerServer)network).physics.Enabled = v), // Column 2 MakeBool(1, -150, "Sound", OptionsKey.UseSound, OnWidgetClick, g => g.UseSound, (g, v) => { g.UseSound = v; g.AudioPlayer.SetSound(g.UseSound); }), MakeBool(1, -100, "Show FPS", OptionsKey.ShowFPS, OnWidgetClick, g => g.ShowFPS, (g, v) => g.ShowFPS = v), MakeBool(1, -50, "View bobbing", OptionsKey.ViewBobbing, OnWidgetClick, g => g.ViewBobbing, (g, v) => g.ViewBobbing = v), MakeOpt(1, 0, "FPS mode", OnWidgetClick, g => g.FpsLimit.ToString(), (g, v) => { object raw = Enum.Parse(typeof(FpsLimitMethod), v); g.SetFpsLimitMethod((FpsLimitMethod)raw); Options.Set(OptionsKey.FpsLimit, v); }), !game.ClassicHacks ? null : MakeBool(0, 60, "Hacks enabled", OptionsKey.HacksEnabled, OnWidgetClick, g => g.LocalPlayer.Hacks.Enabled, (g, v) => { g.LocalPlayer.Hacks.Enabled = v; g.LocalPlayer.CheckHacksConsistency(); }), ButtonWidget.Create(game, 0, 95, 401, 41, "Controls", Anchor.Centre, Anchor.BottomOrRight, titleFont, LeftOnly((g, w) => g.Gui.SetNewScreen(new ClassicKeyBindingsScreen(g)))), MakeBack(401, "Done", 22, titleFont, (g, w) => g.Gui.SetNewScreen(new PauseScreen(g))), null, null, }; MakeValidators(); }
protected ButtonWidget MakeOpt(int dir, int y, string optName, ClickHandler onClick, ButtonValueGetter getter, ButtonValueSetter setter) { ButtonWidget btn = ButtonWidget.Create(game, 300, optName + ": " + getter(game), titleFont, onClick) .SetLocation(Anchor.Centre, Anchor.Centre, 160 * dir, y); btn.OptName = optName; btn.GetValue = getter; btn.SetValue = setter; return(btn); }
protected void OnWidgetClick(Game game, Widget widget, MouseButton btn, int x, int y) { ButtonWidget button = widget as ButtonWidget; if (btn != MouseButton.Left) { return; } if (widget == widgets[widgets.Length - 1]) { ChangeSetting(); return; } if (button == null) { return; } DisposeExtendedHelp(); int index = Array.IndexOf <Widget>(widgets, button); MenuInputValidator validator = validators[index]; if (validator is BooleanValidator) { string value = button.GetValue(game); button.SetValue(game, value == "yes" ? "no" : "yes"); UpdateDescription(button); return; } else if (validator is EnumValidator) { Type type = ((EnumValidator)validator).EnumType; HandleEnumOption(button, type); return; } targetWidget = selectedWidget; if (input != null) { input.Dispose(); } input = MenuInputWidget.Create(game, 400, 30, button.GetValue(game), regularFont, validator) .SetLocation(Anchor.Centre, Anchor.Centre, 0, 110); input.ShowCaret = true; input.OnClick = InputClick; widgets[widgets.Length - 2] = input; widgets[widgets.Length - 1] = ButtonWidget.Create(game, 40, "OK", titleFont, OnWidgetClick) .SetLocation(Anchor.Centre, Anchor.Centre, 240, 110); InputOpened(); UpdateDescription(targetWidget); }
protected override void ContextRecreated() { widgets = new Widget[] { ButtonWidget.Create(game, 400, "Small", titleFont, GenSmallClick) .SetLocation(Anchor.Centre, Anchor.Centre, 0, -100), ButtonWidget.Create(game, 400, "Normal", titleFont, GenMediumClick) .SetLocation(Anchor.Centre, Anchor.Centre, 0, -50), ButtonWidget.Create(game, 400, "Huge", titleFont, GenHugeClick) .SetLocation(Anchor.Centre, Anchor.Centre, 0, 0), MakeBack(false, titleFont, SwitchPause), }; }
public override void MakeButtons() { DisposeWidgets(widgets); widgets[0] = ButtonWidget.Create(game, 160, "Yes", titleFont, OnYesClick) .SetLocation(Anchor.Centre, Anchor.Centre, -110, 30); widgets[1] = ButtonWidget.Create(game, 160, "No", titleFont, OnNoClick) .SetLocation(Anchor.Centre, Anchor.Centre, 110, 30); widgets[2] = ButtonWidget.Create(game, 160, "Always yes", titleFont, OnYesClick) .SetLocation(Anchor.Centre, Anchor.Centre, -110, 85); widgets[3] = ButtonWidget.Create(game, 160, "Always no", titleFont, OnNoClick) .SetLocation(Anchor.Centre, Anchor.Centre, 110, 85); }
protected override void ContextRecreated() { MakeLabels(); widgets[4] = ButtonWidget.Create(game, 160, "Yes", titleFont, OnYesClick) .SetLocation(Anchor.Centre, Anchor.Centre, -110, 30); widgets[5] = ButtonWidget.Create(game, 160, "No", titleFont, OnNoClick) .SetLocation(Anchor.Centre, Anchor.Centre, 110, 30); widgets[6] = ButtonWidget.Create(game, 160, "Always yes", titleFont, OnYesClick) .SetLocation(Anchor.Centre, Anchor.Centre, -110, 85); widgets[7] = ButtonWidget.Create(game, 160, "Always no", titleFont, OnNoClick) .SetLocation(Anchor.Centre, Anchor.Centre, 110, 85); }
protected override void ContextRecreated() { widgets = new Widget[] { TextWidget.Create(game, "Game over!", regularFont) .SetLocation(Anchor.Centre, Anchor.Centre, 0, -150), TextWidget.Create(game, "Score: 0", titleFont) .SetLocation(Anchor.Centre, Anchor.Centre, 0, -75), ButtonWidget.Create(game, 400, "Generate new level...", titleFont, GenLevelClick) .SetLocation(Anchor.Centre, Anchor.Centre, 0, 25), ButtonWidget.Create(game, 400, "Load level...", titleFont, LoadLevelClick) .SetLocation(Anchor.Centre, Anchor.Centre, 0, 75), }; }
void InitConfirmButtons(bool always) { ClickHandler noHandler = always ? (ClickHandler)OnNoAlwaysClick: (ClickHandler)OnNoClick; widgets = new ButtonWidget[] { ButtonWidget.Create(game, -110, 30, 160, 35, "I'm sure", Anchor.Centre, Anchor.Centre, titleFont, noHandler), ButtonWidget.Create(game, 110, 30, 160, 35, "Go back", Anchor.Centre, Anchor.Centre, titleFont, GoBackClick), }; confirmMode = true; SetText(lastTitle, lastBody); }
protected ButtonWidget MakeOpt(int dir, int y, string text, ClickHandler onClick, Func <Game, string> getter, Action <Game, string> setter) { ButtonWidget widget = ButtonWidget.Create(game, 300, text + ": " + getter(game), titleFont, onClick) .SetLocation(Anchor.Centre, Anchor.Centre, 160 * dir, y); widget.Metadata = text; widget.GetValue = getter; widget.SetValue = (g, v) => { setter(g, v); widget.SetText((string)widget.Metadata + ": " + getter(g)); }; return(widget); }
public override void Init() { game.SkipClear = true; widgets = new Widget[] { ChatTextWidget.Create(game, 0, -30, title, Anchor.Centre, Anchor.Centre, titleFont), ChatTextWidget.Create(game, 0, 10, message, Anchor.Centre, Anchor.Centre, messageFont), ButtonWidget.Create(game, 0, 80, 301, 40, "Try to reconnect.. " + delay, Anchor.Centre, Anchor.Centre, titleFont, ReconnectClick), }; game.Graphics.ContextRecreated += ContextRecreated; initTime = DateTime.UtcNow; clearTime = DateTime.UtcNow.AddSeconds(0.5); lastSecsLeft = delay; }
protected override void ContextRecreated() { string score = game.Chat.Status1.Text; widgets = new Widget[] { TextWidget.Create(game, "Game over!", textFont) .SetLocation(Anchor.Centre, Anchor.Centre, 0, -150), TextWidget.Create(game, score, titleFont) .SetLocation(Anchor.Centre, Anchor.Centre, 0, -75), ButtonWidget.Create(game, 400, "Generate new level...", titleFont, GenLevelClick) .SetLocation(Anchor.Centre, Anchor.Centre, 0, 25), ButtonWidget.Create(game, 400, "Load level...", titleFont, LoadLevelClick) .SetLocation(Anchor.Centre, Anchor.Centre, 0, 75), }; }
void MakePages(int btnY) { if (leftPage == null && rightPage == null) { return; } widgets[index++] = ButtonWidget.Create(game, 40, "<", titleFont, LeftOnly(leftPage)) .SetLocation(Anchor.Centre, Anchor.Centre, -btnWidth - 35, btnY); widgets[index++] = ButtonWidget.Create(game, 40, ">", titleFont, LeftOnly(rightPage)) .SetLocation(Anchor.Centre, Anchor.Centre, btnWidth + 35, btnY); widgets[index - 2].Disabled = leftPage == null; widgets[index - 1].Disabled = rightPage == null; }
protected override void ContextRecreated() { input = MenuInputWidget.Create(game, 500, 30, "", regularFont, new PathValidator()) .SetLocation(Anchor.Centre, Anchor.Centre, 0, -30); input.ShowCaret = true; widgets = new Widget[] { ButtonWidget.Create(game, 300, "Save", titleFont, SaveClassic) .SetLocation(Anchor.Centre, Anchor.Centre, 0, 20), ButtonWidget.Create(game, 200, "Save schematic", titleFont, SaveSchematic) .SetLocation(Anchor.Centre, Anchor.Centre, -150, 120), TextWidget.Create(game, "&eCan be imported into MCEdit", regularFont) .SetLocation(Anchor.Centre, Anchor.Centre, 110, 120), null, MakeBack(false, titleFont, SwitchPause), }; }
void InitStandardButtons() { widgets = new ButtonWidget[showAlways ? 4 : 2]; widgets[0] = ButtonWidget.Create(game, -110, 30, 160, 35, "Yes", Anchor.Centre, Anchor.Centre, titleFont, OnYesClick); widgets[1] = ButtonWidget.Create(game, 110, 30, 160, 35, "No", Anchor.Centre, Anchor.Centre, titleFont, OnNoClick); if (!showAlways) { return; } widgets[2] = ButtonWidget.Create(game, -110, 80, 160, 35, "Always yes", Anchor.Centre, Anchor.Centre, titleFont, OnYesAlwaysClick); widgets[3] = ButtonWidget.Create(game, 110, 80, 160, 35, "Always no", Anchor.Centre, Anchor.Centre, titleFont, OnNoAlwaysClick); }
protected int MakeWidgets(int y, int arrowsY, int leftLength, string title, int btnWidth) { int i, origin = y, xOffset = btnWidth / 2 + 5; for (i = 0; i < binds.Length; i++) { if (i == leftLength) { y = origin; // reset y for next column } int xDir = leftLength == -1 ? 0 : (i < leftLength ? -1 : 1); string text = ButtonText(i); widgets[i] = ButtonWidget.Create(game, btnWidth, text, titleFont, OnBindingClick) .SetLocation(Anchor.Centre, Anchor.Centre, xDir * xOffset, y); y += 50; // distance between buttons } widgets[i++] = TextWidget.Create(game, title, titleFont) .SetLocation(Anchor.Centre, Anchor.Centre, 0, -180); if (game.UseClassicOptions) { widgets[i++] = MakeBack("Done", titleFont, SwitchClassicOptions); } else { widgets[i++] = MakeBack("Done", titleFont, SwitchOptions); } if (leftPage == null && rightPage == null) { return(i); } ButtonWidget left = ButtonWidget.Create(game, 40, "<", titleFont, leftPage) .SetLocation(Anchor.Centre, Anchor.Centre, -btnWidth - 35, arrowsY); left.Disabled = leftPage == null; widgets[i++] = left; ButtonWidget right = ButtonWidget.Create(game, 40, ">", titleFont, rightPage) .SetLocation(Anchor.Centre, Anchor.Centre, btnWidth + 35, arrowsY); right.Disabled = rightPage == null; widgets[i++] = right; return(i); }
protected ButtonWidget MakeBool(int dir, int y, string text, string optKey, ClickHandler onClick, Func <Game, bool> getter, Action <Game, bool> setter) { string optName = text; text = text + ": " + (getter(game) ? "ON" : "OFF"); ButtonWidget widget = ButtonWidget.Create(game, 160 * dir, y, 301, 41, text, Anchor.Centre, Anchor.Centre, titleFont, onClick); widget.Metadata = optName; widget.GetValue = g => getter(g) ? "yes" : "no"; widget.SetValue = (g, v) => { setter(g, v == "yes"); Options.Set(optKey, v == "yes"); widget.SetText((string)widget.Metadata + ": " + (v == "yes" ? "ON" : "OFF")); }; return(widget); }