From db99b816db1200e6eeb78f5d00c98799681e84e7 Mon Sep 17 00:00:00 2001 From: s1ww Date: Fri, 19 Sep 2014 06:17:30 +0200 Subject: [PATCH] Implementing search feature in map choosers --- AUTHORS | 1 + .../Widgets/Logic/MapChooserLogic.cs | 31 +++++++++++++++++-- mods/cnc/chrome/mapchooser.yaml | 19 ++++++++++-- mods/ra/chrome/map-chooser.yaml | 29 ++++++++++++++--- 4 files changed, 70 insertions(+), 10 deletions(-) diff --git a/AUTHORS b/AUTHORS index 059a455a28..6e58bb0f86 100644 --- a/AUTHORS +++ b/AUTHORS @@ -63,6 +63,7 @@ Also thanks to: * Matthew Uzzell (MUzzell) * Max621 * Max Ugrumov (katzsmile) + * Michael Sztolcman (s1w_) * Mustafa Alperen Seki (MustaphaTR) * Neil Shivkar (havok13888) * Nukem diff --git a/OpenRA.Mods.RA/Widgets/Logic/MapChooserLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/MapChooserLogic.cs index 609fe348f9..a09942c448 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/MapChooserLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/MapChooserLogic.cs @@ -25,6 +25,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic ScrollPanelWidget scrollpanel; ScrollItemWidget itemTemplate; + string mapFilter; string gameMode; [ObjectCreator.UseCtor] @@ -32,8 +33,11 @@ namespace OpenRA.Mods.RA.Widgets.Logic { selectedUid = WidgetUtils.ChooseInitialMap(initialMap); - widget.Get("BUTTON_OK").OnClick = () => { Ui.CloseWindow(); onSelect(selectedUid); }; - widget.Get("BUTTON_CANCEL").OnClick = () => { Ui.CloseWindow(); onExit(); }; + var approving = new Action(() => { Ui.CloseWindow(); onSelect(selectedUid); }); + var canceling = new Action(() => { Ui.CloseWindow(); onExit(); }); + + widget.Get("BUTTON_OK").OnClick = approving; + widget.Get("BUTTON_CANCEL").OnClick = canceling; scrollpanel = widget.Get("MAP_LIST"); scrollpanel.Layout = new GridLayout(scrollpanel); @@ -69,6 +73,26 @@ namespace OpenRA.Mods.RA.Widgets.Logic gameModeDropdown.GetText = () => showItem(gameModes.First(m => m.First == gameMode)); } + var mapfilterInput = widget.GetOrNull("MAPFILTER_INPUT"); + if (mapfilterInput != null) + { + mapfilterInput.TakeKeyboardFocus(); + mapfilterInput.OnEscKey = () => + { + if (mapfilterInput.Text.Length == 0) + canceling(); + else + { + mapFilter = mapfilterInput.Text = null; + EnumerateMaps(onSelect); + } + return true; + }; + mapfilterInput.OnEnterKey = () => { approving(); return true; }; + mapfilterInput.OnTextEdited = () => + { mapFilter = mapfilterInput.Text; EnumerateMaps(onSelect); }; + } + var randomMapButton = widget.GetOrNull("RANDOMMAP_BUTTON"); if (randomMapButton != null) { @@ -88,7 +112,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic { var maps = Game.modData.MapCache .Where(m => m.Status == MapStatus.Available && m.Map.Selectable) - .Where(m => m.Type == gameMode || gameMode == null) + .Where(m => gameMode == null || m.Type == gameMode) + .Where(m => mapFilter == null || m.Title.IndexOf(mapFilter, StringComparison.OrdinalIgnoreCase) >= 0 || m.Author.IndexOf(mapFilter, StringComparison.OrdinalIgnoreCase) >= 0) .OrderBy(m => m.PlayerCount) .ThenBy(m => m.Title); diff --git a/mods/cnc/chrome/mapchooser.yaml b/mods/cnc/chrome/mapchooser.yaml index 5628df0ade..6aae63c738 100644 --- a/mods/cnc/chrome/mapchooser.yaml +++ b/mods/cnc/chrome/mapchooser.yaml @@ -17,14 +17,27 @@ Container@MAPCHOOSER_PANEL: Height: 500 Background: panel-black Children: - Label@GAMEMODE_DESC: - X: PARENT_RIGHT - WIDTH - 220 + Label@FILTER_DESC: + X: PARENT_RIGHT - WIDTH - 401 Y: 10 - Width: 200 + Width: 60 Height: 25 Font: Bold Align: Right Text: Filter: + TextField@MAPFILTER_INPUT: + X: PARENT_RIGHT - WIDTH - 245 + Y: 10 + Width: 150 + Height: 25 + Label@FILTER_DESC_JOINER: + X: PARENT_RIGHT - WIDTH - 215 + Y: 10 + Width: 30 + Height: 25 + Font: Bold + Align: Center + Text: in DropDownButton@GAMEMODE_FILTER: X: PARENT_RIGHT - WIDTH - 15 Y: 10 diff --git a/mods/ra/chrome/map-chooser.yaml b/mods/ra/chrome/map-chooser.yaml index cb095705e0..f1090d71fd 100644 --- a/mods/ra/chrome/map-chooser.yaml +++ b/mods/ra/chrome/map-chooser.yaml @@ -3,11 +3,11 @@ Background@MAPCHOOSER_PANEL: Y: (WINDOW_BOTTOM - HEIGHT)/2 Logic: MapChooserLogic Width: 858 - Height: 600 + Height: 618 Children: Label@MAPCHOOSER_TITLE: X: 0 - Y: 17 + Y: 15 Align: Center Width: 858 Height: 20 @@ -15,7 +15,7 @@ Background@MAPCHOOSER_PANEL: Font: Bold ScrollPanel@MAP_LIST: X: 20 - Y: 47 + Y: 76 Width: PARENT_RIGHT - 40 Height: 474 Children: @@ -56,9 +56,30 @@ Background@MAPCHOOSER_PANEL: Y: PARENT_BOTTOM-10 Align: Center Font: Tiny + Label@FILTER_DESC: + X: PARENT_RIGHT - 467 + Y: 48 + Width: 60 + Height: 24 + Font: Bold + Align: Right + Text: Filter: + TextField@MAPFILTER_INPUT: + X: PARENT_RIGHT - 401 + Y: 48 + Width: 150 + Height: 25 + Label@FILTER_DESC_JOINER: + X: PARENT_RIGHT - 250 + Y: 48 + Width: 30 + Height: 24 + Font: Bold + Align: Center + Text: in DropDownButton@GAMEMODE_FILTER: X: PARENT_RIGHT - 220 - Y: 17 + Y: 48 Width: 200 Height: 25 Button@RANDOMMAP_BUTTON: