unify C&C and RA colorpicker palette manipulation code
This commit is contained in:
@@ -12,29 +12,28 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA.Widgets.Logic;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class ColorPickerPaletteModifierInfo : ITraitInfo
|
||||
public class ColorPickerPaletteModifierInfo : ITraitInfo
|
||||
{
|
||||
public string PlayerPalette = "player";
|
||||
public object Create( ActorInitializer init ) { return new ColorPickerPaletteModifier( this ); }
|
||||
}
|
||||
|
||||
class ColorPickerPaletteModifier : IPalette, IPaletteModifier
|
||||
public class ColorPickerPaletteModifier : IPalette, IPaletteModifier
|
||||
{
|
||||
ColorPickerPaletteModifierInfo Info;
|
||||
PaletteFormat format;
|
||||
public ColorRamp Ramp;
|
||||
|
||||
public ColorPickerPaletteModifier(ColorPickerPaletteModifierInfo info) { Info = info; }
|
||||
|
||||
public void InitPalette( WorldRenderer wr )
|
||||
{
|
||||
var info = Rules.Info["player"].Traits.WithInterface<PlayerColorPaletteInfo>()
|
||||
.Where(p => p.BaseName == Info.PlayerPalette)
|
||||
.First();
|
||||
.First(p => p.BaseName == Info.PlayerPalette);
|
||||
format = info.PaletteFormat;
|
||||
wr.AddPalette("colorpicker", wr.GetPalette(info.BasePalette));
|
||||
}
|
||||
@@ -42,7 +41,7 @@ namespace OpenRA.Mods.RA
|
||||
public void AdjustPalette(Dictionary<string, Palette> palettes)
|
||||
{
|
||||
palettes["colorpicker"] = new Palette(palettes["colorpicker"],
|
||||
new PlayerColorRemap(LobbyLogic.CurrentColorPreview, format));
|
||||
new PlayerColorRemap(Ramp, format));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ namespace OpenRA.Mods.RA
|
||||
new WidgetArgs() { { "orderManager", orderManager } });
|
||||
break;
|
||||
case ConnectionState.Connected:
|
||||
var lobby = Game.OpenWindow(orderManager.world, "SERVER_LOBBY");
|
||||
var lobby = Game.OpenWindow("SERVER_LOBBY", new WidgetArgs {});
|
||||
lobby.GetWidget<ChatDisplayWidget>("CHAT_DISPLAY").ClearChat();
|
||||
lobby.GetWidget("CHANGEMAP_BUTTON").Visible = true;
|
||||
lobby.GetWidget("ALLOWCHEATS_CHECKBOX").Visible = true;
|
||||
|
||||
@@ -30,12 +30,14 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
string MapUid;
|
||||
Map Map;
|
||||
|
||||
public static ColorRamp CurrentColorPreview;
|
||||
ColorPickerPaletteModifier PlayerPalettePreview;
|
||||
|
||||
readonly OrderManager orderManager;
|
||||
readonly WorldRenderer worldRenderer;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
internal LobbyLogic([ObjectCreator.Param( "widget" )] Widget lobby,
|
||||
[ObjectCreator.Param] World world, // Shellmap world
|
||||
[ObjectCreator.Param] OrderManager orderManager,
|
||||
[ObjectCreator.Param] WorldRenderer worldRenderer)
|
||||
{
|
||||
@@ -47,7 +49,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
Game.LobbyInfoChanged += UpdatePlayerList;
|
||||
UpdateCurrentMap();
|
||||
|
||||
CurrentColorPreview = Game.Settings.Player.ColorRamp;
|
||||
PlayerPalettePreview = world.WorldActor.Trait<ColorPickerPaletteModifier>();
|
||||
PlayerPalettePreview.Ramp = Game.Settings.Player.ColorRamp;
|
||||
|
||||
Players = lobby.GetWidget<ScrollPanelWidget>("PLAYERS");
|
||||
LocalPlayerTemplate = Players.GetWidget("TEMPLATE_LOCAL");
|
||||
@@ -208,7 +211,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
|
||||
void UpdateColorPreview(float hf, float sf, float lf, float r)
|
||||
{
|
||||
CurrentColorPreview = new ColorRamp((byte)(hf * 255), (byte)(sf * 255), (byte)(lf * 255), (byte)(r * 255));
|
||||
PlayerPalettePreview.Ramp = new ColorRamp((byte)(hf * 255), (byte)(sf * 255), (byte)(lf * 255), (byte)(r * 255));
|
||||
}
|
||||
|
||||
void UpdateCurrentMap()
|
||||
|
||||
Reference in New Issue
Block a user