Move ColorValidator logic into a new ColorPickerManager trait.
This commit is contained in:
@@ -385,11 +385,11 @@ namespace OpenRA.Mods.Common.Server
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Pick a random color for the bot
|
// 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 terrainColors = server.ModData.DefaultTerrainInfo[server.Map.TileSet].RestrictedPlayerColors;
|
||||||
var playerColors = server.LobbyInfo.Clients.Select(c => c.Color)
|
var playerColors = server.LobbyInfo.Clients.Select(c => c.Color)
|
||||||
.Concat(server.Map.Players.Players.Values.Select(p => p.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);
|
server.LobbyInfo.Clients.Add(bot);
|
||||||
}
|
}
|
||||||
@@ -1089,7 +1089,7 @@ namespace OpenRA.Mods.Common.Server
|
|||||||
{
|
{
|
||||||
lock (server.LobbyInfo)
|
lock (server.LobbyInfo)
|
||||||
{
|
{
|
||||||
var validator = server.ModData.Manifest.Get<ColorValidator>();
|
var colorManager = server.ModData.DefaultRules.Actors[SystemActors.World].TraitInfo<ColorPickerManagerInfo>();
|
||||||
var askColor = askedColor;
|
var askColor = askedColor;
|
||||||
|
|
||||||
Action<string> onError = message =>
|
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)
|
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();
|
.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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#region Copyright & License Information
|
#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
|
* 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
|
* available to you under the terms of the GNU General Public License
|
||||||
* as published by the Free Software Foundation, either version 3 of
|
* as published by the Free Software Foundation, either version 3 of
|
||||||
@@ -14,10 +14,12 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
using OpenRA.Support;
|
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
|
// The bigger the color threshold, the less permissive is the algorithm
|
||||||
public readonly int Threshold = 0x50;
|
public readonly int Threshold = 0x50;
|
||||||
@@ -182,4 +184,6 @@ namespace OpenRA.Mods.Common
|
|||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ColorPickerManager { }
|
||||||
}
|
}
|
||||||
@@ -65,8 +65,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set the initial state
|
// Set the initial state
|
||||||
var validator = modData.Manifest.Get<ColorValidator>();
|
var colorManager = world.WorldActor.Info.TraitInfo<ColorPickerManagerInfo>();
|
||||||
mixer.SetPaletteRange(validator.HsvSaturationRange[0], validator.HsvSaturationRange[1], validator.HsvValueRange[0], validator.HsvValueRange[1]);
|
mixer.SetPaletteRange(colorManager.HsvSaturationRange[0], colorManager.HsvSaturationRange[1], colorManager.HsvValueRange[0], colorManager.HsvValueRange[1]);
|
||||||
mixer.Set(initialColor);
|
mixer.Set(initialColor);
|
||||||
hueSlider.Value = HueFromColor(initialColor);
|
hueSlider.Value = HueFromColor(initialColor);
|
||||||
|
|
||||||
@@ -116,10 +116,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
for (var i = 0; i < paletteCols; i++)
|
for (var i = 0; i < paletteCols; i++)
|
||||||
{
|
{
|
||||||
var colorIndex = j * paletteCols + i;
|
var colorIndex = j * paletteCols + i;
|
||||||
if (colorIndex >= validator.TeamColorPresets.Length)
|
if (colorIndex >= colorManager.TeamColorPresets.Length)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
var color = validator.TeamColorPresets[colorIndex];
|
var color = colorManager.TeamColorPresets[colorIndex];
|
||||||
|
|
||||||
var newSwatch = (ColorBlockWidget)presetColorTemplate.Clone();
|
var newSwatch = (ColorBlockWidget)presetColorTemplate.Clone();
|
||||||
newSwatch.GetColor = () => color;
|
newSwatch.GetColor = () => color;
|
||||||
|
|||||||
@@ -263,9 +263,6 @@ GameSpeeds:
|
|||||||
Timestep: 20
|
Timestep: 20
|
||||||
OrderLatency: 6
|
OrderLatency: 6
|
||||||
|
|
||||||
ColorValidator:
|
|
||||||
TeamColorPresets: f70606, ff7a22, f8d3b3, f8e947, 94b319, f335a0, a64d6c, ce08f9, f5b2db, 12b572, 502048, 1d06f7, 328dff, 78dbf8, cef6b1, 391d1d
|
|
||||||
|
|
||||||
ModContent:
|
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.
|
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
|
QuickDownload: basefiles
|
||||||
|
|||||||
@@ -254,6 +254,8 @@ World:
|
|||||||
ShellmapRoot: MENU_BACKGROUND
|
ShellmapRoot: MENU_BACKGROUND
|
||||||
ScriptTriggers:
|
ScriptTriggers:
|
||||||
TimeLimitManager:
|
TimeLimitManager:
|
||||||
|
ColorPickerManager:
|
||||||
|
TeamColorPresets: f70606, ff7a22, f8d3b3, f8e947, 94b319, f335a0, a64d6c, ce08f9, f5b2db, 12b572, 502048, 1d06f7, 328dff, 78dbf8, cef6b1, 391d1d
|
||||||
|
|
||||||
EditorWorld:
|
EditorWorld:
|
||||||
Inherits: ^BaseWorld
|
Inherits: ^BaseWorld
|
||||||
|
|||||||
@@ -238,9 +238,6 @@ GameSpeeds:
|
|||||||
Timestep: 20
|
Timestep: 20
|
||||||
OrderLatency: 6
|
OrderLatency: 6
|
||||||
|
|
||||||
ColorValidator:
|
|
||||||
TeamColorPresets: 9023cd, f53333, ffae00, fff830, 87f506, f872ad, da06f3, ddb8ff, def7b2, 39c46f, 200738, 280df6, 2f86f2, 76d2f8, 498221, 392929
|
|
||||||
|
|
||||||
ModContent:
|
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.
|
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.
|
HeaderMessage: The original game content may be copied from an original game disc,\nor downloaded from an online mirror of the game files.
|
||||||
|
|||||||
@@ -235,6 +235,8 @@ World:
|
|||||||
ScriptTriggers:
|
ScriptTriggers:
|
||||||
StartGameNotification:
|
StartGameNotification:
|
||||||
TimeLimitManager:
|
TimeLimitManager:
|
||||||
|
ColorPickerManager:
|
||||||
|
TeamColorPresets: 9023cd, f53333, ffae00, fff830, 87f506, f872ad, da06f3, ddb8ff, def7b2, 39c46f, 200738, 280df6, 2f86f2, 76d2f8, 498221, 392929
|
||||||
|
|
||||||
EditorWorld:
|
EditorWorld:
|
||||||
Inherits: ^BaseWorld
|
Inherits: ^BaseWorld
|
||||||
|
|||||||
@@ -268,9 +268,6 @@ GameSpeeds:
|
|||||||
Timestep: 20
|
Timestep: 20
|
||||||
OrderLatency: 6
|
OrderLatency: 6
|
||||||
|
|
||||||
ColorValidator:
|
|
||||||
TeamColorPresets: f7b3b3, f50606, 98331f, f57606, f7bb06, f861a4, da06f3, ddb8ff, 06f739, cef7b2, 200738, 280df6, 2f86f2, 76d2f8, 34ba93, 391d1d
|
|
||||||
|
|
||||||
ModContent:
|
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.
|
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
|
QuickDownload: quickinstall
|
||||||
|
|||||||
@@ -280,6 +280,8 @@ World:
|
|||||||
3: WarningThreeMinutesRemaining
|
3: WarningThreeMinutesRemaining
|
||||||
2: WarningTwoMinutesRemaining
|
2: WarningTwoMinutesRemaining
|
||||||
1: WarningOneMinuteRemaining
|
1: WarningOneMinuteRemaining
|
||||||
|
ColorPickerManager:
|
||||||
|
TeamColorPresets: f7b3b3, f50606, 98331f, f57606, f7bb06, f861a4, da06f3, ddb8ff, 06f739, cef7b2, 200738, 280df6, 2f86f2, 76d2f8, 34ba93, 391d1d
|
||||||
|
|
||||||
EditorWorld:
|
EditorWorld:
|
||||||
Inherits: ^BaseWorld
|
Inherits: ^BaseWorld
|
||||||
|
|||||||
@@ -297,9 +297,6 @@ GameSpeeds:
|
|||||||
Timestep: 20
|
Timestep: 20
|
||||||
OrderLatency: 6
|
OrderLatency: 6
|
||||||
|
|
||||||
ColorValidator:
|
|
||||||
TeamColorPresets: f70606, ff7a22, f8d3b3, f8e947, 94b319, f335a0, a64d6c, ce08f9, f5b2db, 12b572, 4A1948, 1d06f7, 328dff, 78dbf8, cef6b1, 391d1d
|
|
||||||
|
|
||||||
ModContent:
|
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.
|
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
|
QuickDownload: quickinstall
|
||||||
|
|||||||
@@ -380,6 +380,8 @@ World:
|
|||||||
ShellmapRoot: MAINMENU_PRERELEASE_NOTIFICATION
|
ShellmapRoot: MAINMENU_PRERELEASE_NOTIFICATION
|
||||||
ScriptTriggers:
|
ScriptTriggers:
|
||||||
TimeLimitManager:
|
TimeLimitManager:
|
||||||
|
ColorPickerManager:
|
||||||
|
TeamColorPresets: f70606, ff7a22, f8d3b3, f8e947, 94b319, f335a0, a64d6c, ce08f9, f5b2db, 12b572, 4A1948, 1d06f7, 328dff, 78dbf8, cef6b1, 391d1d
|
||||||
|
|
||||||
EditorWorld:
|
EditorWorld:
|
||||||
Inherits: ^BaseWorld
|
Inherits: ^BaseWorld
|
||||||
|
|||||||
Reference in New Issue
Block a user