| 1 |
{ |
| 2 |
Copyright 2018 Benedikt Magnus. |
| 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 |
|
| 16 |
{ Game initialisation and logic. } |
| 17 |
unit GameInitialize; |
| 18 |
|
| 19 |
interface |
| 20 |
|
| 21 |
uses |
| 22 |
Classes, SysUtils, |
| 23 |
CastleWindow, CastleApplicationProperties, |
| 24 |
CastleControls, CastleUIControls, |
| 25 |
CastleFilesUtils, CastleLocalization; |
| 26 |
|
| 27 |
type |
| 28 |
TLanguageButton = class (TCastleButtonLocalizable) |
| 29 |
protected |
| 30 |
FLanguageFile: String; |
| 31 |
procedure SetLanguage(Sender: TObject); |
| 32 |
public |
| 33 |
constructor Create(AOwner: TComponent); override; |
| 34 |
property LanguageFile: String read FLanguageFile write FLanguageFile; |
| 35 |
end; |
| 36 |
|
| 37 |
TImageLocalized = class (TCastleImageControl) |
| 38 |
protected |
| 39 |
FURLPrefix, FURLPostfix: String; |
| 40 |
public |
| 41 |
procedure LoadImage; |
| 42 |
property URLPrefix: String read FURLPrefix write FURLPrefix; |
| 43 |
property URLPostfix: String read FURLPostfix write FURLPostfix; |
| 44 |
end; |
| 45 |
|
| 46 |
var |
| 47 |
Window: TCastleWindow; |
| 48 |
ImageTop: TImageLocalized; |
| 49 |
|
| 50 |
implementation |
| 51 |
|
| 52 |
{ One-time initialisation. } |
| 53 |
procedure ApplicationInitialize; |
| 54 |
var |
| 55 |
MyLabel: TCastleLabelLocalizable; |
| 56 |
MyButton: TLanguageButton; |
| 57 |
begin |
| 58 |
ImageTop := TImageLocalized.Create(Application); |
| 59 |
ImageTop.Anchor(hpMiddle); |
| 60 |
ImageTop.Anchor(vpTop, -10); |
| 61 |
ImageTop.URLPrefix := 'castle-data:/'; |
| 62 |
ImageTop.URLPostfix := '.png'; |
| 63 |
Localization.OnUpdateLocalization.Add(@ImageTop.LoadImage); |
| 64 |
Window.Controls.InsertFront(ImageTop); |
| 65 |
|
| 66 |
MyLabel := TCastleLabelLocalizable.Create(Application); |
| 67 |
MyLabel.Anchor(hpMiddle); |
| 68 |
MyLabel.Anchor(vpTop, -160); |
| 69 |
Localization.AddOrSet(MyLabel, 'LabelTop'); |
| 70 |
Window.Controls.InsertFront(MyLabel); |
| 71 |
|
| 72 |
MyButton := TLanguageButton.Create(Application); |
| 73 |
MyButton.Anchor(hpMiddle); |
| 74 |
MyButton.Anchor(vpTop, -210); |
| 75 |
MyButton.LanguageFile := 'castle-data:/en.xml'; |
| 76 |
Localization.AddOrSet(MyButton, 'ButtonEnglishXML'); |
| 77 |
Window.Controls.InsertFront(MyButton); |
| 78 |
|
| 79 |
MyButton := TLanguageButton.Create(Application); |
| 80 |
MyButton.Anchor(hpMiddle); |
| 81 |
MyButton.Anchor(vpTop, -260); |
| 82 |
MyButton.LanguageFile := 'castle-data:/en.json'; |
| 83 |
Localization.AddOrSet(MyButton, 'ButtonEnglishJSON'); |
| 84 |
Window.Controls.InsertFront(MyButton); |
| 85 |
|
| 86 |
MyButton := TLanguageButton.Create(Application); |
| 87 |
MyButton.Anchor(hpMiddle); |
| 88 |
MyButton.Anchor(vpTop, -310); |
| 89 |
MyButton.LanguageFile := 'castle-data:/en.jsonobj'; |
| 90 |
Localization.AddOrSet(MyButton, 'ButtonEnglishJSONObj'); |
| 91 |
Window.Controls.InsertFront(MyButton); |
| 92 |
|
| 93 |
MyButton := TLanguageButton.Create(Application); |
| 94 |
MyButton.Anchor(hpMiddle); |
| 95 |
MyButton.Anchor(vpTop, -360); |
| 96 |
MyButton.LanguageFile := 'castle-data:/en.csv'; |
| 97 |
Localization.AddOrSet(MyButton, 'ButtonEnglishCSV'); |
| 98 |
Window.Controls.InsertFront(MyButton); |
| 99 |
|
| 100 |
MyButton := TLanguageButton.Create(Application); |
| 101 |
MyButton.Anchor(hpMiddle); |
| 102 |
MyButton.Anchor(vpTop, -410); |
| 103 |
MyButton.LanguageFile := 'castle-data:/en.mo'; |
| 104 |
Localization.AddOrSet(MyButton, 'ButtonEnglishMO'); |
| 105 |
Window.Controls.InsertFront(MyButton); |
| 106 |
|
| 107 |
MyButton := TLanguageButton.Create(Application); |
| 108 |
MyButton.Anchor(hpMiddle); |
| 109 |
MyButton.Anchor(vpTop, -460); |
| 110 |
MyButton.LanguageFile := 'castle-data:/de.xml'; |
| 111 |
Localization.AddOrSet(MyButton, 'ButtonGermanXML'); |
| 112 |
Window.Controls.InsertFront(MyButton); |
| 113 |
|
| 114 |
Localization.LanguageURL := 'castle-data:/en.xml'; |
| 115 |
end; |
| 116 |
|
| 117 |
constructor TLanguageButton.Create(AOwner: TComponent); |
| 118 |
begin |
| 119 |
inherited; |
| 120 |
|
| 121 |
OnClick := @SetLanguage; |
| 122 |
end; |
| 123 |
|
| 124 |
procedure TLanguageButton.SetLanguage(Sender: TObject); |
| 125 |
begin |
| 126 |
Localization.LanguageURL := FLanguageFile; |
| 127 |
end; |
| 128 |
|
| 129 |
procedure TImageLocalized.LoadImage; |
| 130 |
begin |
| 131 |
URL := URLPrefix + Localization['LangCode'] + URLPostfix; |
| 132 |
end; |
| 133 |
|
| 134 |
initialization |
| 135 |
ApplicationProperties.ApplicationName := 'localization'; |
| 136 |
|
| 137 |
{ initialise Application callbacks } |
| 138 |
Application.OnInitialize := @ApplicationInitialize; |
| 139 |
|
| 140 |
{ create Window and initialise Window callbacks } |
| 141 |
Window := TCastleWindow.Create(Application); |
| 142 |
Application.MainWindow := Window; |
| 143 |
|
| 144 |
end. |