Move ColorValidator logic into a new ColorPickerManager trait.

This commit is contained in:
Paul Chote
2021-04-11 21:27:51 +01:00
committed by teinarss
parent 52577c1de9
commit 7b58f03f1c
11 changed files with 23 additions and 23 deletions

View File

@@ -385,11 +385,11 @@ namespace OpenRA.Mods.Common.Server
};
// Pick a random color for the bot
var validator = server.ModData.Manifest.Get<ColorValidator>();
var colorManager = server.ModData.DefaultRules.Actors[SystemActors.World].TraitInfo<ColorPickerManagerInfo>();
var terrainColors = server.ModData.DefaultTerrainInfo[server.Map.TileSet].RestrictedPlayerColors;
var playerColors = server.LobbyInfo.Clients.Select(c => c.Color)
.Concat(server.Map.Players.Players.Values.Select(p => p.Color));
bot.Color = bot.PreferredColor = validator.RandomPresetColor(server.Random, terrainColors, playerColors);
bot.Color = bot.PreferredColor = colorManager.RandomPresetColor(server.Random, terrainColors, playerColors);
server.LobbyInfo.Clients.Add(bot);
}
@@ -1089,7 +1089,7 @@ namespace OpenRA.Mods.Common.Server
{
lock (server.LobbyInfo)
{
var validator = server.ModData.Manifest.Get<ColorValidator>();
var colorManager = server.ModData.DefaultRules.Actors[SystemActors.World].TraitInfo<ColorPickerManagerInfo>();
var askColor = askedColor;
Action<string> onError = message =>
@@ -1102,7 +1102,7 @@ namespace OpenRA.Mods.Common.Server
var playerColors = server.LobbyInfo.Clients.Where(c => c.Index != playerIndex).Select(c => c.Color)
.Concat(server.Map.Players.Players.Values.Select(p => p.Color)).ToList();
return validator.MakeValid(askColor, server.Random, terrainColors, playerColors, onError);
return colorManager.MakeValid(askColor, server.Random, terrainColors, playerColors, onError);
}
}

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2020 The OpenRA Developers (see AUTHORS)
* Copyright 2007-2021 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, either version 3 of
@@ -14,10 +14,12 @@ using System.Collections.Generic;
using System.Linq;
using OpenRA.Primitives;
using OpenRA.Support;
using OpenRA.Traits;
namespace OpenRA.Mods.Common
namespace OpenRA.Mods.Common.Traits
{
public class ColorValidator : IGlobalModData
[Desc("Configuration options for the lobby player color picker. Attach this to the world actor.")]
public class ColorPickerManagerInfo : TraitInfo<ColorPickerManager>
{
// The bigger the color threshold, the less permissive is the algorithm
public readonly int Threshold = 0x50;
@@ -182,4 +184,6 @@ namespace OpenRA.Mods.Common
return color;
}
}
public class ColorPickerManager { }
}

View File

