Move MapPreviewWidget.HandleInputInner to the lobby delegate.
This commit is contained in:
@@ -19,10 +19,7 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
public class MapPreviewWidget : Widget
|
||||
{
|
||||
public int SpawnClickRadius = 50;
|
||||
|
||||
public Func<MapStub> Map = () => null;
|
||||
public Action<int> OnSpawnClick = spawn => {};
|
||||
public Func<Dictionary<int2, Color>> SpawnColors = () => new Dictionary<int2, Color>();
|
||||
static Cache<MapStub,Bitmap> PreviewCache = new Cache<MapStub, Bitmap>(stub => Minimap.RenderMapPreview( new Map( stub.Path )));
|
||||
|
||||
@@ -32,37 +29,17 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
lastMap = other.lastMap;
|
||||
Map = other.Map;
|
||||
OnSpawnClick = other.OnSpawnClick;
|
||||
SpawnColors = other.SpawnColors;
|
||||
}
|
||||
public override Widget Clone() { return new MapPreviewWidget(this); }
|
||||
|
||||
public override bool HandleInputInner(MouseInput mi) { return true; }
|
||||
|
||||
public int2 ConvertToPreview(MapStub map, int2 point)
|
||||
{
|
||||
return new int2(MapRect.X + (int)(PreviewScale*(point.X - map.Bounds.Left)) , MapRect.Y + (int)(PreviewScale*(point.Y - map.Bounds.Top)));
|
||||
}
|
||||
|
||||
public override bool HandleInputInner(MouseInput mi)
|
||||
{
|
||||
var map = Map();
|
||||
if (map == null)
|
||||
return false;
|
||||
|
||||
if (mi.Event == MouseInputEvent.Down && mi.Button == MouseButton.Left)
|
||||
{
|
||||
var p = map.Waypoints
|
||||
.Select((sp, i) => Pair.New(ConvertToPreview(map, sp.Value), i))
|
||||
.Where(a => (a.First - mi.Location).LengthSquared < SpawnClickRadius)
|
||||
.Select(a => a.Second + 1)
|
||||
.FirstOrDefault();
|
||||
OnSpawnClick(p);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Sheet mapChooserSheet;
|
||||
Sprite mapChooserSprite;
|
||||
MapStub lastMap;
|
||||
|
||||
@@ -194,10 +194,6 @@ namespace OpenRA.Widgets
|
||||
return EventBounds.Contains(pos.ToPoint()) ? GetCursor(pos) : null;
|
||||
}
|
||||
|
||||
// Hack: Don't eat mouse input that others want
|
||||
// TODO: Solve this properly
|
||||
public virtual bool HandleInputInner(MouseInput mi) { return !ClickThrough && mi.Button == MouseButton.Left && mi.Event != MouseInputEvent.Move; }
|
||||
|
||||
public static bool HandleInput(MouseInput mi)
|
||||
{
|
||||
bool handled = false;
|
||||
@@ -239,6 +235,9 @@ namespace OpenRA.Widgets
|
||||
return true;
|
||||
}
|
||||
|
||||
// Hack: Don't eat mouse input that others want
|
||||
// TODO: Solve this properly
|
||||
public virtual bool HandleInputInner(MouseInput mi) { return !ClickThrough && mi.Button == MouseButton.Left && mi.Event != MouseInputEvent.Move; }
|
||||
|
||||
public virtual bool HandleKeyPressInner(KeyInput e) { return false; }
|
||||
public virtual bool HandleKeyPressOuter(KeyInput e)
|
||||
|
||||
@@ -49,12 +49,24 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
|
||||
var mapPreview = lobby.GetWidget<MapPreviewWidget>("LOBBY_MAP_PREVIEW");
|
||||
mapPreview.Map = () => Map;
|
||||
mapPreview.OnSpawnClick = sp =>
|
||||
mapPreview.OnMouseDown = mi =>
|
||||
{
|
||||
if (orderManager.LocalClient.State == Session.ClientState.Ready) return;
|
||||
var owned = orderManager.LobbyInfo.Clients.Any(c => c.SpawnPoint == sp);
|
||||
if (sp == 0 || !owned)
|
||||
orderManager.IssueOrder(Order.Command("spawn {0}".F(sp)));
|
||||
var map = mapPreview.Map();
|
||||
if (map == null || mi.Button != MouseButton.Left
|
||||
|| orderManager.LocalClient.State == Session.ClientState.Ready)
|
||||
return false;
|
||||
|
||||
var p = map.Waypoints
|
||||
.Select((sp, i) => Pair.New(mapPreview.ConvertToPreview(map, sp.Value), i))
|
||||
.Where(a => (a.First - mi.Location).LengthSquared < 64)
|
||||
.Select(a => a.Second + 1)
|
||||
.FirstOrDefault();
|
||||
|
||||
var owned = orderManager.LobbyInfo.Clients.Any(c => c.SpawnPoint == p);
|
||||
if (p == 0 || !owned)
|
||||
orderManager.IssueOrder(Order.Command("spawn {0}".F(p)));
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
mapPreview.SpawnColors = () =>
|
||||
|
||||
Reference in New Issue
Block a user