@@ -127,6 +127,14 @@ namespace OpenRA.FileFormats
|
|||||||
return InvalidValueAction(value, fieldType, fieldName);
|
return InvalidValueAction(value, fieldType, fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fieldType == typeof(long))
|
||||||
|
{
|
||||||
|
long res;
|
||||||
|
if (long.TryParse(value, out res))
|
||||||
|
return res;
|
||||||
|
return InvalidValueAction(value, fieldType, fieldName);
|
||||||
|
}
|
||||||
|
|
||||||
else if (fieldType == typeof(float))
|
else if (fieldType == typeof(float))
|
||||||
{
|
{
|
||||||
float res;
|
float res;
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace OpenRA.FileFormats.Graphics
|
|||||||
IGraphicsDevice Create( Size size, WindowMode windowMode );
|
IGraphicsDevice Create( Size size, WindowMode windowMode );
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum BlendMode { None, Alpha, Additive }
|
public enum BlendMode { None, Alpha, Additive, Subtractive }
|
||||||
|
|
||||||
public interface IGraphicsDevice
|
public interface IGraphicsDevice
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -53,15 +53,11 @@ namespace OpenRA.FileFormats
|
|||||||
// Skip alignment byte
|
// Skip alignment byte
|
||||||
s.ReadUInt8();
|
s.ReadUInt8();
|
||||||
|
|
||||||
// Ignore palette header
|
|
||||||
if (type == 1 && paletteOffset != 0)
|
|
||||||
s.Seek(8, SeekOrigin.Current);
|
|
||||||
|
|
||||||
Image = s.ReadBytes(width*height);
|
Image = s.ReadBytes(width*height);
|
||||||
|
|
||||||
// Ignore palette data
|
// Ignore palette
|
||||||
if (type == 1 && paletteOffset != 0)
|
if (type == 1 && paletteOffset != 0)
|
||||||
s.Seek(512, SeekOrigin.Current);
|
s.Seek(520, SeekOrigin.Current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -79,6 +79,7 @@
|
|||||||
<Compile Include="Widgets\Logic\D2kInstallFromCDLogic.cs" />
|
<Compile Include="Widgets\Logic\D2kInstallFromCDLogic.cs" />
|
||||||
<Compile Include="BuildingCaptureNotification.cs" />
|
<Compile Include="BuildingCaptureNotification.cs" />
|
||||||
<Compile Include="Render\WithCrumbleOverlay.cs" />
|
<Compile Include="Render\WithCrumbleOverlay.cs" />
|
||||||
|
<Compile Include="PaletteFromR8.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
|||||||
55
OpenRA.Mods.D2k/PaletteFromR8.cs
Normal file
55
OpenRA.Mods.D2k/PaletteFromR8.cs
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2012 The OpenRA Developers (see AUTHORS)
|
||||||
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
|
* available to you under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation. For more information,
|
||||||
|
* see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System.IO;
|
||||||
|
using OpenRA.FileFormats;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
using OpenRA.Graphics;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.RA
|
||||||
|
{
|
||||||
|
class PaletteFromR8Info : ITraitInfo
|
||||||
|
{
|
||||||
|
[Desc("Internal palette name")]
|
||||||
|
public readonly string Name = null;
|
||||||
|
[Desc("Filename to load")]
|
||||||
|
public readonly string Filename = null;
|
||||||
|
[Desc("Palette byte offset")]
|
||||||
|
public readonly long Offset = 0;
|
||||||
|
public readonly bool AllowModifiers = true;
|
||||||
|
|
||||||
|
public object Create(ActorInitializer init) { return new PaletteFromR8(this); }
|
||||||
|
}
|
||||||
|
|
||||||
|
class PaletteFromR8 : IPalette
|
||||||
|
{
|
||||||
|
readonly PaletteFromR8Info info;
|
||||||
|
public PaletteFromR8(PaletteFromR8Info info) { this.info = info; }
|
||||||
|
|
||||||
|
public void InitPalette(WorldRenderer wr)
|
||||||
|
{
|
||||||
|
var colors = new uint[256];
|
||||||
|
using (var s = FileSystem.Open(info.Filename))
|
||||||
|
{
|
||||||
|
s.Seek(info.Offset, SeekOrigin.Begin);
|
||||||
|
|
||||||
|
for (var i = 0; i < 256; i++)
|
||||||
|
{
|
||||||
|
// The custom palette is scaled into the range 0-128.
|
||||||
|
// This makes the move-flash match the original game, but may not be correct in other cases.
|
||||||
|
var packed = s.ReadUInt16();
|
||||||
|
colors[i] = (uint)((255 << 24) | ((packed & 0xF800) << 7) | ((packed & 0x7E0) << 4) | ((packed & 0x1f) << 2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wr.AddPalette(info.Name, new Palette(colors), info.AllowModifiers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -154,6 +154,9 @@ namespace OpenRA.Renderer.SdlCommon
|
|||||||
|
|
||||||
public void SetBlendMode(BlendMode mode)
|
public void SetBlendMode(BlendMode mode)
|
||||||
{
|
{
|
||||||
|
Gl.glBlendEquation(Gl.GL_FUNC_ADD);
|
||||||
|
ErrorHandler.CheckGlError();
|
||||||
|
|
||||||
switch (mode)
|
switch (mode)
|
||||||
{
|
{
|
||||||
case BlendMode.None:
|
case BlendMode.None:
|
||||||
@@ -169,6 +172,13 @@ namespace OpenRA.Renderer.SdlCommon
|
|||||||
ErrorHandler.CheckGlError();
|
ErrorHandler.CheckGlError();
|
||||||
Gl.glBlendFunc(Gl.GL_ONE, Gl.GL_ONE);
|
Gl.glBlendFunc(Gl.GL_ONE, Gl.GL_ONE);
|
||||||
break;
|
break;
|
||||||
|
case BlendMode.Subtractive:
|
||||||
|
Gl.glEnable(Gl.GL_BLEND);
|
||||||
|
ErrorHandler.CheckGlError();
|
||||||
|
Gl.glBlendFunc(Gl.GL_ONE, Gl.GL_ONE);
|
||||||
|
ErrorHandler.CheckGlError();
|
||||||
|
Gl.glBlendEquation(Gl.GL_FUNC_REVERSE_SUBTRACT);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
ErrorHandler.CheckGlError();
|
ErrorHandler.CheckGlError();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user