strip a lot of dead crap from Minimap; fix bugs in prev; rudimentary input handler for minimap
This commit is contained in:
@@ -30,10 +30,10 @@ namespace OpenRA.Graphics
|
||||
class Minimap
|
||||
{
|
||||
readonly World world;
|
||||
Sheet sheet, mapOnlySheet;
|
||||
Sheet sheet;
|
||||
SpriteRenderer rgbaRenderer;
|
||||
LineRenderer lineRenderer;
|
||||
Sprite sprite, mapOnlySprite;
|
||||
Sprite sprite;
|
||||
Bitmap terrain, oreLayer;
|
||||
Rectangle bounds;
|
||||
|
||||
@@ -42,13 +42,10 @@ namespace OpenRA.Graphics
|
||||
|
||||
const int alpha = 230;
|
||||
|
||||
public void Tick() { }
|
||||
|
||||
public Minimap(World world, Renderer r)
|
||||
{
|
||||
this.world = world;
|
||||
sheet = new Sheet(r, new Size(world.Map.MapSize.X, world.Map.MapSize.Y));
|
||||
mapOnlySheet = new Sheet(r, new Size(world.Map.MapSize.X, world.Map.MapSize.Y));
|
||||
|
||||
lineRenderer = new LineRenderer(r);
|
||||
rgbaRenderer = r.RgbaSpriteRenderer;
|
||||
@@ -59,7 +56,6 @@ namespace OpenRA.Graphics
|
||||
bounds = new Rectangle(world.Map.TopLeft.X - dw, world.Map.TopLeft.Y - dh, size, size);
|
||||
|
||||
sprite = new Sprite(sheet, bounds, TextureChannel.Alpha);
|
||||
mapOnlySprite = new Sprite(mapOnlySheet, bounds, TextureChannel.Alpha);
|
||||
|
||||
shroudColor = Color.FromArgb(alpha, Color.Black);
|
||||
|
||||
@@ -97,16 +93,6 @@ namespace OpenRA.Graphics
|
||||
return terrain;
|
||||
}
|
||||
|
||||
public static Bitmap RenderTerrainBitmapWithSpawnPoints(Map map, TileSet tileset)
|
||||
{
|
||||
/* todo: do this a bit nicer */
|
||||
var terrain = RenderTerrainBitmap(map, tileset);
|
||||
foreach (var sp in map.SpawnPoints)
|
||||
terrain.SetPixel(sp.X, sp.Y, Color.White);
|
||||
|
||||
return terrain;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (terrain == null)
|
||||
@@ -123,8 +109,6 @@ namespace OpenRA.Graphics
|
||||
oreLayer.SetPixel(x, y, Color.FromArgb(alpha, terrainTypeColors[world.Map.Theater].ColorForTerrainType(TerrainType.Ore)));
|
||||
}
|
||||
|
||||
mapOnlySheet.Texture.SetData(oreLayer);
|
||||
|
||||
if (!world.GameHasStarted || !world.Queries.OwnedBy[world.LocalPlayer].WithTrait<ProvidesRadar>().Any())
|
||||
return;
|
||||
|
||||
@@ -159,9 +143,9 @@ namespace OpenRA.Graphics
|
||||
sheet.Texture.SetData(bitmap);
|
||||
}
|
||||
|
||||
public void Draw(RectangleF rect, bool mapOnly)
|
||||
public void Draw(RectangleF rect)
|
||||
{
|
||||
rgbaRenderer.DrawSprite(mapOnly ? mapOnlySprite : sprite,
|
||||
rgbaRenderer.DrawSprite(sprite,
|
||||
new float2(rect.X, rect.Y), "chrome", new float2(rect.Width, rect.Height));
|
||||
rgbaRenderer.Flush();
|
||||
}
|
||||
|
||||
@@ -48,6 +48,29 @@ namespace OpenRA.Widgets
|
||||
|
||||
string radarCollection;
|
||||
|
||||
int2 MinimapPixelToCell(RectangleF r, int2 p)
|
||||
{
|
||||
return int2.Zero;
|
||||
}
|
||||
|
||||
public override bool HandleInput(MouseInput mi)
|
||||
{
|
||||
if (!hasRadar || radarAnimating) return false; // we're not set up for this.
|
||||
|
||||
var mapRect = new RectangleF(radarOrigin.X + 9, radarOrigin.Y + (192 - radarMinimapHeight) / 2,
|
||||
192, radarMinimapHeight);
|
||||
|
||||
if (!mapRect.Contains(mi.Location.ToPointF()))
|
||||
return false;
|
||||
|
||||
var loc = MinimapPixelToCell(mapRect, mi.Location);
|
||||
|
||||
if ((mi.Event == MouseInputEvent.Down || mi.Event == MouseInputEvent.Move) && mi.Button == MouseButton.Left)
|
||||
Game.viewport.Center(loc);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override Widget Clone() { throw new NotImplementedException("Why are you Cloning RadarBin?"); }
|
||||
|
||||
public override void Draw(World world)
|
||||
@@ -89,7 +112,7 @@ namespace OpenRA.Widgets
|
||||
radarMinimapHeight = float2.Lerp(0, 192, (radarAnimationFrame - radarSlideAnimationLength) * 1.0f / radarActivateAnimationLength);
|
||||
|
||||
// Animation is complete
|
||||
if (radarAnimationFrame == (hasRadar ? radarSlideAnimationLength : 0))
|
||||
if (radarAnimationFrame == (hasRadar ? radarSlideAnimationLength+radarActivateAnimationLength : 0))
|
||||
radarAnimating = false;
|
||||
}
|
||||
|
||||
@@ -121,7 +144,7 @@ namespace OpenRA.Widgets
|
||||
if (radarAnimationFrame >= radarSlideAnimationLength)
|
||||
{
|
||||
RectangleF mapRect = new RectangleF(radarOrigin.X + 9, radarOrigin.Y + (192 - radarMinimapHeight) / 2, 192, radarMinimapHeight);
|
||||
world.Minimap.Draw(mapRect, false);
|
||||
world.Minimap.Draw(mapRect);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user