From 2452ce710864ac74145bcad2ece671a531339fcd Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Thu, 31 Jul 2014 20:47:57 +0000 Subject: [PATCH] Added: FS#11 - Multiselect for Add map dialog Added: double-clicking on a map adds it to the list --- source/view/Forms.Main.pas | 29 +++++++++++++++++-------- source/view/Forms.Map.dfm | 3 ++- source/view/Forms.Map.pas | 44 +++++++++++++++++++++++++++----------- 3 files changed, 54 insertions(+), 22 deletions(-) diff --git a/source/view/Forms.Main.pas b/source/view/Forms.Main.pas index 6077b62..3b5ee4c 100644 --- a/source/view/Forms.Main.pas +++ b/source/view/Forms.Main.pas @@ -949,6 +949,7 @@ end; procedure TMainForm.actMapAddExecute(Sender: TObject); var gameMapList: IGameMapList; + maps: TList; map: TGameMap; node: PVirtualNode; @@ -956,18 +957,28 @@ begin if not Supports(ActiveGame, IGameMapList, gameMapList) then exit; - if TMapForm.Insert(Self, gameMapList, map) then - begin - gameMapList.AddMap(map); - UpdateMapList; - - node := FindMapNode(map); - if Assigned(node) then + maps := TList.Create; + try + if TMapForm.Insert(Self, gameMapList, maps) then begin + for map in maps do + gameMapList.AddMap(map); + + UpdateMapList; vstMapList.ClearSelection; - vstMapList.FocusedNode := node; - vstMapList.Selected[node] := True; + + for map in maps do + begin + node := FindMapNode(map); + if Assigned(node) then + begin + vstMapList.FocusedNode := node; + vstMapList.Selected[node] := True; + end; + end; end; + finally + FreeAndNil(maps); end; end; diff --git a/source/view/Forms.Map.dfm b/source/view/Forms.Map.dfm index 184a92d..900a845 100644 --- a/source/view/Forms.Map.dfm +++ b/source/view/Forms.Map.dfm @@ -80,13 +80,14 @@ object MapForm: TMapForm Header.MainColumn = -1 TabOrder = 1 TreeOptions.PaintOptions = [toHideFocusRect, toShowDropmark, toShowTreeLines, toThemeAware, toUseBlendedImages] - TreeOptions.SelectionOptions = [toFullRowSelect] + TreeOptions.SelectionOptions = [toFullRowSelect, toMultiSelect] OnCollapsing = vstMapCollapsing OnCompareNodes = vstMapCompareNodes OnFocusChanged = vstMapFocusChanged OnFocusChanging = vstMapFocusChanging OnGetText = vstMapGetText OnPaintText = vstMapPaintText + OnNodeDblClick = vstMapNodeDblClick Columns = <> end object pnlMapName: TPanel diff --git a/source/view/Forms.Map.pas b/source/view/Forms.Map.pas index da1a45d..cde7420 100644 --- a/source/view/Forms.Map.pas +++ b/source/view/Forms.Map.pas @@ -3,6 +3,7 @@ unit Forms.Map; interface uses System.Classes, + System.Generics.Collections, Vcl.Controls, Vcl.ExtCtrls, Vcl.Forms, @@ -33,6 +34,7 @@ type procedure btnOKClick(Sender: TObject); procedure FormCreate(Sender: TObject); + procedure vstMapNodeDblClick(Sender: TBaseVirtualTree; const HitInfo: THitInfo); procedure vstMapGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: string); procedure vstMapPaintText(Sender: TBaseVirtualTree; const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType); procedure vstMapFocusChanging(Sender: TBaseVirtualTree; OldNode, NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex; var Allowed: Boolean); @@ -48,19 +50,18 @@ type procedure SetMapName(const Value: string); protected procedure LoadPredefinedMapList(AGame: IGameMapList); - function CreateMap: TGameMap; + procedure CreateMaps(AMaps: TList); function FindMapNode(const AMapName: string): PVirtualNode; property MapName: string read GetMapName write SetMapName; public - class function Insert(AOwner: TComponent; AGame: IGameMapList; out AMap: TGameMap): Boolean; + class function Insert(AOwner: TComponent; AGame: IGameMapList; AMaps: TList): Boolean; end; implementation uses - System.Generics.Collections, System.StrUtils, System.SysUtils, Winapi.Windows; @@ -78,7 +79,7 @@ const { TMapForm } -class function TMapForm.Insert(AOwner: TComponent; AGame: IGameMapList; out AMap: TGameMap): Boolean; +class function TMapForm.Insert(AOwner: TComponent; AGame: IGameMapList; AMaps: TList): Boolean; begin with Self.Create(AOwner) do try @@ -86,7 +87,7 @@ begin Result := (ShowModal = mrOk); if Result then - AMap := CreateMap; + CreateMaps(AMaps); finally Free; end; @@ -142,19 +143,32 @@ begin end; -function TMapForm.CreateMap: TGameMap; +procedure TMapForm.CreateMaps(AMaps: TList); var node: PVirtualNode; nodeData: PGameMap; begin - node := FindMapNode(MapName); - if Assigned(node) then + if vstMap.SelectedCount > 1 then begin - nodeData := vstMap.GetNodeData(node); - Result := TGameMap.Create(nodeData^); + for node in vstMap.SelectedNodes do + begin + if vstMap.GetNodeLevel(node) = 1 then + begin + nodeData := vstMap.GetNodeData(node); + AMaps.Add(TGameMap.Create(nodeData^)); + end; + end; end else - Result := TGameMap.Create(MapName, '', ''); + begin + node := FindMapNode(MapName); + if Assigned(node) then + begin + nodeData := vstMap.GetNodeData(node); + AMaps.Add(TGameMap.Create(nodeData^)); + end else + AMaps.Add(TGameMap.Create(MapName, '', '')); + end; end; @@ -187,7 +201,7 @@ end; procedure TMapForm.btnOKClick(Sender: TObject); begin - if Length(MapName) = 0 then + if (vstMap.SelectedCount <= 1) and (Length(MapName) = 0) then begin MessageBox(Self.Handle, 'Please enter a map name', 'Error', MB_OK or MB_ICONERROR); ActiveControl := edtMapName; @@ -198,6 +212,12 @@ begin end; +procedure TMapForm.vstMapNodeDblClick(Sender: TBaseVirtualTree; const HitInfo: THitInfo); +begin + btnOK.Click; +end; + + procedure TMapForm.vstMapGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: string); var nodeData: PGameMap;