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 e_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';
85 TFontType
= (Texture
, Character
);
87 TFont
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
93 constructor Create(FontID
: DWORD
; FontType
: TFontType
);
94 destructor Destroy
; override;
95 procedure Draw(X
, Y
: Integer; Text: string; R
, G
, B
: Byte);
96 procedure GetTextSize(Text: string; var w
, h
: Word);
97 property Scale
: Single read FScale write FScale
;
103 TOnKeyDownEvent
= procedure(Key
: Byte);
104 TOnKeyDownEventEx
= procedure(win
: TGUIWindow
; Key
: Byte);
105 TOnCloseEvent
= procedure;
106 TOnShowEvent
= procedure;
107 TOnClickEvent
= procedure;
108 TOnChangeEvent
= procedure(Sender
: TGUIControl
);
109 TOnEnterEvent
= procedure(Sender
: TGUIControl
);
111 TGUIControl
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
115 FWindow
: TGUIWindow
;
118 FRightAlign
: Boolean; //HACK! this works only for "normal" menus, only for menu text labels, and generally sux. sorry.
119 FMaxWidth
: Integer; //HACK! used for right-aligning labels
122 procedure OnMessage(var Msg
: TMessage
); virtual;
123 procedure Update
; virtual;
124 procedure Draw
; virtual;
125 function GetWidth(): Integer; virtual;
126 function GetHeight(): Integer; virtual;
127 function WantActivationKey (key
: LongInt): Boolean; virtual;
128 property X
: Integer read FX write FX
;
129 property Y
: Integer read FY write FY
;
130 property Enabled
: Boolean read FEnabled write FEnabled
;
131 property Name
: string read FName write FName
;
132 property UserData
: Pointer read FUserData write FUserData
;
133 property RightAlign
: Boolean read FRightAlign write FRightAlign
; // for menu
136 TGUIWindow
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
138 FActiveControl
: TGUIControl
;
140 FPrevWindow
: TGUIWindow
;
142 FBackTexture
: string;
143 FMainWindow
: Boolean;
144 FOnKeyDown
: TOnKeyDownEvent
;
145 FOnKeyDownEx
: TOnKeyDownEventEx
;
146 FOnCloseEvent
: TOnCloseEvent
;
147 FOnShowEvent
: TOnShowEvent
;
150 Childs
: array of TGUIControl
;
151 constructor Create(Name
: string);
152 destructor Destroy
; override;
153 function AddChild(Child
: TGUIControl
): TGUIControl
;
154 procedure OnMessage(var Msg
: TMessage
);
157 procedure SetActive(Control
: TGUIControl
);
158 function GetControl(Name
: string): TGUIControl
;
159 property OnKeyDown
: TOnKeyDownEvent read FOnKeyDown write FOnKeyDown
;
160 property OnKeyDownEx
: TOnKeyDownEventEx read FOnKeyDownEx write FOnKeyDownEx
;
161 property OnClose
: TOnCloseEvent read FOnCloseEvent write FOnCloseEvent
;
162 property OnShow
: TOnShowEvent read FOnShowEvent write FOnShowEvent
;
163 property Name
: string read FName
;
164 property DefControl
: string read FDefControl write FDefControl
;
165 property BackTexture
: string read FBackTexture write FBackTexture
;
166 property MainWindow
: Boolean read FMainWindow write FMainWindow
;
167 property UserData
: Pointer read FUserData write FUserData
;
170 TGUITextButton
= class(TGUIControl
)
179 ProcEx
: procedure (sender
: TGUITextButton
);
180 constructor Create(aProc
: Pointer; FontID
: DWORD
; Text: string);
181 destructor Destroy(); override;
182 procedure OnMessage(var Msg
: TMessage
); override;
183 procedure Update(); override;
184 procedure Draw(); override;
185 function GetWidth(): Integer; override;
186 function GetHeight(): Integer; override;
187 procedure Click(Silent
: Boolean = False);
188 property Caption
: string read FText write FText
;
189 property Color
: TRGB read FColor write FColor
;
190 property Font
: TFont read FFont write FFont
;
191 property ShowWindow
: string read FShowWindow write FShowWindow
;
194 TGUILabel
= class(TGUIControl
)
200 FOnClickEvent
: TOnClickEvent
;
202 constructor Create(Text: string; FontID
: DWORD
);
203 procedure OnMessage(var Msg
: TMessage
); override;
204 procedure Draw
; override;
205 function GetWidth
: Integer; override;
206 function GetHeight
: Integer; override;
207 property OnClick
: TOnClickEvent read FOnClickEvent write FOnClickEvent
;
208 property FixedLength
: Word read FFixedLen write FFixedLen
;
209 property Text: string read FText write FText
;
210 property Color
: TRGB read FColor write FColor
;
211 property Font
: TFont read FFont write FFont
;
214 TGUIScroll
= class(TGUIControl
)
222 FOnChangeEvent
: TOnChangeEvent
;
223 procedure FSetValue(a
: Integer);
225 constructor Create();
226 procedure OnMessage(var Msg
: TMessage
); override;
227 procedure Update
; override;
228 procedure Draw
; override;
229 function GetWidth(): Integer; override;
230 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
231 property Max
: Word read FMax write FMax
;
232 property Value
: Integer read FValue write FSetValue
;
235 TGUISwitch
= class(TGUIControl
)
238 FItems
: array of string;
241 FOnChangeEvent
: TOnChangeEvent
;
243 constructor Create(FontID
: DWORD
);
244 procedure OnMessage(var Msg
: TMessage
); override;
245 procedure AddItem(Item
: string);
246 procedure Update
; override;
247 procedure Draw
; override;
248 function GetWidth(): Integer; override;
249 function GetText
: string;
250 property ItemIndex
: Integer read FIndex write FIndex
;
251 property Color
: TRGB read FColor write FColor
;
252 property Font
: TFont read FFont write FFont
;
253 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
256 TGUIEdit
= class(TGUIControl
)
264 FOnlyDigits
: Boolean;
268 FOnChangeEvent
: TOnChangeEvent
;
269 FOnEnterEvent
: TOnEnterEvent
;
271 procedure SetText(Text: string);
273 constructor Create(FontID
: DWORD
);
274 procedure OnMessage(var Msg
: TMessage
); override;
275 procedure Update
; override;
276 procedure Draw
; override;
277 function GetWidth(): Integer; override;
278 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
279 property OnEnter
: TOnEnterEvent read FOnEnterEvent write FOnEnterEvent
;
280 property Width
: Word read FWidth write FWidth
;
281 property MaxLength
: Word read FMaxLength write FMaxLength
;
282 property OnlyDigits
: Boolean read FOnlyDigits write FOnlyDigits
;
283 property Text: string read FText write SetText
;
284 property Color
: TRGB read FColor write FColor
;
285 property Font
: TFont read FFont write FFont
;
286 property Invalid
: Boolean read FInvalid write FInvalid
;
289 TGUIKeyRead
= class(TGUIControl
)
296 constructor Create(FontID
: DWORD
);
297 procedure OnMessage(var Msg
: TMessage
); override;
298 procedure Draw
; override;
299 function GetWidth(): Integer; override;
300 function WantActivationKey (key
: LongInt): Boolean; override;
301 property Key
: Word read FKey write FKey
;
302 property Color
: TRGB read FColor write FColor
;
303 property Font
: TFont read FFont write FFont
;
307 TGUIKeyRead2
= class(TGUIControl
)
312 FKey0
, FKey1
: Word; // this should be an array. sorry.
315 FMaxKeyNameWdt
: Integer;
317 constructor Create(FontID
: DWORD
);
318 procedure OnMessage(var Msg
: TMessage
); override;
319 procedure Draw
; override;
320 function GetWidth(): Integer; override;
321 function WantActivationKey (key
: LongInt): Boolean; override;
322 property Key0
: Word read FKey0 write FKey0
;
323 property Key1
: Word read FKey1 write FKey1
;
324 property Color
: TRGB read FColor write FColor
;
325 property Font
: TFont read FFont write FFont
;
328 TGUIModelView
= class(TGUIControl
)
330 FModel
: TPlayerModel
;
334 destructor Destroy
; override;
335 procedure OnMessage(var Msg
: TMessage
); override;
336 procedure SetModel(ModelName
: string);
337 procedure SetColor(Red
, Green
, Blue
: Byte);
338 procedure NextAnim();
339 procedure NextWeapon();
340 procedure Update
; override;
341 procedure Draw
; override;
342 property Model
: TPlayerModel read FModel
;
345 TPreviewPanel
= record
346 X1
, Y1
, X2
, Y2
: Integer;
350 TGUIMapPreview
= class(TGUIControl
)
352 FMapData
: array of TPreviewPanel
;
356 constructor Create();
357 destructor Destroy(); override;
358 procedure OnMessage(var Msg
: TMessage
); override;
359 procedure SetMap(Res
: string);
360 procedure ClearMap();
361 procedure Update(); override;
362 procedure Draw(); override;
363 function GetScaleStr
: String;
366 TGUIImage
= class(TGUIControl
)
371 constructor Create();
372 destructor Destroy(); override;
373 procedure OnMessage(var Msg
: TMessage
); override;
374 procedure SetImage(Res
: string);
375 procedure ClearImage();
376 procedure Update(); override;
377 procedure Draw(); override;
378 property DefaultRes
: string read FDefaultRes write FDefaultRes
;
381 TGUIListBox
= class(TGUIControl
)
385 FUnActiveColor
: TRGB
;
393 FDrawScroll
: Boolean;
394 FOnChangeEvent
: TOnChangeEvent
;
396 procedure FSetItems(Items
: SSArray
);
397 procedure FSetIndex(aIndex
: Integer);
400 constructor Create(FontID
: DWORD
; Width
, Height
: Word);
401 procedure OnMessage(var Msg
: TMessage
); override;
402 procedure Draw(); override;
403 procedure AddItem(Item
: String);
404 function ItemExists (item
: String): Boolean;
405 procedure SelectItem(Item
: String);
407 function GetWidth(): Integer; override;
408 function GetHeight(): Integer; override;
409 function SelectedItem(): String;
411 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
412 property Sort
: Boolean read FSort write FSort
;
413 property ItemIndex
: Integer read FIndex write FSetIndex
;
414 property Items
: SSArray read FItems write FSetItems
;
415 property DrawBack
: Boolean read FDrawBack write FDrawBack
;
416 property DrawScrollBar
: Boolean read FDrawScroll write FDrawScroll
;
417 property ActiveColor
: TRGB read FActiveColor write FActiveColor
;
418 property UnActiveColor
: TRGB read FUnActiveColor write FUnActiveColor
;
419 property Font
: TFont read FFont write FFont
;
422 TGUIFileListBox
= class(TGUIListBox
)
427 FBaseList
: SSArray
; // highter index have highter priority
432 procedure OnMessage (var Msg
: TMessage
); override;
433 procedure SetBase (dirs
: SSArray
; path
: String = '');
434 function SelectedItem(): String;
435 procedure UpdateFileList
;
437 property Dirs
: Boolean read FDirs write FDirs
;
438 property FileMask
: String read FFileMask write FFileMask
;
441 TGUIMemo
= class(TGUIControl
)
450 FDrawScroll
: Boolean;
452 constructor Create(FontID
: DWORD
; Width
, Height
: Word);
453 procedure OnMessage(var Msg
: TMessage
); override;
454 procedure Draw
; override;
456 function GetWidth(): Integer; override;
457 function GetHeight(): Integer; override;
458 procedure SetText(Text: string);
459 property DrawBack
: Boolean read FDrawBack write FDrawBack
;
460 property DrawScrollBar
: Boolean read FDrawScroll write FDrawScroll
;
461 property Color
: TRGB read FColor write FColor
;
462 property Font
: TFont read FFont write FFont
;
465 TGUIMainMenu
= class(TGUIControl
)
467 FButtons
: array of TGUITextButton
;
476 constructor Create(FontID
: DWORD
; Logo
, Header
: string);
477 destructor Destroy
; override;
478 procedure OnMessage(var Msg
: TMessage
); override;
479 function AddButton(fProc
: Pointer; Caption
: string; ShowWindow
: string = ''): TGUITextButton
;
480 function GetButton(aName
: string): TGUITextButton
;
481 procedure EnableButton(aName
: string; e
: Boolean);
482 procedure AddSpace();
483 procedure Update
; override;
484 procedure Draw
; override;
487 TControlType
= class of TGUIControl
;
489 PMenuItem
= ^TMenuItem
;
492 ControlType
: TControlType
;
493 Control
: TGUIControl
;
496 TGUIMenu
= class(TGUIControl
)
498 FItems
: array of TMenuItem
;
506 function NewItem(): Integer;
508 constructor Create(HeaderFont
, ItemsFont
: DWORD
; Header
: string);
509 destructor Destroy
; override;
510 procedure OnMessage(var Msg
: TMessage
); override;
511 procedure AddSpace();
512 procedure AddLine(fText
: string);
513 procedure AddText(fText
: string; MaxWidth
: Word);
514 function AddLabel(fText
: string): TGUILabel
;
515 function AddButton(Proc
: Pointer; fText
: string; _ShowWindow
: string = ''): TGUITextButton
;
516 function AddScroll(fText
: string): TGUIScroll
;
517 function AddSwitch(fText
: string): TGUISwitch
;
518 function AddEdit(fText
: string): TGUIEdit
;
519 function AddKeyRead(fText
: string): TGUIKeyRead
;
520 function AddKeyRead2(fText
: string): TGUIKeyRead2
;
521 function AddList(fText
: string; Width
, Height
: Word): TGUIListBox
;
522 function AddFileList(fText
: string; Width
, Height
: Word): TGUIFileListBox
;
523 function AddMemo(fText
: string; Width
, Height
: Word): TGUIMemo
;
525 function GetControl(aName
: string): TGUIControl
;
526 function GetControlsText(aName
: string): TGUILabel
;
527 procedure Draw
; override;
528 procedure Update
; override;
529 procedure UpdateIndex();
530 property Align
: Boolean read FAlign write FAlign
;
531 property Left
: Integer read FLeft write FLeft
;
532 property YesNo
: Boolean read FYesNo write FYesNo
;
536 g_GUIWindows
: array of TGUIWindow
;
537 g_ActiveWindow
: TGUIWindow
= nil;
538 g_GUIGrabInput
: Boolean = False;
540 procedure g_GUI_Init();
541 function g_GUI_AddWindow(Window
: TGUIWindow
): TGUIWindow
;
542 function g_GUI_GetWindow(Name
: string): TGUIWindow
;
543 procedure g_GUI_ShowWindow(Name
: string);
544 procedure g_GUI_HideWindow(PlaySound
: Boolean = True);
545 function g_GUI_Destroy(): Boolean;
546 procedure g_GUI_SaveMenuPos();
547 procedure g_GUI_LoadMenuPos();
553 {$INCLUDE ../nogl/noGLuses.inc}
554 g_textures
, g_sound
, SysUtils
, e_res
,
555 g_game
, Math
, StrUtils
, g_player
, g_options
, g_console
,
556 g_map
, g_weapons
, xdynrec
, wadreader
;
560 Box
: Array [0..8] of DWORD
;
561 Saved_Windows
: SSArray
;
564 procedure g_GUI_Init();
566 g_Texture_Get(BOX1
, Box
[0]);
567 g_Texture_Get(BOX2
, Box
[1]);
568 g_Texture_Get(BOX3
, Box
[2]);
569 g_Texture_Get(BOX4
, Box
[3]);
570 g_Texture_Get(BOX5
, Box
[4]);
571 g_Texture_Get(BOX6
, Box
[5]);
572 g_Texture_Get(BOX7
, Box
[6]);
573 g_Texture_Get(BOX8
, Box
[7]);
574 g_Texture_Get(BOX9
, Box
[8]);
577 function g_GUI_Destroy(): Boolean;
581 Result
:= (Length(g_GUIWindows
) > 0);
583 for i
:= 0 to High(g_GUIWindows
) do
584 g_GUIWindows
[i
].Free();
587 g_ActiveWindow
:= nil;
590 function g_GUI_AddWindow(Window
: TGUIWindow
): TGUIWindow
;
592 SetLength(g_GUIWindows
, Length(g_GUIWindows
)+1);
593 g_GUIWindows
[High(g_GUIWindows
)] := Window
;
598 function g_GUI_GetWindow(Name
: string): TGUIWindow
;
604 if g_GUIWindows
<> nil then
605 for i
:= 0 to High(g_GUIWindows
) do
606 if g_GUIWindows
[i
].FName
= Name
then
608 Result
:= g_GUIWindows
[i
];
612 Assert(Result
<> nil, 'GUI_Window "'+Name
+'" not found');
615 procedure g_GUI_ShowWindow(Name
: string);
619 if g_GUIWindows
= nil then
622 for i
:= 0 to High(g_GUIWindows
) do
623 if g_GUIWindows
[i
].FName
= Name
then
625 g_GUIWindows
[i
].FPrevWindow
:= g_ActiveWindow
;
626 g_ActiveWindow
:= g_GUIWindows
[i
];
628 if g_ActiveWindow
.MainWindow
then
629 g_ActiveWindow
.FPrevWindow
:= nil;
631 if g_ActiveWindow
.FDefControl
<> '' then
632 g_ActiveWindow
.SetActive(g_ActiveWindow
.GetControl(g_ActiveWindow
.FDefControl
))
634 g_ActiveWindow
.SetActive(nil);
636 if @g_ActiveWindow
.FOnShowEvent
<> nil then
637 g_ActiveWindow
.FOnShowEvent();
643 procedure g_GUI_HideWindow(PlaySound
: Boolean = True);
645 if g_ActiveWindow
<> nil then
647 if @g_ActiveWindow
.OnClose
<> nil then
648 g_ActiveWindow
.OnClose();
649 g_ActiveWindow
:= g_ActiveWindow
.FPrevWindow
;
651 g_Sound_PlayEx(WINDOW_CLOSESOUND
);
655 procedure g_GUI_SaveMenuPos();
660 SetLength(Saved_Windows
, 0);
661 win
:= g_ActiveWindow
;
665 len
:= Length(Saved_Windows
);
666 SetLength(Saved_Windows
, len
+ 1);
668 Saved_Windows
[len
] := win
.Name
;
670 if win
.MainWindow
then
673 win
:= win
.FPrevWindow
;
677 procedure g_GUI_LoadMenuPos();
679 i
, j
, k
, len
: Integer;
682 g_ActiveWindow
:= nil;
683 len
:= Length(Saved_Windows
);
688 // Îêíî ñ ãëàâíûì ìåíþ:
689 g_GUI_ShowWindow(Saved_Windows
[len
-1]);
691 // Íå ïåðåêëþ÷èëîñü (èëè íåêóäà äàëüøå):
692 if (len
= 1) or (g_ActiveWindow
= nil) then
695 // Èùåì êíîïêè â îñòàëüíûõ îêíàõ:
696 for k
:= len
-1 downto 1 do
700 for i
:= 0 to Length(g_ActiveWindow
.Childs
)-1 do
702 if g_ActiveWindow
.Childs
[i
] is TGUIMainMenu
then
703 begin // GUI_MainMenu
704 with TGUIMainMenu(g_ActiveWindow
.Childs
[i
]) do
705 for j
:= 0 to Length(FButtons
)-1 do
706 if FButtons
[j
].ShowWindow
= Saved_Windows
[k
-1] then
708 FButtons
[j
].Click(True);
714 if g_ActiveWindow
.Childs
[i
] is TGUIMenu
then
715 with TGUIMenu(g_ActiveWindow
.Childs
[i
]) do
716 for j
:= 0 to Length(FItems
)-1 do
717 if FItems
[j
].ControlType
= TGUITextButton
then
718 if TGUITextButton(FItems
[j
].Control
).ShowWindow
= Saved_Windows
[k
-1] then
720 TGUITextButton(FItems
[j
].Control
).Click(True);
731 (g_ActiveWindow
.Name
= Saved_Windows
[k
]) then
736 procedure DrawBox(X
, Y
: Integer; Width
, Height
: Word);
738 e_Draw(Box
[0], X
, Y
, 0, False, False);
739 e_DrawFill(Box
[1], X
+4, Y
, Width
*4, 1, 0, False, False);
740 e_Draw(Box
[2], X
+4+Width
*16, Y
, 0, False, False);
741 e_DrawFill(Box
[3], X
, Y
+4, 1, Height
*4, 0, False, False);
742 e_DrawFill(Box
[4], X
+4, Y
+4, Width
, Height
, 0, False, False);
743 e_DrawFill(Box
[5], X
+4+Width
*16, Y
+4, 1, Height
*4, 0, False, False);
744 e_Draw(Box
[6], X
, Y
+4+Height
*16, 0, False, False);
745 e_DrawFill(Box
[7], X
+4, Y
+4+Height
*16, Width
*4, 1, 0, False, False);
746 e_Draw(Box
[8], X
+4+Width
*16, Y
+4+Height
*16, 0, False, False);
749 procedure DrawScroll(X
, Y
: Integer; Height
: Word; Up
, Down
: Boolean);
753 if Height
< 3 then Exit
;
756 g_Texture_Get(BSCROLL_UPA
, ID
)
758 g_Texture_Get(BSCROLL_UPU
, ID
);
759 e_Draw(ID
, X
, Y
, 0, False, False);
762 g_Texture_Get(BSCROLL_DOWNA
, ID
)
764 g_Texture_Get(BSCROLL_DOWNU
, ID
);
765 e_Draw(ID
, X
, Y
+(Height
-1)*16, 0, False, False);
767 g_Texture_Get(BSCROLL_MIDDLE
, ID
);
768 e_DrawFill(ID
, X
, Y
+16, 1, Height
-2, 0, False, False);
773 constructor TGUIWindow
.Create(Name
: string);
776 FActiveControl
:= nil;
780 FOnCloseEvent
:= nil;
784 destructor TGUIWindow
.Destroy
;
791 for i
:= 0 to High(Childs
) do
795 function TGUIWindow
.AddChild(Child
: TGUIControl
): TGUIControl
;
797 Child
.FWindow
:= Self
;
799 SetLength(Childs
, Length(Childs
) + 1);
800 Childs
[High(Childs
)] := Child
;
805 procedure TGUIWindow
.Update
;
809 for i
:= 0 to High(Childs
) do
810 if Childs
[i
] <> nil then Childs
[i
].Update
;
813 procedure TGUIWindow
.Draw
;
819 if FBackTexture
<> '' then // Here goes code duplication from g_game.pas:DrawMenuBackground()
820 if g_Texture_Get(FBackTexture
, ID
) then
822 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
823 e_GetTextureSize(ID
, @tw
, @th
);
825 tw
:= round(tw
* 1.333 * (gScreenHeight
/ th
))
827 tw
:= trunc(tw
* (gScreenHeight
/ th
));
828 e_DrawSize(ID
, (gScreenWidth
- tw
) div 2, 0, 0, False, False, tw
, gScreenHeight
);
831 e_Clear(GL_COLOR_BUFFER_BIT
, 0.5, 0.5, 0.5);
834 if FName
= 'AuthorsMenu' then
835 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
837 for i
:= 0 to High(Childs
) do
838 if Childs
[i
] <> nil then Childs
[i
].Draw
;
841 procedure TGUIWindow
.OnMessage(var Msg
: TMessage
);
843 if FActiveControl
<> nil then FActiveControl
.OnMessage(Msg
);
844 if @FOnKeyDown
<> nil then FOnKeyDown(Msg
.wParam
);
845 if @FOnKeyDownEx
<> nil then FOnKeyDownEx(self
, Msg
.wParam
);
847 if Msg
.Msg
= WM_KEYDOWN
then
859 procedure TGUIWindow
.SetActive(Control
: TGUIControl
);
861 FActiveControl
:= Control
;
864 function TGUIWindow
.GetControl(Name
: String): TGUIControl
;
870 if Childs
<> nil then
871 for i
:= 0 to High(Childs
) do
872 if Childs
[i
] <> nil then
873 if LowerCase(Childs
[i
].FName
) = LowerCase(Name
) then
879 Assert(Result
<> nil, 'Window Control "'+Name
+'" not Found!');
884 constructor TGUIControl
.Create();
890 FRightAlign
:= false;
894 procedure TGUIControl
.OnMessage(var Msg
: TMessage
);
900 procedure TGUIControl
.Update();
904 procedure TGUIControl
.Draw();
908 function TGUIControl
.WantActivationKey (key
: LongInt): Boolean;
913 function TGUIControl
.GetWidth(): Integer;
918 function TGUIControl
.GetHeight(): Integer;
925 procedure TGUITextButton
.Click(Silent
: Boolean = False);
927 if (FSound
<> '') and (not Silent
) then g_Sound_PlayEx(FSound
);
929 if @Proc
<> nil then Proc();
930 if @ProcEx
<> nil then ProcEx(self
);
932 if FShowWindow
<> '' then g_GUI_ShowWindow(FShowWindow
);
935 constructor TGUITextButton
.Create(aProc
: Pointer; FontID
: DWORD
; Text: string);
942 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
947 destructor TGUITextButton
.Destroy
;
953 procedure TGUITextButton
.Draw
;
955 FFont
.Draw(FX
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
)
958 function TGUITextButton
.GetHeight
: Integer;
962 FFont
.GetTextSize(FText
, w
, h
);
966 function TGUITextButton
.GetWidth
: Integer;
970 FFont
.GetTextSize(FText
, w
, h
);
974 procedure TGUITextButton
.OnMessage(var Msg
: TMessage
);
976 if not FEnabled
then Exit
;
983 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
: Click();
988 procedure TGUITextButton
.Update
;
995 constructor TFont
.Create(FontID
: DWORD
; FontType
: TFontType
);
1000 FFontType
:= FontType
;
1003 destructor TFont
.Destroy
;
1009 procedure TFont
.Draw(X
, Y
: Integer; Text: string; R
, G
, B
: Byte);
1011 if FFontType
= TFontType
.Character
then e_CharFont_PrintEx(ID
, X
, Y
, Text, _RGB(R
, G
, B
), FScale
)
1012 else e_TextureFontPrintEx(X
, Y
, Text, ID
, R
, G
, B
, FScale
);
1015 procedure TFont
.GetTextSize(Text: string; var w
, h
: Word);
1019 if FFontType
= TFontType
.Character
then e_CharFont_GetSize(ID
, Text, w
, h
)
1022 e_TextureFontGetSize(ID
, cw
, ch
);
1023 w
:= cw
*Length(Text);
1027 w
:= Round(w
*FScale
);
1028 h
:= Round(h
*FScale
);
1033 function TGUIMainMenu
.AddButton(fProc
: Pointer; Caption
: string; ShowWindow
: string = ''): TGUITextButton
;
1041 SetLength(FButtons
, Length(FButtons
)+1);
1042 FButtons
[High(FButtons
)] := TGUITextButton
.Create(fProc
, FFontID
, Caption
);
1043 FButtons
[High(FButtons
)].ShowWindow
:= ShowWindow
;
1044 with FButtons
[High(FButtons
)] do
1046 if (fProc
<> nil) or (ShowWindow
<> '') then FColor
:= MAINMENU_ITEMS_COLOR
1047 else FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
1048 FSound
:= MAINMENU_CLICKSOUND
;
1051 _x
:= gScreenWidth
div 2;
1053 for a
:= 0 to High(FButtons
) do
1054 if FButtons
[a
] <> nil then
1055 _x
:= Min(_x
, (gScreenWidth
div 2)-(FButtons
[a
].GetWidth
div 2));
1057 if FLogo
<> 0 then e_GetTextureSize(FLogo
, nil, @lh
);
1058 hh
:= FButtons
[High(FButtons
)].GetHeight
;
1060 if FLogo
<> 0 then h
:= lh
+ hh
* (1 + Length(FButtons
)) + MAINMENU_SPACE
* (Length(FButtons
) - 1)
1061 else h
:= hh
* (2 + Length(FButtons
)) + MAINMENU_SPACE
* (Length(FButtons
) - 1);
1062 h
:= (gScreenHeight
div 2) - (h
div 2);
1064 if FHeader
<> nil then with FHeader
do
1070 if FLogo
<> 0 then Inc(h
, lh
)
1073 for a
:= 0 to High(FButtons
) do
1075 if FButtons
[a
] <> nil then
1082 Inc(h
, hh
+MAINMENU_SPACE
);
1085 Result
:= FButtons
[High(FButtons
)];
1088 procedure TGUIMainMenu
.AddSpace
;
1090 SetLength(FButtons
, Length(FButtons
)+1);
1091 FButtons
[High(FButtons
)] := nil;
1094 constructor TGUIMainMenu
.Create(FontID
: DWORD
; Logo
, Header
: string);
1100 FCounter
:= MAINMENU_MARKERDELAY
;
1102 g_Texture_Get(MAINMENU_MARKER1
, FMarkerID1
);
1103 g_Texture_Get(MAINMENU_MARKER2
, FMarkerID2
);
1105 if not g_Texture_Get(Logo
, FLogo
) then
1107 FHeader
:= TGUILabel
.Create(Header
, FFontID
);
1110 FColor
:= MAINMENU_HEADER_COLOR
;
1111 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1112 FY
:= (gScreenHeight
div 2)-(GetHeight
div 2);
1117 destructor TGUIMainMenu
.Destroy
;
1121 if FButtons
<> nil then
1122 for a
:= 0 to High(FButtons
) do
1130 procedure TGUIMainMenu
.Draw
;
1138 if FHeader
<> nil then FHeader
.Draw
1140 e_GetTextureSize(FLogo
, @w
, @h
);
1141 e_Draw(FLogo
, ((gScreenWidth
div 2) - (w
div 2)), FButtons
[0].FY
- FButtons
[0].GetHeight
- h
, 0, True, False);
1144 if FButtons
<> nil then
1146 for a
:= 0 to High(FButtons
) do
1147 if FButtons
[a
] <> nil then FButtons
[a
].Draw
;
1149 if FIndex
<> -1 then
1150 e_Draw(FMarkerID1
, FButtons
[FIndex
].FX
-48, FButtons
[FIndex
].FY
, 0, True, False);
1154 procedure TGUIMainMenu
.EnableButton(aName
: string; e
: Boolean);
1158 if FButtons
= nil then Exit
;
1160 for a
:= 0 to High(FButtons
) do
1161 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= aName
) then
1163 if e
then FButtons
[a
].FColor
:= MAINMENU_ITEMS_COLOR
1164 else FButtons
[a
].FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
1165 FButtons
[a
].Enabled
:= e
;
1170 function TGUIMainMenu
.GetButton(aName
: string): TGUITextButton
;
1176 if FButtons
= nil then Exit
;
1178 for a
:= 0 to High(FButtons
) do
1179 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= aName
) then
1181 Result
:= FButtons
[a
];
1186 procedure TGUIMainMenu
.OnMessage(var Msg
: TMessage
);
1191 if not FEnabled
then Exit
;
1195 if FButtons
= nil then Exit
;
1198 for a
:= 0 to High(FButtons
) do
1199 if FButtons
[a
] <> nil then
1205 if not ok
then Exit
;
1210 IK_UP
, IK_KPUP
, VK_UP
, JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1214 if FIndex
< 0 then FIndex
:= High(FButtons
);
1215 until FButtons
[FIndex
] <> nil;
1217 g_Sound_PlayEx(MENU_CHANGESOUND
);
1219 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1223 if FIndex
> High(FButtons
) then FIndex
:= 0;
1224 until FButtons
[FIndex
] <> nil;
1226 g_Sound_PlayEx(MENU_CHANGESOUND
);
1228 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
;
1233 procedure TGUIMainMenu
.Update
;
1239 if FCounter
= 0 then
1242 FMarkerID1
:= FMarkerID2
;
1245 FCounter
:= MAINMENU_MARKERDELAY
;
1246 end else Dec(FCounter
);
1251 constructor TGUILabel
.Create(Text: string; FontID
: DWORD
);
1255 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
1259 FOnClickEvent
:= nil;
1262 procedure TGUILabel
.Draw
;
1268 FFont
.GetTextSize(FText
, w
, h
);
1269 FFont
.Draw(FX
+FMaxWidth
-w
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
);
1273 FFont
.Draw(FX
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
);
1277 function TGUILabel
.GetHeight
: Integer;
1281 FFont
.GetTextSize(FText
, w
, h
);
1285 function TGUILabel
.GetWidth
: Integer;
1289 if FFixedLen
= 0 then
1290 FFont
.GetTextSize(FText
, w
, h
)
1292 w
:= e_CharFont_GetMaxWidth(FFont
.ID
)*FFixedLen
;
1296 procedure TGUILabel
.OnMessage(var Msg
: TMessage
);
1298 if not FEnabled
then Exit
;
1305 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
: if @FOnClickEvent
<> nil then FOnClickEvent();
1312 function TGUIMenu
.AddButton(Proc
: Pointer; fText
: string; _ShowWindow
: string = ''): TGUITextButton
;
1319 Control
:= TGUITextButton
.Create(Proc
, FFontID
, fText
);
1320 with Control
as TGUITextButton
do
1322 ShowWindow
:= _ShowWindow
;
1323 FColor
:= MENU_ITEMSCTRL_COLOR
;
1327 ControlType
:= TGUITextButton
;
1329 Result
:= (Control
as TGUITextButton
);
1332 if FIndex
= -1 then FIndex
:= i
;
1337 procedure TGUIMenu
.AddLine(fText
: string);
1344 Text := TGUILabel
.Create(fText
, FFontID
);
1347 FColor
:= MENU_ITEMSTEXT_COLOR
;
1356 procedure TGUIMenu
.AddText(fText
: string; MaxWidth
: Word);
1361 l
:= GetLines(fText
, FFontID
, MaxWidth
);
1363 if l
= nil then Exit
;
1365 for a
:= 0 to High(l
) do
1370 Text := TGUILabel
.Create(l
[a
], FFontID
);
1373 with Text do begin FColor
:= _RGB(255, 0, 0); end;
1377 with Text do begin FColor
:= MENU_ITEMSTEXT_COLOR
; end;
1387 procedure TGUIMenu
.AddSpace
;
1401 constructor TGUIMenu
.Create(HeaderFont
, ItemsFont
: DWORD
; Header
: string);
1407 FFontID
:= ItemsFont
;
1408 FCounter
:= MENU_MARKERDELAY
;
1412 FHeader
:= TGUILabel
.Create(Header
, HeaderFont
);
1415 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1417 FColor
:= MAINMENU_HEADER_COLOR
;
1421 destructor TGUIMenu
.Destroy
;
1425 if FItems
<> nil then
1426 for a
:= 0 to High(FItems
) do
1440 procedure TGUIMenu
.Draw
;
1442 a
, locx
, locy
: Integer;
1446 if FHeader
<> nil then FHeader
.Draw
;
1448 if FItems
<> nil then
1449 for a
:= 0 to High(FItems
) do
1451 if FItems
[a
].Text <> nil then FItems
[a
].Text.Draw
;
1452 if FItems
[a
].Control
<> nil then FItems
[a
].Control
.Draw
;
1455 if (FIndex
<> -1) and (FCounter
> MENU_MARKERDELAY
div 2) then
1460 if FItems
[FIndex
].Text <> nil then
1462 locx
:= FItems
[FIndex
].Text.FX
;
1463 locy
:= FItems
[FIndex
].Text.FY
;
1465 if FItems
[FIndex
].Text.RightAlign
then
1467 locx
:= locx
+FItems
[FIndex
].Text.FMaxWidth
-FItems
[FIndex
].Text.GetWidth
;
1470 else if FItems
[FIndex
].Control
<> nil then
1472 locx
:= FItems
[FIndex
].Control
.FX
;
1473 locy
:= FItems
[FIndex
].Control
.FY
;
1476 locx
:= locx
-e_CharFont_GetMaxWidth(FFontID
);
1478 e_CharFont_PrintEx(FFontID
, locx
, locy
, #16, _RGB(255, 0, 0));
1482 function TGUIMenu
.GetControl(aName
: String): TGUIControl
;
1488 if FItems
<> nil then
1489 for a
:= 0 to High(FItems
) do
1490 if FItems
[a
].Control
<> nil then
1491 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(aName
) then
1493 Result
:= FItems
[a
].Control
;
1497 Assert(Result
<> nil, 'GUI control "'+aName
+'" not found!');
1500 function TGUIMenu
.GetControlsText(aName
: String): TGUILabel
;
1506 if FItems
<> nil then
1507 for a
:= 0 to High(FItems
) do
1508 if FItems
[a
].Control
<> nil then
1509 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(aName
) then
1511 Result
:= FItems
[a
].Text;
1515 Assert(Result
<> nil, 'GUI control''s text "'+aName
+'" not found!');
1518 function TGUIMenu
.NewItem
: Integer;
1520 SetLength(FItems
, Length(FItems
)+1);
1521 Result
:= High(FItems
);
1524 procedure TGUIMenu
.OnMessage(var Msg
: TMessage
);
1529 if not FEnabled
then Exit
;
1533 if FItems
= nil then Exit
;
1536 for a
:= 0 to High(FItems
) do
1537 if FItems
[a
].Control
<> nil then
1543 if not ok
then Exit
;
1545 if (Msg
.Msg
= WM_KEYDOWN
) and (FIndex
<> -1) and (FItems
[FIndex
].Control
<> nil) and
1546 (FItems
[FIndex
].Control
.WantActivationKey(Msg
.wParam
)) then
1548 FItems
[FIndex
].Control
.OnMessage(Msg
);
1549 g_Sound_PlayEx(MENU_CLICKSOUND
);
1557 IK_UP
, IK_KPUP
, VK_UP
,JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1562 if c
> Length(FItems
) then
1569 if FIndex
< 0 then FIndex
:= High(FItems
);
1570 until (FItems
[FIndex
].Control
<> nil) and
1571 (FItems
[FIndex
].Control
.Enabled
);
1575 g_Sound_PlayEx(MENU_CHANGESOUND
);
1578 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1583 if c
> Length(FItems
) then
1590 if FIndex
> High(FItems
) then FIndex
:= 0;
1591 until (FItems
[FIndex
].Control
<> nil) and
1592 (FItems
[FIndex
].Control
.Enabled
);
1596 g_Sound_PlayEx(MENU_CHANGESOUND
);
1599 IK_LEFT
, IK_RIGHT
, IK_KPLEFT
, IK_KPRIGHT
, VK_LEFT
, VK_RIGHT
,
1600 JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
,
1601 JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
1603 if FIndex
<> -1 then
1604 if FItems
[FIndex
].Control
<> nil then
1605 FItems
[FIndex
].Control
.OnMessage(Msg
);
1607 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
1609 if FIndex
<> -1 then
1611 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1613 g_Sound_PlayEx(MENU_CLICKSOUND
);
1617 if FYesNo
and (length(FItems
) > 1) then
1619 Msg
.wParam
:= IK_RETURN
; // to register keypress
1620 FIndex
:= High(FItems
)-1;
1621 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1624 if FYesNo
and (length(FItems
) > 1) then
1626 Msg
.wParam
:= IK_RETURN
; // to register keypress
1627 FIndex
:= High(FItems
);
1628 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1635 procedure TGUIMenu
.ReAlign();
1637 a
, tx
, cx
, w
, h
: Integer;
1638 cww
: array of Integer; // cached widths
1641 if FItems
= nil then Exit
;
1643 SetLength(cww
, length(FItems
));
1645 for a
:= 0 to High(FItems
) do
1647 if FItems
[a
].Text <> nil then
1649 cww
[a
] := FItems
[a
].Text.GetWidth
;
1650 if maxcww
< cww
[a
] then maxcww
:= cww
[a
];
1661 for a
:= 0 to High(FItems
) do
1664 if FItems
[a
].Text <> nil then w
:= FItems
[a
].Text.GetWidth
;
1665 if FItems
[a
].Control
<> nil then
1668 if FItems
[a
].ControlType
= TGUILabel
then w
:= w
+(FItems
[a
].Control
as TGUILabel
).GetWidth
1669 else if FItems
[a
].ControlType
= TGUITextButton
then w
:= w
+(FItems
[a
].Control
as TGUITextButton
).GetWidth
1670 else if FItems
[a
].ControlType
= TGUIScroll
then w
:= w
+(FItems
[a
].Control
as TGUIScroll
).GetWidth
1671 else if FItems
[a
].ControlType
= TGUISwitch
then w
:= w
+(FItems
[a
].Control
as TGUISwitch
).GetWidth
1672 else if FItems
[a
].ControlType
= TGUIEdit
then w
:= w
+(FItems
[a
].Control
as TGUIEdit
).GetWidth
1673 else if FItems
[a
].ControlType
= TGUIKeyRead
then w
:= w
+(FItems
[a
].Control
as TGUIKeyRead
).GetWidth
1674 else if FItems
[a
].ControlType
= TGUIKeyRead2
then w
:= w
+(FItems
[a
].Control
as TGUIKeyRead2
).GetWidth
1675 else if FItems
[a
].ControlType
= TGUIListBox
then w
:= w
+(FItems
[a
].Control
as TGUIListBox
).GetWidth
1676 else if FItems
[a
].ControlType
= TGUIFileListBox
then w
:= w
+(FItems
[a
].Control
as TGUIFileListBox
).GetWidth
1677 else if FItems
[a
].ControlType
= TGUIMemo
then w
:= w
+(FItems
[a
].Control
as TGUIMemo
).GetWidth
;
1679 tx
:= Min(tx
, (gScreenWidth
div 2)-(w
div 2));
1684 for a
:= 0 to High(FItems
) do
1688 if (Text <> nil) and (Control
= nil) then Continue
;
1690 if Text <> nil then w
:= tx
+Text.GetWidth
;
1691 if w
> cx
then cx
:= w
;
1695 cx
:= cx
+MENU_HSPACE
;
1697 h
:= FHeader
.GetHeight
*2+MENU_VSPACE
*(Length(FItems
)-1);
1699 for a
:= 0 to High(FItems
) do
1703 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then
1704 h
:= h
+(FItems
[a
].Control
as TGUIListBox
).GetHeight()
1706 h
:= h
+e_CharFont_GetMaxHeight(FFontID
);
1710 h
:= (gScreenHeight
div 2)-(h
div 2);
1714 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1717 Inc(h
, GetHeight
*2);
1720 for a
:= 0 to High(FItems
) do
1732 if Text.RightAlign
and (length(cww
) > a
) then
1734 //Text.FX := Text.FX+maxcww;
1735 Text.FMaxWidth
:= maxcww
;
1739 if Control
<> nil then
1756 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then Inc(h
, (Control
as TGUIListBox
).GetHeight
+MENU_VSPACE
)
1757 else if ControlType
= TGUIMemo
then Inc(h
, (Control
as TGUIMemo
).GetHeight
+MENU_VSPACE
)
1758 else Inc(h
, e_CharFont_GetMaxHeight(FFontID
)+MENU_VSPACE
);
1762 // another ugly hack
1763 if FYesNo
and (length(FItems
) > 1) then
1766 for a
:= High(FItems
)-1 to High(FItems
) do
1768 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1770 cx
:= (FItems
[a
].Control
as TGUITextButton
).GetWidth
;
1771 if cx
> w
then w
:= cx
;
1776 for a
:= High(FItems
)-1 to High(FItems
) do
1778 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1780 FItems
[a
].Control
.FX
:= (gScreenWidth
-w
) div 2;
1787 function TGUIMenu
.AddScroll(fText
: string): TGUIScroll
;
1794 Control
:= TGUIScroll
.Create();
1796 Text := TGUILabel
.Create(fText
, FFontID
);
1799 FColor
:= MENU_ITEMSTEXT_COLOR
;
1802 ControlType
:= TGUIScroll
;
1804 Result
:= (Control
as TGUIScroll
);
1807 if FIndex
= -1 then FIndex
:= i
;
1812 function TGUIMenu
.AddSwitch(fText
: string): TGUISwitch
;
1819 Control
:= TGUISwitch
.Create(FFontID
);
1820 (Control
as TGUISwitch
).FColor
:= MENU_ITEMSCTRL_COLOR
;
1822 Text := TGUILabel
.Create(fText
, FFontID
);
1825 FColor
:= MENU_ITEMSTEXT_COLOR
;
1828 ControlType
:= TGUISwitch
;
1830 Result
:= (Control
as TGUISwitch
);
1833 if FIndex
= -1 then FIndex
:= i
;
1838 function TGUIMenu
.AddEdit(fText
: string): TGUIEdit
;
1845 Control
:= TGUIEdit
.Create(FFontID
);
1846 with Control
as TGUIEdit
do
1848 FWindow
:= Self
.FWindow
;
1849 FColor
:= MENU_ITEMSCTRL_COLOR
;
1852 if fText
= '' then Text := nil else
1854 Text := TGUILabel
.Create(fText
, FFontID
);
1855 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1858 ControlType
:= TGUIEdit
;
1860 Result
:= (Control
as TGUIEdit
);
1863 if FIndex
= -1 then FIndex
:= i
;
1868 procedure TGUIMenu
.Update
;
1874 if FCounter
= 0 then FCounter
:= MENU_MARKERDELAY
else Dec(FCounter
);
1876 if FItems
<> nil then
1877 for a
:= 0 to High(FItems
) do
1878 if FItems
[a
].Control
<> nil then
1879 (FItems
[a
].Control
as FItems
[a
].ControlType
).Update
;
1882 function TGUIMenu
.AddKeyRead(fText
: string): TGUIKeyRead
;
1889 Control
:= TGUIKeyRead
.Create(FFontID
);
1890 with Control
as TGUIKeyRead
do
1892 FWindow
:= Self
.FWindow
;
1893 FColor
:= MENU_ITEMSCTRL_COLOR
;
1896 Text := TGUILabel
.Create(fText
, FFontID
);
1899 FColor
:= MENU_ITEMSTEXT_COLOR
;
1902 ControlType
:= TGUIKeyRead
;
1904 Result
:= (Control
as TGUIKeyRead
);
1907 if FIndex
= -1 then FIndex
:= i
;
1912 function TGUIMenu
.AddKeyRead2(fText
: string): TGUIKeyRead2
;
1919 Control
:= TGUIKeyRead2
.Create(FFontID
);
1920 with Control
as TGUIKeyRead2
do
1922 FWindow
:= Self
.FWindow
;
1923 FColor
:= MENU_ITEMSCTRL_COLOR
;
1926 Text := TGUILabel
.Create(fText
, FFontID
);
1929 FColor
:= MENU_ITEMSCTRL_COLOR
; //MENU_ITEMSTEXT_COLOR;
1933 ControlType
:= TGUIKeyRead2
;
1935 Result
:= (Control
as TGUIKeyRead2
);
1938 if FIndex
= -1 then FIndex
:= i
;
1943 function TGUIMenu
.AddList(fText
: string; Width
, Height
: Word): TGUIListBox
;
1950 Control
:= TGUIListBox
.Create(FFontID
, Width
, Height
);
1951 with Control
as TGUIListBox
do
1953 FWindow
:= Self
.FWindow
;
1954 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
1955 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
1958 Text := TGUILabel
.Create(fText
, FFontID
);
1961 FColor
:= MENU_ITEMSTEXT_COLOR
;
1964 ControlType
:= TGUIListBox
;
1966 Result
:= (Control
as TGUIListBox
);
1969 if FIndex
= -1 then FIndex
:= i
;
1974 function TGUIMenu
.AddFileList(fText
: string; Width
, Height
: Word): TGUIFileListBox
;
1981 Control
:= TGUIFileListBox
.Create(FFontID
, Width
, Height
);
1982 with Control
as TGUIFileListBox
do
1984 FWindow
:= Self
.FWindow
;
1985 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
1986 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
1989 if fText
= '' then Text := nil else
1991 Text := TGUILabel
.Create(fText
, FFontID
);
1992 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1995 ControlType
:= TGUIFileListBox
;
1997 Result
:= (Control
as TGUIFileListBox
);
2000 if FIndex
= -1 then FIndex
:= i
;
2005 function TGUIMenu
.AddLabel(fText
: string): TGUILabel
;
2012 Control
:= TGUILabel
.Create('', FFontID
);
2013 with Control
as TGUILabel
do
2015 FWindow
:= Self
.FWindow
;
2016 FColor
:= MENU_ITEMSCTRL_COLOR
;
2019 Text := TGUILabel
.Create(fText
, FFontID
);
2022 FColor
:= MENU_ITEMSTEXT_COLOR
;
2025 ControlType
:= TGUILabel
;
2027 Result
:= (Control
as TGUILabel
);
2030 if FIndex
= -1 then FIndex
:= i
;
2035 function TGUIMenu
.AddMemo(fText
: string; Width
, Height
: Word): TGUIMemo
;
2042 Control
:= TGUIMemo
.Create(FFontID
, Width
, Height
);
2043 with Control
as TGUIMemo
do
2045 FWindow
:= Self
.FWindow
;
2046 FColor
:= MENU_ITEMSTEXT_COLOR
;
2049 if fText
= '' then Text := nil else
2051 Text := TGUILabel
.Create(fText
, FFontID
);
2052 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
2055 ControlType
:= TGUIMemo
;
2057 Result
:= (Control
as TGUIMemo
);
2060 if FIndex
= -1 then FIndex
:= i
;
2065 procedure TGUIMenu
.UpdateIndex();
2073 if (FIndex
< 0) or (FIndex
> High(FItems
)) then
2079 if FItems
[FIndex
].Control
.Enabled
then
2088 constructor TGUIScroll
.Create
;
2093 FOnChangeEvent
:= nil;
2095 g_Texture_Get(SCROLL_LEFT
, FLeftID
);
2096 g_Texture_Get(SCROLL_RIGHT
, FRightID
);
2097 g_Texture_Get(SCROLL_MIDDLE
, FMiddleID
);
2098 g_Texture_Get(SCROLL_MARKER
, FMarkerID
);
2101 procedure TGUIScroll
.Draw
;
2107 e_Draw(FLeftID
, FX
, FY
, 0, True, False);
2108 e_Draw(FRightID
, FX
+8+(FMax
+1)*8, FY
, 0, True, False);
2110 for a
:= 0 to FMax
do
2111 e_Draw(FMiddleID
, FX
+8+a
*8, FY
, 0, True, False);
2113 e_Draw(FMarkerID
, FX
+8+FValue
*8, FY
, 0, True, False);
2116 procedure TGUIScroll
.FSetValue(a
: Integer);
2118 if a
> FMax
then FValue
:= FMax
else FValue
:= a
;
2121 function TGUIScroll
.GetWidth
: Integer;
2123 Result
:= 16+(FMax
+1)*8;
2126 procedure TGUIScroll
.OnMessage(var Msg
: TMessage
);
2128 if not FEnabled
then Exit
;
2136 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2140 g_Sound_PlayEx(SCROLL_SUBSOUND
);
2141 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2143 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2144 if FValue
< FMax
then
2147 g_Sound_PlayEx(SCROLL_ADDSOUND
);
2148 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2155 procedure TGUIScroll
.Update
;
2163 procedure TGUISwitch
.AddItem(Item
: string);
2165 SetLength(FItems
, Length(FItems
)+1);
2166 FItems
[High(FItems
)] := Item
;
2168 if FIndex
= -1 then FIndex
:= 0;
2171 constructor TGUISwitch
.Create(FontID
: DWORD
);
2177 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2180 procedure TGUISwitch
.Draw
;
2184 FFont
.Draw(FX
, FY
, FItems
[FIndex
], FColor
.R
, FColor
.G
, FColor
.B
);
2187 function TGUISwitch
.GetText
: string;
2189 if FIndex
<> -1 then Result
:= FItems
[FIndex
]
2193 function TGUISwitch
.GetWidth
: Integer;
2200 if FItems
= nil then Exit
;
2202 for a
:= 0 to High(FItems
) do
2204 FFont
.GetTextSize(FItems
[a
], w
, h
);
2205 if w
> Result
then Result
:= w
;
2209 procedure TGUISwitch
.OnMessage(var Msg
: TMessage
);
2211 if not FEnabled
then Exit
;
2215 if FItems
= nil then Exit
;
2220 IK_RETURN
, IK_RIGHT
, IK_KPRETURN
, IK_KPRIGHT
, VK_FIRE
, VK_OPEN
, VK_RIGHT
,
2221 JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
,
2222 JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2224 if FIndex
< High(FItems
) then
2229 g_Sound_PlayEx(SCROLL_ADDSOUND
);
2231 if @FOnChangeEvent
<> nil then
2232 FOnChangeEvent(Self
);
2235 IK_LEFT
, IK_KPLEFT
, VK_LEFT
,
2236 JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2241 FIndex
:= High(FItems
);
2243 g_Sound_PlayEx(SCROLL_SUBSOUND
);
2245 if @FOnChangeEvent
<> nil then
2246 FOnChangeEvent(Self
);
2252 procedure TGUISwitch
.Update
;
2260 constructor TGUIEdit
.Create(FontID
: DWORD
);
2264 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2270 g_Texture_Get(EDIT_LEFT
, FLeftID
);
2271 g_Texture_Get(EDIT_RIGHT
, FRightID
);
2272 g_Texture_Get(EDIT_MIDDLE
, FMiddleID
);
2275 procedure TGUIEdit
.Draw
;
2282 e_Draw(FLeftID
, FX
, FY
, 0, True, False);
2283 e_Draw(FRightID
, FX
+8+FWidth
*16, FY
, 0, True, False);
2285 for c
:= 0 to FWidth
-1 do
2286 e_Draw(FMiddleID
, FX
+8+c
*16, FY
, 0, True, False);
2291 if FInvalid
and (FWindow
.FActiveControl
<> self
) then begin r
:= 128; g
:= 128; b
:= 128; end;
2292 FFont
.Draw(FX
+8, FY
, FText
, r
, g
, b
);
2294 if (FWindow
.FActiveControl
= self
) then
2296 FFont
.GetTextSize(Copy(FText
, 1, FCaretPos
), w
, h
);
2297 h
:= e_CharFont_GetMaxHeight(FFont
.ID
);
2298 e_DrawLine(2, FX
+8+w
, FY
+h
-3, FX
+8+w
+EDIT_CURSORLEN
, FY
+h
-3,
2299 EDIT_CURSORCOLOR
.R
, EDIT_CURSORCOLOR
.G
, EDIT_CURSORCOLOR
.B
);
2303 function TGUIEdit
.GetWidth
: Integer;
2305 Result
:= 16+FWidth
*16;
2308 procedure TGUIEdit
.OnMessage(var Msg
: TMessage
);
2310 if not FEnabled
then Exit
;
2319 if (wParam
in [48..57]) and (Chr(wParam
) <> '`') then
2320 if Length(Text) < FMaxLength
then
2322 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2328 if (wParam
in [32..255]) and (Chr(wParam
) <> '`') then
2329 if Length(Text) < FMaxLength
then
2331 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2339 Delete(FText
, FCaretPos
, 1);
2340 if FCaretPos
> 0 then Dec(FCaretPos
);
2342 IK_DELETE
: Delete(FText
, FCaretPos
+ 1, 1);
2343 IK_END
, IK_KPEND
: FCaretPos
:= Length(FText
);
2344 IK_HOME
, IK_KPHOME
: FCaretPos
:= 0;
2345 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
: if FCaretPos
> 0 then Dec(FCaretPos
);
2346 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
: if FCaretPos
< Length(FText
) then Inc(FCaretPos
);
2347 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2350 if FActiveControl
<> Self
then
2353 if @FOnEnterEvent
<> nil then FOnEnterEvent(Self
);
2357 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
2358 else SetActive(nil);
2359 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2365 g_GUIGrabInput
:= (@FOnEnterEvent
= nil) and (FWindow
.FActiveControl
= Self
);
2366 g_Touch_ShowKeyboard(g_GUIGrabInput
)
2369 procedure TGUIEdit
.SetText(Text: string);
2371 if Length(Text) > FMaxLength
then SetLength(Text, FMaxLength
);
2373 FCaretPos
:= Length(FText
);
2376 procedure TGUIEdit
.Update
;
2383 constructor TGUIKeyRead
.Create(FontID
: DWORD
);
2389 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2392 procedure TGUIKeyRead
.Draw
;
2396 FFont
.Draw(FX
, FY
, IfThen(FIsQuery
, KEYREAD_QUERY
, IfThen(FKey
<> 0, e_KeyNames
[FKey
], KEYREAD_CLEAR
)),
2397 FColor
.R
, FColor
.G
, FColor
.B
);
2400 function TGUIKeyRead
.GetWidth
: Integer;
2407 for a
:= 0 to 255 do
2409 FFont
.GetTextSize(e_KeyNames
[a
], w
, h
);
2410 Result
:= Max(Result
, w
);
2413 FFont
.GetTextSize(KEYREAD_QUERY
, w
, h
);
2414 if w
> Result
then Result
:= w
;
2416 FFont
.GetTextSize(KEYREAD_CLEAR
, w
, h
);
2417 if w
> Result
then Result
:= w
;
2420 function TGUIKeyRead
.WantActivationKey (key
: LongInt): Boolean;
2423 (key
= IK_BACKSPACE
) or
2427 procedure TGUIKeyRead
.OnMessage(var Msg
: TMessage
);
2428 procedure actDefCtl ();
2431 if FDefControl
<> '' then
2432 SetActive(GetControl(FDefControl
))
2440 if not FEnabled
then
2446 if not FIsQuery
then
2449 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2452 if FActiveControl
<> Self
then
2456 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2469 VK_FIRSTKEY
..VK_LASTKEY
: // do not allow to bind virtual keys
2475 if (e_KeyNames
[wParam
] <> '') and not g_Console_MatchBind(wParam
, 'togglemenu') then
2483 g_GUIGrabInput
:= FIsQuery
2488 constructor TGUIKeyRead2
.Create(FontID
: DWORD
);
2501 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2503 FMaxKeyNameWdt
:= 0;
2504 for a
:= 0 to 255 do
2506 FFont
.GetTextSize(e_KeyNames
[a
], w
, h
);
2507 FMaxKeyNameWdt
:= Max(FMaxKeyNameWdt
, w
);
2510 FMaxKeyNameWdt
:= FMaxKeyNameWdt
-(FMaxKeyNameWdt
div 3);
2512 FFont
.GetTextSize(KEYREAD_QUERY
, w
, h
);
2513 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2515 FFont
.GetTextSize(KEYREAD_CLEAR
, w
, h
);
2516 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2519 procedure TGUIKeyRead2
.Draw
;
2520 procedure drawText (idx
: Integer);
2526 if idx
= 0 then kk
:= FKey0
else kk
:= FKey1
;
2528 if idx
= 0 then x
:= FX
+8 else x
:= FX
+8+FMaxKeyNameWdt
+16;
2532 if FKeyIdx
= idx
then begin r
:= 255; g
:= 255; b
:= 255; end;
2533 if FIsQuery
and (FKeyIdx
= idx
) then
2534 FFont
.Draw(x
, y
, KEYREAD_QUERY
, r
, g
, b
)
2536 FFont
.Draw(x
, y
, IfThen(kk
<> 0, e_KeyNames
[kk
], KEYREAD_CLEAR
), r
, g
, b
);
2542 //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);
2543 //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);
2548 function TGUIKeyRead2
.GetWidth
: Integer;
2550 Result
:= FMaxKeyNameWdt
*2+8+8+16;
2553 function TGUIKeyRead2
.WantActivationKey (key
: LongInt): Boolean;
2556 IK_BACKSPACE
, IK_LEFT
, IK_RIGHT
, IK_KPLEFT
, IK_KPRIGHT
, VK_LEFT
, VK_RIGHT
,
2557 JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
,
2558 JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2565 procedure TGUIKeyRead2
.OnMessage(var Msg
: TMessage
);
2566 procedure actDefCtl ();
2569 if FDefControl
<> '' then
2570 SetActive(GetControl(FDefControl
))
2578 if not FEnabled
then
2584 if not FIsQuery
then
2587 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2590 if FActiveControl
<> Self
then
2594 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2596 if (FKeyIdx
= 0) then FKey0
:= 0 else FKey1
:= 0;
2599 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2604 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2617 VK_FIRSTKEY
..VK_LASTKEY
: // do not allow to bind virtual keys
2623 if (e_KeyNames
[wParam
] <> '') and not g_Console_MatchBind(wParam
, 'togglemenu') then
2625 if (FKeyIdx
= 0) then FKey0
:= wParam
else FKey1
:= wParam
;
2633 g_GUIGrabInput
:= FIsQuery
2639 constructor TGUIModelView
.Create
;
2646 destructor TGUIModelView
.Destroy
;
2653 procedure TGUIModelView
.Draw
;
2657 DrawBox(FX
, FY
, 4, 4);
2659 if FModel
<> nil then FModel
.Draw(FX
+4, FY
+4);
2662 procedure TGUIModelView
.NextAnim();
2664 if FModel
= nil then
2667 if FModel
.Animation
< A_PAIN
then
2668 FModel
.ChangeAnimation(FModel
.Animation
+1, True)
2670 FModel
.ChangeAnimation(A_STAND
, True);
2673 procedure TGUIModelView
.NextWeapon();
2675 if FModel
= nil then
2678 if FModel
.Weapon
< WP_LAST
then
2679 FModel
.SetWeapon(FModel
.Weapon
+1)
2681 FModel
.SetWeapon(WEAPON_KASTET
);
2684 procedure TGUIModelView
.OnMessage(var Msg
: TMessage
);
2690 procedure TGUIModelView
.SetColor(Red
, Green
, Blue
: Byte);
2692 if FModel
<> nil then FModel
.SetColor(Red
, Green
, Blue
);
2695 procedure TGUIModelView
.SetModel(ModelName
: string);
2699 FModel
:= g_PlayerModel_Get(ModelName
);
2702 procedure TGUIModelView
.Update
;
2709 if FModel
<> nil then FModel
.Update
;
2714 constructor TGUIMapPreview
.Create();
2720 destructor TGUIMapPreview
.Destroy();
2726 procedure TGUIMapPreview
.Draw();
2733 DrawBox(FX
, FY
, MAPPREVIEW_WIDTH
, MAPPREVIEW_HEIGHT
);
2735 if (FMapSize
.X
<= 0) or (FMapSize
.Y
<= 0) then
2738 e_DrawFillQuad(FX
+4, FY
+4,
2739 FX
+4 + Trunc(FMapSize
.X
/ FScale
) - 1,
2740 FY
+4 + Trunc(FMapSize
.Y
/ FScale
) - 1,
2743 if FMapData
<> nil then
2744 for a
:= 0 to High(FMapData
) do
2747 if X1
> MAPPREVIEW_WIDTH
*16 then Continue
;
2748 if Y1
> MAPPREVIEW_HEIGHT
*16 then Continue
;
2750 if X2
< 0 then Continue
;
2751 if Y2
< 0 then Continue
;
2753 if X2
> MAPPREVIEW_WIDTH
*16 then X2
:= MAPPREVIEW_WIDTH
*16;
2754 if Y2
> MAPPREVIEW_HEIGHT
*16 then Y2
:= MAPPREVIEW_HEIGHT
*16;
2756 if X1
< 0 then X1
:= 0;
2757 if Y1
< 0 then Y1
:= 0;
2798 if ((X2
-X1
) > 0) and ((Y2
-Y1
) > 0) then
2799 e_DrawFillQuad(FX
+4 + X1
, FY
+4 + Y1
,
2800 FX
+4 + X2
- 1, FY
+4 + Y2
- 1, r
, g
, b
, 0);
2804 procedure TGUIMapPreview
.OnMessage(var Msg
: TMessage
);
2810 procedure TGUIMapPreview
.SetMap(Res
: string);
2815 //header: TMapHeaderRec_1;
2820 map
: TDynRecord
= nil;
2827 FileName
:= g_ExtractWadName(Res
);
2829 WAD
:= TWADFile
.Create();
2830 if not WAD
.ReadFile(FileName
) then
2836 //k8: ignores path again
2837 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
2846 map
:= g_Map_ParseMap(Data
, Len
);
2856 if (map
= nil) then exit
;
2859 panlist
:= map
.field
['panel'];
2860 //header := GetMapHeader(map);
2862 FMapSize
.X
:= map
.Width
div 16;
2863 FMapSize
.Y
:= map
.Height
div 16;
2865 rX
:= Ceil(map
.Width
/ (MAPPREVIEW_WIDTH
*256.0));
2866 rY
:= Ceil(map
.Height
/ (MAPPREVIEW_HEIGHT
*256.0));
2867 FScale
:= max(rX
, rY
);
2871 if (panlist
<> nil) then
2873 for pan
in panlist
do
2875 if (pan
.PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or
2876 PANEL_STEP
or PANEL_WATER
or
2877 PANEL_ACID1
or PANEL_ACID2
)) <> 0 then
2879 SetLength(FMapData
, Length(FMapData
)+1);
2880 with FMapData
[High(FMapData
)] do
2885 X2
:= (pan
.X
+ pan
.Width
) div 16;
2886 Y2
:= (pan
.Y
+ pan
.Height
) div 16;
2888 X1
:= Trunc(X1
/FScale
+ 0.5);
2889 Y1
:= Trunc(Y1
/FScale
+ 0.5);
2890 X2
:= Trunc(X2
/FScale
+ 0.5);
2891 Y2
:= Trunc(Y2
/FScale
+ 0.5);
2893 if (X1
<> X2
) or (Y1
<> Y2
) then
2901 PanelType
:= pan
.PanelType
;
2907 //writeln('freeing map');
2912 procedure TGUIMapPreview
.ClearMap();
2914 SetLength(FMapData
, 0);
2921 procedure TGUIMapPreview
.Update();
2927 function TGUIMapPreview
.GetScaleStr(): String;
2929 if FScale
> 0.0 then
2931 Result
:= FloatToStrF(FScale
*16.0, ffFixed
, 3, 3);
2932 while (Result
[Length(Result
)] = '0') do
2933 Delete(Result
, Length(Result
), 1);
2934 if (Result
[Length(Result
)] = ',') or (Result
[Length(Result
)] = '.') then
2935 Delete(Result
, Length(Result
), 1);
2936 Result
:= '1 : ' + Result
;
2944 procedure TGUIListBox
.AddItem(Item
: string);
2946 SetLength(FItems
, Length(FItems
)+1);
2947 FItems
[High(FItems
)] := Item
;
2949 if FSort
then g_Basic
.Sort(FItems
);
2952 function TGUIListBox
.ItemExists (item
: String): Boolean;
2956 while (i
<= High(FItems
)) and (FItems
[i
] <> item
) do Inc(i
);
2957 result
:= i
<= High(FItems
)
2960 procedure TGUIListBox
.Clear
;
2968 constructor TGUIListBox
.Create(FontID
: DWORD
; Width
, Height
: Word);
2972 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2977 FOnChangeEvent
:= nil;
2979 FDrawScroll
:= True;
2982 procedure TGUIListBox
.Draw
;
2990 if FDrawBack
then DrawBox(FX
, FY
, FWidth
+1, FHeight
);
2992 DrawScroll(FX
+4+FWidth
*16, FY
+4, FHeight
, (FStartLine
> 0) and (FItems
<> nil),
2993 (FStartLine
+FHeight
-1 < High(FItems
)) and (FItems
<> nil));
2995 if FItems
<> nil then
2996 for a
:= FStartLine
to Min(High(FItems
), FStartLine
+FHeight
-1) do
3000 FFont
.GetTextSize(s
, w2
, h2
);
3001 while (Length(s
) > 0) and (w2
> FWidth
*16) do
3003 SetLength(s
, Length(s
)-1);
3004 FFont
.GetTextSize(s
, w2
, h2
);
3008 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, s
, FActiveColor
.R
, FActiveColor
.G
, FActiveColor
.B
)
3010 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, s
, FUnActiveColor
.R
, FUnActiveColor
.G
, FUnActiveColor
.B
);
3014 function TGUIListBox
.GetHeight
: Integer;
3016 Result
:= 8+FHeight
*16;
3019 function TGUIListBox
.GetWidth
: Integer;
3021 Result
:= 8+(FWidth
+1)*16;
3024 procedure TGUIListBox
.OnMessage(var Msg
: TMessage
);
3028 if not FEnabled
then Exit
;
3032 if FItems
= nil then Exit
;
3045 FIndex
:= High(FItems
);
3046 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
3048 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
3052 if FIndex
< FStartLine
then Dec(FStartLine
);
3053 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3055 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
3056 if FIndex
< High(FItems
) then
3059 if FIndex
> FStartLine
+FHeight
-1 then Inc(FStartLine
);
3060 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3062 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
3065 if FActiveControl
<> Self
then SetActive(Self
)
3067 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
3068 else SetActive(nil);
3072 for a
:= 0 to High(FItems
) do
3073 if (Length(FItems
[a
]) > 0) and (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) then
3076 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
3077 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3083 function TGUIListBox
.SelectedItem(): String;
3087 if (FIndex
< 0) or (FItems
= nil) or
3088 (FIndex
> High(FItems
)) then
3091 Result
:= FItems
[FIndex
];
3094 procedure TGUIListBox
.FSetItems(Items
: SSArray
);
3096 if FItems
<> nil then
3104 if FSort
then g_Basic
.Sort(FItems
);
3107 procedure TGUIListBox
.SelectItem(Item
: String);
3111 if FItems
= nil then
3115 Item
:= LowerCase(Item
);
3117 for a
:= 0 to High(FItems
) do
3118 if LowerCase(FItems
[a
]) = Item
then
3124 if FIndex
< FHeight
then
3127 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
3130 procedure TGUIListBox
.FSetIndex(aIndex
: Integer);
3132 if FItems
= nil then
3135 if (aIndex
< 0) or (aIndex
> High(FItems
)) then
3140 if FIndex
<= FHeight
then
3143 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
3148 procedure TGUIFileListBox
.OnMessage(var Msg
: TMessage
);
3150 a
, b
: Integer; s
: AnsiString
;
3152 if not FEnabled
then
3155 if FItems
= nil then
3166 if @FOnChangeEvent
<> nil then
3167 FOnChangeEvent(Self
);
3172 FIndex
:= High(FItems
);
3173 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
3174 if @FOnChangeEvent
<> nil then
3175 FOnChangeEvent(Self
);
3178 IK_PAGEUP
, IK_KPPAGEUP
:
3180 if FIndex
> FHeight
then
3181 FIndex
:= FIndex
-FHeight
3185 if FStartLine
> FHeight
then
3186 FStartLine
:= FStartLine
-FHeight
3191 IK_PAGEDN
, IK_KPPAGEDN
:
3193 if FIndex
< High(FItems
)-FHeight
then
3194 FIndex
:= FIndex
+FHeight
3196 FIndex
:= High(FItems
);
3198 if FStartLine
< High(FItems
)-FHeight
then
3199 FStartLine
:= FStartLine
+FHeight
3201 FStartLine
:= High(FItems
)-FHeight
+1;
3204 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
, VK_UP
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
3208 if FIndex
< FStartLine
then
3210 if @FOnChangeEvent
<> nil then
3211 FOnChangeEvent(Self
);
3214 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
, VK_DOWN
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
3215 if FIndex
< High(FItems
) then
3218 if FIndex
> FStartLine
+FHeight
-1 then
3220 if @FOnChangeEvent
<> nil then
3221 FOnChangeEvent(Self
);
3224 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
3227 if FActiveControl
<> Self
then
3231 if FItems
[FIndex
][1] = #29 then // Ïàïêà
3233 if FItems
[FIndex
] = #29 + '..' then
3235 //e_LogWritefln('TGUIFileListBox: Upper dir "%s" -> "%s"', [FSubPath, e_UpperDir(FSubPath)]);
3236 FSubPath
:= e_UpperDir(FSubPath
)
3240 s
:= Copy(AnsiString(FItems
[FIndex
]), 2);
3241 //e_LogWritefln('TGUIFileListBox: Enter dir "%s" -> "%s"', [FSubPath, e_CatPath(FSubPath, s)]);
3242 FSubPath
:= e_CatPath(FSubPath
, s
);
3249 if FDefControl
<> '' then
3250 SetActive(GetControl(FDefControl
))
3258 for b
:= FIndex
+ 1 to High(FItems
) + FIndex
do
3260 a
:= b
mod Length(FItems
);
3261 if ( (Length(FItems
[a
]) > 0) and
3262 (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) ) or
3263 ( (Length(FItems
[a
]) > 1) and
3264 (FItems
[a
][1] = #29) and // Ïàïêà
3265 (LowerCase(FItems
[a
][2]) = LowerCase(Chr(wParam
))) ) then
3268 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
3269 if @FOnChangeEvent
<> nil then
3270 FOnChangeEvent(Self
);
3277 procedure TGUIFileListBox
.ScanDirs
;
3278 var i
, j
: Integer; path
: AnsiString
; SR
: TSearchRec
; sm
, sc
: String;
3282 i
:= High(FBaseList
);
3285 path
:= e_CatPath(FBaseList
[i
], FSubPath
);
3288 if FindFirst(path
+ '/' + '*', faDirectory
, SR
) = 0 then
3291 if LongBool(SR
.Attr
and faDirectory
) then
3292 if (SR
.Name
<> '.') and ((FSubPath
<> '') or (SR
.Name
<> '..')) then
3293 if Self
.ItemExists(#1 + SR
.Name
) = false then
3294 Self
.AddItem(#1 + SR
.Name
)
3295 until FindNext(SR
) <> 0
3302 i
:= High(FBaseList
);
3305 path
:= e_CatPath(FBaseList
[i
], FSubPath
);
3311 j
:= length(sm
) + 1;
3312 sc
:= Copy(sm
, 1, j
- 1);
3314 if FindFirst(path
+ '/' + sc
, faAnyFile
, SR
) = 0 then
3317 if Self
.ItemExists(SR
.Name
) = false then
3319 until FindNext(SR
) <> 0
3326 for i
:= 0 to High(FItems
) do
3327 if FItems
[i
][1] = #1 then
3328 FItems
[i
][1] := #29;
3331 procedure TGUIFileListBox
.SetBase (dirs
: SSArray
; path
: String = '');
3338 function TGUIFileListBox
.SelectedItem (): String;
3342 if (FIndex
>= 0) and (FIndex
<= High(FItems
)) and (FItems
[FIndex
][1] <> '/') and (FItems
[FIndex
][1] <> '\') then
3344 s
:= e_CatPath(FSubPath
, FItems
[FIndex
]);
3345 if e_FindResource(FBaseList
, s
) = true then
3346 result
:= ExpandFileName(s
)
3348 e_LogWritefln('TGUIFileListBox.SelectedItem -> "%s"', [result
]);
3351 procedure TGUIFileListBox
.UpdateFileList();
3355 if (FIndex
= -1) or (FItems
= nil) or
3356 (FIndex
> High(FItems
)) or
3357 (FItems
[FIndex
][1] = '/') or
3358 (FItems
[FIndex
][1] = '\') then
3361 fn
:= FItems
[FIndex
];
3372 procedure TGUIMemo
.Clear
;
3378 constructor TGUIMemo
.Create(FontID
: DWORD
; Width
, Height
: Word);
3382 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
3387 FDrawScroll
:= True;
3390 procedure TGUIMemo
.Draw
;
3396 if FDrawBack
then DrawBox(FX
, FY
, FWidth
+1, FHeight
);
3398 DrawScroll(FX
+4+FWidth
*16, FY
+4, FHeight
, (FStartLine
> 0) and (FLines
<> nil),
3399 (FStartLine
+FHeight
-1 < High(FLines
)) and (FLines
<> nil));
3401 if FLines
<> nil then
3402 for a
:= FStartLine
to Min(High(FLines
), FStartLine
+FHeight
-1) do
3403 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, FLines
[a
], FColor
.R
, FColor
.G
, FColor
.B
);
3406 function TGUIMemo
.GetHeight
: Integer;
3408 Result
:= 8+FHeight
*16;
3411 function TGUIMemo
.GetWidth
: Integer;
3413 Result
:= 8+(FWidth
+1)*16;
3416 procedure TGUIMemo
.OnMessage(var Msg
: TMessage
);
3418 if not FEnabled
then Exit
;
3422 if FLines
= nil then Exit
;
3428 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
, VK_UP
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
3429 if FStartLine
> 0 then
3431 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
, VK_DOWN
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
3432 if FStartLine
< Length(FLines
)-FHeight
then
3434 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
3437 if FActiveControl
<> Self
then
3443 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
3444 else SetActive(nil);
3450 procedure TGUIMemo
.SetText(Text: string);
3453 FLines
:= GetLines(Text, FFont
.ID
, FWidth
*16);
3458 procedure TGUIimage
.ClearImage();
3460 if FImageRes
= '' then Exit
;
3462 g_Texture_Delete(FImageRes
);
3466 constructor TGUIimage
.Create();
3473 destructor TGUIimage
.Destroy();
3478 procedure TGUIimage
.Draw();
3484 if FImageRes
= '' then
3486 if g_Texture_Get(FDefaultRes
, ID
) then e_Draw(ID
, FX
, FY
, 0, True, False);
3489 if g_Texture_Get(FImageRes
, ID
) then e_Draw(ID
, FX
, FY
, 0, True, False);
3492 procedure TGUIimage
.OnMessage(var Msg
: TMessage
);
3497 procedure TGUIimage
.SetImage(Res
: string);
3501 if g_Texture_CreateWADEx(Res
, Res
) then FImageRes
:= Res
;
3504 procedure TGUIimage
.Update();