Merge pull request #9518 from JoppyFurr/bleed
Tiberian Sun style right-click-and-drag scrolling implementation
This commit is contained in:
1
AUTHORS
1
AUTHORS
@@ -70,6 +70,7 @@ Also thanks to:
|
|||||||
* Jeff Harris (jeff_1amstudios)
|
* Jeff Harris (jeff_1amstudios)
|
||||||
* Jes
|
* Jes
|
||||||
* Joakim Lindberg (booom3)
|
* Joakim Lindberg (booom3)
|
||||||
|
* Joppy Furr
|
||||||
* Kanar
|
* Kanar
|
||||||
* Kenny Hoxworth (hoxworth)
|
* Kenny Hoxworth (hoxworth)
|
||||||
* Krishnakanth Mallik
|
* Krishnakanth Mallik
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA
|
namespace OpenRA
|
||||||
{
|
{
|
||||||
public enum MouseScrollType { Disabled, Standard, Inverted }
|
public enum MouseScrollType { Disabled, Standard, Inverted, Joystick }
|
||||||
|
|
||||||
public class ServerSettings
|
public class ServerSettings
|
||||||
{
|
{
|
||||||
@@ -167,6 +167,7 @@ namespace OpenRA
|
|||||||
public float ViewportEdgeScrollStep = 10f;
|
public float ViewportEdgeScrollStep = 10f;
|
||||||
public float UIScrollSpeed = 50f;
|
public float UIScrollSpeed = 50f;
|
||||||
public int SelectionDeadzone = 24;
|
public int SelectionDeadzone = 24;
|
||||||
|
public int JoystickScrollDeadzone = 8;
|
||||||
|
|
||||||
public bool UseClassicMouseStyle = false;
|
public bool UseClassicMouseStyle = false;
|
||||||
public bool AlwaysShowStatusBars = false;
|
public bool AlwaysShowStatusBars = false;
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ namespace OpenRA.Widgets
|
|||||||
YieldMouseFocus(mi);
|
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
|
// Don't do anything while selecting
|
||||||
if (!hasBox)
|
if (!hasBox)
|
||||||
@@ -318,4 +318,4 @@ namespace OpenRA.Widgets
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -588,6 +588,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
{ "Disabled", MouseScrollType.Disabled },
|
{ "Disabled", MouseScrollType.Disabled },
|
||||||
{ "Standard", MouseScrollType.Standard },
|
{ "Standard", MouseScrollType.Standard },
|
||||||
{ "Inverted", MouseScrollType.Inverted },
|
{ "Inverted", MouseScrollType.Inverted },
|
||||||
|
{ "Joystick", MouseScrollType.Joystick },
|
||||||
};
|
};
|
||||||
|
|
||||||
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (o, itemTemplate) =>
|
Func<string, ScrollItemWidget, ScrollItemWidget> setupItem = (o, itemTemplate) =>
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
public int EdgeScrollThreshold = 15;
|
public int EdgeScrollThreshold = 15;
|
||||||
public int EdgeCornerScrollThreshold = 35;
|
public int EdgeCornerScrollThreshold = 35;
|
||||||
|
|
||||||
|
int2? joystickScrollStart, joystickScrollEnd;
|
||||||
|
|
||||||
static readonly Dictionary<ScrollDirection, string> ScrollCursors = new Dictionary<ScrollDirection, string>
|
static readonly Dictionary<ScrollDirection, string> ScrollCursors = new Dictionary<ScrollDirection, string>
|
||||||
{
|
{
|
||||||
{ ScrollDirection.Up | ScrollDirection.Left, "scroll-tl" },
|
{ ScrollDirection.Up | ScrollDirection.Left, "scroll-tl" },
|
||||||
@@ -87,6 +89,15 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
|
|
||||||
public override void Draw()
|
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();
|
UpdateMouseover();
|
||||||
base.Draw();
|
base.Draw();
|
||||||
}
|
}
|
||||||
@@ -147,18 +158,57 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
return null;
|
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)
|
public override bool HandleMouseInput(MouseInput mi)
|
||||||
{
|
{
|
||||||
var scrolltype = Game.Settings.Game.MouseScroll;
|
var scrolltype = Game.Settings.Game.MouseScroll;
|
||||||
if (scrolltype == MouseScrollType.Disabled)
|
if (scrolltype == MouseScrollType.Disabled)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (mi.Event == MouseInputEvent.Move &&
|
if (scrolltype == MouseScrollType.Standard || scrolltype == MouseScrollType.Inverted)
|
||||||
(mi.Button == MouseButton.Middle || mi.Button == (MouseButton.Left | MouseButton.Right)))
|
|
||||||
{
|
{
|
||||||
var d = scrolltype == MouseScrollType.Inverted ? -1 : 1;
|
if (mi.Event == MouseInputEvent.Move &&
|
||||||
worldRenderer.Viewport.Scroll((Viewport.LastMousePos - mi.Location) * d, false);
|
(mi.Button == MouseButton.Middle || mi.Button == (MouseButton.Left | MouseButton.Right)))
|
||||||
return true;
|
{
|
||||||
|
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;
|
return false;
|
||||||
|
|||||||
@@ -333,7 +333,7 @@ Container@SETTINGS_PANEL:
|
|||||||
Width: 160
|
Width: 160
|
||||||
Height: 20
|
Height: 20
|
||||||
Font: Regular
|
Font: Regular
|
||||||
Text: Middle-Mouse Scrolling:
|
Text: Mouse Scrolling Method:
|
||||||
Align: Right
|
Align: Right
|
||||||
DropDownButton@MOUSE_SCROLL:
|
DropDownButton@MOUSE_SCROLL:
|
||||||
X: PARENT_RIGHT - WIDTH - 15
|
X: PARENT_RIGHT - WIDTH - 15
|
||||||
|
|||||||
@@ -337,7 +337,7 @@ Background@SETTINGS_PANEL:
|
|||||||
Width: 160
|
Width: 160
|
||||||
Height: 20
|
Height: 20
|
||||||
Font: Regular
|
Font: Regular
|
||||||
Text: Middle-Mouse Scrolling:
|
Text: Mouse Scrolling Method:
|
||||||
Align: Right
|
Align: Right
|
||||||
DropDownButton@MOUSE_SCROLL:
|
DropDownButton@MOUSE_SCROLL:
|
||||||
X: PARENT_RIGHT - WIDTH - 15
|
X: PARENT_RIGHT - WIDTH - 15
|
||||||
|
|||||||
Reference in New Issue
Block a user