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, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
22 {$IFDEF USE_MEMPOOL}mempool
,{$ENDIF}
23 e_graphics
, e_input
, e_log
, g_playermodel
, g_basic
, g_touch
, MAPDEF
, utils
;
26 MAINMENU_HEADER_COLOR
: TRGB
= (R
:255; G
:255; B
:255);
27 MAINMENU_ITEMS_COLOR
: TRGB
= (R
:255; G
:255; B
:255);
28 MAINMENU_UNACTIVEITEMS_COLOR
: TRGB
= (R
:192; G
:192; B
:192);
29 MAINMENU_CLICKSOUND
= 'MENU_SELECT';
30 MAINMENU_CHANGESOUND
= 'MENU_CHANGE';
32 MAINMENU_MARKER1
= 'MAINMENU_MARKER1';
33 MAINMENU_MARKER2
= 'MAINMENU_MARKER2';
34 MAINMENU_MARKERDELAY
= 24;
35 WINDOW_CLOSESOUND
= 'MENU_CLOSE';
36 MENU_HEADERCOLOR
: TRGB
= (R
:255; G
:255; B
:255);
37 MENU_ITEMSTEXT_COLOR
: TRGB
= (R
:255; G
:255; B
:255);
38 MENU_UNACTIVEITEMS_COLOR
: TRGB
= (R
:128; G
:128; B
:128);
39 MENU_ITEMSCTRL_COLOR
: TRGB
= (R
:255; G
:0; B
:0);
42 MENU_CLICKSOUND
= 'MENU_SELECT';
43 MENU_CHANGESOUND
= 'MENU_CHANGE';
44 MENU_MARKERDELAY
= 24;
45 SCROLL_LEFT
= 'SCROLL_LEFT';
46 SCROLL_RIGHT
= 'SCROLL_RIGHT';
47 SCROLL_MIDDLE
= 'SCROLL_MIDDLE';
48 SCROLL_MARKER
= 'SCROLL_MARKER';
49 SCROLL_ADDSOUND
= 'SCROLL_ADD';
50 SCROLL_SUBSOUND
= 'SCROLL_SUB';
51 EDIT_LEFT
= 'EDIT_LEFT';
52 EDIT_RIGHT
= 'EDIT_RIGHT';
53 EDIT_MIDDLE
= 'EDIT_MIDDLE';
54 EDIT_CURSORCOLOR
: TRGB
= (R
:200; G
:0; B
:0);
56 KEYREAD_QUERY
= '<...>';
57 KEYREAD_CLEAR
= '???';
60 MAPPREVIEW_HEIGHT
= 8;
70 BSCROLL_UPA
= 'BSCROLL_UP_A';
71 BSCROLL_UPU
= 'BSCROLL_UP_U';
72 BSCROLL_DOWNA
= 'BSCROLL_DOWN_A';
73 BSCROLL_DOWNU
= 'BSCROLL_DOWN_U';
74 BSCROLL_MIDDLE
= 'BSCROLL_MIDDLE';
86 TFontType
= (Texture
, Character
);
88 TFont
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
94 constructor Create(FontID
: DWORD
; FontType
: TFontType
);
95 destructor Destroy
; override;
96 procedure Draw(X
, Y
: Integer; Text: string; R
, G
, B
: Byte);
97 procedure GetTextSize(Text: string; var w
, h
: Word);
98 property Scale
: Single read FScale write FScale
;
104 TOnKeyDownEvent
= procedure(Key
: Byte);
105 TOnKeyDownEventEx
= procedure(win
: TGUIWindow
; Key
: Byte);
106 TOnCloseEvent
= procedure;
107 TOnShowEvent
= procedure;
108 TOnClickEvent
= procedure;
109 TOnChangeEvent
= procedure(Sender
: TGUIControl
);
110 TOnEnterEvent
= procedure(Sender
: TGUIControl
);
112 TGUIControl
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
116 FWindow
: TGUIWindow
;
119 FRightAlign
: Boolean; //HACK! this works only for "normal" menus, only for menu text labels, and generally sux. sorry.
120 FMaxWidth
: Integer; //HACK! used for right-aligning labels
123 procedure OnMessage(var Msg
: TMessage
); virtual;
124 procedure Update
; virtual;
125 procedure Draw
; virtual;
126 function GetWidth(): Integer; virtual;
127 function GetHeight(): Integer; virtual;
128 function WantActivationKey (key
: LongInt): Boolean; virtual;
129 property X
: Integer read FX write FX
;
130 property Y
: Integer read FY write FY
;
131 property Enabled
: Boolean read FEnabled write FEnabled
;
132 property Name
: string read FName write FName
;
133 property UserData
: Pointer read FUserData write FUserData
;
134 property RightAlign
: Boolean read FRightAlign write FRightAlign
; // for menu
137 TGUIWindow
= class{$IFDEF USE_MEMPOOL}(TPoolObject
){$ENDIF}
139 FActiveControl
: TGUIControl
;
141 FPrevWindow
: TGUIWindow
;
143 FBackTexture
: string;
144 FMainWindow
: Boolean;
145 FOnKeyDown
: TOnKeyDownEvent
;
146 FOnKeyDownEx
: TOnKeyDownEventEx
;
147 FOnCloseEvent
: TOnCloseEvent
;
148 FOnShowEvent
: TOnShowEvent
;
151 Childs
: array of TGUIControl
;
152 constructor Create(Name
: string);
153 destructor Destroy
; override;
154 function AddChild(Child
: TGUIControl
): TGUIControl
;
155 procedure OnMessage(var Msg
: TMessage
);
158 procedure SetActive(Control
: TGUIControl
);
159 function GetControl(Name
: string): TGUIControl
;
160 property OnKeyDown
: TOnKeyDownEvent read FOnKeyDown write FOnKeyDown
;
161 property OnKeyDownEx
: TOnKeyDownEventEx read FOnKeyDownEx write FOnKeyDownEx
;
162 property OnClose
: TOnCloseEvent read FOnCloseEvent write FOnCloseEvent
;
163 property OnShow
: TOnShowEvent read FOnShowEvent write FOnShowEvent
;
164 property Name
: string read FName
;
165 property DefControl
: string read FDefControl write FDefControl
;
166 property BackTexture
: string read FBackTexture write FBackTexture
;
167 property MainWindow
: Boolean read FMainWindow write FMainWindow
;
168 property UserData
: Pointer read FUserData write FUserData
;
171 TGUITextButton
= class(TGUIControl
)
180 ProcEx
: procedure (sender
: TGUITextButton
);
181 constructor Create(aProc
: Pointer; FontID
: DWORD
; Text: string);
182 destructor Destroy(); override;
183 procedure OnMessage(var Msg
: TMessage
); override;
184 procedure Update(); override;
185 procedure Draw(); override;
186 function GetWidth(): Integer; override;
187 function GetHeight(): Integer; override;
188 procedure Click(Silent
: Boolean = False);
189 property Caption
: string read FText write FText
;
190 property Color
: TRGB read FColor write FColor
;
191 property Font
: TFont read FFont write FFont
;
192 property ShowWindow
: string read FShowWindow write FShowWindow
;
195 TGUILabel
= class(TGUIControl
)
201 FOnClickEvent
: TOnClickEvent
;
203 constructor Create(Text: string; FontID
: DWORD
);
204 procedure OnMessage(var Msg
: TMessage
); override;
205 procedure Draw
; override;
206 function GetWidth
: Integer; override;
207 function GetHeight
: Integer; override;
208 property OnClick
: TOnClickEvent read FOnClickEvent write FOnClickEvent
;
209 property FixedLength
: Word read FFixedLen write FFixedLen
;
210 property Text: string read FText write FText
;
211 property Color
: TRGB read FColor write FColor
;
212 property Font
: TFont read FFont write FFont
;
215 TGUIScroll
= class(TGUIControl
)
223 FOnChangeEvent
: TOnChangeEvent
;
224 procedure FSetValue(a
: Integer);
226 constructor Create();
227 procedure OnMessage(var Msg
: TMessage
); override;
228 procedure Update
; override;
229 procedure Draw
; override;
230 function GetWidth(): Integer; override;
231 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
232 property Max
: Word read FMax write FMax
;
233 property Value
: Integer read FValue write FSetValue
;
236 TGUISwitch
= class(TGUIControl
)
239 FItems
: array of string;
242 FOnChangeEvent
: TOnChangeEvent
;
244 constructor Create(FontID
: DWORD
);
245 procedure OnMessage(var Msg
: TMessage
); override;
246 procedure AddItem(Item
: string);
247 procedure Update
; override;
248 procedure Draw
; override;
249 function GetWidth(): Integer; override;
250 function GetText
: string;
251 property ItemIndex
: Integer read FIndex write FIndex
;
252 property Color
: TRGB read FColor write FColor
;
253 property Font
: TFont read FFont write FFont
;
254 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
257 TGUIEdit
= class(TGUIControl
)
265 FOnlyDigits
: Boolean;
269 FOnChangeEvent
: TOnChangeEvent
;
270 FOnEnterEvent
: TOnEnterEvent
;
272 procedure SetText(Text: string);
274 constructor Create(FontID
: DWORD
);
275 procedure OnMessage(var Msg
: TMessage
); override;
276 procedure Update
; override;
277 procedure Draw
; override;
278 function GetWidth(): Integer; override;
279 property OnChange
: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent
;
280 property OnEnter
: TOnEnterEvent read FOnEnterEvent write FOnEnterEvent
;
281 property Width
: Word read FWidth write FWidth
;
282 property MaxLength
: Word read FMaxLength write FMaxLength
;
283 property OnlyDigits
: Boolean read FOnlyDigits write FOnlyDigits
;
284 property Text: string read FText write SetText
;
285 property Color
: TRGB read FColor write FColor
;
286 property Font
: TFont read FFont write FFont
;
287 property Invalid
: Boolean read FInvalid write FInvalid
;
290 TGUIKeyRead
= class(TGUIControl
)
297 constructor Create(FontID
: DWORD
);
298 procedure OnMessage(var Msg
: TMessage
); override;
299 procedure Draw
; override;
300 function GetWidth(): Integer; override;
301 function WantActivationKey (key
: LongInt): Boolean; override;
302 property Key
: Word read FKey write FKey
;
303 property Color
: TRGB read FColor write FColor
;
304 property Font
: TFont read FFont write FFont
;
308 TGUIKeyRead2
= class(TGUIControl
)
313 FKey0
, FKey1
: Word; // this should be an array. sorry.
316 FMaxKeyNameWdt
: Integer;
318 constructor Create(FontID
: DWORD
);
319 procedure OnMessage(var Msg
: TMessage
); override;
320 procedure Draw
; override;
321 function GetWidth(): Integer; override;
322 function WantActivationKey (key
: LongInt): Boolean; override;
323 property Key0
: Word read FKey0 write FKey0
;
324 property Key1
: Word read FKey1 write FKey1
;
325 property Color
: TRGB read FColor write FColor
;
326 property Font
: TFont read FFont write FFont
;
329 TGUIModelView
= class(TGUIControl
)
331 FModel
: TPlayerModel
;
335 destructor Destroy
; override;
336 procedure OnMessage(var Msg
: TMessage
); override;
337 procedure SetModel(ModelName
: string);
338 procedure SetColor(Red
, Green
, Blue
: Byte);
339 procedure NextAnim();
340 procedure NextWeapon();
341 procedure Update
; override;
342 procedure Draw
; override;
343 property Model
: TPlayerModel read FModel
;
346 TPreviewPanel
= record
347 X1
, Y1
, X2
, Y2
: Integer;
351 TGUIMapPreview
= class(TGUIControl
)
353 FMapData
: array of TPreviewPanel
;
357 constructor Create();
358 destructor Destroy(); override;
359 procedure OnMessage(var Msg
: TMessage
); override;
360 procedure SetMap(Res
: string);
361 procedure ClearMap();
362 procedure Update(); override;
363 procedure Draw(); override;
364 function GetScaleStr
: String;
367 TGUIImage
= class(TGUIControl
)
372 constructor Create();
373 destructor Destroy(); override;
374 procedure OnMessage(var Msg
: TMessage
); override;
375 procedure SetImage(Res
: string);
376 procedure ClearImage();
377 procedure Update(); override;
378 procedure Draw(); override;
379 property DefaultRes
: string read FDefaultRes write FDefaultRes
;
382 TGUIListBox
= class(TGUIControl
)
386 FUnActiveColor
: TRGB
;
394 FDrawScroll
: Boolean;
395 FOnChangeEvent
: TOnChangeEvent
;
397 procedure FSetItems(Items
: SSArray
);
398 procedure FSetIndex(aIndex
: Integer);
401 constructor Create(FontID
: DWORD
; Width
, Height
: Word);
402 procedure OnMessage(var Msg
: TMessage
); override;
403 procedure Draw(); override;
404 procedure AddItem(Item
: String);
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
)
429 procedure OpenDir(path
: String);
432 procedure OnMessage(var Msg
: TMessage
); override;
433 procedure SetBase(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
;
439 property Path
: String read FPath
;
442 TGUIMemo
= class(TGUIControl
)
451 FDrawScroll
: Boolean;
453 constructor Create(FontID
: DWORD
; Width
, Height
: Word);
454 procedure OnMessage(var Msg
: TMessage
); override;
455 procedure Draw
; override;
457 function GetWidth(): Integer; override;
458 function GetHeight(): Integer; override;
459 procedure SetText(Text: string);
460 property DrawBack
: Boolean read FDrawBack write FDrawBack
;
461 property DrawScrollBar
: Boolean read FDrawScroll write FDrawScroll
;
462 property Color
: TRGB read FColor write FColor
;
463 property Font
: TFont read FFont write FFont
;
466 TGUIMainMenu
= class(TGUIControl
)
468 FButtons
: array of TGUITextButton
;
476 constructor Create(FontID
: DWORD
; 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;
539 procedure g_GUI_Init();
540 function g_GUI_AddWindow(Window
: TGUIWindow
): TGUIWindow
;
541 function g_GUI_GetWindow(Name
: string): TGUIWindow
;
542 procedure g_GUI_ShowWindow(Name
: string);
543 procedure g_GUI_HideWindow(PlaySound
: Boolean = True);
544 function g_GUI_Destroy(): Boolean;
545 procedure g_GUI_SaveMenuPos();
546 procedure g_GUI_LoadMenuPos();
552 {$INCLUDE ../nogl/noGLuses.inc}
553 g_textures
, g_sound
, SysUtils
,
554 g_game
, Math
, StrUtils
, g_player
, g_options
,
555 g_map
, g_weapons
, xdynrec
, wadreader
;
559 Box
: Array [0..8] of DWORD
;
560 Saved_Windows
: SSArray
;
563 procedure g_GUI_Init();
565 g_Texture_Get(BOX1
, Box
[0]);
566 g_Texture_Get(BOX2
, Box
[1]);
567 g_Texture_Get(BOX3
, Box
[2]);
568 g_Texture_Get(BOX4
, Box
[3]);
569 g_Texture_Get(BOX5
, Box
[4]);
570 g_Texture_Get(BOX6
, Box
[5]);
571 g_Texture_Get(BOX7
, Box
[6]);
572 g_Texture_Get(BOX8
, Box
[7]);
573 g_Texture_Get(BOX9
, Box
[8]);
576 function g_GUI_Destroy(): Boolean;
580 Result
:= (Length(g_GUIWindows
) > 0);
582 for i
:= 0 to High(g_GUIWindows
) do
583 g_GUIWindows
[i
].Free();
586 g_ActiveWindow
:= nil;
589 function g_GUI_AddWindow(Window
: TGUIWindow
): TGUIWindow
;
591 SetLength(g_GUIWindows
, Length(g_GUIWindows
)+1);
592 g_GUIWindows
[High(g_GUIWindows
)] := Window
;
597 function g_GUI_GetWindow(Name
: string): TGUIWindow
;
603 if g_GUIWindows
<> nil then
604 for i
:= 0 to High(g_GUIWindows
) do
605 if g_GUIWindows
[i
].FName
= Name
then
607 Result
:= g_GUIWindows
[i
];
611 Assert(Result
<> nil, 'GUI_Window "'+Name
+'" not found');
614 procedure g_GUI_ShowWindow(Name
: string);
618 if g_GUIWindows
= nil then
621 for i
:= 0 to High(g_GUIWindows
) do
622 if g_GUIWindows
[i
].FName
= Name
then
624 g_GUIWindows
[i
].FPrevWindow
:= g_ActiveWindow
;
625 g_ActiveWindow
:= g_GUIWindows
[i
];
627 if g_ActiveWindow
.MainWindow
then
628 g_ActiveWindow
.FPrevWindow
:= nil;
630 if g_ActiveWindow
.FDefControl
<> '' then
631 g_ActiveWindow
.SetActive(g_ActiveWindow
.GetControl(g_ActiveWindow
.FDefControl
))
633 g_ActiveWindow
.SetActive(nil);
635 if @g_ActiveWindow
.FOnShowEvent
<> nil then
636 g_ActiveWindow
.FOnShowEvent();
642 procedure g_GUI_HideWindow(PlaySound
: Boolean = True);
644 if g_ActiveWindow
<> nil then
646 if @g_ActiveWindow
.OnClose
<> nil then
647 g_ActiveWindow
.OnClose();
648 g_ActiveWindow
:= g_ActiveWindow
.FPrevWindow
;
650 g_Sound_PlayEx(WINDOW_CLOSESOUND
);
654 procedure g_GUI_SaveMenuPos();
659 SetLength(Saved_Windows
, 0);
660 win
:= g_ActiveWindow
;
664 len
:= Length(Saved_Windows
);
665 SetLength(Saved_Windows
, len
+ 1);
667 Saved_Windows
[len
] := win
.Name
;
669 if win
.MainWindow
then
672 win
:= win
.FPrevWindow
;
676 procedure g_GUI_LoadMenuPos();
678 i
, j
, k
, len
: Integer;
681 g_ActiveWindow
:= nil;
682 len
:= Length(Saved_Windows
);
687 // Îêíî ñ ãëàâíûì ìåíþ:
688 g_GUI_ShowWindow(Saved_Windows
[len
-1]);
690 // Íå ïåðåêëþ÷èëîñü (èëè íåêóäà äàëüøå):
691 if (len
= 1) or (g_ActiveWindow
= nil) then
694 // Èùåì êíîïêè â îñòàëüíûõ îêíàõ:
695 for k
:= len
-1 downto 1 do
699 for i
:= 0 to Length(g_ActiveWindow
.Childs
)-1 do
701 if g_ActiveWindow
.Childs
[i
] is TGUIMainMenu
then
702 begin // GUI_MainMenu
703 with TGUIMainMenu(g_ActiveWindow
.Childs
[i
]) do
704 for j
:= 0 to Length(FButtons
)-1 do
705 if FButtons
[j
].ShowWindow
= Saved_Windows
[k
-1] then
707 FButtons
[j
].Click(True);
713 if g_ActiveWindow
.Childs
[i
] is TGUIMenu
then
714 with TGUIMenu(g_ActiveWindow
.Childs
[i
]) do
715 for j
:= 0 to Length(FItems
)-1 do
716 if FItems
[j
].ControlType
= TGUITextButton
then
717 if TGUITextButton(FItems
[j
].Control
).ShowWindow
= Saved_Windows
[k
-1] then
719 TGUITextButton(FItems
[j
].Control
).Click(True);
730 (g_ActiveWindow
.Name
= Saved_Windows
[k
]) then
735 procedure DrawBox(X
, Y
: Integer; Width
, Height
: Word);
737 e_Draw(Box
[0], X
, Y
, 0, False, False);
738 e_DrawFill(Box
[1], X
+4, Y
, Width
*4, 1, 0, False, False);
739 e_Draw(Box
[2], X
+4+Width
*16, Y
, 0, False, False);
740 e_DrawFill(Box
[3], X
, Y
+4, 1, Height
*4, 0, False, False);
741 e_DrawFill(Box
[4], X
+4, Y
+4, Width
, Height
, 0, False, False);
742 e_DrawFill(Box
[5], X
+4+Width
*16, Y
+4, 1, Height
*4, 0, False, False);
743 e_Draw(Box
[6], X
, Y
+4+Height
*16, 0, False, False);
744 e_DrawFill(Box
[7], X
+4, Y
+4+Height
*16, Width
*4, 1, 0, False, False);
745 e_Draw(Box
[8], X
+4+Width
*16, Y
+4+Height
*16, 0, False, False);
748 procedure DrawScroll(X
, Y
: Integer; Height
: Word; Up
, Down
: Boolean);
752 if Height
< 3 then Exit
;
755 g_Texture_Get(BSCROLL_UPA
, ID
)
757 g_Texture_Get(BSCROLL_UPU
, ID
);
758 e_Draw(ID
, X
, Y
, 0, False, False);
761 g_Texture_Get(BSCROLL_DOWNA
, ID
)
763 g_Texture_Get(BSCROLL_DOWNU
, ID
);
764 e_Draw(ID
, X
, Y
+(Height
-1)*16, 0, False, False);
766 g_Texture_Get(BSCROLL_MIDDLE
, ID
);
767 e_DrawFill(ID
, X
, Y
+16, 1, Height
-2, 0, False, False);
772 constructor TGUIWindow
.Create(Name
: string);
775 FActiveControl
:= nil;
779 FOnCloseEvent
:= nil;
783 destructor TGUIWindow
.Destroy
;
790 for i
:= 0 to High(Childs
) do
794 function TGUIWindow
.AddChild(Child
: TGUIControl
): TGUIControl
;
796 Child
.FWindow
:= Self
;
798 SetLength(Childs
, Length(Childs
) + 1);
799 Childs
[High(Childs
)] := Child
;
804 procedure TGUIWindow
.Update
;
808 for i
:= 0 to High(Childs
) do
809 if Childs
[i
] <> nil then Childs
[i
].Update
;
812 procedure TGUIWindow
.Draw
;
817 if FBackTexture
<> '' then
818 if g_Texture_Get(FBackTexture
, ID
) then
819 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
821 e_Clear(GL_COLOR_BUFFER_BIT
, 0.5, 0.5, 0.5);
824 if FName
= 'AuthorsMenu' then
825 e_DarkenQuadWH(0, 0, gScreenWidth
, gScreenHeight
, 150);
827 for i
:= 0 to High(Childs
) do
828 if Childs
[i
] <> nil then Childs
[i
].Draw
;
831 procedure TGUIWindow
.OnMessage(var Msg
: TMessage
);
833 if FActiveControl
<> nil then FActiveControl
.OnMessage(Msg
);
834 if @FOnKeyDown
<> nil then FOnKeyDown(Msg
.wParam
);
835 if @FOnKeyDownEx
<> nil then FOnKeyDownEx(self
, Msg
.wParam
);
837 if Msg
.Msg
= WM_KEYDOWN
then
840 IK_ESCAPE
, VK_ESCAPE
, JOY0_JUMP
, JOY1_JUMP
, JOY2_JUMP
, JOY3_JUMP
:
849 procedure TGUIWindow
.SetActive(Control
: TGUIControl
);
851 FActiveControl
:= Control
;
854 function TGUIWindow
.GetControl(Name
: String): TGUIControl
;
860 if Childs
<> nil then
861 for i
:= 0 to High(Childs
) do
862 if Childs
[i
] <> nil then
863 if LowerCase(Childs
[i
].FName
) = LowerCase(Name
) then
869 Assert(Result
<> nil, 'Window Control "'+Name
+'" not Found!');
874 constructor TGUIControl
.Create();
880 FRightAlign
:= false;
884 procedure TGUIControl
.OnMessage(var Msg
: TMessage
);
890 procedure TGUIControl
.Update();
894 procedure TGUIControl
.Draw();
898 function TGUIControl
.WantActivationKey (key
: LongInt): Boolean;
903 function TGUIControl
.GetWidth(): Integer;
908 function TGUIControl
.GetHeight(): Integer;
915 procedure TGUITextButton
.Click(Silent
: Boolean = False);
917 if (FSound
<> '') and (not Silent
) then g_Sound_PlayEx(FSound
);
919 if @Proc
<> nil then Proc();
920 if @ProcEx
<> nil then ProcEx(self
);
922 if FShowWindow
<> '' then g_GUI_ShowWindow(FShowWindow
);
925 constructor TGUITextButton
.Create(aProc
: Pointer; FontID
: DWORD
; Text: string);
932 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
937 destructor TGUITextButton
.Destroy
;
943 procedure TGUITextButton
.Draw
;
945 FFont
.Draw(FX
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
)
948 function TGUITextButton
.GetHeight
: Integer;
952 FFont
.GetTextSize(FText
, w
, h
);
956 function TGUITextButton
.GetWidth
: Integer;
960 FFont
.GetTextSize(FText
, w
, h
);
964 procedure TGUITextButton
.OnMessage(var Msg
: TMessage
);
966 if not FEnabled
then Exit
;
973 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
: Click();
978 procedure TGUITextButton
.Update
;
985 constructor TFont
.Create(FontID
: DWORD
; FontType
: TFontType
);
990 FFontType
:= FontType
;
993 destructor TFont
.Destroy
;
999 procedure TFont
.Draw(X
, Y
: Integer; Text: string; R
, G
, B
: Byte);
1001 if FFontType
= TFontType
.Character
then e_CharFont_PrintEx(ID
, X
, Y
, Text, _RGB(R
, G
, B
), FScale
)
1002 else e_TextureFontPrintEx(X
, Y
, Text, ID
, R
, G
, B
, FScale
);
1005 procedure TFont
.GetTextSize(Text: string; var w
, h
: Word);
1009 if FFontType
= TFontType
.Character
then e_CharFont_GetSize(ID
, Text, w
, h
)
1012 e_TextureFontGetSize(ID
, cw
, ch
);
1013 w
:= cw
*Length(Text);
1017 w
:= Round(w
*FScale
);
1018 h
:= Round(h
*FScale
);
1023 function TGUIMainMenu
.AddButton(fProc
: Pointer; Caption
: string; ShowWindow
: string = ''): TGUITextButton
;
1030 SetLength(FButtons
, Length(FButtons
)+1);
1031 FButtons
[High(FButtons
)] := TGUITextButton
.Create(fProc
, FFontID
, Caption
);
1032 FButtons
[High(FButtons
)].ShowWindow
:= ShowWindow
;
1033 with FButtons
[High(FButtons
)] do
1035 if (fProc
<> nil) or (ShowWindow
<> '') then FColor
:= MAINMENU_ITEMS_COLOR
1036 else FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
1037 FSound
:= MAINMENU_CLICKSOUND
;
1040 _x
:= gScreenWidth
div 2;
1042 for a
:= 0 to High(FButtons
) do
1043 if FButtons
[a
] <> nil then
1044 _x
:= Min(_x
, (gScreenWidth
div 2)-(FButtons
[a
].GetWidth
div 2));
1046 hh
:= FHeader
.GetHeight
;
1048 h
:= hh
*(2+Length(FButtons
))+MAINMENU_SPACE
*(Length(FButtons
)-1);
1049 h
:= (gScreenHeight
div 2)-(h
div 2);
1059 for a
:= 0 to High(FButtons
) do
1061 if FButtons
[a
] <> nil then
1068 Inc(h
, hh
+MAINMENU_SPACE
);
1071 Result
:= FButtons
[High(FButtons
)];
1074 procedure TGUIMainMenu
.AddSpace
;
1076 SetLength(FButtons
, Length(FButtons
)+1);
1077 FButtons
[High(FButtons
)] := nil;
1080 constructor TGUIMainMenu
.Create(FontID
: DWORD
; Header
: string);
1086 FCounter
:= MAINMENU_MARKERDELAY
;
1088 g_Texture_Get(MAINMENU_MARKER1
, FMarkerID1
);
1089 g_Texture_Get(MAINMENU_MARKER2
, FMarkerID2
);
1091 FHeader
:= TGUILabel
.Create(Header
, FFontID
);
1094 FColor
:= MAINMENU_HEADER_COLOR
;
1095 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1096 FY
:= (gScreenHeight
div 2)-(GetHeight
div 2);
1100 destructor TGUIMainMenu
.Destroy
;
1104 if FButtons
<> nil then
1105 for a
:= 0 to High(FButtons
) do
1113 procedure TGUIMainMenu
.Draw
;
1121 if FButtons
<> nil then
1123 for a
:= 0 to High(FButtons
) do
1124 if FButtons
[a
] <> nil then FButtons
[a
].Draw
;
1126 if FIndex
<> -1 then
1127 e_Draw(FMarkerID1
, FButtons
[FIndex
].FX
-48, FButtons
[FIndex
].FY
, 0, True, False);
1131 procedure TGUIMainMenu
.EnableButton(aName
: string; e
: Boolean);
1135 if FButtons
= nil then Exit
;
1137 for a
:= 0 to High(FButtons
) do
1138 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= aName
) then
1140 if e
then FButtons
[a
].FColor
:= MAINMENU_ITEMS_COLOR
1141 else FButtons
[a
].FColor
:= MAINMENU_UNACTIVEITEMS_COLOR
;
1142 FButtons
[a
].Enabled
:= e
;
1147 function TGUIMainMenu
.GetButton(aName
: string): TGUITextButton
;
1153 if FButtons
= nil then Exit
;
1155 for a
:= 0 to High(FButtons
) do
1156 if (FButtons
[a
] <> nil) and (FButtons
[a
].Name
= aName
) then
1158 Result
:= FButtons
[a
];
1163 procedure TGUIMainMenu
.OnMessage(var Msg
: TMessage
);
1168 if not FEnabled
then Exit
;
1172 if FButtons
= nil then Exit
;
1175 for a
:= 0 to High(FButtons
) do
1176 if FButtons
[a
] <> nil then
1182 if not ok
then Exit
;
1187 IK_UP
, IK_KPUP
, VK_UP
, JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1191 if FIndex
< 0 then FIndex
:= High(FButtons
);
1192 until FButtons
[FIndex
] <> nil;
1194 g_Sound_PlayEx(MENU_CHANGESOUND
);
1196 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1200 if FIndex
> High(FButtons
) then FIndex
:= 0;
1201 until FButtons
[FIndex
] <> nil;
1203 g_Sound_PlayEx(MENU_CHANGESOUND
);
1205 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
;
1210 procedure TGUIMainMenu
.Update
;
1216 if FCounter
= 0 then
1219 FMarkerID1
:= FMarkerID2
;
1222 FCounter
:= MAINMENU_MARKERDELAY
;
1223 end else Dec(FCounter
);
1228 constructor TGUILabel
.Create(Text: string; FontID
: DWORD
);
1232 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
1236 FOnClickEvent
:= nil;
1239 procedure TGUILabel
.Draw
;
1245 FFont
.GetTextSize(FText
, w
, h
);
1246 FFont
.Draw(FX
+FMaxWidth
-w
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
);
1250 FFont
.Draw(FX
, FY
, FText
, FColor
.R
, FColor
.G
, FColor
.B
);
1254 function TGUILabel
.GetHeight
: Integer;
1258 FFont
.GetTextSize(FText
, w
, h
);
1262 function TGUILabel
.GetWidth
: Integer;
1266 if FFixedLen
= 0 then
1267 FFont
.GetTextSize(FText
, w
, h
)
1269 w
:= e_CharFont_GetMaxWidth(FFont
.ID
)*FFixedLen
;
1273 procedure TGUILabel
.OnMessage(var Msg
: TMessage
);
1275 if not FEnabled
then Exit
;
1282 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
: if @FOnClickEvent
<> nil then FOnClickEvent();
1289 function TGUIMenu
.AddButton(Proc
: Pointer; fText
: string; _ShowWindow
: string = ''): TGUITextButton
;
1296 Control
:= TGUITextButton
.Create(Proc
, FFontID
, fText
);
1297 with Control
as TGUITextButton
do
1299 ShowWindow
:= _ShowWindow
;
1300 FColor
:= MENU_ITEMSCTRL_COLOR
;
1304 ControlType
:= TGUITextButton
;
1306 Result
:= (Control
as TGUITextButton
);
1309 if FIndex
= -1 then FIndex
:= i
;
1314 procedure TGUIMenu
.AddLine(fText
: string);
1321 Text := TGUILabel
.Create(fText
, FFontID
);
1324 FColor
:= MENU_ITEMSTEXT_COLOR
;
1333 procedure TGUIMenu
.AddText(fText
: string; MaxWidth
: Word);
1338 l
:= GetLines(fText
, FFontID
, MaxWidth
);
1340 if l
= nil then Exit
;
1342 for a
:= 0 to High(l
) do
1347 Text := TGUILabel
.Create(l
[a
], FFontID
);
1350 with Text do begin FColor
:= _RGB(255, 0, 0); end;
1354 with Text do begin FColor
:= MENU_ITEMSTEXT_COLOR
; end;
1364 procedure TGUIMenu
.AddSpace
;
1378 constructor TGUIMenu
.Create(HeaderFont
, ItemsFont
: DWORD
; Header
: string);
1384 FFontID
:= ItemsFont
;
1385 FCounter
:= MENU_MARKERDELAY
;
1389 FHeader
:= TGUILabel
.Create(Header
, HeaderFont
);
1392 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1394 FColor
:= MAINMENU_HEADER_COLOR
;
1398 destructor TGUIMenu
.Destroy
;
1402 if FItems
<> nil then
1403 for a
:= 0 to High(FItems
) do
1417 procedure TGUIMenu
.Draw
;
1419 a
, locx
, locy
: Integer;
1423 if FHeader
<> nil then FHeader
.Draw
;
1425 if FItems
<> nil then
1426 for a
:= 0 to High(FItems
) do
1428 if FItems
[a
].Text <> nil then FItems
[a
].Text.Draw
;
1429 if FItems
[a
].Control
<> nil then FItems
[a
].Control
.Draw
;
1432 if (FIndex
<> -1) and (FCounter
> MENU_MARKERDELAY
div 2) then
1437 if FItems
[FIndex
].Text <> nil then
1439 locx
:= FItems
[FIndex
].Text.FX
;
1440 locy
:= FItems
[FIndex
].Text.FY
;
1442 if FItems
[FIndex
].Text.RightAlign
then
1444 locx
:= locx
+FItems
[FIndex
].Text.FMaxWidth
-FItems
[FIndex
].Text.GetWidth
;
1447 else if FItems
[FIndex
].Control
<> nil then
1449 locx
:= FItems
[FIndex
].Control
.FX
;
1450 locy
:= FItems
[FIndex
].Control
.FY
;
1453 locx
:= locx
-e_CharFont_GetMaxWidth(FFontID
);
1455 e_CharFont_PrintEx(FFontID
, locx
, locy
, #16, _RGB(255, 0, 0));
1459 function TGUIMenu
.GetControl(aName
: String): TGUIControl
;
1465 if FItems
<> nil then
1466 for a
:= 0 to High(FItems
) do
1467 if FItems
[a
].Control
<> nil then
1468 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(aName
) then
1470 Result
:= FItems
[a
].Control
;
1474 Assert(Result
<> nil, 'GUI control "'+aName
+'" not found!');
1477 function TGUIMenu
.GetControlsText(aName
: String): TGUILabel
;
1483 if FItems
<> nil then
1484 for a
:= 0 to High(FItems
) do
1485 if FItems
[a
].Control
<> nil then
1486 if LowerCase(FItems
[a
].Control
.Name
) = LowerCase(aName
) then
1488 Result
:= FItems
[a
].Text;
1492 Assert(Result
<> nil, 'GUI control''s text "'+aName
+'" not found!');
1495 function TGUIMenu
.NewItem
: Integer;
1497 SetLength(FItems
, Length(FItems
)+1);
1498 Result
:= High(FItems
);
1501 procedure TGUIMenu
.OnMessage(var Msg
: TMessage
);
1506 if not FEnabled
then Exit
;
1510 if FItems
= nil then Exit
;
1513 for a
:= 0 to High(FItems
) do
1514 if FItems
[a
].Control
<> nil then
1520 if not ok
then Exit
;
1522 if (Msg
.Msg
= WM_KEYDOWN
) and (FIndex
<> -1) and (FItems
[FIndex
].Control
<> nil) and
1523 (FItems
[FIndex
].Control
.WantActivationKey(Msg
.wParam
)) then
1525 FItems
[FIndex
].Control
.OnMessage(Msg
);
1526 g_Sound_PlayEx(MENU_CLICKSOUND
);
1534 IK_UP
, IK_KPUP
, VK_UP
,JOY0_UP
, JOY1_UP
, JOY2_UP
, JOY3_UP
:
1539 if c
> Length(FItems
) then
1546 if FIndex
< 0 then FIndex
:= High(FItems
);
1547 until (FItems
[FIndex
].Control
<> nil) and
1548 (FItems
[FIndex
].Control
.Enabled
);
1552 g_Sound_PlayEx(MENU_CHANGESOUND
);
1555 IK_DOWN
, IK_KPDOWN
, VK_DOWN
, JOY0_DOWN
, JOY1_DOWN
, JOY2_DOWN
, JOY3_DOWN
:
1560 if c
> Length(FItems
) then
1567 if FIndex
> High(FItems
) then FIndex
:= 0;
1568 until (FItems
[FIndex
].Control
<> nil) and
1569 (FItems
[FIndex
].Control
.Enabled
);
1573 g_Sound_PlayEx(MENU_CHANGESOUND
);
1576 IK_LEFT
, IK_RIGHT
, IK_KPLEFT
, IK_KPRIGHT
, VK_LEFT
, VK_RIGHT
,
1577 JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
,
1578 JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
1580 if FIndex
<> -1 then
1581 if FItems
[FIndex
].Control
<> nil then
1582 FItems
[FIndex
].Control
.OnMessage(Msg
);
1584 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
1586 if FIndex
<> -1 then
1588 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1590 g_Sound_PlayEx(MENU_CLICKSOUND
);
1594 if FYesNo
and (length(FItems
) > 1) then
1596 Msg
.wParam
:= IK_RETURN
; // to register keypress
1597 FIndex
:= High(FItems
)-1;
1598 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1601 if FYesNo
and (length(FItems
) > 1) then
1603 Msg
.wParam
:= IK_RETURN
; // to register keypress
1604 FIndex
:= High(FItems
);
1605 if FItems
[FIndex
].Control
<> nil then FItems
[FIndex
].Control
.OnMessage(Msg
);
1612 procedure TGUIMenu
.ReAlign();
1614 a
, tx
, cx
, w
, h
: Integer;
1615 cww
: array of Integer; // cached widths
1618 if FItems
= nil then Exit
;
1620 SetLength(cww
, length(FItems
));
1622 for a
:= 0 to High(FItems
) do
1624 if FItems
[a
].Text <> nil then
1626 cww
[a
] := FItems
[a
].Text.GetWidth
;
1627 if maxcww
< cww
[a
] then maxcww
:= cww
[a
];
1638 for a
:= 0 to High(FItems
) do
1641 if FItems
[a
].Text <> nil then w
:= FItems
[a
].Text.GetWidth
;
1642 if FItems
[a
].Control
<> nil then
1645 if FItems
[a
].ControlType
= TGUILabel
then w
:= w
+(FItems
[a
].Control
as TGUILabel
).GetWidth
1646 else if FItems
[a
].ControlType
= TGUITextButton
then w
:= w
+(FItems
[a
].Control
as TGUITextButton
).GetWidth
1647 else if FItems
[a
].ControlType
= TGUIScroll
then w
:= w
+(FItems
[a
].Control
as TGUIScroll
).GetWidth
1648 else if FItems
[a
].ControlType
= TGUISwitch
then w
:= w
+(FItems
[a
].Control
as TGUISwitch
).GetWidth
1649 else if FItems
[a
].ControlType
= TGUIEdit
then w
:= w
+(FItems
[a
].Control
as TGUIEdit
).GetWidth
1650 else if FItems
[a
].ControlType
= TGUIKeyRead
then w
:= w
+(FItems
[a
].Control
as TGUIKeyRead
).GetWidth
1651 else if FItems
[a
].ControlType
= TGUIKeyRead2
then w
:= w
+(FItems
[a
].Control
as TGUIKeyRead2
).GetWidth
1652 else if FItems
[a
].ControlType
= TGUIListBox
then w
:= w
+(FItems
[a
].Control
as TGUIListBox
).GetWidth
1653 else if FItems
[a
].ControlType
= TGUIFileListBox
then w
:= w
+(FItems
[a
].Control
as TGUIFileListBox
).GetWidth
1654 else if FItems
[a
].ControlType
= TGUIMemo
then w
:= w
+(FItems
[a
].Control
as TGUIMemo
).GetWidth
;
1656 tx
:= Min(tx
, (gScreenWidth
div 2)-(w
div 2));
1661 for a
:= 0 to High(FItems
) do
1665 if (Text <> nil) and (Control
= nil) then Continue
;
1667 if Text <> nil then w
:= tx
+Text.GetWidth
;
1668 if w
> cx
then cx
:= w
;
1672 cx
:= cx
+MENU_HSPACE
;
1674 h
:= FHeader
.GetHeight
*2+MENU_VSPACE
*(Length(FItems
)-1);
1676 for a
:= 0 to High(FItems
) do
1680 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then
1681 h
:= h
+(FItems
[a
].Control
as TGUIListBox
).GetHeight()
1683 h
:= h
+e_CharFont_GetMaxHeight(FFontID
);
1687 h
:= (gScreenHeight
div 2)-(h
div 2);
1691 FX
:= (gScreenWidth
div 2)-(GetWidth
div 2);
1694 Inc(h
, GetHeight
*2);
1697 for a
:= 0 to High(FItems
) do
1709 if Text.RightAlign
and (length(cww
) > a
) then
1711 //Text.FX := Text.FX+maxcww;
1712 Text.FMaxWidth
:= maxcww
;
1716 if Control
<> nil then
1733 if (ControlType
= TGUIListBox
) or (ControlType
= TGUIFileListBox
) then Inc(h
, (Control
as TGUIListBox
).GetHeight
+MENU_VSPACE
)
1734 else if ControlType
= TGUIMemo
then Inc(h
, (Control
as TGUIMemo
).GetHeight
+MENU_VSPACE
)
1735 else Inc(h
, e_CharFont_GetMaxHeight(FFontID
)+MENU_VSPACE
);
1739 // another ugly hack
1740 if FYesNo
and (length(FItems
) > 1) then
1743 for a
:= High(FItems
)-1 to High(FItems
) do
1745 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1747 cx
:= (FItems
[a
].Control
as TGUITextButton
).GetWidth
;
1748 if cx
> w
then w
:= cx
;
1753 for a
:= High(FItems
)-1 to High(FItems
) do
1755 if (FItems
[a
].Control
<> nil) and (FItems
[a
].ControlType
= TGUITextButton
) then
1757 FItems
[a
].Control
.FX
:= (gScreenWidth
-w
) div 2;
1764 function TGUIMenu
.AddScroll(fText
: string): TGUIScroll
;
1771 Control
:= TGUIScroll
.Create();
1773 Text := TGUILabel
.Create(fText
, FFontID
);
1776 FColor
:= MENU_ITEMSTEXT_COLOR
;
1779 ControlType
:= TGUIScroll
;
1781 Result
:= (Control
as TGUIScroll
);
1784 if FIndex
= -1 then FIndex
:= i
;
1789 function TGUIMenu
.AddSwitch(fText
: string): TGUISwitch
;
1796 Control
:= TGUISwitch
.Create(FFontID
);
1797 (Control
as TGUISwitch
).FColor
:= MENU_ITEMSCTRL_COLOR
;
1799 Text := TGUILabel
.Create(fText
, FFontID
);
1802 FColor
:= MENU_ITEMSTEXT_COLOR
;
1805 ControlType
:= TGUISwitch
;
1807 Result
:= (Control
as TGUISwitch
);
1810 if FIndex
= -1 then FIndex
:= i
;
1815 function TGUIMenu
.AddEdit(fText
: string): TGUIEdit
;
1822 Control
:= TGUIEdit
.Create(FFontID
);
1823 with Control
as TGUIEdit
do
1825 FWindow
:= Self
.FWindow
;
1826 FColor
:= MENU_ITEMSCTRL_COLOR
;
1829 if fText
= '' then Text := nil else
1831 Text := TGUILabel
.Create(fText
, FFontID
);
1832 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1835 ControlType
:= TGUIEdit
;
1837 Result
:= (Control
as TGUIEdit
);
1840 if FIndex
= -1 then FIndex
:= i
;
1845 procedure TGUIMenu
.Update
;
1851 if FCounter
= 0 then FCounter
:= MENU_MARKERDELAY
else Dec(FCounter
);
1853 if FItems
<> nil then
1854 for a
:= 0 to High(FItems
) do
1855 if FItems
[a
].Control
<> nil then
1856 (FItems
[a
].Control
as FItems
[a
].ControlType
).Update
;
1859 function TGUIMenu
.AddKeyRead(fText
: string): TGUIKeyRead
;
1866 Control
:= TGUIKeyRead
.Create(FFontID
);
1867 with Control
as TGUIKeyRead
do
1869 FWindow
:= Self
.FWindow
;
1870 FColor
:= MENU_ITEMSCTRL_COLOR
;
1873 Text := TGUILabel
.Create(fText
, FFontID
);
1876 FColor
:= MENU_ITEMSTEXT_COLOR
;
1879 ControlType
:= TGUIKeyRead
;
1881 Result
:= (Control
as TGUIKeyRead
);
1884 if FIndex
= -1 then FIndex
:= i
;
1889 function TGUIMenu
.AddKeyRead2(fText
: string): TGUIKeyRead2
;
1896 Control
:= TGUIKeyRead2
.Create(FFontID
);
1897 with Control
as TGUIKeyRead2
do
1899 FWindow
:= Self
.FWindow
;
1900 FColor
:= MENU_ITEMSCTRL_COLOR
;
1903 Text := TGUILabel
.Create(fText
, FFontID
);
1906 FColor
:= MENU_ITEMSCTRL_COLOR
; //MENU_ITEMSTEXT_COLOR;
1910 ControlType
:= TGUIKeyRead2
;
1912 Result
:= (Control
as TGUIKeyRead2
);
1915 if FIndex
= -1 then FIndex
:= i
;
1920 function TGUIMenu
.AddList(fText
: string; Width
, Height
: Word): TGUIListBox
;
1927 Control
:= TGUIListBox
.Create(FFontID
, Width
, Height
);
1928 with Control
as TGUIListBox
do
1930 FWindow
:= Self
.FWindow
;
1931 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
1932 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
1935 Text := TGUILabel
.Create(fText
, FFontID
);
1938 FColor
:= MENU_ITEMSTEXT_COLOR
;
1941 ControlType
:= TGUIListBox
;
1943 Result
:= (Control
as TGUIListBox
);
1946 if FIndex
= -1 then FIndex
:= i
;
1951 function TGUIMenu
.AddFileList(fText
: string; Width
, Height
: Word): TGUIFileListBox
;
1958 Control
:= TGUIFileListBox
.Create(FFontID
, Width
, Height
);
1959 with Control
as TGUIFileListBox
do
1961 FWindow
:= Self
.FWindow
;
1962 FActiveColor
:= MENU_ITEMSCTRL_COLOR
;
1963 FUnActiveColor
:= MENU_ITEMSTEXT_COLOR
;
1966 if fText
= '' then Text := nil else
1968 Text := TGUILabel
.Create(fText
, FFontID
);
1969 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
1972 ControlType
:= TGUIFileListBox
;
1974 Result
:= (Control
as TGUIFileListBox
);
1977 if FIndex
= -1 then FIndex
:= i
;
1982 function TGUIMenu
.AddLabel(fText
: string): TGUILabel
;
1989 Control
:= TGUILabel
.Create('', FFontID
);
1990 with Control
as TGUILabel
do
1992 FWindow
:= Self
.FWindow
;
1993 FColor
:= MENU_ITEMSCTRL_COLOR
;
1996 Text := TGUILabel
.Create(fText
, FFontID
);
1999 FColor
:= MENU_ITEMSTEXT_COLOR
;
2002 ControlType
:= TGUILabel
;
2004 Result
:= (Control
as TGUILabel
);
2007 if FIndex
= -1 then FIndex
:= i
;
2012 function TGUIMenu
.AddMemo(fText
: string; Width
, Height
: Word): TGUIMemo
;
2019 Control
:= TGUIMemo
.Create(FFontID
, Width
, Height
);
2020 with Control
as TGUIMemo
do
2022 FWindow
:= Self
.FWindow
;
2023 FColor
:= MENU_ITEMSTEXT_COLOR
;
2026 if fText
= '' then Text := nil else
2028 Text := TGUILabel
.Create(fText
, FFontID
);
2029 Text.FColor
:= MENU_ITEMSTEXT_COLOR
;
2032 ControlType
:= TGUIMemo
;
2034 Result
:= (Control
as TGUIMemo
);
2037 if FIndex
= -1 then FIndex
:= i
;
2042 procedure TGUIMenu
.UpdateIndex();
2050 if (FIndex
< 0) or (FIndex
> High(FItems
)) then
2056 if FItems
[FIndex
].Control
.Enabled
then
2065 constructor TGUIScroll
.Create
;
2070 FOnChangeEvent
:= nil;
2072 g_Texture_Get(SCROLL_LEFT
, FLeftID
);
2073 g_Texture_Get(SCROLL_RIGHT
, FRightID
);
2074 g_Texture_Get(SCROLL_MIDDLE
, FMiddleID
);
2075 g_Texture_Get(SCROLL_MARKER
, FMarkerID
);
2078 procedure TGUIScroll
.Draw
;
2084 e_Draw(FLeftID
, FX
, FY
, 0, True, False);
2085 e_Draw(FRightID
, FX
+8+(FMax
+1)*8, FY
, 0, True, False);
2087 for a
:= 0 to FMax
do
2088 e_Draw(FMiddleID
, FX
+8+a
*8, FY
, 0, True, False);
2090 e_Draw(FMarkerID
, FX
+8+FValue
*8, FY
, 0, True, False);
2093 procedure TGUIScroll
.FSetValue(a
: Integer);
2095 if a
> FMax
then FValue
:= FMax
else FValue
:= a
;
2098 function TGUIScroll
.GetWidth
: Integer;
2100 Result
:= 16+(FMax
+1)*8;
2103 procedure TGUIScroll
.OnMessage(var Msg
: TMessage
);
2105 if not FEnabled
then Exit
;
2113 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2117 g_Sound_PlayEx(SCROLL_SUBSOUND
);
2118 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2120 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2121 if FValue
< FMax
then
2124 g_Sound_PlayEx(SCROLL_ADDSOUND
);
2125 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2132 procedure TGUIScroll
.Update
;
2140 procedure TGUISwitch
.AddItem(Item
: string);
2142 SetLength(FItems
, Length(FItems
)+1);
2143 FItems
[High(FItems
)] := Item
;
2145 if FIndex
= -1 then FIndex
:= 0;
2148 constructor TGUISwitch
.Create(FontID
: DWORD
);
2154 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2157 procedure TGUISwitch
.Draw
;
2161 FFont
.Draw(FX
, FY
, FItems
[FIndex
], FColor
.R
, FColor
.G
, FColor
.B
);
2164 function TGUISwitch
.GetText
: string;
2166 if FIndex
<> -1 then Result
:= FItems
[FIndex
]
2170 function TGUISwitch
.GetWidth
: Integer;
2177 if FItems
= nil then Exit
;
2179 for a
:= 0 to High(FItems
) do
2181 FFont
.GetTextSize(FItems
[a
], w
, h
);
2182 if w
> Result
then Result
:= w
;
2186 procedure TGUISwitch
.OnMessage(var Msg
: TMessage
);
2188 if not FEnabled
then Exit
;
2192 if FItems
= nil then Exit
;
2197 IK_RETURN
, IK_RIGHT
, IK_KPRETURN
, IK_KPRIGHT
, VK_FIRE
, VK_OPEN
, VK_RIGHT
,
2198 JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
,
2199 JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2201 if FIndex
< High(FItems
) then
2206 if @FOnChangeEvent
<> nil then
2207 FOnChangeEvent(Self
);
2210 IK_LEFT
, IK_KPLEFT
, VK_LEFT
,
2211 JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2216 FIndex
:= High(FItems
);
2218 if @FOnChangeEvent
<> nil then
2219 FOnChangeEvent(Self
);
2225 procedure TGUISwitch
.Update
;
2233 constructor TGUIEdit
.Create(FontID
: DWORD
);
2237 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2243 g_Texture_Get(EDIT_LEFT
, FLeftID
);
2244 g_Texture_Get(EDIT_RIGHT
, FRightID
);
2245 g_Texture_Get(EDIT_MIDDLE
, FMiddleID
);
2248 procedure TGUIEdit
.Draw
;
2255 e_Draw(FLeftID
, FX
, FY
, 0, True, False);
2256 e_Draw(FRightID
, FX
+8+FWidth
*16, FY
, 0, True, False);
2258 for c
:= 0 to FWidth
-1 do
2259 e_Draw(FMiddleID
, FX
+8+c
*16, FY
, 0, True, False);
2264 if FInvalid
and (FWindow
.FActiveControl
<> self
) then begin r
:= 128; g
:= 128; b
:= 128; end;
2265 FFont
.Draw(FX
+8, FY
, FText
, r
, g
, b
);
2267 if (FWindow
.FActiveControl
= self
) then
2269 FFont
.GetTextSize(Copy(FText
, 1, FCaretPos
), w
, h
);
2270 h
:= e_CharFont_GetMaxHeight(FFont
.ID
);
2271 e_DrawLine(2, FX
+8+w
, FY
+h
-3, FX
+8+w
+EDIT_CURSORLEN
, FY
+h
-3,
2272 EDIT_CURSORCOLOR
.R
, EDIT_CURSORCOLOR
.G
, EDIT_CURSORCOLOR
.B
);
2276 function TGUIEdit
.GetWidth
: Integer;
2278 Result
:= 16+FWidth
*16;
2281 procedure TGUIEdit
.OnMessage(var Msg
: TMessage
);
2283 if not FEnabled
then Exit
;
2292 if (wParam
in [48..57]) and (Chr(wParam
) <> '`') then
2293 if Length(Text) < FMaxLength
then
2295 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2301 if (wParam
in [32..255]) and (Chr(wParam
) <> '`') then
2302 if Length(Text) < FMaxLength
then
2304 Insert(Chr(wParam
), FText
, FCaretPos
+ 1);
2312 Delete(FText
, FCaretPos
, 1);
2313 if FCaretPos
> 0 then Dec(FCaretPos
);
2315 IK_DELETE
: Delete(FText
, FCaretPos
+ 1, 1);
2316 IK_END
, IK_KPEND
: FCaretPos
:= Length(FText
);
2317 IK_HOME
, IK_KPHOME
: FCaretPos
:= 0;
2318 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
: if FCaretPos
> 0 then Dec(FCaretPos
);
2319 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
: if FCaretPos
< Length(FText
) then Inc(FCaretPos
);
2320 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2323 if FActiveControl
<> Self
then
2326 if @FOnEnterEvent
<> nil then FOnEnterEvent(Self
);
2330 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
2331 else SetActive(nil);
2332 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
2338 g_Touch_ShowKeyboard(FWindow
.FActiveControl
= Self
);
2341 procedure TGUIEdit
.SetText(Text: string);
2343 if Length(Text) > FMaxLength
then SetLength(Text, FMaxLength
);
2345 FCaretPos
:= Length(FText
);
2348 procedure TGUIEdit
.Update
;
2355 constructor TGUIKeyRead
.Create(FontID
: DWORD
);
2361 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2364 procedure TGUIKeyRead
.Draw
;
2368 FFont
.Draw(FX
, FY
, IfThen(FIsQuery
, KEYREAD_QUERY
, IfThen(FKey
<> 0, e_KeyNames
[FKey
], KEYREAD_CLEAR
)),
2369 FColor
.R
, FColor
.G
, FColor
.B
);
2372 function TGUIKeyRead
.GetWidth
: Integer;
2379 for a
:= 0 to 255 do
2381 FFont
.GetTextSize(e_KeyNames
[a
], w
, h
);
2382 Result
:= Max(Result
, w
);
2385 FFont
.GetTextSize(KEYREAD_QUERY
, w
, h
);
2386 if w
> Result
then Result
:= w
;
2388 FFont
.GetTextSize(KEYREAD_CLEAR
, w
, h
);
2389 if w
> Result
then Result
:= w
;
2392 function TGUIKeyRead
.WantActivationKey (key
: LongInt): Boolean;
2395 (key
= IK_BACKSPACE
) or
2399 procedure TGUIKeyRead
.OnMessage(var Msg
: TMessage
);
2400 procedure actDefCtl ();
2403 if FDefControl
<> '' then
2404 SetActive(GetControl(FDefControl
))
2412 if not FEnabled
then
2419 IK_ESCAPE
, VK_ESCAPE
, JOY0_JUMP
, JOY1_JUMP
, JOY2_JUMP
, JOY3_JUMP
:
2421 if FIsQuery
then actDefCtl();
2424 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2426 if not FIsQuery
then
2429 if FActiveControl
<> Self
then
2436 FKey
:= IK_ENTER
; // <Enter>
2441 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2443 if not FIsQuery
then
2453 if not FIsQuery
and (wParam
= IK_BACKSPACE
) then
2458 else if FIsQuery
then
2461 IK_ENTER
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
: // Not <Enter
2463 if e_KeyNames
[wParam
] <> '' then
2475 constructor TGUIKeyRead2
.Create(FontID
: DWORD
);
2488 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2490 FMaxKeyNameWdt
:= 0;
2491 for a
:= 0 to 255 do
2493 FFont
.GetTextSize(e_KeyNames
[a
], w
, h
);
2494 FMaxKeyNameWdt
:= Max(FMaxKeyNameWdt
, w
);
2497 FMaxKeyNameWdt
:= FMaxKeyNameWdt
-(FMaxKeyNameWdt
div 3);
2499 FFont
.GetTextSize(KEYREAD_QUERY
, w
, h
);
2500 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2502 FFont
.GetTextSize(KEYREAD_CLEAR
, w
, h
);
2503 if w
> FMaxKeyNameWdt
then FMaxKeyNameWdt
:= w
;
2506 procedure TGUIKeyRead2
.Draw
;
2507 procedure drawText (idx
: Integer);
2513 if idx
= 0 then kk
:= FKey0
else kk
:= FKey1
;
2515 if idx
= 0 then x
:= FX
+8 else x
:= FX
+8+FMaxKeyNameWdt
+16;
2519 if FKeyIdx
= idx
then begin r
:= 255; g
:= 255; b
:= 255; end;
2520 if FIsQuery
and (FKeyIdx
= idx
) then
2521 FFont
.Draw(x
, y
, KEYREAD_QUERY
, r
, g
, b
)
2523 FFont
.Draw(x
, y
, IfThen(kk
<> 0, e_KeyNames
[kk
], KEYREAD_CLEAR
), r
, g
, b
);
2529 //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);
2530 //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);
2535 function TGUIKeyRead2
.GetWidth
: Integer;
2537 Result
:= FMaxKeyNameWdt
*2+8+8+16;
2540 function TGUIKeyRead2
.WantActivationKey (key
: LongInt): Boolean;
2543 IK_BACKSPACE
, IK_LEFT
, IK_RIGHT
, IK_KPLEFT
, IK_KPRIGHT
, VK_LEFT
, VK_RIGHT
,
2544 JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
,
2545 JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2552 procedure TGUIKeyRead2
.OnMessage(var Msg
: TMessage
);
2553 procedure actDefCtl ();
2556 if FDefControl
<> '' then
2557 SetActive(GetControl(FDefControl
))
2565 if not FEnabled
then
2572 IK_ESCAPE
, VK_ESCAPE
, JOY0_JUMP
, JOY1_JUMP
, JOY2_JUMP
, JOY3_JUMP
:
2574 if FIsQuery
then actDefCtl();
2577 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
2579 if not FIsQuery
then
2582 if FActiveControl
<> Self
then
2589 if (FKeyIdx
= 0) then FKey0
:= IK_ENTER
else FKey1
:= IK_ENTER
; // <Enter>
2594 IK_BACKSPACE
: // clear keybinding if we aren't waiting for a key
2596 if not FIsQuery
then
2598 if (FKeyIdx
= 0) then FKey0
:= 0 else FKey1
:= 0;
2602 IK_LEFT
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
2603 if not FIsQuery
then
2608 IK_RIGHT
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
2609 if not FIsQuery
then
2618 if not FIsQuery
and (wParam
= IK_BACKSPACE
) then
2620 if (FKeyIdx
= 0) then FKey0
:= 0 else FKey1
:= 0;
2623 else if FIsQuery
then
2626 IK_ENTER
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
,
2627 JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
: // Not <Enter
2629 if e_KeyNames
[wParam
] <> '' then
2631 if (FKeyIdx
= 0) then FKey0
:= wParam
else FKey1
:= wParam
;
2644 constructor TGUIModelView
.Create
;
2651 destructor TGUIModelView
.Destroy
;
2658 procedure TGUIModelView
.Draw
;
2662 DrawBox(FX
, FY
, 4, 4);
2664 if FModel
<> nil then FModel
.Draw(FX
+4, FY
+4);
2667 procedure TGUIModelView
.NextAnim();
2669 if FModel
= nil then
2672 if FModel
.Animation
< A_PAIN
then
2673 FModel
.ChangeAnimation(FModel
.Animation
+1, True)
2675 FModel
.ChangeAnimation(A_STAND
, True);
2678 procedure TGUIModelView
.NextWeapon();
2680 if FModel
= nil then
2683 if FModel
.Weapon
< WP_LAST
then
2684 FModel
.SetWeapon(FModel
.Weapon
+1)
2686 FModel
.SetWeapon(WEAPON_KASTET
);
2689 procedure TGUIModelView
.OnMessage(var Msg
: TMessage
);
2695 procedure TGUIModelView
.SetColor(Red
, Green
, Blue
: Byte);
2697 if FModel
<> nil then FModel
.SetColor(Red
, Green
, Blue
);
2700 procedure TGUIModelView
.SetModel(ModelName
: string);
2704 FModel
:= g_PlayerModel_Get(ModelName
);
2707 procedure TGUIModelView
.Update
;
2714 if FModel
<> nil then FModel
.Update
;
2719 constructor TGUIMapPreview
.Create();
2725 destructor TGUIMapPreview
.Destroy();
2731 procedure TGUIMapPreview
.Draw();
2738 DrawBox(FX
, FY
, MAPPREVIEW_WIDTH
, MAPPREVIEW_HEIGHT
);
2740 if (FMapSize
.X
<= 0) or (FMapSize
.Y
<= 0) then
2743 e_DrawFillQuad(FX
+4, FY
+4,
2744 FX
+4 + Trunc(FMapSize
.X
/ FScale
) - 1,
2745 FY
+4 + Trunc(FMapSize
.Y
/ FScale
) - 1,
2748 if FMapData
<> nil then
2749 for a
:= 0 to High(FMapData
) do
2752 if X1
> MAPPREVIEW_WIDTH
*16 then Continue
;
2753 if Y1
> MAPPREVIEW_HEIGHT
*16 then Continue
;
2755 if X2
< 0 then Continue
;
2756 if Y2
< 0 then Continue
;
2758 if X2
> MAPPREVIEW_WIDTH
*16 then X2
:= MAPPREVIEW_WIDTH
*16;
2759 if Y2
> MAPPREVIEW_HEIGHT
*16 then Y2
:= MAPPREVIEW_HEIGHT
*16;
2761 if X1
< 0 then X1
:= 0;
2762 if Y1
< 0 then Y1
:= 0;
2803 if ((X2
-X1
) > 0) and ((Y2
-Y1
) > 0) then
2804 e_DrawFillQuad(FX
+4 + X1
, FY
+4 + Y1
,
2805 FX
+4 + X2
- 1, FY
+4 + Y2
- 1, r
, g
, b
, 0);
2809 procedure TGUIMapPreview
.OnMessage(var Msg
: TMessage
);
2815 procedure TGUIMapPreview
.SetMap(Res
: string);
2820 //header: TMapHeaderRec_1;
2825 map
: TDynRecord
= nil;
2832 FileName
:= g_ExtractWadName(Res
);
2834 WAD
:= TWADFile
.Create();
2835 if not WAD
.ReadFile(FileName
) then
2841 //k8: ignores path again
2842 if not WAD
.GetMapResource(g_ExtractFileName(Res
), Data
, Len
) then
2851 map
:= g_Map_ParseMap(Data
, Len
);
2861 if (map
= nil) then exit
;
2864 panlist
:= map
.field
['panel'];
2865 //header := GetMapHeader(map);
2867 FMapSize
.X
:= map
.Width
div 16;
2868 FMapSize
.Y
:= map
.Height
div 16;
2870 rX
:= Ceil(map
.Width
/ (MAPPREVIEW_WIDTH
*256.0));
2871 rY
:= Ceil(map
.Height
/ (MAPPREVIEW_HEIGHT
*256.0));
2872 FScale
:= max(rX
, rY
);
2876 if (panlist
<> nil) then
2878 for pan
in panlist
do
2880 if (pan
.PanelType
and (PANEL_WALL
or PANEL_CLOSEDOOR
or
2881 PANEL_STEP
or PANEL_WATER
or
2882 PANEL_ACID1
or PANEL_ACID2
)) <> 0 then
2884 SetLength(FMapData
, Length(FMapData
)+1);
2885 with FMapData
[High(FMapData
)] do
2890 X2
:= (pan
.X
+ pan
.Width
) div 16;
2891 Y2
:= (pan
.Y
+ pan
.Height
) div 16;
2893 X1
:= Trunc(X1
/FScale
+ 0.5);
2894 Y1
:= Trunc(Y1
/FScale
+ 0.5);
2895 X2
:= Trunc(X2
/FScale
+ 0.5);
2896 Y2
:= Trunc(Y2
/FScale
+ 0.5);
2898 if (X1
<> X2
) or (Y1
<> Y2
) then
2906 PanelType
:= pan
.PanelType
;
2912 //writeln('freeing map');
2917 procedure TGUIMapPreview
.ClearMap();
2919 SetLength(FMapData
, 0);
2926 procedure TGUIMapPreview
.Update();
2932 function TGUIMapPreview
.GetScaleStr(): String;
2934 if FScale
> 0.0 then
2936 Result
:= FloatToStrF(FScale
*16.0, ffFixed
, 3, 3);
2937 while (Result
[Length(Result
)] = '0') do
2938 Delete(Result
, Length(Result
), 1);
2939 if (Result
[Length(Result
)] = ',') or (Result
[Length(Result
)] = '.') then
2940 Delete(Result
, Length(Result
), 1);
2941 Result
:= '1 : ' + Result
;
2949 procedure TGUIListBox
.AddItem(Item
: string);
2951 SetLength(FItems
, Length(FItems
)+1);
2952 FItems
[High(FItems
)] := Item
;
2954 if FSort
then g_Basic
.Sort(FItems
);
2957 procedure TGUIListBox
.Clear();
2965 constructor TGUIListBox
.Create(FontID
: DWORD
; Width
, Height
: Word);
2969 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
2974 FOnChangeEvent
:= nil;
2976 FDrawScroll
:= True;
2979 procedure TGUIListBox
.Draw
;
2987 if FDrawBack
then DrawBox(FX
, FY
, FWidth
+1, FHeight
);
2989 DrawScroll(FX
+4+FWidth
*16, FY
+4, FHeight
, (FStartLine
> 0) and (FItems
<> nil),
2990 (FStartLine
+FHeight
-1 < High(FItems
)) and (FItems
<> nil));
2992 if FItems
<> nil then
2993 for a
:= FStartLine
to Min(High(FItems
), FStartLine
+FHeight
-1) do
2997 FFont
.GetTextSize(s
, w2
, h2
);
2998 while (Length(s
) > 0) and (w2
> FWidth
*16) do
3000 SetLength(s
, Length(s
)-1);
3001 FFont
.GetTextSize(s
, w2
, h2
);
3005 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, s
, FActiveColor
.R
, FActiveColor
.G
, FActiveColor
.B
)
3007 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, s
, FUnActiveColor
.R
, FUnActiveColor
.G
, FUnActiveColor
.B
);
3011 function TGUIListBox
.GetHeight
: Integer;
3013 Result
:= 8+FHeight
*16;
3016 function TGUIListBox
.GetWidth
: Integer;
3018 Result
:= 8+(FWidth
+1)*16;
3021 procedure TGUIListBox
.OnMessage(var Msg
: TMessage
);
3025 if not FEnabled
then Exit
;
3029 if FItems
= nil then Exit
;
3042 FIndex
:= High(FItems
);
3043 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
3045 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
3049 if FIndex
< FStartLine
then Dec(FStartLine
);
3050 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3052 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
3053 if FIndex
< High(FItems
) then
3056 if FIndex
> FStartLine
+FHeight
-1 then Inc(FStartLine
);
3057 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3059 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
3062 if FActiveControl
<> Self
then SetActive(Self
)
3064 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
3065 else SetActive(nil);
3069 for a
:= 0 to High(FItems
) do
3070 if (Length(FItems
[a
]) > 0) and (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) then
3073 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
3074 if @FOnChangeEvent
<> nil then FOnChangeEvent(Self
);
3080 function TGUIListBox
.SelectedItem(): String;
3084 if (FIndex
< 0) or (FItems
= nil) or
3085 (FIndex
> High(FItems
)) then
3088 Result
:= FItems
[FIndex
];
3091 procedure TGUIListBox
.FSetItems(Items
: SSArray
);
3093 if FItems
<> nil then
3101 if FSort
then g_Basic
.Sort(FItems
);
3104 procedure TGUIListBox
.SelectItem(Item
: String);
3108 if FItems
= nil then
3112 Item
:= LowerCase(Item
);
3114 for a
:= 0 to High(FItems
) do
3115 if LowerCase(FItems
[a
]) = Item
then
3121 if FIndex
< FHeight
then
3124 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
3127 procedure TGUIListBox
.FSetIndex(aIndex
: Integer);
3129 if FItems
= nil then
3132 if (aIndex
< 0) or (aIndex
> High(FItems
)) then
3137 if FIndex
<= FHeight
then
3140 FStartLine
:= Min(FIndex
, Length(FItems
)-FHeight
);
3145 procedure TGUIFileListBox
.OnMessage(var Msg
: TMessage
);
3149 if not FEnabled
then
3152 if FItems
= nil then
3163 if @FOnChangeEvent
<> nil then
3164 FOnChangeEvent(Self
);
3169 FIndex
:= High(FItems
);
3170 FStartLine
:= Max(High(FItems
)-FHeight
+1, 0);
3171 if @FOnChangeEvent
<> nil then
3172 FOnChangeEvent(Self
);
3175 IK_PAGEUP
, IK_KPPAGEUP
:
3177 if FIndex
> FHeight
then
3178 FIndex
:= FIndex
-FHeight
3182 if FStartLine
> FHeight
then
3183 FStartLine
:= FStartLine
-FHeight
3188 IK_PAGEDN
, IK_KPPAGEDN
:
3190 if FIndex
< High(FItems
)-FHeight
then
3191 FIndex
:= FIndex
+FHeight
3193 FIndex
:= High(FItems
);
3195 if FStartLine
< High(FItems
)-FHeight
then
3196 FStartLine
:= FStartLine
+FHeight
3198 FStartLine
:= High(FItems
)-FHeight
+1;
3201 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
, VK_UP
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
3205 if FIndex
< FStartLine
then
3207 if @FOnChangeEvent
<> nil then
3208 FOnChangeEvent(Self
);
3211 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
, VK_DOWN
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
3212 if FIndex
< High(FItems
) then
3215 if FIndex
> FStartLine
+FHeight
-1 then
3217 if @FOnChangeEvent
<> nil then
3218 FOnChangeEvent(Self
);
3221 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
3224 if FActiveControl
<> Self
then
3228 if FItems
[FIndex
][1] = #29 then // Ïàïêà
3230 OpenDir(FPath
+Copy(FItems
[FIndex
], 2, 255));
3235 if FDefControl
<> '' then
3236 SetActive(GetControl(FDefControl
))
3244 for a
:= 0 to High(FItems
) do
3245 if ( (Length(FItems
[a
]) > 0) and
3246 (LowerCase(FItems
[a
][1]) = LowerCase(Chr(wParam
))) ) or
3247 ( (Length(FItems
[a
]) > 1) and
3248 (FItems
[a
][1] = #29) and // Ïàïêà
3249 (LowerCase(FItems
[a
][2]) = LowerCase(Chr(wParam
))) ) then
3252 FStartLine
:= Min(Max(FIndex
-1, 0), Length(FItems
)-FHeight
);
3253 if @FOnChangeEvent
<> nil then
3254 FOnChangeEvent(Self
);
3260 procedure TGUIFileListBox
.OpenDir(path
: String);
3268 path
:= IncludeTrailingPathDelimiter(path
);
3269 path
:= ExpandFileName(path
);
3274 if FindFirst(path
+'*', faDirectory
, SR
) = 0 then
3276 if not LongBool(SR
.Attr
and faDirectory
) then
3278 if (SR
.Name
= '.') or
3279 ((SR
.Name
= '..') and (path
= ExpandFileName(FBasePath
))) then
3282 AddItem(#1 + SR
.Name
);
3283 until FindNext(SR
) <> 0;
3293 if i
= 0 then i
:= length(sm
)+1;
3294 sc
:= Copy(sm
, 1, i
-1);
3296 if FindFirst(path
+sc
, faAnyFile
, SR
) = 0 then repeat AddItem(SR
.Name
); until FindNext(SR
) <> 0;
3300 for i
:= 0 to High(FItems
) do
3301 if FItems
[i
][1] = #1 then
3302 FItems
[i
][1] := #29;
3307 procedure TGUIFileListBox
.SetBase(path
: String);
3313 function TGUIFileListBox
.SelectedItem(): String;
3317 if (FIndex
= -1) or (FItems
= nil) or
3318 (FIndex
> High(FItems
)) or
3319 (FItems
[FIndex
][1] = '/') or
3320 (FItems
[FIndex
][1] = '\') then
3323 Result
:= FPath
+ FItems
[FIndex
];
3326 procedure TGUIFileListBox
.UpdateFileList();
3330 if (FIndex
= -1) or (FItems
= nil) or
3331 (FIndex
> High(FItems
)) or
3332 (FItems
[FIndex
][1] = '/') or
3333 (FItems
[FIndex
][1] = '\') then
3336 fn
:= FItems
[FIndex
];
3346 procedure TGUIMemo
.Clear
;
3352 constructor TGUIMemo
.Create(FontID
: DWORD
; Width
, Height
: Word);
3356 FFont
:= TFont
.Create(FontID
, TFontType
.Character
);
3361 FDrawScroll
:= True;
3364 procedure TGUIMemo
.Draw
;
3370 if FDrawBack
then DrawBox(FX
, FY
, FWidth
+1, FHeight
);
3372 DrawScroll(FX
+4+FWidth
*16, FY
+4, FHeight
, (FStartLine
> 0) and (FLines
<> nil),
3373 (FStartLine
+FHeight
-1 < High(FLines
)) and (FLines
<> nil));
3375 if FLines
<> nil then
3376 for a
:= FStartLine
to Min(High(FLines
), FStartLine
+FHeight
-1) do
3377 FFont
.Draw(FX
+4, FY
+4+(a
-FStartLine
)*16, FLines
[a
], FColor
.R
, FColor
.G
, FColor
.B
);
3380 function TGUIMemo
.GetHeight
: Integer;
3382 Result
:= 8+FHeight
*16;
3385 function TGUIMemo
.GetWidth
: Integer;
3387 Result
:= 8+(FWidth
+1)*16;
3390 procedure TGUIMemo
.OnMessage(var Msg
: TMessage
);
3392 if not FEnabled
then Exit
;
3396 if FLines
= nil then Exit
;
3402 IK_UP
, IK_LEFT
, IK_KPUP
, IK_KPLEFT
, VK_UP
, VK_LEFT
, JOY0_LEFT
, JOY1_LEFT
, JOY2_LEFT
, JOY3_LEFT
:
3403 if FStartLine
> 0 then
3405 IK_DOWN
, IK_RIGHT
, IK_KPDOWN
, IK_KPRIGHT
, VK_DOWN
, VK_RIGHT
, JOY0_RIGHT
, JOY1_RIGHT
, JOY2_RIGHT
, JOY3_RIGHT
:
3406 if FStartLine
< Length(FLines
)-FHeight
then
3408 IK_RETURN
, IK_KPRETURN
, VK_FIRE
, VK_OPEN
, JOY0_ATTACK
, JOY1_ATTACK
, JOY2_ATTACK
, JOY3_ATTACK
:
3411 if FActiveControl
<> Self
then
3417 if FDefControl
<> '' then SetActive(GetControl(FDefControl
))
3418 else SetActive(nil);
3424 procedure TGUIMemo
.SetText(Text: string);
3427 FLines
:= GetLines(Text, FFont
.ID
, FWidth
*16);
3432 procedure TGUIimage
.ClearImage();
3434 if FImageRes
= '' then Exit
;
3436 g_Texture_Delete(FImageRes
);
3440 constructor TGUIimage
.Create();
3447 destructor TGUIimage
.Destroy();
3452 procedure TGUIimage
.Draw();
3458 if FImageRes
= '' then
3460 if g_Texture_Get(FDefaultRes
, ID
) then e_Draw(ID
, FX
, FY
, 0, True, False);
3463 if g_Texture_Get(FImageRes
, ID
) then e_Draw(ID
, FX
, FY
, 0, True, False);
3466 procedure TGUIimage
.OnMessage(var Msg
: TMessage
);
3471 procedure TGUIimage
.SetImage(Res
: string);
3475 if g_Texture_CreateWADEx(Res
, Res
) then FImageRes
:= Res
;
3478 procedure TGUIimage
.Update();