1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../shared/a_modes.inc}
21 {$IFDEF USE_MEMPOOL}mempool
,{$ENDIF}
22 g_base
, e_input
, e_log
, g_playermodel
, g_basic
, MAPDEF
, utils
;
25 MAINMENU_HEADER_COLOR
: TRGB
= (R
:255; G
:255; B
:255);
26 MAINMENU_ITEMS_COLOR
: TRGB
= (R
:255; G
:255; B
:255);
27 MAINMENU_UNACTIVEITEMS_COLOR
: TRGB
= (R
:192; G
:192; B
:192);
28 MAINMENU_CLICKSOUND
= 'MENU_SELECT';
29 MAINMENU_CHANGESOUND
= 'MENU_CHANGE';
31 MAINMENU_MARKER1
= 'MAINMENU_MARKER1';
32 MAINMENU_MARKER2
= 'MAINMENU_MARKER2';
33 MAINMENU_MARKERDELAY
= 24;
34 WINDOW_CLOSESOUND
= 'MENU_CLOSE';
35 MENU_HEADERCOLOR
: TRGB
= (R
:255; G
:255; B
:255);
36 MENU_ITEMSTEXT_COLOR
: TRGB
= (R
:255; G
:255; B
:255);
37 MENU_UNACTIVEITEMS_COLOR
: TRGB
= (R
:128; G
:128; B
:128);
38 MENU_ITEMSCTRL_COLOR
: TRGB
= (R
:255; G
:0; B
:0);
41 MENU_CLICKSOUND
= 'MENU_SELECT';
42 MENU_CHANGESOUND
= 'MENU_CHANGE';
43 MENU_MARKERDELAY
= 24;
44 SCROLL_LEFT
= 'SCROLL_LEFT';
45 SCROLL_RIGHT
= 'SCROLL_RIGHT';
46 SCROLL_MIDDLE
= 'SCROLL_MIDDLE';
47 SCROLL_MARKER
= 'SCROLL_MARKER';
48 SCROLL_ADDSOUND
= 'SCROLL_ADD';
49 SCROLL_SUBSOUND
= 'SCROLL_SUB';
50 EDIT_LEFT
= 'EDIT_LEFT';
51 EDIT_RIGHT
= 'EDIT_RIGHT';
52 EDIT_MIDDLE
= 'EDIT_MIDDLE';
53 EDIT_CURSORCOLOR
: TRGB
= (R
:200; G
:0; B
:0);
55 KEYREAD_QUERY
= '<...>';
56 KEYREAD_CLEAR
= '???';
59 MAPPREVIEW_HEIGHT
= 8;
60 BSCROLL_UPA
= 'BSCROLL_UP_A';
61 BSCROLL_UPU
= 'BSCROLL_UP_U';
62 BSCROLL_DOWNA
= 'BSCROLL_DOWN_A';
63 BSCROLL_DOWNU
= 'BSCROLL_DOWN_U';
64 BSCROLL_MIDDLE
= 'BSCROLL_MIDDLE';
69 MESSAGE_DIKEY
= WM_USER
+ 1;
81 TOnKeyDownEvent
= procedure(Key
: Byte);
82 TOnKeyDownEventEx
= procedure(win
: TGUIWindow
; Key
: Byte);
83 TOnCloseEvent
= procedure;
84 TOnShowEvent
= procedure;
85 TOnClickEvent
= procedure;
86 TOnChangeEvent
= procedure(Sender
: TGUIControl
);
87 TOnEnterEvent
= procedure(Sender
: TGUIControl
);
89 TGUIControl
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
96 FRightAlign
: Boolean; //HACK! this works only for "normal" menus, only for menu text labels, and generally sux. sorry.
97 FMaxWidth
: Integer; //HACK! used for right-aligning labels
100 procedure OnMessage(var Msg
: TMessage
); virtual;
101 procedure Update
; virtual;
102 function GetWidth(): Integer; virtual;
103 function GetHeight(): Integer; virtual;
104 function WantActivationKey (key
: LongInt): Boolean; virtual;
105 property X
: Integer read FX write FX
;
106 property Y
: Integer read FY write FY
;
107 property Enabled
: Boolean read FEnabled write FEnabled
;
108 property Name
: string read FName write FName
;
109 property UserData
: Pointer read FUserData write FUserData
;
110 property RightAlign
: Boolean read FRightAlign write FRightAlign
; // for menu
111 property CMaxWidth
: Integer read FMaxWidth
;
113 property Window
: TGUIWindow read FWindow
;
116 TGUIWindow
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
118 FActiveControl
: TGUIControl
;
120 FPrevWindow
: TGUIWindow
;
122 FBackTexture
: string;
123 FMainWindow
: Boolean;
124 FOnKeyDown
: TOnKeyDownEvent
;
125 FOnKeyDownEx
: TOnKeyDownEventEx
;
126 FOnCloseEvent
: TOnCloseEvent
;
127 FOnShowEvent
: TOnShowEvent
;
130 Childs
: array of TGUIControl
;
131 constructor Create(Name
: string);
132 destructor Destroy
; override;
133 function AddChild(Child
: TGUIControl
): TGUIControl
;
134 procedure OnMessage(var Msg
: TMessage
);
136 procedure SetActive(Control
: TGUIControl
);
137 function GetControl(Name
: string): TGUIControl
;
138 property OnKeyDown
: TOnKeyDownEvent read FOnKeyDown write FOnKeyDown
;
139 property OnKeyDownEx
: TOnKeyDownEventEx read FOnKeyDownEx write FOnKeyDownEx
;
140 property OnClose
: TOnCloseEvent read FOnCloseEvent write FOnCloseEvent
;
141 property OnShow
: TOnShowEvent read FOnShowEvent write FOnShowEvent
;
142 property Name
: string read FName
;
143 property DefControl
: string read FDefControl write FDefControl
;
144 property BackTexture
: string read FBackTexture write FBackTexture
;
145 property MainWindow
: Boolean read FMainWindow write FMainWindow
;
146 property UserData
: Pointer read FUserData write FUserData
;
148 property ActiveControl
: TGUIControl read FActiveControl
;
151 TGUITextButton
= class(TGUIControl
)
160 ProcEx
: procedure (sender
: TGUITextButton
);
161 constructor Create(aProc
: Pointer; BigFont
: Boolean; Text: string);
162 destructor Destroy(); override;
163 procedure OnMessage(var Msg
: TMessage
); override;
164 procedure Update(); override;
165 procedure Click(Silent
: Boolean = False);
166 property Caption
: string read FText write FText
;
167 property Color
: TRGB read FColor write FColor
;
168 property BigFont
: Boolean read FBigFont write FBigFont
;
169 property ShowWindow
: string read FShowWindow write FShowWindow
;
172 TGUILabel
= class(TGUIControl
)
178 FOnClickEvent
: TOnClickEvent
;
180 constructor Create(Text: string; BigFont
: Boolean);
181 procedure OnMessage(var Msg
: TMessage
); override;
182 property OnClick
: TOnClickEvent read FOnClickEvent write FOnClickEvent
;
183 property FixedLength
: Word read FFixedLen write FFixedLen
;
184 property Text: string read FText write FText
;
185 property Color
: TRGB read FColor write FColor
;
186 property BigFont
: Boolean read FBigFont write FBigFont
;
189 TGUIScroll
= class(TGUIControl
)
193 FOnChangeEvent
: TOnChangeEvent
;
194 procedure FSetValue(a
: Integer);
196 constructor Create();
197 procedure OnMessage(var Msg
: TMessage
); override;
198 procedure Update
; override;
199 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
200 property Max
: Word read FMax write FMax
;
201 property Value
: Integer read FValue write FSetValue
;
204 TGUIItemsList
= array of string;
206 TGUISwitch
= class(TGUIControl
)
209 FItems
: TGUIItemsList
;
212 FOnChangeEvent
: TOnChangeEvent
;
214 constructor Create(BigFont
: Boolean);
215 procedure OnMessage(var Msg
: TMessage
); override;
216 procedure AddItem(Item
: string);
217 procedure Update
; override;
218 function GetText
: string;
219 property ItemIndex
: Integer read FIndex write FIndex
;
220 property Color
: TRGB read FColor write FColor
;
221 property BigFont
: Boolean read FBigFont write FBigFont
;
222 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
223 property Items
: TGUIItemsList read FItems
;
226 TGUIEdit
= class(TGUIControl
)
234 FOnlyDigits
: Boolean;
235 FOnChangeEvent
: TOnChangeEvent
;
236 FOnEnterEvent
: TOnEnterEvent
;
238 procedure SetText(Text: string);
240 constructor Create(BigFont
: Boolean);
241 procedure OnMessage(var Msg
: TMessage
); override;
242 procedure Update
; override;
243 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
244 property OnEnter
: TOnEnterEvent read FOnEnterEvent write FOnEnterEvent
;
245 property Width
: Word read FWidth write FWidth
;
246 property MaxLength
: Word read FMaxLength write FMaxLength
;
247 property OnlyDigits
: Boolean read FOnlyDigits write FOnlyDigits
;
248 property Text: string read FText write SetText
;
249 property Color
: TRGB read FColor write FColor
;
250 property BigFont
: Boolean read FBigFont write FBigFont
;
251 property Invalid
: Boolean read FInvalid write FInvalid
;
253 property CaretPos
: Integer read FCaretPos
;
256 TGUIKeyRead
= class(TGUIControl
)
263 constructor Create(BigFont
: Boolean);
264 procedure OnMessage(var Msg
: TMessage
); override;
265 function WantActivationKey (key
: LongInt): Boolean; override;
266 property Key
: Word read FKey write FKey
;
267 property Color
: TRGB read FColor write FColor
;
268 property BigFont
: Boolean read FBigFont write FBigFont
;
270 property IsQuery
: Boolean read FIsQuery
;
274 TGUIKeyRead2
= class(TGUIControl
)
278 FKey0
, FKey1
: Word; // this should be an array. sorry.
281 FMaxKeyNameWdt
: Integer;
283 constructor Create(BigFont
: Boolean);
284 procedure OnMessage(var Msg
: TMessage
); override;
285 function WantActivationKey (key
: LongInt): Boolean; override;
286 property Key0
: Word read FKey0 write FKey0
;
287 property Key1
: Word read FKey1 write FKey1
;
288 property Color
: TRGB read FColor write FColor
;
289 property BigFont
: Boolean read FBigFont write FBigFont
;
291 property IsQuery
: Boolean read FIsQuery
;
292 property MaxKeyNameWdt
: Integer read FMaxKeyNameWdt
;
293 property KeyIdx
: Integer read FKeyIdx
;
296 TGUIModelView
= class(TGUIControl
)
298 FModel
: TPlayerModel
;
302 destructor Destroy
; override;
303 procedure OnMessage(var Msg
: TMessage
); override;
304 procedure SetModel(ModelName
: string);
305 procedure SetColor(Red
, Green
, Blue
: Byte);
306 procedure NextAnim();
307 procedure NextWeapon();
308 procedure Update
; override;
309 property Model
: TPlayerModel read FModel
;
312 TPreviewPanel
= record
313 X1
, Y1
, X2
, Y2
: Integer;
317 TPreviewPanelArray
= array of TPreviewPanel
;
319 TGUIMapPreview
= class(TGUIControl
)
321 FMapData
: TPreviewPanelArray
;
325 constructor Create();
326 destructor Destroy(); override;
327 procedure OnMessage(var Msg
: TMessage
); override;
328 procedure SetMap(Res
: string);
329 procedure ClearMap();
330 procedure Update(); override;
331 function GetScaleStr
: String;
333 property MapData
: TPreviewPanelArray read FMapData
;
334 property MapSize
: TDFPoint read FMapSize
;
335 property Scale
: Single read FScale
;
338 TGUIImage
= class(TGUIControl
)
343 constructor Create();
344 destructor Destroy(); override;
345 procedure OnMessage(var Msg
: TMessage
); override;
346 procedure SetImage(Res
: string);
347 procedure ClearImage();
348 procedure Update(); override;
350 property DefaultRes
: string read FDefaultRes write FDefaultRes
;
351 property ImageRes
: string read FImageRes
;
354 TGUIListBox
= class(TGUIControl
)
358 FUnActiveColor
: TRGB
;
366 FDrawScroll
: Boolean;
367 FOnChangeEvent
: TOnChangeEvent
;
369 procedure FSetItems(Items
: SSArray
);
370 procedure FSetIndex(aIndex
: Integer);
373 constructor Create(BigFont
: Boolean; Width
, Height
: Word);
374 procedure OnMessage(var Msg
: TMessage
); override;
375 procedure AddItem(Item
: String);
376 function ItemExists (item
: String): Boolean;
377 procedure SelectItem(Item
: String);
379 function SelectedItem(): String;
381 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
382 property Sort
: Boolean read FSort write FSort
;
383 property ItemIndex
: Integer read FIndex write FSetIndex
;
384 property Items
: SSArray read FItems write FSetItems
;
385 property DrawBack
: Boolean read FDrawBack write FDrawBack
;
386 property DrawScrollBar
: Boolean read FDrawScroll write FDrawScroll
;
387 property ActiveColor
: TRGB read FActiveColor write FActiveColor
;
388 property UnActiveColor
: TRGB read FUnActiveColor write FUnActiveColor
;
389 property BigFont
: Boolean read FBigFont write FBigFont
;
391 property Width
: Word read FWidth
;
392 property Height
: Word read FHeight
;
393 property StartLine
: Integer read FStartLine
;
396 TGUIFileListBox
= class(TGUIListBox
)
401 FBaseList
: SSArray
; // highter index have highter priority
406 procedure OnMessage (var Msg
: TMessage
); override;
407 procedure SetBase (dirs
: SSArray
; path
: String = '');
408 function SelectedItem(): String;
409 procedure UpdateFileList
;
411 property Dirs
: Boolean read FDirs write FDirs
;
412 property FileMask
: String read FFileMask write FFileMask
;
415 TGUIMemo
= class(TGUIControl
)
424 FDrawScroll
: Boolean;
426 constructor Create(BigFont
: Boolean; Width
, Height
: Word);
427 procedure OnMessage(var Msg
: TMessage
); override;
429 procedure SetText(Text: string);
430 property DrawBack
: Boolean read FDrawBack write FDrawBack
;
431 property DrawScrollBar
: Boolean read FDrawScroll write FDrawScroll
;
432 property Color
: TRGB read FColor write FColor
;
433 property BigFont
: Boolean read FBigFont write FBigFont
;
435 property Width
: Word read FWidth
;
436 property Height
: Word read FHeight
;
437 property StartLine
: Integer read FStartLine
;
438 property Lines
: SSArray read FLines
;
441 TGUITextButtonList
= array of TGUITextButton
;
443 TGUIMainMenu
= class(TGUIControl
)
445 FButtons
: TGUITextButtonList
;
449 FCounter
: Byte; // !!! update it within render
451 constructor Create(BigFont
: Boolean; Header
: string);
452 destructor Destroy
; override;
453 procedure OnMessage(var Msg
: TMessage
); override;
454 function AddButton(fProc
: Pointer; Caption
: string; ShowWindow
: string = ''): TGUITextButton
;
455 function GetButton(aName
: string): TGUITextButton
;
456 procedure EnableButton(aName
: string; e
: Boolean);
457 procedure AddSpace();
458 procedure Update
; override;
460 property Header
: TGUILabel read FHeader
;
461 property Buttons
: TGUITextButtonList read FButtons
;
462 property Index
: Integer read FIndex
;
463 property Counter
: Byte read FCounter
;
466 TControlType
= class of TGUIControl
;
468 PMenuItem
= ^TMenuItem
;
471 ControlType
: TControlType
;
472 Control
: TGUIControl
;
474 TMenuItemList
= array of TMenuItem
;
476 TGUIMenu
= class(TGUIControl
)
478 FItems
: TMenuItemList
;
486 function NewItem(): Integer;
488 constructor Create(HeaderBigFont
, ItemsBigFont
: Boolean; Header
: string);
489 destructor Destroy
; override;
490 procedure OnMessage(var Msg
: TMessage
); override;
491 procedure AddSpace();
492 procedure AddLine(fText
: string);
493 procedure AddText(fText
: string; MaxWidth
: Word);
494 function AddLabel(fText
: string): TGUILabel
;
495 function AddButton(Proc
: Pointer; fText
: string; _ShowWindow
: string = ''): TGUITextButton
;
496 function AddScroll(fText
: string): TGUIScroll
;
497 function AddSwitch(fText
: string): TGUISwitch
;
498 function AddEdit(fText
: string): TGUIEdit
;
499 function AddKeyRead(fText
: string): TGUIKeyRead
;
500 function AddKeyRead2(fText
: string): TGUIKeyRead2
;
501 function AddList(fText
: string; Width
, Height
: Word): TGUIListBox
;
502 function AddFileList(fText
: string; Width
, Height
: Word): TGUIFileListBox
;
503 function AddMemo(fText
: string; Width
, Height
: Word): TGUIMemo
;
505 function GetControl(aName
: string): TGUIControl
;
506 function GetControlsText(aName
: string): TGUILabel
;
507 procedure Update
; override;
508 procedure UpdateIndex();
509 property Align
: Boolean read FAlign write FAlign
;
510 property Left
: Integer read FLeft write FLeft
;
511 property YesNo
: Boolean read FYesNo write FYesNo
;
513 property Header
: TGUILabel read FHeader
;
514 property Counter
: Byte read FCounter
;
515 property Index
: Integer read FIndex
;
516 property Items
: TMenuItemList read FItems
;
517 property BigFont
: Boolean read FBigFont
;
521 g_GUIWindows
: array of TGUIWindow
;
522 g_ActiveWindow
: TGUIWindow
= nil;
523 g_GUIGrabInput
: Boolean = False;
525 function g_GUI_AddWindow(Window
: TGUIWindow
): TGUIWindow
;
526 function g_GUI_GetWindow(Name
: string): TGUIWindow
;
527 procedure g_GUI_ShowWindow(Name
: string);
528 procedure g_GUI_HideWindow(PlaySound
: Boolean = True);
529 function g_GUI_Destroy(): Boolean;
530 procedure g_GUI_SaveMenuPos();
531 procedure g_GUI_LoadMenuPos();
537 {$IFDEF ENABLE_TOUCH}
540 {$IFDEF ENABLE_RENDER}
543 g_sound
, SysUtils
, e_res
,
544 g_game
, Math
, StrUtils
, g_player
, g_options
, g_console
,
545 g_map
, g_weapons
, xdynrec
, wadreader
;
549 Saved_Windows
: SSArray
;
551 function GetLines (text: string; BigFont
: Boolean; MaxWidth
: Word): SSArray
;
555 i
, len
, lastsep
: Integer;
557 function PrepareStep (): Boolean; inline;
559 // Skip leading spaces.
560 while PChar(text)[k
-1] = ' ' do k
+= 1;
565 function GetLine (j
: Integer; Strip
: Boolean): String; inline;
567 // Exclude trailing spaces from the line.
569 while text[j
] = ' ' do j
-= 1;
571 Result
:= Copy(text, k
, j
-k
+1);
574 function LineWidth (): Integer; inline;
575 {$IFDEF ENABLE_RENDER}
579 {$IFDEF ENABLE_RENDER}
580 r_GUI_GetStringSize(BigFont
, GetLine(i
, False), w
, h
);
590 //e_LogWritefln('GetLines @%s len=%s [%s]', [MaxWidth, len, text]);
592 while PrepareStep() do
594 // Get longest possible sequence (this is not constant because fonts are not monospaced).
597 if text[i
] in [' ', '.', ',', ':', ';']
600 until (i
> len
) or (LineWidth() > MaxWidth
);
602 // Do not include part of a word if possible.
603 if (lastsep
-k
> 3) and (i
<= len
) and (text[i
] <> ' ')
604 then i
:= lastsep
+ 1;
607 SetLength(Result
, lines
+ 1);
608 Result
[lines
] := GetLine(i
-1, True);
609 //e_LogWritefln(' -> (%s:%s::%s) [%s]', [k, i, LineWidth(), Result[lines]]);
616 procedure Sort(var a
: SSArray
);
621 if a
= nil then Exit
;
623 for i
:= High(a
) downto Low(a
) do
624 for j
:= Low(a
) to High(a
)-1 do
625 if LowerCase(a
[j
]) > LowerCase(a
[j
+1]) then
633 function g_GUI_Destroy(): Boolean;
637 Result
:= (Length(g_GUIWindows
) > 0);
639 for i
:= 0 to High(g_GUIWindows
) do
640 g_GUIWindows
[i
].Free();
643 g_ActiveWindow
:= nil;
646 function g_GUI_AddWindow(Window
: TGUIWindow
): TGUIWindow
;
648 SetLength(g_GUIWindows
, Length(g_GUIWindows
)+1);
649 g_GUIWindows
[High(g_GUIWindows
)] := Window
;
654 function g_GUI_GetWindow(Name
: string): TGUIWindow
;
660 if g_GUIWindows
<> nil then
661 for i
:= 0 to High(g_GUIWindows
) do
662 if g_GUIWindows
[i
].FName
= Name
then
664 Result
:= g_GUIWindows
[i
];
668 Assert(Result
<> nil, 'GUI_Window "'+Name
+'" not found');
671 procedure g_GUI_ShowWindow(Name
: string);
675 if g_GUIWindows
= nil then
678 for i
:= 0 to High(g_GUIWindows
) do
679 if g_GUIWindows
[i
].FName
= Name
then
681 g_GUIWindows
[i
].FPrevWindow
:= g_ActiveWindow
;
682 g_ActiveWindow
:= g_GUIWindows
[i
];
684 if g_ActiveWindow
.MainWindow
then
685 g_ActiveWindow
.FPrevWindow
:= nil;
687 if g_ActiveWindow
.FDefControl
<> '' then
688 g_ActiveWindow
.SetActive(g_ActiveWindow
.GetControl(g_ActiveWindow
.FDefControl
))
690 g_ActiveWindow
.SetActive(nil);
692 if @g_ActiveWindow
.FOnShowEvent
<> nil then
693 g_ActiveWindow
.FOnShowEvent();
699 procedure g_GUI_HideWindow(PlaySound
: Boolean = True);
701 if g_ActiveWindow
<> nil then
703 if @g_ActiveWindow
.OnClose
<> nil then
704 g_ActiveWindow
.OnClose();
705 g_ActiveWindow
:= g_ActiveWindow
.FPrevWindow
;
707 g_Sound_PlayEx(WINDOW_CLOSESOUND
);
711 procedure g_GUI_SaveMenuPos();
716 SetLength(Saved_Windows
, 0);
717 win
:= g_ActiveWindow
;
721 len
:= Length(Saved_Windows
);
722 SetLength(Saved_Windows
, len
+ 1);
724 Saved_Windows
[len
] := win
.Name
;
726 if win
.MainWindow
then
729 win
:= win
.FPrevWindow
;
733 procedure g_GUI_LoadMenuPos();
735 i
, j
, k
, len
: Integer;
738 g_ActiveWindow
:= nil;
739 len
:= Length(Saved_Windows
);
744 // Îêíî ñ ãëàâíûì ìåíþ:
745 g_GUI_ShowWindow(Saved_Windows
[len
-1]);
747 // Íå ïåðåêëþ÷èëîñü (èëè íåêóäà äàëüøå):
748 if (len
= 1) or (g_ActiveWindow
= nil) then
751 // Èùåì êíîïêè â îñòàëüíûõ îêíàõ:
752 for k
:= len
-1 downto 1 do
756 for i
:= 0 to Length(g_ActiveWindow
.Childs
)-1 do
758 if g_ActiveWindow
.Childs
[i
] is TGUIMainMenu
then
759 begin // GUI_MainMenu
760 with TGUIMainMenu(g_ActiveWindow
.Childs
[i
]) do
761 for j
:= 0 to Length(FButtons
)-1 do
762 if FButtons
[j
].ShowWindow
= Saved_Windows
[k
-1] then
764 FButtons
[j
].Click(True);
770 if g_ActiveWindow
.Childs
[i
] is TGUIMenu
then
771 with TGUIMenu(g_ActiveWindow
.Childs
[i
]) do
772 for j
:= 0 to Length(FItems
)-1 do
773 if FItems
[j
].ControlType
= TGUITextButton
then
774 if TGUITextButton(FItems
[j
].Control
).ShowWindow
= Saved_Windows
[k
-1] then
776 TGUITextButton(FItems
[j
].Control
).Click(True);
787 (g_ActiveWindow
.Name
= Saved_Windows
[k
]) then
794 constructor TGUIWindow
.Create(Name
: string);
797 FActiveControl
:= nil;
801 FOnCloseEvent
:= nil;
805 destructor TGUIWindow
.Destroy
;
812 for i
:= 0 to High(Childs
) do
816 function TGUIWindow
.AddChild(Child
: TGUIControl
): TGUIControl
;
818 Child
.FWindow
:= Self
;
820 SetLength(Childs
, Length(Childs
) + 1);
821 Childs
[High(Childs
)] := Child
;
826 procedure TGUIWindow
.Update
;
830 for i
:= 0 to High(Childs
) do
831 if Childs
[i
] <> nil then Childs
[i
].Update
;
834 procedure TGUIWindow
.OnMessage(var Msg
: TMessage
);
836 if FActiveControl
<> nil then FActiveControl
.OnMessage(Msg
);
837 if @FOnKeyDown
<> nil then FOnKeyDown(Msg
.wParam
);
838 if @FOnKeyDownEx
<> nil then FOnKeyDownEx(self
, Msg
.wParam
);
840 if Msg
.Msg
= WM_KEYDOWN
then
852 procedure TGUIWindow
.SetActive(Control
: TGUIControl
);
854 FActiveControl
:= Control
;
857 function TGUIWindow
.GetControl(Name
: String): TGUIControl
;
863 if Childs
<> nil then
864 for i
:= 0 to High(Childs
) do
865 if Childs
[i
] <> nil then
866 if LowerCase(Childs
[i
].FName
) = LowerCase(Name
) then
872 Assert(Result
<> nil, 'Window Control "'+Name
+'" not Found!');
877 constructor TGUIControl
.Create();
883 FRightAlign
:= false;
887 procedure TGUIControl
.OnMessage(var Msg
: TMessage
);
893 procedure TGUIControl
.Update();
897 function TGUIControl
.WantActivationKey (key
: LongInt): Boolean;
902 function TGUIControl
.GetWidth (): Integer;
903 {$IFDEF ENABLE_RENDER}
907 {$IFDEF ENABLE_RENDER}
908 r_GUI_GetSize(Self
, Result
, h
);
914 function TGUIControl
.GetHeight (): Integer;
915 {$IFDEF ENABLE_RENDER}
919 {$IFDEF ENABLE_RENDER}
920 r_GUI_GetSize(Self
, w
, Result
);
928 procedure TGUITextButton
.Click(Silent
: Boolean = False);
930 if (FSound
<> '') and (not Silent
) then g_Sound_PlayEx(FSound
);
932 if @Proc
<> nil then Proc();
933 if @ProcEx
<> nil then ProcEx(self
);
935 if FShowWindow
<> '' then g_GUI_ShowWindow(FShowWindow
);
938 constructor TGUITextButton
.Create(aProc
: Pointer; BigFont
: Boolean; Text: string);
949 destructor TGUITextButton
.Destroy
;
955 procedure TGUITextButton
.OnMessage(var Msg
: TMessage
);
957 if not FEnabled
then Exit
;
964 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
: Click();
969 procedure TGUITextButton
.Update
;
976 function TGUIMainMenu
.AddButton(fProc
: Pointer; Caption
: string; ShowWindow
: string = ''): TGUITextButton
;
978 {$IFDEF ENABLE_RENDER}
987 SetLength(FButtons
, Length(FButtons
)+1);
988 FButtons
[High(FButtons
)] := TGUITextButton
.Create(fProc
, FBigFont
, Caption
);
989 FButtons
[High(FButtons
)].ShowWindow
:= ShowWindow
;
990 with FButtons
[High(FButtons
)] do
992 if (fProc
<> nil) or (ShowWindow
<> '') then FColor
:= MAINMENU_ITEMS_COLOR
993 else FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
994 FSound
:= MAINMENU_CLICKSOUND
;
997 _x
:= gScreenWidth
div 2;
999 for a
:= 0 to High(FButtons
) do
1000 if FButtons
[a
] <> nil then
1001 _x
:= Min(_x
, (gScreenWidth
div 2)-(FButtons
[a
].GetWidth
div 2));
1003 {$IFDEF ENABLE_RENDER}
1004 if FHeader
= nil then
1005 r_GUI_GetLogoSize(lw
, lh
);
1007 hh
:= FButtons
[High(FButtons
)].GetHeight
;
1009 if FHeader
= nil then h
:= lh
+ hh
* (1 + Length(FButtons
)) + MAINMENU_SPACE
* (Length(FButtons
) - 1)
1010 else h
:= hh
* (2 + Length(FButtons
)) + MAINMENU_SPACE
* (Length(FButtons
) - 1);
1011 h
:= (gScreenHeight
div 2) - (h
div 2);
1013 if FHeader
<> nil then with FHeader
do
1019 if FHeader
= nil then Inc(h
, lh
)
1022 for a
:= 0 to High(FButtons
) do
1024 if FButtons
[a
] <> nil then
1031 Inc(h
, hh
+MAINMENU_SPACE
);
1034 Result
:= FButtons
[High(FButtons
)];
1037 procedure TGUIMainMenu
.AddSpace
;
1039 SetLength(FButtons
, Length(FButtons
)+1);
1040 FButtons
[High(FButtons
)] := nil;
1043 constructor TGUIMainMenu
.Create(BigFont
: Boolean; Header
: string);
1048 FBigFont
:= BigFont
;
1049 FCounter
:= MAINMENU_MARKERDELAY
;
1051 if Header
<> '' then
1053 FHeader
:= TGUILabel
.Create(Header
, BigFont
);
1056 FColor
:= MAINMENU_HEADER_COLOR
;
1057 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1058 FY
:= (gScreenHeight
div 2)-(GetHeight
div 2);
1063 destructor TGUIMainMenu
.Destroy
;
1067 if FButtons
<> nil then
1068 for a
:= 0 to High(FButtons
) do
1076 procedure TGUIMainMenu
.EnableButton(aName
: string; e
: Boolean);
1080 if FButtons
= nil then Exit
;
1082 for a
:= 0 to High(FButtons
) do
1083 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= aName
) then
1085 if e
then FButtons
[a
].FColor
:= MAINMENU_ITEMS_COLOR
1086 else FButtons
[a
].FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
1087 FButtons
[a
].Enabled
:= e
;
1092 function TGUIMainMenu
.GetButton(aName
: string): TGUITextButton
;
1098 if FButtons
= nil then Exit
;
1100 for a
:= 0 to High(FButtons
) do
1101 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= aName
) then
1103 Result
:= FButtons
[a
];
1108 procedure TGUIMainMenu
.OnMessage(var Msg
: TMessage
);
1113 if not FEnabled
then Exit
;
1117 if FButtons
= nil then Exit
;
1120 for a
:= 0 to High(FButtons
) do
1121 if FButtons
[a
] <> nil then
1127 if not ok
then Exit
;
1132 IK_UP
, IK_KPUP
, VK_UP
, JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1136 if FIndex
< 0 then FIndex
:= High(FButtons
);
1137 until FButtons
[FIndex
] <> nil;
1139 g_Sound_PlayEx(MENU_CHANGESOUND
);
1141 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1145 if FIndex
> High(FButtons
) then FIndex
:= 0;
1146 until FButtons
[FIndex
] <> nil;
1148 g_Sound_PlayEx(MENU_CHANGESOUND
);
1150 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
: if (FIndex
<> -1) and FButtons
[FIndex
].FEnabled
then FButtons
[FIndex
].Click
;
1155 procedure TGUIMainMenu
.Update
;
1158 FCounter
:= (FCounter
+ 1) MOD (2 * MAINMENU_MARKERDELAY
)
1163 constructor TGUILabel
.Create(Text: string; BigFont
: Boolean);
1167 FBigFont
:= BigFont
;
1170 FOnClickEvent
:= nil;
1173 procedure TGUILabel
.OnMessage(var Msg
: TMessage
);
1175 if not FEnabled
then Exit
;
1182 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
: if @FOnClickEvent
<> nil then FOnClickEvent();
1189 function TGUIMenu
.AddButton(Proc
: Pointer; fText
: string; _ShowWindow
: string = ''): TGUITextButton
;
1196 Control
:= TGUITextButton
.Create(Proc
, FBigFont
, fText
);
1197 with Control
as TGUITextButton
do
1199 ShowWindow
:= _ShowWindow
;
1200 FColor
:= MENU_ITEMSCTRL_COLOR
;
1204 ControlType
:= TGUITextButton
;
1206 Result
:= (Control
as TGUITextButton
);
1209 if FIndex
= -1 then FIndex
:= i
;
1214 procedure TGUIMenu
.AddLine(fText
: string);
1221 Text := TGUILabel
.Create(fText
, FBigFont
);
1224 FColor
:= MENU_ITEMSTEXT_COLOR
;
1233 procedure TGUIMenu
.AddText(fText
: string; MaxWidth
: Word);
1238 l
:= GetLines(fText
, FBigFont
, MaxWidth
);
1240 if l
= nil then Exit
;
1242 for a
:= 0 to High(l
) do
1247 Text := TGUILabel
.Create(l
[a
], FBigFont
);
1250 with Text do begin FColor
:= _RGB(255, 0, 0); end;
1254 with Text do begin FColor
:= MENU_ITEMSTEXT_COLOR
; end;
1264 procedure TGUIMenu
.AddSpace
;
1278 constructor TGUIMenu
.Create(HeaderBigFont
, ItemsBigFont
: Boolean; Header
: string);
1284 FBigFont
:= ItemsBigFont
;
1285 FCounter
:= MENU_MARKERDELAY
;
1289 FHeader
:= TGUILabel
.Create(Header
, HeaderBigFont
);
1292 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1294 FColor
:= MAINMENU_HEADER_COLOR
;
1298 destructor TGUIMenu
.Destroy
;
1302 if FItems
<> nil then
1303 for a
:= 0 to High(FItems
) do
1317 function TGUIMenu
.GetControl(aName
: String): TGUIControl
;
1323 if FItems
<> nil then
1324 for a
:= 0 to High(FItems
) do
1325 if FItems
[a
].Control
<> nil then
1326 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(aName
) then
1328 Result
:= FItems
[a
].Control
;
1332 Assert(Result
<> nil, 'GUI control "'+aName
+'" not found!');
1335 function TGUIMenu
.GetControlsText(aName
: String): TGUILabel
;
1341 if FItems
<> nil then
1342 for a
:= 0 to High(FItems
) do
1343 if FItems
[a
].Control
<> nil then
1344 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(aName
) then
1346 Result
:= FItems
[a
].Text;
1350 Assert(Result
<> nil, 'GUI control''s text "'+aName
+'" not found!');
1353 function TGUIMenu
.NewItem
: Integer;
1355 SetLength(FItems
, Length(FItems
)+1);
1356 Result
:= High(FItems
);
1359 procedure TGUIMenu
.OnMessage(var Msg
: TMessage
);
1364 if not FEnabled
then Exit
;
1368 if FItems
= nil then Exit
;
1371 for a
:= 0 to High(FItems
) do
1372 if FItems
[a
].Control
<> nil then
1378 if not ok
then Exit
;
1380 if (Msg
.Msg
= WM_KEYDOWN
) and (FIndex
<> -1) and (FItems
[FIndex
].Control
<> nil) and
1381 (FItems
[FIndex
].Control
.WantActivationKey(Msg
.wParam
)) then
1383 FItems
[FIndex
].Control
.OnMessage(Msg
);
1384 g_Sound_PlayEx(MENU_CLICKSOUND
);
1392 IK_UP
, IK_KPUP
, VK_UP
,JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1397 if c
> Length(FItems
) then
1404 if FIndex
< 0 then FIndex
:= High(FItems
);
1405 until (FItems
[FIndex
].Control
<> nil) and
1406 (FItems
[FIndex
].Control
.Enabled
);
1410 g_Sound_PlayEx(MENU_CHANGESOUND
);
1413 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1418 if c
> Length(FItems
) then
1425 if FIndex
> High(FItems
) then FIndex
:= 0;
1426 until (FItems
[FIndex
].Control
<> nil) and
1427 (FItems
[FIndex
].Control
.Enabled
);
1431 g_Sound_PlayEx(MENU_CHANGESOUND
);
1434 IK_LEFT
, IK_RIGHT
, IK_KPLEFT
, IK_KPRIGHT
, VK_LEFT
, VK_RIGHT
,
1435 JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
,
1436 JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
1438 if FIndex
<> -1 then
1439 if FItems
[FIndex
].Control
<> nil then
1440 FItems
[FIndex
].Control
.OnMessage(Msg
);
1442 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
1444 if FIndex
<> -1 then
1446 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1448 g_Sound_PlayEx(MENU_CLICKSOUND
);
1452 if FYesNo
and (length(FItems
) > 1) then
1454 Msg
.wParam
:= IK_RETURN
; // to register keypress
1455 FIndex
:= High(FItems
)-1;
1456 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1459 if FYesNo
and (length(FItems
) > 1) then
1461 Msg
.wParam
:= IK_RETURN
; // to register keypress
1462 FIndex
:= High(FItems
);
1463 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1470 procedure TGUIMenu
.ReAlign();
1472 {$IFDEF ENABLE_RENDER}
1475 a
, tx
, cx
, w
, h
: Integer;
1476 cww
: array of Integer; // cached widths
1479 if FItems
= nil then Exit
;
1481 SetLength(cww
, length(FItems
));
1483 for a
:= 0 to High(FItems
) do
1485 if FItems
[a
].Text <> nil then
1487 cww
[a
] := FItems
[a
].Text.GetWidth
;
1488 if maxcww
< cww
[a
] then maxcww
:= cww
[a
];
1499 for a
:= 0 to High(FItems
) do
1502 if FItems
[a
].Text <> nil then w
:= FItems
[a
].Text.GetWidth
;
1503 if FItems
[a
].Control
<> nil then
1506 if FItems
[a
].ControlType
= TGUILabel
then w
:= w
+(FItems
[a
].Control
as TGUILabel
).GetWidth
1507 else if FItems
[a
].ControlType
= TGUITextButton
then w
:= w
+(FItems
[a
].Control
as TGUITextButton
).GetWidth
1508 else if FItems
[a
].ControlType
= TGUIScroll
then w
:= w
+(FItems
[a
].Control
as TGUIScroll
).GetWidth
1509 else if FItems
[a
].ControlType
= TGUISwitch
then w
:= w
+(FItems
[a
].Control
as TGUISwitch
).GetWidth
1510 else if FItems
[a
].ControlType
= TGUIEdit
then w
:= w
+(FItems
[a
].Control
as TGUIEdit
).GetWidth
1511 else if FItems
[a
].ControlType
= TGUIKeyRead
then w
:= w
+(FItems
[a
].Control
as TGUIKeyRead
).GetWidth
1512 else if FItems
[a
].ControlType
= TGUIKeyRead2
then w
:= w
+(FItems
[a
].Control
as TGUIKeyRead2
).GetWidth
1513 else if FItems
[a
].ControlType
= TGUIListBox
then w
:= w
+(FItems
[a
].Control
as TGUIListBox
).GetWidth
1514 else if FItems
[a
].ControlType
= TGUIFileListBox
then w
:= w
+(FItems
[a
].Control
as TGUIFileListBox
).GetWidth
1515 else if FItems
[a
].ControlType
= TGUIMemo
then w
:= w
+(FItems
[a
].Control
as TGUIMemo
).GetWidth
;
1517 tx
:= Min(tx
, (gScreenWidth
div 2)-(w
div 2));
1522 for a
:= 0 to High(FItems
) do
1526 if (Text <> nil) and (Control
= nil) then Continue
;
1528 if Text <> nil then w
:= tx
+Text.GetWidth
;
1529 if w
> cx
then cx
:= w
;
1533 cx
:= cx
+MENU_HSPACE
;
1535 h
:= FHeader
.GetHeight
*2+MENU_VSPACE
*(Length(FItems
)-1);
1537 for a
:= 0 to High(FItems
) do
1541 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then
1542 h
:= h
+(FItems
[a
].Control
as TGUIListBox
).GetHeight()
1545 {$IFDEF ENABLE_RENDER}
1546 r_GUI_GetMaxFontSize(FBigFont
, fw
, fh
);
1553 h
:= (gScreenHeight
div 2)-(h
div 2);
1557 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1560 Inc(h
, GetHeight
*2);
1563 for a
:= 0 to High(FItems
) do
1575 if Text.RightAlign
and (length(cww
) > a
) then
1577 //Text.FX := Text.FX+maxcww;
1578 Text.FMaxWidth
:= maxcww
;
1582 if Control
<> nil then
1599 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then Inc(h
, (Control
as TGUIListBox
).GetHeight
+MENU_VSPACE
)
1600 else if ControlType
= TGUIMemo
then Inc(h
, (Control
as TGUIMemo
).GetHeight
+MENU_VSPACE
)
1603 {$IFDEF ENABLE_RENDER}
1604 r_GUI_GetMaxFontSize(FBigFont
, fw
, fh
);
1605 h
:= h
+ fh
+ MENU_VSPACE
;
1607 h
:= h
+ MENU_VSPACE
;
1613 // another ugly hack
1614 if FYesNo
and (length(FItems
) > 1) then
1617 for a
:= High(FItems
)-1 to High(FItems
) do
1619 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1621 cx
:= (FItems
[a
].Control
as TGUITextButton
).GetWidth
;
1622 if cx
> w
then w
:= cx
;
1627 for a
:= High(FItems
)-1 to High(FItems
) do
1629 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1631 FItems
[a
].Control
.FX
:= (gScreenWidth
-w
) div 2;
1638 function TGUIMenu
.AddScroll(fText
: string): TGUIScroll
;
1645 Control
:= TGUIScroll
.Create();
1647 Text := TGUILabel
.Create(fText
, FBigFont
);
1650 FColor
:= MENU_ITEMSTEXT_COLOR
;
1653 ControlType
:= TGUIScroll
;
1655 Result
:= (Control
as TGUIScroll
);
1658 if FIndex
= -1 then FIndex
:= i
;
1663 function TGUIMenu
.AddSwitch(fText
: string): TGUISwitch
;
1670 Control
:= TGUISwitch
.Create(FBigFont
);
1671 (Control
as TGUISwitch
).FColor
:= MENU_ITEMSCTRL_COLOR
;
1673 Text := TGUILabel
.Create(fText
, FBigFont
);
1676 FColor
:= MENU_ITEMSTEXT_COLOR
;
1679 ControlType
:= TGUISwitch
;
1681 Result
:= (Control
as TGUISwitch
);
1684 if FIndex
= -1 then FIndex
:= i
;
1689 function TGUIMenu
.AddEdit(fText
: string): TGUIEdit
;
1696 Control
:= TGUIEdit
.Create(FBigFont
);
1697 with Control
as TGUIEdit
do
1699 FWindow
:= Self
.FWindow
;
1700 FColor
:= MENU_ITEMSCTRL_COLOR
;
1703 if fText
= '' then Text := nil else
1705 Text := TGUILabel
.Create(fText
, FBigFont
);
1706 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1709 ControlType
:= TGUIEdit
;
1711 Result
:= (Control
as TGUIEdit
);
1714 if FIndex
= -1 then FIndex
:= i
;
1719 procedure TGUIMenu
.Update
;
1725 if FCounter
= 0 then FCounter
:= MENU_MARKERDELAY
else Dec(FCounter
);
1727 if FItems
<> nil then
1728 for a
:= 0 to High(FItems
) do
1729 if FItems
[a
].Control
<> nil then
1730 (FItems
[a
].Control
as FItems
[a
].ControlType
).Update
;
1733 function TGUIMenu
.AddKeyRead(fText
: string): TGUIKeyRead
;
1740 Control
:= TGUIKeyRead
.Create(FBigFont
);
1741 with Control
as TGUIKeyRead
do
1743 FWindow
:= Self
.FWindow
;
1744 FColor
:= MENU_ITEMSCTRL_COLOR
;
1747 Text := TGUILabel
.Create(fText
, FBigFont
);
1750 FColor
:= MENU_ITEMSTEXT_COLOR
;
1753 ControlType
:= TGUIKeyRead
;
1755 Result
:= (Control
as TGUIKeyRead
);
1758 if FIndex
= -1 then FIndex
:= i
;
1763 function TGUIMenu
.AddKeyRead2(fText
: string): TGUIKeyRead2
;
1770 Control
:= TGUIKeyRead2
.Create(FBigFont
);
1771 with Control
as TGUIKeyRead2
do
1773 FWindow
:= Self
.FWindow
;
1774 FColor
:= MENU_ITEMSCTRL_COLOR
;
1777 Text := TGUILabel
.Create(fText
, FBigFont
);
1780 FColor
:= MENU_ITEMSCTRL_COLOR
; //MENU_ITEMSTEXT_COLOR;
1784 ControlType
:= TGUIKeyRead2
;
1786 Result
:= (Control
as TGUIKeyRead2
);
1789 if FIndex
= -1 then FIndex
:= i
;
1794 function TGUIMenu
.AddList(fText
: string; Width
, Height
: Word): TGUIListBox
;
1801 Control
:= TGUIListBox
.Create(FBigFont
, Width
, Height
);
1802 with Control
as TGUIListBox
do
1804 FWindow
:= Self
.FWindow
;
1805 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
1806 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
1809 Text := TGUILabel
.Create(fText
, FBigFont
);
1812 FColor
:= MENU_ITEMSTEXT_COLOR
;
1815 ControlType
:= TGUIListBox
;
1817 Result
:= (Control
as TGUIListBox
);
1820 if FIndex
= -1 then FIndex
:= i
;
1825 function TGUIMenu
.AddFileList(fText
: string; Width
, Height
: Word): TGUIFileListBox
;
1832 Control
:= TGUIFileListBox
.Create(FBigFont
, Width
, Height
);
1833 with Control
as TGUIFileListBox
do
1835 FWindow
:= Self
.FWindow
;
1836 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
1837 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
1840 if fText
= '' then Text := nil else
1842 Text := TGUILabel
.Create(fText
, FBigFont
);
1843 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1846 ControlType
:= TGUIFileListBox
;
1848 Result
:= (Control
as TGUIFileListBox
);
1851 if FIndex
= -1 then FIndex
:= i
;
1856 function TGUIMenu
.AddLabel(fText
: string): TGUILabel
;
1863 Control
:= TGUILabel
.Create('', FBigFont
);
1864 with Control
as TGUILabel
do
1866 FWindow
:= Self
.FWindow
;
1867 FColor
:= MENU_ITEMSCTRL_COLOR
;
1870 Text := TGUILabel
.Create(fText
, FBigFont
);
1873 FColor
:= MENU_ITEMSTEXT_COLOR
;
1876 ControlType
:= TGUILabel
;
1878 Result
:= (Control
as TGUILabel
);
1881 if FIndex
= -1 then FIndex
:= i
;
1886 function TGUIMenu
.AddMemo(fText
: string; Width
, Height
: Word): TGUIMemo
;
1893 Control
:= TGUIMemo
.Create(FBigFont
, Width
, Height
);
1894 with Control
as TGUIMemo
do
1896 FWindow
:= Self
.FWindow
;
1897 FColor
:= MENU_ITEMSTEXT_COLOR
;
1900 if fText
= '' then Text := nil else
1902 Text := TGUILabel
.Create(fText
, FBigFont
);
1903 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1906 ControlType
:= TGUIMemo
;
1908 Result
:= (Control
as TGUIMemo
);
1911 if FIndex
= -1 then FIndex
:= i
;
1916 procedure TGUIMenu
.UpdateIndex();
1924 if (FIndex
< 0) or (FIndex
> High(FItems
)) then
1930 if FItems
[FIndex
].Control
.Enabled
then
1939 constructor TGUIScroll
.Create
;
1944 FOnChangeEvent
:= nil;
1947 procedure TGUIScroll
.FSetValue(a
: Integer);
1949 if a
> FMax
then FValue
:= FMax
else FValue
:= a
;
1952 procedure TGUIScroll
.OnMessage(var Msg
: TMessage
);
1954 if not FEnabled
then Exit
;
1962 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
1966 g_Sound_PlayEx(SCROLL_SUBSOUND
);
1967 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
1969 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
1970 if FValue
< FMax
then
1973 g_Sound_PlayEx(SCROLL_ADDSOUND
);
1974 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
1981 procedure TGUIScroll
.Update
;
1989 procedure TGUISwitch
.AddItem(Item
: string);
1991 SetLength(FItems
, Length(FItems
)+1);
1992 FItems
[High(FItems
)] := Item
;
1994 if FIndex
= -1 then FIndex
:= 0;
1997 constructor TGUISwitch
.Create(BigFont
: Boolean);
2003 FBigFont
:= BigFont
;
2006 function TGUISwitch
.GetText
: string;
2008 if FIndex
<> -1 then Result
:= FItems
[FIndex
]
2012 procedure TGUISwitch
.OnMessage(var Msg
: TMessage
);
2014 if not FEnabled
then Exit
;
2018 if FItems
= nil then Exit
;
2023 IK_RETURN
, IK_RIGHT
, IK_KPRETURN
, IK_KPRIGHT
, VK_FIRE
, VK_OPEN
, VK_RIGHT
,
2024 JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
,
2025 JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2027 if FIndex
< High(FItems
) then
2032 g_Sound_PlayEx(SCROLL_ADDSOUND
);
2034 if @FOnChangeEvent
<> nil then
2035 FOnChangeEvent(Self
);
2038 IK_LEFT
, IK_KPLEFT
, VK_LEFT
,
2039 JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2044 FIndex
:= High(FItems
);
2046 g_Sound_PlayEx(SCROLL_SUBSOUND
);
2048 if @FOnChangeEvent
<> nil then
2049 FOnChangeEvent(Self
);
2055 procedure TGUISwitch
.Update
;
2063 constructor TGUIEdit
.Create(BigFont
: Boolean);
2067 FBigFont
:= BigFont
;
2073 procedure TGUIEdit
.OnMessage(var Msg
: TMessage
);
2075 if not FEnabled
then Exit
;
2084 if (wParam
in [48..57]) and (Chr(wParam
) <> '`') then
2085 if Length(Text) < FMaxLength
then
2087 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2093 if (wParam
in [32..255]) and (Chr(wParam
) <> '`') then
2094 if Length(Text) < FMaxLength
then
2096 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2104 Delete(FText
, FCaretPos
, 1);
2105 if FCaretPos
> 0 then Dec(FCaretPos
);
2107 IK_DELETE
: Delete(FText
, FCaretPos
+ 1, 1);
2108 IK_END
, IK_KPEND
: FCaretPos
:= Length(FText
);
2109 IK_HOME
, IK_KPHOME
: FCaretPos
:= 0;
2110 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
: if FCaretPos
> 0 then Dec(FCaretPos
);
2111 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
: if FCaretPos
< Length(FText
) then Inc(FCaretPos
);
2112 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2115 if FActiveControl
<> Self
then
2118 if @FOnEnterEvent
<> nil then FOnEnterEvent(Self
);
2122 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
2123 else SetActive(nil);
2124 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2130 g_GUIGrabInput
:= (@FOnEnterEvent
= nil) and (FWindow
.FActiveControl
= Self
);
2132 {$IFDEF ENABLE_TOUCH}
2133 sys_ShowKeyboard(g_GUIGrabInput
)
2137 procedure TGUIEdit
.SetText(Text: string);
2139 if Length(Text) > FMaxLength
then SetLength(Text, FMaxLength
);
2141 FCaretPos
:= Length(FText
);
2144 procedure TGUIEdit
.Update
;
2151 constructor TGUIKeyRead
.Create(BigFont
: Boolean);
2156 FBigFont
:= BigFont
;
2159 function TGUIKeyRead
.WantActivationKey (key
: LongInt): Boolean;
2162 (key
= IK_BACKSPACE
) or
2166 procedure TGUIKeyRead
.OnMessage(var Msg
: TMessage
);
2167 procedure actDefCtl ();
2170 if FDefControl
<> '' then
2171 SetActive(GetControl(FDefControl
))
2179 if not FEnabled
then
2185 if not FIsQuery
then
2188 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2191 if FActiveControl
<> Self
then
2195 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2208 VK_FIRSTKEY
..VK_LASTKEY
: // do not allow to bind virtual keys
2214 if (e_KeyNames
[wParam
] <> '') and not g_Console_MatchBind(wParam
, 'togglemenu') then
2222 g_GUIGrabInput
:= FIsQuery
2227 constructor TGUIKeyRead2
.Create(BigFont
: Boolean);
2228 {$IFDEF ENABLE_RENDER}
2229 var a
: Byte; w
, h
: Integer;
2239 FBigFont
:= BigFont
;
2241 FMaxKeyNameWdt
:= 0;
2243 {$IFDEF ENABLE_RENDER}
2244 for a
:= 0 to 255 do
2246 r_GUI_GetStringSize(BigFont
, e_KeyNames
[a
], w
, h
);
2247 FMaxKeyNameWdt
:= Max(FMaxKeyNameWdt
, w
);
2249 FMaxKeyNameWdt
:= FMaxKeyNameWdt
-(FMaxKeyNameWdt
div 3);
2250 r_GUI_GetStringSize(BigFont
, KEYREAD_QUERY
, w
, h
);
2251 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2252 r_GUI_GetStringSize(BigFont
, KEYREAD_CLEAR
, w
, h
);
2253 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2257 function TGUIKeyRead2
.WantActivationKey (key
: LongInt): Boolean;
2260 IK_BACKSPACE
, IK_LEFT
, IK_RIGHT
, IK_KPLEFT
, IK_KPRIGHT
, VK_LEFT
, VK_RIGHT
,
2261 JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
,
2262 JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2269 procedure TGUIKeyRead2
.OnMessage(var Msg
: TMessage
);
2270 procedure actDefCtl ();
2273 if FDefControl
<> '' then
2274 SetActive(GetControl(FDefControl
))
2282 if not FEnabled
then
2288 if not FIsQuery
then
2291 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2294 if FActiveControl
<> Self
then
2298 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2300 if (FKeyIdx
= 0) then FKey0
:= 0 else FKey1
:= 0;
2303 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2308 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2321 VK_FIRSTKEY
..VK_LASTKEY
: // do not allow to bind virtual keys
2327 if (e_KeyNames
[wParam
] <> '') and not g_Console_MatchBind(wParam
, 'togglemenu') then
2329 if (FKeyIdx
= 0) then FKey0
:= wParam
else FKey1
:= wParam
;
2337 g_GUIGrabInput
:= FIsQuery
2343 constructor TGUIModelView
.Create
;
2350 destructor TGUIModelView
.Destroy
;
2357 procedure TGUIModelView
.NextAnim();
2359 if FModel
= nil then
2362 if FModel
.Animation
< A_PAIN
then
2363 FModel
.ChangeAnimation(FModel
.Animation
+1, True)
2365 FModel
.ChangeAnimation(A_STAND
, True);
2368 procedure TGUIModelView
.NextWeapon();
2370 if FModel
= nil then
2373 if FModel
.Weapon
< WP_LAST
then
2374 FModel
.SetWeapon(FModel
.Weapon
+1)
2376 FModel
.SetWeapon(WEAPON_KASTET
);
2379 procedure TGUIModelView
.OnMessage(var Msg
: TMessage
);
2385 procedure TGUIModelView
.SetColor(Red
, Green
, Blue
: Byte);
2387 if FModel
<> nil then FModel
.SetColor(Red
, Green
, Blue
);
2390 procedure TGUIModelView
.SetModel(ModelName
: string);
2394 FModel
:= g_PlayerModel_Get(ModelName
);
2397 procedure TGUIModelView
.Update
;
2404 if FModel
<> nil then FModel
.Update
;
2409 constructor TGUIMapPreview
.Create();
2415 destructor TGUIMapPreview
.Destroy();
2421 procedure TGUIMapPreview
.OnMessage(var Msg
: TMessage
);
2427 procedure TGUIMapPreview
.SetMap(Res
: string);
2432 //header: TMapHeaderRec_1;
2437 map
: TDynRecord
= nil;
2444 FileName
:= g_ExtractWadName(Res
);
2446 WAD
:= TWADFile
.Create();
2447 if not WAD
.ReadFile(FileName
) then
2453 //k8: ignores path again
2454 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
2463 map
:= g_Map_ParseMap(Data
, Len
);
2473 if (map
= nil) then exit
;
2476 panlist
:= map
.field
['panel'];
2477 //header := GetMapHeader(map);
2479 FMapSize
.X
:= map
.Width
div 16;
2480 FMapSize
.Y
:= map
.Height
div 16;
2482 rX
:= Ceil(map
.Width
/ (MAPPREVIEW_WIDTH
*256.0));
2483 rY
:= Ceil(map
.Height
/ (MAPPREVIEW_HEIGHT
*256.0));
2484 FScale
:= max(rX
, rY
);
2488 if (panlist
<> nil) then
2490 for pan
in panlist
do
2492 if (pan
.PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or
2493 PANEL_STEP
or PANEL_WATER
or
2494 PANEL_ACID1
or PANEL_ACID2
)) <> 0 then
2496 SetLength(FMapData
, Length(FMapData
)+1);
2497 with FMapData
[High(FMapData
)] do
2502 X2
:= (pan
.X
+ pan
.Width
) div 16;
2503 Y2
:= (pan
.Y
+ pan
.Height
) div 16;
2505 X1
:= Trunc(X1
/FScale
+ 0.5);
2506 Y1
:= Trunc(Y1
/FScale
+ 0.5);
2507 X2
:= Trunc(X2
/FScale
+ 0.5);
2508 Y2
:= Trunc(Y2
/FScale
+ 0.5);
2510 if (X1
<> X2
) or (Y1
<> Y2
) then
2518 PanelType
:= pan
.PanelType
;
2524 //writeln('freeing map');
2529 procedure TGUIMapPreview
.ClearMap();
2531 SetLength(FMapData
, 0);
2538 procedure TGUIMapPreview
.Update();
2544 function TGUIMapPreview
.GetScaleStr(): String;
2546 if FScale
> 0.0 then
2548 Result
:= FloatToStrF(FScale
*16.0, ffFixed
, 3, 3);
2549 while (Result
[Length(Result
)] = '0') do
2550 Delete(Result
, Length(Result
), 1);
2551 if (Result
[Length(Result
)] = ',') or (Result
[Length(Result
)] = '.') then
2552 Delete(Result
, Length(Result
), 1);
2553 Result
:= '1 : ' + Result
;
2561 procedure TGUIListBox
.AddItem(Item
: string);
2563 SetLength(FItems
, Length(FItems
)+1);
2564 FItems
[High(FItems
)] := Item
;
2566 if FSort
then g_gui
.Sort(FItems
);
2569 function TGUIListBox
.ItemExists (item
: String): Boolean;
2573 while (i
<= High(FItems
)) and (FItems
[i
] <> item
) do Inc(i
);
2574 result
:= i
<= High(FItems
)
2577 procedure TGUIListBox
.Clear
;
2585 constructor TGUIListBox
.Create(BigFont
: Boolean; Width
, Height
: Word);
2589 FBigFont
:= BigFont
;
2593 FOnChangeEvent
:= nil;
2595 FDrawScroll
:= True;
2598 procedure TGUIListBox
.OnMessage(var Msg
: TMessage
);
2602 if not FEnabled
then Exit
;
2606 if FItems
= nil then Exit
;
2619 FIndex
:= High(FItems
);
2620 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
2622 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2626 if FIndex
< FStartLine
then Dec(FStartLine
);
2627 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2629 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2630 if FIndex
< High(FItems
) then
2633 if FIndex
> FStartLine
+FHeight
-1 then Inc(FStartLine
);
2634 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2636 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2639 if FActiveControl
<> Self
then SetActive(Self
)
2641 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
2642 else SetActive(nil);
2646 for a
:= 0 to High(FItems
) do
2647 if (Length(FItems
[a
]) > 0) and (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) then
2650 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
2651 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2657 function TGUIListBox
.SelectedItem(): String;
2661 if (FIndex
< 0) or (FItems
= nil) or
2662 (FIndex
> High(FItems
)) then
2665 Result
:= FItems
[FIndex
];
2668 procedure TGUIListBox
.FSetItems(Items
: SSArray
);
2670 if FItems
<> nil then
2678 if FSort
then g_gui
.Sort(FItems
);
2681 procedure TGUIListBox
.SelectItem(Item
: String);
2685 if FItems
= nil then
2689 Item
:= LowerCase(Item
);
2691 for a
:= 0 to High(FItems
) do
2692 if LowerCase(FItems
[a
]) = Item
then
2698 if FIndex
< FHeight
then
2701 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
2704 procedure TGUIListBox
.FSetIndex(aIndex
: Integer);
2706 if FItems
= nil then
2709 if (aIndex
< 0) or (aIndex
> High(FItems
)) then
2714 if FIndex
<= FHeight
then
2717 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
2722 procedure TGUIFileListBox
.OnMessage(var Msg
: TMessage
);
2724 a
, b
: Integer; s
: AnsiString;
2726 if not FEnabled
then
2729 if FItems
= nil then
2740 if @FOnChangeEvent
<> nil then
2741 FOnChangeEvent(Self
);
2746 FIndex
:= High(FItems
);
2747 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
2748 if @FOnChangeEvent
<> nil then
2749 FOnChangeEvent(Self
);
2752 IK_PAGEUP
, IK_KPPAGEUP
:
2754 if FIndex
> FHeight
then
2755 FIndex
:= FIndex
-FHeight
2759 if FStartLine
> FHeight
then
2760 FStartLine
:= FStartLine
-FHeight
2765 IK_PAGEDN
, IK_KPPAGEDN
:
2767 if FIndex
< High(FItems
)-FHeight
then
2768 FIndex
:= FIndex
+FHeight
2770 FIndex
:= High(FItems
);
2772 if FStartLine
< High(FItems
)-FHeight
then
2773 FStartLine
:= FStartLine
+FHeight
2775 FStartLine
:= High(FItems
)-FHeight
+1;
2778 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
, VK_UP
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2782 if FIndex
< FStartLine
then
2784 if @FOnChangeEvent
<> nil then
2785 FOnChangeEvent(Self
);
2788 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
, VK_DOWN
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2789 if FIndex
< High(FItems
) then
2792 if FIndex
> FStartLine
+FHeight
-1 then
2794 if @FOnChangeEvent
<> nil then
2795 FOnChangeEvent(Self
);
2798 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2801 if FActiveControl
<> Self
then
2805 if FItems
[FIndex
][1] = #29 then // Ïàïêà
2807 if FItems
[FIndex
] = #29 + '..' then
2809 //e_LogWritefln('TGUIFileListBox: Upper dir "%s" -> "%s"', [FSubPath, e_UpperDir(FSubPath)]);
2810 FSubPath
:= e_UpperDir(FSubPath
)
2814 s
:= Copy(AnsiString(FItems
[FIndex
]), 2);
2815 //e_LogWritefln('TGUIFileListBox: Enter dir "%s" -> "%s"', [FSubPath, e_CatPath(FSubPath, s)]);
2816 FSubPath
:= e_CatPath(FSubPath
, s
);
2823 if FDefControl
<> '' then
2824 SetActive(GetControl(FDefControl
))
2832 for b
:= FIndex
+ 1 to High(FItems
) + FIndex
do
2834 a
:= b
mod Length(FItems
);
2835 if ( (Length(FItems
[a
]) > 0) and
2836 (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) ) or
2837 ( (Length(FItems
[a
]) > 1) and
2838 (FItems
[a
][1] = #29) and // Ïàïêà
2839 (LowerCase(FItems
[a
][2]) = LowerCase(Chr(wParam
))) ) then
2842 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
2843 if @FOnChangeEvent
<> nil then
2844 FOnChangeEvent(Self
);
2851 procedure TGUIFileListBox
.ScanDirs
;
2852 var i
, j
: Integer; path
: AnsiString; SR
: TSearchRec
; sm
, sc
: String;
2856 i
:= High(FBaseList
);
2859 path
:= e_CatPath(FBaseList
[i
], FSubPath
);
2862 if FindFirst(path
+ '/' + '*', faDirectory
, SR
) = 0 then
2865 if LongBool(SR
.Attr
and faDirectory
) then
2866 if (SR
.Name
<> '.') and ((FSubPath
<> '') or (SR
.Name
<> '..')) then
2867 if Self
.ItemExists(#1 + SR
.Name
) = false then
2868 Self
.AddItem(#1 + SR
.Name
)
2869 until FindNext(SR
) <> 0
2876 i
:= High(FBaseList
);
2879 path
:= e_CatPath(FBaseList
[i
], FSubPath
);
2885 j
:= length(sm
) + 1;
2886 sc
:= Copy(sm
, 1, j
- 1);
2888 if FindFirst(path
+ '/' + sc
, faAnyFile
, SR
) = 0 then
2891 if Self
.ItemExists(SR
.Name
) = false then
2893 until FindNext(SR
) <> 0
2900 for i
:= 0 to High(FItems
) do
2901 if FItems
[i
][1] = #1 then
2902 FItems
[i
][1] := #29;
2905 procedure TGUIFileListBox
.SetBase (dirs
: SSArray
; path
: String = '');
2912 function TGUIFileListBox
.SelectedItem (): String;
2916 if (FIndex
>= 0) and (FIndex
<= High(FItems
)) and (FItems
[FIndex
][1] <> '/') and (FItems
[FIndex
][1] <> '\') then
2918 s
:= e_CatPath(FSubPath
, FItems
[FIndex
]);
2919 if e_FindResource(FBaseList
, s
) = true then
2920 result
:= ExpandFileName(s
)
2922 e_LogWritefln('TGUIFileListBox.SelectedItem -> "%s"', [result
]);
2925 procedure TGUIFileListBox
.UpdateFileList();
2929 if (FIndex
= -1) or (FItems
= nil) or
2930 (FIndex
> High(FItems
)) or
2931 (FItems
[FIndex
][1] = '/') or
2932 (FItems
[FIndex
][1] = '\') then
2935 fn
:= FItems
[FIndex
];
2946 procedure TGUIMemo
.Clear
;
2952 constructor TGUIMemo
.Create(BigFont
: Boolean; Width
, Height
: Word);
2956 FBigFont
:= BigFont
;
2960 FDrawScroll
:= True;
2963 procedure TGUIMemo
.OnMessage(var Msg
: TMessage
);
2965 if not FEnabled
then Exit
;
2969 if FLines
= nil then Exit
;
2975 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
, VK_UP
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2976 if FStartLine
> 0 then
2978 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
, VK_DOWN
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2979 if FStartLine
< Length(FLines
)-FHeight
then
2981 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2984 if FActiveControl
<> Self
then
2990 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
2991 else SetActive(nil);
2997 procedure TGUIMemo
.SetText(Text: string);
3000 FLines
:= GetLines(Text, FBigFont
, FWidth
* 16);
3005 procedure TGUIimage
.ClearImage();
3010 constructor TGUIimage
.Create();
3017 destructor TGUIimage
.Destroy();
3022 procedure TGUIimage
.OnMessage(var Msg
: TMessage
);
3027 procedure TGUIimage
.SetImage(Res
: string);
3032 procedure TGUIimage
.Update();