Skip to content

Commit

Permalink
Unhardcode transparent index in manual palettes as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mailaender authored and pchote committed Jan 5, 2020
1 parent 6ea85a1 commit 7e9a3d3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion OpenRA.Mods.Common/Traits/World/PaletteFromRGBA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class PaletteFromRGBAInfo : ITraitInfo

public readonly bool AllowModifiers = true;

[Desc("Index set to be fully transparent/invisible.")]
public readonly int TransparentIndex = 0;

public object Create(ActorInitializer init) { return new PaletteFromRGBA(init.World, this); }
}

Expand All @@ -65,7 +68,7 @@ public void LoadPalettes(WorldRenderer wr)
var g = (int)(a * info.G + 0.5f).Clamp(0, 255);
var b = (int)(a * info.B + 0.5f).Clamp(0, 255);
var c = (uint)Color.FromArgb(info.A, r, g, b).ToArgb();
wr.AddPalette(info.Name, new ImmutablePalette(Enumerable.Range(0, Palette.Size).Select(i => (i == 0) ? 0 : c)), info.AllowModifiers);
wr.AddPalette(info.Name, new ImmutablePalette(Enumerable.Range(0, Palette.Size).Select(i => (i == info.TransparentIndex) ? 0 : c)), info.AllowModifiers);
}
}
}

0 comments on commit 7e9a3d3

Please sign in to comment.