Fix lobby color picker
This commit is contained in:
48
OpenRA.Mods.Cnc/CncColorPickerPaletteModifier.cs
Normal file
48
OpenRA.Mods.Cnc/CncColorPickerPaletteModifier.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 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.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.Cnc.Widgets;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Cnc
|
||||
{
|
||||
class CncColorPickerPaletteModifierInfo : ITraitInfo
|
||||
{
|
||||
public string PlayerPalette = "player";
|
||||
public object Create( ActorInitializer init ) { return new CncColorPickerPaletteModifier( this ); }
|
||||
}
|
||||
|
||||
class CncColorPickerPaletteModifier : IPalette, IPaletteModifier
|
||||
{
|
||||
CncColorPickerPaletteModifierInfo Info;
|
||||
PaletteFormat format;
|
||||
|
||||
public CncColorPickerPaletteModifier(CncColorPickerPaletteModifierInfo info) { Info = info; }
|
||||
|
||||
public void InitPalette( WorldRenderer wr )
|
||||
{
|
||||
var info = Rules.Info["player"].Traits.WithInterface<PlayerColorPaletteInfo>()
|
||||
.Where(p => p.BaseName == Info.PlayerPalette)
|
||||
.First();
|
||||
format = info.PaletteFormat;
|
||||
wr.AddPalette("colorpicker", wr.GetPalette(info.BasePalette));
|
||||
}
|
||||
|
||||
public void AdjustPalette(Dictionary<string, Palette> palettes)
|
||||
{
|
||||
palettes["colorpicker"] = new Palette(palettes["colorpicker"],
|
||||
new PlayerColorRemap(CncLobbyLogic.CurrentColorPreview, format));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,6 +81,7 @@
|
||||
<Compile Include="Widgets\CncIngameChromeLogic.cs" />
|
||||
<Compile Include="Widgets\CncInstallLogic.cs" />
|
||||
<Compile Include="Widgets\CncMusicPlayerLogic.cs" />
|
||||
<Compile Include="CncColorPickerPaletteModifier.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
@@ -229,5 +229,45 @@ namespace OpenRA.Mods.Cnc.Widgets
|
||||
|
||||
public override Widget Clone() { return new CncTextFieldWidget(this); }
|
||||
}
|
||||
|
||||
public class CncSliderWidget : SliderWidget
|
||||
{
|
||||
public Func<bool> IsDisabled = () => false;
|
||||
|
||||
public CncSliderWidget() : base() { }
|
||||
public CncSliderWidget(CncSliderWidget other) : base(other) { }
|
||||
|
||||
|
||||
public override Widget Clone() { return new CncSliderWidget(this); }
|
||||
public override void DrawInner()
|
||||
{
|
||||
if (!IsVisible())
|
||||
return;
|
||||
|
||||
var tr = thumbRect;
|
||||
var trackWidth = RenderBounds.Width - tr.Width;
|
||||
var trackOrigin = RenderBounds.X + tr.Width / 2;
|
||||
var trackRect = new Rectangle(trackOrigin - 1, RenderBounds.Y + (RenderBounds.Height - TrackHeight) / 2, trackWidth + 2, TrackHeight);
|
||||
|
||||
// Tickmarks (hacked until we have real art)
|
||||
for (int i = 0; i < Ticks; i++)
|
||||
{
|
||||
var tickRect = new Rectangle(trackOrigin - 1 + (int)(i * trackWidth * 1f / (Ticks - 1)),
|
||||
RenderBounds.Y + RenderBounds.Height / 2, 2, RenderBounds.Height / 2);
|
||||
WidgetUtils.DrawPanel("button-hover", tickRect);
|
||||
}
|
||||
|
||||
// Track
|
||||
WidgetUtils.DrawPanel("button-pressed", trackRect);
|
||||
|
||||
// Thumb
|
||||
var state = IsDisabled() ? "button-disabled" :
|
||||
isMoving ? "button-pressed" :
|
||||
tr.Contains(Viewport.LastMousePos) ? "button-hover" :
|
||||
"button";
|
||||
|
||||
WidgetUtils.DrawPanel(state, tr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user