diff --git a/OpenRA.Mods.Cnc/Widgets/CncLobbyLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncLobbyLogic.cs index bae7878e91..c876c58839 100755 --- a/OpenRA.Mods.Cnc/Widgets/CncLobbyLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncLobbyLogic.cs @@ -420,7 +420,7 @@ namespace OpenRA.Mods.Cnc.Widgets { "initialRamp", orderManager.LocalClient.ColorRamp } }); - color.DisplayPanel(colorChooser); + color.AttachPanel(colorChooser); } void UpdatePlayerList() diff --git a/OpenRA.Mods.Cnc/Widgets/CncMenuButton.cs b/OpenRA.Mods.Cnc/Widgets/CncMenuButton.cs index 63a44edd09..724b0955f5 100644 --- a/OpenRA.Mods.Cnc/Widgets/CncMenuButton.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncMenuButton.cs @@ -34,7 +34,7 @@ namespace OpenRA.Mods.Cnc.Widgets panel = fullscreenMask = null; } - public void DisplayPanel(Widget p) + public void AttachPanel(Widget p) { if (panel != null) throw new InvalidOperationException("Attempted to attach a panel to an open dropdown"); diff --git a/OpenRA.Mods.Cnc/Widgets/CncSettingsLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncSettingsLogic.cs index af9f2f23e4..25856a7a7e 100755 --- a/OpenRA.Mods.Cnc/Widgets/CncSettingsLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncSettingsLogic.cs @@ -137,7 +137,7 @@ namespace OpenRA.Mods.Cnc.Widgets mouseScroll = Game.Settings.Game.MouseScroll; var mouseScrollDropdown = inputPane.GetWidget("MOUSE_SCROLL"); - mouseScrollDropdown.OnMouseUp = _ => ShowMouseScrollDropdown(mouseScrollDropdown); + mouseScrollDropdown.OnClick = () => ShowMouseScrollDropdown(mouseScrollDropdown); mouseScrollDropdown.GetText = () => mouseScroll.ToString(); var teamchat = Game.Settings.Game.TeamChatToggle; @@ -147,7 +147,7 @@ namespace OpenRA.Mods.Cnc.Widgets groupAddModifier = Game.Settings.Keyboard.ControlGroupModifier; var groupModifierDropdown = inputPane.GetWidget("GROUPADD_MODIFIER"); - groupModifierDropdown.OnMouseUp = _ => ShowGroupModifierDropdown(groupModifierDropdown); + groupModifierDropdown.OnClick = () => ShowGroupModifierDropdown(groupModifierDropdown); groupModifierDropdown.GetText = () => groupAddModifier.ToString(); @@ -214,31 +214,32 @@ namespace OpenRA.Mods.Cnc.Widgets { "initialRamp", playerColor } }); - color.DisplayPanel(colorChooser); + color.AttachPanel(colorChooser); } - bool ShowGroupModifierDropdown(Widget dropdown) + void ShowGroupModifierDropdown(CncDropDownButtonWidget dropdown) { - var dropDownOptions = new List>() - { - Pair.New("Ctrl", new Action(() => groupAddModifier = Modifiers.Ctrl)), - Pair.New("Alt", new Action(() => groupAddModifier = Modifiers.Alt)), - Pair.New("Shift", new Action(() => groupAddModifier = Modifiers.Shift)), - // TODO: Display this as Cmd on osx once we have platform detection - Pair.New("Meta", new Action(() => groupAddModifier = Modifiers.Meta)), - }; + var panel = Game.LoadWidget(world, "LABEL_DROPDOWN_TEMPLATE", null, new WidgetArgs()) as ScrollPanelWidget; + var itemTemplate = panel.GetWidget("TEMPLATE"); + var options = new List>() + { + Pair.New("Ctrl", Modifiers.Ctrl), + Pair.New("Alt", Modifiers.Alt), + Pair.New("Shift", Modifiers.Shift), + // TODO: Display this as Cmd on osx once we have platform detection + Pair.New("Meta", Modifiers.Meta) + }; - CncDropDownButtonWidget.ShowDropDown(dropdown, - dropDownOptions, - (ac, w) => new LabelWidget - { - Bounds = new Rectangle(0, 0, w, 24), - Text = ac.First, - Align = LabelWidget.TextAlign.Center, - OnMouseUp = mi => { ac.Second(); return true; }, - }); - return true; + foreach (var o in options) + { + var key = o; + var item = ScrollItemWidget.Setup(itemTemplate, () => groupAddModifier == key.Second, () => { groupAddModifier = key.Second; dropdown.RemovePanel(); }); + item.GetWidget("LABEL").GetText = () => key.First; + panel.AddChild(item); + } + panel.Bounds.Height = panel.ContentHeight; + dropdown.AttachPanel(panel); } bool ShowWindowModeDropdown(Widget dropdown) diff --git a/mods/cnc/chrome/dropdowns.yaml b/mods/cnc/chrome/dropdowns.yaml new file mode 100644 index 0000000000..e103c50833 --- /dev/null +++ b/mods/cnc/chrome/dropdowns.yaml @@ -0,0 +1,91 @@ +Background@COLOR_CHOOSER: + Id:COLOR_CHOOSER + Delegate:CncColorPickerLogic + Background:panel-black + Width:315 + Height:130 + Children: + Button@SAVE_BUTTON: + Id:SAVE_BUTTON + X:210 + Y:90 + Width:90 + Height:25 + Text:Save + Button@RANDOM_BUTTON: + Id:RANDOM_BUTTON + X:15 + Y:90 + Width:90 + Height:25 + Text:Random + ShpImage@FACT: + Id:FACT + X:220 + Y:15 + Image:fact + Palette:colorpicker + Label@HUE_LABEL: + X:5 + Y:5 + Width:40 + Height:20 + Align:Right + Text:Hue: + Font:Bold + Slider@HUE: + Id:HUE_SLIDER + X:43 + Y:10 + Width:160 + Height:20 + Ticks:5 + Label@SAT_LABEL: + X:5 + Y:30 + Width:40 + Height:20 + Align:Right + Text:Sat: + Font:Bold + Slider@SAT: + Id:SAT_SLIDER + X:43 + Y:35 + Width:160 + Height:20 + Ticks:5 + Label@LUM_LABEL: + X:5 + Y:55 + Width:40 + Height:20 + Align:Right + Text:Lum: + Font:Bold + Slider@LUM: + Id:LUM_SLIDER + X:43 + Y:60 + Width:160 + Height:20 + Ticks:5 + Range:0.2,1 + +ScrollPanel@LABEL_DROPDOWN_TEMPLATE: + Id:LABEL_DROPDOWN_TEMPLATE + Width:100 + Children: + ScrollItem@TEMPLATE: + Id:TEMPLATE + Width:PARENT_RIGHT-27 + Height:25 + X:2 + Y:0 + Visible:false + Children: + Label@LABEL: + X:10 + Id:LABEL + Width:PARENT_RIGHT-20 + Height:25 \ No newline at end of file diff --git a/mods/cnc/chrome/lobby.yaml b/mods/cnc/chrome/lobby.yaml index 0324f3da8b..f437d09a13 100644 --- a/mods/cnc/chrome/lobby.yaml +++ b/mods/cnc/chrome/lobby.yaml @@ -380,77 +380,4 @@ Container@SERVER_LOBBY: Y:499 Width:140 Height:35 - Text:Start Game -Background@COLOR_CHOOSER: - Id:COLOR_CHOOSER - Delegate:CncColorPickerLogic - Background:panel-black - Width:315 - Height:130 - Children: - Button@SAVE_BUTTON: - Id:SAVE_BUTTON - X:210 - Y:90 - Width:90 - Height:25 - Text:Save - Button@RANDOM_BUTTON: - Id:RANDOM_BUTTON - X:15 - Y:90 - Width:90 - Height:25 - Text:Random - ShpImage@FACT: - Id:FACT - X:220 - Y:15 - Image:fact - Palette:colorpicker - Label@HUE_LABEL: - X:5 - Y:5 - Width:40 - Height:20 - Align:Right - Text:Hue: - Font:Bold - Slider@HUE: - Id:HUE_SLIDER - X:43 - Y:10 - Width:160 - Height:20 - Ticks:5 - Label@SAT_LABEL: - X:5 - Y:30 - Width:40 - Height:20 - Align:Right - Text:Sat: - Font:Bold - Slider@SAT: - Id:SAT_SLIDER - X:43 - Y:35 - Width:160 - Height:20 - Ticks:5 - Label@LUM_LABEL: - X:5 - Y:55 - Width:40 - Height:20 - Align:Right - Text:Lum: - Font:Bold - Slider@LUM: - Id:LUM_SLIDER - X:43 - Y:60 - Width:160 - Height:20 - Ticks:5 - Range:0.2,1 \ No newline at end of file + Text:Start Game \ No newline at end of file diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index b55a4a1e47..3b883331db 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -78,6 +78,7 @@ ChromeLayout: mods/cnc/chrome/modchooser.yaml mods/cnc/chrome/preferences.yaml mods/cnc/chrome/cheats.yaml + mods/cnc/chrome/dropdowns.yaml Weapons: mods/cnc/weapons.yaml