ChivalryServerLauncher/source/view/Frame.MapPreview.pas
Mark van Renswoude 9c720f5922 Added: Inno Setup script
Changed: MapList now uses JSON format, preview filename parameter added
Changed: cleaned up preview folder, no more duplicates
Changed: version number now uses XE2's auto generated date numbers
2014-08-02 12:15:14 +00:00

97 lines
1.9 KiB
ObjectPascal

unit Frame.MapPreview;
interface
uses
System.Classes,
Vcl.Controls,
Vcl.Dialogs,
Vcl.ExtCtrls,
Vcl.Forms,
Vcl.Imaging.jpeg,
X2CLGraphicList;
type
TMapPreviewFrame = class(TFrame)
shpBorder: TShape;
imgMapPreview: TImage;
gcMapPreview: TX2GraphicContainer;
gcMapPreviewUnknownMap: TX2GraphicContainerItem;
public
constructor Create(AOwner: TComponent); override;
procedure Clear;
procedure Load(const APreviewName: string);
end;
implementation
uses
System.SysUtils,
Vcl.Graphics,
Resources;
{$R *.dfm}
{ TMapPreviewFrame }
constructor TMapPreviewFrame.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
{ Having the components not aligned at design-time makes it easier to drag the frame around }
shpBorder.Align := alClient;
imgMapPreview.Align := alClient;
Clear;
end;
procedure TMapPreviewFrame.Clear;
begin
imgMapPreview.Picture.Assign(gcMapPreviewUnknownMap.Picture);
end;
procedure TMapPreviewFrame.Load(const APreviewName: string);
var
preview: TPicture;
fileName: string;
previewItem: TX2GraphicContainerItem;
begin
preview := nil;
if Length(APreviewName) > 0 then
begin
preview := gcMapPreview.PictureByName(APreviewName);
if not Assigned(preview) then
begin
previewItem := TX2GraphicContainerItem.Create(Self);
previewItem.Container := gcMapPreview;
previewItem.PictureName := APreviewName;
preview := previewItem.Picture;
fileName := GetAssetPath(AssetMapPreviewPath + APreviewName + AssetMapPreviewExtension);
if FileExists(fileName) then
begin
try
preview.LoadFromFile(fileName);
except
preview.Assign(nil);
end;
end;
end;
end;
if Assigned(preview) and Assigned(preview.Graphic) then
imgMapPreview.Picture.Assign(preview)
else
Clear;
end;
end.