fixed powerbar colours,darkening, position. Moved lerping into Graphics.Util

This commit is contained in:
Alli
2010-01-04 00:43:01 +13:00
parent 4bb22a8de3
commit 4410274e36
3 changed files with 30 additions and 18 deletions

View File

@@ -236,12 +236,23 @@ namespace OpenRa.Game
//draw bar
float2 powerTop = new float2(bottom.X, bottom.Y + (top.Y - bottom.Y) * (Game.LocalPlayer.PowerProvided / (float)scale));
for(int i = 7; i < 11; i++)
lineRenderer.DrawLine(bottom + new float2(i, 0), powerTop + new float2(i, 0), Color.LimeGreen, Color.LimeGreen);
var color = Color.LimeGreen;
if (Game.LocalPlayer.GetPowerState() == PowerState.Low)
color = Color.Orange;
if (Game.LocalPlayer.GetPowerState() == PowerState.Critical)
color = Color.Red;
var color2 = Graphics.Util.Lerp(0.25f, color, Color.Black);
for(int i = 11; i < 13; i++)
lineRenderer.DrawLine(bottom + new float2(i, 0), powerTop + new float2(i, 0), color, color);
for (int i = 13; i < 15; i++)
lineRenderer.DrawLine(bottom + new float2(i, 0), powerTop + new float2(i, 0), color2, color2);
lineRenderer.Flush();
//draw indicator
float2 drainedPosition = new float2(bottom.X , bottom.Y + (top.Y - bottom.Y)*(Game.LocalPlayer.PowerDrained/(float) scale));
float2 drainedPosition = new float2(bottom.X + 2 , bottom.Y + (top.Y - bottom.Y)*(Game.LocalPlayer.PowerDrained/(float) scale) + 2);
buildPaletteRenderer.DrawSprite(powerIndicatorSprite, drainedPosition, PaletteType.Chrome);
buildPaletteRenderer.Flush();

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.IO;
using System.Drawing;
namespace OpenRa.Game.Graphics
{
@@ -111,5 +112,19 @@ namespace OpenRa.Game.Graphics
bitmap.UnlockBits(bits);
}
}
public static Color Lerp(float t, Color a, Color b)
{
return Color.FromArgb(
LerpChannel(t, a.A, b.A),
LerpChannel(t, a.R, b.R),
LerpChannel(t, a.G, b.G),
LerpChannel(t, a.B, b.B));
}
public static int LerpChannel(float t, int a, int b)
{
return (int)((1 - t) * a + t * b);
}
}
}

View File

@@ -33,22 +33,8 @@ namespace OpenRa.Game.Traits
var orig = b.GetPixel(x, y);
var lum = (int)(255 * orig.GetBrightness());
var desat = Color.FromArgb(orig.A, lum, lum, lum);
b.SetPixel(x, y, Lerp(frac, orig, desat));
b.SetPixel(x, y, Graphics.Util.Lerp(frac, orig, desat));
}
}
static Color Lerp(float t, Color a, Color b)
{
return Color.FromArgb(
LerpChannel(t, a.A, b.A),
LerpChannel(t, a.R, b.R),
LerpChannel(t, a.G, b.G),
LerpChannel(t, a.B, b.B));
}
static int LerpChannel(float t, int a, int b)
{
return (int)((1 - t) * a + t * b);
}
}
}