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
, 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 {$IFDEF ENABLE_TOUCH}
558 g_sound
, SysUtils
, e_res
, r_textures
,
559 g_game
, Math
, StrUtils
, g_player
, g_options
, g_console
, r_playermodel
,
560 g_map
, g_weapons
, xdynrec
, wadreader
;
564 Box
: Array [0..8] of DWORD
;
565 Saved_Windows
: SSArray
;
567 function GetLines (text: string; FontID
: DWORD
; MaxWidth
: Word): SSArray
;
571 i
, len
, lastsep
: Integer;
573 function PrepareStep (): Boolean; inline;
575 // Skip leading spaces.
576 while PChar(text)[k
-1] = ' ' do k
+= 1;
581 function GetLine (j
: Integer; Strip
: Boolean): String; inline;
583 // Exclude trailing spaces from the line.
585 while text[j
] = ' ' do j
-= 1;
587 Result
:= Copy(text, k
, j
-k
+1);
590 function LineWidth (): Integer; inline;
593 e_CharFont_GetSize(FontID
, GetLine(i
, False), w
, h
);
600 //e_LogWritefln('GetLines @%s len=%s [%s]', [MaxWidth, len, text]);
602 while PrepareStep() do
604 // Get longest possible sequence (this is not constant because fonts are not monospaced).
607 if text[i
] in [' ', '.', ',', ':', ';']
610 until (i
> len
) or (LineWidth() > MaxWidth
);
612 // Do not include part of a word if possible.
613 if (lastsep
-k
> 3) and (i
<= len
) and (text[i
] <> ' ')
614 then i
:= lastsep
+ 1;
617 SetLength(Result
, lines
+ 1);
618 Result
[lines
] := GetLine(i
-1, True);
619 //e_LogWritefln(' -> (%s:%s::%s) [%s]', [k, i, LineWidth(), Result[lines]]);
626 procedure Sort(var a
: SSArray
);
631 if a
= nil then Exit
;
633 for i
:= High(a
) downto Low(a
) do
634 for j
:= Low(a
) to High(a
)-1 do
635 if LowerCase(a
[j
]) > LowerCase(a
[j
+1]) then
643 procedure g_GUI_Init();
645 g_Texture_Get(BOX1
, Box
[0]);
646 g_Texture_Get(BOX2
, Box
[1]);
647 g_Texture_Get(BOX3
, Box
[2]);
648 g_Texture_Get(BOX4
, Box
[3]);
649 g_Texture_Get(BOX5
, Box
[4]);
650 g_Texture_Get(BOX6
, Box
[5]);
651 g_Texture_Get(BOX7
, Box
[6]);
652 g_Texture_Get(BOX8
, Box
[7]);
653 g_Texture_Get(BOX9
, Box
[8]);
656 function g_GUI_Destroy(): Boolean;
660 Result
:= (Length(g_GUIWindows
) > 0);
662 for i
:= 0 to High(g_GUIWindows
) do
663 g_GUIWindows
[i
].Free();
666 g_ActiveWindow
:= nil;
669 function g_GUI_AddWindow(Window
: TGUIWindow
): TGUIWindow
;
671 SetLength(g_GUIWindows
, Length(g_GUIWindows
)+1);
672 g_GUIWindows
[High(g_GUIWindows
)] := Window
;
677 function g_GUI_GetWindow(Name
: string): TGUIWindow
;
683 if g_GUIWindows
<> nil then
684 for i
:= 0 to High(g_GUIWindows
) do
685 if g_GUIWindows
[i
].FName
= Name
then
687 Result
:= g_GUIWindows
[i
];
691 Assert(Result
<> nil, 'GUI_Window "'+Name
+'" not found');
694 procedure g_GUI_ShowWindow(Name
: string);
698 if g_GUIWindows
= nil then
701 for i
:= 0 to High(g_GUIWindows
) do
702 if g_GUIWindows
[i
].FName
= Name
then
704 g_GUIWindows
[i
].FPrevWindow
:= g_ActiveWindow
;
705 g_ActiveWindow
:= g_GUIWindows
[i
];
707 if g_ActiveWindow
.MainWindow
then
708 g_ActiveWindow
.FPrevWindow
:= nil;
710 if g_ActiveWindow
.FDefControl
<> '' then
711 g_ActiveWindow
.SetActive(g_ActiveWindow
.GetControl(g_ActiveWindow
.FDefControl
))
713 g_ActiveWindow
.SetActive(nil);
715 if @g_ActiveWindow
.FOnShowEvent
<> nil then
716 g_ActiveWindow
.FOnShowEvent();
722 procedure g_GUI_HideWindow(PlaySound
: Boolean = True);
724 if g_ActiveWindow
<> nil then
726 if @g_ActiveWindow
.OnClose
<> nil then
727 g_ActiveWindow
.OnClose();
728 g_ActiveWindow
:= g_ActiveWindow
.FPrevWindow
;
730 g_Sound_PlayEx(WINDOW_CLOSESOUND
);
734 procedure g_GUI_SaveMenuPos();
739 SetLength(Saved_Windows
, 0);
740 win
:= g_ActiveWindow
;
744 len
:= Length(Saved_Windows
);
745 SetLength(Saved_Windows
, len
+ 1);
747 Saved_Windows
[len
] := win
.Name
;
749 if win
.MainWindow
then
752 win
:= win
.FPrevWindow
;
756 procedure g_GUI_LoadMenuPos();
758 i
, j
, k
, len
: Integer;
761 g_ActiveWindow
:= nil;
762 len
:= Length(Saved_Windows
);
767 // Îêíî ñ ãëàâíûì ìåíþ:
768 g_GUI_ShowWindow(Saved_Windows
[len
-1]);
770 // Íå ïåðåêëþ÷èëîñü (èëè íåêóäà äàëüøå):
771 if (len
= 1) or (g_ActiveWindow
= nil) then
774 // Èùåì êíîïêè â îñòàëüíûõ îêíàõ:
775 for k
:= len
-1 downto 1 do
779 for i
:= 0 to Length(g_ActiveWindow
.Childs
)-1 do
781 if g_ActiveWindow
.Childs
[i
] is TGUIMainMenu
then
782 begin // GUI_MainMenu
783 with TGUIMainMenu(g_ActiveWindow
.Childs
[i
]) do
784 for j
:= 0 to Length(FButtons
)-1 do
785 if FButtons
[j
].ShowWindow
= Saved_Windows
[k
-1] then
787 FButtons
[j
].Click(True);
793 if g_ActiveWindow
.Childs
[i
] is TGUIMenu
then
794 with TGUIMenu(g_ActiveWindow
.Childs
[i
]) do
795 for j
:= 0 to Length(FItems
)-1 do
796 if FItems
[j
].ControlType
= TGUITextButton
then
797 if TGUITextButton(FItems
[j
].Control
).ShowWindow
= Saved_Windows
[k
-1] then
799 TGUITextButton(FItems
[j
].Control
).Click(True);
810 (g_ActiveWindow
.Name
= Saved_Windows
[k
]) then
815 procedure DrawBox(X
, Y
: Integer; Width
, Height
: Word);
817 e_Draw(Box
[0], X
, Y
, 0, False, False);
818 e_DrawFill(Box
[1], X
+4, Y
, Width
*4, 1, 0, False, False);
819 e_Draw(Box
[2], X
+4+Width
*16, Y
, 0, False, False);
820 e_DrawFill(Box
[3], X
, Y
+4, 1, Height
*4, 0, False, False);
821 e_DrawFill(Box
[4], X
+4, Y
+4, Width
, Height
, 0, False, False);
822 e_DrawFill(Box
[5], X
+4+Width
*16, Y
+4, 1, Height
*4, 0, False, False);
823 e_Draw(Box
[6], X
, Y
+4+Height
*16, 0, False, False);
824 e_DrawFill(Box
[7], X
+4, Y
+4+Height
*16, Width
*4, 1, 0, False, False);
825 e_Draw(Box
[8], X
+4+Width
*16, Y
+4+Height
*16, 0, False, False);
828 procedure DrawScroll(X
, Y
: Integer; Height
: Word; Up
, Down
: Boolean);
832 if Height
< 3 then Exit
;
835 g_Texture_Get(BSCROLL_UPA
, ID
)
837 g_Texture_Get(BSCROLL_UPU
, ID
);
838 e_Draw(ID
, X
, Y
, 0, False, False);
841 g_Texture_Get(BSCROLL_DOWNA
, ID
)
843 g_Texture_Get(BSCROLL_DOWNU
, ID
);
844 e_Draw(ID
, X
, Y
+(Height
-1)*16, 0, False, False);
846 g_Texture_Get(BSCROLL_MIDDLE
, ID
);
847 e_DrawFill(ID
, X
, Y
+16, 1, Height
-2, 0, False, False);
852 constructor TGUIWindow
.Create(Name
: string);
855 FActiveControl
:= nil;
859 FOnCloseEvent
:= nil;
863 destructor TGUIWindow
.Destroy
;
870 for i
:= 0 to High(Childs
) do
874 function TGUIWindow
.AddChild(Child
: TGUIControl
): TGUIControl
;
876 Child
.FWindow
:= Self
;
878 SetLength(Childs
, Length(Childs
) + 1);
879 Childs
[High(Childs
)] := Child
;
884 procedure TGUIWindow
.Update
;
888 for i
:= 0 to High(Childs
) do
889 if Childs
[i
] <> nil then Childs
[i
].Update
;
892 procedure TGUIWindow
.Draw
;
898 if FBackTexture
<> '' then // Here goes code duplication from g_game.pas:DrawMenuBackground()
899 if g_Texture_Get(FBackTexture
, ID
) then
902 e_GetTextureSize(ID
, @tw
, @th
);
904 tw
:= round(tw
* 1.333 * (gScreenHeight
/ th
))
906 tw
:= trunc(tw
* (gScreenHeight
/ th
));
907 e_DrawSize(ID
, (gScreenWidth
- tw
) div 2, 0, 0, False, False, tw
, gScreenHeight
);
910 e_Clear(0.5, 0.5, 0.5);
913 if FName
= 'AuthorsMenu' then
914 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
916 for i
:= 0 to High(Childs
) do
917 if Childs
[i
] <> nil then Childs
[i
].Draw
;
920 procedure TGUIWindow
.OnMessage(var Msg
: TMessage
);
922 if FActiveControl
<> nil then FActiveControl
.OnMessage(Msg
);
923 if @FOnKeyDown
<> nil then FOnKeyDown(Msg
.wParam
);
924 if @FOnKeyDownEx
<> nil then FOnKeyDownEx(self
, Msg
.wParam
);
926 if Msg
.Msg
= WM_KEYDOWN
then
938 procedure TGUIWindow
.SetActive(Control
: TGUIControl
);
940 FActiveControl
:= Control
;
943 function TGUIWindow
.GetControl(Name
: String): TGUIControl
;
949 if Childs
<> nil then
950 for i
:= 0 to High(Childs
) do
951 if Childs
[i
] <> nil then
952 if LowerCase(Childs
[i
].FName
) = LowerCase(Name
) then
958 Assert(Result
<> nil, 'Window Control "'+Name
+'" not Found!');
963 constructor TGUIControl
.Create();
969 FRightAlign
:= false;
973 procedure TGUIControl
.OnMessage(var Msg
: TMessage
);
979 procedure TGUIControl
.Update();
983 procedure TGUIControl
.Draw();
987 function TGUIControl
.WantActivationKey (key
: LongInt): Boolean;
992 function TGUIControl
.GetWidth(): Integer;
997 function TGUIControl
.GetHeight(): Integer;
1004 procedure TGUITextButton
.Click(Silent
: Boolean = False);
1006 if (FSound
<> '') and (not Silent
) then g_Sound_PlayEx(FSound
);
1008 if @Proc
<> nil then Proc();
1009 if @ProcEx
<> nil then ProcEx(self
);
1011 if FShowWindow
<> '' then g_GUI_ShowWindow(FShowWindow
);
1014 constructor TGUITextButton
.Create(aProc
: Pointer; FontID
: DWORD
; Text: string);
1021 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
1026 destructor TGUITextButton
.Destroy
;
1032 procedure TGUITextButton
.Draw
;
1034 FFont
.Draw(FX
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
)
1037 function TGUITextButton
.GetHeight
: Integer;
1041 FFont
.GetTextSize(FText
, w
, h
);
1045 function TGUITextButton
.GetWidth
: Integer;
1049 FFont
.GetTextSize(FText
, w
, h
);
1053 procedure TGUITextButton
.OnMessage(var Msg
: TMessage
);
1055 if not FEnabled
then Exit
;
1062 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
: Click();
1067 procedure TGUITextButton
.Update
;
1074 constructor TFont
.Create(FontID
: DWORD
; FontType
: TFontType
);
1079 FFontType
:= FontType
;
1082 destructor TFont
.Destroy
;
1088 procedure TFont
.Draw(X
, Y
: Integer; Text: string; R
, G
, B
: Byte);
1090 if FFontType
= TFontType
.Character
then e_CharFont_PrintEx(ID
, X
, Y
, Text, _RGB(R
, G
, B
), FScale
)
1091 else e_TextureFontPrintEx(X
, Y
, Text, ID
, R
, G
, B
, FScale
);
1094 procedure TFont
.GetTextSize(Text: string; var w
, h
: Word);
1098 if FFontType
= TFontType
.Character
then e_CharFont_GetSize(ID
, Text, w
, h
)
1101 e_TextureFontGetSize(ID
, cw
, ch
);
1102 w
:= cw
*Length(Text);
1106 w
:= Round(w
*FScale
);
1107 h
:= Round(h
*FScale
);
1112 function TGUIMainMenu
.AddButton(fProc
: Pointer; Caption
: string; ShowWindow
: string = ''): TGUITextButton
;
1120 SetLength(FButtons
, Length(FButtons
)+1);
1121 FButtons
[High(FButtons
)] := TGUITextButton
.Create(fProc
, FFontID
, Caption
);
1122 FButtons
[High(FButtons
)].ShowWindow
:= ShowWindow
;
1123 with FButtons
[High(FButtons
)] do
1125 if (fProc
<> nil) or (ShowWindow
<> '') then FColor
:= MAINMENU_ITEMS_COLOR
1126 else FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
1127 FSound
:= MAINMENU_CLICKSOUND
;
1130 _x
:= gScreenWidth
div 2;
1132 for a
:= 0 to High(FButtons
) do
1133 if FButtons
[a
] <> nil then
1134 _x
:= Min(_x
, (gScreenWidth
div 2)-(FButtons
[a
].GetWidth
div 2));
1136 if FLogo
<> 0 then e_GetTextureSize(FLogo
, nil, @lh
);
1137 hh
:= FButtons
[High(FButtons
)].GetHeight
;
1139 if FLogo
<> 0 then h
:= lh
+ hh
* (1 + Length(FButtons
)) + MAINMENU_SPACE
* (Length(FButtons
) - 1)
1140 else h
:= hh
* (2 + Length(FButtons
)) + MAINMENU_SPACE
* (Length(FButtons
) - 1);
1141 h
:= (gScreenHeight
div 2) - (h
div 2);
1143 if FHeader
<> nil then with FHeader
do
1149 if FLogo
<> 0 then Inc(h
, lh
)
1152 for a
:= 0 to High(FButtons
) do
1154 if FButtons
[a
] <> nil then
1161 Inc(h
, hh
+MAINMENU_SPACE
);
1164 Result
:= FButtons
[High(FButtons
)];
1167 procedure TGUIMainMenu
.AddSpace
;
1169 SetLength(FButtons
, Length(FButtons
)+1);
1170 FButtons
[High(FButtons
)] := nil;
1173 constructor TGUIMainMenu
.Create(FontID
: DWORD
; Logo
, Header
: string);
1179 FCounter
:= MAINMENU_MARKERDELAY
;
1181 g_Texture_Get(MAINMENU_MARKER1
, FMarkerID1
);
1182 g_Texture_Get(MAINMENU_MARKER2
, FMarkerID2
);
1184 if not g_Texture_Get(Logo
, FLogo
) then
1186 FHeader
:= TGUILabel
.Create(Header
, FFontID
);
1189 FColor
:= MAINMENU_HEADER_COLOR
;
1190 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1191 FY
:= (gScreenHeight
div 2)-(GetHeight
div 2);
1196 destructor TGUIMainMenu
.Destroy
;
1200 if FButtons
<> nil then
1201 for a
:= 0 to High(FButtons
) do
1209 procedure TGUIMainMenu
.Draw
;
1217 if FHeader
<> nil then FHeader
.Draw
1219 e_GetTextureSize(FLogo
, @w
, @h
);
1220 e_Draw(FLogo
, ((gScreenWidth
div 2) - (w
div 2)), FButtons
[0].FY
- FButtons
[0].GetHeight
- h
, 0, True, False);
1223 if FButtons
<> nil then
1225 for a
:= 0 to High(FButtons
) do
1226 if FButtons
[a
] <> nil then FButtons
[a
].Draw
;
1228 if FIndex
<> -1 then
1229 e_Draw(FMarkerID1
, FButtons
[FIndex
].FX
-48, FButtons
[FIndex
].FY
, 0, True, False);
1233 procedure TGUIMainMenu
.EnableButton(aName
: string; e
: Boolean);
1237 if FButtons
= nil then Exit
;
1239 for a
:= 0 to High(FButtons
) do
1240 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= aName
) then
1242 if e
then FButtons
[a
].FColor
:= MAINMENU_ITEMS_COLOR
1243 else FButtons
[a
].FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
1244 FButtons
[a
].Enabled
:= e
;
1249 function TGUIMainMenu
.GetButton(aName
: string): TGUITextButton
;
1255 if FButtons
= nil then Exit
;
1257 for a
:= 0 to High(FButtons
) do
1258 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= aName
) then
1260 Result
:= FButtons
[a
];
1265 procedure TGUIMainMenu
.OnMessage(var Msg
: TMessage
);
1270 if not FEnabled
then Exit
;
1274 if FButtons
= nil then Exit
;
1277 for a
:= 0 to High(FButtons
) do
1278 if FButtons
[a
] <> nil then
1284 if not ok
then Exit
;
1289 IK_UP
, IK_KPUP
, VK_UP
, JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1293 if FIndex
< 0 then FIndex
:= High(FButtons
);
1294 until FButtons
[FIndex
] <> nil;
1296 g_Sound_PlayEx(MENU_CHANGESOUND
);
1298 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1302 if FIndex
> High(FButtons
) then FIndex
:= 0;
1303 until FButtons
[FIndex
] <> nil;
1305 g_Sound_PlayEx(MENU_CHANGESOUND
);
1307 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
;
1312 procedure TGUIMainMenu
.Update
;
1318 if FCounter
= 0 then
1321 FMarkerID1
:= FMarkerID2
;
1324 FCounter
:= MAINMENU_MARKERDELAY
;
1325 end else Dec(FCounter
);
1330 constructor TGUILabel
.Create(Text: string; FontID
: DWORD
);
1334 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
1338 FOnClickEvent
:= nil;
1341 procedure TGUILabel
.Draw
;
1347 FFont
.GetTextSize(FText
, w
, h
);
1348 FFont
.Draw(FX
+FMaxWidth
-w
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
);
1352 FFont
.Draw(FX
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
);
1356 function TGUILabel
.GetHeight
: Integer;
1360 FFont
.GetTextSize(FText
, w
, h
);
1364 function TGUILabel
.GetWidth
: Integer;
1368 if FFixedLen
= 0 then
1369 FFont
.GetTextSize(FText
, w
, h
)
1371 w
:= e_CharFont_GetMaxWidth(FFont
.ID
)*FFixedLen
;
1375 procedure TGUILabel
.OnMessage(var Msg
: TMessage
);
1377 if not FEnabled
then Exit
;
1384 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
: if @FOnClickEvent
<> nil then FOnClickEvent();
1391 function TGUIMenu
.AddButton(Proc
: Pointer; fText
: string; _ShowWindow
: string = ''): TGUITextButton
;
1398 Control
:= TGUITextButton
.Create(Proc
, FFontID
, fText
);
1399 with Control
as TGUITextButton
do
1401 ShowWindow
:= _ShowWindow
;
1402 FColor
:= MENU_ITEMSCTRL_COLOR
;
1406 ControlType
:= TGUITextButton
;
1408 Result
:= (Control
as TGUITextButton
);
1411 if FIndex
= -1 then FIndex
:= i
;
1416 procedure TGUIMenu
.AddLine(fText
: string);
1423 Text := TGUILabel
.Create(fText
, FFontID
);
1426 FColor
:= MENU_ITEMSTEXT_COLOR
;
1435 procedure TGUIMenu
.AddText(fText
: string; MaxWidth
: Word);
1440 l
:= GetLines(fText
, FFontID
, MaxWidth
);
1442 if l
= nil then Exit
;
1444 for a
:= 0 to High(l
) do
1449 Text := TGUILabel
.Create(l
[a
], FFontID
);
1452 with Text do begin FColor
:= _RGB(255, 0, 0); end;
1456 with Text do begin FColor
:= MENU_ITEMSTEXT_COLOR
; end;
1466 procedure TGUIMenu
.AddSpace
;
1480 constructor TGUIMenu
.Create(HeaderFont
, ItemsFont
: DWORD
; Header
: string);
1486 FFontID
:= ItemsFont
;
1487 FCounter
:= MENU_MARKERDELAY
;
1491 FHeader
:= TGUILabel
.Create(Header
, HeaderFont
);
1494 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1496 FColor
:= MAINMENU_HEADER_COLOR
;
1500 destructor TGUIMenu
.Destroy
;
1504 if FItems
<> nil then
1505 for a
:= 0 to High(FItems
) do
1519 procedure TGUIMenu
.Draw
;
1521 a
, locx
, locy
: Integer;
1525 if FHeader
<> nil then FHeader
.Draw
;
1527 if FItems
<> nil then
1528 for a
:= 0 to High(FItems
) do
1530 if FItems
[a
].Text <> nil then FItems
[a
].Text.Draw
;
1531 if FItems
[a
].Control
<> nil then FItems
[a
].Control
.Draw
;
1534 if (FIndex
<> -1) and (FCounter
> MENU_MARKERDELAY
div 2) then
1539 if FItems
[FIndex
].Text <> nil then
1541 locx
:= FItems
[FIndex
].Text.FX
;
1542 locy
:= FItems
[FIndex
].Text.FY
;
1544 if FItems
[FIndex
].Text.RightAlign
then
1546 locx
:= locx
+FItems
[FIndex
].Text.FMaxWidth
-FItems
[FIndex
].Text.GetWidth
;
1549 else if FItems
[FIndex
].Control
<> nil then
1551 locx
:= FItems
[FIndex
].Control
.FX
;
1552 locy
:= FItems
[FIndex
].Control
.FY
;
1555 locx
:= locx
-e_CharFont_GetMaxWidth(FFontID
);
1557 e_CharFont_PrintEx(FFontID
, locx
, locy
, #16, _RGB(255, 0, 0));
1561 function TGUIMenu
.GetControl(aName
: String): TGUIControl
;
1567 if FItems
<> nil then
1568 for a
:= 0 to High(FItems
) do
1569 if FItems
[a
].Control
<> nil then
1570 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(aName
) then
1572 Result
:= FItems
[a
].Control
;
1576 Assert(Result
<> nil, 'GUI control "'+aName
+'" not found!');
1579 function TGUIMenu
.GetControlsText(aName
: String): TGUILabel
;
1585 if FItems
<> nil then
1586 for a
:= 0 to High(FItems
) do
1587 if FItems
[a
].Control
<> nil then
1588 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(aName
) then
1590 Result
:= FItems
[a
].Text;
1594 Assert(Result
<> nil, 'GUI control''s text "'+aName
+'" not found!');
1597 function TGUIMenu
.NewItem
: Integer;
1599 SetLength(FItems
, Length(FItems
)+1);
1600 Result
:= High(FItems
);
1603 procedure TGUIMenu
.OnMessage(var Msg
: TMessage
);
1608 if not FEnabled
then Exit
;
1612 if FItems
= nil then Exit
;
1615 for a
:= 0 to High(FItems
) do
1616 if FItems
[a
].Control
<> nil then
1622 if not ok
then Exit
;
1624 if (Msg
.Msg
= WM_KEYDOWN
) and (FIndex
<> -1) and (FItems
[FIndex
].Control
<> nil) and
1625 (FItems
[FIndex
].Control
.WantActivationKey(Msg
.wParam
)) then
1627 FItems
[FIndex
].Control
.OnMessage(Msg
);
1628 g_Sound_PlayEx(MENU_CLICKSOUND
);
1636 IK_UP
, IK_KPUP
, VK_UP
,JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1641 if c
> Length(FItems
) then
1648 if FIndex
< 0 then FIndex
:= High(FItems
);
1649 until (FItems
[FIndex
].Control
<> nil) and
1650 (FItems
[FIndex
].Control
.Enabled
);
1654 g_Sound_PlayEx(MENU_CHANGESOUND
);
1657 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1662 if c
> Length(FItems
) then
1669 if FIndex
> High(FItems
) then FIndex
:= 0;
1670 until (FItems
[FIndex
].Control
<> nil) and
1671 (FItems
[FIndex
].Control
.Enabled
);
1675 g_Sound_PlayEx(MENU_CHANGESOUND
);
1678 IK_LEFT
, IK_RIGHT
, IK_KPLEFT
, IK_KPRIGHT
, VK_LEFT
, VK_RIGHT
,
1679 JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
,
1680 JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
1682 if FIndex
<> -1 then
1683 if FItems
[FIndex
].Control
<> nil then
1684 FItems
[FIndex
].Control
.OnMessage(Msg
);
1686 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
1688 if FIndex
<> -1 then
1690 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1692 g_Sound_PlayEx(MENU_CLICKSOUND
);
1696 if FYesNo
and (length(FItems
) > 1) then
1698 Msg
.wParam
:= IK_RETURN
; // to register keypress
1699 FIndex
:= High(FItems
)-1;
1700 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1703 if FYesNo
and (length(FItems
) > 1) then
1705 Msg
.wParam
:= IK_RETURN
; // to register keypress
1706 FIndex
:= High(FItems
);
1707 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1714 procedure TGUIMenu
.ReAlign();
1716 a
, tx
, cx
, w
, h
: Integer;
1717 cww
: array of Integer; // cached widths
1720 if FItems
= nil then Exit
;
1722 SetLength(cww
, length(FItems
));
1724 for a
:= 0 to High(FItems
) do
1726 if FItems
[a
].Text <> nil then
1728 cww
[a
] := FItems
[a
].Text.GetWidth
;
1729 if maxcww
< cww
[a
] then maxcww
:= cww
[a
];
1740 for a
:= 0 to High(FItems
) do
1743 if FItems
[a
].Text <> nil then w
:= FItems
[a
].Text.GetWidth
;
1744 if FItems
[a
].Control
<> nil then
1747 if FItems
[a
].ControlType
= TGUILabel
then w
:= w
+(FItems
[a
].Control
as TGUILabel
).GetWidth
1748 else if FItems
[a
].ControlType
= TGUITextButton
then w
:= w
+(FItems
[a
].Control
as TGUITextButton
).GetWidth
1749 else if FItems
[a
].ControlType
= TGUIScroll
then w
:= w
+(FItems
[a
].Control
as TGUIScroll
).GetWidth
1750 else if FItems
[a
].ControlType
= TGUISwitch
then w
:= w
+(FItems
[a
].Control
as TGUISwitch
).GetWidth
1751 else if FItems
[a
].ControlType
= TGUIEdit
then w
:= w
+(FItems
[a
].Control
as TGUIEdit
).GetWidth
1752 else if FItems
[a
].ControlType
= TGUIKeyRead
then w
:= w
+(FItems
[a
].Control
as TGUIKeyRead
).GetWidth
1753 else if FItems
[a
].ControlType
= TGUIKeyRead2
then w
:= w
+(FItems
[a
].Control
as TGUIKeyRead2
).GetWidth
1754 else if FItems
[a
].ControlType
= TGUIListBox
then w
:= w
+(FItems
[a
].Control
as TGUIListBox
).GetWidth
1755 else if FItems
[a
].ControlType
= TGUIFileListBox
then w
:= w
+(FItems
[a
].Control
as TGUIFileListBox
).GetWidth
1756 else if FItems
[a
].ControlType
= TGUIMemo
then w
:= w
+(FItems
[a
].Control
as TGUIMemo
).GetWidth
;
1758 tx
:= Min(tx
, (gScreenWidth
div 2)-(w
div 2));
1763 for a
:= 0 to High(FItems
) do
1767 if (Text <> nil) and (Control
= nil) then Continue
;
1769 if Text <> nil then w
:= tx
+Text.GetWidth
;
1770 if w
> cx
then cx
:= w
;
1774 cx
:= cx
+MENU_HSPACE
;
1776 h
:= FHeader
.GetHeight
*2+MENU_VSPACE
*(Length(FItems
)-1);
1778 for a
:= 0 to High(FItems
) do
1782 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then
1783 h
:= h
+(FItems
[a
].Control
as TGUIListBox
).GetHeight()
1785 h
:= h
+e_CharFont_GetMaxHeight(FFontID
);
1789 h
:= (gScreenHeight
div 2)-(h
div 2);
1793 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1796 Inc(h
, GetHeight
*2);
1799 for a
:= 0 to High(FItems
) do
1811 if Text.RightAlign
and (length(cww
) > a
) then
1813 //Text.FX := Text.FX+maxcww;
1814 Text.FMaxWidth
:= maxcww
;
1818 if Control
<> nil then
1835 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then Inc(h
, (Control
as TGUIListBox
).GetHeight
+MENU_VSPACE
)
1836 else if ControlType
= TGUIMemo
then Inc(h
, (Control
as TGUIMemo
).GetHeight
+MENU_VSPACE
)
1837 else Inc(h
, e_CharFont_GetMaxHeight(FFontID
)+MENU_VSPACE
);
1841 // another ugly hack
1842 if FYesNo
and (length(FItems
) > 1) then
1845 for a
:= High(FItems
)-1 to High(FItems
) do
1847 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1849 cx
:= (FItems
[a
].Control
as TGUITextButton
).GetWidth
;
1850 if cx
> w
then w
:= cx
;
1855 for a
:= High(FItems
)-1 to High(FItems
) do
1857 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1859 FItems
[a
].Control
.FX
:= (gScreenWidth
-w
) div 2;
1866 function TGUIMenu
.AddScroll(fText
: string): TGUIScroll
;
1873 Control
:= TGUIScroll
.Create();
1875 Text := TGUILabel
.Create(fText
, FFontID
);
1878 FColor
:= MENU_ITEMSTEXT_COLOR
;
1881 ControlType
:= TGUIScroll
;
1883 Result
:= (Control
as TGUIScroll
);
1886 if FIndex
= -1 then FIndex
:= i
;
1891 function TGUIMenu
.AddSwitch(fText
: string): TGUISwitch
;
1898 Control
:= TGUISwitch
.Create(FFontID
);
1899 (Control
as TGUISwitch
).FColor
:= MENU_ITEMSCTRL_COLOR
;
1901 Text := TGUILabel
.Create(fText
, FFontID
);
1904 FColor
:= MENU_ITEMSTEXT_COLOR
;
1907 ControlType
:= TGUISwitch
;
1909 Result
:= (Control
as TGUISwitch
);
1912 if FIndex
= -1 then FIndex
:= i
;
1917 function TGUIMenu
.AddEdit(fText
: string): TGUIEdit
;
1924 Control
:= TGUIEdit
.Create(FFontID
);
1925 with Control
as TGUIEdit
do
1927 FWindow
:= Self
.FWindow
;
1928 FColor
:= MENU_ITEMSCTRL_COLOR
;
1931 if fText
= '' then Text := nil else
1933 Text := TGUILabel
.Create(fText
, FFontID
);
1934 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1937 ControlType
:= TGUIEdit
;
1939 Result
:= (Control
as TGUIEdit
);
1942 if FIndex
= -1 then FIndex
:= i
;
1947 procedure TGUIMenu
.Update
;
1953 if FCounter
= 0 then FCounter
:= MENU_MARKERDELAY
else Dec(FCounter
);
1955 if FItems
<> nil then
1956 for a
:= 0 to High(FItems
) do
1957 if FItems
[a
].Control
<> nil then
1958 (FItems
[a
].Control
as FItems
[a
].ControlType
).Update
;
1961 function TGUIMenu
.AddKeyRead(fText
: string): TGUIKeyRead
;
1968 Control
:= TGUIKeyRead
.Create(FFontID
);
1969 with Control
as TGUIKeyRead
do
1971 FWindow
:= Self
.FWindow
;
1972 FColor
:= MENU_ITEMSCTRL_COLOR
;
1975 Text := TGUILabel
.Create(fText
, FFontID
);
1978 FColor
:= MENU_ITEMSTEXT_COLOR
;
1981 ControlType
:= TGUIKeyRead
;
1983 Result
:= (Control
as TGUIKeyRead
);
1986 if FIndex
= -1 then FIndex
:= i
;
1991 function TGUIMenu
.AddKeyRead2(fText
: string): TGUIKeyRead2
;
1998 Control
:= TGUIKeyRead2
.Create(FFontID
);
1999 with Control
as TGUIKeyRead2
do
2001 FWindow
:= Self
.FWindow
;
2002 FColor
:= MENU_ITEMSCTRL_COLOR
;
2005 Text := TGUILabel
.Create(fText
, FFontID
);
2008 FColor
:= MENU_ITEMSCTRL_COLOR
; //MENU_ITEMSTEXT_COLOR;
2012 ControlType
:= TGUIKeyRead2
;
2014 Result
:= (Control
as TGUIKeyRead2
);
2017 if FIndex
= -1 then FIndex
:= i
;
2022 function TGUIMenu
.AddList(fText
: string; Width
, Height
: Word): TGUIListBox
;
2029 Control
:= TGUIListBox
.Create(FFontID
, Width
, Height
);
2030 with Control
as TGUIListBox
do
2032 FWindow
:= Self
.FWindow
;
2033 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
2034 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
2037 Text := TGUILabel
.Create(fText
, FFontID
);
2040 FColor
:= MENU_ITEMSTEXT_COLOR
;
2043 ControlType
:= TGUIListBox
;
2045 Result
:= (Control
as TGUIListBox
);
2048 if FIndex
= -1 then FIndex
:= i
;
2053 function TGUIMenu
.AddFileList(fText
: string; Width
, Height
: Word): TGUIFileListBox
;
2060 Control
:= TGUIFileListBox
.Create(FFontID
, Width
, Height
);
2061 with Control
as TGUIFileListBox
do
2063 FWindow
:= Self
.FWindow
;
2064 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
2065 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
2068 if fText
= '' then Text := nil else
2070 Text := TGUILabel
.Create(fText
, FFontID
);
2071 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
2074 ControlType
:= TGUIFileListBox
;
2076 Result
:= (Control
as TGUIFileListBox
);
2079 if FIndex
= -1 then FIndex
:= i
;
2084 function TGUIMenu
.AddLabel(fText
: string): TGUILabel
;
2091 Control
:= TGUILabel
.Create('', FFontID
);
2092 with Control
as TGUILabel
do
2094 FWindow
:= Self
.FWindow
;
2095 FColor
:= MENU_ITEMSCTRL_COLOR
;
2098 Text := TGUILabel
.Create(fText
, FFontID
);
2101 FColor
:= MENU_ITEMSTEXT_COLOR
;
2104 ControlType
:= TGUILabel
;
2106 Result
:= (Control
as TGUILabel
);
2109 if FIndex
= -1 then FIndex
:= i
;
2114 function TGUIMenu
.AddMemo(fText
: string; Width
, Height
: Word): TGUIMemo
;
2121 Control
:= TGUIMemo
.Create(FFontID
, Width
, Height
);
2122 with Control
as TGUIMemo
do
2124 FWindow
:= Self
.FWindow
;
2125 FColor
:= MENU_ITEMSTEXT_COLOR
;
2128 if fText
= '' then Text := nil else
2130 Text := TGUILabel
.Create(fText
, FFontID
);
2131 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
2134 ControlType
:= TGUIMemo
;
2136 Result
:= (Control
as TGUIMemo
);
2139 if FIndex
= -1 then FIndex
:= i
;
2144 procedure TGUIMenu
.UpdateIndex();
2152 if (FIndex
< 0) or (FIndex
> High(FItems
)) then
2158 if FItems
[FIndex
].Control
.Enabled
then
2167 constructor TGUIScroll
.Create
;
2172 FOnChangeEvent
:= nil;
2174 g_Texture_Get(SCROLL_LEFT
, FLeftID
);
2175 g_Texture_Get(SCROLL_RIGHT
, FRightID
);
2176 g_Texture_Get(SCROLL_MIDDLE
, FMiddleID
);
2177 g_Texture_Get(SCROLL_MARKER
, FMarkerID
);
2180 procedure TGUIScroll
.Draw
;
2186 e_Draw(FLeftID
, FX
, FY
, 0, True, False);
2187 e_Draw(FRightID
, FX
+8+(FMax
+1)*8, FY
, 0, True, False);
2189 for a
:= 0 to FMax
do
2190 e_Draw(FMiddleID
, FX
+8+a
*8, FY
, 0, True, False);
2192 e_Draw(FMarkerID
, FX
+8+FValue
*8, FY
, 0, True, False);
2195 procedure TGUIScroll
.FSetValue(a
: Integer);
2197 if a
> FMax
then FValue
:= FMax
else FValue
:= a
;
2200 function TGUIScroll
.GetWidth
: Integer;
2202 Result
:= 16+(FMax
+1)*8;
2205 procedure TGUIScroll
.OnMessage(var Msg
: TMessage
);
2207 if not FEnabled
then Exit
;
2215 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2219 g_Sound_PlayEx(SCROLL_SUBSOUND
);
2220 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2222 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2223 if FValue
< FMax
then
2226 g_Sound_PlayEx(SCROLL_ADDSOUND
);
2227 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2234 procedure TGUIScroll
.Update
;
2242 procedure TGUISwitch
.AddItem(Item
: string);
2244 SetLength(FItems
, Length(FItems
)+1);
2245 FItems
[High(FItems
)] := Item
;
2247 if FIndex
= -1 then FIndex
:= 0;
2250 constructor TGUISwitch
.Create(FontID
: DWORD
);
2256 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2259 procedure TGUISwitch
.Draw
;
2263 FFont
.Draw(FX
, FY
, FItems
[FIndex
], FColor
.R
, FColor
.G
, FColor
.B
);
2266 function TGUISwitch
.GetText
: string;
2268 if FIndex
<> -1 then Result
:= FItems
[FIndex
]
2272 function TGUISwitch
.GetWidth
: Integer;
2279 if FItems
= nil then Exit
;
2281 for a
:= 0 to High(FItems
) do
2283 FFont
.GetTextSize(FItems
[a
], w
, h
);
2284 if w
> Result
then Result
:= w
;
2288 procedure TGUISwitch
.OnMessage(var Msg
: TMessage
);
2290 if not FEnabled
then Exit
;
2294 if FItems
= nil then Exit
;
2299 IK_RETURN
, IK_RIGHT
, IK_KPRETURN
, IK_KPRIGHT
, VK_FIRE
, VK_OPEN
, VK_RIGHT
,
2300 JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
,
2301 JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2303 if FIndex
< High(FItems
) then
2308 g_Sound_PlayEx(SCROLL_ADDSOUND
);
2310 if @FOnChangeEvent
<> nil then
2311 FOnChangeEvent(Self
);
2314 IK_LEFT
, IK_KPLEFT
, VK_LEFT
,
2315 JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2320 FIndex
:= High(FItems
);
2322 g_Sound_PlayEx(SCROLL_SUBSOUND
);
2324 if @FOnChangeEvent
<> nil then
2325 FOnChangeEvent(Self
);
2331 procedure TGUISwitch
.Update
;
2339 constructor TGUIEdit
.Create(FontID
: DWORD
);
2343 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2349 g_Texture_Get(EDIT_LEFT
, FLeftID
);
2350 g_Texture_Get(EDIT_RIGHT
, FRightID
);
2351 g_Texture_Get(EDIT_MIDDLE
, FMiddleID
);
2354 procedure TGUIEdit
.Draw
;
2361 e_Draw(FLeftID
, FX
, FY
, 0, True, False);
2362 e_Draw(FRightID
, FX
+8+FWidth
*16, FY
, 0, True, False);
2364 for c
:= 0 to FWidth
-1 do
2365 e_Draw(FMiddleID
, FX
+8+c
*16, FY
, 0, True, False);
2370 if FInvalid
and (FWindow
.FActiveControl
<> self
) then begin r
:= 128; g
:= 128; b
:= 128; end;
2371 FFont
.Draw(FX
+8, FY
, FText
, r
, g
, b
);
2373 if (FWindow
.FActiveControl
= self
) then
2375 FFont
.GetTextSize(Copy(FText
, 1, FCaretPos
), w
, h
);
2376 h
:= e_CharFont_GetMaxHeight(FFont
.ID
);
2377 e_DrawLine(2, FX
+8+w
, FY
+h
-3, FX
+8+w
+EDIT_CURSORLEN
, FY
+h
-3,
2378 EDIT_CURSORCOLOR
.R
, EDIT_CURSORCOLOR
.G
, EDIT_CURSORCOLOR
.B
);
2382 function TGUIEdit
.GetWidth
: Integer;
2384 Result
:= 16+FWidth
*16;
2387 procedure TGUIEdit
.OnMessage(var Msg
: TMessage
);
2389 if not FEnabled
then Exit
;
2398 if (wParam
in [48..57]) and (Chr(wParam
) <> '`') then
2399 if Length(Text) < FMaxLength
then
2401 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2407 if (wParam
in [32..255]) and (Chr(wParam
) <> '`') then
2408 if Length(Text) < FMaxLength
then
2410 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2418 Delete(FText
, FCaretPos
, 1);
2419 if FCaretPos
> 0 then Dec(FCaretPos
);
2421 IK_DELETE
: Delete(FText
, FCaretPos
+ 1, 1);
2422 IK_END
, IK_KPEND
: FCaretPos
:= Length(FText
);
2423 IK_HOME
, IK_KPHOME
: FCaretPos
:= 0;
2424 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
: if FCaretPos
> 0 then Dec(FCaretPos
);
2425 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
: if FCaretPos
< Length(FText
) then Inc(FCaretPos
);
2426 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2429 if FActiveControl
<> Self
then
2432 if @FOnEnterEvent
<> nil then FOnEnterEvent(Self
);
2436 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
2437 else SetActive(nil);
2438 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2444 g_GUIGrabInput
:= (@FOnEnterEvent
= nil) and (FWindow
.FActiveControl
= Self
);
2446 {$IFDEF ENABLE_TOUCH}
2447 sys_ShowKeyboard(g_GUIGrabInput
)
2451 procedure TGUIEdit
.SetText(Text: string);
2453 if Length(Text) > FMaxLength
then SetLength(Text, FMaxLength
);
2455 FCaretPos
:= Length(FText
);
2458 procedure TGUIEdit
.Update
;
2465 constructor TGUIKeyRead
.Create(FontID
: DWORD
);
2471 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2474 procedure TGUIKeyRead
.Draw
;
2478 FFont
.Draw(FX
, FY
, IfThen(FIsQuery
, KEYREAD_QUERY
, IfThen(FKey
<> 0, e_KeyNames
[FKey
], KEYREAD_CLEAR
)),
2479 FColor
.R
, FColor
.G
, FColor
.B
);
2482 function TGUIKeyRead
.GetWidth
: Integer;
2489 for a
:= 0 to 255 do
2491 FFont
.GetTextSize(e_KeyNames
[a
], w
, h
);
2492 Result
:= Max(Result
, w
);
2495 FFont
.GetTextSize(KEYREAD_QUERY
, w
, h
);
2496 if w
> Result
then Result
:= w
;
2498 FFont
.GetTextSize(KEYREAD_CLEAR
, w
, h
);
2499 if w
> Result
then Result
:= w
;
2502 function TGUIKeyRead
.WantActivationKey (key
: LongInt): Boolean;
2505 (key
= IK_BACKSPACE
) or
2509 procedure TGUIKeyRead
.OnMessage(var Msg
: TMessage
);
2510 procedure actDefCtl ();
2513 if FDefControl
<> '' then
2514 SetActive(GetControl(FDefControl
))
2522 if not FEnabled
then
2528 if not FIsQuery
then
2531 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2534 if FActiveControl
<> Self
then
2538 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2551 VK_FIRSTKEY
..VK_LASTKEY
: // do not allow to bind virtual keys
2557 if (e_KeyNames
[wParam
] <> '') and not g_Console_MatchBind(wParam
, 'togglemenu') then
2565 g_GUIGrabInput
:= FIsQuery
2570 constructor TGUIKeyRead2
.Create(FontID
: DWORD
);
2583 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2585 FMaxKeyNameWdt
:= 0;
2586 for a
:= 0 to 255 do
2588 FFont
.GetTextSize(e_KeyNames
[a
], w
, h
);
2589 FMaxKeyNameWdt
:= Max(FMaxKeyNameWdt
, w
);
2592 FMaxKeyNameWdt
:= FMaxKeyNameWdt
-(FMaxKeyNameWdt
div 3);
2594 FFont
.GetTextSize(KEYREAD_QUERY
, w
, h
);
2595 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2597 FFont
.GetTextSize(KEYREAD_CLEAR
, w
, h
);
2598 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2601 procedure TGUIKeyRead2
.Draw
;
2602 procedure drawText (idx
: Integer);
2608 if idx
= 0 then kk
:= FKey0
else kk
:= FKey1
;
2610 if idx
= 0 then x
:= FX
+8 else x
:= FX
+8+FMaxKeyNameWdt
+16;
2614 if FKeyIdx
= idx
then begin r
:= 255; g
:= 255; b
:= 255; end;
2615 if FIsQuery
and (FKeyIdx
= idx
) then
2616 FFont
.Draw(x
, y
, KEYREAD_QUERY
, r
, g
, b
)
2618 FFont
.Draw(x
, y
, IfThen(kk
<> 0, e_KeyNames
[kk
], KEYREAD_CLEAR
), r
, g
, b
);
2624 //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);
2625 //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);
2630 function TGUIKeyRead2
.GetWidth
: Integer;
2632 Result
:= FMaxKeyNameWdt
*2+8+8+16;
2635 function TGUIKeyRead2
.WantActivationKey (key
: LongInt): Boolean;
2638 IK_BACKSPACE
, IK_LEFT
, IK_RIGHT
, IK_KPLEFT
, IK_KPRIGHT
, VK_LEFT
, VK_RIGHT
,
2639 JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
,
2640 JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2647 procedure TGUIKeyRead2
.OnMessage(var Msg
: TMessage
);
2648 procedure actDefCtl ();
2651 if FDefControl
<> '' then
2652 SetActive(GetControl(FDefControl
))
2660 if not FEnabled
then
2666 if not FIsQuery
then
2669 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2672 if FActiveControl
<> Self
then
2676 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2678 if (FKeyIdx
= 0) then FKey0
:= 0 else FKey1
:= 0;
2681 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2686 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2699 VK_FIRSTKEY
..VK_LASTKEY
: // do not allow to bind virtual keys
2705 if (e_KeyNames
[wParam
] <> '') and not g_Console_MatchBind(wParam
, 'togglemenu') then
2707 if (FKeyIdx
= 0) then FKey0
:= wParam
else FKey1
:= wParam
;
2715 g_GUIGrabInput
:= FIsQuery
2721 constructor TGUIModelView
.Create
;
2728 destructor TGUIModelView
.Destroy
;
2735 procedure TGUIModelView
.Draw
;
2739 DrawBox(FX
, FY
, 4, 4);
2741 if FModel
<> nil then
2742 r_PlayerModel_Draw(FModel
, FX
+4, FY
+4);
2745 procedure TGUIModelView
.NextAnim();
2747 if FModel
= nil then
2750 if FModel
.Animation
< A_PAIN
then
2751 FModel
.ChangeAnimation(FModel
.Animation
+1, True)
2753 FModel
.ChangeAnimation(A_STAND
, True);
2756 procedure TGUIModelView
.NextWeapon();
2758 if FModel
= nil then
2761 if FModel
.Weapon
< WP_LAST
then
2762 FModel
.SetWeapon(FModel
.Weapon
+1)
2764 FModel
.SetWeapon(WEAPON_KASTET
);
2767 procedure TGUIModelView
.OnMessage(var Msg
: TMessage
);
2773 procedure TGUIModelView
.SetColor(Red
, Green
, Blue
: Byte);
2775 if FModel
<> nil then FModel
.SetColor(Red
, Green
, Blue
);
2778 procedure TGUIModelView
.SetModel(ModelName
: string);
2782 FModel
:= g_PlayerModel_Get(ModelName
);
2785 procedure TGUIModelView
.Update
;
2792 if FModel
<> nil then FModel
.Update
;
2797 constructor TGUIMapPreview
.Create();
2803 destructor TGUIMapPreview
.Destroy();
2809 procedure TGUIMapPreview
.Draw();
2816 DrawBox(FX
, FY
, MAPPREVIEW_WIDTH
, MAPPREVIEW_HEIGHT
);
2818 if (FMapSize
.X
<= 0) or (FMapSize
.Y
<= 0) then
2821 e_DrawFillQuad(FX
+4, FY
+4,
2822 FX
+4 + Trunc(FMapSize
.X
/ FScale
) - 1,
2823 FY
+4 + Trunc(FMapSize
.Y
/ FScale
) - 1,
2826 if FMapData
<> nil then
2827 for a
:= 0 to High(FMapData
) do
2830 if X1
> MAPPREVIEW_WIDTH
*16 then Continue
;
2831 if Y1
> MAPPREVIEW_HEIGHT
*16 then Continue
;
2833 if X2
< 0 then Continue
;
2834 if Y2
< 0 then Continue
;
2836 if X2
> MAPPREVIEW_WIDTH
*16 then X2
:= MAPPREVIEW_WIDTH
*16;
2837 if Y2
> MAPPREVIEW_HEIGHT
*16 then Y2
:= MAPPREVIEW_HEIGHT
*16;
2839 if X1
< 0 then X1
:= 0;
2840 if Y1
< 0 then Y1
:= 0;
2881 if ((X2
-X1
) > 0) and ((Y2
-Y1
) > 0) then
2882 e_DrawFillQuad(FX
+4 + X1
, FY
+4 + Y1
,
2883 FX
+4 + X2
- 1, FY
+4 + Y2
- 1, r
, g
, b
, 0);
2887 procedure TGUIMapPreview
.OnMessage(var Msg
: TMessage
);
2893 procedure TGUIMapPreview
.SetMap(Res
: string);
2898 //header: TMapHeaderRec_1;
2903 map
: TDynRecord
= nil;
2910 FileName
:= g_ExtractWadName(Res
);
2912 WAD
:= TWADFile
.Create();
2913 if not WAD
.ReadFile(FileName
) then
2919 //k8: ignores path again
2920 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
2929 map
:= g_Map_ParseMap(Data
, Len
);
2939 if (map
= nil) then exit
;
2942 panlist
:= map
.field
['panel'];
2943 //header := GetMapHeader(map);
2945 FMapSize
.X
:= map
.Width
div 16;
2946 FMapSize
.Y
:= map
.Height
div 16;
2948 rX
:= Ceil(map
.Width
/ (MAPPREVIEW_WIDTH
*256.0));
2949 rY
:= Ceil(map
.Height
/ (MAPPREVIEW_HEIGHT
*256.0));
2950 FScale
:= max(rX
, rY
);
2954 if (panlist
<> nil) then
2956 for pan
in panlist
do
2958 if (pan
.PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or
2959 PANEL_STEP
or PANEL_WATER
or
2960 PANEL_ACID1
or PANEL_ACID2
)) <> 0 then
2962 SetLength(FMapData
, Length(FMapData
)+1);
2963 with FMapData
[High(FMapData
)] do
2968 X2
:= (pan
.X
+ pan
.Width
) div 16;
2969 Y2
:= (pan
.Y
+ pan
.Height
) div 16;
2971 X1
:= Trunc(X1
/FScale
+ 0.5);
2972 Y1
:= Trunc(Y1
/FScale
+ 0.5);
2973 X2
:= Trunc(X2
/FScale
+ 0.5);
2974 Y2
:= Trunc(Y2
/FScale
+ 0.5);
2976 if (X1
<> X2
) or (Y1
<> Y2
) then
2984 PanelType
:= pan
.PanelType
;
2990 //writeln('freeing map');
2995 procedure TGUIMapPreview
.ClearMap();
2997 SetLength(FMapData
, 0);
3004 procedure TGUIMapPreview
.Update();
3010 function TGUIMapPreview
.GetScaleStr(): String;
3012 if FScale
> 0.0 then
3014 Result
:= FloatToStrF(FScale
*16.0, ffFixed
, 3, 3);
3015 while (Result
[Length(Result
)] = '0') do
3016 Delete(Result
, Length(Result
), 1);
3017 if (Result
[Length(Result
)] = ',') or (Result
[Length(Result
)] = '.') then
3018 Delete(Result
, Length(Result
), 1);
3019 Result
:= '1 : ' + Result
;
3027 procedure TGUIListBox
.AddItem(Item
: string);
3029 SetLength(FItems
, Length(FItems
)+1);
3030 FItems
[High(FItems
)] := Item
;
3032 if FSort
then g_gui
.Sort(FItems
);
3035 function TGUIListBox
.ItemExists (item
: String): Boolean;
3039 while (i
<= High(FItems
)) and (FItems
[i
] <> item
) do Inc(i
);
3040 result
:= i
<= High(FItems
)
3043 procedure TGUIListBox
.Clear
;
3051 constructor TGUIListBox
.Create(FontID
: DWORD
; Width
, Height
: Word);
3055 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
3060 FOnChangeEvent
:= nil;
3062 FDrawScroll
:= True;
3065 procedure TGUIListBox
.Draw
;
3073 if FDrawBack
then DrawBox(FX
, FY
, FWidth
+1, FHeight
);
3075 DrawScroll(FX
+4+FWidth
*16, FY
+4, FHeight
, (FStartLine
> 0) and (FItems
<> nil),
3076 (FStartLine
+FHeight
-1 < High(FItems
)) and (FItems
<> nil));
3078 if FItems
<> nil then
3079 for a
:= FStartLine
to Min(High(FItems
), FStartLine
+FHeight
-1) do
3083 FFont
.GetTextSize(s
, w2
, h2
);
3084 while (Length(s
) > 0) and (w2
> FWidth
*16) do
3086 SetLength(s
, Length(s
)-1);
3087 FFont
.GetTextSize(s
, w2
, h2
);
3091 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, s
, FActiveColor
.R
, FActiveColor
.G
, FActiveColor
.B
)
3093 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, s
, FUnActiveColor
.R
, FUnActiveColor
.G
, FUnActiveColor
.B
);
3097 function TGUIListBox
.GetHeight
: Integer;
3099 Result
:= 8+FHeight
*16;
3102 function TGUIListBox
.GetWidth
: Integer;
3104 Result
:= 8+(FWidth
+1)*16;
3107 procedure TGUIListBox
.OnMessage(var Msg
: TMessage
);
3111 if not FEnabled
then Exit
;
3115 if FItems
= nil then Exit
;
3128 FIndex
:= High(FItems
);
3129 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
3131 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
3135 if FIndex
< FStartLine
then Dec(FStartLine
);
3136 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3138 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
3139 if FIndex
< High(FItems
) then
3142 if FIndex
> FStartLine
+FHeight
-1 then Inc(FStartLine
);
3143 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3145 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
3148 if FActiveControl
<> Self
then SetActive(Self
)
3150 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
3151 else SetActive(nil);
3155 for a
:= 0 to High(FItems
) do
3156 if (Length(FItems
[a
]) > 0) and (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) then
3159 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
3160 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3166 function TGUIListBox
.SelectedItem(): String;
3170 if (FIndex
< 0) or (FItems
= nil) or
3171 (FIndex
> High(FItems
)) then
3174 Result
:= FItems
[FIndex
];
3177 procedure TGUIListBox
.FSetItems(Items
: SSArray
);
3179 if FItems
<> nil then
3187 if FSort
then g_gui
.Sort(FItems
);
3190 procedure TGUIListBox
.SelectItem(Item
: String);
3194 if FItems
= nil then
3198 Item
:= LowerCase(Item
);
3200 for a
:= 0 to High(FItems
) do
3201 if LowerCase(FItems
[a
]) = Item
then
3207 if FIndex
< FHeight
then
3210 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
3213 procedure TGUIListBox
.FSetIndex(aIndex
: Integer);
3215 if FItems
= nil then
3218 if (aIndex
< 0) or (aIndex
> High(FItems
)) then
3223 if FIndex
<= FHeight
then
3226 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
3231 procedure TGUIFileListBox
.OnMessage(var Msg
: TMessage
);
3233 a
, b
: Integer; s
: AnsiString;
3235 if not FEnabled
then
3238 if FItems
= nil then
3249 if @FOnChangeEvent
<> nil then
3250 FOnChangeEvent(Self
);
3255 FIndex
:= High(FItems
);
3256 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
3257 if @FOnChangeEvent
<> nil then
3258 FOnChangeEvent(Self
);
3261 IK_PAGEUP
, IK_KPPAGEUP
:
3263 if FIndex
> FHeight
then
3264 FIndex
:= FIndex
-FHeight
3268 if FStartLine
> FHeight
then
3269 FStartLine
:= FStartLine
-FHeight
3274 IK_PAGEDN
, IK_KPPAGEDN
:
3276 if FIndex
< High(FItems
)-FHeight
then
3277 FIndex
:= FIndex
+FHeight
3279 FIndex
:= High(FItems
);
3281 if FStartLine
< High(FItems
)-FHeight
then
3282 FStartLine
:= FStartLine
+FHeight
3284 FStartLine
:= High(FItems
)-FHeight
+1;
3287 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
, VK_UP
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
3291 if FIndex
< FStartLine
then
3293 if @FOnChangeEvent
<> nil then
3294 FOnChangeEvent(Self
);
3297 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
, VK_DOWN
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
3298 if FIndex
< High(FItems
) then
3301 if FIndex
> FStartLine
+FHeight
-1 then
3303 if @FOnChangeEvent
<> nil then
3304 FOnChangeEvent(Self
);
3307 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
3310 if FActiveControl
<> Self
then
3314 if FItems
[FIndex
][1] = #29 then // Ïàïêà
3316 if FItems
[FIndex
] = #29 + '..' then
3318 //e_LogWritefln('TGUIFileListBox: Upper dir "%s" -> "%s"', [FSubPath, e_UpperDir(FSubPath)]);
3319 FSubPath
:= e_UpperDir(FSubPath
)
3323 s
:= Copy(AnsiString(FItems
[FIndex
]), 2);
3324 //e_LogWritefln('TGUIFileListBox: Enter dir "%s" -> "%s"', [FSubPath, e_CatPath(FSubPath, s)]);
3325 FSubPath
:= e_CatPath(FSubPath
, s
);
3332 if FDefControl
<> '' then
3333 SetActive(GetControl(FDefControl
))
3341 for b
:= FIndex
+ 1 to High(FItems
) + FIndex
do
3343 a
:= b
mod Length(FItems
);
3344 if ( (Length(FItems
[a
]) > 0) and
3345 (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) ) or
3346 ( (Length(FItems
[a
]) > 1) and
3347 (FItems
[a
][1] = #29) and // Ïàïêà
3348 (LowerCase(FItems
[a
][2]) = LowerCase(Chr(wParam
))) ) then
3351 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
3352 if @FOnChangeEvent
<> nil then
3353 FOnChangeEvent(Self
);
3360 procedure TGUIFileListBox
.ScanDirs
;
3361 var i
, j
: Integer; path
: AnsiString; SR
: TSearchRec
; sm
, sc
: String;
3365 i
:= High(FBaseList
);
3368 path
:= e_CatPath(FBaseList
[i
], FSubPath
);
3371 if FindFirst(path
+ '/' + '*', faDirectory
, SR
) = 0 then
3374 if LongBool(SR
.Attr
and faDirectory
) then
3375 if (SR
.Name
<> '.') and ((FSubPath
<> '') or (SR
.Name
<> '..')) then
3376 if Self
.ItemExists(#1 + SR
.Name
) = false then
3377 Self
.AddItem(#1 + SR
.Name
)
3378 until FindNext(SR
) <> 0
3385 i
:= High(FBaseList
);
3388 path
:= e_CatPath(FBaseList
[i
], FSubPath
);
3394 j
:= length(sm
) + 1;
3395 sc
:= Copy(sm
, 1, j
- 1);
3397 if FindFirst(path
+ '/' + sc
, faAnyFile
, SR
) = 0 then
3400 if Self
.ItemExists(SR
.Name
) = false then
3402 until FindNext(SR
) <> 0
3409 for i
:= 0 to High(FItems
) do
3410 if FItems
[i
][1] = #1 then
3411 FItems
[i
][1] := #29;
3414 procedure TGUIFileListBox
.SetBase (dirs
: SSArray
; path
: String = '');
3421 function TGUIFileListBox
.SelectedItem (): String;
3425 if (FIndex
>= 0) and (FIndex
<= High(FItems
)) and (FItems
[FIndex
][1] <> '/') and (FItems
[FIndex
][1] <> '\') then
3427 s
:= e_CatPath(FSubPath
, FItems
[FIndex
]);
3428 if e_FindResource(FBaseList
, s
) = true then
3429 result
:= ExpandFileName(s
)
3431 e_LogWritefln('TGUIFileListBox.SelectedItem -> "%s"', [result
]);
3434 procedure TGUIFileListBox
.UpdateFileList();
3438 if (FIndex
= -1) or (FItems
= nil) or
3439 (FIndex
> High(FItems
)) or
3440 (FItems
[FIndex
][1] = '/') or
3441 (FItems
[FIndex
][1] = '\') then
3444 fn
:= FItems
[FIndex
];
3455 procedure TGUIMemo
.Clear
;
3461 constructor TGUIMemo
.Create(FontID
: DWORD
; Width
, Height
: Word);
3465 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
3470 FDrawScroll
:= True;
3473 procedure TGUIMemo
.Draw
;
3479 if FDrawBack
then DrawBox(FX
, FY
, FWidth
+1, FHeight
);
3481 DrawScroll(FX
+4+FWidth
*16, FY
+4, FHeight
, (FStartLine
> 0) and (FLines
<> nil),
3482 (FStartLine
+FHeight
-1 < High(FLines
)) and (FLines
<> nil));
3484 if FLines
<> nil then
3485 for a
:= FStartLine
to Min(High(FLines
), FStartLine
+FHeight
-1) do
3486 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, FLines
[a
], FColor
.R
, FColor
.G
, FColor
.B
);
3489 function TGUIMemo
.GetHeight
: Integer;
3491 Result
:= 8+FHeight
*16;
3494 function TGUIMemo
.GetWidth
: Integer;
3496 Result
:= 8+(FWidth
+1)*16;
3499 procedure TGUIMemo
.OnMessage(var Msg
: TMessage
);
3501 if not FEnabled
then Exit
;
3505 if FLines
= nil then Exit
;
3511 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
, VK_UP
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
3512 if FStartLine
> 0 then
3514 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
, VK_DOWN
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
3515 if FStartLine
< Length(FLines
)-FHeight
then
3517 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
3520 if FActiveControl
<> Self
then
3526 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
3527 else SetActive(nil);
3533 procedure TGUIMemo
.SetText(Text: string);
3536 FLines
:= GetLines(Text, FFont
.ID
, FWidth
*16);
3541 procedure TGUIimage
.ClearImage();
3543 if FImageRes
= '' then Exit
;
3545 g_Texture_Delete(FImageRes
);
3549 constructor TGUIimage
.Create();
3556 destructor TGUIimage
.Destroy();
3561 procedure TGUIimage
.Draw();
3567 if FImageRes
= '' then
3569 if g_Texture_Get(FDefaultRes
, ID
) then e_Draw(ID
, FX
, FY
, 0, True, False);
3572 if g_Texture_Get(FImageRes
, ID
) then e_Draw(ID
, FX
, FY
, 0, True, False);
3575 procedure TGUIimage
.OnMessage(var Msg
: TMessage
);
3580 procedure TGUIimage
.SetImage(Res
: string);
3584 if g_Texture_CreateWADEx(Res
, Res
) then FImageRes
:= Res
;
3587 procedure TGUIimage
.Update();