Fix lobby color picker

This commit is contained in:
Paul Chote
2011-05-10 21:27:24 +12:00
parent c4f40babb5
commit 86159f9ddc
6 changed files with 117 additions and 24 deletions

View File

@@ -25,7 +25,7 @@ namespace OpenRA.Widgets
private float Offset = 0;
int2 lastMouseLocation;
bool isMoving = false;
protected bool isMoving = false;
public SliderWidget()
: base()
@@ -159,7 +159,7 @@ namespace OpenRA.Widgets
public override Widget Clone() { return new SliderWidget(this); }
Rectangle thumbRect
protected Rectangle thumbRect
{
get
{

View 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));
}
}
}

View File

@@ -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">

View File

@@ -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);
}
}
}

View File

@@ -380,14 +380,14 @@ Container@SERVER_LOBBY:
Text:Start Game
Background@COLOR_CHOOSER:
Id:COLOR_CHOOSER
Background:dialog2
Width:310
Background:panel-black
Width:315
Height:120
Children:
Button@BUTTON_OK:
CncMenuButton@BUTTON_OK:
Id:BUTTON_OK
X:210
Y:85
Y:80
Width:90
Height:25
Text:Ok
@@ -395,17 +395,18 @@ Background@COLOR_CHOOSER:
ShpImage@FACT:
Id:FACT
X:220
Y:10
Y:15
Image:fact
Palette:colorpicker
Label@HUE_LABEL:
X:0
X:5
Y:5
Width:40
Height:20
Align: Right
Text: Hue:
Slider@HUE:
Align:Right
Text:Hue:
Font:Bold
CncSlider@HUE:
Id:HUE_SLIDER
X:43
Y:10
@@ -413,13 +414,14 @@ Background@COLOR_CHOOSER:
Height:20
Ticks:5
Label@SAT_LABEL:
X:0
X:5
Y:30
Width:40
Height:20
Align: Right
Text: Sat:
Slider@SAT:
Align:Right
Text:Sat:
Font:Bold
CncSlider@SAT:
Id:SAT_SLIDER
X:43
Y:35
@@ -427,13 +429,14 @@ Background@COLOR_CHOOSER:
Height:20
Ticks:5
Label@LUM_LABEL:
X:0
X:5
Y:55
Width:40
Height:20
Align: Right
Text: Lum:
Slider@LUM:
Align:Right
Text:Lum:
Font:Bold
CncSlider@LUM:
Id:LUM_SLIDER
X:43
Y:60
@@ -442,13 +445,14 @@ Background@COLOR_CHOOSER:
Ticks:5
Range:0.2,1
Label@RANGE_LABEL:
X:0
X:5
Y:80
Width:40
Height:20
Align: Right
Text: Ran:
Slider@RANGE:
Align:Right
Text:Ran:
Font:Bold
CncSlider@RANGE:
Id:RANGE_SLIDER
X:43
Y:85

View File

@@ -82,7 +82,7 @@ World:
G: 0
B: 0
A: 180
ColorPickerPaletteModifier:
CncColorPickerPaletteModifier:
ShroudPalette@shroud:
ShroudPalette@fog:
IsFog: yes