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
, r_graphics
, e_input
, e_log
, g_playermodel
, g_basic
, g_touch
, 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;
69 BSCROLL_UPA
= 'BSCROLL_UP_A';
70 BSCROLL_UPU
= 'BSCROLL_UP_U';
71 BSCROLL_DOWNA
= 'BSCROLL_DOWN_A';
72 BSCROLL_DOWNU
= 'BSCROLL_DOWN_U';
73 BSCROLL_MIDDLE
= 'BSCROLL_MIDDLE';
78 MESSAGE_DIKEY
= WM_USER
+ 1;
87 TFontType
= (Texture
, Character
);
89 TFont
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
95 constructor Create(FontID
: DWORD
; FontType
: TFontType
);
96 destructor Destroy
; override;
97 procedure Draw(X
, Y
: Integer; Text: string; R
, G
, B
: Byte);
98 procedure GetTextSize(Text: string; var w
, h
: Word);
99 property Scale
: Single read FScale write FScale
;
105 TOnKeyDownEvent
= procedure(Key
: Byte);
106 TOnKeyDownEventEx
= procedure(win
: TGUIWindow
; Key
: Byte);
107 TOnCloseEvent
= procedure;
108 TOnShowEvent
= procedure;
109 TOnClickEvent
= procedure;
110 TOnChangeEvent
= procedure(Sender
: TGUIControl
);
111 TOnEnterEvent
= procedure(Sender
: TGUIControl
);
113 TGUIControl
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
117 FWindow
: TGUIWindow
;
120 FRightAlign
: Boolean; //HACK! this works only for "normal" menus, only for menu text labels, and generally sux. sorry.
121 FMaxWidth
: Integer; //HACK! used for right-aligning labels
124 procedure OnMessage(var Msg
: TMessage
); virtual;
125 procedure Update
; virtual;
126 procedure Draw
; virtual;
127 function GetWidth(): Integer; virtual;
128 function GetHeight(): Integer; virtual;
129 function WantActivationKey (key
: LongInt): Boolean; virtual;
130 property X
: Integer read FX write FX
;
131 property Y
: Integer read FY write FY
;
132 property Enabled
: Boolean read FEnabled write FEnabled
;
133 property Name
: string read FName write FName
;
134 property UserData
: Pointer read FUserData write FUserData
;
135 property RightAlign
: Boolean read FRightAlign write FRightAlign
; // for menu
138 TGUIWindow
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
140 FActiveControl
: TGUIControl
;
142 FPrevWindow
: TGUIWindow
;
144 FBackTexture
: string;
145 FMainWindow
: Boolean;
146 FOnKeyDown
: TOnKeyDownEvent
;
147 FOnKeyDownEx
: TOnKeyDownEventEx
;
148 FOnCloseEvent
: TOnCloseEvent
;
149 FOnShowEvent
: TOnShowEvent
;
152 Childs
: array of TGUIControl
;
153 constructor Create(Name
: string);
154 destructor Destroy
; override;
155 function AddChild(Child
: TGUIControl
): TGUIControl
;
156 procedure OnMessage(var Msg
: TMessage
);
159 procedure SetActive(Control
: TGUIControl
);
160 function GetControl(Name
: string): TGUIControl
;
161 property OnKeyDown
: TOnKeyDownEvent read FOnKeyDown write FOnKeyDown
;
162 property OnKeyDownEx
: TOnKeyDownEventEx read FOnKeyDownEx write FOnKeyDownEx
;
163 property OnClose
: TOnCloseEvent read FOnCloseEvent write FOnCloseEvent
;
164 property OnShow
: TOnShowEvent read FOnShowEvent write FOnShowEvent
;
165 property Name
: string read FName
;
166 property DefControl
: string read FDefControl write FDefControl
;
167 property BackTexture
: string read FBackTexture write FBackTexture
;
168 property MainWindow
: Boolean read FMainWindow write FMainWindow
;
169 property UserData
: Pointer read FUserData write FUserData
;
172 TGUITextButton
= class(TGUIControl
)
181 ProcEx
: procedure (sender
: TGUITextButton
);
182 constructor Create(aProc
: Pointer; FontID
: DWORD
; Text: string);
183 destructor Destroy(); override;
184 procedure OnMessage(var Msg
: TMessage
); override;
185 procedure Update(); override;
186 procedure Draw(); override;
187 function GetWidth(): Integer; override;
188 function GetHeight(): Integer; override;
189 procedure Click(Silent
: Boolean = False);
190 property Caption
: string read FText write FText
;
191 property Color
: TRGB read FColor write FColor
;
192 property Font
: TFont read FFont write FFont
;
193 property ShowWindow
: string read FShowWindow write FShowWindow
;
196 TGUILabel
= class(TGUIControl
)
202 FOnClickEvent
: TOnClickEvent
;
204 constructor Create(Text: string; FontID
: DWORD
);
205 procedure OnMessage(var Msg
: TMessage
); override;
206 procedure Draw
; override;
207 function GetWidth
: Integer; override;
208 function GetHeight
: Integer; override;
209 property OnClick
: TOnClickEvent read FOnClickEvent write FOnClickEvent
;
210 property FixedLength
: Word read FFixedLen write FFixedLen
;
211 property Text: string read FText write FText
;
212 property Color
: TRGB read FColor write FColor
;
213 property Font
: TFont read FFont write FFont
;
216 TGUIScroll
= class(TGUIControl
)
224 FOnChangeEvent
: TOnChangeEvent
;
225 procedure FSetValue(a
: Integer);
227 constructor Create();
228 procedure OnMessage(var Msg
: TMessage
); override;
229 procedure Update
; override;
230 procedure Draw
; override;
231 function GetWidth(): Integer; override;
232 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
233 property Max
: Word read FMax write FMax
;
234 property Value
: Integer read FValue write FSetValue
;
237 TGUISwitch
= class(TGUIControl
)
240 FItems
: array of string;
243 FOnChangeEvent
: TOnChangeEvent
;
245 constructor Create(FontID
: DWORD
);
246 procedure OnMessage(var Msg
: TMessage
); override;
247 procedure AddItem(Item
: string);
248 procedure Update
; override;
249 procedure Draw
; override;
250 function GetWidth(): Integer; override;
251 function GetText
: string;
252 property ItemIndex
: Integer read FIndex write FIndex
;
253 property Color
: TRGB read FColor write FColor
;
254 property Font
: TFont read FFont write FFont
;
255 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
258 TGUIEdit
= class(TGUIControl
)
266 FOnlyDigits
: Boolean;
270 FOnChangeEvent
: TOnChangeEvent
;
271 FOnEnterEvent
: TOnEnterEvent
;
273 procedure SetText(Text: string);
275 constructor Create(FontID
: DWORD
);
276 procedure OnMessage(var Msg
: TMessage
); override;
277 procedure Update
; override;
278 procedure Draw
; override;
279 function GetWidth(): Integer; override;
280 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
281 property OnEnter
: TOnEnterEvent read FOnEnterEvent write FOnEnterEvent
;
282 property Width
: Word read FWidth write FWidth
;
283 property MaxLength
: Word read FMaxLength write FMaxLength
;
284 property OnlyDigits
: Boolean read FOnlyDigits write FOnlyDigits
;
285 property Text: string read FText write SetText
;
286 property Color
: TRGB read FColor write FColor
;
287 property Font
: TFont read FFont write FFont
;
288 property Invalid
: Boolean read FInvalid write FInvalid
;
291 TGUIKeyRead
= class(TGUIControl
)
298 constructor Create(FontID
: DWORD
);
299 procedure OnMessage(var Msg
: TMessage
); override;
300 procedure Draw
; override;
301 function GetWidth(): Integer; override;
302 function WantActivationKey (key
: LongInt): Boolean; override;
303 property Key
: Word read FKey write FKey
;
304 property Color
: TRGB read FColor write FColor
;
305 property Font
: TFont read FFont write FFont
;
309 TGUIKeyRead2
= class(TGUIControl
)
314 FKey0
, FKey1
: Word; // this should be an array. sorry.
317 FMaxKeyNameWdt
: Integer;
319 constructor Create(FontID
: DWORD
);
320 procedure OnMessage(var Msg
: TMessage
); override;
321 procedure Draw
; override;
322 function GetWidth(): Integer; override;
323 function WantActivationKey (key
: LongInt): Boolean; override;
324 property Key0
: Word read FKey0 write FKey0
;
325 property Key1
: Word read FKey1 write FKey1
;
326 property Color
: TRGB read FColor write FColor
;
327 property Font
: TFont read FFont write FFont
;
330 TGUIModelView
= class(TGUIControl
)
332 FModel
: TPlayerModel
;
336 destructor Destroy
; override;
337 procedure OnMessage(var Msg
: TMessage
); override;
338 procedure SetModel(ModelName
: string);
339 procedure SetColor(Red
, Green
, Blue
: Byte);
340 procedure NextAnim();
341 procedure NextWeapon();
342 procedure Update
; override;
343 procedure Draw
; override;
344 property Model
: TPlayerModel read FModel
;
347 TPreviewPanel
= record
348 X1
, Y1
, X2
, Y2
: Integer;
352 TGUIMapPreview
= class(TGUIControl
)
354 FMapData
: array of TPreviewPanel
;
358 constructor Create();
359 destructor Destroy(); override;
360 procedure OnMessage(var Msg
: TMessage
); override;
361 procedure SetMap(Res
: string);
362 procedure ClearMap();
363 procedure Update(); override;
364 procedure Draw(); override;
365 function GetScaleStr
: String;
368 TGUIImage
= class(TGUIControl
)
373 constructor Create();
374 destructor Destroy(); override;
375 procedure OnMessage(var Msg
: TMessage
); override;
376 procedure SetImage(Res
: string);
377 procedure ClearImage();
378 procedure Update(); override;
379 procedure Draw(); override;
380 property DefaultRes
: string read FDefaultRes write FDefaultRes
;
383 TGUIListBox
= class(TGUIControl
)
387 FUnActiveColor
: TRGB
;
395 FDrawScroll
: Boolean;
396 FOnChangeEvent
: TOnChangeEvent
;
398 procedure FSetItems(Items
: SSArray
);
399 procedure FSetIndex(aIndex
: Integer);
402 constructor Create(FontID
: DWORD
; Width
, Height
: Word);
403 procedure OnMessage(var Msg
: TMessage
); override;
404 procedure Draw(); override;
405 procedure AddItem(Item
: String);
406 function ItemExists (item
: String): Boolean;
407 procedure SelectItem(Item
: String);
409 function GetWidth(): Integer; override;
410 function GetHeight(): Integer; override;
411 function SelectedItem(): String;
413 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
414 property Sort
: Boolean read FSort write FSort
;
415 property ItemIndex
: Integer read FIndex write FSetIndex
;
416 property Items
: SSArray read FItems write FSetItems
;
417 property DrawBack
: Boolean read FDrawBack write FDrawBack
;
418 property DrawScrollBar
: Boolean read FDrawScroll write FDrawScroll
;
419 property ActiveColor
: TRGB read FActiveColor write FActiveColor
;
420 property UnActiveColor
: TRGB read FUnActiveColor write FUnActiveColor
;
421 property Font
: TFont read FFont write FFont
;
424 TGUIFileListBox
= class(TGUIListBox
)
429 FBaseList
: SSArray
; // highter index have highter priority
434 procedure OnMessage (var Msg
: TMessage
); override;
435 procedure SetBase (dirs
: SSArray
; path
: String = '');
436 function SelectedItem(): String;
437 procedure UpdateFileList
;
439 property Dirs
: Boolean read FDirs write FDirs
;
440 property FileMask
: String read FFileMask write FFileMask
;
443 TGUIMemo
= class(TGUIControl
)
452 FDrawScroll
: Boolean;
454 constructor Create(FontID
: DWORD
; Width
, Height
: Word);
455 procedure OnMessage(var Msg
: TMessage
); override;
456 procedure Draw
; override;
458 function GetWidth(): Integer; override;
459 function GetHeight(): Integer; override;
460 procedure SetText(Text: string);
461 property DrawBack
: Boolean read FDrawBack write FDrawBack
;
462 property DrawScrollBar
: Boolean read FDrawScroll write FDrawScroll
;
463 property Color
: TRGB read FColor write FColor
;
464 property Font
: TFont read FFont write FFont
;
467 TGUIMainMenu
= class(TGUIControl
)
469 FButtons
: array of TGUITextButton
;
478 constructor Create(FontID
: DWORD
; Logo
, Header
: string);
479 destructor Destroy
; override;
480 procedure OnMessage(var Msg
: TMessage
); override;
481 function AddButton(fProc
: Pointer; Caption
: string; ShowWindow
: string = ''): TGUITextButton
;
482 function GetButton(aName
: string): TGUITextButton
;
483 procedure EnableButton(aName
: string; e
: Boolean);
484 procedure AddSpace();
485 procedure Update
; override;
486 procedure Draw
; override;
489 TControlType
= class of TGUIControl
;
491 PMenuItem
= ^TMenuItem
;
494 ControlType
: TControlType
;
495 Control
: TGUIControl
;
498 TGUIMenu
= class(TGUIControl
)
500 FItems
: array of TMenuItem
;
508 function NewItem(): Integer;
510 constructor Create(HeaderFont
, ItemsFont
: DWORD
; Header
: string);
511 destructor Destroy
; override;
512 procedure OnMessage(var Msg
: TMessage
); override;
513 procedure AddSpace();
514 procedure AddLine(fText
: string);
515 procedure AddText(fText
: string; MaxWidth
: Word);
516 function AddLabel(fText
: string): TGUILabel
;
517 function AddButton(Proc
: Pointer; fText
: string; _ShowWindow
: string = ''): TGUITextButton
;
518 function AddScroll(fText
: string): TGUIScroll
;
519 function AddSwitch(fText
: string): TGUISwitch
;
520 function AddEdit(fText
: string): TGUIEdit
;
521 function AddKeyRead(fText
: string): TGUIKeyRead
;
522 function AddKeyRead2(fText
: string): TGUIKeyRead2
;
523 function AddList(fText
: string; Width
, Height
: Word): TGUIListBox
;
524 function AddFileList(fText
: string; Width
, Height
: Word): TGUIFileListBox
;
525 function AddMemo(fText
: string; Width
, Height
: Word): TGUIMemo
;
527 function GetControl(aName
: string): TGUIControl
;
528 function GetControlsText(aName
: string): TGUILabel
;
529 procedure Draw
; override;
530 procedure Update
; override;
531 procedure UpdateIndex();
532 property Align
: Boolean read FAlign write FAlign
;
533 property Left
: Integer read FLeft write FLeft
;
534 property YesNo
: Boolean read FYesNo write FYesNo
;
538 g_GUIWindows
: array of TGUIWindow
;
539 g_ActiveWindow
: TGUIWindow
= nil;
540 g_GUIGrabInput
: Boolean = False;
542 procedure g_GUI_Init();
543 function g_GUI_AddWindow(Window
: TGUIWindow
): TGUIWindow
;
544 function g_GUI_GetWindow(Name
: string): TGUIWindow
;
545 procedure g_GUI_ShowWindow(Name
: string);
546 procedure g_GUI_HideWindow(PlaySound
: Boolean = True);
547 function g_GUI_Destroy(): Boolean;
548 procedure g_GUI_SaveMenuPos();
549 procedure g_GUI_LoadMenuPos();
555 g_sound
, SysUtils
, e_res
, r_textures
,
556 g_game
, Math
, StrUtils
, g_player
, g_options
, g_console
, r_playermodel
,
557 g_map
, g_weapons
, xdynrec
, wadreader
;
561 Box
: Array [0..8] of DWORD
;
562 Saved_Windows
: SSArray
;
564 function GetLines (text: string; FontID
: DWORD
; MaxWidth
: Word): SSArray
;
568 i
, len
, lastsep
: Integer;
570 function PrepareStep (): Boolean; inline;
572 // Skip leading spaces.
573 while PChar(text)[k
-1] = ' ' do k
+= 1;
578 function GetLine (j
: Integer; Strip
: Boolean): String; inline;
580 // Exclude trailing spaces from the line.
582 while text[j
] = ' ' do j
-= 1;
584 Result
:= Copy(text, k
, j
-k
+1);
587 function LineWidth (): Integer; inline;
590 e_CharFont_GetSize(FontID
, GetLine(i
, False), w
, h
);
597 //e_LogWritefln('GetLines @%s len=%s [%s]', [MaxWidth, len, text]);
599 while PrepareStep() do
601 // Get longest possible sequence (this is not constant because fonts are not monospaced).
604 if text[i
] in [' ', '.', ',', ':', ';']
607 until (i
> len
) or (LineWidth() > MaxWidth
);
609 // Do not include part of a word if possible.
610 if (lastsep
-k
> 3) and (i
<= len
) and (text[i
] <> ' ')
611 then i
:= lastsep
+ 1;
614 SetLength(Result
, lines
+ 1);
615 Result
[lines
] := GetLine(i
-1, True);
616 //e_LogWritefln(' -> (%s:%s::%s) [%s]', [k, i, LineWidth(), Result[lines]]);
623 procedure Sort(var a
: SSArray
);
628 if a
= nil then Exit
;
630 for i
:= High(a
) downto Low(a
) do
631 for j
:= Low(a
) to High(a
)-1 do
632 if LowerCase(a
[j
]) > LowerCase(a
[j
+1]) then
640 procedure g_GUI_Init();
642 g_Texture_Get(BOX1
, Box
[0]);
643 g_Texture_Get(BOX2
, Box
[1]);
644 g_Texture_Get(BOX3
, Box
[2]);
645 g_Texture_Get(BOX4
, Box
[3]);
646 g_Texture_Get(BOX5
, Box
[4]);
647 g_Texture_Get(BOX6
, Box
[5]);
648 g_Texture_Get(BOX7
, Box
[6]);
649 g_Texture_Get(BOX8
, Box
[7]);
650 g_Texture_Get(BOX9
, Box
[8]);
653 function g_GUI_Destroy(): Boolean;
657 Result
:= (Length(g_GUIWindows
) > 0);
659 for i
:= 0 to High(g_GUIWindows
) do
660 g_GUIWindows
[i
].Free();
663 g_ActiveWindow
:= nil;
666 function g_GUI_AddWindow(Window
: TGUIWindow
): TGUIWindow
;
668 SetLength(g_GUIWindows
, Length(g_GUIWindows
)+1);
669 g_GUIWindows
[High(g_GUIWindows
)] := Window
;
674 function g_GUI_GetWindow(Name
: string): TGUIWindow
;
680 if g_GUIWindows
<> nil then
681 for i
:= 0 to High(g_GUIWindows
) do
682 if g_GUIWindows
[i
].FName
= Name
then
684 Result
:= g_GUIWindows
[i
];
688 Assert(Result
<> nil, 'GUI_Window "'+Name
+'" not found');
691 procedure g_GUI_ShowWindow(Name
: string);
695 if g_GUIWindows
= nil then
698 for i
:= 0 to High(g_GUIWindows
) do
699 if g_GUIWindows
[i
].FName
= Name
then
701 g_GUIWindows
[i
].FPrevWindow
:= g_ActiveWindow
;
702 g_ActiveWindow
:= g_GUIWindows
[i
];
704 if g_ActiveWindow
.MainWindow
then
705 g_ActiveWindow
.FPrevWindow
:= nil;
707 if g_ActiveWindow
.FDefControl
<> '' then
708 g_ActiveWindow
.SetActive(g_ActiveWindow
.GetControl(g_ActiveWindow
.FDefControl
))
710 g_ActiveWindow
.SetActive(nil);
712 if @g_ActiveWindow
.FOnShowEvent
<> nil then
713 g_ActiveWindow
.FOnShowEvent();
719 procedure g_GUI_HideWindow(PlaySound
: Boolean = True);
721 if g_ActiveWindow
<> nil then
723 if @g_ActiveWindow
.OnClose
<> nil then
724 g_ActiveWindow
.OnClose();
725 g_ActiveWindow
:= g_ActiveWindow
.FPrevWindow
;
727 g_Sound_PlayEx(WINDOW_CLOSESOUND
);
731 procedure g_GUI_SaveMenuPos();
736 SetLength(Saved_Windows
, 0);
737 win
:= g_ActiveWindow
;
741 len
:= Length(Saved_Windows
);
742 SetLength(Saved_Windows
, len
+ 1);
744 Saved_Windows
[len
] := win
.Name
;
746 if win
.MainWindow
then
749 win
:= win
.FPrevWindow
;
753 procedure g_GUI_LoadMenuPos();
755 i
, j
, k
, len
: Integer;
758 g_ActiveWindow
:= nil;
759 len
:= Length(Saved_Windows
);
764 // Îêíî ñ ãëàâíûì ìåíþ:
765 g_GUI_ShowWindow(Saved_Windows
[len
-1]);
767 // Íå ïåðåêëþ÷èëîñü (èëè íåêóäà äàëüøå):
768 if (len
= 1) or (g_ActiveWindow
= nil) then
771 // Èùåì êíîïêè â îñòàëüíûõ îêíàõ:
772 for k
:= len
-1 downto 1 do
776 for i
:= 0 to Length(g_ActiveWindow
.Childs
)-1 do
778 if g_ActiveWindow
.Childs
[i
] is TGUIMainMenu
then
779 begin // GUI_MainMenu
780 with TGUIMainMenu(g_ActiveWindow
.Childs
[i
]) do
781 for j
:= 0 to Length(FButtons
)-1 do
782 if FButtons
[j
].ShowWindow
= Saved_Windows
[k
-1] then
784 FButtons
[j
].Click(True);
790 if g_ActiveWindow
.Childs
[i
] is TGUIMenu
then
791 with TGUIMenu(g_ActiveWindow
.Childs
[i
]) do
792 for j
:= 0 to Length(FItems
)-1 do
793 if FItems
[j
].ControlType
= TGUITextButton
then
794 if TGUITextButton(FItems
[j
].Control
).ShowWindow
= Saved_Windows
[k
-1] then
796 TGUITextButton(FItems
[j
].Control
).Click(True);
807 (g_ActiveWindow
.Name
= Saved_Windows
[k
]) then
812 procedure DrawBox(X
, Y
: Integer; Width
, Height
: Word);
814 e_Draw(Box
[0], X
, Y
, 0, False, False);
815 e_DrawFill(Box
[1], X
+4, Y
, Width
*4, 1, 0, False, False);
816 e_Draw(Box
[2], X
+4+Width
*16, Y
, 0, False, False);
817 e_DrawFill(Box
[3], X
, Y
+4, 1, Height
*4, 0, False, False);
818 e_DrawFill(Box
[4], X
+4, Y
+4, Width
, Height
, 0, False, False);
819 e_DrawFill(Box
[5], X
+4+Width
*16, Y
+4, 1, Height
*4, 0, False, False);
820 e_Draw(Box
[6], X
, Y
+4+Height
*16, 0, False, False);
821 e_DrawFill(Box
[7], X
+4, Y
+4+Height
*16, Width
*4, 1, 0, False, False);
822 e_Draw(Box
[8], X
+4+Width
*16, Y
+4+Height
*16, 0, False, False);
825 procedure DrawScroll(X
, Y
: Integer; Height
: Word; Up
, Down
: Boolean);
829 if Height
< 3 then Exit
;
832 g_Texture_Get(BSCROLL_UPA
, ID
)
834 g_Texture_Get(BSCROLL_UPU
, ID
);
835 e_Draw(ID
, X
, Y
, 0, False, False);
838 g_Texture_Get(BSCROLL_DOWNA
, ID
)
840 g_Texture_Get(BSCROLL_DOWNU
, ID
);
841 e_Draw(ID
, X
, Y
+(Height
-1)*16, 0, False, False);
843 g_Texture_Get(BSCROLL_MIDDLE
, ID
);
844 e_DrawFill(ID
, X
, Y
+16, 1, Height
-2, 0, False, False);
849 constructor TGUIWindow
.Create(Name
: string);
852 FActiveControl
:= nil;
856 FOnCloseEvent
:= nil;
860 destructor TGUIWindow
.Destroy
;
867 for i
:= 0 to High(Childs
) do
871 function TGUIWindow
.AddChild(Child
: TGUIControl
): TGUIControl
;
873 Child
.FWindow
:= Self
;
875 SetLength(Childs
, Length(Childs
) + 1);
876 Childs
[High(Childs
)] := Child
;
881 procedure TGUIWindow
.Update
;
885 for i
:= 0 to High(Childs
) do
886 if Childs
[i
] <> nil then Childs
[i
].Update
;
889 procedure TGUIWindow
.Draw
;
895 if FBackTexture
<> '' then // Here goes code duplication from g_game.pas:DrawMenuBackground()
896 if g_Texture_Get(FBackTexture
, ID
) then
899 e_GetTextureSize(ID
, @tw
, @th
);
901 tw
:= round(tw
* 1.333 * (gScreenHeight
/ th
))
903 tw
:= trunc(tw
* (gScreenHeight
/ th
));
904 e_DrawSize(ID
, (gScreenWidth
- tw
) div 2, 0, 0, False, False, tw
, gScreenHeight
);
907 e_Clear(0.5, 0.5, 0.5);
910 if FName
= 'AuthorsMenu' then
911 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
913 for i
:= 0 to High(Childs
) do
914 if Childs
[i
] <> nil then Childs
[i
].Draw
;
917 procedure TGUIWindow
.OnMessage(var Msg
: TMessage
);
919 if FActiveControl
<> nil then FActiveControl
.OnMessage(Msg
);
920 if @FOnKeyDown
<> nil then FOnKeyDown(Msg
.wParam
);
921 if @FOnKeyDownEx
<> nil then FOnKeyDownEx(self
, Msg
.wParam
);
923 if Msg
.Msg
= WM_KEYDOWN
then
935 procedure TGUIWindow
.SetActive(Control
: TGUIControl
);
937 FActiveControl
:= Control
;
940 function TGUIWindow
.GetControl(Name
: String): TGUIControl
;
946 if Childs
<> nil then
947 for i
:= 0 to High(Childs
) do
948 if Childs
[i
] <> nil then
949 if LowerCase(Childs
[i
].FName
) = LowerCase(Name
) then
955 Assert(Result
<> nil, 'Window Control "'+Name
+'" not Found!');
960 constructor TGUIControl
.Create();
966 FRightAlign
:= false;
970 procedure TGUIControl
.OnMessage(var Msg
: TMessage
);
976 procedure TGUIControl
.Update();
980 procedure TGUIControl
.Draw();
984 function TGUIControl
.WantActivationKey (key
: LongInt): Boolean;
989 function TGUIControl
.GetWidth(): Integer;
994 function TGUIControl
.GetHeight(): Integer;
1001 procedure TGUITextButton
.Click(Silent
: Boolean = False);
1003 if (FSound
<> '') and (not Silent
) then g_Sound_PlayEx(FSound
);
1005 if @Proc
<> nil then Proc();
1006 if @ProcEx
<> nil then ProcEx(self
);
1008 if FShowWindow
<> '' then g_GUI_ShowWindow(FShowWindow
);
1011 constructor TGUITextButton
.Create(aProc
: Pointer; FontID
: DWORD
; Text: string);
1018 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
1023 destructor TGUITextButton
.Destroy
;
1029 procedure TGUITextButton
.Draw
;
1031 FFont
.Draw(FX
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
)
1034 function TGUITextButton
.GetHeight
: Integer;
1038 FFont
.GetTextSize(FText
, w
, h
);
1042 function TGUITextButton
.GetWidth
: Integer;
1046 FFont
.GetTextSize(FText
, w
, h
);
1050 procedure TGUITextButton
.OnMessage(var Msg
: TMessage
);
1052 if not FEnabled
then Exit
;
1059 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
: Click();
1064 procedure TGUITextButton
.Update
;
1071 constructor TFont
.Create(FontID
: DWORD
; FontType
: TFontType
);
1076 FFontType
:= FontType
;
1079 destructor TFont
.Destroy
;
1085 procedure TFont
.Draw(X
, Y
: Integer; Text: string; R
, G
, B
: Byte);
1087 if FFontType
= TFontType
.Character
then e_CharFont_PrintEx(ID
, X
, Y
, Text, _RGB(R
, G
, B
), FScale
)
1088 else e_TextureFontPrintEx(X
, Y
, Text, ID
, R
, G
, B
, FScale
);
1091 procedure TFont
.GetTextSize(Text: string; var w
, h
: Word);
1095 if FFontType
= TFontType
.Character
then e_CharFont_GetSize(ID
, Text, w
, h
)
1098 e_TextureFontGetSize(ID
, cw
, ch
);
1099 w
:= cw
*Length(Text);
1103 w
:= Round(w
*FScale
);
1104 h
:= Round(h
*FScale
);
1109 function TGUIMainMenu
.AddButton(fProc
: Pointer; Caption
: string; ShowWindow
: string = ''): TGUITextButton
;
1117 SetLength(FButtons
, Length(FButtons
)+1);
1118 FButtons
[High(FButtons
)] := TGUITextButton
.Create(fProc
, FFontID
, Caption
);
1119 FButtons
[High(FButtons
)].ShowWindow
:= ShowWindow
;
1120 with FButtons
[High(FButtons
)] do
1122 if (fProc
<> nil) or (ShowWindow
<> '') then FColor
:= MAINMENU_ITEMS_COLOR
1123 else FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
1124 FSound
:= MAINMENU_CLICKSOUND
;
1127 _x
:= gScreenWidth
div 2;
1129 for a
:= 0 to High(FButtons
) do
1130 if FButtons
[a
] <> nil then
1131 _x
:= Min(_x
, (gScreenWidth
div 2)-(FButtons
[a
].GetWidth
div 2));
1133 if FLogo
<> 0 then e_GetTextureSize(FLogo
, nil, @lh
);
1134 hh
:= FButtons
[High(FButtons
)].GetHeight
;
1136 if FLogo
<> 0 then h
:= lh
+ hh
* (1 + Length(FButtons
)) + MAINMENU_SPACE
* (Length(FButtons
) - 1)
1137 else h
:= hh
* (2 + Length(FButtons
)) + MAINMENU_SPACE
* (Length(FButtons
) - 1);
1138 h
:= (gScreenHeight
div 2) - (h
div 2);
1140 if FHeader
<> nil then with FHeader
do
1146 if FLogo
<> 0 then Inc(h
, lh
)
1149 for a
:= 0 to High(FButtons
) do
1151 if FButtons
[a
] <> nil then
1158 Inc(h
, hh
+MAINMENU_SPACE
);
1161 Result
:= FButtons
[High(FButtons
)];
1164 procedure TGUIMainMenu
.AddSpace
;
1166 SetLength(FButtons
, Length(FButtons
)+1);
1167 FButtons
[High(FButtons
)] := nil;
1170 constructor TGUIMainMenu
.Create(FontID
: DWORD
; Logo
, Header
: string);
1176 FCounter
:= MAINMENU_MARKERDELAY
;
1178 g_Texture_Get(MAINMENU_MARKER1
, FMarkerID1
);
1179 g_Texture_Get(MAINMENU_MARKER2
, FMarkerID2
);
1181 if not g_Texture_Get(Logo
, FLogo
) then
1183 FHeader
:= TGUILabel
.Create(Header
, FFontID
);
1186 FColor
:= MAINMENU_HEADER_COLOR
;
1187 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1188 FY
:= (gScreenHeight
div 2)-(GetHeight
div 2);
1193 destructor TGUIMainMenu
.Destroy
;
1197 if FButtons
<> nil then
1198 for a
:= 0 to High(FButtons
) do
1206 procedure TGUIMainMenu
.Draw
;
1214 if FHeader
<> nil then FHeader
.Draw
1216 e_GetTextureSize(FLogo
, @w
, @h
);
1217 e_Draw(FLogo
, ((gScreenWidth
div 2) - (w
div 2)), FButtons
[0].FY
- FButtons
[0].GetHeight
- h
, 0, True, False);
1220 if FButtons
<> nil then
1222 for a
:= 0 to High(FButtons
) do
1223 if FButtons
[a
] <> nil then FButtons
[a
].Draw
;
1225 if FIndex
<> -1 then
1226 e_Draw(FMarkerID1
, FButtons
[FIndex
].FX
-48, FButtons
[FIndex
].FY
, 0, True, False);
1230 procedure TGUIMainMenu
.EnableButton(aName
: string; e
: Boolean);
1234 if FButtons
= nil then Exit
;
1236 for a
:= 0 to High(FButtons
) do
1237 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= aName
) then
1239 if e
then FButtons
[a
].FColor
:= MAINMENU_ITEMS_COLOR
1240 else FButtons
[a
].FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
1241 FButtons
[a
].Enabled
:= e
;
1246 function TGUIMainMenu
.GetButton(aName
: string): TGUITextButton
;
1252 if FButtons
= nil then Exit
;
1254 for a
:= 0 to High(FButtons
) do
1255 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= aName
) then
1257 Result
:= FButtons
[a
];
1262 procedure TGUIMainMenu
.OnMessage(var Msg
: TMessage
);
1267 if not FEnabled
then Exit
;
1271 if FButtons
= nil then Exit
;
1274 for a
:= 0 to High(FButtons
) do
1275 if FButtons
[a
] <> nil then
1281 if not ok
then Exit
;
1286 IK_UP
, IK_KPUP
, VK_UP
, JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1290 if FIndex
< 0 then FIndex
:= High(FButtons
);
1291 until FButtons
[FIndex
] <> nil;
1293 g_Sound_PlayEx(MENU_CHANGESOUND
);
1295 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1299 if FIndex
> High(FButtons
) then FIndex
:= 0;
1300 until FButtons
[FIndex
] <> nil;
1302 g_Sound_PlayEx(MENU_CHANGESOUND
);
1304 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
;
1309 procedure TGUIMainMenu
.Update
;
1315 if FCounter
= 0 then
1318 FMarkerID1
:= FMarkerID2
;
1321 FCounter
:= MAINMENU_MARKERDELAY
;
1322 end else Dec(FCounter
);
1327 constructor TGUILabel
.Create(Text: string; FontID
: DWORD
);
1331 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
1335 FOnClickEvent
:= nil;
1338 procedure TGUILabel
.Draw
;
1344 FFont
.GetTextSize(FText
, w
, h
);
1345 FFont
.Draw(FX
+FMaxWidth
-w
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
);
1349 FFont
.Draw(FX
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
);
1353 function TGUILabel
.GetHeight
: Integer;
1357 FFont
.GetTextSize(FText
, w
, h
);
1361 function TGUILabel
.GetWidth
: Integer;
1365 if FFixedLen
= 0 then
1366 FFont
.GetTextSize(FText
, w
, h
)
1368 w
:= e_CharFont_GetMaxWidth(FFont
.ID
)*FFixedLen
;
1372 procedure TGUILabel
.OnMessage(var Msg
: TMessage
);
1374 if not FEnabled
then Exit
;
1381 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
: if @FOnClickEvent
<> nil then FOnClickEvent();
1388 function TGUIMenu
.AddButton(Proc
: Pointer; fText
: string; _ShowWindow
: string = ''): TGUITextButton
;
1395 Control
:= TGUITextButton
.Create(Proc
, FFontID
, fText
);
1396 with Control
as TGUITextButton
do
1398 ShowWindow
:= _ShowWindow
;
1399 FColor
:= MENU_ITEMSCTRL_COLOR
;
1403 ControlType
:= TGUITextButton
;
1405 Result
:= (Control
as TGUITextButton
);
1408 if FIndex
= -1 then FIndex
:= i
;
1413 procedure TGUIMenu
.AddLine(fText
: string);
1420 Text := TGUILabel
.Create(fText
, FFontID
);
1423 FColor
:= MENU_ITEMSTEXT_COLOR
;
1432 procedure TGUIMenu
.AddText(fText
: string; MaxWidth
: Word);
1437 l
:= GetLines(fText
, FFontID
, MaxWidth
);
1439 if l
= nil then Exit
;
1441 for a
:= 0 to High(l
) do
1446 Text := TGUILabel
.Create(l
[a
], FFontID
);
1449 with Text do begin FColor
:= _RGB(255, 0, 0); end;
1453 with Text do begin FColor
:= MENU_ITEMSTEXT_COLOR
; end;
1463 procedure TGUIMenu
.AddSpace
;
1477 constructor TGUIMenu
.Create(HeaderFont
, ItemsFont
: DWORD
; Header
: string);
1483 FFontID
:= ItemsFont
;
1484 FCounter
:= MENU_MARKERDELAY
;
1488 FHeader
:= TGUILabel
.Create(Header
, HeaderFont
);
1491 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1493 FColor
:= MAINMENU_HEADER_COLOR
;
1497 destructor TGUIMenu
.Destroy
;
1501 if FItems
<> nil then
1502 for a
:= 0 to High(FItems
) do
1516 procedure TGUIMenu
.Draw
;
1518 a
, locx
, locy
: Integer;
1522 if FHeader
<> nil then FHeader
.Draw
;
1524 if FItems
<> nil then
1525 for a
:= 0 to High(FItems
) do
1527 if FItems
[a
].Text <> nil then FItems
[a
].Text.Draw
;
1528 if FItems
[a
].Control
<> nil then FItems
[a
].Control
.Draw
;
1531 if (FIndex
<> -1) and (FCounter
> MENU_MARKERDELAY
div 2) then
1536 if FItems
[FIndex
].Text <> nil then
1538 locx
:= FItems
[FIndex
].Text.FX
;
1539 locy
:= FItems
[FIndex
].Text.FY
;
1541 if FItems
[FIndex
].Text.RightAlign
then
1543 locx
:= locx
+FItems
[FIndex
].Text.FMaxWidth
-FItems
[FIndex
].Text.GetWidth
;
1546 else if FItems
[FIndex
].Control
<> nil then
1548 locx
:= FItems
[FIndex
].Control
.FX
;
1549 locy
:= FItems
[FIndex
].Control
.FY
;
1552 locx
:= locx
-e_CharFont_GetMaxWidth(FFontID
);
1554 e_CharFont_PrintEx(FFontID
, locx
, locy
, #16, _RGB(255, 0, 0));
1558 function TGUIMenu
.GetControl(aName
: String): TGUIControl
;
1564 if FItems
<> nil then
1565 for a
:= 0 to High(FItems
) do
1566 if FItems
[a
].Control
<> nil then
1567 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(aName
) then
1569 Result
:= FItems
[a
].Control
;
1573 Assert(Result
<> nil, 'GUI control "'+aName
+'" not found!');
1576 function TGUIMenu
.GetControlsText(aName
: String): TGUILabel
;
1582 if FItems
<> nil then
1583 for a
:= 0 to High(FItems
) do
1584 if FItems
[a
].Control
<> nil then
1585 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(aName
) then
1587 Result
:= FItems
[a
].Text;
1591 Assert(Result
<> nil, 'GUI control''s text "'+aName
+'" not found!');
1594 function TGUIMenu
.NewItem
: Integer;
1596 SetLength(FItems
, Length(FItems
)+1);
1597 Result
:= High(FItems
);
1600 procedure TGUIMenu
.OnMessage(var Msg
: TMessage
);
1605 if not FEnabled
then Exit
;
1609 if FItems
= nil then Exit
;
1612 for a
:= 0 to High(FItems
) do
1613 if FItems
[a
].Control
<> nil then
1619 if not ok
then Exit
;
1621 if (Msg
.Msg
= WM_KEYDOWN
) and (FIndex
<> -1) and (FItems
[FIndex
].Control
<> nil) and
1622 (FItems
[FIndex
].Control
.WantActivationKey(Msg
.wParam
)) then
1624 FItems
[FIndex
].Control
.OnMessage(Msg
);
1625 g_Sound_PlayEx(MENU_CLICKSOUND
);
1633 IK_UP
, IK_KPUP
, VK_UP
,JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1638 if c
> Length(FItems
) then
1645 if FIndex
< 0 then FIndex
:= High(FItems
);
1646 until (FItems
[FIndex
].Control
<> nil) and
1647 (FItems
[FIndex
].Control
.Enabled
);
1651 g_Sound_PlayEx(MENU_CHANGESOUND
);
1654 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1659 if c
> Length(FItems
) then
1666 if FIndex
> High(FItems
) then FIndex
:= 0;
1667 until (FItems
[FIndex
].Control
<> nil) and
1668 (FItems
[FIndex
].Control
.Enabled
);
1672 g_Sound_PlayEx(MENU_CHANGESOUND
);
1675 IK_LEFT
, IK_RIGHT
, IK_KPLEFT
, IK_KPRIGHT
, VK_LEFT
, VK_RIGHT
,
1676 JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
,
1677 JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
1679 if FIndex
<> -1 then
1680 if FItems
[FIndex
].Control
<> nil then
1681 FItems
[FIndex
].Control
.OnMessage(Msg
);
1683 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
1685 if FIndex
<> -1 then
1687 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1689 g_Sound_PlayEx(MENU_CLICKSOUND
);
1693 if FYesNo
and (length(FItems
) > 1) then
1695 Msg
.wParam
:= IK_RETURN
; // to register keypress
1696 FIndex
:= High(FItems
)-1;
1697 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1700 if FYesNo
and (length(FItems
) > 1) then
1702 Msg
.wParam
:= IK_RETURN
; // to register keypress
1703 FIndex
:= High(FItems
);
1704 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1711 procedure TGUIMenu
.ReAlign();
1713 a
, tx
, cx
, w
, h
: Integer;
1714 cww
: array of Integer; // cached widths
1717 if FItems
= nil then Exit
;
1719 SetLength(cww
, length(FItems
));
1721 for a
:= 0 to High(FItems
) do
1723 if FItems
[a
].Text <> nil then
1725 cww
[a
] := FItems
[a
].Text.GetWidth
;
1726 if maxcww
< cww
[a
] then maxcww
:= cww
[a
];
1737 for a
:= 0 to High(FItems
) do
1740 if FItems
[a
].Text <> nil then w
:= FItems
[a
].Text.GetWidth
;
1741 if FItems
[a
].Control
<> nil then
1744 if FItems
[a
].ControlType
= TGUILabel
then w
:= w
+(FItems
[a
].Control
as TGUILabel
).GetWidth
1745 else if FItems
[a
].ControlType
= TGUITextButton
then w
:= w
+(FItems
[a
].Control
as TGUITextButton
).GetWidth
1746 else if FItems
[a
].ControlType
= TGUIScroll
then w
:= w
+(FItems
[a
].Control
as TGUIScroll
).GetWidth
1747 else if FItems
[a
].ControlType
= TGUISwitch
then w
:= w
+(FItems
[a
].Control
as TGUISwitch
).GetWidth
1748 else if FItems
[a
].ControlType
= TGUIEdit
then w
:= w
+(FItems
[a
].Control
as TGUIEdit
).GetWidth
1749 else if FItems
[a
].ControlType
= TGUIKeyRead
then w
:= w
+(FItems
[a
].Control
as TGUIKeyRead
).GetWidth
1750 else if FItems
[a
].ControlType
= TGUIKeyRead2
then w
:= w
+(FItems
[a
].Control
as TGUIKeyRead2
).GetWidth
1751 else if FItems
[a
].ControlType
= TGUIListBox
then w
:= w
+(FItems
[a
].Control
as TGUIListBox
).GetWidth
1752 else if FItems
[a
].ControlType
= TGUIFileListBox
then w
:= w
+(FItems
[a
].Control
as TGUIFileListBox
).GetWidth
1753 else if FItems
[a
].ControlType
= TGUIMemo
then w
:= w
+(FItems
[a
].Control
as TGUIMemo
).GetWidth
;
1755 tx
:= Min(tx
, (gScreenWidth
div 2)-(w
div 2));
1760 for a
:= 0 to High(FItems
) do
1764 if (Text <> nil) and (Control
= nil) then Continue
;
1766 if Text <> nil then w
:= tx
+Text.GetWidth
;
1767 if w
> cx
then cx
:= w
;
1771 cx
:= cx
+MENU_HSPACE
;
1773 h
:= FHeader
.GetHeight
*2+MENU_VSPACE
*(Length(FItems
)-1);
1775 for a
:= 0 to High(FItems
) do
1779 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then
1780 h
:= h
+(FItems
[a
].Control
as TGUIListBox
).GetHeight()
1782 h
:= h
+e_CharFont_GetMaxHeight(FFontID
);
1786 h
:= (gScreenHeight
div 2)-(h
div 2);
1790 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1793 Inc(h
, GetHeight
*2);
1796 for a
:= 0 to High(FItems
) do
1808 if Text.RightAlign
and (length(cww
) > a
) then
1810 //Text.FX := Text.FX+maxcww;
1811 Text.FMaxWidth
:= maxcww
;
1815 if Control
<> nil then
1832 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then Inc(h
, (Control
as TGUIListBox
).GetHeight
+MENU_VSPACE
)
1833 else if ControlType
= TGUIMemo
then Inc(h
, (Control
as TGUIMemo
).GetHeight
+MENU_VSPACE
)
1834 else Inc(h
, e_CharFont_GetMaxHeight(FFontID
)+MENU_VSPACE
);
1838 // another ugly hack
1839 if FYesNo
and (length(FItems
) > 1) then
1842 for a
:= High(FItems
)-1 to High(FItems
) do
1844 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1846 cx
:= (FItems
[a
].Control
as TGUITextButton
).GetWidth
;
1847 if cx
> w
then w
:= cx
;
1852 for a
:= High(FItems
)-1 to High(FItems
) do
1854 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1856 FItems
[a
].Control
.FX
:= (gScreenWidth
-w
) div 2;
1863 function TGUIMenu
.AddScroll(fText
: string): TGUIScroll
;
1870 Control
:= TGUIScroll
.Create();
1872 Text := TGUILabel
.Create(fText
, FFontID
);
1875 FColor
:= MENU_ITEMSTEXT_COLOR
;
1878 ControlType
:= TGUIScroll
;
1880 Result
:= (Control
as TGUIScroll
);
1883 if FIndex
= -1 then FIndex
:= i
;
1888 function TGUIMenu
.AddSwitch(fText
: string): TGUISwitch
;
1895 Control
:= TGUISwitch
.Create(FFontID
);
1896 (Control
as TGUISwitch
).FColor
:= MENU_ITEMSCTRL_COLOR
;
1898 Text := TGUILabel
.Create(fText
, FFontID
);
1901 FColor
:= MENU_ITEMSTEXT_COLOR
;
1904 ControlType
:= TGUISwitch
;
1906 Result
:= (Control
as TGUISwitch
);
1909 if FIndex
= -1 then FIndex
:= i
;
1914 function TGUIMenu
.AddEdit(fText
: string): TGUIEdit
;
1921 Control
:= TGUIEdit
.Create(FFontID
);
1922 with Control
as TGUIEdit
do
1924 FWindow
:= Self
.FWindow
;
1925 FColor
:= MENU_ITEMSCTRL_COLOR
;
1928 if fText
= '' then Text := nil else
1930 Text := TGUILabel
.Create(fText
, FFontID
);
1931 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1934 ControlType
:= TGUIEdit
;
1936 Result
:= (Control
as TGUIEdit
);
1939 if FIndex
= -1 then FIndex
:= i
;
1944 procedure TGUIMenu
.Update
;
1950 if FCounter
= 0 then FCounter
:= MENU_MARKERDELAY
else Dec(FCounter
);
1952 if FItems
<> nil then
1953 for a
:= 0 to High(FItems
) do
1954 if FItems
[a
].Control
<> nil then
1955 (FItems
[a
].Control
as FItems
[a
].ControlType
).Update
;
1958 function TGUIMenu
.AddKeyRead(fText
: string): TGUIKeyRead
;
1965 Control
:= TGUIKeyRead
.Create(FFontID
);
1966 with Control
as TGUIKeyRead
do
1968 FWindow
:= Self
.FWindow
;
1969 FColor
:= MENU_ITEMSCTRL_COLOR
;
1972 Text := TGUILabel
.Create(fText
, FFontID
);
1975 FColor
:= MENU_ITEMSTEXT_COLOR
;
1978 ControlType
:= TGUIKeyRead
;
1980 Result
:= (Control
as TGUIKeyRead
);
1983 if FIndex
= -1 then FIndex
:= i
;
1988 function TGUIMenu
.AddKeyRead2(fText
: string): TGUIKeyRead2
;
1995 Control
:= TGUIKeyRead2
.Create(FFontID
);
1996 with Control
as TGUIKeyRead2
do
1998 FWindow
:= Self
.FWindow
;
1999 FColor
:= MENU_ITEMSCTRL_COLOR
;
2002 Text := TGUILabel
.Create(fText
, FFontID
);
2005 FColor
:= MENU_ITEMSCTRL_COLOR
; //MENU_ITEMSTEXT_COLOR;
2009 ControlType
:= TGUIKeyRead2
;
2011 Result
:= (Control
as TGUIKeyRead2
);
2014 if FIndex
= -1 then FIndex
:= i
;
2019 function TGUIMenu
.AddList(fText
: string; Width
, Height
: Word): TGUIListBox
;
2026 Control
:= TGUIListBox
.Create(FFontID
, Width
, Height
);
2027 with Control
as TGUIListBox
do
2029 FWindow
:= Self
.FWindow
;
2030 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
2031 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
2034 Text := TGUILabel
.Create(fText
, FFontID
);
2037 FColor
:= MENU_ITEMSTEXT_COLOR
;
2040 ControlType
:= TGUIListBox
;
2042 Result
:= (Control
as TGUIListBox
);
2045 if FIndex
= -1 then FIndex
:= i
;
2050 function TGUIMenu
.AddFileList(fText
: string; Width
, Height
: Word): TGUIFileListBox
;
2057 Control
:= TGUIFileListBox
.Create(FFontID
, Width
, Height
);
2058 with Control
as TGUIFileListBox
do
2060 FWindow
:= Self
.FWindow
;
2061 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
2062 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
2065 if fText
= '' then Text := nil else
2067 Text := TGUILabel
.Create(fText
, FFontID
);
2068 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
2071 ControlType
:= TGUIFileListBox
;
2073 Result
:= (Control
as TGUIFileListBox
);
2076 if FIndex
= -1 then FIndex
:= i
;
2081 function TGUIMenu
.AddLabel(fText
: string): TGUILabel
;
2088 Control
:= TGUILabel
.Create('', FFontID
);
2089 with Control
as TGUILabel
do
2091 FWindow
:= Self
.FWindow
;
2092 FColor
:= MENU_ITEMSCTRL_COLOR
;
2095 Text := TGUILabel
.Create(fText
, FFontID
);
2098 FColor
:= MENU_ITEMSTEXT_COLOR
;
2101 ControlType
:= TGUILabel
;
2103 Result
:= (Control
as TGUILabel
);
2106 if FIndex
= -1 then FIndex
:= i
;
2111 function TGUIMenu
.AddMemo(fText
: string; Width
, Height
: Word): TGUIMemo
;
2118 Control
:= TGUIMemo
.Create(FFontID
, Width
, Height
);
2119 with Control
as TGUIMemo
do
2121 FWindow
:= Self
.FWindow
;
2122 FColor
:= MENU_ITEMSTEXT_COLOR
;
2125 if fText
= '' then Text := nil else
2127 Text := TGUILabel
.Create(fText
, FFontID
);
2128 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
2131 ControlType
:= TGUIMemo
;
2133 Result
:= (Control
as TGUIMemo
);
2136 if FIndex
= -1 then FIndex
:= i
;
2141 procedure TGUIMenu
.UpdateIndex();
2149 if (FIndex
< 0) or (FIndex
> High(FItems
)) then
2155 if FItems
[FIndex
].Control
.Enabled
then
2164 constructor TGUIScroll
.Create
;
2169 FOnChangeEvent
:= nil;
2171 g_Texture_Get(SCROLL_LEFT
, FLeftID
);
2172 g_Texture_Get(SCROLL_RIGHT
, FRightID
);
2173 g_Texture_Get(SCROLL_MIDDLE
, FMiddleID
);
2174 g_Texture_Get(SCROLL_MARKER
, FMarkerID
);
2177 procedure TGUIScroll
.Draw
;
2183 e_Draw(FLeftID
, FX
, FY
, 0, True, False);
2184 e_Draw(FRightID
, FX
+8+(FMax
+1)*8, FY
, 0, True, False);
2186 for a
:= 0 to FMax
do
2187 e_Draw(FMiddleID
, FX
+8+a
*8, FY
, 0, True, False);
2189 e_Draw(FMarkerID
, FX
+8+FValue
*8, FY
, 0, True, False);
2192 procedure TGUIScroll
.FSetValue(a
: Integer);
2194 if a
> FMax
then FValue
:= FMax
else FValue
:= a
;
2197 function TGUIScroll
.GetWidth
: Integer;
2199 Result
:= 16+(FMax
+1)*8;
2202 procedure TGUIScroll
.OnMessage(var Msg
: TMessage
);
2204 if not FEnabled
then Exit
;
2212 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2216 g_Sound_PlayEx(SCROLL_SUBSOUND
);
2217 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2219 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2220 if FValue
< FMax
then
2223 g_Sound_PlayEx(SCROLL_ADDSOUND
);
2224 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2231 procedure TGUIScroll
.Update
;
2239 procedure TGUISwitch
.AddItem(Item
: string);
2241 SetLength(FItems
, Length(FItems
)+1);
2242 FItems
[High(FItems
)] := Item
;
2244 if FIndex
= -1 then FIndex
:= 0;
2247 constructor TGUISwitch
.Create(FontID
: DWORD
);
2253 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2256 procedure TGUISwitch
.Draw
;
2260 FFont
.Draw(FX
, FY
, FItems
[FIndex
], FColor
.R
, FColor
.G
, FColor
.B
);
2263 function TGUISwitch
.GetText
: string;
2265 if FIndex
<> -1 then Result
:= FItems
[FIndex
]
2269 function TGUISwitch
.GetWidth
: Integer;
2276 if FItems
= nil then Exit
;
2278 for a
:= 0 to High(FItems
) do
2280 FFont
.GetTextSize(FItems
[a
], w
, h
);
2281 if w
> Result
then Result
:= w
;
2285 procedure TGUISwitch
.OnMessage(var Msg
: TMessage
);
2287 if not FEnabled
then Exit
;
2291 if FItems
= nil then Exit
;
2296 IK_RETURN
, IK_RIGHT
, IK_KPRETURN
, IK_KPRIGHT
, VK_FIRE
, VK_OPEN
, VK_RIGHT
,
2297 JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
,
2298 JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2300 if FIndex
< High(FItems
) then
2305 g_Sound_PlayEx(SCROLL_ADDSOUND
);
2307 if @FOnChangeEvent
<> nil then
2308 FOnChangeEvent(Self
);
2311 IK_LEFT
, IK_KPLEFT
, VK_LEFT
,
2312 JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2317 FIndex
:= High(FItems
);
2319 g_Sound_PlayEx(SCROLL_SUBSOUND
);
2321 if @FOnChangeEvent
<> nil then
2322 FOnChangeEvent(Self
);
2328 procedure TGUISwitch
.Update
;
2336 constructor TGUIEdit
.Create(FontID
: DWORD
);
2340 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2346 g_Texture_Get(EDIT_LEFT
, FLeftID
);
2347 g_Texture_Get(EDIT_RIGHT
, FRightID
);
2348 g_Texture_Get(EDIT_MIDDLE
, FMiddleID
);
2351 procedure TGUIEdit
.Draw
;
2358 e_Draw(FLeftID
, FX
, FY
, 0, True, False);
2359 e_Draw(FRightID
, FX
+8+FWidth
*16, FY
, 0, True, False);
2361 for c
:= 0 to FWidth
-1 do
2362 e_Draw(FMiddleID
, FX
+8+c
*16, FY
, 0, True, False);
2367 if FInvalid
and (FWindow
.FActiveControl
<> self
) then begin r
:= 128; g
:= 128; b
:= 128; end;
2368 FFont
.Draw(FX
+8, FY
, FText
, r
, g
, b
);
2370 if (FWindow
.FActiveControl
= self
) then
2372 FFont
.GetTextSize(Copy(FText
, 1, FCaretPos
), w
, h
);
2373 h
:= e_CharFont_GetMaxHeight(FFont
.ID
);
2374 e_DrawLine(2, FX
+8+w
, FY
+h
-3, FX
+8+w
+EDIT_CURSORLEN
, FY
+h
-3,
2375 EDIT_CURSORCOLOR
.R
, EDIT_CURSORCOLOR
.G
, EDIT_CURSORCOLOR
.B
);
2379 function TGUIEdit
.GetWidth
: Integer;
2381 Result
:= 16+FWidth
*16;
2384 procedure TGUIEdit
.OnMessage(var Msg
: TMessage
);
2386 if not FEnabled
then Exit
;
2395 if (wParam
in [48..57]) and (Chr(wParam
) <> '`') then
2396 if Length(Text) < FMaxLength
then
2398 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2404 if (wParam
in [32..255]) and (Chr(wParam
) <> '`') then
2405 if Length(Text) < FMaxLength
then
2407 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2415 Delete(FText
, FCaretPos
, 1);
2416 if FCaretPos
> 0 then Dec(FCaretPos
);
2418 IK_DELETE
: Delete(FText
, FCaretPos
+ 1, 1);
2419 IK_END
, IK_KPEND
: FCaretPos
:= Length(FText
);
2420 IK_HOME
, IK_KPHOME
: FCaretPos
:= 0;
2421 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
: if FCaretPos
> 0 then Dec(FCaretPos
);
2422 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
: if FCaretPos
< Length(FText
) then Inc(FCaretPos
);
2423 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2426 if FActiveControl
<> Self
then
2429 if @FOnEnterEvent
<> nil then FOnEnterEvent(Self
);
2433 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
2434 else SetActive(nil);
2435 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2441 g_GUIGrabInput
:= (@FOnEnterEvent
= nil) and (FWindow
.FActiveControl
= Self
);
2442 g_Touch_ShowKeyboard(g_GUIGrabInput
)
2445 procedure TGUIEdit
.SetText(Text: string);
2447 if Length(Text) > FMaxLength
then SetLength(Text, FMaxLength
);
2449 FCaretPos
:= Length(FText
);
2452 procedure TGUIEdit
.Update
;
2459 constructor TGUIKeyRead
.Create(FontID
: DWORD
);
2465 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2468 procedure TGUIKeyRead
.Draw
;
2472 FFont
.Draw(FX
, FY
, IfThen(FIsQuery
, KEYREAD_QUERY
, IfThen(FKey
<> 0, e_KeyNames
[FKey
], KEYREAD_CLEAR
)),
2473 FColor
.R
, FColor
.G
, FColor
.B
);
2476 function TGUIKeyRead
.GetWidth
: Integer;
2483 for a
:= 0 to 255 do
2485 FFont
.GetTextSize(e_KeyNames
[a
], w
, h
);
2486 Result
:= Max(Result
, w
);
2489 FFont
.GetTextSize(KEYREAD_QUERY
, w
, h
);
2490 if w
> Result
then Result
:= w
;
2492 FFont
.GetTextSize(KEYREAD_CLEAR
, w
, h
);
2493 if w
> Result
then Result
:= w
;
2496 function TGUIKeyRead
.WantActivationKey (key
: LongInt): Boolean;
2499 (key
= IK_BACKSPACE
) or
2503 procedure TGUIKeyRead
.OnMessage(var Msg
: TMessage
);
2504 procedure actDefCtl ();
2507 if FDefControl
<> '' then
2508 SetActive(GetControl(FDefControl
))
2516 if not FEnabled
then
2522 if not FIsQuery
then
2525 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2528 if FActiveControl
<> Self
then
2532 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2545 VK_FIRSTKEY
..VK_LASTKEY
: // do not allow to bind virtual keys
2551 if (e_KeyNames
[wParam
] <> '') and not g_Console_MatchBind(wParam
, 'togglemenu') then
2559 g_GUIGrabInput
:= FIsQuery
2564 constructor TGUIKeyRead2
.Create(FontID
: DWORD
);
2577 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2579 FMaxKeyNameWdt
:= 0;
2580 for a
:= 0 to 255 do
2582 FFont
.GetTextSize(e_KeyNames
[a
], w
, h
);
2583 FMaxKeyNameWdt
:= Max(FMaxKeyNameWdt
, w
);
2586 FMaxKeyNameWdt
:= FMaxKeyNameWdt
-(FMaxKeyNameWdt
div 3);
2588 FFont
.GetTextSize(KEYREAD_QUERY
, w
, h
);
2589 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2591 FFont
.GetTextSize(KEYREAD_CLEAR
, w
, h
);
2592 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2595 procedure TGUIKeyRead2
.Draw
;
2596 procedure drawText (idx
: Integer);
2602 if idx
= 0 then kk
:= FKey0
else kk
:= FKey1
;
2604 if idx
= 0 then x
:= FX
+8 else x
:= FX
+8+FMaxKeyNameWdt
+16;
2608 if FKeyIdx
= idx
then begin r
:= 255; g
:= 255; b
:= 255; end;
2609 if FIsQuery
and (FKeyIdx
= idx
) then
2610 FFont
.Draw(x
, y
, KEYREAD_QUERY
, r
, g
, b
)
2612 FFont
.Draw(x
, y
, IfThen(kk
<> 0, e_KeyNames
[kk
], KEYREAD_CLEAR
), r
, g
, b
);
2618 //FFont.Draw(FX+8, FY, IfThen(FIsQuery and (FKeyIdx = 0), KEYREAD_QUERY, IfThen(FKey0 <> 0, e_KeyNames[FKey0], KEYREAD_CLEAR)), FColor.R, FColor.G, FColor.B);
2619 //FFont.Draw(FX+8+FMaxKeyNameWdt+16, FY, IfThen(FIsQuery and (FKeyIdx = 1), KEYREAD_QUERY, IfThen(FKey1 <> 0, e_KeyNames[FKey1], KEYREAD_CLEAR)), FColor.R, FColor.G, FColor.B);
2624 function TGUIKeyRead2
.GetWidth
: Integer;
2626 Result
:= FMaxKeyNameWdt
*2+8+8+16;
2629 function TGUIKeyRead2
.WantActivationKey (key
: LongInt): Boolean;
2632 IK_BACKSPACE
, IK_LEFT
, IK_RIGHT
, IK_KPLEFT
, IK_KPRIGHT
, VK_LEFT
, VK_RIGHT
,
2633 JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
,
2634 JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2641 procedure TGUIKeyRead2
.OnMessage(var Msg
: TMessage
);
2642 procedure actDefCtl ();
2645 if FDefControl
<> '' then
2646 SetActive(GetControl(FDefControl
))
2654 if not FEnabled
then
2660 if not FIsQuery
then
2663 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2666 if FActiveControl
<> Self
then
2670 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2672 if (FKeyIdx
= 0) then FKey0
:= 0 else FKey1
:= 0;
2675 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2680 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2693 VK_FIRSTKEY
..VK_LASTKEY
: // do not allow to bind virtual keys
2699 if (e_KeyNames
[wParam
] <> '') and not g_Console_MatchBind(wParam
, 'togglemenu') then
2701 if (FKeyIdx
= 0) then FKey0
:= wParam
else FKey1
:= wParam
;
2709 g_GUIGrabInput
:= FIsQuery
2715 constructor TGUIModelView
.Create
;
2722 destructor TGUIModelView
.Destroy
;
2729 procedure TGUIModelView
.Draw
;
2733 DrawBox(FX
, FY
, 4, 4);
2735 if FModel
<> nil then
2736 r_PlayerModel_Draw(FModel
, FX
+4, FY
+4);
2739 procedure TGUIModelView
.NextAnim();
2741 if FModel
= nil then
2744 if FModel
.Animation
< A_PAIN
then
2745 FModel
.ChangeAnimation(FModel
.Animation
+1, True)
2747 FModel
.ChangeAnimation(A_STAND
, True);
2750 procedure TGUIModelView
.NextWeapon();
2752 if FModel
= nil then
2755 if FModel
.Weapon
< WP_LAST
then
2756 FModel
.SetWeapon(FModel
.Weapon
+1)
2758 FModel
.SetWeapon(WEAPON_KASTET
);
2761 procedure TGUIModelView
.OnMessage(var Msg
: TMessage
);
2767 procedure TGUIModelView
.SetColor(Red
, Green
, Blue
: Byte);
2769 if FModel
<> nil then FModel
.SetColor(Red
, Green
, Blue
);
2772 procedure TGUIModelView
.SetModel(ModelName
: string);
2776 FModel
:= g_PlayerModel_Get(ModelName
);
2779 procedure TGUIModelView
.Update
;
2786 if FModel
<> nil then FModel
.Update
;
2791 constructor TGUIMapPreview
.Create();
2797 destructor TGUIMapPreview
.Destroy();
2803 procedure TGUIMapPreview
.Draw();
2810 DrawBox(FX
, FY
, MAPPREVIEW_WIDTH
, MAPPREVIEW_HEIGHT
);
2812 if (FMapSize
.X
<= 0) or (FMapSize
.Y
<= 0) then
2815 e_DrawFillQuad(FX
+4, FY
+4,
2816 FX
+4 + Trunc(FMapSize
.X
/ FScale
) - 1,
2817 FY
+4 + Trunc(FMapSize
.Y
/ FScale
) - 1,
2820 if FMapData
<> nil then
2821 for a
:= 0 to High(FMapData
) do
2824 if X1
> MAPPREVIEW_WIDTH
*16 then Continue
;
2825 if Y1
> MAPPREVIEW_HEIGHT
*16 then Continue
;
2827 if X2
< 0 then Continue
;
2828 if Y2
< 0 then Continue
;
2830 if X2
> MAPPREVIEW_WIDTH
*16 then X2
:= MAPPREVIEW_WIDTH
*16;
2831 if Y2
> MAPPREVIEW_HEIGHT
*16 then Y2
:= MAPPREVIEW_HEIGHT
*16;
2833 if X1
< 0 then X1
:= 0;
2834 if Y1
< 0 then Y1
:= 0;
2875 if ((X2
-X1
) > 0) and ((Y2
-Y1
) > 0) then
2876 e_DrawFillQuad(FX
+4 + X1
, FY
+4 + Y1
,
2877 FX
+4 + X2
- 1, FY
+4 + Y2
- 1, r
, g
, b
, 0);
2881 procedure TGUIMapPreview
.OnMessage(var Msg
: TMessage
);
2887 procedure TGUIMapPreview
.SetMap(Res
: string);
2892 //header: TMapHeaderRec_1;
2897 map
: TDynRecord
= nil;
2904 FileName
:= g_ExtractWadName(Res
);
2906 WAD
:= TWADFile
.Create();
2907 if not WAD
.ReadFile(FileName
) then
2913 //k8: ignores path again
2914 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
2923 map
:= g_Map_ParseMap(Data
, Len
);
2933 if (map
= nil) then exit
;
2936 panlist
:= map
.field
['panel'];
2937 //header := GetMapHeader(map);
2939 FMapSize
.X
:= map
.Width
div 16;
2940 FMapSize
.Y
:= map
.Height
div 16;
2942 rX
:= Ceil(map
.Width
/ (MAPPREVIEW_WIDTH
*256.0));
2943 rY
:= Ceil(map
.Height
/ (MAPPREVIEW_HEIGHT
*256.0));
2944 FScale
:= max(rX
, rY
);
2948 if (panlist
<> nil) then
2950 for pan
in panlist
do
2952 if (pan
.PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or
2953 PANEL_STEP
or PANEL_WATER
or
2954 PANEL_ACID1
or PANEL_ACID2
)) <> 0 then
2956 SetLength(FMapData
, Length(FMapData
)+1);
2957 with FMapData
[High(FMapData
)] do
2962 X2
:= (pan
.X
+ pan
.Width
) div 16;
2963 Y2
:= (pan
.Y
+ pan
.Height
) div 16;
2965 X1
:= Trunc(X1
/FScale
+ 0.5);
2966 Y1
:= Trunc(Y1
/FScale
+ 0.5);
2967 X2
:= Trunc(X2
/FScale
+ 0.5);
2968 Y2
:= Trunc(Y2
/FScale
+ 0.5);
2970 if (X1
<> X2
) or (Y1
<> Y2
) then
2978 PanelType
:= pan
.PanelType
;
2984 //writeln('freeing map');
2989 procedure TGUIMapPreview
.ClearMap();
2991 SetLength(FMapData
, 0);
2998 procedure TGUIMapPreview
.Update();
3004 function TGUIMapPreview
.GetScaleStr(): String;
3006 if FScale
> 0.0 then
3008 Result
:= FloatToStrF(FScale
*16.0, ffFixed
, 3, 3);
3009 while (Result
[Length(Result
)] = '0') do
3010 Delete(Result
, Length(Result
), 1);
3011 if (Result
[Length(Result
)] = ',') or (Result
[Length(Result
)] = '.') then
3012 Delete(Result
, Length(Result
), 1);
3013 Result
:= '1 : ' + Result
;
3021 procedure TGUIListBox
.AddItem(Item
: string);
3023 SetLength(FItems
, Length(FItems
)+1);
3024 FItems
[High(FItems
)] := Item
;
3026 if FSort
then g_gui
.Sort(FItems
);
3029 function TGUIListBox
.ItemExists (item
: String): Boolean;
3033 while (i
<= High(FItems
)) and (FItems
[i
] <> item
) do Inc(i
);
3034 result
:= i
<= High(FItems
)
3037 procedure TGUIListBox
.Clear
;
3045 constructor TGUIListBox
.Create(FontID
: DWORD
; Width
, Height
: Word);
3049 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
3054 FOnChangeEvent
:= nil;
3056 FDrawScroll
:= True;
3059 procedure TGUIListBox
.Draw
;
3067 if FDrawBack
then DrawBox(FX
, FY
, FWidth
+1, FHeight
);
3069 DrawScroll(FX
+4+FWidth
*16, FY
+4, FHeight
, (FStartLine
> 0) and (FItems
<> nil),
3070 (FStartLine
+FHeight
-1 < High(FItems
)) and (FItems
<> nil));
3072 if FItems
<> nil then
3073 for a
:= FStartLine
to Min(High(FItems
), FStartLine
+FHeight
-1) do
3077 FFont
.GetTextSize(s
, w2
, h2
);
3078 while (Length(s
) > 0) and (w2
> FWidth
*16) do
3080 SetLength(s
, Length(s
)-1);
3081 FFont
.GetTextSize(s
, w2
, h2
);
3085 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, s
, FActiveColor
.R
, FActiveColor
.G
, FActiveColor
.B
)
3087 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, s
, FUnActiveColor
.R
, FUnActiveColor
.G
, FUnActiveColor
.B
);
3091 function TGUIListBox
.GetHeight
: Integer;
3093 Result
:= 8+FHeight
*16;
3096 function TGUIListBox
.GetWidth
: Integer;
3098 Result
:= 8+(FWidth
+1)*16;
3101 procedure TGUIListBox
.OnMessage(var Msg
: TMessage
);
3105 if not FEnabled
then Exit
;
3109 if FItems
= nil then Exit
;
3122 FIndex
:= High(FItems
);
3123 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
3125 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
3129 if FIndex
< FStartLine
then Dec(FStartLine
);
3130 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3132 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
3133 if FIndex
< High(FItems
) then
3136 if FIndex
> FStartLine
+FHeight
-1 then Inc(FStartLine
);
3137 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3139 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
3142 if FActiveControl
<> Self
then SetActive(Self
)
3144 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
3145 else SetActive(nil);
3149 for a
:= 0 to High(FItems
) do
3150 if (Length(FItems
[a
]) > 0) and (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) then
3153 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
3154 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3160 function TGUIListBox
.SelectedItem(): String;
3164 if (FIndex
< 0) or (FItems
= nil) or
3165 (FIndex
> High(FItems
)) then
3168 Result
:= FItems
[FIndex
];
3171 procedure TGUIListBox
.FSetItems(Items
: SSArray
);
3173 if FItems
<> nil then
3181 if FSort
then g_gui
.Sort(FItems
);
3184 procedure TGUIListBox
.SelectItem(Item
: String);
3188 if FItems
= nil then
3192 Item
:= LowerCase(Item
);
3194 for a
:= 0 to High(FItems
) do
3195 if LowerCase(FItems
[a
]) = Item
then
3201 if FIndex
< FHeight
then
3204 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
3207 procedure TGUIListBox
.FSetIndex(aIndex
: Integer);
3209 if FItems
= nil then
3212 if (aIndex
< 0) or (aIndex
> High(FItems
)) then
3217 if FIndex
<= FHeight
then
3220 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
3225 procedure TGUIFileListBox
.OnMessage(var Msg
: TMessage
);
3227 a
, b
: Integer; s
: AnsiString;
3229 if not FEnabled
then
3232 if FItems
= nil then
3243 if @FOnChangeEvent
<> nil then
3244 FOnChangeEvent(Self
);
3249 FIndex
:= High(FItems
);
3250 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
3251 if @FOnChangeEvent
<> nil then
3252 FOnChangeEvent(Self
);
3255 IK_PAGEUP
, IK_KPPAGEUP
:
3257 if FIndex
> FHeight
then
3258 FIndex
:= FIndex
-FHeight
3262 if FStartLine
> FHeight
then
3263 FStartLine
:= FStartLine
-FHeight
3268 IK_PAGEDN
, IK_KPPAGEDN
:
3270 if FIndex
< High(FItems
)-FHeight
then
3271 FIndex
:= FIndex
+FHeight
3273 FIndex
:= High(FItems
);
3275 if FStartLine
< High(FItems
)-FHeight
then
3276 FStartLine
:= FStartLine
+FHeight
3278 FStartLine
:= High(FItems
)-FHeight
+1;
3281 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
, VK_UP
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
3285 if FIndex
< FStartLine
then
3287 if @FOnChangeEvent
<> nil then
3288 FOnChangeEvent(Self
);
3291 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
, VK_DOWN
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
3292 if FIndex
< High(FItems
) then
3295 if FIndex
> FStartLine
+FHeight
-1 then
3297 if @FOnChangeEvent
<> nil then
3298 FOnChangeEvent(Self
);
3301 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
3304 if FActiveControl
<> Self
then
3308 if FItems
[FIndex
][1] = #29 then // Ïàïêà
3310 if FItems
[FIndex
] = #29 + '..' then
3312 //e_LogWritefln('TGUIFileListBox: Upper dir "%s" -> "%s"', [FSubPath, e_UpperDir(FSubPath)]);
3313 FSubPath
:= e_UpperDir(FSubPath
)
3317 s
:= Copy(AnsiString(FItems
[FIndex
]), 2);
3318 //e_LogWritefln('TGUIFileListBox: Enter dir "%s" -> "%s"', [FSubPath, e_CatPath(FSubPath, s)]);
3319 FSubPath
:= e_CatPath(FSubPath
, s
);
3326 if FDefControl
<> '' then
3327 SetActive(GetControl(FDefControl
))
3335 for b
:= FIndex
+ 1 to High(FItems
) + FIndex
do
3337 a
:= b
mod Length(FItems
);
3338 if ( (Length(FItems
[a
]) > 0) and
3339 (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) ) or
3340 ( (Length(FItems
[a
]) > 1) and
3341 (FItems
[a
][1] = #29) and // Ïàïêà
3342 (LowerCase(FItems
[a
][2]) = LowerCase(Chr(wParam
))) ) then
3345 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
3346 if @FOnChangeEvent
<> nil then
3347 FOnChangeEvent(Self
);
3354 procedure TGUIFileListBox
.ScanDirs
;
3355 var i
, j
: Integer; path
: AnsiString; SR
: TSearchRec
; sm
, sc
: String;
3359 i
:= High(FBaseList
);
3362 path
:= e_CatPath(FBaseList
[i
], FSubPath
);
3365 if FindFirst(path
+ '/' + '*', faDirectory
, SR
) = 0 then
3368 if LongBool(SR
.Attr
and faDirectory
) then
3369 if (SR
.Name
<> '.') and ((FSubPath
<> '') or (SR
.Name
<> '..')) then
3370 if Self
.ItemExists(#1 + SR
.Name
) = false then
3371 Self
.AddItem(#1 + SR
.Name
)
3372 until FindNext(SR
) <> 0
3379 i
:= High(FBaseList
);
3382 path
:= e_CatPath(FBaseList
[i
], FSubPath
);
3388 j
:= length(sm
) + 1;
3389 sc
:= Copy(sm
, 1, j
- 1);
3391 if FindFirst(path
+ '/' + sc
, faAnyFile
, SR
) = 0 then
3394 if Self
.ItemExists(SR
.Name
) = false then
3396 until FindNext(SR
) <> 0
3403 for i
:= 0 to High(FItems
) do
3404 if FItems
[i
][1] = #1 then
3405 FItems
[i
][1] := #29;
3408 procedure TGUIFileListBox
.SetBase (dirs
: SSArray
; path
: String = '');
3415 function TGUIFileListBox
.SelectedItem (): String;
3419 if (FIndex
>= 0) and (FIndex
<= High(FItems
)) and (FItems
[FIndex
][1] <> '/') and (FItems
[FIndex
][1] <> '\') then
3421 s
:= e_CatPath(FSubPath
, FItems
[FIndex
]);
3422 if e_FindResource(FBaseList
, s
) = true then
3423 result
:= ExpandFileName(s
)
3425 e_LogWritefln('TGUIFileListBox.SelectedItem -> "%s"', [result
]);
3428 procedure TGUIFileListBox
.UpdateFileList();
3432 if (FIndex
= -1) or (FItems
= nil) or
3433 (FIndex
> High(FItems
)) or
3434 (FItems
[FIndex
][1] = '/') or
3435 (FItems
[FIndex
][1] = '\') then
3438 fn
:= FItems
[FIndex
];
3449 procedure TGUIMemo
.Clear
;
3455 constructor TGUIMemo
.Create(FontID
: DWORD
; Width
, Height
: Word);
3459 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
3464 FDrawScroll
:= True;
3467 procedure TGUIMemo
.Draw
;
3473 if FDrawBack
then DrawBox(FX
, FY
, FWidth
+1, FHeight
);
3475 DrawScroll(FX
+4+FWidth
*16, FY
+4, FHeight
, (FStartLine
> 0) and (FLines
<> nil),
3476 (FStartLine
+FHeight
-1 < High(FLines
)) and (FLines
<> nil));
3478 if FLines
<> nil then
3479 for a
:= FStartLine
to Min(High(FLines
), FStartLine
+FHeight
-1) do
3480 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, FLines
[a
], FColor
.R
, FColor
.G
, FColor
.B
);
3483 function TGUIMemo
.GetHeight
: Integer;
3485 Result
:= 8+FHeight
*16;
3488 function TGUIMemo
.GetWidth
: Integer;
3490 Result
:= 8+(FWidth
+1)*16;
3493 procedure TGUIMemo
.OnMessage(var Msg
: TMessage
);
3495 if not FEnabled
then Exit
;
3499 if FLines
= nil then Exit
;
3505 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
, VK_UP
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
3506 if FStartLine
> 0 then
3508 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
, VK_DOWN
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
3509 if FStartLine
< Length(FLines
)-FHeight
then
3511 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
3514 if FActiveControl
<> Self
then
3520 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
3521 else SetActive(nil);
3527 procedure TGUIMemo
.SetText(Text: string);
3530 FLines
:= GetLines(Text, FFont
.ID
, FWidth
*16);
3535 procedure TGUIimage
.ClearImage();
3537 if FImageRes
= '' then Exit
;
3539 g_Texture_Delete(FImageRes
);
3543 constructor TGUIimage
.Create();
3550 destructor TGUIimage
.Destroy();
3555 procedure TGUIimage
.Draw();
3561 if FImageRes
= '' then
3563 if g_Texture_Get(FDefaultRes
, ID
) then e_Draw(ID
, FX
, FY
, 0, True, False);
3566 if g_Texture_Get(FImageRes
, ID
) then e_Draw(ID
, FX
, FY
, 0, True, False);
3569 procedure TGUIimage
.OnMessage(var Msg
: TMessage
);
3574 procedure TGUIimage
.SetImage(Res
: string);
3578 if g_Texture_CreateWADEx(Res
, Res
) then FImageRes
:= Res
;
3581 procedure TGUIimage
.Update();