Added new setting : Scroll Speed (added to cnc & ra)

This commit is contained in:
unknown
2010-09-30 02:12:11 +02:00
committed by Chris Forbes
parent c0ca35a4ff
commit de429a4c62
5 changed files with 199 additions and 164 deletions

View File

@@ -69,6 +69,7 @@ namespace OpenRA.GameRules
// Behaviour settings // Behaviour settings
public bool ViewportEdgeScroll = true; public bool ViewportEdgeScroll = true;
public bool InverseDragScroll = false; public bool InverseDragScroll = false;
public float ViewportEdgeScrollStep = 0.1f; // 0.1f equals 10 - Gecko
// Internal game settings // Internal game settings
public int Timestep = 40; public int Timestep = 40;

View File

@@ -53,6 +53,14 @@ namespace OpenRA.Widgets.Delegates
Game.Settings.Game.ViewportEdgeScroll ^= true; Game.Settings.Game.ViewportEdgeScroll ^= true;
return true; return true;
}; };
// Added scroll sensitivity - Gecko
var edgeScrollSlider = general.GetWidget<SliderWidget>("EDGE_SCROLL_AMOUNT");
if (edgeScrollSlider != null) // Backwards compatible - Gecko
{
edgeScrollSlider.OnChange += x => { x += 0.1f; Game.Settings.Game.ViewportEdgeScrollStep = x; };
edgeScrollSlider.GetOffset = () => { return Game.Settings.Game.ViewportEdgeScrollStep - 0.1f; };
}
var inverseScroll = general.GetWidget<CheckboxWidget>("INVERSE_SCROLL"); var inverseScroll = general.GetWidget<CheckboxWidget>("INVERSE_SCROLL");
inverseScroll.Checked = () => Game.Settings.Game.InverseDragScroll; inverseScroll.Checked = () => Game.Settings.Game.InverseDragScroll;

View File

