moved starting or stopping network mode to separate function
authorHolger Schemel <info@artsoft.org>
Mon, 1 Oct 2018 19:22:42 +0000 (21:22 +0200)
committerHolger Schemel <info@artsoft.org>
Mon, 1 Oct 2018 19:22:42 +0000 (21:22 +0200)
src/screens.c

index 7771f24ed7fd853ffef061927a2a04f1c01b76ad..6dd964f3f3df109cba6f08c22dcb2d8a825a004a 100644 (file)
@@ -5951,6 +5951,27 @@ static void execGadgetNetworkServer(void)
   ClickOnGadget(gi, MB_LEFTBUTTON);
 }
 
+static void ToggleNetworkModeIfNeeded(void)
+{
+  if (setup.network_mode == network.enabled)
+    return;
+
+  network.enabled = setup.network_mode;
+
+  FadeOut(REDRAW_ALL);
+
+  ClearField();
+
+  FadeIn(REDRAW_ALL);
+
+  if (network.enabled)
+    InitNetworkServer();
+  else
+    DisconnectFromNetworkServer();
+
+  DrawSetupScreen();
+}
+
 static struct
 {
   void *value;
@@ -6621,24 +6642,9 @@ static void changeSetupValue(int screen_pos, int setup_info_pos_raw, int dx)
   if (si->value == &setup.fullscreen)
     ToggleFullscreenOrChangeWindowScalingIfNeeded();
 
-  if (si->value == &setup.network_mode &&
-      setup.network_mode != network.enabled)
-  {
-    network.enabled = setup.network_mode;
-
-    FadeOut(REDRAW_ALL);
-
-    ClearField();
-
-    FadeIn(REDRAW_ALL);
-
-    if (network.enabled)
-      InitNetworkServer();
-    else
-      DisconnectFromNetworkServer();
-
-    DrawSetupScreen();
-  }
+  // network mode may have changed at this point
+  if (si->value == &setup.network_mode)
+    ToggleNetworkModeIfNeeded();
 }
 
 static struct TokenInfo *getSetupInfoFinal(struct TokenInfo *setup_info_orig)