diff --git a/OpenRa.DataStructures/float2.cs b/OpenRa.DataStructures/float2.cs index 8c6f3ef20d..6d2943b75b 100644 --- a/OpenRa.DataStructures/float2.cs +++ b/OpenRa.DataStructures/float2.cs @@ -56,6 +56,19 @@ namespace OpenRa public static float2 operator *( float2 a, float2 b ) { return new float2( a.X * b.X, a.Y * b.Y ); } public static float2 operator /( float2 a, float2 b ) { return new float2( a.X / b.X, a.Y / b.Y ); } + public static bool operator ==(float2 me, float2 other) { return (me.X == other.X && me.Y == other.Y); } + public static bool operator !=(float2 me, float2 other) { return !(me == other); } + public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); } + + public override bool Equals(object obj) + { + if (obj == null) + return false; + + float2 o = (float2)obj; + return o == this; + } + public static readonly float2 Zero = new float2(0, 0); public static bool WithinEpsilon(float2 a, float2 b, float e) diff --git a/OpenRa.Game/Controller.cs b/OpenRa.Game/Controller.cs index d4c78be2af..4c7bfa9a56 100644 --- a/OpenRa.Game/Controller.cs +++ b/OpenRa.Game/Controller.cs @@ -17,17 +17,45 @@ namespace OpenRa.Game this.game = game; } + float2 GetWorldPos(MouseInput mi) + { + return (1 / 24.0f) * (new float2(mi.Location.X, mi.Location.Y) + game.viewport.Location); + } + + float2? dragStart, dragEnd; public void HandleMouseInput(MouseInput mi) { if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Down) { - var xy = (1 / 24.0f) * (new float2(mi.Location.X, mi.Location.Y) + game.viewport.Location); + var xy = GetWorldPos(mi); if (orderGenerator != null) orderGenerator.Order(game, new int2((int)xy.X, (int)xy.Y)).Apply(game); + + else { dragStart = dragEnd = xy; } // todo: route all orders through netcode } + if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Move) + if (dragEnd != null) + dragEnd = GetWorldPos(mi); + + if (mi.Button == MouseButtons.Left && mi.Event == MouseInputEvent.Up) + if (dragStart.HasValue && !(dragStart.Value == GetWorldPos(mi))) + { + /* finalize drag selection */ + } + else + { + /* finalize click selection */ + } + + if (mi.Button == MouseButtons.None && mi.Event == MouseInputEvent.Move) + { + /* update the cursor to reflect the thing under us - note this + * needs to also happen when the *thing* changes, so per-frame hook */ + } + if (mi.Button == MouseButtons.Right && mi.Event == MouseInputEvent.Down) orderGenerator = null; }