protected override void ContextRecreated() { string flags = HotkeyListScreen.MakeFlagsString(curHotkey.Flags); if (curHotkey.Text == null) { curHotkey.Text = ""; } string staysOpen = curHotkey.StaysOpen ? "ON" : "OFF"; bool existed = origHotkey.BaseKey != Key.Unknown; widgets = new Widget[] { Make(0, -150, "Key: " + curHotkey.BaseKey, 300, titleFont, BaseKeyClick), Make(0, -100, "Modifiers:" + flags, 300, titleFont, ModifiersClick), MenuInputWidget.Create(game, 500, 30, curHotkey.Text, regularFont, new StringValidator()) .SetLocation(Anchor.Centre, Anchor.Centre, 0, -35), Make(-100, 10, "Input stays open: " + staysOpen, 300, titleFont, LeaveOpenClick), Make(0, 80, existed ? "Save changes" : "Add hotkey", 300, titleFont, SaveChangesClick), Make(0, 130, existed ? "Remove hotkey" : "Cancel", 300, titleFont, RemoveHotkeyClick), MakeBack(false, titleFont, SwitchPause), }; ((InputWidget)widgets[actionI]).ShowCaret = true; widgets[actionI].OnClick = InputClick; }
protected override void ContextRecreated() { string flags = MakeFlagsString(curHotkey.Flags); if (curHotkey.Text == null) { curHotkey.Text = ""; } string staysOpen = curHotkey.StaysOpen ? "ON" : "OFF"; bool existed = origHotkey.Trigger != Key.None; InputWidget input; input = MenuInputWidget.Create(game, 500, 30, curHotkey.Text, textFont, new StringValidator()) .SetLocation(Anchor.Centre, Anchor.Centre, 0, -35); input.ShowCaret = true; widgets = new Widget[] { Make(0, -150, "Key: " + curHotkey.Trigger, BaseKeyClick), Make(0, -100, "Modifiers:" + flags, ModifiersClick), input, Make(-100, 10, "Input stays open: " + staysOpen, LeaveOpenClick), Make(0, 80, existed ? "Save changes" : "Add hotkey", SaveChangesClick), Make(0, 130, existed ? "Remove hotkey" : "Cancel", RemoveHotkeyClick), MakeBack(false, titleFont, SwitchPause), }; }
InputWidget MakeInput(int y, bool seed, string value) { MenuInputValidator validator = seed ? new SeedValidator() : new IntegerValidator(1, 8192); InputWidget input = MenuInputWidget.Create(game, 200, 30, value, textFont, validator) .SetLocation(Anchor.Centre, Anchor.Centre, 0, y); input.MenuClick = InputClick; return(input); }
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); }
MenuInputWidget MakeInput(int y, bool seed, string value) { MenuInputValidator validator = seed ? new SeedValidator() : new IntegerValidator(1, 8192); MenuInputWidget widget = MenuInputWidget.Create( game, 0, y, 200, 30, value, Anchor.Centre, Anchor.Centre, regularFont, titleFont, validator); widget.Active = false; widget.OnClick = InputClick; return(widget); }
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), }; }
protected void OnInputClick(Game game, Widget widget) { ButtonWidget button = (ButtonWidget)widget; activeI = IndexWidget(button); DisposeExtendedHelp(); DisposeInput(); MenuInputValidator validator = validators[activeI]; input = MenuInputWidget.Create(game, 400, 30, button.GetValue(game), textFont, validator) .SetLocation(Anchor.Centre, Anchor.Centre, 0, 110); input.ShowCaret = true; widgets[widgets.Length - 1] = input; widgets[widgets.Length - 2] = ButtonWidget.Create(game, 40, "OK", titleFont, OKButtonClick) .SetLocation(Anchor.Centre, Anchor.Centre, 240, 110); widgets[widgets.Length - 3] = ButtonWidget.Create(game, 200, "Default value", titleFont, DefaultButtonClick) .SetLocation(Anchor.Centre, Anchor.Centre, 0, 150); }
InputWidget MakeInput(int y, bool seed, string value) { MenuInputValidator validator; if (seed) { validator = new SeedValidator(); } else { validator = new IntegerValidator(1, 8192); } InputWidget input = MenuInputWidget.Create(game, 200, 30, value, regularFont, validator) .SetLocation(Anchor.Centre, Anchor.Centre, 0, y); input.Active = false; input.OnClick = InputClick; return(input); }
protected void OnButtonClick(Game game, Widget widget) { ButtonWidget button = widget as ButtonWidget; if (button == null) { return; } DisposeExtendedHelp(); int index = IndexOfWidget(button); MenuInputValidator validator = validators[index]; if (validator is BooleanValidator) { string value = button.GetValue(game); SetButtonValue(button, value == "ON" ? "OFF" : "ON"); UpdateDescription(button); return; } else if (validator is EnumValidator) { Type type = ((EnumValidator)validator).EnumType; HandleEnumOption(button, type); return; } activeButton = button; InputClosed(); input = MenuInputWidget.Create(game, 400, 30, button.GetValue(game), textFont, validator) .SetLocation(Anchor.Centre, Anchor.Centre, 0, 110); input.ShowCaret = true; widgets[widgets.Length - 2] = input; widgets[widgets.Length - 1] = ButtonWidget.Create(game, 40, "OK", titleFont, OnOKButtonClick) .SetLocation(Anchor.Centre, Anchor.Centre, 240, 110); InputOpened(); UpdateDescription(activeButton); }
public override void Init() { game.Keyboard.KeyRepeat = true; base.Init(); regularFont = new Font(game.FontName, 16, FontStyle.Regular); inputWidget = MenuInputWidget.Create( game, 0, -30, 500, 30, "", Anchor.Centre, Anchor.Centre, regularFont, titleFont, new PathValidator()); widgets = new Widget[] { ButtonWidget.Create(game, 0, 20, 301, 40, "Save", Anchor.Centre, Anchor.Centre, titleFont, SaveClassic), ButtonWidget.Create(game, -150, 120, 201, 40, "Save schematic", Anchor.Centre, Anchor.Centre, titleFont, SaveSchematic), ChatTextWidget.Create(game, 110, 120, "&eCan be imported into MCEdit", Anchor.Centre, Anchor.Centre, regularFont), null, MakeBack(false, titleFont, (g, w) => g.Gui.SetNewScreen(new PauseScreen(g))), }; }
public override void Init() { game.Keyboard.KeyRepeat = true; base.Init(); regularFont = new Font(game.FontName, 16, FontStyle.Regular); string flags = HotkeyListScreen.MakeFlagsString(curHotkey.Flags); if (curHotkey.Text == null) { curHotkey.Text = ""; } string staysOpen = curHotkey.StaysOpen ? "yes" : "no"; bool existed = origHotkey.BaseKey != Key.Unknown; widgets = new Widget[] { Make(0, -150, "Key: " + curHotkey.BaseKey, 301, 40, titleFont, BaseKeyClick), Make(0, -100, "Modifiers:" + flags, 301, 40, titleFont, ModifiersClick), MenuInputWidget.Create( game, 0, -35, 500, 30, curHotkey.Text, Anchor.Centre, Anchor.Centre, regularFont, titleFont, new StringValidator(Utils.StringLength)), Make(-100, 10, "Input stays open: " + staysOpen, 301, 40, titleFont, LeaveOpenClick), Make(0, 80, existed ? "Save changes" : "Add hotkey", 301, 40, titleFont, SaveChangesClick), Make(0, 130, existed ? "Remove hotkey" : "Cancel", 301, 40, titleFont, RemoveHotkeyClick), MakeBack(false, titleFont, (g, w) => g.Gui.SetNewScreen(new PauseScreen(g))), }; }