DEADSOFTWARE

Menu: Update scale only if it really changed
[d2df-sdl.git] / src / game / g_menu.pas
index 0e272d4b2368003b24f37f72edc929add4947cfd..f43a8c6459dcd52dc57c82c486f2d553ed8f6057 100644 (file)
@@ -38,6 +38,7 @@ var
   gMenuSmallFont: DWORD;
   PromptIP: string;
   PromptPort: Word;
+  TempScale: Integer = -1;
 
 implementation
 
@@ -161,7 +162,11 @@ begin
   gRevertPlayers := TGUISwitch(menu.GetControl('swRevertPlayers')).ItemIndex = 0;
   gChatBubble := TGUISwitch(menu.GetControl('swChatBubble')).ItemIndex;
   gPlayerIndicator := TGUISwitch(menu.GetControl('swPlayerIndicator')).ItemIndex = 0;
-  g_dbg_scale := TGUIScroll(menu.GetControl('scScaleFactor')).Value + 1;
+  if TGUIScroll(menu.GetControl('scScaleFactor')).Value <> TempScale then
+  begin
+    TempScale := TGUIScroll(menu.GetControl('scScaleFactor')).Value;
+    g_dbg_scale := TempScale + 1;
+  end;
 
   menu := TGUIMenu(g_GUI_GetWindow('OptionsControlsMenu').GetControl('mOptionsControlsMenu'));
 
@@ -293,14 +298,15 @@ begin
     end;
   end;
 
-  if e_JoysticksAvailable > 0 then
+  if e_HasJoysticks then
   begin
     menu := TGUIMenu(g_GUI_GetWindow('OptionsControlsJoystickMenu').GetControl('mOptionsControlsJoystickMenu'));
     with menu do
     begin
-      for i := 0 to e_JoysticksAvailable-1 do
-        e_JoystickDeadzones[i] := TGUIScroll(menu.GetControl('scDeadzone' + IntToStr(i))).Value*(32767 div 20);
-    end;
+      for i := 0 to e_MaxJoys - 1 do
+        if e_JoystickAvailable[i] then
+          e_JoystickDeadzones[i] := TGUIScroll(menu.GetControl('scDeadzone' + IntToStr(i))).Value*(32767 div 20)
+    end
   end;
 
   if g_touch_enabled then
@@ -368,7 +374,7 @@ begin
   if g_Game_IsClient then MC_SEND_PlayerSettings;
 
   g_Options_Write(GameDir+'/'+CONFIG_FILENAME);
-  g_Console_WriteConfig(GameDir + '/dfconfig.cfg');
+  g_Console_WriteGameConfig();
 end;
 
 procedure ReadOptions();
@@ -491,14 +497,15 @@ begin
     end;
   end;
 
-  if e_JoysticksAvailable > 0 then
+  if e_HasJoysticks then
   begin
     menu := TGUIMenu(g_GUI_GetWindow('OptionsControlsJoystickMenu').GetControl('mOptionsControlsJoystickMenu'));
     with menu do
     begin
-      for i := 0 to e_JoysticksAvailable-1 do
-        TGUIScroll(menu.GetControl('scDeadzone' + IntToStr(i))).Value := e_JoystickDeadzones[i] div (32767 div 20);
-    end;
+      for i := 0 to e_MaxJoys - 1 do
+        if e_JoystickAvailable[i] then
+          TGUIScroll(menu.GetControl('scDeadzone' + IntToStr(i))).Value := e_JoystickDeadzones[i] div (32767 div 20)
+    end
   end;
 
   if g_touch_enabled then
@@ -565,7 +572,8 @@ begin
   with TGUISwitch(menu.GetControl('swPlayerIndicator')) do
     if gPlayerIndicator then ItemIndex := 0 else ItemIndex := 1;
 
-  TGUIScroll(menu.GetControl('scScaleFactor')).Value := Round(g_dbg_scale - 1);
+  TempScale := Round(g_dbg_scale - 1);
+  TGUIScroll(menu.GetControl('scScaleFactor')).Value := TempScale;
 
   menu := TGUIMenu(g_GUI_GetWindow('OptionsPlayersP1Menu').GetControl('mOptionsPlayersP1Menu'));
 
@@ -1337,7 +1345,11 @@ var
   menu: TGUIMenu;
 begin
   menu := TGUIMenu(g_GUI_GetWindow('OptionsGameMenu').GetControl('mOptionsGameMenu'));
-  g_dbg_scale := TGUIScroll(menu.GetControl('scScaleFactor')).Value + 1;
+  if TGUIScroll(menu.GetControl('scScaleFactor')).Value <> TempScale then
+  begin
+    TempScale := TGUIScroll(menu.GetControl('scScaleFactor')).Value;
+    g_dbg_scale := TempScale + 1;
+  end;
 end;
 
 procedure ProcChangeTouchSettings(Sender: TGUIControl);
@@ -2797,7 +2809,7 @@ begin
     AddButton(nil, _lc[I_MENU_PLAYER_2_KBD], 'OptionsControlsP2Menu');
     {AddButton(nil, _lc[I_MENU_PLAYER_2_ALT], 'OptionsControlsP2MenuAlt');}
     AddButton(nil, _lc[I_MENU_PLAYER_2_WEAPONS], 'OptionsControlsP2MenuWeapons');
-    if e_JoysticksAvailable <> 0 then
+    if e_HasJoysticks then
     begin
       AddSpace();
       AddButton(nil, _lc[I_MENU_CONTROL_JOYSTICKS], 'OptionsControlsJoystickMenu');
@@ -2873,12 +2885,13 @@ begin
   with TGUIMenu(Menu.AddChild(TGUIMenu.Create(gMenuFont, gMenuSmallFont, _lc[I_MENU_CONTROL_JOYSTICKS]))) do
   begin
     Name := 'mOptionsControlsJoystickMenu';
-    for i := 0 to e_JoysticksAvailable-1 do
-      with AddScroll(Format(_lc[I_MENU_CONTROL_DEADZONE], [i + 1])) do
-      begin
-        Name := 'scDeadzone' + IntToStr(i);
-        Max := 20;
-      end;
+    for i := 0 to e_MaxJoys - 1 do
+      if e_JoystickAvailable[i] then
+        with AddScroll(Format(_lc[I_MENU_CONTROL_DEADZONE], [i + 1])) do
+        begin
+          Name := 'scDeadzone' + IntToStr(i);
+          Max := 20
+        end
   end;
   Menu.DefControl := 'mOptionsControlsJoystickMenu';
   g_GUI_AddWindow(Menu);