Skip to content

Commit bb81e1b

Browse files
committed
adapt ca85609 from MAO
1 parent 367b278 commit bb81e1b

File tree

5 files changed

+62
-8
lines changed

5 files changed

+62
-8
lines changed

Intersect.Client.Core/Core/Input.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,33 @@ public static partial class Input
3737

3838
public static HandleKeyEvent? MouseUp { get => _mouseUp; set => _mouseUp = value; }
3939

40-
private static void HandleZoomOut()
40+
public static void HandleZoomOut(bool wrap = true)
4141
{
42-
Globals.Database.WorldZoom /= 2;
43-
if (Globals.Database.WorldZoom < Graphics.MinimumWorldScale)
42+
var nextZoom = Globals.Database.WorldZoom / 2;
43+
if (nextZoom < Graphics.MinimumWorldScale)
4444
{
45-
Globals.Database.WorldZoom = Graphics.MaximumWorldScale;
45+
if (wrap)
46+
{
47+
Globals.Database.WorldZoom = Graphics.MaximumWorldScale;
48+
}
49+
return;
4650
}
51+
52+
Globals.Database.WorldZoom = nextZoom;
4753
}
4854

49-
private static void HandleZoomIn()
55+
public static void HandleZoomIn(bool wrap = true)
5056
{
51-
Globals.Database.WorldZoom *= 2;
52-
if (Globals.Database.WorldZoom > Graphics.MaximumWorldScale)
57+
var nextZoom = Globals.Database.WorldZoom * 2;
58+
if (nextZoom > Graphics.MaximumWorldScale)
5359
{
54-
Globals.Database.WorldZoom = Graphics.MinimumWorldScale;
60+
if (wrap)
61+
{
62+
Globals.Database.WorldZoom = Graphics.MinimumWorldScale;
63+
}
64+
return;
5565
}
66+
Globals.Database.WorldZoom = nextZoom;
5667
}
5768

5869
public static void OnKeyPressed(Keys modifier, Keys key)

Intersect.Client.Core/Interface/Shared/SettingsWindow.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public partial class SettingsWindow : Window
7878
private readonly LabeledSlider _worldScale;
7979
private readonly LabeledCheckBox _fullscreenCheckbox;
8080
private readonly LabeledCheckBox _lightingEnabledCheckbox;
81+
public readonly LabeledCheckBox _enableMouseScrollZoomCheckbox;
8182
private MenuItem? _customResolutionMenuItem;
8283

8384
// Audio Settings
@@ -422,6 +423,14 @@ public SettingsWindow(Base parent) : base(parent: parent, title: Strings.Setting
422423
Text = Strings.Settings.EnableLighting,
423424
};
424425

426+
// Video Settings - Enable Mouse Scroll Zoom Checkbox
427+
_enableMouseScrollZoomCheckbox = new LabeledCheckBox(parent: _videoContainer, name: nameof(_enableMouseScrollZoomCheckbox))
428+
{
429+
Dock = Pos.Top,
430+
Font = _defaultFont,
431+
Text = Strings.Settings.EnableMouseScrollZoom,
432+
};
433+
425434
_worldScale = new LabeledSlider(parent: _videoContainer, name: nameof(_worldScale))
426435
{
427436
Dock = Pos.Top,
@@ -929,6 +938,7 @@ public void Show(Base? returnTo)
929938
// Video Settings.
930939
_fullscreenCheckbox.IsChecked = Globals.Database.FullScreen;
931940
_lightingEnabledCheckbox.IsChecked = Globals.Database.EnableLighting;
941+
_enableMouseScrollZoomCheckbox.IsChecked = Globals.Database.EnableMouseScrollZoom;
932942

933943
// _uiScale.Value = Globals.Database.UIScale;
934944

@@ -1114,6 +1124,8 @@ private void SettingsApplyBtn_Clicked(Base sender, MouseButtonState arguments)
11141124

11151125
Globals.Database.EnableLighting = _lightingEnabledCheckbox.IsChecked;
11161126

1127+
Globals.Database.EnableMouseScrollZoom = _enableMouseScrollZoomCheckbox.IsChecked;
1128+
11171129
if (targetResolution > -1)
11181130
{
11191131
shouldReset = Globals.Database.TargetResolution != targetResolution || Graphics.Renderer?.HasOverrideResolution == true;

Intersect.Client.Core/Localization/Strings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,6 +2089,9 @@ public partial struct Settings
20892089
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
20902090
public static LocalizedString EnableLighting = @"Enable Light Effects";
20912091

2092+
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
2093+
public static LocalizedString EnableMouseScrollZoom = @"Enable Mouse Scroll Zoom";
2094+
20922095
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
20932096
public static LocalizedString FormatResolution = @"{00}x{01}";
20942097

Intersect.Client.Core/MonoGame/Input/MonoInput.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ private void CheckMouseButton(Keys modifier, ButtonState bs, MouseButton mb)
237237
}
238238
}
239239

