Clean up custom color palette

This commit is contained in:
Paul Chote
2010-08-15 00:15:23 +12:00
parent 271be551b0
commit 694fd84188
10 changed files with 53 additions and 26 deletions

View File

@@ -93,14 +93,12 @@ namespace OpenRA.FileFormats
frameData = new uint[frameSize,frameSize]; frameData = new uint[frameSize,frameSize];
var type = new String(reader.ReadChars(4)); var type = new String(reader.ReadChars(4));
Console.WriteLine(type);
if (type != "FINF") if (type != "FINF")
{ {
reader.ReadBytes(27); reader.ReadBytes(27);
type = new String(reader.ReadChars(4)); type = new String(reader.ReadChars(4));
} }
Console.WriteLine(type);
/*var length = */reader.ReadUInt16(); /*var length = */reader.ReadUInt16();
/*var unknown4 = */reader.ReadUInt16(); /*var unknown4 = */reader.ReadUInt16();

View File

@@ -37,7 +37,7 @@ namespace OpenRA
public static World world; public static World world;
public static Viewport viewport; public static Viewport viewport;
internal static UserSettings Settings; public static UserSettings Settings;
internal static OrderManager orderManager; internal static OrderManager orderManager;

View File

@@ -52,16 +52,10 @@ namespace OpenRA.Graphics
public void AddPalette(string name, Palette p) public void AddPalette(string name, Palette p)
{ {
Console.WriteLine("Adding palette "+name);
palettes.Add(name, p); palettes.Add(name, p);
indices.Add(name, allocated++); indices.Add(name, allocated++);
} }
public void UpdatePalette(string name, Palette p)
{
palettes[name] = p;
}
public void Update(IEnumerable<IPaletteModifier> paletteMods) public void Update(IEnumerable<IPaletteModifier> paletteMods)
{ {
var copy = palettes.ToDictionary(p => p.Key, p => new Palette(p.Value)); var copy = palettes.ToDictionary(p => p.Key, p => new Palette(p.Value));

View File

@@ -36,7 +36,6 @@ namespace OpenRA.Graphics
public int GetPaletteIndex(string name) { return palette.GetPaletteIndex(name); } public int GetPaletteIndex(string name) { return palette.GetPaletteIndex(name); }
public Palette GetPalette(string name) { return palette.GetPalette(name); } public Palette GetPalette(string name) { return palette.GetPalette(name); }
public void AddPalette(string name, Palette pal) { palette.AddPalette(name, pal); } public void AddPalette(string name, Palette pal) { palette.AddPalette(name, pal); }
public void UpdatePalette(string name, Palette pal) { palette.UpdatePalette(name, pal); }
class SpriteComparer : IComparer<Renderable> class SpriteComparer : IComparer<Renderable>
{ {

View File

@@ -20,18 +20,21 @@ namespace OpenRA.Widgets.Delegates
public class LobbyDelegate : IWidgetDelegate public class LobbyDelegate : IWidgetDelegate
{ {
Widget Players, LocalPlayerTemplate, RemotePlayerTemplate; Widget Players, LocalPlayerTemplate, RemotePlayerTemplate;
Dictionary<string, string> CountryNames; Dictionary<string, string> CountryNames;
string MapUid; string MapUid;
MapStub Map; MapStub Map;
bool SplitPlayerPalette = false; public static Color CurrentColorPreview1;
Palette BasePlayerPalette = null; public static Color CurrentColorPreview2;
public LobbyDelegate() public LobbyDelegate()
{ {
Game.LobbyInfoChanged += UpdateCurrentMap; Game.LobbyInfoChanged += UpdateCurrentMap;
UpdateCurrentMap(); UpdateCurrentMap();
CurrentColorPreview1 = Game.Settings.PlayerColor1;
CurrentColorPreview2 = Game.Settings.PlayerColor2;
var r = Widget.RootWidget; var r = Widget.RootWidget;
var lobby = r.GetWidget("SERVER_LOBBY"); var lobby = r.GetWidget("SERVER_LOBBY");
@@ -151,13 +154,7 @@ namespace OpenRA.Widgets.Delegates
UpdateColorPreview(hueSlider.GetOffset(), satSlider.GetOffset(), lumSlider.GetOffset(), rangeSlider.GetOffset()); UpdateColorPreview(hueSlider.GetOffset(), satSlider.GetOffset(), lumSlider.GetOffset(), rangeSlider.GetOffset());
UpdatePlayerColor(hueSlider.GetOffset(), satSlider.GetOffset(), lumSlider.GetOffset(), rangeSlider.GetOffset()); UpdatePlayerColor(hueSlider.GetOffset(), satSlider.GetOffset(), lumSlider.GetOffset(), rangeSlider.GetOffset());
return true; return true;
}; };
// Copy the base palette for the colorpicker
var info = Rules.Info["world"].Traits.Get<PlayerColorPaletteInfo>();
BasePlayerPalette = Game.world.WorldRenderer.GetPalette(info.BasePalette);
SplitPlayerPalette = info.SplitRamp;
Game.world.WorldRenderer.AddPalette("colorpicker",BasePlayerPalette);
} }
void UpdatePlayerColor(float hf, float sf, float lf, float r) void UpdatePlayerColor(float hf, float sf, float lf, float r)
@@ -173,9 +170,8 @@ namespace OpenRA.Widgets.Delegates
void UpdateColorPreview(float hf, float sf, float lf, float r) void UpdateColorPreview(float hf, float sf, float lf, float r)
{ {
var c1 = ColorFromHSL(hf, sf, lf); CurrentColorPreview1 = ColorFromHSL(hf, sf, lf);
var c2 = ColorFromHSL(hf, sf, r*lf); CurrentColorPreview2 = ColorFromHSL(hf, sf, r*lf);
Game.world.WorldRenderer.UpdatePalette("colorpicker", new Palette(BasePlayerPalette, new PlayerColorRemap(c1, c2, SplitPlayerPalette)));
Game.viewport.RefreshPalette(); Game.viewport.RefreshPalette();
} }

View File

@@ -39,7 +39,6 @@ namespace OpenRA.Mods.RA
return; return;
var frac = (float)remainingFrames / chronoEffectLength; var frac = (float)remainingFrames / chronoEffectLength;
System.Console.WriteLine("{0}",frac);
var excludePalettes = new List<string>(){"cursor", "chrome", "colorpicker"}; var excludePalettes = new List<string>(){"cursor", "chrome", "colorpicker"};
foreach (var pal in palettes) foreach (var pal in palettes)
{ {

View File

@@ -0,0 +1,38 @@
#region Copyright & License Information
/*
* Copyright 2007-2010 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 LICENSE.
*/
#endregion
using System.Drawing;
using OpenRA.Traits;
using System.Collections.Generic;
using OpenRA.FileFormats;
using OpenRA.Widgets.Delegates;
namespace OpenRA.Mods.RA
{
class ColorPickerPaletteModifierInfo : TraitInfo<ColorPickerPaletteModifier> {}
class ColorPickerPaletteModifier : IPaletteModifier, ILoadWorldHook
{
bool SplitPlayerPalette;
public void WorldLoaded(World w)
{
// Copy the base palette for the colorpicker
var info = Rules.Info["world"].Traits.Get<PlayerColorPaletteInfo>();
SplitPlayerPalette = info.SplitRamp;
w.WorldRenderer.AddPalette("colorpicker", w.WorldRenderer.GetPalette(info.BasePalette));
}
public void AdjustPalette(Dictionary<string,Palette> palettes)
{
palettes["colorpicker"] = new Palette(palettes["colorpicker"],
new PlayerColorRemap(LobbyDelegate.CurrentColorPreview1, LobbyDelegate.CurrentColorPreview2, SplitPlayerPalette));
}
}
}

View File

@@ -232,6 +232,7 @@
<Compile Include="Activities\Transform.cs" /> <Compile Include="Activities\Transform.cs" />
<Compile Include="ActorLostNotification.cs" /> <Compile Include="ActorLostNotification.cs" />
<Compile Include="AppearsOnRadar.cs" /> <Compile Include="AppearsOnRadar.cs" />
<Compile Include="ColorPickerPaletteModifier.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj"> <ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -44,6 +44,7 @@ Player:
World: World:
ScreenShaker: ScreenShaker:
ColorPickerPaletteModifier:
WaterPaletteRotation: WaterPaletteRotation:
CncMode: true CncMode: true
BuildingInfluence: BuildingInfluence:

View File

@@ -87,6 +87,7 @@ Player:
World: World:
ScreenShaker: ScreenShaker:
ColorPickerPaletteModifier:
WaterPaletteRotation: WaterPaletteRotation:
ChronoshiftPaletteEffect: ChronoshiftPaletteEffect:
NukePaletteEffect: NukePaletteEffect: