Added: FS#11 - Multiselect for Add map dialog

Added: double-clicking on a map adds it to the list
This commit is contained in:
Mark van Renswoude 2014-07-31 20:47:57 +00:00
parent 6bf321999d
commit 2452ce7108
3 changed files with 54 additions and 22 deletions

View File

@ -949,6 +949,7 @@ end;
procedure TMainForm.actMapAddExecute(Sender: TObject); procedure TMainForm.actMapAddExecute(Sender: TObject);
var var
gameMapList: IGameMapList; gameMapList: IGameMapList;
maps: TList<TGameMap>;
map: TGameMap; map: TGameMap;
node: PVirtualNode; node: PVirtualNode;
@ -956,18 +957,28 @@ begin
if not Supports(ActiveGame, IGameMapList, gameMapList) then if not Supports(ActiveGame, IGameMapList, gameMapList) then
exit; exit;
if TMapForm.Insert(Self, gameMapList, map) then maps := TList<TGameMap>.Create;
begin try
gameMapList.AddMap(map); if TMapForm.Insert(Self, gameMapList, maps) then
UpdateMapList;
node := FindMapNode(map);
if Assigned(node) then
begin begin
for map in maps do
gameMapList.AddMap(map);
UpdateMapList;
vstMapList.ClearSelection; 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; end;
finally
FreeAndNil(maps);
end; end;
end; end;

View File

@ -80,13 +80,14 @@ object MapForm: TMapForm
Header.MainColumn = -1 Header.MainColumn = -1
TabOrder = 1 TabOrder = 1
TreeOptions.PaintOptions = [toHideFocusRect, toShowDropmark, toShowTreeLines, toThemeAware, toUseBlendedImages] TreeOptions.PaintOptions = [toHideFocusRect, toShowDropmark, toShowTreeLines, toThemeAware, toUseBlendedImages]
TreeOptions.SelectionOptions = [toFullRowSelect] TreeOptions.SelectionOptions = [toFullRowSelect, toMultiSelect]
OnCollapsing = vstMapCollapsing OnCollapsing = vstMapCollapsing
OnCompareNodes = vstMapCompareNodes OnCompareNodes = vstMapCompareNodes
OnFocusChanged = vstMapFocusChanged OnFocusChanged = vstMapFocusChanged
OnFocusChanging = vstMapFocusChanging OnFocusChanging = vstMapFocusChanging
OnGetText = vstMapGetText OnGetText = vstMapGetText
OnPaintText = vstMapPaintText OnPaintText = vstMapPaintText
OnNodeDblClick = vstMapNodeDblClick
Columns = <> Columns = <>
end end
object pnlMapName: TPanel object pnlMapName: TPanel

View File

@ -3,6 +3,7 @@ unit Forms.Map;
interface interface
uses uses
System.Classes, System.Classes,
System.Generics.Collections,
Vcl.Controls, Vcl.Controls,
Vcl.ExtCtrls, Vcl.ExtCtrls,
Vcl.Forms, Vcl.Forms,
@ -33,6 +34,7 @@ type
procedure btnOKClick(Sender: TObject); procedure btnOKClick(Sender: TObject);
procedure FormCreate(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 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 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); procedure vstMapFocusChanging(Sender: TBaseVirtualTree; OldNode, NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex; var Allowed: Boolean);
@ -48,19 +50,18 @@ type
procedure SetMapName(const Value: string); procedure SetMapName(const Value: string);
protected protected
procedure LoadPredefinedMapList(AGame: IGameMapList); procedure LoadPredefinedMapList(AGame: IGameMapList);
function CreateMap: TGameMap; procedure CreateMaps(AMaps: TList<TGameMap>);
function FindMapNode(const AMapName: string): PVirtualNode; function FindMapNode(const AMapName: string): PVirtualNode;
property MapName: string read GetMapName write SetMapName; property MapName: string read GetMapName write SetMapName;
public public
class function Insert(AOwner: TComponent; AGame: IGameMapList; out AMap: TGameMap): Boolean; class function Insert(AOwner: TComponent; AGame: IGameMapList; AMaps: TList<TGameMap>): Boolean;
end; end;
implementation implementation
uses uses
System.Generics.Collections,
System.StrUtils, System.StrUtils,
System.SysUtils, System.SysUtils,
Winapi.Windows; Winapi.Windows;
@ -78,7 +79,7 @@ const
{ TMapForm } { TMapForm }
class function TMapForm.Insert(AOwner: TComponent; AGame: IGameMapList; out AMap: TGameMap): Boolean; class function TMapForm.Insert(AOwner: TComponent; AGame: IGameMapList; AMaps: TList<TGameMap>): Boolean;
begin begin
with Self.Create(AOwner) do with Self.Create(AOwner) do
try try
@ -86,7 +87,7 @@ begin
Result := (ShowModal = mrOk); Result := (ShowModal = mrOk);
if Result then if Result then
AMap := CreateMap; CreateMaps(AMaps);
finally finally
Free; Free;
end; end;
@ -142,19 +143,32 @@ begin
end; end;
function TMapForm.CreateMap: TGameMap; procedure TMapForm.CreateMaps(AMaps: TList<TGameMap>);
var var
node: PVirtualNode; node: PVirtualNode;
nodeData: PGameMap; nodeData: PGameMap;
begin begin
node := FindMapNode(MapName); if vstMap.SelectedCount > 1 then
if Assigned(node) then
begin begin
nodeData := vstMap.GetNodeData(node); for node in vstMap.SelectedNodes do
Result := TGameMap.Create(nodeData^); begin
if vstMap.GetNodeLevel(node) = 1 then
begin
nodeData := vstMap.GetNodeData(node);
AMaps.Add(TGameMap.Create(nodeData^));
end;
end;
end else 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; end;
@ -187,7 +201,7 @@ end;
procedure TMapForm.btnOKClick(Sender: TObject); procedure TMapForm.btnOKClick(Sender: TObject);
begin begin
if Length(MapName) = 0 then if (vstMap.SelectedCount <= 1) and (Length(MapName) = 0) then
begin begin
MessageBox(Self.Handle, 'Please enter a map name', 'Error', MB_OK or MB_ICONERROR); MessageBox(Self.Handle, 'Please enter a map name', 'Error', MB_OK or MB_ICONERROR);
ActiveControl := edtMapName; ActiveControl := edtMapName;
@ -198,6 +212,12 @@ begin
end; 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); procedure TMapForm.vstMapGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
var var
nodeData: PGameMap; nodeData: PGameMap;