240+
private const double ZoomDelayInMilliseconds = 300;
241+
private DateTime _lastZoomTime = DateTime.MinValue;
242+
240243
private void CheckMouseScrollWheel(int scrlVValue, int scrlHValue)
241244
{
242245
Pointf p = new Pointf(0, 0);
@@ -249,6 +252,27 @@ private void CheckMouseScrollWheel(int scrlVValue, int scrlHValue)
249252
new GwenInputMessage(IntersectInput.InputEvent.MouseScroll, p, MouseButton.Middle, Keys.Alt)
250253
);
251254

255+
var deltaV = Math.Sign(mMouseVScroll - scrlVValue);
256+
257+
if ((DateTime.Now - _lastZoomTime).TotalMilliseconds >= ZoomDelayInMilliseconds)
258+
259+
{
260+
261+
if ((InputHandler.HoveredControl == null || !InputHandler.HoveredControl.IsVisible)
262+
&& Globals.GameState == GameStates.InGame
263+
&& Globals.Database.EnableMouseScrollZoom)
264+
{
265+
if (deltaV < 0)
266+
{
267+
Core.Input.HandleZoomIn(false);
268+
}
269+
else
270+
{
271+
Core.Input.HandleZoomOut(false);
272+
}
273+
_lastZoomTime = DateTime.Now;
274+
}
275+
}
252276
mMouseVScroll = scrlVValue;
253277
mMouseHScroll = scrlHValue;
254278
}

Intersect.Client.Framework/Database/GameDatabase.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public abstract partial class GameDatabase
2727

2828
public bool EnableLighting { get; set; }
2929

30+
public bool EnableMouseScrollZoom { get; set; }
31+
3032
public bool StickyTarget { get; set; }
3133

3234
public bool AutoTurnToTarget { get; set; }
@@ -119,6 +121,7 @@ public virtual void LoadPreferences()
119121
TargetFps = LoadPreference(nameof(TargetFps), 0);
120122
FullScreen = LoadPreference(nameof(FullScreen), false);
121123
EnableLighting = LoadPreference(nameof(EnableLighting), true);
124+
EnableMouseScrollZoom = LoadPreference(nameof(EnableMouseScrollZoom), false);
122125
HideOthersOnWindowOpen = LoadPreference(nameof(HideOthersOnWindowOpen), true);
123126
AutoToggleChatLog = LoadPreference(nameof(AutoToggleChatLog), false);
124127
TargetAccountDirection = LoadPreference(nameof(TargetAccountDirection), false);
@@ -158,6 +161,7 @@ public virtual void SavePreferences()
158161
SavePreference(nameof(FullScreen), FullScreen);
159162
SavePreference(nameof(ShowFPSCounter), ShowFPSCounter);
160163
SavePreference(nameof(EnableLighting), EnableLighting);
164+
SavePreference(nameof(EnableMouseScrollZoom), EnableMouseScrollZoom);
161165
SavePreference(nameof(HideOthersOnWindowOpen), HideOthersOnWindowOpen);
162166
SavePreference(nameof(AutoToggleChatLog), AutoToggleChatLog);
163167
SavePreference(nameof(TargetAccountDirection), TargetAccountDirection);

0 commit comments

Comments
 (0)