@@ -1,172 +1,174 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS) * Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made * This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License * available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information, * as published by the Free Software Foundation. For more information,
* see LICENSE. * see LICENSE.
*/ */
#endregion #endregion
using System; using System;
using OpenRA.Graphics; using OpenRA.Graphics;
namespace OpenRA.Widgets namespace OpenRA.Widgets
{ {
[Flags] [Flags]
public enum ScrollDirection public enum ScrollDirection
{ {
None = 0, None = 0,
Up = 1, Up = 1,
Left = 2, Left = 2,
Down = 4, Down = 4,
Right = 8 Right = 8
} }
class ViewportScrollControllerWidget : Widget class ViewportScrollControllerWidget : Widget
{ {
public int EdgeScrollThreshold = 15; public int EdgeScrollThreshold = 15;
ScrollDirection Keyboard; ScrollDirection Keyboard;
ScrollDirection Edge; ScrollDirection Edge;
public ViewportScrollControllerWidget() : base() { } public ViewportScrollControllerWidget() : base() { }
protected ViewportScrollControllerWidget(ViewportScrollControllerWidget widget) : base(widget) {} protected ViewportScrollControllerWidget(ViewportScrollControllerWidget widget) : base(widget) {}
public override void DrawInner( World world ) {} public override void DrawInner( World world ) {}
public override bool HandleInputInner(MouseInput mi) public override bool HandleInputInner(MouseInput mi)
{ {
if (mi.Event == MouseInputEvent.Move && if (mi.Event == MouseInputEvent.Move &&
(mi.Button == MouseButton.Middle || mi.Button == (MouseButton.Left | MouseButton.Right))) (mi.Button == MouseButton.Middle || mi.Button == (MouseButton.Left | MouseButton.Right)))
{ {
int InverseScroll = Game.Settings.Game.InverseDragScroll ? -1 : 1; int InverseScroll = Game.Settings.Game.InverseDragScroll ? -1 : 1;
Game.viewport.Scroll((Viewport.LastMousePos - mi.Location) * InverseScroll); Game.viewport.Scroll((Viewport.LastMousePos - mi.Location) * InverseScroll);
return true; return true;
} }
return false; return false;
} }
public override string GetCursor(int2 pos) public override string GetCursor(int2 pos)
{ {
if (!Game.Settings.Game.ViewportEdgeScroll) if (!Game.Settings.Game.ViewportEdgeScroll)
return null; return null;
if (Edge.Includes(ScrollDirection.Up) && Edge.Includes(ScrollDirection.Left)){ if (Edge.Includes(ScrollDirection.Up) && Edge.Includes(ScrollDirection.Left)){
ScrollDirection BlockedDirections = Game.viewport.GetBlockedDirections(); ScrollDirection BlockedDirections = Game.viewport.GetBlockedDirections();
if(BlockedDirections.Includes(ScrollDirection.Up) && BlockedDirections.Includes(ScrollDirection.Left)) if(BlockedDirections.Includes(ScrollDirection.Up) && BlockedDirections.Includes(ScrollDirection.Left))
return "scroll-tl-blocked"; return "scroll-tl-blocked";
else else
return "scroll-tl"; return "scroll-tl";
} }
if (Edge.Includes(ScrollDirection.Up) && Edge.Includes(ScrollDirection.Right)){ if (Edge.Includes(ScrollDirection.Up) && Edge.Includes(ScrollDirection.Right)){
ScrollDirection BlockedDirections = Game.viewport.GetBlockedDirections(); ScrollDirection BlockedDirections = Game.viewport.GetBlockedDirections();
if (BlockedDirections.Includes(ScrollDirection.Up) && BlockedDirections.Includes(ScrollDirection.Right)) if (BlockedDirections.Includes(ScrollDirection.Up) && BlockedDirections.Includes(ScrollDirection.Right))
return "scroll-tr-blocked"; return "scroll-tr-blocked";
else else
return "scroll-tr"; return "scroll-tr";
} }
if (Edge.Includes(ScrollDirection.Down) && Edge.Includes(ScrollDirection.Left)){ if (Edge.Includes(ScrollDirection.Down) && Edge.Includes(ScrollDirection.Left)){
ScrollDirection BlockedDirections = Game.viewport.GetBlockedDirections(); ScrollDirection BlockedDirections = Game.viewport.GetBlockedDirections();
if (BlockedDirections.Includes(ScrollDirection.Down) && BlockedDirections.Includes(ScrollDirection.Left)) if (BlockedDirections.Includes(ScrollDirection.Down) && BlockedDirections.Includes(ScrollDirection.Left))
return "scroll-bl-blocked"; return "scroll-bl-blocked";
else else
return "scroll-bl"; return "scroll-bl";
} }
if (Edge.Includes(ScrollDirection.Down) && Edge.Includes(ScrollDirection.Right)){ if (Edge.Includes(ScrollDirection.Down) && Edge.Includes(ScrollDirection.Right)){
ScrollDirection BlockedDirections = Game.viewport.GetBlockedDirections(); ScrollDirection BlockedDirections = Game.viewport.GetBlockedDirections();
if (BlockedDirections.Includes(ScrollDirection.Down) && BlockedDirections.Includes(ScrollDirection.Right)) if (BlockedDirections.Includes(ScrollDirection.Down) && BlockedDirections.Includes(ScrollDirection.Right))
return "scroll-br-blocked"; return "scroll-br-blocked";
else else
return "scroll-br"; return "scroll-br";
} }
if (Edge.Includes(ScrollDirection.Up)) if (Edge.Includes(ScrollDirection.Up))
if (Game.viewport.GetBlockedDirections().Includes(ScrollDirection.Up)) if (Game.viewport.GetBlockedDirections().Includes(ScrollDirection.Up))
return "scroll-t-blocked"; return "scroll-t-blocked";
else else
return "scroll-t"; return "scroll-t";
if (Edge.Includes(ScrollDirection.Down)) if (Edge.Includes(ScrollDirection.Down))
if (Game.viewport.GetBlockedDirections().Includes(ScrollDirection.Down)) if (Game.viewport.GetBlockedDirections().Includes(ScrollDirection.Down))
return "scroll-b-blocked"; return "scroll-b-blocked";
else else
return "scroll-b"; return "scroll-b";
if (Edge.Includes(ScrollDirection.Left)) if (Edge.Includes(ScrollDirection.Left))
if (Game.viewport.GetBlockedDirections().Includes(ScrollDirection.Left)) if (Game.viewport.GetBlockedDirections().Includes(ScrollDirection.Left))
return "scroll-l-blocked"; return "scroll-l-blocked";
else else
return "scroll-l"; return "scroll-l";
if (Edge.Includes(ScrollDirection.Right)) if (Edge.Includes(ScrollDirection.Right))
if (Game.viewport.GetBlockedDirections().Includes(ScrollDirection.Right)) if (Game.viewport.GetBlockedDirections().Includes(ScrollDirection.Right))
return "scroll-r-blocked"; return "scroll-r-blocked";
else else
return "scroll-r"; return "scroll-r";
return null; return null;
} }
public override bool LoseFocus (MouseInput mi) public override bool LoseFocus (MouseInput mi)
{ {
Keyboard = ScrollDirection.None; Keyboard = ScrollDirection.None;
return base.LoseFocus(mi); return base.LoseFocus(mi);
} }
public override bool HandleKeyPressInner(KeyInput e) public override bool HandleKeyPressInner(KeyInput e)
{ {
switch (e.KeyName) switch (e.KeyName)
{ {
case "up": Keyboard = Keyboard.Set(ScrollDirection.Up, (e.Event == KeyInputEvent.Down)); return true; case "up": Keyboard = Keyboard.Set(ScrollDirection.Up, (e.Event == KeyInputEvent.Down)); return true;
case "down": Keyboard = Keyboard.Set(ScrollDirection.Down, (e.Event == KeyInputEvent.Down)); return true; case "down": Keyboard = Keyboard.Set(ScrollDirection.Down, (e.Event == KeyInputEvent.Down)); return true;
case "left": Keyboard = Keyboard.Set(ScrollDirection.Left, (e.Event == KeyInputEvent.Down)); return true; case "left": Keyboard = Keyboard.Set(ScrollDirection.Left, (e.Event == KeyInputEvent.Down)); return true;
case "right": Keyboard = Keyboard.Set(ScrollDirection.Right, (e.Event == KeyInputEvent.Down)); return true; case "right": Keyboard = Keyboard.Set(ScrollDirection.Right, (e.Event == KeyInputEvent.Down)); return true;
} }
return false; return false;
} }
public override void Tick(World world) public override void Tick(World world)
{ {
Edge = ScrollDirection.None; Edge = ScrollDirection.None;
if (Game.Settings.Game.ViewportEdgeScroll && Game.HasInputFocus) if (Game.Settings.Game.ViewportEdgeScroll && Game.HasInputFocus)
{ {
// Check for edge-scroll // Check for edge-scroll
if (Viewport.LastMousePos.X < EdgeScrollThreshold) if (Viewport.LastMousePos.X < EdgeScrollThreshold)
Edge = Edge.Set(ScrollDirection.Left, true); Edge = Edge.Set(ScrollDirection.Left, true);
if (Viewport.LastMousePos.Y < EdgeScrollThreshold) if (Viewport.LastMousePos.Y < EdgeScrollThreshold)
Edge = Edge.Set(ScrollDirection.Up, true); Edge = Edge.Set(ScrollDirection.Up, true);
if (Viewport.LastMousePos.X >= Game.viewport.Width - EdgeScrollThreshold) if (Viewport.LastMousePos.X >= Game.viewport.Width - EdgeScrollThreshold)
Edge = Edge.Set(ScrollDirection.Right, true); Edge = Edge.Set(ScrollDirection.Right, true);
if (Viewport.LastMousePos.Y >= Game.viewport.Height - EdgeScrollThreshold) if (Viewport.LastMousePos.Y >= Game.viewport.Height - EdgeScrollThreshold)
Edge = Edge.Set(ScrollDirection.Down, true); Edge = Edge.Set(ScrollDirection.Down, true);
} }
if(Keyboard != ScrollDirection.None || Edge != ScrollDirection.None) if(Keyboard != ScrollDirection.None || Edge != ScrollDirection.None)
{ {
var scroll = new float2(0,0); var scroll = new float2(0, 0);
if (Keyboard.Includes(ScrollDirection.Up) || Edge.Includes(ScrollDirection.Up))
scroll += new float2(0, -10); // Modified to use the ViewportEdgeScrollStep setting - Gecko
if (Keyboard.Includes(ScrollDirection.Right) || Edge.Includes(ScrollDirection.Right)) if (Keyboard.Includes(ScrollDirection.Up) || Edge.Includes(ScrollDirection.Up))
scroll += new float2(10, 0); scroll += new float2(0, -(Game.Settings.Game.ViewportEdgeScrollStep * 100));
if (Keyboard.Includes(ScrollDirection.Down) || Edge.Includes(ScrollDirection.Down)) if (Keyboard.Includes(ScrollDirection.Right) || Edge.Includes(ScrollDirection.Right))
scroll += new float2(0, 10); scroll += new float2((Game.Settings.Game.ViewportEdgeScrollStep * 100), 0);
if (Keyboard.Includes(ScrollDirection.Left) || Edge.Includes(ScrollDirection.Left)) if (Keyboard.Includes(ScrollDirection.Down) || Edge.Includes(ScrollDirection.Down))
scroll += new float2(-10, 0); scroll += new float2(0, (Game.Settings.Game.ViewportEdgeScrollStep * 100));
if (Keyboard.Includes(ScrollDirection.Left) || Edge.Includes(ScrollDirection.Left))
Game.viewport.Scroll(scroll); scroll += new float2(-(Game.Settings.Game.ViewportEdgeScrollStep * 100), 0);
}
} Game.viewport.Scroll(scroll);
}
public override Widget Clone() { return new ViewportScrollControllerWidget(this); } }
}
public override Widget Clone() { return new ViewportScrollControllerWidget(this); }
public static class ViewportExts }
{
public static bool Includes(this ScrollDirection d, ScrollDirection s) public static class ViewportExts
{ {
return (d & s) == s; public static bool Includes(this ScrollDirection d, ScrollDirection s)
} {
return (d & s) == s;
public static ScrollDirection Set(this ScrollDirection d, ScrollDirection s, bool val) }
{
return (d.Includes(s) != val) ? d ^ s : d; public static ScrollDirection Set(this ScrollDirection d, ScrollDirection s, bool val)
} {
} return (d.Includes(s) != val) ? d ^ s : d;
}
}
} }

