| 1 |
{ |
| 2 |
Copyright 2017-2023 Michalis Kamburelis. |
| 3 |
|
| 4 |
This file is part of "Castle Game Engine". |
| 5 |
|
| 6 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 7 |
included in this distribution, for details about the copyright. |
| 8 |
|
| 9 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 |
|
| 13 |
---------------------------------------------------------------------------- |
| 14 |
} |
| 15 |
{ Main view, where most of the application logic takes place. |
| 16 |
|
| 17 |
Note: This file must contain UTF-8 BOM, otherwise Delphi will not interpret |
| 18 |
correctly the chars in "String hardcoded in Pascal sources:" below. } |
| 19 |
unit GameViewMain; |
| 20 |
|
| 21 |
interface |
| 22 |
|
| 23 |
uses Classes, |
| 24 |
CastleVectors, CastleUIControls, CastleControls, CastleKeysMouse, |
| 25 |
CastleScene; |
| 26 |
|
| 27 |
type |
| 28 |
{ Main view, where most of the application logic takes place. } |
| 29 |
TViewMain = class(TCastleView) |
| 30 |
published |
| 31 |
{ Components designed using CGE editor. |
| 32 |
These fields will be automatically initialized at Start. } |
| 33 |
ButtonLoadFromFiles: TCastleButton; |
| 34 |
LabelInternational, LabelChinese: TCastleLabel; |
| 35 |
TextInternational, TextChinese: TCastleText; |
| 36 |
private |
| 37 |
procedure ClickLoadFromFiles(Sender: TObject); |
| 38 |
public |
| 39 |
constructor Create(AOwner: TComponent); override; |
| 40 |
procedure Start; override; |
| 41 |
end; |
| 42 |
|
| 43 |
var |
| 44 |
ViewMain: TViewMain; |
| 45 |
|
| 46 |
implementation |
| 47 |
|
| 48 |
uses DOM, SysUtils, |
| 49 |
CastleUtils, CastleConfig, CastleXmlUtils, CastleDownload; |
| 50 |
|
| 51 |
constructor TViewMain.Create(AOwner: TComponent); |
| 52 |
begin |
| 53 |
inherited; |
| 54 |
DesignUrl := 'castle-data:/gameviewmain.castle-user-interface'; |
| 55 |
end; |
| 56 |
|
| 57 |
procedure TViewMain.Start; |
| 58 |
begin |
| 59 |
inherited; |
| 60 |
ButtonLoadFromFiles.OnClick := {$ifdef FPC}@{$endif} ClickLoadFromFiles; |
| 61 |
end; |
| 62 |
|
| 63 |
procedure TViewMain.ClickLoadFromFiles(Sender: TObject); |
| 64 |
|
| 65 |
function TestText: String; |
| 66 |
var |
| 67 |
Config: TCastleConfig; |
| 68 |
Doc: TXmlDocument; |
| 69 |
TextReader: TTextReader; |
| 70 |
StringList: TStringList; |
| 71 |
begin |
| 72 |
Result := |
| 73 |
'String hardcoded in Pascal sources:' + NL + |
| 74 |
'Chinese: 你好世界' + NL + |
| 75 |
'Greek: Γεια σου κόσμε!' + NL + |
| 76 |
'Russian: Здравствуй, мир!' + NL + |
| 77 |
'Polish: Witaj świecie! Oraz: źrebię ćma koń wężyk dąb!' + NL + |
| 78 |
NL; |
| 79 |
|
| 80 |
Config := TCastleConfig.Create(nil); |
| 81 |
try |
| 82 |
Config.Load('castle-data:/example_config.xml'); |
| 83 |
Result := Result + |
| 84 |
'String from TCastleConfig:' + NL + |
| 85 |
Config.GetStringNonEmpty('value') + NL + |
| 86 |
NL; |
| 87 |
finally FreeAndNil(Config) end; |
| 88 |
|
| 89 |
Doc := URLReadXML('castle-data:/example_strings.xml'); |
| 90 |
try |
| 91 |
Result := Result + |
| 92 |
'Strings from XML:' + NL + |
| 93 |
Doc.DocumentElement.ChildElement('element').TextData + NL + |
| 94 |
Doc.DocumentElement.ChildElement('element_with_multiline_content').TextData + NL + |
| 95 |
Doc.DocumentElement.ChildElement('element_with_attributes').AttributeString('value') + NL + |
| 96 |
Doc.DocumentElement.ChildElement('element_with_attributes').AttributeString('value_with_multiline_content') + NL + |
| 97 |
NL; |
| 98 |
finally FreeAndNil(Doc) end; |
| 99 |
|
| 100 |
TextReader := TTextReader.Create('castle-data:/example_text.txt'); |
| 101 |
try |
| 102 |
Result := Result + |
| 103 |
'Strings from txt (TTextReader):' + NL + |
| 104 |
TextReader.Readln + NL + |
| 105 |
TextReader.Readln + NL + |
| 106 |
TextReader.Readln + NL + |
| 107 |
TextReader.Readln + NL + |
| 108 |
NL; |
| 109 |
finally FreeAndNil(TextReader) end; |
| 110 |
|
| 111 |
StringList := TStringList.Create; |
| 112 |
try |
| 113 |
StringList.LoadFromURL('castle-data:/example_text.txt', TEncoding.UTF8); |
| 114 |
Result := Result + |
| 115 |
'Strings from txt (TStringList):' + NL + |
| 116 |
StringList.Text + NL + |
| 117 |
NL; |
| 118 |
finally FreeAndNil(StringList) end; |
| 119 |
end; |
| 120 |
|
| 121 |
var |
| 122 |
S: String; |
| 123 |
begin |
| 124 |
S := TestText; |
| 125 |
LabelInternational.Caption := S; |
| 126 |
LabelChinese.Caption := S; |
| 127 |
TextInternational.Caption := S; |
| 128 |
TextChinese.Caption := S; |
| 129 |
end; |
| 130 |
|
| 131 |
end. |