| 1 |
{%MainUnit castlepropedits.pas} |
| 2 |
{ |
| 3 |
Copyright 2010-2024 Michalis Kamburelis. |
| 4 |
|
| 5 |
This file is part of "Castle Game Engine". |
| 6 |
|
| 7 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 8 |
included in this distribution, for details about the copyright. |
| 9 |
|
| 10 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 |
|
| 14 |
---------------------------------------------------------------------------- |
| 15 |
} |
| 16 |
|
| 17 |
{ URL editors. } |
| 18 |
|
| 19 |
{$ifdef read_interface} |
| 20 |
|
| 21 |
type |
| 22 |
{ Property editor for URL that refers to something that can be loaded by |
| 23 |
@link(LoadNode) or @link(TCastleSceneCore.Load). |
| 24 |
Show an TCastleOpenSceneDialog on Edit. } |
| 25 |
TSceneURLPropertyEditor = class(TStringPropertyEditor) |
| 26 |
public |
| 27 |
function GetAttributes: TPropertyAttributes; override; |
| 28 |
procedure Edit; override; |
| 29 |
end; |
| 30 |
|
| 31 |
{ Property editor for URL that refers to an image readable by Castle Game Engine. |
| 32 |
Show an TCastleOpenImageDialog on Edit. } |
| 33 |
TImageURLPropertyEditor = class(TStringPropertyEditor) |
| 34 |
public |
| 35 |
function GetAttributes: TPropertyAttributes; override; |
| 36 |
procedure Edit; override; |
| 37 |
end; |
| 38 |
|
| 39 |
{ Property editor for URL that refers to a file readable by UserInterfaceLoad. } |
| 40 |
TDesignURLPropertyEditor = class(TStringPropertyEditor) |
| 41 |
public |
| 42 |
function GetAttributes: TPropertyAttributes; override; |
| 43 |
procedure Edit; override; |
| 44 |
end; |
| 45 |
|
| 46 |
{ Property editor for URL that refers to a file readable by TransformLoad. } |
| 47 |
TTransformDesignURLPropertyEditor = class(TStringPropertyEditor) |
| 48 |
public |
| 49 |
function GetAttributes: TPropertyAttributes; override; |
| 50 |
procedure Edit; override; |
| 51 |
end; |
| 52 |
|
| 53 |
{ Property editor for URL that refers to a Tiled Map file. } |
| 54 |
TTiledMapURLPropertyEditor = class(TStringPropertyEditor) |
| 55 |
public |
| 56 |
function GetAttributes: TPropertyAttributes; override; |
| 57 |
procedure Edit; override; |
| 58 |
end; |
| 59 |
|
| 60 |
{ Property editor for URL that refers to a sound file. } |
| 61 |
TSoundURLPropertyEditor = class(TStringPropertyEditor) |
| 62 |
public |
| 63 |
function GetAttributes: TPropertyAttributes; override; |
| 64 |
procedure Edit; override; |
| 65 |
end; |
| 66 |
|
| 67 |
{ Property editor for URL that refers to a font file. } |
| 68 |
TFontURLPropertyEditor = class(TStringPropertyEditor) |
| 69 |
public |
| 70 |
function GetAttributes: TPropertyAttributes; override; |
| 71 |
procedure Edit; override; |
| 72 |
end; |
| 73 |
|
| 74 |
{$endif read_interface} |
| 75 |
|
| 76 |
{$ifdef read_implementation} |
| 77 |
|
| 78 |
{ Useful by many dialogs here ------------------------------------------------ } |
| 79 |
|
| 80 |
function PropertyEditorsAdviceDataDirectory: Boolean; |
| 81 |
begin |
| 82 |
{ There's no reason to leave it false, in practice. } |
| 83 |
Result := true; |
| 84 |
|
| 85 |
if Result then |
| 86 |
{ By the way, do FixApplicationDataInIDE to have good ApplicationDataOverride. } |
| 87 |
FixApplicationDataInIDE; |
| 88 |
end; |
| 89 |
|
| 90 |
{ TSceneURLPropertyEditor ---------------------------------------------------- } |
| 91 |
|
| 92 |
function TSceneURLPropertyEditor.GetAttributes: TPropertyAttributes; |
| 93 |
begin |
| 94 |
Result := [paDialog, paRevertable, paMultiSelect]; |
| 95 |
end; |
| 96 |
|
| 97 |
procedure TSceneURLPropertyEditor.Edit; |
| 98 |
var |
| 99 |
Dialog: TCastleOpenSceneDialog; |
| 100 |
begin |
| 101 |
Dialog := TCastleOpenSceneDialog.Create(nil); |
| 102 |
try |
| 103 |
Dialog.AdviceDataDirectory := PropertyEditorsAdviceDataDirectory; |
| 104 |
if (GetStrValue = '') and PropertyEditorsAdviceDataDirectory then |
| 105 |
Dialog.URL := 'castle-data:/' // make it easier to open files within data folder |
| 106 |
else |
| 107 |
Dialog.URL := GetStrValue; |
| 108 |
if Dialog.Execute then |
| 109 |
SetStrValue(Dialog.URL); |
| 110 |
finally FreeAndNil(Dialog) end; |
| 111 |
end; |
| 112 |
|
| 113 |
{ TImageURLPropertyEditor ---------------------------------------------------- } |
| 114 |
|
| 115 |
function TImageURLPropertyEditor.GetAttributes: TPropertyAttributes; |
| 116 |
begin |
| 117 |
Result := [paDialog, paRevertable, paMultiSelect]; |
| 118 |
end; |
| 119 |
|
| 120 |
procedure TImageURLPropertyEditor.Edit; |
| 121 |
var |
| 122 |
Dialog: TCastleOpenImageDialog; |
| 123 |
begin |
| 124 |
Dialog := TCastleOpenImageDialog.Create(nil); |
| 125 |
try |
| 126 |
Dialog.AdviceDataDirectory := PropertyEditorsAdviceDataDirectory; |
| 127 |
if (GetStrValue = '') and PropertyEditorsAdviceDataDirectory then |
| 128 |
Dialog.URL := 'castle-data:/' // make it easier to open files within data folder |
| 129 |
else |
| 130 |
Dialog.URL := GetStrValue; |
| 131 |
if Dialog.Execute then |
| 132 |
SetStrValue(Dialog.URL); |
| 133 |
finally FreeAndNil(Dialog) end; |
| 134 |
end; |
| 135 |
|
| 136 |
{ TDesignURLPropertyEditor ---------------------------------------------------- } |
| 137 |
|
| 138 |
function TDesignURLPropertyEditor.GetAttributes: TPropertyAttributes; |
| 139 |
begin |
| 140 |
Result := [paDialog, paRevertable, paMultiSelect]; |
| 141 |
end; |
| 142 |
|
| 143 |
procedure TDesignURLPropertyEditor.Edit; |
| 144 |
var |
| 145 |
Dialog: TCastleOpenDialog; |
| 146 |
begin |
| 147 |
Dialog := TCastleOpenDialog.Create(nil); |
| 148 |
try |
| 149 |
Dialog.Filter := 'CGE User Interace Design (*.castle-user-interface)|*.castle-user-interface|All Files|*'; |
| 150 |
Dialog.AdviceDataDirectory := PropertyEditorsAdviceDataDirectory; |
| 151 |
if (GetStrValue = '') and PropertyEditorsAdviceDataDirectory then |
| 152 |
Dialog.URL := 'castle-data:/' // make it easier to open files within data folder |
| 153 |
else |
| 154 |
Dialog.URL := GetStrValue; |
| 155 |
if Dialog.Execute then |
| 156 |
SetStrValue(Dialog.URL); |
| 157 |
finally FreeAndNil(Dialog) end; |
| 158 |
end; |
| 159 |
|
| 160 |
{ TTransformDesignURLPropertyEditor ---------------------------------------------------- } |
| 161 |
|
| 162 |
function TTransformDesignURLPropertyEditor.GetAttributes: TPropertyAttributes; |
| 163 |
begin |
| 164 |
Result := [paDialog, paRevertable, paMultiSelect]; |
| 165 |
end; |
| 166 |
|
| 167 |
procedure TTransformDesignURLPropertyEditor.Edit; |
| 168 |
var |
| 169 |
Dialog: TCastleOpenDialog; |
| 170 |
begin |
| 171 |
Dialog := TCastleOpenDialog.Create(nil); |
| 172 |
try |
| 173 |
Dialog.Filter := 'CGE Transform Design (*.castle-transform)|*.castle-transform|All Files|*'; |
| 174 |
Dialog.AdviceDataDirectory := PropertyEditorsAdviceDataDirectory; |
| 175 |
if (GetStrValue = '') and PropertyEditorsAdviceDataDirectory then |
| 176 |
Dialog.URL := 'castle-data:/' // make it easier to open files within data folder |
| 177 |
else |
| 178 |
Dialog.URL := GetStrValue; |
| 179 |
if Dialog.Execute then |
| 180 |
SetStrValue(Dialog.URL); |
| 181 |
finally FreeAndNil(Dialog) end; |
| 182 |
end; |
| 183 |
|
| 184 |
{ TTiledMapURLPropertyEditor ---------------------------------------------------- } |
| 185 |
|
| 186 |
function TTiledMapURLPropertyEditor.GetAttributes: TPropertyAttributes; |
| 187 |
begin |
| 188 |
Result := [paDialog, paRevertable, paMultiSelect]; |
| 189 |
end; |
| 190 |
|
| 191 |
procedure TTiledMapURLPropertyEditor.Edit; |
| 192 |
var |
| 193 |
Dialog: TCastleOpenDialog; |
| 194 |
begin |
| 195 |
Dialog := TCastleOpenDialog.Create(nil); |
| 196 |
try |
| 197 |
Dialog.Filter := LoadTiledMap_FileFilters; |
| 198 |
Dialog.AdviceDataDirectory := PropertyEditorsAdviceDataDirectory; |
| 199 |
if (GetStrValue = '') and PropertyEditorsAdviceDataDirectory then |
| 200 |
Dialog.URL := 'castle-data:/' // make it easier to open files within data folder |
| 201 |
else |
| 202 |
Dialog.URL := GetStrValue; |
| 203 |
if Dialog.Execute then |
| 204 |
SetStrValue(Dialog.URL); |
| 205 |
finally FreeAndNil(Dialog) end; |
| 206 |
end; |
| 207 |
|
| 208 |
{ TSoundURLPropertyEditor ---------------------------------------------------- } |
| 209 |
|
| 210 |
function TSoundURLPropertyEditor.GetAttributes: TPropertyAttributes; |
| 211 |
begin |
| 212 |
Result := [paDialog, paRevertable, paMultiSelect]; |
| 213 |
end; |
| 214 |
|
| 215 |
procedure TSoundURLPropertyEditor.Edit; |
| 216 |
var |
| 217 |
Dialog: TCastleOpenDialog; |
| 218 |
begin |
| 219 |
Dialog := TCastleOpenDialog.Create(nil); |
| 220 |
try |
| 221 |
FileFiltersToDialog(LoadSound_FileFilters, Dialog); |
| 222 |
Dialog.AdviceDataDirectory := PropertyEditorsAdviceDataDirectory; |
| 223 |
if (GetStrValue = '') and PropertyEditorsAdviceDataDirectory then |
| 224 |
Dialog.URL := 'castle-data:/' // make it easier to open files within data folder |
| 225 |
else |
| 226 |
Dialog.URL := GetStrValue; |
| 227 |
if Dialog.Execute then |
| 228 |
SetStrValue(Dialog.URL); |
| 229 |
finally FreeAndNil(Dialog) end; |
| 230 |
end; |
| 231 |
|
| 232 |
{ TFontURLPropertyEditor ---------------------------------------------------- } |
| 233 |
|
| 234 |
function TFontURLPropertyEditor.GetAttributes: TPropertyAttributes; |
| 235 |
begin |
| 236 |
Result := [paDialog, paRevertable, paMultiSelect]; |
| 237 |
end; |
| 238 |
|
| 239 |
procedure TFontURLPropertyEditor.Edit; |
| 240 |
var |
| 241 |
Dialog: TCastleOpenDialog; |
| 242 |
begin |
| 243 |
Dialog := TCastleOpenDialog.Create(nil); |
| 244 |
try |
| 245 |
FileFiltersToDialog(LoadFont_FileFilters, Dialog); |
| 246 |
Dialog.AdviceDataDirectory := PropertyEditorsAdviceDataDirectory; |
| 247 |
if (GetStrValue = '') and PropertyEditorsAdviceDataDirectory then |
| 248 |
Dialog.URL := 'castle-data:/' // make it easier to open files within data folder |
| 249 |
else |
| 250 |
Dialog.URL := GetStrValue; |
| 251 |
if Dialog.Execute then |
| 252 |
SetStrValue(Dialog.URL); |
| 253 |
finally FreeAndNil(Dialog) end; |
| 254 |
end; |
| 255 |
|
| 256 |
{$endif read_implementation} |