View File

@@ -90,6 +90,18 @@ Background@SETTINGS_MENU:
Width:200 Width:200
Height:20 Height:20
Text: Enable Edge Scrolling Text: Enable Edge Scrolling
Label@EDGE_SCROLL_AMOUNT_LABEL:
Id:EDGE_SCROLL_AMOUNT_LABEL
X:0
Y:70
Text: Scroll Speed
Slider@EDGE_SCROLL_AMOUNT:
Id:EDGE_SCROLL_AMOUNT
X:130
Y:60
Width:250
Height:20
Ticks:100
Checkbox@INVERSE_SCROLL: Checkbox@INVERSE_SCROLL:
Id:INVERSE_SCROLL Id:INVERSE_SCROLL
X:0 X:0

View File

@@ -91,6 +91,18 @@ Background@SETTINGS_MENU:
Width:200 Width:200
Height:20 Height:20
Text: Enable Edge Scrolling Text: Enable Edge Scrolling
Label@EDGE_SCROLL_AMOUNT_LABEL:
Id:EDGE_SCROLL_AMOUNT_LABEL
X:0
Y:70
Text: Scroll Speed
Slider@EDGE_SCROLL_AMOUNT:
Id:EDGE_SCROLL_AMOUNT
X:130
Y:60
Width:250
Height:20
Ticks:100
Checkbox@INVERSE_SCROLL: Checkbox@INVERSE_SCROLL:
Id:INVERSE_SCROLL Id:INVERSE_SCROLL
X:0 X:0