untangling WorldRenderer from World

This commit is contained in:
Bob
2010-10-12 01:11:56 +13:00
parent 1c1483377c
commit 597dba8584
17 changed files with 162 additions and 124 deletions

View File

@@ -11,21 +11,21 @@
using System.Collections.Generic;
using OpenRA.FileFormats;
using OpenRA.Traits;
using OpenRA.Widgets.Delegates;
using OpenRA.Widgets.Delegates;
using OpenRA.Graphics;
namespace OpenRA.Mods.RA
{
class ColorPickerPaletteModifierInfo : TraitInfo<ColorPickerPaletteModifier> {}
class ColorPickerPaletteModifier : IPaletteModifier, IWorldLoaded
class ColorPickerPaletteModifier : IPalette, IPaletteModifier
{
PaletteFormat format;
public void WorldLoaded(World w)
{
// Copy the base palette for the colorpicker
var info = Rules.Info["world"].Traits.Get<PlayerColorPaletteInfo>();
public void InitPalette( WorldRenderer wr )
{
var info = Rules.Info["player"].Traits.Get<PlayerColorPaletteInfo>();
format = info.PaletteFormat;
w.WorldRenderer.AddPalette("colorpicker", w.WorldRenderer.GetPalette(info.BasePalette));
wr.AddPalette("colorpicker", wr.GetPalette(info.BasePalette));
}
public void AdjustPalette(Dictionary<string, Palette> palettes)
@@ -33,6 +33,6 @@ namespace OpenRA.Mods.RA
palettes["colorpicker"] = new Palette(palettes["colorpicker"],
new PlayerColorRemap(LobbyDelegate.CurrentColorPreview1,
LobbyDelegate.CurrentColorPreview2, format));
}
}
}
}

View File

@@ -21,12 +21,20 @@ namespace OpenRA.Mods.RA
public object Create(ActorInitializer init) { return new PaletteFromCurrentTheatre(init.world, this); }
}
class PaletteFromCurrentTheatre
{
class PaletteFromCurrentTheatre : IPalette
{
readonly World world;
readonly PaletteFromCurrentTheatreInfo info;
public PaletteFromCurrentTheatre(World world, PaletteFromCurrentTheatreInfo info)
{
world.WorldRenderer.AddPalette(info.Name,
new Palette(FileSystem.Open(world.TileSet.Palette), info.Transparent));
}
{
this.world = world;
this.info = info;
}
public void InitPalette( OpenRA.Graphics.WorldRenderer wr )
{
wr.AddPalette( info.Name, new Palette( FileSystem.Open( world.TileSet.Palette ), info.Transparent ) );
}
}
}

View File

@@ -10,6 +10,7 @@
using OpenRA.FileFormats;
using OpenRA.Traits;
using OpenRA.Graphics;
namespace OpenRA.Mods.RA
{
@@ -23,16 +24,20 @@ namespace OpenRA.Mods.RA
public object Create(ActorInitializer init) { return new PaletteFromFile(init.world, this); }
}
class PaletteFromFile
class PaletteFromFile : IPalette
{
readonly World world;
readonly PaletteFromFileInfo info;
public PaletteFromFile(World world, PaletteFromFileInfo info)
{
if (info.Theater == null ||
info.Theater.ToLowerInvariant() == world.Map.Theater.ToLowerInvariant())
{
world.WorldRenderer.AddPalette(info.Name,
new Palette(FileSystem.Open(info.Filename), info.Transparent));
}
this.world = world;
this.info = info;
}
public void InitPalette( WorldRenderer wr )
{
if( info.Theater == null || info.Theater.ToLowerInvariant() == world.Map.Theater.ToLowerInvariant() )
wr.AddPalette( info.Name, new Palette( FileSystem.Open( info.Filename ), info.Transparent ) );
}
}
}

View File

@@ -11,6 +11,7 @@
using System.Drawing;
using OpenRA.FileFormats;
using OpenRA.Traits;
using OpenRA.Graphics;
namespace OpenRA.Mods.RA
{
@@ -26,15 +27,21 @@ namespace OpenRA.Mods.RA
public object Create(ActorInitializer init) { return new PaletteFromRGBA(init.world, this); }
}
class PaletteFromRGBA
class PaletteFromRGBA : IPalette
{
readonly World world;
readonly PaletteFromRGBAInfo info;
public PaletteFromRGBA(World world, PaletteFromRGBAInfo info)
{
if (info.Theatre == null ||
info.Theatre.ToLowerInvariant() == world.Map.Theater.ToLowerInvariant())
this.world = world;
this.info = info;
}
public void InitPalette( WorldRenderer wr )
{
if (info.Theatre == null || info.Theatre.ToLowerInvariant() == world.Map.Theater.ToLowerInvariant())
{
// TODO: This shouldn't rely on a base palette
var wr = world.WorldRenderer;
var pal = wr.GetPalette("terrain");
wr.AddPalette(info.Name, new Palette(pal, new SingleColorRemap(Color.FromArgb(info.A, info.R, info.G, info.B))));
}

View File

@@ -11,6 +11,7 @@
using System.Drawing;
using OpenRA.FileFormats;
using OpenRA.Traits;
using OpenRA.Graphics;
namespace OpenRA.Mods.RA
{
@@ -18,17 +19,21 @@ namespace OpenRA.Mods.RA
{
public readonly string Name = "shroud";
public readonly bool IsFog = false;
public object Create(ActorInitializer init) { return new ShroudPalette(init.world, this); }
public object Create(ActorInitializer init) { return new ShroudPalette(this); }
}
class ShroudPalette
class ShroudPalette : IPalette
{
public ShroudPalette(World world, ShroudPaletteInfo info)
readonly ShroudPaletteInfo info;
public ShroudPalette( ShroudPaletteInfo info )
{
// TODO: This shouldn't rely on a base palette
var wr = world.WorldRenderer;
var pal = wr.GetPalette("terrain");
wr.AddPalette(info.Name, new Palette(pal, new ShroudPaletteRemap(info.IsFog)));
this.info = info;
}
public void InitPalette( WorldRenderer wr )
{
var pal = wr.GetPalette( "terrain" );
wr.AddPalette( info.Name, new Palette( pal, new ShroudPaletteRemap( info.IsFog ) ) );
}
}