diff --git a/OpenRA.Game/Widgets/SliderWidget.cs b/OpenRA.Game/Widgets/SliderWidget.cs index 9984083401..53f3975cb9 100755 --- a/OpenRA.Game/Widgets/SliderWidget.cs +++ b/OpenRA.Game/Widgets/SliderWidget.cs @@ -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 { diff --git a/OpenRA.Mods.Cnc/CncColorPickerPaletteModifier.cs b/OpenRA.Mods.Cnc/CncColorPickerPaletteModifier.cs new file mode 100644 index 0000000000..7865b835f4 --- /dev/null +++ b/OpenRA.Mods.Cnc/CncColorPickerPaletteModifier.cs @@ -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() + .Where(p => p.BaseName == Info.PlayerPalette) + .First(); + format = info.PaletteFormat; + wr.AddPalette("colorpicker", wr.GetPalette(info.BasePalette)); + } + + public void AdjustPalette(Dictionary palettes) + { + palettes["colorpicker"] = new Palette(palettes["colorpicker"], + new PlayerColorRemap(CncLobbyLogic.CurrentColorPreview, format)); + } + } +} diff --git a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj index 0072033ca7..a09be31a4d 100644 --- a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj +++ b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj @@ -81,6 +81,7 @@ + diff --git a/OpenRA.Mods.Cnc/Widgets/CncMenuButton.cs b/OpenRA.Mods.Cnc/Widgets/CncMenuButton.cs index 91829bb3f4..1db65d87d4 100644 --- a/OpenRA.Mods.Cnc/Widgets/CncMenuButton.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncMenuButton.cs @@ -229,5 +229,45 @@ namespace OpenRA.Mods.Cnc.Widgets public override Widget Clone() { return new CncTextFieldWidget(this); } } + + public class CncSliderWidget : SliderWidget + { + public Func 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); + } + } } diff --git a/mods/cnc/chrome/lobby.yaml b/mods/cnc/chrome/lobby.yaml index 74b222c3e9..205c47b01d 100644 --- a/mods/cnc/chrome/lobby.yaml +++ b/mods/cnc/chrome/lobby.yaml @@ -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 diff --git a/mods/cnc/rules/system.yaml b/mods/cnc/rules/system.yaml index cf57aafd37..257edfaf29 100644 --- a/mods/cnc/rules/system.yaml +++ b/mods/cnc/rules/system.yaml @@ -82,7 +82,7 @@ World: G: 0 B: 0 A: 180 - ColorPickerPaletteModifier: + CncColorPickerPaletteModifier: ShroudPalette@shroud: ShroudPalette@fog: IsFog: yes