@@ -65,8 +65,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
}
// Set the initial state
var validator = modData.Manifest.Get<ColorValidator>();
mixer.SetPaletteRange(validator.HsvSaturationRange[0], validator.HsvSaturationRange[1], validator.HsvValueRange[0], validator.HsvValueRange[1]);
var colorManager = world.WorldActor.Info.TraitInfo<ColorPickerManagerInfo>();
mixer.SetPaletteRange(colorManager.HsvSaturationRange[0], colorManager.HsvSaturationRange[1], colorManager.HsvValueRange[0], colorManager.HsvValueRange[1]);
mixer.Set(initialColor);
hueSlider.Value = HueFromColor(initialColor);
@@ -116,10 +116,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
for (var i = 0; i < paletteCols; i++)
{
var colorIndex = j * paletteCols + i;
if (colorIndex >= validator.TeamColorPresets.Length)
if (colorIndex >= colorManager.TeamColorPresets.Length)
break;
var color = validator.TeamColorPresets[colorIndex];
var color = colorManager.TeamColorPresets[colorIndex];
var newSwatch = (ColorBlockWidget)presetColorTemplate.Clone();
newSwatch.GetColor = () => color;

View File

@@ -263,9 +263,6 @@ GameSpeeds:
Timestep: 20
OrderLatency: 6
ColorValidator:
TeamColorPresets: f70606, ff7a22, f8d3b3, f8e947, 94b319, f335a0, a64d6c, ce08f9, f5b2db, 12b572, 502048, 1d06f7, 328dff, 78dbf8, cef6b1, 391d1d
ModContent:
InstallPromptMessage: Tiberian Dawn requires artwork and audio from the original game.\n\nQuick Install will automatically download this content (without music\nor videos) from a mirror of the 2007 C&C Gold freeware release.\n\nAdvanced Install includes options for copying the music, videos, and\nother content from an original game disc or digital installation.
QuickDownload: basefiles

View File

@@ -254,6 +254,8 @@ World:
ShellmapRoot: MENU_BACKGROUND
ScriptTriggers:
TimeLimitManager:
ColorPickerManager:
TeamColorPresets: f70606, ff7a22, f8d3b3, f8e947, 94b319, f335a0, a64d6c, ce08f9, f5b2db, 12b572, 502048, 1d06f7, 328dff, 78dbf8, cef6b1, 391d1d
EditorWorld:
Inherits: ^BaseWorld

View File

@@ -238,9 +238,6 @@ GameSpeeds:
Timestep: 20
OrderLatency: 6
ColorValidator:
TeamColorPresets: 9023cd, f53333, ffae00, fff830, 87f506, f872ad, da06f3, ddb8ff, def7b2, 39c46f, 200738, 280df6, 2f86f2, 76d2f8, 498221, 392929
ModContent:
InstallPromptMessage: Dune 2000 requires artwork and audio from the original game.\n\nQuick Install will automatically download this content (without\nmusic or videos) from an online mirror of the game files.\n\nAdvanced Install includes options for copying the music, videos,\nand other content from an original game disc.
HeaderMessage: The original game content may be copied from an original game disc,\nor downloaded from an online mirror of the game files.

View File

@@ -235,6 +235,8 @@ World:
ScriptTriggers:
StartGameNotification:
TimeLimitManager:
ColorPickerManager:
TeamColorPresets: 9023cd, f53333, ffae00, fff830, 87f506, f872ad, da06f3, ddb8ff, def7b2, 39c46f, 200738, 280df6, 2f86f2, 76d2f8, 498221, 392929
EditorWorld:
Inherits: ^BaseWorld

View File

@@ -268,9 +268,6 @@ GameSpeeds:
Timestep: 20
OrderLatency: 6
ColorValidator:
TeamColorPresets: f7b3b3, f50606, 98331f, f57606, f7bb06, f861a4, da06f3, ddb8ff, 06f739, cef7b2, 200738, 280df6, 2f86f2, 76d2f8, 34ba93, 391d1d
ModContent:
InstallPromptMessage: Red Alert requires artwork and audio from the original game.\n\nQuick Install will automatically download this content (without music\nor videos) from a mirror of the 2008 Red Alert freeware release.\n\nAdvanced Install includes options for copying the music, videos, and\nother content from an original game disc or digital installation.
QuickDownload: quickinstall

View File

@@ -280,6 +280,8 @@ World:
3: WarningThreeMinutesRemaining
2: WarningTwoMinutesRemaining
1: WarningOneMinuteRemaining
ColorPickerManager:
TeamColorPresets: f7b3b3, f50606, 98331f, f57606, f7bb06, f861a4, da06f3, ddb8ff, 06f739, cef7b2, 200738, 280df6, 2f86f2, 76d2f8, 34ba93, 391d1d
EditorWorld:
Inherits: ^BaseWorld

View File

@@ -297,9 +297,6 @@ GameSpeeds:
Timestep: 20
OrderLatency: 6
ColorValidator:
TeamColorPresets: f70606, ff7a22, f8d3b3, f8e947, 94b319, f335a0, a64d6c, ce08f9, f5b2db, 12b572, 4A1948, 1d06f7, 328dff, 78dbf8, cef6b1, 391d1d
ModContent:
InstallPromptMessage: Tiberian Sun requires artwork and audio from the original game.\n\nQuick Install will automatically download this content (without music\nor videos) from a mirror of the 2012 Tiberian Sun freeware release.\n\nAdvanced Install includes options for copying the music, videos, and\nother content from an original game disc or digital installation.
QuickDownload: quickinstall

View File

@@ -380,6 +380,8 @@ World:
ShellmapRoot: MAINMENU_PRERELEASE_NOTIFICATION
ScriptTriggers:
TimeLimitManager:
ColorPickerManager:
TeamColorPresets: f70606, ff7a22, f8d3b3, f8e947, 94b319, f335a0, a64d6c, ce08f9, f5b2db, 12b572, 4A1948, 1d06f7, 328dff, 78dbf8, cef6b1, 391d1d
EditorWorld:
Inherits: ^BaseWorld