more refs to Game.world (Controller)
This commit is contained in:
@@ -812,7 +812,7 @@ namespace OpenRa
|
|||||||
}
|
}
|
||||||
|
|
||||||
int2 lastMousePos;
|
int2 lastMousePos;
|
||||||
public bool HandleInput(MouseInput mi)
|
public bool HandleInput(World world, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Event == MouseInputEvent.Move)
|
if (mi.Event == MouseInputEvent.Move)
|
||||||
lastMousePos = mi.Location;
|
lastMousePos = mi.Location;
|
||||||
|
|||||||
@@ -43,15 +43,15 @@ namespace OpenRa
|
|||||||
|
|
||||||
List<Order> recentOrders = new List<Order>();
|
List<Order> recentOrders = new List<Order>();
|
||||||
|
|
||||||
void ApplyOrders(float2 xy, MouseInput mi)
|
void ApplyOrders(World world, float2 xy, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (orderGenerator == null) return;
|
if (orderGenerator == null) return;
|
||||||
|
|
||||||
var orders = orderGenerator.Order(Game.world, xy.ToInt2(), mi).ToArray();
|
var orders = orderGenerator.Order(world, xy.ToInt2(), mi).ToArray();
|
||||||
recentOrders.AddRange( orders );
|
recentOrders.AddRange( orders );
|
||||||
|
|
||||||
var voicedActor = orders.Select(o => o.Subject)
|
var voicedActor = orders.Select(o => o.Subject)
|
||||||
.FirstOrDefault(a => a.Owner == Game.world.LocalPlayer && a.traits.Contains<Unit>());
|
.FirstOrDefault(a => a.Owner == world.LocalPlayer && a.traits.Contains<Unit>());
|
||||||
|
|
||||||
var isMove = orders.Any(o => o.OrderString == "Move");
|
var isMove = orders.Any(o => o.OrderString == "Move");
|
||||||
var isAttack = orders.Any( o => o.OrderString == "Attack" );
|
var isAttack = orders.Any( o => o.OrderString == "Attack" );
|
||||||
@@ -61,7 +61,7 @@ namespace OpenRa
|
|||||||
Sound.PlayVoice(isAttack ? "Attack" : "Move", voicedActor);
|
Sound.PlayVoice(isAttack ? "Attack" : "Move", voicedActor);
|
||||||
|
|
||||||
if (isMove)
|
if (isMove)
|
||||||
Game.world.Add(new Effects.MoveFlash(Game.world, Game.CellSize * xy));
|
world.Add(new Effects.MoveFlash(world, Game.CellSize * xy));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ namespace OpenRa
|
|||||||
}
|
}
|
||||||
|
|
||||||
float2 dragStart, dragEnd;
|
float2 dragStart, dragEnd;
|
||||||
public bool HandleInput(MouseInput mi)
|
public bool HandleInput(World world, MouseInput mi)
|
||||||
{
|
{
|
||||||
var xy = Game.viewport.ViewToWorld(mi);
|
var xy = Game.viewport.ViewToWorld(mi);
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ namespace OpenRa
|
|||||||
{
|
{
|
||||||
if (!(orderGenerator is PlaceBuildingOrderGenerator))
|
if (!(orderGenerator is PlaceBuildingOrderGenerator))
|
||||||
dragStart = dragEnd = xy;
|
dragStart = dragEnd = xy;
|
||||||
ApplyOrders(xy, mi);
|
ApplyOrders(world, xy, mi);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Move)
|
if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Move)
|
||||||
@@ -94,8 +94,8 @@ namespace OpenRa
|
|||||||
{
|
{
|
||||||
if (orderGenerator is UnitOrderGenerator)
|
if (orderGenerator is UnitOrderGenerator)
|
||||||
{
|
{
|
||||||
var newSelection = Game.world.SelectActorsInBox(Game.CellSize * dragStart, Game.CellSize * xy);
|
var newSelection = world.SelectActorsInBox(Game.CellSize * dragStart, Game.CellSize * xy);
|
||||||
CombineSelection(newSelection, mi.Modifiers.HasModifier(Modifiers.Shift), dragStart == xy);
|
CombineSelection(world, newSelection, mi.Modifiers.HasModifier(Modifiers.Shift), dragStart == xy);
|
||||||
}
|
}
|
||||||
|
|
||||||
dragStart = dragEnd = xy;
|
dragStart = dragEnd = xy;
|
||||||
@@ -105,12 +105,12 @@ namespace OpenRa
|
|||||||
dragStart = dragEnd = xy;
|
dragStart = dragEnd = xy;
|
||||||
|
|
||||||
if (mi.Button == MouseButton.Right && mi.Event == MouseInputEvent.Down)
|
if (mi.Button == MouseButton.Right && mi.Event == MouseInputEvent.Down)
|
||||||
ApplyOrders(xy, mi);
|
ApplyOrders(world, xy, mi);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CombineSelection(IEnumerable<Actor> newSelection, bool isCombine, bool isClick)
|
void CombineSelection(World world, IEnumerable<Actor> newSelection, bool isCombine, bool isClick)
|
||||||
{
|
{
|
||||||
var oldSelection = (orderGenerator is UnitOrderGenerator)
|
var oldSelection = (orderGenerator is UnitOrderGenerator)
|
||||||
? (orderGenerator as UnitOrderGenerator).selection : new Actor[] { }.AsEnumerable();
|
? (orderGenerator as UnitOrderGenerator).selection : new Actor[] { }.AsEnumerable();
|
||||||
@@ -127,7 +127,7 @@ namespace OpenRa
|
|||||||
|
|
||||||
var voicedUnit = ((UnitOrderGenerator)orderGenerator).selection
|
var voicedUnit = ((UnitOrderGenerator)orderGenerator).selection
|
||||||
.Where(a => a.traits.Contains<Unit>()
|
.Where(a => a.traits.Contains<Unit>()
|
||||||
&& a.Owner == Game.world.LocalPlayer)
|
&& a.Owner == world.LocalPlayer)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
|
||||||
Sound.PlayVoice("Select", voicedUnit);
|
Sound.PlayVoice("Select", voicedUnit);
|
||||||
@@ -144,9 +144,9 @@ namespace OpenRa
|
|||||||
|
|
||||||
public float2 MousePosition { get { return dragEnd; } }
|
public float2 MousePosition { get { return dragEnd; } }
|
||||||
|
|
||||||
public Cursor ChooseCursor()
|
public Cursor ChooseCursor( World world )
|
||||||
{
|
{
|
||||||
int sync = Game.world.SyncHash();
|
int sync = world.SyncHash();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -157,18 +157,18 @@ namespace OpenRa
|
|||||||
Modifiers = GetModifierKeys(),
|
Modifiers = GetModifierKeys(),
|
||||||
};
|
};
|
||||||
|
|
||||||
return orderGenerator.GetCursor( Game.world, MousePosition.ToInt2(), mi );
|
return orderGenerator.GetCursor( world, MousePosition.ToInt2(), mi );
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if( sync != Game.world.SyncHash() )
|
if( sync != world.SyncHash() )
|
||||||
throw new InvalidOperationException( "Desync in Controller.ChooseCursor" );
|
throw new InvalidOperationException( "Desync in Controller.ChooseCursor" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Cache<int, List<Actor>> controlGroups = new Cache<int, List<Actor>>(_ => new List<Actor>());
|
Cache<int, List<Actor>> controlGroups = new Cache<int, List<Actor>>(_ => new List<Actor>());
|
||||||
|
|
||||||
public void DoControlGroup(int group, Modifiers mods)
|
public void DoControlGroup(World world, int group, Modifiers mods)
|
||||||
{
|
{
|
||||||
var uog = orderGenerator as UnitOrderGenerator;
|
var uog = orderGenerator as UnitOrderGenerator;
|
||||||
if (uog == null) return;
|
if (uog == null) return;
|
||||||
@@ -193,7 +193,7 @@ namespace OpenRa
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CombineSelection(controlGroups[group], mods.HasModifier(Modifiers.Shift), false);
|
CombineSelection(world, controlGroups[group], mods.HasModifier(Modifiers.Shift), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int? GetControlGroupForActor(Actor a)
|
public int? GetControlGroupForActor(Actor a)
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ namespace OpenRa
|
|||||||
{
|
{
|
||||||
int sync = Game.world.SyncHash();
|
int sync = Game.world.SyncHash();
|
||||||
|
|
||||||
Game.viewport.DispatchMouseInput(
|
Game.viewport.DispatchMouseInput( world,
|
||||||
new MouseInput
|
new MouseInput
|
||||||
{
|
{
|
||||||
Button = (MouseButton)(int)e.Button,
|
Button = (MouseButton)(int)e.Button,
|
||||||
@@ -271,7 +271,7 @@ namespace OpenRa
|
|||||||
|
|
||||||
if( !Game.chat.isChatting )
|
if( !Game.chat.isChatting )
|
||||||
if( e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9 )
|
if( e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9 )
|
||||||
Game.controller.DoControlGroup( (int)e.KeyCode - (int)Keys.D0, (Modifiers)(int)e.Modifiers );
|
Game.controller.DoControlGroup( world, (int)e.KeyCode - (int)Keys.D0, (Modifiers)(int)e.Modifiers );
|
||||||
|
|
||||||
if( sync != Game.world.SyncHash() )
|
if( sync != Game.world.SyncHash() )
|
||||||
throw new InvalidOperationException( "Desync in OnKeyDown" );
|
throw new InvalidOperationException( "Desync in OnKeyDown" );
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace OpenRa.Graphics
|
|||||||
{
|
{
|
||||||
interface IHandleInput
|
interface IHandleInput
|
||||||
{
|
{
|
||||||
bool HandleInput(MouseInput mi);
|
bool HandleInput(World world, MouseInput mi);
|
||||||
}
|
}
|
||||||
|
|
||||||
class Viewport
|
class Viewport
|
||||||
@@ -85,7 +85,7 @@ namespace OpenRa.Graphics
|
|||||||
Game.chrome.DrawLobby( world );
|
Game.chrome.DrawLobby( world );
|
||||||
}
|
}
|
||||||
|
|
||||||
var c = Game.chrome.HitTest(mousePos) ? Cursor.Default : Game.controller.ChooseCursor();
|
var c = Game.chrome.HitTest(mousePos) ? Cursor.Default : Game.controller.ChooseCursor( world );
|
||||||
cursorRenderer.DrawSprite(c.GetSprite((int)cursorFrame), mousePos + Location - c.GetHotspot(), 0);
|
cursorRenderer.DrawSprite(c.GetSprite((int)cursorFrame), mousePos + Location - c.GetHotspot(), 0);
|
||||||
cursorRenderer.Flush();
|
cursorRenderer.Flush();
|
||||||
|
|
||||||
@@ -98,18 +98,18 @@ namespace OpenRa.Graphics
|
|||||||
}
|
}
|
||||||
|
|
||||||
IHandleInput dragRegion = null;
|
IHandleInput dragRegion = null;
|
||||||
public void DispatchMouseInput(MouseInput mi)
|
public void DispatchMouseInput(World world, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Event == MouseInputEvent.Move)
|
if (mi.Event == MouseInputEvent.Move)
|
||||||
mousePos = mi.Location;
|
mousePos = mi.Location;
|
||||||
|
|
||||||
if (dragRegion != null) {
|
if (dragRegion != null) {
|
||||||
dragRegion.HandleInput( mi );
|
dragRegion.HandleInput( world, mi );
|
||||||
if (mi.Event == MouseInputEvent.Up) dragRegion = null;
|
if (mi.Event == MouseInputEvent.Up) dragRegion = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dragRegion = regions.FirstOrDefault(r => r.HandleInput(mi));
|
dragRegion = regions.FirstOrDefault(r => r.HandleInput(world, mi));
|
||||||
if (mi.Event != MouseInputEvent.Down)
|
if (mi.Event != MouseInputEvent.Down)
|
||||||
dragRegion = null;
|
dragRegion = null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user