-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGameTextScreen.pas
256 lines (212 loc) · 5.87 KB
/
GameTextScreen.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
{$include lem_directives.inc}
unit GameTextScreen;
interface
uses
Types,
Dialogs,
LemmixHotkeys,
Windows, Classes, SysUtils, Controls, StrUtils,
UMisc,
Gr32, Gr32_Layers, GR32_Image,
LemTypes, LemStrings, LemGame,
GameControl, GameBaseScreenCommon, GameBaseMenuScreen,
SharedGlobals;
{-------------------------------------------------------------------------------
The dos postview screen, which shows you how you've done it.
-------------------------------------------------------------------------------}
type
TGameTextScreen = class(TGameBaseMenuScreen)
private
function GetScreenText: string;
procedure ToNextScreen;
procedure ExitToMenu;
procedure TryLoadReplay;
protected
procedure BuildScreen; override;
function GetWallpaperSuffix: String; override;
procedure OnMouseClick(aPoint: TPoint; aButton: TMouseButton); override;
public
constructor Create(aOwner: TComponent); override;
end;
implementation
uses Forms;
{ TDosGamePreview }
procedure TGameTextScreen.BuildScreen;
var
NewOption: TClickableRegion;
begin
ScreenImg.BeginUpdate;
try
CurrentScreen := gstText;
MenuFont.DrawTextCentered(ScreenImg.Bitmap, GetScreenText, 16);
NewOption := MakeClickableText(Point(FOOTER_ONE_OPTION_X, FOOTER_OPTIONS_ONE_ROW_Y), SOptionContinue, ToNextScreen);
NewOption.ShortcutKeys.Add(VK_RETURN);
NewOption.ShortcutKeys.Add(VK_SPACE);
if GameParams.PlaybackModeActive then
MakeHiddenOption(lka_CancelPlayback, CancelPlaybackMode)
else begin
if GameParams.IsPreTextScreen then
MakeHiddenOption(lka_LoadReplay, TryLoadReplay);
end;
MakeHiddenOption(lka_SaveReplay, SaveReplay);
MakeHiddenOption(VK_ESCAPE, ExitToMenu);
DrawAllClickables;
if GameParams.IsPreTextScreen then
GameParams.ShownText := True;
finally
ScreenImg.EndUpdate;
end;
end;
function TGameTextScreen.GetWallpaperSuffix: String;
begin
if GameParams.IsPreTextScreen then
Result := 'pretext'
else
Result := 'posttext';
end;
function TGameTextScreen.GetScreenText: string;
var
i: Integer;
lfc: Integer;
SL: TStringList;
procedure HandleSubstitutions(var S: String);
var
KeyNames: TKeyNameArray;
function MakeHotkeyText(const S: String): String;
var
Key: TLemmixHotkeyAction;
Modifier: Integer;
CheckMod: Boolean;
ThisKey: TLemmixHotkey;
n: Integer;
begin
Result := '';
if Pos(':', S) = 0 then
begin
if Uppercase(S) = 'SKIP+' then
begin
Key := lka_Skip;
Modifier := 1;
CheckMod := False;
end else if Uppercase(S) = 'SKIP-' then
begin
Key := lka_Skip;
Modifier := -1;
CheckMod := False;
end else begin
Key := TLemmixHotkeyManager.InterpretMain(S);
Modifier := 0;
CheckMod := False;
end;
end else begin
Key := TLemmixHotkeyManager.InterpretMain(LeftStr(S, Pos(':', S) - 1));
Modifier := TLemmixHotkeyManager.InterpretSecondary(RightStr(S, Length(S) - Pos(':', S)));
CheckMod := True;
end;
if Key = lka_Null then
begin
Result := '## INVALID KEY ##';
Exit;
end;
for n := 0 to MAX_KEY do
begin
ThisKey := GameParams.Hotkeys.CheckKeyEffect(n);
if ThisKey.Action <> Key then Continue;
if CheckMod and (ThisKey.Modifier <> Modifier) then Continue;
if (not CheckMod) and (Key = lka_Skip) and (Modifier <> 0) then
if (Modifier < 0) <> (ThisKey.Modifier < 0) then
Continue;
Result := Result + '{' + Keynames[n] + '} ';
end;
if Length(Result) = 0 then
Result := '{None}'
else
Result := LeftStr(Result, Length(Result) - 2); // Remove the double-space at the end
end;
var
FoundStartPos, FoundEndPos: Integer;
SubSrcText: String;
procedure Replace(const newText: String);
begin
S := LeftStr(S, FoundStartPos - 1) +
newText +
RightStr(S, Length(S) - FoundEndPos);
end;
begin
KeyNames := TLemmixHotkeyManager.GetKeyNames(True);
while Pos('[', S) <> 0 do
begin
FoundStartPos := Pos('[', S);
FoundEndPos := Pos(']', S, FoundStartPos);
SubSrcText := Uppercase(MidStr(S, FoundStartPos + 1, FoundEndPos - FoundStartPos - 1));
if LeftStr(SubSrcText, 7) = 'HOTKEY:' then
Replace(MakeHotkeyText(RightStr(SubSrcText, Length(SubSrcText) - 7)))
else
Break;
end;
end;
procedure Add(S: string);
begin
HandleSubstitutions(S);
Result := Result + S + #13;
Inc(lfc);
end;
procedure LF(aCount: Integer);
begin
Result := Result + StringOfChar(#13, aCount);
Inc(lfc, aCount);
end;
procedure PreLF(aCount: Integer);
begin
Result := StringOfChar(#13, aCount) + Result;
Inc(lfc, aCount);
end;
begin
Result := '';
lfc := 0;
if GameParams.IsPreTextScreen then
SL := GameParams.Level.PreText
else
SL := GameParams.Level.PostText;
for i := 0 to SL.Count-1 do
if i > 20 then
Break
else
Add(SL[i]);
while lfc < 22 do
if lfc mod 2 = 1 then
PreLF(1)
else
LF(1);
end;
procedure TGameTextScreen.OnMouseClick(aPoint: TPoint; aButton: TMouseButton);
begin
inherited;
ToNextScreen;
end;
constructor TGameTextScreen.Create(aOwner: TComponent);
begin
inherited Create(aOwner);
end;
procedure TGameTextScreen.ExitToMenu;
begin
if GameParams.TestModeLevel <> nil then
CloseScreen(gstExit)
else
CloseScreen(gstMenu);
end;
procedure TGameTextScreen.ToNextScreen;
begin
if GameParams.IsPreTextScreen then
begin
GameParams.IsPreTextScreen := False;
CloseScreen(gstPlay);
end else
CloseScreen(gstPostview);
end;
procedure TGameTextScreen.TryLoadReplay;
begin
// See comment on TGamePreviewScreen.TryLoadReplay.
LoadReplay;
end;
end.