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
, 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
;
565 var i
, j
, len
, lines
: Integer;
567 function GetLine (j
, i
: Integer): String;
569 result
:= Copy(text, j
, i
- j
+ 1);
572 function GetWidth (j
, i
: Integer): Integer;
575 e_CharFont_GetSize(FontID
, GetLine(j
, i
), w
, h
);
580 result
:= nil; lines
:= 0;
581 j
:= 1; i
:= 1; len
:= Length(Text);
582 // e_LogWritefln('GetLines @%s len=%s [%s]', [MaxWidth, len, Text]);
585 (* --- Get longest possible sequence --- *)
586 while (i
+ 1 <= len
) and (GetWidth(j
, i
+ 1) <= MaxWidth
) do Inc(i
);
587 (* --- Do not include part of word --- *)
588 if (i
< len
) and (text[i
] <> ' ') then
589 while (i
>= j
) and (text[i
] <> ' ') do Dec(i
);
590 (* --- Do not include spaces --- *)
591 while (i
>= j
) and (text[i
] = ' ') do Dec(i
);
592 (* --- Add line --- *)
593 SetLength(result
, lines
+ 1);
594 result
[lines
] := GetLine(j
, i
);
595 // e_LogWritefln(' -> (%s:%s::%s) [%s]', [j, i, GetWidth(j, i), result[lines]]);
597 (* --- Skip spaces --- *)
598 while (i
<= len
) and (text[i
] = ' ') do Inc(i
);
603 procedure Sort (var a
: SSArray
);
604 var i
, j
: Integer; s
: string;
606 if a
= nil then Exit
;
608 for i
:= High(a
) downto Low(a
) do
609 for j
:= Low(a
) to High(a
) - 1 do
610 if LowerCase(a
[j
]) > LowerCase(a
[j
+ 1]) then
618 procedure g_GUI_Init();
620 g_Texture_Get(BOX1
, Box
[0]);
621 g_Texture_Get(BOX2
, Box
[1]);
622 g_Texture_Get(BOX3
, Box
[2]);
623 g_Texture_Get(BOX4
, Box
[3]);
624 g_Texture_Get(BOX5
, Box
[4]);
625 g_Texture_Get(BOX6
, Box
[5]);
626 g_Texture_Get(BOX7
, Box
[6]);
627 g_Texture_Get(BOX8
, Box
[7]);
628 g_Texture_Get(BOX9
, Box
[8]);
631 function g_GUI_Destroy(): Boolean;
635 Result
:= (Length(g_GUIWindows
) > 0);
637 for i
:= 0 to High(g_GUIWindows
) do
638 g_GUIWindows
[i
].Free();
641 g_ActiveWindow
:= nil;
644 function g_GUI_AddWindow(Window
: TGUIWindow
): TGUIWindow
;
646 SetLength(g_GUIWindows
, Length(g_GUIWindows
)+1);
647 g_GUIWindows
[High(g_GUIWindows
)] := Window
;
652 function g_GUI_GetWindow(Name
: string): TGUIWindow
;
658 if g_GUIWindows
<> nil then
659 for i
:= 0 to High(g_GUIWindows
) do
660 if g_GUIWindows
[i
].FName
= Name
then
662 Result
:= g_GUIWindows
[i
];
666 Assert(Result
<> nil, 'GUI_Window "'+Name
+'" not found');
669 procedure g_GUI_ShowWindow(Name
: string);
673 if g_GUIWindows
= nil then
676 for i
:= 0 to High(g_GUIWindows
) do
677 if g_GUIWindows
[i
].FName
= Name
then
679 g_GUIWindows
[i
].FPrevWindow
:= g_ActiveWindow
;
680 g_ActiveWindow
:= g_GUIWindows
[i
];
682 if g_ActiveWindow
.MainWindow
then
683 g_ActiveWindow
.FPrevWindow
:= nil;
685 if g_ActiveWindow
.FDefControl
<> '' then
686 g_ActiveWindow
.SetActive(g_ActiveWindow
.GetControl(g_ActiveWindow
.FDefControl
))
688 g_ActiveWindow
.SetActive(nil);
690 if @g_ActiveWindow
.FOnShowEvent
<> nil then
691 g_ActiveWindow
.FOnShowEvent();
697 procedure g_GUI_HideWindow(PlaySound
: Boolean = True);
699 if g_ActiveWindow
<> nil then
701 if @g_ActiveWindow
.OnClose
<> nil then
702 g_ActiveWindow
.OnClose();
703 g_ActiveWindow
:= g_ActiveWindow
.FPrevWindow
;
705 g_Sound_PlayEx(WINDOW_CLOSESOUND
);
709 procedure g_GUI_SaveMenuPos();
714 SetLength(Saved_Windows
, 0);
715 win
:= g_ActiveWindow
;
719 len
:= Length(Saved_Windows
);
720 SetLength(Saved_Windows
, len
+ 1);
722 Saved_Windows
[len
] := win
.Name
;
724 if win
.MainWindow
then
727 win
:= win
.FPrevWindow
;
731 procedure g_GUI_LoadMenuPos();
733 i
, j
, k
, len
: Integer;
736 g_ActiveWindow
:= nil;
737 len
:= Length(Saved_Windows
);
742 // Îêíî ñ ãëàâíûì ìåíþ:
743 g_GUI_ShowWindow(Saved_Windows
[len
-1]);
745 // Íå ïåðåêëþ÷èëîñü (èëè íåêóäà äàëüøå):
746 if (len
= 1) or (g_ActiveWindow
= nil) then
749 // Èùåì êíîïêè â îñòàëüíûõ îêíàõ:
750 for k
:= len
-1 downto 1 do
754 for i
:= 0 to Length(g_ActiveWindow
.Childs
)-1 do
756 if g_ActiveWindow
.Childs
[i
] is TGUIMainMenu
then
757 begin // GUI_MainMenu
758 with TGUIMainMenu(g_ActiveWindow
.Childs
[i
]) do
759 for j
:= 0 to Length(FButtons
)-1 do
760 if FButtons
[j
].ShowWindow
= Saved_Windows
[k
-1] then
762 FButtons
[j
].Click(True);
768 if g_ActiveWindow
.Childs
[i
] is TGUIMenu
then
769 with TGUIMenu(g_ActiveWindow
.Childs
[i
]) do
770 for j
:= 0 to Length(FItems
)-1 do
771 if FItems
[j
].ControlType
= TGUITextButton
then
772 if TGUITextButton(FItems
[j
].Control
).ShowWindow
= Saved_Windows
[k
-1] then
774 TGUITextButton(FItems
[j
].Control
).Click(True);
785 (g_ActiveWindow
.Name
= Saved_Windows
[k
]) then
790 procedure DrawBox(X
, Y
: Integer; Width
, Height
: Word);
792 e_Draw(Box
[0], X
, Y
, 0, False, False);
793 e_DrawFill(Box
[1], X
+4, Y
, Width
*4, 1, 0, False, False);
794 e_Draw(Box
[2], X
+4+Width
*16, Y
, 0, False, False);
795 e_DrawFill(Box
[3], X
, Y
+4, 1, Height
*4, 0, False, False);
796 e_DrawFill(Box
[4], X
+4, Y
+4, Width
, Height
, 0, False, False);
797 e_DrawFill(Box
[5], X
+4+Width
*16, Y
+4, 1, Height
*4, 0, False, False);
798 e_Draw(Box
[6], X
, Y
+4+Height
*16, 0, False, False);
799 e_DrawFill(Box
[7], X
+4, Y
+4+Height
*16, Width
*4, 1, 0, False, False);
800 e_Draw(Box
[8], X
+4+Width
*16, Y
+4+Height
*16, 0, False, False);
803 procedure DrawScroll(X
, Y
: Integer; Height
: Word; Up
, Down
: Boolean);
807 if Height
< 3 then Exit
;
810 g_Texture_Get(BSCROLL_UPA
, ID
)
812 g_Texture_Get(BSCROLL_UPU
, ID
);
813 e_Draw(ID
, X
, Y
, 0, False, False);
816 g_Texture_Get(BSCROLL_DOWNA
, ID
)
818 g_Texture_Get(BSCROLL_DOWNU
, ID
);
819 e_Draw(ID
, X
, Y
+(Height
-1)*16, 0, False, False);
821 g_Texture_Get(BSCROLL_MIDDLE
, ID
);
822 e_DrawFill(ID
, X
, Y
+16, 1, Height
-2, 0, False, False);
827 constructor TGUIWindow
.Create(Name
: string);
830 FActiveControl
:= nil;
834 FOnCloseEvent
:= nil;
838 destructor TGUIWindow
.Destroy
;
845 for i
:= 0 to High(Childs
) do
849 function TGUIWindow
.AddChild(Child
: TGUIControl
): TGUIControl
;
851 Child
.FWindow
:= Self
;
853 SetLength(Childs
, Length(Childs
) + 1);
854 Childs
[High(Childs
)] := Child
;
859 procedure TGUIWindow
.Update
;
863 for i
:= 0 to High(Childs
) do
864 if Childs
[i
] <> nil then Childs
[i
].Update
;
867 procedure TGUIWindow
.Draw
;
873 if FBackTexture
<> '' then // Here goes code duplication from g_game.pas:DrawMenuBackground()
874 if g_Texture_Get(FBackTexture
, ID
) then
877 e_GetTextureSize(ID
, @tw
, @th
);
879 tw
:= round(tw
* 1.333 * (gScreenHeight
/ th
))
881 tw
:= trunc(tw
* (gScreenHeight
/ th
));
882 e_DrawSize(ID
, (gScreenWidth
- tw
) div 2, 0, 0, False, False, tw
, gScreenHeight
);
885 e_Clear(0.5, 0.5, 0.5);
888 if FName
= 'AuthorsMenu' then
889 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
891 for i
:= 0 to High(Childs
) do
892 if Childs
[i
] <> nil then Childs
[i
].Draw
;
895 procedure TGUIWindow
.OnMessage(var Msg
: TMessage
);
897 if FActiveControl
<> nil then FActiveControl
.OnMessage(Msg
);
898 if @FOnKeyDown
<> nil then FOnKeyDown(Msg
.wParam
);
899 if @FOnKeyDownEx
<> nil then FOnKeyDownEx(self
, Msg
.wParam
);
901 if Msg
.Msg
= WM_KEYDOWN
then
913 procedure TGUIWindow
.SetActive(Control
: TGUIControl
);
915 FActiveControl
:= Control
;
918 function TGUIWindow
.GetControl(Name
: String): TGUIControl
;
924 if Childs
<> nil then
925 for i
:= 0 to High(Childs
) do
926 if Childs
[i
] <> nil then
927 if LowerCase(Childs
[i
].FName
) = LowerCase(Name
) then
933 Assert(Result
<> nil, 'Window Control "'+Name
+'" not Found!');
938 constructor TGUIControl
.Create();
944 FRightAlign
:= false;
948 procedure TGUIControl
.OnMessage(var Msg
: TMessage
);
954 procedure TGUIControl
.Update();
958 procedure TGUIControl
.Draw();
962 function TGUIControl
.WantActivationKey (key
: LongInt): Boolean;
967 function TGUIControl
.GetWidth(): Integer;
972 function TGUIControl
.GetHeight(): Integer;
979 procedure TGUITextButton
.Click(Silent
: Boolean = False);
981 if (FSound
<> '') and (not Silent
) then g_Sound_PlayEx(FSound
);
983 if @Proc
<> nil then Proc();
984 if @ProcEx
<> nil then ProcEx(self
);
986 if FShowWindow
<> '' then g_GUI_ShowWindow(FShowWindow
);
989 constructor TGUITextButton
.Create(aProc
: Pointer; FontID
: DWORD
; Text: string);
996 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
1001 destructor TGUITextButton
.Destroy
;
1007 procedure TGUITextButton
.Draw
;
1009 FFont
.Draw(FX
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
)
1012 function TGUITextButton
.GetHeight
: Integer;
1016 FFont
.GetTextSize(FText
, w
, h
);
1020 function TGUITextButton
.GetWidth
: Integer;
1024 FFont
.GetTextSize(FText
, w
, h
);
1028 procedure TGUITextButton
.OnMessage(var Msg
: TMessage
);
1030 if not FEnabled
then Exit
;
1037 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
: Click();
1042 procedure TGUITextButton
.Update
;
1049 constructor TFont
.Create(FontID
: DWORD
; FontType
: TFontType
);
1054 FFontType
:= FontType
;
1057 destructor TFont
.Destroy
;
1063 procedure TFont
.Draw(X
, Y
: Integer; Text: string; R
, G
, B
: Byte);
1065 if FFontType
= TFontType
.Character
then e_CharFont_PrintEx(ID
, X
, Y
, Text, _RGB(R
, G
, B
), FScale
)
1066 else e_TextureFontPrintEx(X
, Y
, Text, ID
, R
, G
, B
, FScale
);
1069 procedure TFont
.GetTextSize(Text: string; var w
, h
: Word);
1073 if FFontType
= TFontType
.Character
then e_CharFont_GetSize(ID
, Text, w
, h
)
1076 e_TextureFontGetSize(ID
, cw
, ch
);
1077 w
:= cw
*Length(Text);
1081 w
:= Round(w
*FScale
);
1082 h
:= Round(h
*FScale
);
1087 function TGUIMainMenu
.AddButton(fProc
: Pointer; Caption
: string; ShowWindow
: string = ''): TGUITextButton
;
1095 SetLength(FButtons
, Length(FButtons
)+1);
1096 FButtons
[High(FButtons
)] := TGUITextButton
.Create(fProc
, FFontID
, Caption
);
1097 FButtons
[High(FButtons
)].ShowWindow
:= ShowWindow
;
1098 with FButtons
[High(FButtons
)] do
1100 if (fProc
<> nil) or (ShowWindow
<> '') then FColor
:= MAINMENU_ITEMS_COLOR
1101 else FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
1102 FSound
:= MAINMENU_CLICKSOUND
;
1105 _x
:= gScreenWidth
div 2;
1107 for a
:= 0 to High(FButtons
) do
1108 if FButtons
[a
] <> nil then
1109 _x
:= Min(_x
, (gScreenWidth
div 2)-(FButtons
[a
].GetWidth
div 2));
1111 if FLogo
<> 0 then e_GetTextureSize(FLogo
, nil, @lh
);
1112 hh
:= FButtons
[High(FButtons
)].GetHeight
;
1114 if FLogo
<> 0 then h
:= lh
+ hh
* (1 + Length(FButtons
)) + MAINMENU_SPACE
* (Length(FButtons
) - 1)
1115 else h
:= hh
* (2 + Length(FButtons
)) + MAINMENU_SPACE
* (Length(FButtons
) - 1);
1116 h
:= (gScreenHeight
div 2) - (h
div 2);
1118 if FHeader
<> nil then with FHeader
do
1124 if FLogo
<> 0 then Inc(h
, lh
)
1127 for a
:= 0 to High(FButtons
) do
1129 if FButtons
[a
] <> nil then
1136 Inc(h
, hh
+MAINMENU_SPACE
);
1139 Result
:= FButtons
[High(FButtons
)];
1142 procedure TGUIMainMenu
.AddSpace
;
1144 SetLength(FButtons
, Length(FButtons
)+1);
1145 FButtons
[High(FButtons
)] := nil;
1148 constructor TGUIMainMenu
.Create(FontID
: DWORD
; Logo
, Header
: string);
1154 FCounter
:= MAINMENU_MARKERDELAY
;
1156 g_Texture_Get(MAINMENU_MARKER1
, FMarkerID1
);
1157 g_Texture_Get(MAINMENU_MARKER2
, FMarkerID2
);
1159 if not g_Texture_Get(Logo
, FLogo
) then
1161 FHeader
:= TGUILabel
.Create(Header
, FFontID
);
1164 FColor
:= MAINMENU_HEADER_COLOR
;
1165 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1166 FY
:= (gScreenHeight
div 2)-(GetHeight
div 2);
1171 destructor TGUIMainMenu
.Destroy
;
1175 if FButtons
<> nil then
1176 for a
:= 0 to High(FButtons
) do
1184 procedure TGUIMainMenu
.Draw
;
1192 if FHeader
<> nil then FHeader
.Draw
1194 e_GetTextureSize(FLogo
, @w
, @h
);
1195 e_Draw(FLogo
, ((gScreenWidth
div 2) - (w
div 2)), FButtons
[0].FY
- FButtons
[0].GetHeight
- h
, 0, True, False);
1198 if FButtons
<> nil then
1200 for a
:= 0 to High(FButtons
) do
1201 if FButtons
[a
] <> nil then FButtons
[a
].Draw
;
1203 if FIndex
<> -1 then
1204 e_Draw(FMarkerID1
, FButtons
[FIndex
].FX
-48, FButtons
[FIndex
].FY
, 0, True, False);
1208 procedure TGUIMainMenu
.EnableButton(aName
: string; e
: Boolean);
1212 if FButtons
= nil then Exit
;
1214 for a
:= 0 to High(FButtons
) do
1215 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= aName
) then
1217 if e
then FButtons
[a
].FColor
:= MAINMENU_ITEMS_COLOR
1218 else FButtons
[a
].FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
1219 FButtons
[a
].Enabled
:= e
;
1224 function TGUIMainMenu
.GetButton(aName
: string): TGUITextButton
;
1230 if FButtons
= nil then Exit
;
1232 for a
:= 0 to High(FButtons
) do
1233 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= aName
) then
1235 Result
:= FButtons
[a
];
1240 procedure TGUIMainMenu
.OnMessage(var Msg
: TMessage
);
1245 if not FEnabled
then Exit
;
1249 if FButtons
= nil then Exit
;
1252 for a
:= 0 to High(FButtons
) do
1253 if FButtons
[a
] <> nil then
1259 if not ok
then Exit
;
1264 IK_UP
, IK_KPUP
, VK_UP
, JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1268 if FIndex
< 0 then FIndex
:= High(FButtons
);
1269 until FButtons
[FIndex
] <> nil;
1271 g_Sound_PlayEx(MENU_CHANGESOUND
);
1273 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1277 if FIndex
> High(FButtons
) then FIndex
:= 0;
1278 until FButtons
[FIndex
] <> nil;
1280 g_Sound_PlayEx(MENU_CHANGESOUND
);
1282 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
;
1287 procedure TGUIMainMenu
.Update
;
1293 if FCounter
= 0 then
1296 FMarkerID1
:= FMarkerID2
;
1299 FCounter
:= MAINMENU_MARKERDELAY
;
1300 end else Dec(FCounter
);
1305 constructor TGUILabel
.Create(Text: string; FontID
: DWORD
);
1309 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
1313 FOnClickEvent
:= nil;
1316 procedure TGUILabel
.Draw
;
1322 FFont
.GetTextSize(FText
, w
, h
);
1323 FFont
.Draw(FX
+FMaxWidth
-w
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
);
1327 FFont
.Draw(FX
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
);
1331 function TGUILabel
.GetHeight
: Integer;
1335 FFont
.GetTextSize(FText
, w
, h
);
1339 function TGUILabel
.GetWidth
: Integer;
1343 if FFixedLen
= 0 then
1344 FFont
.GetTextSize(FText
, w
, h
)
1346 w
:= e_CharFont_GetMaxWidth(FFont
.ID
)*FFixedLen
;
1350 procedure TGUILabel
.OnMessage(var Msg
: TMessage
);
1352 if not FEnabled
then Exit
;
1359 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
: if @FOnClickEvent
<> nil then FOnClickEvent();
1366 function TGUIMenu
.AddButton(Proc
: Pointer; fText
: string; _ShowWindow
: string = ''): TGUITextButton
;
1373 Control
:= TGUITextButton
.Create(Proc
, FFontID
, fText
);
1374 with Control
as TGUITextButton
do
1376 ShowWindow
:= _ShowWindow
;
1377 FColor
:= MENU_ITEMSCTRL_COLOR
;
1381 ControlType
:= TGUITextButton
;
1383 Result
:= (Control
as TGUITextButton
);
1386 if FIndex
= -1 then FIndex
:= i
;
1391 procedure TGUIMenu
.AddLine(fText
: string);
1398 Text := TGUILabel
.Create(fText
, FFontID
);
1401 FColor
:= MENU_ITEMSTEXT_COLOR
;
1410 procedure TGUIMenu
.AddText(fText
: string; MaxWidth
: Word);
1415 l
:= GetLines(fText
, FFontID
, MaxWidth
);
1417 if l
= nil then Exit
;
1419 for a
:= 0 to High(l
) do
1424 Text := TGUILabel
.Create(l
[a
], FFontID
);
1427 with Text do begin FColor
:= _RGB(255, 0, 0); end;
1431 with Text do begin FColor
:= MENU_ITEMSTEXT_COLOR
; end;
1441 procedure TGUIMenu
.AddSpace
;
1455 constructor TGUIMenu
.Create(HeaderFont
, ItemsFont
: DWORD
; Header
: string);
1461 FFontID
:= ItemsFont
;
1462 FCounter
:= MENU_MARKERDELAY
;
1466 FHeader
:= TGUILabel
.Create(Header
, HeaderFont
);
1469 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1471 FColor
:= MAINMENU_HEADER_COLOR
;
1475 destructor TGUIMenu
.Destroy
;
1479 if FItems
<> nil then
1480 for a
:= 0 to High(FItems
) do
1494 procedure TGUIMenu
.Draw
;
1496 a
, locx
, locy
: Integer;
1500 if FHeader
<> nil then FHeader
.Draw
;
1502 if FItems
<> nil then
1503 for a
:= 0 to High(FItems
) do
1505 if FItems
[a
].Text <> nil then FItems
[a
].Text.Draw
;
1506 if FItems
[a
].Control
<> nil then FItems
[a
].Control
.Draw
;
1509 if (FIndex
<> -1) and (FCounter
> MENU_MARKERDELAY
div 2) then
1514 if FItems
[FIndex
].Text <> nil then
1516 locx
:= FItems
[FIndex
].Text.FX
;
1517 locy
:= FItems
[FIndex
].Text.FY
;
1519 if FItems
[FIndex
].Text.RightAlign
then
1521 locx
:= locx
+FItems
[FIndex
].Text.FMaxWidth
-FItems
[FIndex
].Text.GetWidth
;
1524 else if FItems
[FIndex
].Control
<> nil then
1526 locx
:= FItems
[FIndex
].Control
.FX
;
1527 locy
:= FItems
[FIndex
].Control
.FY
;
1530 locx
:= locx
-e_CharFont_GetMaxWidth(FFontID
);
1532 e_CharFont_PrintEx(FFontID
, locx
, locy
, #16, _RGB(255, 0, 0));
1536 function TGUIMenu
.GetControl(aName
: String): TGUIControl
;
1542 if FItems
<> nil then
1543 for a
:= 0 to High(FItems
) do
1544 if FItems
[a
].Control
<> nil then
1545 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(aName
) then
1547 Result
:= FItems
[a
].Control
;
1551 Assert(Result
<> nil, 'GUI control "'+aName
+'" not found!');
1554 function TGUIMenu
.GetControlsText(aName
: String): TGUILabel
;
1560 if FItems
<> nil then
1561 for a
:= 0 to High(FItems
) do
1562 if FItems
[a
].Control
<> nil then
1563 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(aName
) then
1565 Result
:= FItems
[a
].Text;
1569 Assert(Result
<> nil, 'GUI control''s text "'+aName
+'" not found!');
1572 function TGUIMenu
.NewItem
: Integer;
1574 SetLength(FItems
, Length(FItems
)+1);
1575 Result
:= High(FItems
);
1578 procedure TGUIMenu
.OnMessage(var Msg
: TMessage
);
1583 if not FEnabled
then Exit
;
1587 if FItems
= nil then Exit
;
1590 for a
:= 0 to High(FItems
) do
1591 if FItems
[a
].Control
<> nil then
1597 if not ok
then Exit
;
1599 if (Msg
.Msg
= WM_KEYDOWN
) and (FIndex
<> -1) and (FItems
[FIndex
].Control
<> nil) and
1600 (FItems
[FIndex
].Control
.WantActivationKey(Msg
.wParam
)) then
1602 FItems
[FIndex
].Control
.OnMessage(Msg
);
1603 g_Sound_PlayEx(MENU_CLICKSOUND
);
1611 IK_UP
, IK_KPUP
, VK_UP
,JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1616 if c
> Length(FItems
) then
1623 if FIndex
< 0 then FIndex
:= High(FItems
);
1624 until (FItems
[FIndex
].Control
<> nil) and
1625 (FItems
[FIndex
].Control
.Enabled
);
1629 g_Sound_PlayEx(MENU_CHANGESOUND
);
1632 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1637 if c
> Length(FItems
) then
1644 if FIndex
> High(FItems
) then FIndex
:= 0;
1645 until (FItems
[FIndex
].Control
<> nil) and
1646 (FItems
[FIndex
].Control
.Enabled
);
1650 g_Sound_PlayEx(MENU_CHANGESOUND
);
1653 IK_LEFT
, IK_RIGHT
, IK_KPLEFT
, IK_KPRIGHT
, VK_LEFT
, VK_RIGHT
,
1654 JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
,
1655 JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
1657 if FIndex
<> -1 then
1658 if FItems
[FIndex
].Control
<> nil then
1659 FItems
[FIndex
].Control
.OnMessage(Msg
);
1661 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
1663 if FIndex
<> -1 then
1665 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1667 g_Sound_PlayEx(MENU_CLICKSOUND
);
1671 if FYesNo
and (length(FItems
) > 1) then
1673 Msg
.wParam
:= IK_RETURN
; // to register keypress
1674 FIndex
:= High(FItems
)-1;
1675 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1678 if FYesNo
and (length(FItems
) > 1) then
1680 Msg
.wParam
:= IK_RETURN
; // to register keypress
1681 FIndex
:= High(FItems
);
1682 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1689 procedure TGUIMenu
.ReAlign();
1691 a
, tx
, cx
, w
, h
: Integer;
1692 cww
: array of Integer; // cached widths
1695 if FItems
= nil then Exit
;
1697 SetLength(cww
, length(FItems
));
1699 for a
:= 0 to High(FItems
) do
1701 if FItems
[a
].Text <> nil then
1703 cww
[a
] := FItems
[a
].Text.GetWidth
;
1704 if maxcww
< cww
[a
] then maxcww
:= cww
[a
];
1715 for a
:= 0 to High(FItems
) do
1718 if FItems
[a
].Text <> nil then w
:= FItems
[a
].Text.GetWidth
;
1719 if FItems
[a
].Control
<> nil then
1722 if FItems
[a
].ControlType
= TGUILabel
then w
:= w
+(FItems
[a
].Control
as TGUILabel
).GetWidth
1723 else if FItems
[a
].ControlType
= TGUITextButton
then w
:= w
+(FItems
[a
].Control
as TGUITextButton
).GetWidth
1724 else if FItems
[a
].ControlType
= TGUIScroll
then w
:= w
+(FItems
[a
].Control
as TGUIScroll
).GetWidth
1725 else if FItems
[a
].ControlType
= TGUISwitch
then w
:= w
+(FItems
[a
].Control
as TGUISwitch
).GetWidth
1726 else if FItems
[a
].ControlType
= TGUIEdit
then w
:= w
+(FItems
[a
].Control
as TGUIEdit
).GetWidth
1727 else if FItems
[a
].ControlType
= TGUIKeyRead
then w
:= w
+(FItems
[a
].Control
as TGUIKeyRead
).GetWidth
1728 else if FItems
[a
].ControlType
= TGUIKeyRead2
then w
:= w
+(FItems
[a
].Control
as TGUIKeyRead2
).GetWidth
1729 else if FItems
[a
].ControlType
= TGUIListBox
then w
:= w
+(FItems
[a
].Control
as TGUIListBox
).GetWidth
1730 else if FItems
[a
].ControlType
= TGUIFileListBox
then w
:= w
+(FItems
[a
].Control
as TGUIFileListBox
).GetWidth
1731 else if FItems
[a
].ControlType
= TGUIMemo
then w
:= w
+(FItems
[a
].Control
as TGUIMemo
).GetWidth
;
1733 tx
:= Min(tx
, (gScreenWidth
div 2)-(w
div 2));
1738 for a
:= 0 to High(FItems
) do
1742 if (Text <> nil) and (Control
= nil) then Continue
;
1744 if Text <> nil then w
:= tx
+Text.GetWidth
;
1745 if w
> cx
then cx
:= w
;
1749 cx
:= cx
+MENU_HSPACE
;
1751 h
:= FHeader
.GetHeight
*2+MENU_VSPACE
*(Length(FItems
)-1);
1753 for a
:= 0 to High(FItems
) do
1757 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then
1758 h
:= h
+(FItems
[a
].Control
as TGUIListBox
).GetHeight()
1760 h
:= h
+e_CharFont_GetMaxHeight(FFontID
);
1764 h
:= (gScreenHeight
div 2)-(h
div 2);
1768 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1771 Inc(h
, GetHeight
*2);
1774 for a
:= 0 to High(FItems
) do
1786 if Text.RightAlign
and (length(cww
) > a
) then
1788 //Text.FX := Text.FX+maxcww;
1789 Text.FMaxWidth
:= maxcww
;
1793 if Control
<> nil then
1810 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then Inc(h
, (Control
as TGUIListBox
).GetHeight
+MENU_VSPACE
)
1811 else if ControlType
= TGUIMemo
then Inc(h
, (Control
as TGUIMemo
).GetHeight
+MENU_VSPACE
)
1812 else Inc(h
, e_CharFont_GetMaxHeight(FFontID
)+MENU_VSPACE
);
1816 // another ugly hack
1817 if FYesNo
and (length(FItems
) > 1) then
1820 for a
:= High(FItems
)-1 to High(FItems
) do
1822 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1824 cx
:= (FItems
[a
].Control
as TGUITextButton
).GetWidth
;
1825 if cx
> w
then w
:= cx
;
1830 for a
:= High(FItems
)-1 to High(FItems
) do
1832 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1834 FItems
[a
].Control
.FX
:= (gScreenWidth
-w
) div 2;
1841 function TGUIMenu
.AddScroll(fText
: string): TGUIScroll
;
1848 Control
:= TGUIScroll
.Create();
1850 Text := TGUILabel
.Create(fText
, FFontID
);
1853 FColor
:= MENU_ITEMSTEXT_COLOR
;
1856 ControlType
:= TGUIScroll
;
1858 Result
:= (Control
as TGUIScroll
);
1861 if FIndex
= -1 then FIndex
:= i
;
1866 function TGUIMenu
.AddSwitch(fText
: string): TGUISwitch
;
1873 Control
:= TGUISwitch
.Create(FFontID
);
1874 (Control
as TGUISwitch
).FColor
:= MENU_ITEMSCTRL_COLOR
;
1876 Text := TGUILabel
.Create(fText
, FFontID
);
1879 FColor
:= MENU_ITEMSTEXT_COLOR
;
1882 ControlType
:= TGUISwitch
;
1884 Result
:= (Control
as TGUISwitch
);
1887 if FIndex
= -1 then FIndex
:= i
;
1892 function TGUIMenu
.AddEdit(fText
: string): TGUIEdit
;
1899 Control
:= TGUIEdit
.Create(FFontID
);
1900 with Control
as TGUIEdit
do
1902 FWindow
:= Self
.FWindow
;
1903 FColor
:= MENU_ITEMSCTRL_COLOR
;
1906 if fText
= '' then Text := nil else
1908 Text := TGUILabel
.Create(fText
, FFontID
);
1909 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1912 ControlType
:= TGUIEdit
;
1914 Result
:= (Control
as TGUIEdit
);
1917 if FIndex
= -1 then FIndex
:= i
;
1922 procedure TGUIMenu
.Update
;
1928 if FCounter
= 0 then FCounter
:= MENU_MARKERDELAY
else Dec(FCounter
);
1930 if FItems
<> nil then
1931 for a
:= 0 to High(FItems
) do
1932 if FItems
[a
].Control
<> nil then
1933 (FItems
[a
].Control
as FItems
[a
].ControlType
).Update
;
1936 function TGUIMenu
.AddKeyRead(fText
: string): TGUIKeyRead
;
1943 Control
:= TGUIKeyRead
.Create(FFontID
);
1944 with Control
as TGUIKeyRead
do
1946 FWindow
:= Self
.FWindow
;
1947 FColor
:= MENU_ITEMSCTRL_COLOR
;
1950 Text := TGUILabel
.Create(fText
, FFontID
);
1953 FColor
:= MENU_ITEMSTEXT_COLOR
;
1956 ControlType
:= TGUIKeyRead
;
1958 Result
:= (Control
as TGUIKeyRead
);
1961 if FIndex
= -1 then FIndex
:= i
;
1966 function TGUIMenu
.AddKeyRead2(fText
: string): TGUIKeyRead2
;
1973 Control
:= TGUIKeyRead2
.Create(FFontID
);
1974 with Control
as TGUIKeyRead2
do
1976 FWindow
:= Self
.FWindow
;
1977 FColor
:= MENU_ITEMSCTRL_COLOR
;
1980 Text := TGUILabel
.Create(fText
, FFontID
);
1983 FColor
:= MENU_ITEMSCTRL_COLOR
; //MENU_ITEMSTEXT_COLOR;
1987 ControlType
:= TGUIKeyRead2
;
1989 Result
:= (Control
as TGUIKeyRead2
);
1992 if FIndex
= -1 then FIndex
:= i
;
1997 function TGUIMenu
.AddList(fText
: string; Width
, Height
: Word): TGUIListBox
;
2004 Control
:= TGUIListBox
.Create(FFontID
, Width
, Height
);
2005 with Control
as TGUIListBox
do
2007 FWindow
:= Self
.FWindow
;
2008 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
2009 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
2012 Text := TGUILabel
.Create(fText
, FFontID
);
2015 FColor
:= MENU_ITEMSTEXT_COLOR
;
2018 ControlType
:= TGUIListBox
;
2020 Result
:= (Control
as TGUIListBox
);
2023 if FIndex
= -1 then FIndex
:= i
;
2028 function TGUIMenu
.AddFileList(fText
: string; Width
, Height
: Word): TGUIFileListBox
;
2035 Control
:= TGUIFileListBox
.Create(FFontID
, Width
, Height
);
2036 with Control
as TGUIFileListBox
do
2038 FWindow
:= Self
.FWindow
;
2039 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
2040 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
2043 if fText
= '' then Text := nil else
2045 Text := TGUILabel
.Create(fText
, FFontID
);
2046 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
2049 ControlType
:= TGUIFileListBox
;
2051 Result
:= (Control
as TGUIFileListBox
);
2054 if FIndex
= -1 then FIndex
:= i
;
2059 function TGUIMenu
.AddLabel(fText
: string): TGUILabel
;
2066 Control
:= TGUILabel
.Create('', FFontID
);
2067 with Control
as TGUILabel
do
2069 FWindow
:= Self
.FWindow
;
2070 FColor
:= MENU_ITEMSCTRL_COLOR
;
2073 Text := TGUILabel
.Create(fText
, FFontID
);
2076 FColor
:= MENU_ITEMSTEXT_COLOR
;
2079 ControlType
:= TGUILabel
;
2081 Result
:= (Control
as TGUILabel
);
2084 if FIndex
= -1 then FIndex
:= i
;
2089 function TGUIMenu
.AddMemo(fText
: string; Width
, Height
: Word): TGUIMemo
;
2096 Control
:= TGUIMemo
.Create(FFontID
, Width
, Height
);
2097 with Control
as TGUIMemo
do
2099 FWindow
:= Self
.FWindow
;
2100 FColor
:= MENU_ITEMSTEXT_COLOR
;
2103 if fText
= '' then Text := nil else
2105 Text := TGUILabel
.Create(fText
, FFontID
);
2106 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
2109 ControlType
:= TGUIMemo
;
2111 Result
:= (Control
as TGUIMemo
);
2114 if FIndex
= -1 then FIndex
:= i
;
2119 procedure TGUIMenu
.UpdateIndex();
2127 if (FIndex
< 0) or (FIndex
> High(FItems
)) then
2133 if FItems
[FIndex
].Control
.Enabled
then
2142 constructor TGUIScroll
.Create
;
2147 FOnChangeEvent
:= nil;
2149 g_Texture_Get(SCROLL_LEFT
, FLeftID
);
2150 g_Texture_Get(SCROLL_RIGHT
, FRightID
);
2151 g_Texture_Get(SCROLL_MIDDLE
, FMiddleID
);
2152 g_Texture_Get(SCROLL_MARKER
, FMarkerID
);
2155 procedure TGUIScroll
.Draw
;
2161 e_Draw(FLeftID
, FX
, FY
, 0, True, False);
2162 e_Draw(FRightID
, FX
+8+(FMax
+1)*8, FY
, 0, True, False);
2164 for a
:= 0 to FMax
do
2165 e_Draw(FMiddleID
, FX
+8+a
*8, FY
, 0, True, False);
2167 e_Draw(FMarkerID
, FX
+8+FValue
*8, FY
, 0, True, False);
2170 procedure TGUIScroll
.FSetValue(a
: Integer);
2172 if a
> FMax
then FValue
:= FMax
else FValue
:= a
;
2175 function TGUIScroll
.GetWidth
: Integer;
2177 Result
:= 16+(FMax
+1)*8;
2180 procedure TGUIScroll
.OnMessage(var Msg
: TMessage
);
2182 if not FEnabled
then Exit
;
2190 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2194 g_Sound_PlayEx(SCROLL_SUBSOUND
);
2195 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2197 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2198 if FValue
< FMax
then
2201 g_Sound_PlayEx(SCROLL_ADDSOUND
);
2202 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2209 procedure TGUIScroll
.Update
;
2217 procedure TGUISwitch
.AddItem(Item
: string);
2219 SetLength(FItems
, Length(FItems
)+1);
2220 FItems
[High(FItems
)] := Item
;
2222 if FIndex
= -1 then FIndex
:= 0;
2225 constructor TGUISwitch
.Create(FontID
: DWORD
);
2231 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2234 procedure TGUISwitch
.Draw
;
2238 FFont
.Draw(FX
, FY
, FItems
[FIndex
], FColor
.R
, FColor
.G
, FColor
.B
);
2241 function TGUISwitch
.GetText
: string;
2243 if FIndex
<> -1 then Result
:= FItems
[FIndex
]
2247 function TGUISwitch
.GetWidth
: Integer;
2254 if FItems
= nil then Exit
;
2256 for a
:= 0 to High(FItems
) do
2258 FFont
.GetTextSize(FItems
[a
], w
, h
);
2259 if w
> Result
then Result
:= w
;
2263 procedure TGUISwitch
.OnMessage(var Msg
: TMessage
);
2265 if not FEnabled
then Exit
;
2269 if FItems
= nil then Exit
;
2274 IK_RETURN
, IK_RIGHT
, IK_KPRETURN
, IK_KPRIGHT
, VK_FIRE
, VK_OPEN
, VK_RIGHT
,
2275 JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
,
2276 JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2278 if FIndex
< High(FItems
) then
2283 g_Sound_PlayEx(SCROLL_ADDSOUND
);
2285 if @FOnChangeEvent
<> nil then
2286 FOnChangeEvent(Self
);
2289 IK_LEFT
, IK_KPLEFT
, VK_LEFT
,
2290 JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2295 FIndex
:= High(FItems
);
2297 g_Sound_PlayEx(SCROLL_SUBSOUND
);
2299 if @FOnChangeEvent
<> nil then
2300 FOnChangeEvent(Self
);
2306 procedure TGUISwitch
.Update
;
2314 constructor TGUIEdit
.Create(FontID
: DWORD
);
2318 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2324 g_Texture_Get(EDIT_LEFT
, FLeftID
);
2325 g_Texture_Get(EDIT_RIGHT
, FRightID
);
2326 g_Texture_Get(EDIT_MIDDLE
, FMiddleID
);
2329 procedure TGUIEdit
.Draw
;
2336 e_Draw(FLeftID
, FX
, FY
, 0, True, False);
2337 e_Draw(FRightID
, FX
+8+FWidth
*16, FY
, 0, True, False);
2339 for c
:= 0 to FWidth
-1 do
2340 e_Draw(FMiddleID
, FX
+8+c
*16, FY
, 0, True, False);
2345 if FInvalid
and (FWindow
.FActiveControl
<> self
) then begin r
:= 128; g
:= 128; b
:= 128; end;
2346 FFont
.Draw(FX
+8, FY
, FText
, r
, g
, b
);
2348 if (FWindow
.FActiveControl
= self
) then
2350 FFont
.GetTextSize(Copy(FText
, 1, FCaretPos
), w
, h
);
2351 h
:= e_CharFont_GetMaxHeight(FFont
.ID
);
2352 e_DrawLine(2, FX
+8+w
, FY
+h
-3, FX
+8+w
+EDIT_CURSORLEN
, FY
+h
-3,
2353 EDIT_CURSORCOLOR
.R
, EDIT_CURSORCOLOR
.G
, EDIT_CURSORCOLOR
.B
);
2357 function TGUIEdit
.GetWidth
: Integer;
2359 Result
:= 16+FWidth
*16;
2362 procedure TGUIEdit
.OnMessage(var Msg
: TMessage
);
2364 if not FEnabled
then Exit
;
2373 if (wParam
in [48..57]) and (Chr(wParam
) <> '`') then
2374 if Length(Text) < FMaxLength
then
2376 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2382 if (wParam
in [32..255]) and (Chr(wParam
) <> '`') then
2383 if Length(Text) < FMaxLength
then
2385 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2393 Delete(FText
, FCaretPos
, 1);
2394 if FCaretPos
> 0 then Dec(FCaretPos
);
2396 IK_DELETE
: Delete(FText
, FCaretPos
+ 1, 1);
2397 IK_END
, IK_KPEND
: FCaretPos
:= Length(FText
);
2398 IK_HOME
, IK_KPHOME
: FCaretPos
:= 0;
2399 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
: if FCaretPos
> 0 then Dec(FCaretPos
);
2400 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
: if FCaretPos
< Length(FText
) then Inc(FCaretPos
);
2401 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2404 if FActiveControl
<> Self
then
2407 if @FOnEnterEvent
<> nil then FOnEnterEvent(Self
);
2411 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
2412 else SetActive(nil);
2413 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2419 g_GUIGrabInput
:= (@FOnEnterEvent
= nil) and (FWindow
.FActiveControl
= Self
);
2420 g_Touch_ShowKeyboard(g_GUIGrabInput
)
2423 procedure TGUIEdit
.SetText(Text: string);
2425 if Length(Text) > FMaxLength
then SetLength(Text, FMaxLength
);
2427 FCaretPos
:= Length(FText
);
2430 procedure TGUIEdit
.Update
;
2437 constructor TGUIKeyRead
.Create(FontID
: DWORD
);
2443 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2446 procedure TGUIKeyRead
.Draw
;
2450 FFont
.Draw(FX
, FY
, IfThen(FIsQuery
, KEYREAD_QUERY
, IfThen(FKey
<> 0, e_KeyNames
[FKey
], KEYREAD_CLEAR
)),
2451 FColor
.R
, FColor
.G
, FColor
.B
);
2454 function TGUIKeyRead
.GetWidth
: Integer;
2461 for a
:= 0 to 255 do
2463 FFont
.GetTextSize(e_KeyNames
[a
], w
, h
);
2464 Result
:= Max(Result
, w
);
2467 FFont
.GetTextSize(KEYREAD_QUERY
, w
, h
);
2468 if w
> Result
then Result
:= w
;
2470 FFont
.GetTextSize(KEYREAD_CLEAR
, w
, h
);
2471 if w
> Result
then Result
:= w
;
2474 function TGUIKeyRead
.WantActivationKey (key
: LongInt): Boolean;
2477 (key
= IK_BACKSPACE
) or
2481 procedure TGUIKeyRead
.OnMessage(var Msg
: TMessage
);
2482 procedure actDefCtl ();
2485 if FDefControl
<> '' then
2486 SetActive(GetControl(FDefControl
))
2494 if not FEnabled
then
2503 if FIsQuery
then actDefCtl();
2506 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2508 if not FIsQuery
then
2511 if FActiveControl
<> Self
then
2516 else if (wParam
< VK_FIRSTKEY
) and (wParam
> VK_LASTKEY
) then
2518 // FKey := IK_ENTER; // <Enter>
2524 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2526 if not FIsQuery
then
2536 if not FIsQuery
and (wParam
= IK_BACKSPACE
) then
2541 else if FIsQuery
then
2544 IK_ENTER
, IK_KPRETURN
, VK_FIRSTKEY
..VK_LASTKEY (*, JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK*): // Not <Enter
2546 if e_KeyNames
[wParam
] <> '' then
2555 g_GUIGrabInput
:= FIsQuery
2560 constructor TGUIKeyRead2
.Create(FontID
: DWORD
);
2573 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2575 FMaxKeyNameWdt
:= 0;
2576 for a
:= 0 to 255 do
2578 FFont
.GetTextSize(e_KeyNames
[a
], w
, h
);
2579 FMaxKeyNameWdt
:= Max(FMaxKeyNameWdt
, w
);
2582 FMaxKeyNameWdt
:= FMaxKeyNameWdt
-(FMaxKeyNameWdt
div 3);
2584 FFont
.GetTextSize(KEYREAD_QUERY
, w
, h
);
2585 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2587 FFont
.GetTextSize(KEYREAD_CLEAR
, w
, h
);
2588 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2591 procedure TGUIKeyRead2
.Draw
;
2592 procedure drawText (idx
: Integer);
2598 if idx
= 0 then kk
:= FKey0
else kk
:= FKey1
;
2600 if idx
= 0 then x
:= FX
+8 else x
:= FX
+8+FMaxKeyNameWdt
+16;
2604 if FKeyIdx
= idx
then begin r
:= 255; g
:= 255; b
:= 255; end;
2605 if FIsQuery
and (FKeyIdx
= idx
) then
2606 FFont
.Draw(x
, y
, KEYREAD_QUERY
, r
, g
, b
)
2608 FFont
.Draw(x
, y
, IfThen(kk
<> 0, e_KeyNames
[kk
], KEYREAD_CLEAR
), r
, g
, b
);
2614 //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);
2615 //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);
2620 function TGUIKeyRead2
.GetWidth
: Integer;
2622 Result
:= FMaxKeyNameWdt
*2+8+8+16;
2625 function TGUIKeyRead2
.WantActivationKey (key
: LongInt): Boolean;
2628 IK_BACKSPACE
, IK_LEFT
, IK_RIGHT
, IK_KPLEFT
, IK_KPRIGHT
, VK_LEFT
, VK_RIGHT
,
2629 JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
,
2630 JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2637 procedure TGUIKeyRead2
.OnMessage(var Msg
: TMessage
);
2638 procedure actDefCtl ();
2641 if FDefControl
<> '' then
2642 SetActive(GetControl(FDefControl
))
2650 if not FEnabled
then
2659 if FIsQuery
then actDefCtl();
2662 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2664 if not FIsQuery
then
2667 if FActiveControl
<> Self
then
2672 else if (wParam
< VK_FIRSTKEY
) and (wParam
> VK_LASTKEY
) then
2674 // if (FKeyIdx = 0) then FKey0 := IK_ENTER else FKey1 := IK_ENTER; // <Enter>
2675 if (FKeyIdx
= 0) then FKey0
:= wParam
else FKey1
:= wParam
;
2680 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2682 if not FIsQuery
then
2684 if (FKeyIdx
= 0) then FKey0
:= 0 else FKey1
:= 0;
2688 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2689 if not FIsQuery
then
2694 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2695 if not FIsQuery
then
2704 if not FIsQuery
and (wParam
= IK_BACKSPACE
) then
2706 if (FKeyIdx
= 0) then FKey0
:= 0 else FKey1
:= 0;
2709 else if FIsQuery
then
2712 IK_ENTER
, IK_KPRETURN
, VK_FIRSTKEY
..VK_LASTKEY (*, JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK*): // Not <Enter
2714 if e_KeyNames
[wParam
] <> '' then
2716 if (FKeyIdx
= 0) then FKey0
:= wParam
else FKey1
:= wParam
;
2725 g_GUIGrabInput
:= FIsQuery
2731 constructor TGUIModelView
.Create
;
2738 destructor TGUIModelView
.Destroy
;
2745 procedure TGUIModelView
.Draw
;
2749 DrawBox(FX
, FY
, 4, 4);
2751 if FModel
<> nil then
2752 r_PlayerModel_Draw(FModel
, FX
+4, FY
+4);
2755 procedure TGUIModelView
.NextAnim();
2757 if FModel
= nil then
2760 if FModel
.Animation
< A_PAIN
then
2761 FModel
.ChangeAnimation(FModel
.Animation
+1, True)
2763 FModel
.ChangeAnimation(A_STAND
, True);
2766 procedure TGUIModelView
.NextWeapon();
2768 if FModel
= nil then
2771 if FModel
.Weapon
< WP_LAST
then
2772 FModel
.SetWeapon(FModel
.Weapon
+1)
2774 FModel
.SetWeapon(WEAPON_KASTET
);
2777 procedure TGUIModelView
.OnMessage(var Msg
: TMessage
);
2783 procedure TGUIModelView
.SetColor(Red
, Green
, Blue
: Byte);
2785 if FModel
<> nil then FModel
.SetColor(Red
, Green
, Blue
);
2788 procedure TGUIModelView
.SetModel(ModelName
: string);
2792 FModel
:= g_PlayerModel_Get(ModelName
);
2795 procedure TGUIModelView
.Update
;
2802 if FModel
<> nil then FModel
.Update
;
2807 constructor TGUIMapPreview
.Create();
2813 destructor TGUIMapPreview
.Destroy();
2819 procedure TGUIMapPreview
.Draw();
2826 DrawBox(FX
, FY
, MAPPREVIEW_WIDTH
, MAPPREVIEW_HEIGHT
);
2828 if (FMapSize
.X
<= 0) or (FMapSize
.Y
<= 0) then
2831 e_DrawFillQuad(FX
+4, FY
+4,
2832 FX
+4 + Trunc(FMapSize
.X
/ FScale
) - 1,
2833 FY
+4 + Trunc(FMapSize
.Y
/ FScale
) - 1,
2836 if FMapData
<> nil then
2837 for a
:= 0 to High(FMapData
) do
2840 if X1
> MAPPREVIEW_WIDTH
*16 then Continue
;
2841 if Y1
> MAPPREVIEW_HEIGHT
*16 then Continue
;
2843 if X2
< 0 then Continue
;
2844 if Y2
< 0 then Continue
;
2846 if X2
> MAPPREVIEW_WIDTH
*16 then X2
:= MAPPREVIEW_WIDTH
*16;
2847 if Y2
> MAPPREVIEW_HEIGHT
*16 then Y2
:= MAPPREVIEW_HEIGHT
*16;
2849 if X1
< 0 then X1
:= 0;
2850 if Y1
< 0 then Y1
:= 0;
2891 if ((X2
-X1
) > 0) and ((Y2
-Y1
) > 0) then
2892 e_DrawFillQuad(FX
+4 + X1
, FY
+4 + Y1
,
2893 FX
+4 + X2
- 1, FY
+4 + Y2
- 1, r
, g
, b
, 0);
2897 procedure TGUIMapPreview
.OnMessage(var Msg
: TMessage
);
2903 procedure TGUIMapPreview
.SetMap(Res
: string);
2908 //header: TMapHeaderRec_1;
2913 map
: TDynRecord
= nil;
2920 FileName
:= g_ExtractWadName(Res
);
2922 WAD
:= TWADFile
.Create();
2923 if not WAD
.ReadFile(FileName
) then
2929 //k8: ignores path again
2930 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
2939 map
:= g_Map_ParseMap(Data
, Len
);
2949 if (map
= nil) then exit
;
2952 panlist
:= map
.field
['panel'];
2953 //header := GetMapHeader(map);
2955 FMapSize
.X
:= map
.Width
div 16;
2956 FMapSize
.Y
:= map
.Height
div 16;
2958 rX
:= Ceil(map
.Width
/ (MAPPREVIEW_WIDTH
*256.0));
2959 rY
:= Ceil(map
.Height
/ (MAPPREVIEW_HEIGHT
*256.0));
2960 FScale
:= max(rX
, rY
);
2964 if (panlist
<> nil) then
2966 for pan
in panlist
do
2968 if (pan
.PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or
2969 PANEL_STEP
or PANEL_WATER
or
2970 PANEL_ACID1
or PANEL_ACID2
)) <> 0 then
2972 SetLength(FMapData
, Length(FMapData
)+1);
2973 with FMapData
[High(FMapData
)] do
2978 X2
:= (pan
.X
+ pan
.Width
) div 16;
2979 Y2
:= (pan
.Y
+ pan
.Height
) div 16;
2981 X1
:= Trunc(X1
/FScale
+ 0.5);
2982 Y1
:= Trunc(Y1
/FScale
+ 0.5);
2983 X2
:= Trunc(X2
/FScale
+ 0.5);
2984 Y2
:= Trunc(Y2
/FScale
+ 0.5);
2986 if (X1
<> X2
) or (Y1
<> Y2
) then
2994 PanelType
:= pan
.PanelType
;
3000 //writeln('freeing map');
3005 procedure TGUIMapPreview
.ClearMap();
3007 SetLength(FMapData
, 0);
3014 procedure TGUIMapPreview
.Update();
3020 function TGUIMapPreview
.GetScaleStr(): String;
3022 if FScale
> 0.0 then
3024 Result
:= FloatToStrF(FScale
*16.0, ffFixed
, 3, 3);
3025 while (Result
[Length(Result
)] = '0') do
3026 Delete(Result
, Length(Result
), 1);
3027 if (Result
[Length(Result
)] = ',') or (Result
[Length(Result
)] = '.') then
3028 Delete(Result
, Length(Result
), 1);
3029 Result
:= '1 : ' + Result
;
3037 procedure TGUIListBox
.AddItem(Item
: string);
3039 SetLength(FItems
, Length(FItems
)+1);
3040 FItems
[High(FItems
)] := Item
;
3042 if FSort
then g_gui
.Sort(FItems
);
3045 function TGUIListBox
.ItemExists (item
: String): Boolean;
3049 while (i
<= High(FItems
)) and (FItems
[i
] <> item
) do Inc(i
);
3050 result
:= i
<= High(FItems
)
3053 procedure TGUIListBox
.Clear
;
3061 constructor TGUIListBox
.Create(FontID
: DWORD
; Width
, Height
: Word);
3065 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
3070 FOnChangeEvent
:= nil;
3072 FDrawScroll
:= True;
3075 procedure TGUIListBox
.Draw
;
3083 if FDrawBack
then DrawBox(FX
, FY
, FWidth
+1, FHeight
);
3085 DrawScroll(FX
+4+FWidth
*16, FY
+4, FHeight
, (FStartLine
> 0) and (FItems
<> nil),
3086 (FStartLine
+FHeight
-1 < High(FItems
)) and (FItems
<> nil));
3088 if FItems
<> nil then
3089 for a
:= FStartLine
to Min(High(FItems
), FStartLine
+FHeight
-1) do
3093 FFont
.GetTextSize(s
, w2
, h2
);
3094 while (Length(s
) > 0) and (w2
> FWidth
*16) do
3096 SetLength(s
, Length(s
)-1);
3097 FFont
.GetTextSize(s
, w2
, h2
);
3101 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, s
, FActiveColor
.R
, FActiveColor
.G
, FActiveColor
.B
)
3103 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, s
, FUnActiveColor
.R
, FUnActiveColor
.G
, FUnActiveColor
.B
);
3107 function TGUIListBox
.GetHeight
: Integer;
3109 Result
:= 8+FHeight
*16;
3112 function TGUIListBox
.GetWidth
: Integer;
3114 Result
:= 8+(FWidth
+1)*16;
3117 procedure TGUIListBox
.OnMessage(var Msg
: TMessage
);
3121 if not FEnabled
then Exit
;
3125 if FItems
= nil then Exit
;
3138 FIndex
:= High(FItems
);
3139 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
3141 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
3145 if FIndex
< FStartLine
then Dec(FStartLine
);
3146 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3148 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
3149 if FIndex
< High(FItems
) then
3152 if FIndex
> FStartLine
+FHeight
-1 then Inc(FStartLine
);
3153 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3155 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
3158 if FActiveControl
<> Self
then SetActive(Self
)
3160 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
3161 else SetActive(nil);
3165 for a
:= 0 to High(FItems
) do
3166 if (Length(FItems
[a
]) > 0) and (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) then
3169 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
3170 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3176 function TGUIListBox
.SelectedItem(): String;
3180 if (FIndex
< 0) or (FItems
= nil) or
3181 (FIndex
> High(FItems
)) then
3184 Result
:= FItems
[FIndex
];
3187 procedure TGUIListBox
.FSetItems(Items
: SSArray
);
3189 if FItems
<> nil then
3197 if FSort
then g_gui
.Sort(FItems
);
3200 procedure TGUIListBox
.SelectItem(Item
: String);
3204 if FItems
= nil then
3208 Item
:= LowerCase(Item
);
3210 for a
:= 0 to High(FItems
) do
3211 if LowerCase(FItems
[a
]) = Item
then
3217 if FIndex
< FHeight
then
3220 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
3223 procedure TGUIListBox
.FSetIndex(aIndex
: Integer);
3225 if FItems
= nil then
3228 if (aIndex
< 0) or (aIndex
> High(FItems
)) then
3233 if FIndex
<= FHeight
then
3236 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
3241 procedure TGUIFileListBox
.OnMessage(var Msg
: TMessage
);
3243 a
, b
: Integer; s
: AnsiString;
3245 if not FEnabled
then
3248 if FItems
= nil then
3259 if @FOnChangeEvent
<> nil then
3260 FOnChangeEvent(Self
);
3265 FIndex
:= High(FItems
);
3266 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
3267 if @FOnChangeEvent
<> nil then
3268 FOnChangeEvent(Self
);
3271 IK_PAGEUP
, IK_KPPAGEUP
:
3273 if FIndex
> FHeight
then
3274 FIndex
:= FIndex
-FHeight
3278 if FStartLine
> FHeight
then
3279 FStartLine
:= FStartLine
-FHeight
3284 IK_PAGEDN
, IK_KPPAGEDN
:
3286 if FIndex
< High(FItems
)-FHeight
then
3287 FIndex
:= FIndex
+FHeight
3289 FIndex
:= High(FItems
);
3291 if FStartLine
< High(FItems
)-FHeight
then
3292 FStartLine
:= FStartLine
+FHeight
3294 FStartLine
:= High(FItems
)-FHeight
+1;
3297 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
, VK_UP
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
3301 if FIndex
< FStartLine
then
3303 if @FOnChangeEvent
<> nil then
3304 FOnChangeEvent(Self
);
3307 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
, VK_DOWN
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
3308 if FIndex
< High(FItems
) then
3311 if FIndex
> FStartLine
+FHeight
-1 then
3313 if @FOnChangeEvent
<> nil then
3314 FOnChangeEvent(Self
);
3317 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
3320 if FActiveControl
<> Self
then
3324 if FItems
[FIndex
][1] = #29 then // Ïàïêà
3326 if FItems
[FIndex
] = #29 + '..' then
3328 e_LogWritefln('TGUIFileListBox: Upper dir "%s" -> "%s"', [FSubPath
, e_UpperDir(FSubPath
)]);
3329 FSubPath
:= e_UpperDir(FSubPath
)
3333 s
:= Copy(AnsiString(FItems
[FIndex
]), 2);
3334 e_LogWritefln('TGUIFileListBox: Enter dir "%s" -> "%s"', [FSubPath
, e_CatPath(FSubPath
, s
)]);
3335 FSubPath
:= e_CatPath(FSubPath
, s
);
3342 if FDefControl
<> '' then
3343 SetActive(GetControl(FDefControl
))
3351 for b
:= FIndex
+ 1 to High(FItems
) + FIndex
do
3353 a
:= b
mod Length(FItems
);
3354 if ( (Length(FItems
[a
]) > 0) and
3355 (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) ) or
3356 ( (Length(FItems
[a
]) > 1) and
3357 (FItems
[a
][1] = #29) and // Ïàïêà
3358 (LowerCase(FItems
[a
][2]) = LowerCase(Chr(wParam
))) ) then
3361 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
3362 if @FOnChangeEvent
<> nil then
3363 FOnChangeEvent(Self
);
3370 procedure TGUIFileListBox
.ScanDirs
;
3371 var i
, j
: Integer; path
: AnsiString; SR
: TSearchRec
; sm
, sc
: String;
3375 i
:= High(FBaseList
);
3378 path
:= e_CatPath(FBaseList
[i
], FSubPath
);
3381 if FindFirst(path
+ '/' + '*', faDirectory
, SR
) = 0 then
3384 if LongBool(SR
.Attr
and faDirectory
) then
3385 if (SR
.Name
<> '.') and ((FSubPath
<> '') or (SR
.Name
<> '..')) then
3386 if Self
.ItemExists(#1 + SR
.Name
) = false then
3387 Self
.AddItem(#1 + SR
.Name
)
3388 until FindNext(SR
) <> 0
3395 i
:= High(FBaseList
);
3398 path
:= e_CatPath(FBaseList
[i
], FSubPath
);
3404 j
:= length(sm
) + 1;
3405 sc
:= Copy(sm
, 1, j
- 1);
3407 if FindFirst(path
+ '/' + sc
, faAnyFile
, SR
) = 0 then
3410 if Self
.ItemExists(SR
.Name
) = false then
3412 until FindNext(SR
) <> 0
3419 for i
:= 0 to High(FItems
) do
3420 if FItems
[i
][1] = #1 then
3421 FItems
[i
][1] := #29;
3424 procedure TGUIFileListBox
.SetBase (dirs
: SSArray
; path
: String = '');
3431 function TGUIFileListBox
.SelectedItem (): String;
3435 if (FIndex
>= 0) and (FIndex
<= High(FItems
)) and (FItems
[FIndex
][1] <> '/') and (FItems
[FIndex
][1] <> '\') then
3437 s
:= e_CatPath(FSubPath
, FItems
[FIndex
]);
3438 if e_FindResource(FBaseList
, s
) = true then
3439 result
:= ExpandFileName(s
)
3441 e_LogWritefln('TGUIFileListBox.SelectedItem -> "%s"', [result
]);
3444 procedure TGUIFileListBox
.UpdateFileList();
3448 if (FIndex
= -1) or (FItems
= nil) or
3449 (FIndex
> High(FItems
)) or
3450 (FItems
[FIndex
][1] = '/') or
3451 (FItems
[FIndex
][1] = '\') then
3454 fn
:= FItems
[FIndex
];
3465 procedure TGUIMemo
.Clear
;
3471 constructor TGUIMemo
.Create(FontID
: DWORD
; Width
, Height
: Word);
3475 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
3480 FDrawScroll
:= True;
3483 procedure TGUIMemo
.Draw
;
3489 if FDrawBack
then DrawBox(FX
, FY
, FWidth
+1, FHeight
);
3491 DrawScroll(FX
+4+FWidth
*16, FY
+4, FHeight
, (FStartLine
> 0) and (FLines
<> nil),
3492 (FStartLine
+FHeight
-1 < High(FLines
)) and (FLines
<> nil));
3494 if FLines
<> nil then
3495 for a
:= FStartLine
to Min(High(FLines
), FStartLine
+FHeight
-1) do
3496 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, FLines
[a
], FColor
.R
, FColor
.G
, FColor
.B
);
3499 function TGUIMemo
.GetHeight
: Integer;
3501 Result
:= 8+FHeight
*16;
3504 function TGUIMemo
.GetWidth
: Integer;
3506 Result
:= 8+(FWidth
+1)*16;
3509 procedure TGUIMemo
.OnMessage(var Msg
: TMessage
);
3511 if not FEnabled
then Exit
;
3515 if FLines
= nil then Exit
;
3521 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
, VK_UP
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
3522 if FStartLine
> 0 then
3524 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
, VK_DOWN
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
3525 if FStartLine
< Length(FLines
)-FHeight
then
3527 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
3530 if FActiveControl
<> Self
then
3536 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
3537 else SetActive(nil);
3543 procedure TGUIMemo
.SetText(Text: string);
3546 FLines
:= GetLines(Text, FFont
.ID
, FWidth
*16);
3551 procedure TGUIimage
.ClearImage();
3553 if FImageRes
= '' then Exit
;
3555 g_Texture_Delete(FImageRes
);
3559 constructor TGUIimage
.Create();
3566 destructor TGUIimage
.Destroy();
3571 procedure TGUIimage
.Draw();
3577 if FImageRes
= '' then
3579 if g_Texture_Get(FDefaultRes
, ID
) then e_Draw(ID
, FX
, FY
, 0, True, False);
3582 if g_Texture_Get(FImageRes
, ID
) then e_Draw(ID
, FX
, FY
, 0, True, False);
3585 procedure TGUIimage
.OnMessage(var Msg
: TMessage
);
3590 procedure TGUIimage
.SetImage(Res
: string);
3594 if g_Texture_CreateWADEx(Res
, Res
) then FImageRes
:= Res
;
3597 procedure TGUIimage
.Update();