moved some input stuff from MainWindow to Game
This commit is contained in:
@@ -9,6 +9,7 @@ using OpenRa.Graphics;
|
|||||||
using OpenRa.Orders;
|
using OpenRa.Orders;
|
||||||
using OpenRa.Support;
|
using OpenRa.Support;
|
||||||
using OpenRa.Traits;
|
using OpenRa.Traits;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace OpenRa
|
namespace OpenRa
|
||||||
{
|
{
|
||||||
@@ -231,5 +232,62 @@ namespace OpenRa
|
|||||||
taken.Add(sp);
|
taken.Add(sp);
|
||||||
return sp;
|
return sp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static void DispatchMouseInput(MouseInputEvent ev, MouseEventArgs e, Keys ModifierKeys)
|
||||||
|
{
|
||||||
|
int sync = Game.world.SyncHash();
|
||||||
|
|
||||||
|
Game.viewport.DispatchMouseInput(
|
||||||
|
new MouseInput
|
||||||
|
{
|
||||||
|
Button = (MouseButton)(int)e.Button,
|
||||||
|
Event = ev,
|
||||||
|
Location = new int2(e.Location),
|
||||||
|
Modifiers = (Modifiers)(int)ModifierKeys,
|
||||||
|
});
|
||||||
|
|
||||||
|
if( sync != Game.world.SyncHash() )
|
||||||
|
throw new InvalidOperationException( "Desync in DispatchMouseInput" );
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void HandleKeyDown( KeyEventArgs e )
|
||||||
|
{
|
||||||
|
int sync = Game.world.SyncHash();
|
||||||
|
|
||||||
|
/* hack hack hack */
|
||||||
|
if( e.KeyCode == Keys.F8 && !Game.orderManager.GameStarted )
|
||||||
|
{
|
||||||
|
Game.controller.AddOrder(
|
||||||
|
new Order( "ToggleReady", Game.world.LocalPlayer.PlayerActor, null, int2.Zero, "" ) { IsImmediate = true } );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* temporary hack: DO NOT LEAVE IN */
|
||||||
|
if( e.KeyCode == Keys.F2 )
|
||||||
|
Game.world.LocalPlayer = Game.world.players[ ( Game.world.LocalPlayer.Index + 1 ) % 4 ];
|
||||||
|
if( e.KeyCode == Keys.F3 )
|
||||||
|
Game.controller.orderGenerator = new SellOrderGenerator();
|
||||||
|
if( e.KeyCode == Keys.F4 )
|
||||||
|
Game.controller.orderGenerator = new RepairOrderGenerator();
|
||||||
|
|
||||||
|
if( !Game.chat.isChatting )
|
||||||
|
if( e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9 )
|
||||||
|
Game.controller.DoControlGroup( (int)e.KeyCode - (int)Keys.D0, (Modifiers)(int)e.Modifiers );
|
||||||
|
|
||||||
|
if( sync != Game.world.SyncHash() )
|
||||||
|
throw new InvalidOperationException( "Desync in OnKeyDown" );
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void HandleKeyPress( KeyPressEventArgs e )
|
||||||
|
{
|
||||||
|
int sync = Game.world.SyncHash();
|
||||||
|
|
||||||
|
if( e.KeyChar == '\r' )
|
||||||
|
Game.chat.Toggle();
|
||||||
|
else if( Game.chat.isChatting )
|
||||||
|
Game.chat.TypeChar( e.KeyChar );
|
||||||
|
|
||||||
|
if( sync != Game.world.SyncHash() )
|
||||||
|
throw new InvalidOperationException( "Desync in OnKeyPress" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,28 +90,11 @@ namespace OpenRa
|
|||||||
|
|
||||||
int2 lastPos;
|
int2 lastPos;
|
||||||
|
|
||||||
void DispatchMouseInput(MouseInputEvent ev, MouseEventArgs e)
|
|
||||||
{
|
|
||||||
int sync = Game.world.SyncHash();
|
|
||||||
|
|
||||||
Game.viewport.DispatchMouseInput(
|
|
||||||
new MouseInput
|
|
||||||
{
|
|
||||||
Button = (MouseButton)(int)e.Button,
|
|
||||||
Event = ev,
|
|
||||||
Location = new int2(e.Location),
|
|
||||||
Modifiers = (Modifiers)(int)ModifierKeys,
|
|
||||||
});
|
|
||||||
|
|
||||||
if( sync != Game.world.SyncHash() )
|
|
||||||
throw new InvalidOperationException( "Desync in DispatchMouseInput" );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnMouseDown(MouseEventArgs e)
|
protected override void OnMouseDown(MouseEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnMouseDown(e);
|
base.OnMouseDown(e);
|
||||||
lastPos = new int2(e.Location);
|
lastPos = new int2(e.Location);
|
||||||
DispatchMouseInput(MouseInputEvent.Down, e);
|
Game.DispatchMouseInput(MouseInputEvent.Down, e, ModifierKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnMouseMove(MouseEventArgs e)
|
protected override void OnMouseMove(MouseEventArgs e)
|
||||||
@@ -125,57 +108,27 @@ namespace OpenRa
|
|||||||
lastPos = p;
|
lastPos = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
DispatchMouseInput(MouseInputEvent.Move, e);
|
Game.DispatchMouseInput(MouseInputEvent.Move, e, ModifierKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnMouseUp(MouseEventArgs e)
|
protected override void OnMouseUp(MouseEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnMouseUp(e);
|
base.OnMouseUp(e);
|
||||||
DispatchMouseInput(MouseInputEvent.Up, e);
|
Game.DispatchMouseInput(MouseInputEvent.Up, e, ModifierKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnKeyDown(KeyEventArgs e)
|
protected override void OnKeyDown(KeyEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnKeyDown(e);
|
base.OnKeyDown(e);
|
||||||
|
|
||||||
int sync = Game.world.SyncHash();
|
Game.HandleKeyDown( e );
|
||||||
|
|
||||||
/* hack hack hack */
|
|
||||||
if (e.KeyCode == Keys.F8 && !Game.orderManager.GameStarted)
|
|
||||||
{
|
|
||||||
Game.controller.AddOrder(
|
|
||||||
new Order( "ToggleReady", Game.world.LocalPlayer.PlayerActor, null, int2.Zero, "") { IsImmediate = true });
|
|
||||||
}
|
|
||||||
|
|
||||||
/* temporary hack: DO NOT LEAVE IN */
|
|
||||||
if (e.KeyCode == Keys.F2)
|
|
||||||
Game.world.LocalPlayer = Game.world.players[(Game.world.LocalPlayer.Index + 1) % 4];
|
|
||||||
if (e.KeyCode == Keys.F3)
|
|
||||||
Game.controller.orderGenerator = new SellOrderGenerator();
|
|
||||||
if (e.KeyCode == Keys.F4)
|
|
||||||
Game.controller.orderGenerator = new RepairOrderGenerator();
|
|
||||||
|
|
||||||
if (!Game.chat.isChatting)
|
|
||||||
if (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9)
|
|
||||||
Game.controller.DoControlGroup( (int)e.KeyCode - (int)Keys.D0, (Modifiers)(int)e.Modifiers );
|
|
||||||
|
|
||||||
if( sync != Game.world.SyncHash() )
|
|
||||||
throw new InvalidOperationException( "Desync in OnKeyDown" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnKeyPress(KeyPressEventArgs e)
|
protected override void OnKeyPress(KeyPressEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnKeyPress(e);
|
base.OnKeyPress(e);
|
||||||
|
|
||||||
int sync = Game.world.SyncHash();
|
Game.HandleKeyPress( e );
|
||||||
|
|
||||||
if (e.KeyChar == '\r')
|
|
||||||
Game.chat.Toggle();
|
|
||||||
else if (Game.chat.isChatting)
|
|
||||||
Game.chat.TypeChar(e.KeyChar);
|
|
||||||
|
|
||||||
if( sync != Game.world.SyncHash() )
|
|
||||||
throw new InvalidOperationException( "Desync in OnKeyPress" );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user