public PlayerColorRemap(int[] ramp, Color c, float rampFraction) { var h = c.GetHue() / 360.0f; var s = c.GetSaturation(); var l = c.GetBrightness(); // Increase luminosity if required to represent the full ramp var rampRange = (byte)((1 - rampFraction) * l); var c1 = Color.FromAhsl(h, s, Math.Max(rampRange, l)); var c2 = Color.FromAhsl(h, s, (byte)Math.Max(0, l - rampRange)); var baseIndex = ramp[0]; var remapRamp = ramp.Select(r => r - ramp[0]); var rampMaxIndex = ramp.Length - 1; // reversed remapping if (ramp[0] > ramp[rampMaxIndex]) { baseIndex = ramp[rampMaxIndex]; for (var i = rampMaxIndex; i > 0; i--) { remapRamp = ramp.Select(r => r - ramp[rampMaxIndex]); } } remapColors = remapRamp.Select((x, i) => Pair.New(baseIndex + i, Exts.ColorLerp(x / (float)ramp.Length, c1, c2))) .ToDictionary(u => u.First, u => u.Second); }
public void AdjustPalette(IReadOnlyDictionary <string, MutablePalette> palettes) { if (to == EffectType.None && endTime == 0) { return; } foreach (var pal in palettes.Values) { for (var x = 0; x < Palette.Size; x++) { var orig = pal.GetColor(x); var t = ColorForEffect(to, orig); if (endTime == 0) { pal.SetColor(x, t); } else { var f = ColorForEffect(from, orig); pal.SetColor(x, Exts.ColorLerp(frac, t, f)); } } } }
public void AdjustPalette(Dictionary <string, Palette> palettes) { if (to == EffectType.None && remainingFrames == 0) { return; } foreach (var pal in palettes) { if (excludePalettes.Contains(pal.Key)) { continue; } for (var x = 0; x < 256; x++) { var orig = pal.Value.GetColor(x); var t = ColorForEffect(to, orig); if (remainingFrames == 0) { pal.Value.SetColor(x, t); } else { var f = ColorForEffect(from, orig); pal.Value.SetColor(x, Exts.ColorLerp((float)remainingFrames / Info.FadeLength, t, f)); } } } }
public void AdjustPalette(Dictionary <string, Palette> palettes) { if (remainingFrames == 0) { return; } var frac = (float)remainingFrames / chronoEffectLength; foreach (var pal in palettes) { if (excludePalettes.Contains(pal.Key)) { continue; } for (var x = 0; x < 256; x++) { var orig = pal.Value.GetColor(x); var lum = (int)(255 * orig.GetBrightness()); var desat = Color.FromArgb(orig.A, lum, lum, lum); pal.Value.SetColor(x, Exts.ColorLerp(frac, orig, desat)); } } }
public void Render(WorldRenderer wr) { // Need at least 4 points to smooth the contrail over if (length - skip < 4) { return; } // Start of the first line segment is the tail of the list - don't smooth it. var curPos = trail[idx(next - skip - 1)]; var curCell = curPos.ToCPos(); var curColor = color; for (var i = 0; i < length - skip - 4; i++) { var j = next - skip - i - 2; var nextPos = Average(trail[idx(j)], trail[idx(j - 1)], trail[idx(j - 2)], trail[idx(j - 3)]); var nextCell = nextPos.ToCPos(); var nextColor = Exts.ColorLerp(i * 1f / (length - 4), color, Color.Transparent); if (!world.FogObscures(curCell) && !world.FogObscures(nextCell)) { Game.Renderer.WorldLineRenderer.DrawLine(wr.ScreenPosition(curPos), wr.ScreenPosition(nextPos), curColor, nextColor); } curPos = nextPos; curCell = nextCell; curColor = nextColor; } }
public void Render(WorldRenderer wr) { // Need at least 4 points to smooth the contrail over if (length - skip < 4) { return; } var screenWidth = wr.ScreenVector(new WVec(width, WDist.Zero, WDist.Zero))[0]; var wcr = Game.Renderer.WorldRgbaColorRenderer; // Start of the first line segment is the tail of the list - don't smooth it. var curPos = trail[Index(next - skip - 1)]; var curColor = color; for (var i = 0; i < length - skip - 4; i++) { var j = next - skip - i - 2; var nextPos = Average(trail[Index(j)], trail[Index(j - 1)], trail[Index(j - 2)], trail[Index(j - 3)]); var nextColor = Exts.ColorLerp(i * 1f / (length - 4), color, Color.Transparent); if (!world.FogObscures(curPos) && !world.FogObscures(nextPos)) { wcr.DrawLine(wr.Screen3DPosition(curPos), wr.Screen3DPosition(nextPos), screenWidth, curColor, nextColor); } curPos = nextPos; curColor = nextColor; } }
public void AdjustPalette(IReadOnlyDictionary <string, MutablePalette> palettes) { if (to == EffectType.None && remainingFrames == 0) { return; } foreach (var pal in palettes.Values) { for (var x = 0; x < Palette.Size; x++) { var orig = pal.GetColor(x); var t = ColorForEffect(to, orig); if (remainingFrames == 0) { pal.SetColor(x, t); } else { var f = ColorForEffect(from, orig); pal.SetColor(x, Exts.ColorLerp((float)remainingFrames / Info.FadeLength, t, f)); } } } }
public PlayerColorRemap(PaletteFormat fmt, ColorRamp c) { var c1 = c.GetColor(0); var c2 = c.GetColor(1); /* temptemp: this can be expressed better */ var baseIndex = GetRemapBase(fmt); var ramp = GetRemapRamp(fmt); remapColors = ramp.Select((x, i) => Pair.New(baseIndex + i, Exts.ColorLerp(x / 16f, c1, c2))) .ToDictionary(u => u.First, u => u.Second); }
public PlayerColorRemap(int[] Ramp, ColorRamp c) { var c1 = c.GetColor(0); var c2 = c.GetColor(1); /* temptemp: this can be expressed better */ var baseIndex = Ramp[0]; var RemapRamp = GetRemapRamp(Ramp); remapColors = RemapRamp.Select((x, i) => Pair.New(baseIndex + i, Exts.ColorLerp(x / 16f, c1, c2))) .ToDictionary(u => u.First, u => u.Second); }
public void AdjustPalette(Dictionary<string, Palette> palettes) { foreach (var pal in palettes) { if (ExcludePalettes.Contains(pal.Key)) continue; for (var x = 0; x < 256; x++) { var from = pal.Value.GetColor(x); var to = Color.FromArgb(from.A, Color.FromKnownColor(KnownColor.DarkOrange)); pal.Value.SetColor(x, Exts.ColorLerp(0.15f, from, to)); } } }
public void AdjustPalette(Dictionary <string, Palette> palettes) { if (remainingFrames == 0) { return; } var frac = (float)remainingFrames / nukeEffectLength; foreach (var pal in palettes) { for (var x = 0; x < 256; x++) { var orig = pal.Value.GetColor(x); var white = Color.FromArgb(orig.A, 255, 255, 255); pal.Value.SetColor(x, Exts.ColorLerp(frac, orig, white)); } } }
void IPaletteModifier.AdjustPalette(IReadOnlyDictionary <string, MutablePalette> palettes) { if (remainingFrames == 0) { return; } var frac = (float)remainingFrames / info.ChronoEffectLength; foreach (var pal in palettes) { for (var x = 0; x < Palette.Size; x++) { var orig = pal.Value.GetColor(x); var lum = (int)(255 * orig.GetBrightness()); var desat = Color.FromArgb(orig.A, lum, lum, lum); pal.Value.SetColor(x, Exts.ColorLerp(frac, orig, desat)); } } }
public PlayerColorRemap(int[] Ramp, ColorRamp c) { var c1 = c.GetColor(0); var c2 = c.GetColor(1); // temptemp: this can be expressed better var baseIndex = Ramp[0]; var RemapRamp = Ramp.Select(r => r - Ramp[0]).ToArray(); if (Ramp[0] > Ramp[15]) // reversed remapping { baseIndex = Ramp[15]; for (int i = 15; i > 0; i--) { RemapRamp = Ramp.Select(r => r - Ramp[15]).ToArray(); } } remapColors = RemapRamp.Select((x, i) => Pair.New(baseIndex + i, Exts.ColorLerp(x / 16f, c1, c2))) .ToDictionary(u => u.First, u => u.Second); }
public PlayerColorRemap(int[] Ramp, HSLColor c, float rampFraction) { // Increase luminosity if required to represent the full ramp var rampRange = (byte)((1 - rampFraction) * c.L); var c1 = new HSLColor(c.H, c.S, (byte)Math.Max(rampRange, c.L)).RGB; var c2 = new HSLColor(c.H, c.S, (byte)Math.Max(0, c.L - rampRange)).RGB; var baseIndex = Ramp[0]; var RemapRamp = Ramp.Select(r => r - Ramp[0]).ToArray(); if (Ramp[0] > Ramp[15]) // reversed remapping { baseIndex = Ramp[15]; for (var i = 15; i > 0; i--) { RemapRamp = Ramp.Select(r => r - Ramp[15]).ToArray(); } } remapColors = RemapRamp.Select((x, i) => Pair.New(baseIndex + i, Exts.ColorLerp(x / 16f, c1, c2))) .ToDictionary(u => u.First, u => u.Second); }
public PlayerColorRemap(int[] ramp, HSLColor c, float rampFraction) { // Increase luminosity if required to represent the full ramp var rampRange = (byte)((1 - rampFraction) * c.L); var c1 = new HSLColor(c.H, c.S, Math.Max(rampRange, c.L)).RGB; var c2 = new HSLColor(c.H, c.S, (byte)Math.Max(0, c.L - rampRange)).RGB; var baseIndex = ramp[0]; var remapRamp = ramp.Select(r => r - ramp[0]); var rampMaxIndex = ramp.Length - 1; // reversed remapping if (ramp[0] > ramp[rampMaxIndex]) { baseIndex = ramp[rampMaxIndex]; for (var i = rampMaxIndex; i > 0; i--) { remapRamp = ramp.Select(r => r - ramp[rampMaxIndex]); } } remapColors = remapRamp.Select((x, i) => Pair.New(baseIndex + i, Exts.ColorLerp(x / (float)ramp.Length, c1, c2))) .ToDictionary(u => u.First, u => u.Second); }
public void Render(WorldRenderer wr) { // Need at least 4 points to smooth the contrail over if (length - skip < 4) { return; } var wlr = Game.Renderer.WorldLineRenderer; var oldWidth = wlr.LineWidth; wlr.LineWidth = wr.Viewport.Zoom; // Start of the first line segment is the tail of the list - don't smooth it. var curPos = trail[Index(next - skip - 1)]; var curCell = wr.World.Map.CellContaining(curPos); var curColor = color; for (var i = 0; i < length - skip - 4; i++) { var j = next - skip - i - 2; var nextPos = Average(trail[Index(j)], trail[Index(j - 1)], trail[Index(j - 2)], trail[Index(j - 3)]); var nextCell = wr.World.Map.CellContaining(nextPos); var nextColor = Exts.ColorLerp(i * 1f / (length - 4), color, Color.Transparent); if (!world.FogObscures(curCell) && !world.FogObscures(nextCell)) { wlr.DrawLine(wr.ScreenPosition(curPos), wr.ScreenPosition(nextPos), curColor, nextColor); } curPos = nextPos; curCell = nextCell; curColor = nextColor; } wlr.LineWidth = oldWidth; }
public override void Draw() { var scaleBy = 100.0f; var provided = GetProvided(); var used = GetUsed(); var max = Math.Max(provided, used); while (max >= scaleBy) { scaleBy *= 2; } var providedFrac = providedLerp.Update(provided / scaleBy); var usedFrac = usedLerp.Update(used / scaleBy); var b = RenderBounds; var indicator = ChromeProvider.GetImage(IndicatorCollection, IndicatorImage); var color = GetBarColor(); if (Orientation == ResourceBarOrientation.Vertical) { if (Style == ResourceBarStyle.Bevelled) { var colorDark = Exts.ColorLerp(0.25f, color, Color.Black); for (var i = 0; i < b.Height; i++) { color = (i - 1 < b.Height / 2) ? color : colorDark; var bottom = new float2(b.Left + i, b.Bottom); var top = new float2(b.Left + i, b.Bottom + providedFrac * b.Height); // Indent corners if ((i == 0 || i == b.Width - 1) && providedFrac * b.Height > 1) { bottom.Y += 1; top.Y -= 1; } Game.Renderer.LineRenderer.DrawLine(bottom, top, color, color); } } else { Game.Renderer.LineRenderer.FillRect(new Rectangle(b.X, (int)float2.Lerp(b.Bottom, b.Top, providedFrac), b.Width, (int)(providedFrac * b.Height)), color); } var x = (b.Left + b.Right - indicator.size.X) / 2; var y = float2.Lerp(b.Bottom, b.Top, usedFrac) - indicator.size.Y / 2; Game.Renderer.RgbaSpriteRenderer.DrawSprite(indicator, new float2(x, y)); } else { if (Style == ResourceBarStyle.Bevelled) { var colorDark = Exts.ColorLerp(0.25f, color, Color.Black); for (var i = 0; i < b.Height; i++) { color = (i - 1 < b.Height / 2) ? color : colorDark; var left = new float2(b.Left, b.Top + i); var right = new float2(b.Left + providedFrac * b.Width, b.Top + i); // Indent corners if ((i == 0 || i == b.Height - 1) && providedFrac * b.Width > 1) { left.X += 1; right.X -= 1; } Game.Renderer.LineRenderer.DrawLine(left, right, color, color); } } else { Game.Renderer.LineRenderer.FillRect(new Rectangle(b.X, b.Y, (int)(providedFrac * b.Width), b.Height), color); } var x = float2.Lerp(b.Left, b.Right, usedFrac) - indicator.size.X / 2; var y = (b.Bottom + b.Top - indicator.size.Y) / 2; Game.Renderer.RgbaSpriteRenderer.DrawSprite(indicator, new float2(x, y)); } }
public static Color ChooseColor(Actor self) { var ownerColor = Color.FromArgb(255, self.Owner.Color.RGB); return(Exts.ColorLerp(0.5f, ownerColor, Color.White)); }
public override void Draw() { if (world.LocalPlayer == null) { return; } if (world.LocalPlayer.WinState != WinState.Undefined) { return; } var radarBin = Ui.Root.GetWidget <RadarBinWidget>(RadarBin); powerCollection = "power-" + world.LocalPlayer.Country.Race; // Nothing to draw if (power.PowerProvided == 0 && power.PowerDrained == 0) { return; } // Draw bar horizontally var barStart = powerOrigin + radarBin.RadarOrigin; var barEnd = barStart + new float2(powerSize.Width, 0); float powerScaleBy = 100; var maxPower = Math.Max(power.PowerProvided, power.PowerDrained); while (maxPower >= powerScaleBy) { powerScaleBy *= 2; } // Current power supply var powerLevelTemp = barStart.X + (barEnd.X - barStart.X) * (power.PowerProvided / powerScaleBy); lastPowerProvidedPos = float2.Lerp(lastPowerProvidedPos.GetValueOrDefault(powerLevelTemp), powerLevelTemp, PowerBarLerpFactor); var powerLevel = new float2(lastPowerProvidedPos.Value, barStart.Y); var color = GetPowerColor(power); var colorDark = Exts.ColorLerp(0.25f, color, Color.Black); for (int i = 0; i < powerSize.Height; i++) { color = (i - 1 < powerSize.Height / 2) ? color : colorDark; var leftOffset = new float2(0, i); var rightOffset = new float2(0, i); // Indent corners if ((i == 0 || i == powerSize.Height - 1) && powerLevel.X - barStart.X > 1) { leftOffset.X += 1; rightOffset.X -= 1; } Game.Renderer.LineRenderer.DrawLine(barStart + leftOffset, powerLevel + rightOffset, color, color); } // Power usage indicator var indicator = ChromeProvider.GetImage(powerCollection, "power-indicator"); var powerDrainedTemp = barStart.X + (barEnd.X - barStart.X) * (power.PowerDrained / powerScaleBy); lastPowerDrainedPos = float2.Lerp(lastPowerDrainedPos.GetValueOrDefault(powerDrainedTemp), powerDrainedTemp, PowerBarLerpFactor); var powerDrainLevel = new float2(lastPowerDrainedPos.Value - indicator.size.X / 2, barStart.Y - 1); Game.Renderer.RgbaSpriteRenderer.DrawSprite(indicator, powerDrainLevel); }
public override void Draw() { if (world.LocalPlayer == null) { return; } if (world.LocalPlayer.WinState != WinState.Undefined) { return; } var radarBin = Ui.Root.Get <RadarBinWidget>(RadarBin); powerCollection = "power-" + world.LocalPlayer.Country.Race; // Nothing to draw if (power.PowerProvided == 0 && power.PowerDrained == 0) { return; } // Draw bar horizontally var barStart = powerOrigin + radarBin.RadarOrigin; var barEnd = barStart + new float2(powerSize.Width, 0); float powerScaleBy = 100; var maxPower = Math.Max(power.PowerProvided, power.PowerDrained); while (maxPower >= powerScaleBy) { powerScaleBy *= 2; } // Current power supply var powerLevelTemp = barStart.X + (barEnd.X - barStart.X) * (power.PowerProvided / powerScaleBy); lastPowerProvidedPos = float2.Lerp(lastPowerProvidedPos.GetValueOrDefault(powerLevelTemp), powerLevelTemp, PowerBarLerpFactor); var powerLevel = new float2(lastPowerProvidedPos.Value, barStart.Y); var color = GetPowerColor(power); var colorDark = Exts.ColorLerp(0.25f, color, Color.Black); for (int i = 0; i < powerSize.Height; i++) { color = (i - 1 < powerSize.Height / 2) ? color : colorDark; var leftOffset = new float2(0, i); var rightOffset = new float2(0, i); // Indent corners if ((i == 0 || i == powerSize.Height - 1) && powerLevel.X - barStart.X > 1) { leftOffset.X += 1; rightOffset.X -= 1; } Game.Renderer.LineRenderer.DrawLine(barStart + leftOffset, powerLevel + rightOffset, color, color); } // Power usage indicator var indicator = ChromeProvider.GetImage(powerCollection, "power-indicator"); var powerDrainedTemp = barStart.X + (barEnd.X - barStart.X) * (power.PowerDrained / powerScaleBy); lastPowerDrainedPos = float2.Lerp(lastPowerDrainedPos.GetValueOrDefault(powerDrainedTemp), powerDrainedTemp, PowerBarLerpFactor); var powerDrainLevel = new float2(lastPowerDrainedPos.Value - indicator.size.X / 2, barStart.Y - 1); Game.Renderer.RgbaSpriteRenderer.DrawSprite(indicator, powerDrainLevel); // Render the tooltip var rect = new Rectangle((int)barStart.X, (int)barStart.Y, powerSize.Width, powerSize.Height); if (rect.InflateBy(0, 5, 0, 5).Contains(Viewport.LastMousePos)) { var pos = new int2(rect.Left + 5, rect.Top + 5); var border = WidgetUtils.GetBorderSizes("dialog4"); WidgetUtils.DrawPanel("dialog4", rect.InflateBy(0, 0, 0, 50 + border[1])); Game.Renderer.Fonts["Bold"].DrawText("Power", pos, Color.White); pos += new int2(0, 20); Game.Renderer.Fonts["Regular"].DrawText("Provided: {0}\nDrained: {1}".F(power.PowerProvided, power.PowerDrained), pos, Color.White); } }