Unify ra and cnc main menu logic and clean up the main menus.

Move a bunch of buttons into an Extras submenu and the server browser.
Move CncMenuPaletteEffect to ra so it can be used elsewhere and rename it to MenuPaletteEffect.
This commit is contained in:
ScottNZ
2014-01-31 23:29:59 +13:00
parent 81ec978a61
commit 1a3ec26a1e
25 changed files with 577 additions and 601 deletions

View File

@@ -0,0 +1,88 @@
#region Copyright & License Information
/*
* Copyright 2007-2014 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 COPYING.
*/
#endregion
using System.Collections.Generic;
using System.Drawing;
using OpenRA.FileFormats;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
public class MenuPaletteEffectInfo : ITraitInfo
{
public readonly int FadeLength = 10;
public object Create(ActorInitializer init) { return new MenuPaletteEffect(this); }
}
public class MenuPaletteEffect : IPaletteModifier, ITickRender
{
public enum EffectType { None, Black, Desaturated }
public readonly MenuPaletteEffectInfo Info;
int remainingFrames;
EffectType from = EffectType.Black;
EffectType to = EffectType.Black;
public MenuPaletteEffect(MenuPaletteEffectInfo info) { Info = info; }
public void Fade(EffectType type)
{
remainingFrames = Info.FadeLength;
from = to;
to = type;
}
public void TickRender(WorldRenderer wr, Actor self)
{
if (remainingFrames > 0)
remainingFrames--;
}
Color ColorForEffect(EffectType t, Color orig)
{
switch (t)
{
case EffectType.Black:
return Color.FromArgb(orig.A, Color.Black);
case EffectType.Desaturated:
var lum = (int)(255 * orig.GetBrightness());
return Color.FromArgb(orig.A, lum, lum, lum);
default:
case EffectType.None:
return orig;
}
}
public void AdjustPalette(Dictionary<string, Palette> palettes)
{
if (to == EffectType.None && remainingFrames == 0)
return;
foreach (var pal in palettes)
{
for (var x = 0; x < 256; x++)
{
var orig = pal.Value.GetColor(x);
var t = ColorForEffect(to, orig);
if (remainingFrames == 0)
pal.Value.SetColor(x, t);
else
{
var f = ColorForEffect(from, orig);
pal.Value.SetColor(x, Exts.ColorLerp((float)remainingFrames / Info.FadeLength, t, f));
}
}
}
}
}
}