Merge pull request #9518 from JoppyFurr/bleed

Tiberian Sun style right-click-and-drag scrolling implementation
This commit is contained in:
Pavel Penev
2015-10-04 14:45:21 +03:00
7 changed files with 63 additions and 10 deletions

View File

@@ -70,6 +70,7 @@ Also thanks to:
* Jeff Harris (jeff_1amstudios)
* Jes
* Joakim Lindberg (booom3)
* Joppy Furr
* Kanar
* Kenny Hoxworth (hoxworth)
* Krishnakanth Mallik

View File

@@ -19,7 +19,7 @@ using OpenRA.Traits;
namespace OpenRA
{
public enum MouseScrollType { Disabled, Standard, Inverted }
public enum MouseScrollType { Disabled, Standard, Inverted, Joystick }
public class ServerSettings
{
@@ -167,6 +167,7 @@ namespace OpenRA
public float ViewportEdgeScrollStep = 10f;
public float UIScrollSpeed = 50f;
public int SelectionDeadzone = 24;
public int JoystickScrollDeadzone = 8;
public bool UseClassicMouseStyle = false;
public bool AlwaysShowStatusBars = false;

View File

@@ -132,7 +132,7 @@ namespace OpenRA.Widgets
YieldMouseFocus(mi);
}
if (mi.Button == MouseButton.Right && mi.Event == MouseInputEvent.Down)
if (mi.Button == MouseButton.Right && mi.Event == MouseInputEvent.Up)
{
// Don't do anything while selecting
if (!hasBox)
@@ -318,4 +318,4 @@ namespace OpenRA.Widgets
return true;
}
}
}
}

View File

@@ -588,6 +588,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ "Disabled", MouseScrollType.Disabled },
{ "Standard", MouseScrollType.Standard },
{ "Inverted", MouseScrollType.Inverted },
{ "Joystick", MouseScrollType.Joystick },
};
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (o, itemTemplate) =>

View File

@@ -34,6 +34,8 @@ namespace OpenRA.Mods.Common.Widgets
public int EdgeScrollThreshold = 15;
public int EdgeCornerScrollThreshold = 35;
int2? joystickScrollStart, joystickScrollEnd;
static readonly Dictionary<ScrollDirection, string> ScrollCursors = new Dictionary<ScrollDirection, string>
{
{ ScrollDirection.Up | ScrollDirection.Left, "scroll-tl" },
@@ -87,6 +89,15 @@ namespace OpenRA.Mods.Common.Widgets
public override void Draw()
{
if (IsJoystickScrolling)
{
// Base the JoystickScrolling speed on the Scroll Speed slider
var rate = 0.01f * Game.Settings.Game.ViewportEdgeScrollStep;
var scroll = (joystickScrollEnd.Value - joystickScrollStart.Value).ToFloat2() * rate;
worldRenderer.Viewport.Scroll(scroll, false);
}
UpdateMouseover();
base.Draw();
}
@@ -147,18 +158,57 @@ namespace OpenRA.Mods.Common.Widgets
return null;
}
bool IsJoystickScrolling
{
get
{
return joystickScrollStart.HasValue && joystickScrollEnd.HasValue &&
(joystickScrollStart.Value - joystickScrollEnd.Value).Length > Game.Settings.Game.JoystickScrollDeadzone;
}
}
public override bool HandleMouseInput(MouseInput mi)
{
var scrolltype = Game.Settings.Game.MouseScroll;
if (scrolltype == MouseScrollType.Disabled)
return false;
if (mi.Event == MouseInputEvent.Move &&
(mi.Button == MouseButton.Middle || mi.Button == (MouseButton.Left | MouseButton.Right)))
if (scrolltype == MouseScrollType.Standard || scrolltype == MouseScrollType.Inverted)
{
var d = scrolltype == MouseScrollType.Inverted ? -1 : 1;
worldRenderer.Viewport.Scroll((Viewport.LastMousePos - mi.Location) * d, false);
return true;
if (mi.Event == MouseInputEvent.Move &&
(mi.Button == MouseButton.Middle || mi.Button == (MouseButton.Left | MouseButton.Right)))
{
var d = scrolltype == MouseScrollType.Inverted ? -1 : 1;
worldRenderer.Viewport.Scroll((Viewport.LastMousePos - mi.Location) * d, false);
return true;
}
}
// Tiberian Sun style right-click-and-drag scrolling
if (scrolltype == MouseScrollType.Joystick)
{
if (mi.Button == MouseButton.Right && mi.Event == MouseInputEvent.Down)
{
if (!TakeMouseFocus(mi))
return false;
joystickScrollStart = mi.Location;
}
if (mi.Button == MouseButton.Right && mi.Event == MouseInputEvent.Up)
{
var wasJoystickScrolling = IsJoystickScrolling;
joystickScrollStart = joystickScrollEnd = null;
YieldMouseFocus(mi);
if (wasJoystickScrolling)
return true;
}
if (mi.Event == MouseInputEvent.Move && mi.Button == MouseButton.Right && joystickScrollStart.HasValue)
{
joystickScrollEnd = mi.Location;
}
}
return false;

View File

@@ -333,7 +333,7 @@ Container@SETTINGS_PANEL:
Width: 160
Height: 20
Font: Regular
Text: Middle-Mouse Scrolling:
Text: Mouse Scrolling Method:
Align: Right
DropDownButton@MOUSE_SCROLL:
X: PARENT_RIGHT - WIDTH - 15

View File

@@ -337,7 +337,7 @@ Background@SETTINGS_PANEL:
Width: 160
Height: 20
Font: Regular
Text: Middle-Mouse Scrolling:
Text: Mouse Scrolling Method:
Align: Right
DropDownButton@MOUSE_SCROLL:
X: PARENT_RIGHT - WIDTH - 15