Fix crash when clicking on graphics options button twice in very quick succession, then clicking on 'ok'.

This commit is contained in:
UnknownShadow200 2018-02-03 12:22:03 +11:00
parent 5860746eda
commit 132d83b9aa
5 changed files with 19 additions and 16 deletions

View File

@ -119,7 +119,7 @@ namespace ClassicalSharp.Gui.Screens {
void DefaultButtonClick(Game game, Widget widget, MouseButton btn, int x, int y) { void DefaultButtonClick(Game game, Widget widget, MouseButton btn, int x, int y) {
if (btn != MouseButton.Left) return; if (btn != MouseButton.Left) return;
int index = IndexOfWidget(targetWidget); int index = IndexOfWidget(activeButton);
string defValue = defaultValues[index]; string defValue = defaultValues[index];
input.Clear(); input.Clear();

View File

@ -85,7 +85,7 @@ namespace ClassicalSharp.Gui.Screens {
} }
void HandleFontChange() { void HandleFontChange() {
int selIndex = IndexOfWidget(selectedWidget); int selIndex = IndexOfWidget(selectedButton);
game.Events.RaiseChatFontChanged(); game.Events.RaiseChatFontChanged();
base.Dispose(); base.Dispose();
base.Init(); base.Init();
@ -102,7 +102,7 @@ namespace ClassicalSharp.Gui.Screens {
} }
if (selIndex >= 0) if (selIndex >= 0)
selectedWidget = (ButtonWidget)widgets[selIndex]; selectedButton = (ButtonWidget)widgets[selIndex];
} }
void MakeValidators() { void MakeValidators() {

View File

@ -185,7 +185,7 @@ namespace ClassicalSharp.Gui.Screens {
void DefaultButtonClick(Game game, Widget widget, MouseButton btn, int x, int y) { void DefaultButtonClick(Game game, Widget widget, MouseButton btn, int x, int y) {
if (btn != MouseButton.Left) return; if (btn != MouseButton.Left) return;
int index = IndexOfWidget(targetWidget); int index = IndexOfWidget(activeButton);
string defValue = defaultValues[index]; string defValue = defaultValues[index];
input.Clear(); input.Clear();

View File

@ -86,15 +86,15 @@ namespace ClassicalSharp.Gui.Screens {
base.Dispose(); base.Dispose();
} }
protected ButtonWidget selectedWidget, targetWidget; protected ButtonWidget selectedButton, activeButton;
protected override void WidgetSelected(Widget widget) { protected override void WidgetSelected(Widget widget) {
ButtonWidget button = widget as ButtonWidget; ButtonWidget button = widget as ButtonWidget;
if (selectedWidget == button || button == null || if (selectedButton == button || button == null ||
button == widgets[widgets.Length - 2]) return; button == widgets[widgets.Length - 2]) return;
selectedWidget = button; selectedButton = button;
if (targetWidget != null) return; if (activeButton != null) return;
UpdateDescription(selectedWidget); UpdateDescription(selectedButton);
} }
protected void UpdateDescription(ButtonWidget widget) { protected void UpdateDescription(ButtonWidget widget) {
@ -133,10 +133,10 @@ namespace ClassicalSharp.Gui.Screens {
} }
void ShowExtendedHelp() { void ShowExtendedHelp() {
bool canShow = input == null && selectedWidget != null && descriptions != null; bool canShow = input == null && selectedButton != null && descriptions != null;
if (!canShow) return; if (!canShow) return;
int index = IndexOfWidget(selectedWidget); int index = IndexOfWidget(selectedButton);
if (index < 0 || index >= descriptions.Length) return; if (index < 0 || index >= descriptions.Length) return;
string[] desc = descriptions[index]; string[] desc = descriptions[index];
if (desc == null) return; if (desc == null) return;
@ -186,7 +186,7 @@ namespace ClassicalSharp.Gui.Screens {
return; return;
} }
targetWidget = selectedWidget; activeButton = button;
InputClosed(); InputClosed();
input = MenuInputWidget.Create(game, 400, 30, input = MenuInputWidget.Create(game, 400, 30,
@ -200,7 +200,7 @@ namespace ClassicalSharp.Gui.Screens {
.SetLocation(Anchor.Centre, Anchor.Centre, 240, 110); .SetLocation(Anchor.Centre, Anchor.Centre, 240, 110);
InputOpened(); InputOpened();
UpdateDescription(targetWidget); UpdateDescription(activeButton);
} }
void InputClick(Game game, Widget widget, MouseButton btn, int x, int y) { void InputClick(Game game, Widget widget, MouseButton btn, int x, int y) {
@ -222,11 +222,11 @@ namespace ClassicalSharp.Gui.Screens {
void ChangeSetting() { void ChangeSetting() {
string text = input.Text.ToString(); string text = input.Text.ToString();
if (((MenuInputWidget)input).Validator.IsValidValue(text)) { if (((MenuInputWidget)input).Validator.IsValidValue(text)) {
SetButtonValue(targetWidget, text); SetButtonValue(activeButton, text);
} }
UpdateDescription(targetWidget); UpdateDescription(activeButton);
targetWidget = null; activeButton = null;
InputClosed(); InputClosed();
} }

View File

@ -19,6 +19,9 @@ typedef struct HotkeyData_ {
#define HOTKEYS_MAX_COUNT 256 #define HOTKEYS_MAX_COUNT 256
HotkeyData HotkeysList[HOTKEYS_MAX_COUNT]; HotkeyData HotkeysList[HOTKEYS_MAX_COUNT];
StringsBuffer HotkeysText; StringsBuffer HotkeysText;
#define HOTKEYS_FLAG_CTRL 1
#define HOTKEYS_FLAG_SHIFT 2
#define HOTKEYS_FLAT_ALT 4
void Hotkeys_Add(Key baseKey, UInt8 flags, STRING_PURE String* text, bool more); void Hotkeys_Add(Key baseKey, UInt8 flags, STRING_PURE String* text, bool more);
bool Hotkeys_Remove(Key baseKey, UInt8 flags); bool Hotkeys_Remove(Key baseKey, UInt8 flags);