X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_gui.pas;h=832e737f8681709107255781c9a3ef440b3517e7;hb=57eea56cadbee2ab1e505f50144d1e1671deaa30;hp=9319e45a7b9e29550da578fa07bf4af5ac32dc25;hpb=af3c404e11867c6794975f1d45dd98932d804ede;p=d2df-sdl.git diff --git a/src/game/g_gui.pas b/src/game/g_gui.pas index 9319e45..832e737 100644 --- a/src/game/g_gui.pas +++ b/src/game/g_gui.pas @@ -1,10 +1,25 @@ -{$MODE DELPHI} +(* Copyright (C) Doom 2D: Forever Developers + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License ONLY. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + *) +{$INCLUDE ../shared/a_modes.inc} unit g_gui; interface uses - e_graphics, e_input, g_playermodel, g_basic, MAPSTRUCT, wadreader; + {$IFDEF USE_MEMPOOL}mempool,{$ENDIF} + g_base, e_input, e_log, g_playermodel, g_basic, MAPDEF, utils; const MAINMENU_HEADER_COLOR: TRGB = (R:255; G:255; B:255); @@ -42,15 +57,6 @@ const KEYREAD_TIMEOUT = 24; MAPPREVIEW_WIDTH = 8; MAPPREVIEW_HEIGHT = 8; - BOX1 = 'BOX1'; - BOX2 = 'BOX2'; - BOX3 = 'BOX3'; - BOX4 = 'BOX4'; - BOX5 = 'BOX5'; - BOX6 = 'BOX6'; - BOX7 = 'BOX7'; - BOX8 = 'BOX8'; - BOX9 = 'BOX9'; BSCROLL_UPA = 'BSCROLL_UP_A'; BSCROLL_UPU = 'BSCROLL_UP_U'; BSCROLL_DOWNA = 'BSCROLL_DOWN_A'; @@ -60,6 +66,8 @@ const WM_CHAR = 102; WM_USER = 110; + MESSAGE_DIKEY = WM_USER + 1; + type TMessage = record Msg: DWORD; @@ -67,11 +75,11 @@ type lParam: LongInt; end; - TFontType = (FONT_TEXTURE, FONT_CHAR); + TFontType = (Texture, Character); - TFont = class(TObject) + TFont = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF} private - ID: DWORD; + FID: DWORD; FScale: Single; FFontType: TFontType; public @@ -80,6 +88,7 @@ type procedure Draw(X, Y: Integer; Text: string; R, G, B: Byte); procedure GetTextSize(Text: string; var w, h: Word); property Scale: Single read FScale write FScale; + property ID: DWORD read FID; end; TGUIControl = class; @@ -93,26 +102,34 @@ type TOnChangeEvent = procedure(Sender: TGUIControl); TOnEnterEvent = procedure(Sender: TGUIControl); - TGUIControl = class + TGUIControl = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF} private FX, FY: Integer; FEnabled: Boolean; FWindow : TGUIWindow; FName: string; FUserData: Pointer; + FRightAlign: Boolean; //HACK! this works only for "normal" menus, only for menu text labels, and generally sux. sorry. + FMaxWidth: Integer; //HACK! used for right-aligning labels public constructor Create; procedure OnMessage(var Msg: TMessage); virtual; procedure Update; virtual; - procedure Draw; virtual; + function GetWidth(): Integer; virtual; + function GetHeight(): Integer; virtual; + function WantActivationKey (key: LongInt): Boolean; virtual; property X: Integer read FX write FX; property Y: Integer read FY write FY; property Enabled: Boolean read FEnabled write FEnabled; property Name: string read FName write FName; property UserData: Pointer read FUserData write FUserData; + property RightAlign: Boolean read FRightAlign write FRightAlign; // for menu + property CMaxWidth: Integer read FMaxWidth; + + property Window: TGUIWindow read FWindow; end; - TGUIWindow = class + TGUIWindow = class{$IFDEF USE_MEMPOOL}(TPoolObject){$ENDIF} private FActiveControl: TGUIControl; FDefControl: string; @@ -132,7 +149,6 @@ type function AddChild(Child: TGUIControl): TGUIControl; procedure OnMessage(var Msg: TMessage); procedure Update; - procedure Draw; procedure SetActive(Control: TGUIControl); function GetControl(Name: string): TGUIControl; property OnKeyDown: TOnKeyDownEvent read FOnKeyDown write FOnKeyDown; @@ -144,6 +160,8 @@ type property BackTexture: string read FBackTexture write FBackTexture; property MainWindow: Boolean read FMainWindow write FMainWindow; property UserData: Pointer read FUserData write FUserData; + + property ActiveControl: TGUIControl read FActiveControl; end; TGUITextButton = class(TGUIControl) @@ -156,13 +174,10 @@ type public Proc: procedure; ProcEx: procedure (sender: TGUITextButton); - constructor Create(Proc: Pointer; FontID: DWORD; Text: string); + constructor Create(aProc: Pointer; FontID: DWORD; Text: string); destructor Destroy(); override; procedure OnMessage(var Msg: TMessage); override; procedure Update(); override; - procedure Draw(); override; - function GetWidth(): Integer; - function GetHeight(): Integer; procedure Click(Silent: Boolean = False); property Caption: string read FText write FText; property Color: TRGB read FColor write FColor; @@ -180,9 +195,6 @@ type public constructor Create(Text: string; FontID: DWORD); procedure OnMessage(var Msg: TMessage); override; - procedure Draw; override; - function GetWidth: Integer; - function GetHeight: Integer; property OnClick: TOnClickEvent read FOnClickEvent write FOnClickEvent; property FixedLength: Word read FFixedLen write FFixedLen; property Text: string read FText write FText; @@ -194,27 +206,23 @@ type private FValue: Integer; FMax: Word; - FLeftID: DWORD; - FRightID: DWORD; - FMiddleID: DWORD; - FMarkerID: DWORD; FOnChangeEvent: TOnChangeEvent; procedure FSetValue(a: Integer); public constructor Create(); procedure OnMessage(var Msg: TMessage); override; procedure Update; override; - procedure Draw; override; - function GetWidth(): Word; property OnChange: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent; property Max: Word read FMax write FMax; property Value: Integer read FValue write FSetValue; - end; + end; + + TGUIItemsList = array of string; TGUISwitch = class(TGUIControl) private FFont: TFont; - FItems: array of string; + FItems: TGUIItemsList; FIndex: Integer; FColor: TRGB; FOnChangeEvent: TOnChangeEvent; @@ -223,13 +231,12 @@ type procedure OnMessage(var Msg: TMessage); override; procedure AddItem(Item: string); procedure Update; override; - procedure Draw; override; - function GetWidth(): Word; function GetText: string; property ItemIndex: Integer read FIndex write FIndex; property Color: TRGB read FColor write FColor; property Font: TFont read FFont write FFont; property OnChange: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent; + property Items: TGUIItemsList read FItems; end; TGUIEdit = class(TGUIControl) @@ -241,18 +248,14 @@ type FText: string; FColor: TRGB; FOnlyDigits: Boolean; - FLeftID: DWORD; - FRightID: DWORD; - FMiddleID: DWORD; FOnChangeEvent: TOnChangeEvent; FOnEnterEvent: TOnEnterEvent; + FInvalid: Boolean; procedure SetText(Text: string); public constructor Create(FontID: DWORD); procedure OnMessage(var Msg: TMessage); override; procedure Update; override; - procedure Draw; override; - function GetWidth(): Word; property OnChange: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent; property OnEnter: TOnEnterEvent read FOnEnterEvent write FOnEnterEvent; property Width: Word read FWidth write FWidth; @@ -261,6 +264,9 @@ type property Text: string read FText write SetText; property Color: TRGB read FColor write FColor; property Font: TFont read FFont write FFont; + property Invalid: Boolean read FInvalid write FInvalid; + + property CaretPos: Integer read FCaretPos; end; TGUIKeyRead = class(TGUIControl) @@ -272,11 +278,36 @@ type public constructor Create(FontID: DWORD); procedure OnMessage(var Msg: TMessage); override; - procedure Draw; override; - function GetWidth(): Word; + function WantActivationKey (key: LongInt): Boolean; override; property Key: Word read FKey write FKey; property Color: TRGB read FColor write FColor; property Font: TFont read FFont write FFont; + + property IsQuery: Boolean read FIsQuery; + end; + + // can hold two keys + TGUIKeyRead2 = class(TGUIControl) + private + FFont: TFont; + FFontID: DWORD; + FColor: TRGB; + FKey0, FKey1: Word; // this should be an array. sorry. + FKeyIdx: Integer; + FIsQuery: Boolean; + FMaxKeyNameWdt: Integer; + public + constructor Create(FontID: DWORD); + procedure OnMessage(var Msg: TMessage); override; + function WantActivationKey (key: LongInt): Boolean; override; + property Key0: Word read FKey0 write FKey0; + property Key1: Word read FKey1 write FKey1; + property Color: TRGB read FColor write FColor; + property Font: TFont read FFont write FFont; + + property IsQuery: Boolean read FIsQuery; + property MaxKeyNameWdt: Integer read FMaxKeyNameWdt; + property KeyIdx: Integer read FKeyIdx; end; TGUIModelView = class(TGUIControl) @@ -292,7 +323,6 @@ type procedure NextAnim(); procedure NextWeapon(); procedure Update; override; - procedure Draw; override; property Model: TPlayerModel read FModel; end; @@ -301,10 +331,12 @@ type PanelType: Word; end; + TPreviewPanelArray = array of TPreviewPanel; + TGUIMapPreview = class(TGUIControl) private - FMapData: array of TPreviewPanel; - FMapSize: TPoint; + FMapData: TPreviewPanelArray; + FMapSize: TDFPoint; FScale: Single; public constructor Create(); @@ -313,8 +345,11 @@ type procedure SetMap(Res: string); procedure ClearMap(); procedure Update(); override; - procedure Draw(); override; function GetScaleStr: String; + + property MapData: TPreviewPanelArray read FMapData; + property MapSize: TDFPoint read FMapSize; + property Scale: Single read FScale; end; TGUIImage = class(TGUIControl) @@ -328,13 +363,14 @@ type procedure SetImage(Res: string); procedure ClearImage(); procedure Update(); override; - procedure Draw(); override; + property DefaultRes: string read FDefaultRes write FDefaultRes; + property ImageRes: string read FImageRes; end; TGUIListBox = class(TGUIControl) private - FItems: SArray; + FItems: SSArray; FActiveColor: TRGB; FUnActiveColor: TRGB; FFont: TFont; @@ -347,54 +383,55 @@ type FDrawScroll: Boolean; FOnChangeEvent: TOnChangeEvent; - procedure FSetItems(Items: SArray); + procedure FSetItems(Items: SSArray); procedure FSetIndex(aIndex: Integer); public constructor Create(FontID: DWORD; Width, Height: Word); procedure OnMessage(var Msg: TMessage); override; - procedure Draw(); override; procedure AddItem(Item: String); + function ItemExists (item: String): Boolean; procedure SelectItem(Item: String); procedure Clear(); - function GetWidth(): Word; - function GetHeight(): Word; function SelectedItem(): String; property OnChange: TOnChangeEvent read FOnChangeEvent write FOnChangeEvent; property Sort: Boolean read FSort write FSort; property ItemIndex: Integer read FIndex write FSetIndex; - property Items: SArray read FItems write FSetItems; + property Items: SSArray read FItems write FSetItems; property DrawBack: Boolean read FDrawBack write FDrawBack; property DrawScrollBar: Boolean read FDrawScroll write FDrawScroll; property ActiveColor: TRGB read FActiveColor write FActiveColor; property UnActiveColor: TRGB read FUnActiveColor write FUnActiveColor; property Font: TFont read FFont write FFont; + + property Width: Word read FWidth; + property Height: Word read FHeight; + property StartLine: Integer read FStartLine; end; - TGUIFileListBox = class (TGUIListBox) + TGUIFileListBox = class(TGUIListBox) private - FBasePath: String; - FPath: String; + FSubPath: String; FFileMask: String; FDirs: Boolean; + FBaseList: SSArray; // highter index have highter priority - procedure OpenDir(path: String); + procedure ScanDirs; public - procedure OnMessage(var Msg: TMessage); override; - procedure SetBase(path: String); + procedure OnMessage (var Msg: TMessage); override; + procedure SetBase (dirs: SSArray; path: String = ''); function SelectedItem(): String; - procedure UpdateFileList(); + procedure UpdateFileList; property Dirs: Boolean read FDirs write FDirs; property FileMask: String read FFileMask write FFileMask; - property Path: String read FPath; end; TGUIMemo = class(TGUIControl) private - FLines: SArray; + FLines: SSArray; FFont: TFont; FStartLine: Integer; FWidth: Word; @@ -405,36 +442,42 @@ type public constructor Create(FontID: DWORD; Width, Height: Word); procedure OnMessage(var Msg: TMessage); override; - procedure Draw; override; procedure Clear; - function GetWidth(): Word; - function GetHeight(): Word; procedure SetText(Text: string); property DrawBack: Boolean read FDrawBack write FDrawBack; property DrawScrollBar: Boolean read FDrawScroll write FDrawScroll; property Color: TRGB read FColor write FColor; property Font: TFont read FFont write FFont; + + property Width: Word read FWidth; + property Height: Word read FHeight; + property StartLine: Integer read FStartLine; + property Lines: SSArray read FLines; end; + TGUITextButtonList = array of TGUITextButton; + TGUIMainMenu = class(TGUIControl) private - FButtons: array of TGUITextButton; + FButtons: TGUITextButtonList; FHeader: TGUILabel; FIndex: Integer; FFontID: DWORD; - FCounter: Byte; - FMarkerID1: DWORD; - FMarkerID2: DWORD; + FCounter: Byte; // !!! update it within render public constructor Create(FontID: DWORD; Header: string); destructor Destroy; override; procedure OnMessage(var Msg: TMessage); override; function AddButton(fProc: Pointer; Caption: string; ShowWindow: string = ''): TGUITextButton; - function GetButton(Name: string): TGUITextButton; - procedure EnableButton(Name: string; e: Boolean); + function GetButton(aName: string): TGUITextButton; + procedure EnableButton(aName: string; e: Boolean); procedure AddSpace(); procedure Update; override; - procedure Draw; override; + + property Header: TGUILabel read FHeader; + property Buttons: TGUITextButtonList read FButtons; + property Index: Integer read FIndex; + property Counter: Byte read FCounter; end; TControlType = class of TGUIControl; @@ -445,10 +488,11 @@ type ControlType: TControlType; Control: TGUIControl; end; + TMenuItemList = array of TMenuItem; TGUIMenu = class(TGUIControl) private - FItems: array of TMenuItem; + FItems: TMenuItemList; FHeader: TGUILabel; FIndex: Integer; FFontID: DWORD; @@ -470,25 +514,31 @@ type function AddSwitch(fText: string): TGUISwitch; function AddEdit(fText: string): TGUIEdit; function AddKeyRead(fText: string): TGUIKeyRead; + function AddKeyRead2(fText: string): TGUIKeyRead2; function AddList(fText: string; Width, Height: Word): TGUIListBox; function AddFileList(fText: string; Width, Height: Word): TGUIFileListBox; function AddMemo(fText: string; Width, Height: Word): TGUIMemo; procedure ReAlign(); - function GetControl(Name: string): TGUIControl; - function GetControlsText(Name: string): TGUILabel; - procedure Draw; override; + function GetControl(aName: string): TGUIControl; + function GetControlsText(aName: string): TGUILabel; procedure Update; override; procedure UpdateIndex(); property Align: Boolean read FAlign write FAlign; property Left: Integer read FLeft write FLeft; property YesNo: Boolean read FYesNo write FYesNo; + + property Header: TGUILabel read FHeader; + property Counter: Byte read FCounter; + property Index: Integer read FIndex; + property Items: TMenuItemList read FItems; + property FontID: DWORD read FFontID; end; var g_GUIWindows: array of TGUIWindow; g_ActiveWindow: TGUIWindow = nil; + g_GUIGrabInput: Boolean = False; -procedure g_GUI_Init(); function g_GUI_AddWindow(Window: TGUIWindow): TGUIWindow; function g_GUI_GetWindow(Name: string): TGUIWindow; procedure g_GUI_ShowWindow(Name: string); @@ -497,28 +547,76 @@ function g_GUI_Destroy(): Boolean; procedure g_GUI_SaveMenuPos(); procedure g_GUI_LoadMenuPos(); + implementation uses - GL, GLExt, g_textures, g_sound, SysUtils, - g_game, Math, StrUtils, g_player, g_options, MAPREADER, - g_map, MAPDEF, g_weapons; + {$IFDEF ENABLE_TOUCH} + g_system, + {$ENDIF} + {$IFDEF ENABLE_RENDER} + r_gui, r_textures, r_graphics, + {$ENDIF} + g_sound, SysUtils, e_res, + g_game, Math, StrUtils, g_player, g_options, + g_map, g_weapons, xdynrec, wadreader; + var - Box: Array [0..8] of DWORD; - Saved_Windows: SArray; + Saved_Windows: SSArray; + +function GetLines (Text: string; FontID: DWORD; MaxWidth: Word): SSArray; + var i, j, len, lines: Integer; + + function GetLine (j, i: Integer): String; + begin + result := Copy(text, j, i - j + 1); + end; + + function GetWidth (j, i: Integer): Integer; + var w, h: Word; + begin + e_CharFont_GetSize(FontID, GetLine(j, i), w, h); + result := w + end; -procedure g_GUI_Init(); begin - g_Texture_Get(BOX1, Box[0]); - g_Texture_Get(BOX2, Box[1]); - g_Texture_Get(BOX3, Box[2]); - g_Texture_Get(BOX4, Box[3]); - g_Texture_Get(BOX5, Box[4]); - g_Texture_Get(BOX6, Box[5]); - g_Texture_Get(BOX7, Box[6]); - g_Texture_Get(BOX8, Box[7]); - g_Texture_Get(BOX9, Box[8]); + result := nil; lines := 0; + j := 1; i := 1; len := Length(Text); + // e_LogWritefln('GetLines @%s len=%s [%s]', [MaxWidth, len, Text]); + while j <= len do + begin + (* --- Get longest possible sequence --- *) + while (i + 1 <= len) and (GetWidth(j, i + 1) <= MaxWidth) do Inc(i); + (* --- Do not include part of word --- *) + if (i < len) and (text[i] <> ' ') then + while (i >= j) and (text[i] <> ' ') do Dec(i); + (* --- Do not include spaces --- *) + while (i >= j) and (text[i] = ' ') do Dec(i); + (* --- Add line --- *) + SetLength(result, lines + 1); + result[lines] := GetLine(j, i); + // e_LogWritefln(' -> (%s:%s::%s) [%s]', [j, i, GetWidth(j, i), result[lines]]); + Inc(lines); + (* --- Skip spaces --- *) + while (i <= len) and (text[i] = ' ') do Inc(i); + j := i + 2; + end; +end; + +procedure Sort (var a: SSArray); + var i, j: Integer; s: string; +begin + if a = nil then Exit; + + for i := High(a) downto Low(a) do + for j := Low(a) to High(a) - 1 do + if LowerCase(a[j]) > LowerCase(a[j + 1]) then + begin + s := a[j]; + a[j] := a[j + 1]; + a[j + 1] := s; + end; end; function g_GUI_Destroy(): Boolean; @@ -680,41 +778,6 @@ begin end; end; -procedure DrawBox(X, Y: Integer; Width, Height: Word); -begin - e_Draw(Box[0], X, Y, 0, False, False); - e_DrawFill(Box[1], X+4, Y, Width*4, 1, 0, False, False); - e_Draw(Box[2], X+4+Width*16, Y, 0, False, False); - e_DrawFill(Box[3], X, Y+4, 1, Height*4, 0, False, False); - e_DrawFill(Box[4], X+4, Y+4, Width, Height, 0, False, False); - e_DrawFill(Box[5], X+4+Width*16, Y+4, 1, Height*4, 0, False, False); - e_Draw(Box[6], X, Y+4+Height*16, 0, False, False); - e_DrawFill(Box[7], X+4, Y+4+Height*16, Width*4, 1, 0, False, False); - e_Draw(Box[8], X+4+Width*16, Y+4+Height*16, 0, False, False); -end; - -procedure DrawScroll(X, Y: Integer; Height: Word; Up, Down: Boolean); -var - ID: DWORD; -begin - if Height < 3 then Exit; - - if Up then - g_Texture_Get(BSCROLL_UPA, ID) - else - g_Texture_Get(BSCROLL_UPU, ID); - e_Draw(ID, X, Y, 0, False, False); - - if Down then - g_Texture_Get(BSCROLL_DOWNA, ID) - else - g_Texture_Get(BSCROLL_DOWNU, ID); - e_Draw(ID, X, Y+(Height-1)*16, 0, False, False); - - g_Texture_Get(BSCROLL_MIDDLE, ID); - e_DrawFill(ID, X, Y+16, 1, Height-2, 0, False, False); -end; - { TGUIWindow } constructor TGUIWindow.Create(Name: string); @@ -757,21 +820,6 @@ begin if Childs[i] <> nil then Childs[i].Update; end; -procedure TGUIWindow.Draw; -var - i: Integer; - ID: DWORD; -begin - if FBackTexture <> '' then - if g_Texture_Get(FBackTexture, ID) then - e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight) - else - e_Clear(GL_COLOR_BUFFER_BIT, 0.5, 0.5, 0.5); - - for i := 0 to High(Childs) do - if Childs[i] <> nil then Childs[i].Draw; -end; - procedure TGUIWindow.OnMessage(var Msg: TMessage); begin if FActiveControl <> nil then FActiveControl.OnMessage(Msg); @@ -779,11 +827,15 @@ begin if @FOnKeyDownEx <> nil then FOnKeyDownEx(self, Msg.wParam); if Msg.Msg = WM_KEYDOWN then - if Msg.wParam = IK_ESCAPE then - begin - g_GUI_HideWindow; - Exit; - end; + begin + case Msg.wParam of + VK_ESCAPE: + begin + g_GUI_HideWindow; + Exit + end + end + end end; procedure TGUIWindow.SetActive(Control: TGUIControl); @@ -817,6 +869,8 @@ begin FY := 0; FEnabled := True; + FRightAlign := false; + FMaxWidth := -1; end; procedure TGUIControl.OnMessage(var Msg: TMessage); @@ -827,14 +881,37 @@ end; procedure TGUIControl.Update(); begin - end; -procedure TGUIControl.Draw(); +function TGUIControl.WantActivationKey (key: LongInt): Boolean; begin - + result := false; end; + function TGUIControl.GetWidth (): Integer; + {$IFDEF ENABLE_RENDER} + var h: Integer; + {$ENDIF} + begin + {$IFDEF ENABLE_RENDER} + r_GUI_GetSize(Self, Result, h); + {$ELSE} + Result := 0; + {$ENDIF} + end; + + function TGUIControl.GetHeight (): Integer; + {$IFDEF ENABLE_RENDER} + var w: Integer; + {$ENDIF} + begin + {$IFDEF ENABLE_RENDER} + r_GUI_GetSize(Self, w, Result); + {$ELSE} + Result := 0; + {$ENDIF} + end; + { TGUITextButton } procedure TGUITextButton.Click(Silent: Boolean = False); @@ -847,14 +924,14 @@ begin if FShowWindow <> '' then g_GUI_ShowWindow(FShowWindow); end; -constructor TGUITextButton.Create(Proc: Pointer; FontID: DWORD; Text: string); +constructor TGUITextButton.Create(aProc: Pointer; FontID: DWORD; Text: string); begin inherited Create(); - Self.Proc := Proc; + Self.Proc := aProc; ProcEx := nil; - FFont := TFont.Create(FontID, FONT_CHAR); + FFont := TFont.Create(FontID, TFontType.Character); FText := Text; end; @@ -865,27 +942,6 @@ begin inherited; end; -procedure TGUITextButton.Draw; -begin - FFont.Draw(FX, FY, FText, FColor.R, FColor.G, FColor.B) -end; - -function TGUITextButton.GetHeight: Integer; -var - w, h: Word; -begin - FFont.GetTextSize(FText, w, h); - Result := h; -end; - -function TGUITextButton.GetWidth: Integer; -var - w, h: Word; -begin - FFont.GetTextSize(FText, w, h); - Result := w; -end; - procedure TGUITextButton.OnMessage(var Msg: TMessage); begin if not FEnabled then Exit; @@ -895,7 +951,7 @@ begin case Msg.Msg of WM_KEYDOWN: case Msg.wParam of - IK_RETURN, IK_KPRETURN: Click(); + IK_RETURN, IK_KPRETURN, VK_FIRE, VK_OPEN, JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK: Click(); end; end; end; @@ -909,8 +965,7 @@ end; constructor TFont.Create(FontID: DWORD; FontType: TFontType); begin - ID := FontID; - + FID := FontID; FScale := 1; FFontType := FontType; end; @@ -923,7 +978,7 @@ end; procedure TFont.Draw(X, Y: Integer; Text: string; R, G, B: Byte); begin - if FFontType = FONT_CHAR then e_CharFont_PrintEx(ID, X, Y, Text, _RGB(R, G, B), FScale) + if FFontType = TFontType.Character then e_CharFont_PrintEx(ID, X, Y, Text, _RGB(R, G, B), FScale) else e_TextureFontPrintEx(X, Y, Text, ID, R, G, B, FScale); end; @@ -931,7 +986,7 @@ procedure TFont.GetTextSize(Text: string; var w, h: Word); var cw, ch: Byte; begin - if FFontType = FONT_CHAR then e_CharFont_GetSize(ID, Text, w, h) + if FFontType = TFontType.Character then e_CharFont_GetSize(ID, Text, w, h) else begin e_TextureFontGetSize(ID, cw, ch); @@ -949,6 +1004,8 @@ function TGUIMainMenu.AddButton(fProc: Pointer; Caption: string; ShowWindow: str var a, _x: Integer; h, hh: Word; + lw: Word = 0; + lh: Word = 0; begin FIndex := 0; @@ -968,18 +1025,22 @@ begin if FButtons[a] <> nil then _x := Min(_x, (gScreenWidth div 2)-(FButtons[a].GetWidth div 2)); - hh := FHeader.GetHeight; + if FHeader = nil then + r_GUI_GetLogoSize(lw, lh); + hh := FButtons[High(FButtons)].GetHeight; - h := hh*(2+Length(FButtons))+MAINMENU_SPACE*(Length(FButtons)-1); - h := (gScreenHeight div 2)-(h div 2); + if FHeader = nil then h := lh + hh * (1 + Length(FButtons)) + MAINMENU_SPACE * (Length(FButtons) - 1) + else h := hh * (2 + Length(FButtons)) + MAINMENU_SPACE * (Length(FButtons) - 1); + h := (gScreenHeight div 2) - (h div 2); - with FHeader do + if FHeader <> nil then with FHeader do begin FX := _x; FY := h; end; - Inc(h, hh*2); + if FHeader = nil then Inc(h, lh) + else Inc(h, hh*2); for a := 0 to High(FButtons) do begin @@ -1010,15 +1071,15 @@ begin FFontID := FontID; FCounter := MAINMENU_MARKERDELAY; - g_Texture_Get(MAINMENU_MARKER1, FMarkerID1); - g_Texture_Get(MAINMENU_MARKER2, FMarkerID2); - - FHeader := TGUILabel.Create(Header, FFontID); - with FHeader do + if Header <> '' then begin - FColor := MAINMENU_HEADER_COLOR; - FX := (gScreenWidth div 2)-(GetWidth div 2); - FY := (gScreenHeight div 2)-(GetHeight div 2); + FHeader := TGUILabel.Create(Header, FFontID); + with FHeader do + begin + FColor := MAINMENU_HEADER_COLOR; + FX := (gScreenWidth div 2)-(GetWidth div 2); + FY := (gScreenHeight div 2)-(GetHeight div 2); + end; end; end; @@ -1035,32 +1096,14 @@ begin inherited; end; -procedure TGUIMainMenu.Draw; -var - a: Integer; -begin - inherited; - - FHeader.Draw; - - if FButtons <> nil then - begin - for a := 0 to High(FButtons) do - if FButtons[a] <> nil then FButtons[a].Draw; - - if FIndex <> -1 then - e_Draw(FMarkerID1, FButtons[FIndex].FX-48, FButtons[FIndex].FY, 0, True, False); - end; -end; - -procedure TGUIMainMenu.EnableButton(Name: string; e: Boolean); +procedure TGUIMainMenu.EnableButton(aName: string; e: Boolean); var a: Integer; begin if FButtons = nil then Exit; for a := 0 to High(FButtons) do - if (FButtons[a] <> nil) and (FButtons[a].Name = Name) then + if (FButtons[a] <> nil) and (FButtons[a].Name = aName) then begin if e then FButtons[a].FColor := MAINMENU_ITEMS_COLOR else FButtons[a].FColor := MAINMENU_UNACTIVEITEMS_COLOR; @@ -1069,7 +1112,7 @@ begin end; end; -function TGUIMainMenu.GetButton(Name: string): TGUITextButton; +function TGUIMainMenu.GetButton(aName: string): TGUITextButton; var a: Integer; begin @@ -1078,7 +1121,7 @@ begin if FButtons = nil then Exit; for a := 0 to High(FButtons) do - if (FButtons[a] <> nil) and (FButtons[a].Name = Name) then + if (FButtons[a] <> nil) and (FButtons[a].Name = aName) then begin Result := FButtons[a]; Break; @@ -1109,7 +1152,7 @@ begin case Msg.Msg of WM_KEYDOWN: case Msg.wParam of - IK_UP, IK_KPUP: + IK_UP, IK_KPUP, VK_UP, JOY0_UP, JOY1_UP, JOY2_UP, JOY3_UP: begin repeat Dec(FIndex); @@ -1118,7 +1161,7 @@ begin g_Sound_PlayEx(MENU_CHANGESOUND); end; - IK_DOWN, IK_KPDOWN: + IK_DOWN, IK_KPDOWN, VK_DOWN, JOY0_DOWN, JOY1_DOWN, JOY2_DOWN, JOY3_DOWN: begin repeat Inc(FIndex); @@ -1127,25 +1170,15 @@ begin g_Sound_PlayEx(MENU_CHANGESOUND); end; - IK_RETURN, IK_KPRETURN: if (FIndex <> -1) and FButtons[FIndex].FEnabled then FButtons[FIndex].Click; + 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; end; end; end; procedure TGUIMainMenu.Update; -var - t: DWORD; begin inherited; - - if FCounter = 0 then - begin - t := FMarkerID1; - FMarkerID1 := FMarkerID2; - FMarkerID2 := t; - - FCounter := MAINMENU_MARKERDELAY; - end else Dec(FCounter); + FCounter := (FCounter + 1) MOD (2 * MAINMENU_MARKERDELAY) end; { TGUILabel } @@ -1154,37 +1187,13 @@ constructor TGUILabel.Create(Text: string; FontID: DWORD); begin inherited Create(); - FFont := TFont.Create(FontID, FONT_CHAR); + FFont := TFont.Create(FontID, TFontType.Character); FText := Text; FFixedLen := 0; FOnClickEvent := nil; end; -procedure TGUILabel.Draw; -begin - FFont.Draw(FX, FY, FText, FColor.R, FColor.G, FColor.B); -end; - -function TGUILabel.GetHeight: Integer; -var - w, h: Word; -begin - FFont.GetTextSize(FText, w, h); - Result := h; -end; - -function TGUILabel.GetWidth: Integer; -var - w, h: Word; -begin - if FFixedLen = 0 then - FFont.GetTextSize(FText, w, h) - else - w := e_CharFont_GetMaxWidth(FFont.ID)*FFixedLen; - Result := w; -end; - procedure TGUILabel.OnMessage(var Msg: TMessage); begin if not FEnabled then Exit; @@ -1194,7 +1203,7 @@ begin case Msg.Msg of WM_KEYDOWN: case Msg.wParam of - IK_RETURN, IK_KPRETURN: if @FOnClickEvent <> nil then FOnClickEvent(); + IK_RETURN, IK_KPRETURN, VK_FIRE, VK_OPEN, JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK: if @FOnClickEvent <> nil then FOnClickEvent(); end; end; end; @@ -1248,7 +1257,7 @@ end; procedure TGUIMenu.AddText(fText: string; MaxWidth: Word); var a, i: Integer; - l: SArray; + l: SSArray; begin l := GetLines(fText, FFontID, MaxWidth); @@ -1329,44 +1338,7 @@ begin inherited; end; -procedure TGUIMenu.Draw; -var - a, x, y: Integer; -begin - inherited; - - if FHeader <> nil then FHeader.Draw; - - if FItems <> nil then - for a := 0 to High(FItems) do - begin - if FItems[a].Text <> nil then FItems[a].Text.Draw; - if FItems[a].Control <> nil then FItems[a].Control.Draw; - end; - - if (FIndex <> -1) and (FCounter > MENU_MARKERDELAY div 2) then - begin - x := 0; - y := 0; - - if FItems[FIndex].Text <> nil then - begin - x := FItems[FIndex].Text.FX; - y := FItems[FIndex].Text.FY; - end - else if FItems[FIndex].Control <> nil then - begin - x := FItems[FIndex].Control.FX; - y := FItems[FIndex].Control.FY; - end; - - x := x-e_CharFont_GetMaxWidth(FFontID); - - e_CharFont_PrintEx(FFontID, x, y, #16, _RGB(255, 0, 0)); - end; -end; - -function TGUIMenu.GetControl(Name: String): TGUIControl; +function TGUIMenu.GetControl(aName: String): TGUIControl; var a: Integer; begin @@ -1375,16 +1347,16 @@ begin if FItems <> nil then for a := 0 to High(FItems) do if FItems[a].Control <> nil then - if LowerCase(FItems[a].Control.Name) = LowerCase(Name) then + if LowerCase(FItems[a].Control.Name) = LowerCase(aName) then begin Result := FItems[a].Control; Break; end; - Assert(Result <> nil, 'GUI control "'+Name+'" not found!'); + Assert(Result <> nil, 'GUI control "'+aName+'" not found!'); end; -function TGUIMenu.GetControlsText(Name: String): TGUILabel; +function TGUIMenu.GetControlsText(aName: String): TGUILabel; var a: Integer; begin @@ -1393,13 +1365,13 @@ begin if FItems <> nil then for a := 0 to High(FItems) do if FItems[a].Control <> nil then - if LowerCase(FItems[a].Control.Name) = LowerCase(Name) then + if LowerCase(FItems[a].Control.Name) = LowerCase(aName) then begin Result := FItems[a].Text; Break; end; - Assert(Result <> nil, 'GUI control''s text "'+Name+'" not found!'); + Assert(Result <> nil, 'GUI control''s text "'+aName+'" not found!'); end; function TGUIMenu.NewItem: Integer; @@ -1429,11 +1401,19 @@ begin if not ok then Exit; + if (Msg.Msg = WM_KEYDOWN) and (FIndex <> -1) and (FItems[FIndex].Control <> nil) and + (FItems[FIndex].Control.WantActivationKey(Msg.wParam)) then + begin + FItems[FIndex].Control.OnMessage(Msg); + g_Sound_PlayEx(MENU_CLICKSOUND); + exit; + end; + case Msg.Msg of WM_KEYDOWN: begin case Msg.wParam of - IK_UP, IK_KPUP: + IK_UP, IK_KPUP, VK_UP,JOY0_UP, JOY1_UP, JOY2_UP, JOY3_UP: begin c := 0; repeat @@ -1454,7 +1434,7 @@ begin g_Sound_PlayEx(MENU_CHANGESOUND); end; - IK_DOWN, IK_KPDOWN: + IK_DOWN, IK_KPDOWN, VK_DOWN, JOY0_DOWN, JOY1_DOWN, JOY2_DOWN, JOY3_DOWN: begin c := 0; repeat @@ -1475,13 +1455,15 @@ begin g_Sound_PlayEx(MENU_CHANGESOUND); end; - IK_LEFT, IK_RIGHT, IK_KPLEFT, IK_KPRIGHT: + IK_LEFT, IK_RIGHT, IK_KPLEFT, IK_KPRIGHT, VK_LEFT, VK_RIGHT, + JOY0_LEFT, JOY1_LEFT, JOY2_LEFT, JOY3_LEFT, + JOY0_RIGHT, JOY1_RIGHT, JOY2_RIGHT, JOY3_RIGHT: begin if FIndex <> -1 then if FItems[FIndex].Control <> nil then FItems[FIndex].Control.OnMessage(Msg); end; - IK_RETURN, IK_KPRETURN: + IK_RETURN, IK_KPRETURN, VK_FIRE, VK_OPEN, JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK: begin if FIndex <> -1 then begin @@ -1512,10 +1494,27 @@ end; procedure TGUIMenu.ReAlign(); var a, tx, cx, w, h: Integer; + cww: array of Integer; // cached widths + maxcww: Integer; begin if FItems = nil then Exit; - if not FAlign then tx := FLeft else + SetLength(cww, length(FItems)); + maxcww := 0; + for a := 0 to High(FItems) do + begin + if FItems[a].Text <> nil then + begin + cww[a] := FItems[a].Text.GetWidth; + if maxcww < cww[a] then maxcww := cww[a]; + end; + end; + + if not FAlign then + begin + tx := FLeft; + end + else begin tx := gScreenWidth; for a := 0 to High(FItems) do @@ -1525,27 +1524,17 @@ begin if FItems[a].Control <> nil then begin w := w+MENU_HSPACE; - - if FItems[a].ControlType = TGUILabel then - w := w+(FItems[a].Control as TGUILabel).GetWidth - else if FItems[a].ControlType = TGUITextButton then - w := w+(FItems[a].Control as TGUITextButton).GetWidth - else if FItems[a].ControlType = TGUIScroll then - w := w+(FItems[a].Control as TGUIScroll).GetWidth - else if FItems[a].ControlType = TGUISwitch then - w := w+(FItems[a].Control as TGUISwitch).GetWidth - else if FItems[a].ControlType = TGUIEdit then - w := w+(FItems[a].Control as TGUIEdit).GetWidth - else if FItems[a].ControlType = TGUIKeyRead then - w := w+(FItems[a].Control as TGUIKeyRead).GetWidth - else if (FItems[a].ControlType = TGUIListBox) then - w := w+(FItems[a].Control as TGUIListBox).GetWidth - else if (FItems[a].ControlType = TGUIFileListBox) then - w := w+(FItems[a].Control as TGUIFileListBox).GetWidth - else if FItems[a].ControlType = TGUIMemo then - w := w+(FItems[a].Control as TGUIMemo).GetWidth; + if FItems[a].ControlType = TGUILabel then w := w+(FItems[a].Control as TGUILabel).GetWidth + else if FItems[a].ControlType = TGUITextButton then w := w+(FItems[a].Control as TGUITextButton).GetWidth + else if FItems[a].ControlType = TGUIScroll then w := w+(FItems[a].Control as TGUIScroll).GetWidth + else if FItems[a].ControlType = TGUISwitch then w := w+(FItems[a].Control as TGUISwitch).GetWidth + else if FItems[a].ControlType = TGUIEdit then w := w+(FItems[a].Control as TGUIEdit).GetWidth + else if FItems[a].ControlType = TGUIKeyRead then w := w+(FItems[a].Control as TGUIKeyRead).GetWidth + else if FItems[a].ControlType = TGUIKeyRead2 then w := w+(FItems[a].Control as TGUIKeyRead2).GetWidth + else if FItems[a].ControlType = TGUIListBox then w := w+(FItems[a].Control as TGUIListBox).GetWidth + else if FItems[a].ControlType = TGUIFileListBox then w := w+(FItems[a].Control as TGUIFileListBox).GetWidth + else if FItems[a].ControlType = TGUIMemo then w := w+(FItems[a].Control as TGUIMemo).GetWidth; end; - tx := Min(tx, (gScreenWidth div 2)-(w div 2)); end; end; @@ -1588,35 +1577,46 @@ begin end; for a := 0 to High(FItems) do + begin with FItems[a] do begin if Text <> nil then + begin with Text do begin FX := tx; FY := h; end; + //HACK! + if Text.RightAlign and (length(cww) > a) then + begin + //Text.FX := Text.FX+maxcww; + Text.FMaxWidth := maxcww; + end; + end; - if Control <> nil then - with Control do - if Text <> nil then - begin - FX := cx; - FY := h; - end - else - begin - FX := tx; - FY := h; - end; + if Control <> nil then + begin + with Control do + begin + if Text <> nil then + begin + FX := cx; + FY := h; + end + else + begin + FX := tx; + FY := h; + end; + end; + end; - if (ControlType = TGUIListBox) or (ControlType = TGUIFileListBox) then - Inc(h, (Control as TGUIListBox).GetHeight+MENU_VSPACE) - else if ControlType = TGUIMemo then - Inc(h, (Control as TGUIMemo).GetHeight+MENU_VSPACE) - else - Inc(h, e_CharFont_GetMaxHeight(FFontID)+MENU_VSPACE); + if (ControlType = TGUIListBox) or (ControlType = TGUIFileListBox) then Inc(h, (Control as TGUIListBox).GetHeight+MENU_VSPACE) + else if ControlType = TGUIMemo then Inc(h, (Control as TGUIMemo).GetHeight+MENU_VSPACE) + else Inc(h, e_CharFont_GetMaxHeight(FFontID)+MENU_VSPACE); end; + end; // another ugly hack if FYesNo and (length(FItems) > 1) then @@ -1768,6 +1768,37 @@ begin ReAlign(); end; +function TGUIMenu.AddKeyRead2(fText: string): TGUIKeyRead2; +var + i: Integer; +begin + i := NewItem(); + with FItems[i] do + begin + Control := TGUIKeyRead2.Create(FFontID); + with Control as TGUIKeyRead2 do + begin + FWindow := Self.FWindow; + FColor := MENU_ITEMSCTRL_COLOR; + end; + + Text := TGUILabel.Create(fText, FFontID); + with Text do + begin + FColor := MENU_ITEMSCTRL_COLOR; //MENU_ITEMSTEXT_COLOR; + RightAlign := true; + end; + + ControlType := TGUIKeyRead2; + + Result := (Control as TGUIKeyRead2); + end; + + if FIndex = -1 then FIndex := i; + + ReAlign(); +end; + function TGUIMenu.AddList(fText: string; Width, Height: Word): TGUIListBox; var i: Integer; @@ -1919,26 +1950,6 @@ begin FMax := 0; FOnChangeEvent := nil; - - g_Texture_Get(SCROLL_LEFT, FLeftID); - g_Texture_Get(SCROLL_RIGHT, FRightID); - g_Texture_Get(SCROLL_MIDDLE, FMiddleID); - g_Texture_Get(SCROLL_MARKER, FMarkerID); -end; - -procedure TGUIScroll.Draw; -var - a: Integer; -begin - inherited; - - e_Draw(FLeftID, FX, FY, 0, True, False); - e_Draw(FRightID, FX+8+(FMax+1)*8, FY, 0, True, False); - - for a := 0 to FMax do - e_Draw(FMiddleID, FX+8+a*8, FY, 0, True, False); - - e_Draw(FMarkerID, FX+8+FValue*8, FY, 0, True, False); end; procedure TGUIScroll.FSetValue(a: Integer); @@ -1946,11 +1957,6 @@ begin if a > FMax then FValue := FMax else FValue := a; end; -function TGUIScroll.GetWidth: Word; -begin - Result := 16+(FMax+1)*8; -end; - procedure TGUIScroll.OnMessage(var Msg: TMessage); begin if not FEnabled then Exit; @@ -1961,14 +1967,14 @@ begin WM_KEYDOWN: begin case Msg.wParam of - IK_LEFT, IK_KPLEFT: + IK_LEFT, IK_KPLEFT, VK_LEFT, JOY0_LEFT, JOY1_LEFT, JOY2_LEFT, JOY3_LEFT: if FValue > 0 then begin Dec(FValue); g_Sound_PlayEx(SCROLL_SUBSOUND); if @FOnChangeEvent <> nil then FOnChangeEvent(Self); end; - IK_RIGHT, IK_KPRIGHT: + IK_RIGHT, IK_KPRIGHT, VK_RIGHT, JOY0_RIGHT, JOY1_RIGHT, JOY2_RIGHT, JOY3_RIGHT: if FValue < FMax then begin Inc(FValue); @@ -2002,14 +2008,7 @@ begin FIndex := -1; - FFont := TFont.Create(FontID, FONT_CHAR); -end; - -procedure TGUISwitch.Draw; -begin - inherited; - - FFont.Draw(FX, FY, FItems[FIndex], FColor.R, FColor.G, FColor.B); + FFont := TFont.Create(FontID, TFontType.Character); end; function TGUISwitch.GetText: string; @@ -2018,22 +2017,6 @@ begin else Result := ''; end; -function TGUISwitch.GetWidth: Word; -var - a: Integer; - w, h: Word; -begin - Result := 0; - - if FItems = nil then Exit; - - for a := 0 to High(FItems) do - begin - FFont.GetTextSize(FItems[a], w, h); - if w > Result then Result := w; - end; -end; - procedure TGUISwitch.OnMessage(var Msg: TMessage); begin if not FEnabled then Exit; @@ -2045,27 +2028,34 @@ begin case Msg.Msg of WM_KEYDOWN: case Msg.wParam of - IK_RETURN, IK_RIGHT, IK_KPRETURN, IK_KPRIGHT: + IK_RETURN, IK_RIGHT, IK_KPRETURN, IK_KPRIGHT, VK_FIRE, VK_OPEN, VK_RIGHT, + JOY0_RIGHT, JOY1_RIGHT, JOY2_RIGHT, JOY3_RIGHT, + JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK: begin if FIndex < High(FItems) then Inc(FIndex) else FIndex := 0; + g_Sound_PlayEx(SCROLL_ADDSOUND); + if @FOnChangeEvent <> nil then FOnChangeEvent(Self); end; - IK_LEFT, IK_KPLEFT: - begin - if FIndex > 0 then - Dec(FIndex) - else - FIndex := High(FItems); + IK_LEFT, IK_KPLEFT, VK_LEFT, + JOY0_LEFT, JOY1_LEFT, JOY2_LEFT, JOY3_LEFT: + begin + if FIndex > 0 then + Dec(FIndex) + else + FIndex := High(FItems); - if @FOnChangeEvent <> nil then - FOnChangeEvent(Self); - end; + g_Sound_PlayEx(SCROLL_SUBSOUND); + + if @FOnChangeEvent <> nil then + FOnChangeEvent(Self); + end; end; end; end; @@ -2082,42 +2072,11 @@ constructor TGUIEdit.Create(FontID: DWORD); begin inherited Create(); - FFont := TFont.Create(FontID, FONT_CHAR); + FFont := TFont.Create(FontID, TFontType.Character); FMaxLength := 0; FWidth := 0; - - g_Texture_Get(EDIT_LEFT, FLeftID); - g_Texture_Get(EDIT_RIGHT, FRightID); - g_Texture_Get(EDIT_MIDDLE, FMiddleID); -end; - -procedure TGUIEdit.Draw; -var - c, w, h: Word; -begin - inherited; - - e_Draw(FLeftID, FX, FY, 0, True, False); - e_Draw(FRightID, FX+8+FWidth*16, FY, 0, True, False); - - for c := 0 to FWidth-1 do - e_Draw(FMiddleID, FX+8+c*16, FY, 0, True, False); - - FFont.Draw(FX+8, FY, FText, FColor.R, FColor.G, FColor.B); - - if FWindow.FActiveControl = Self then - begin - FFont.GetTextSize(Copy(FText, 1, FCaretPos), w, h); - h := e_CharFont_GetMaxHeight(FFont.ID); - e_DrawLine(2, FX+8+w, FY+h-3, FX+8+w+EDIT_CURSORLEN, FY+h-3, - EDIT_CURSORCOLOR.R, EDIT_CURSORCOLOR.G, EDIT_CURSORCOLOR.B); - end; -end; - -function TGUIEdit.GetWidth: Word; -begin - Result := 16+FWidth*16; + FInvalid := false; end; procedure TGUIEdit.OnMessage(var Msg: TMessage); @@ -2157,9 +2116,9 @@ begin IK_DELETE: Delete(FText, FCaretPos + 1, 1); IK_END, IK_KPEND: FCaretPos := Length(FText); IK_HOME, IK_KPHOME: FCaretPos := 0; - IK_LEFT, IK_KPLEFT: if FCaretPos > 0 then Dec(FCaretPos); - IK_RIGHT, IK_KPRIGHT: if FCaretPos < Length(FText) then Inc(FCaretPos); - IK_RETURN, IK_KPRETURN: + IK_LEFT, IK_KPLEFT, VK_LEFT, JOY0_LEFT, JOY1_LEFT, JOY2_LEFT, JOY3_LEFT: if FCaretPos > 0 then Dec(FCaretPos); + IK_RIGHT, IK_KPRIGHT, VK_RIGHT, JOY0_RIGHT, JOY1_RIGHT, JOY2_RIGHT, JOY3_RIGHT: if FCaretPos < Length(FText) then Inc(FCaretPos); + IK_RETURN, IK_KPRETURN, VK_FIRE, VK_OPEN, JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK: with FWindow do begin if FActiveControl <> Self then @@ -2176,6 +2135,12 @@ begin end; end; end; + + g_GUIGrabInput := (@FOnEnterEvent = nil) and (FWindow.FActiveControl = Self); + + {$IFDEF ENABLE_TOUCH} + sys_ShowKeyboard(g_GUIGrabInput) + {$ENDIF} end; procedure TGUIEdit.SetText(Text: string); @@ -2195,39 +2160,151 @@ end; constructor TGUIKeyRead.Create(FontID: DWORD); begin inherited Create(); + FKey := 0; + FIsQuery := false; - FFont := TFont.Create(FontID, FONT_CHAR); + FFont := TFont.Create(FontID, TFontType.Character); end; -procedure TGUIKeyRead.Draw; +function TGUIKeyRead.WantActivationKey (key: LongInt): Boolean; +begin + result := + (key = IK_BACKSPACE) or + false; // oops +end; + +procedure TGUIKeyRead.OnMessage(var Msg: TMessage); + procedure actDefCtl (); + begin + with FWindow do + if FDefControl <> '' then + SetActive(GetControl(FDefControl)) + else + SetActive(nil); + end; + begin inherited; - FFont.Draw(FX, FY, IfThen(FIsQuery, KEYREAD_QUERY, IfThen(FKey <> 0, e_KeyNames[FKey], KEYREAD_CLEAR)), - FColor.R, FColor.G, FColor.B); + if not FEnabled then + Exit; + + with Msg do + case Msg of + WM_KEYDOWN: + case wParam of + VK_ESCAPE: + begin + if FIsQuery then actDefCtl(); + FIsQuery := False; + end; + IK_RETURN, IK_KPRETURN, VK_FIRE, VK_OPEN, JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK: + begin + if not FIsQuery then + begin + with FWindow do + if FActiveControl <> Self then + SetActive(Self); + + FIsQuery := True; + end + else if (wParam < VK_FIRSTKEY) and (wParam > VK_LASTKEY) then + begin + // FKey := IK_ENTER; // + FKey := wParam; + FIsQuery := False; + actDefCtl(); + end; + end; + IK_BACKSPACE: // clear keybinding if we aren't waiting for a key + begin + if not FIsQuery then + begin + FKey := 0; + actDefCtl(); + end; + end; + end; + + MESSAGE_DIKEY: + begin + if not FIsQuery and (wParam = IK_BACKSPACE) then + begin + FKey := 0; + actDefCtl(); + end + else if FIsQuery then + begin + case wParam of + IK_ENTER, IK_KPRETURN, VK_FIRSTKEY..VK_LASTKEY (*, JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK*): // Not '' then + FKey := wParam; + FIsQuery := False; + actDefCtl(); + end + end; + end; + end; + + g_GUIGrabInput := FIsQuery end; -function TGUIKeyRead.GetWidth: Word; +{ TGUIKeyRead2 } + +constructor TGUIKeyRead2.Create(FontID: DWORD); var a: Byte; w, h: Word; begin - Result := 0; + inherited Create(); + + FKey0 := 0; + FKey1 := 0; + FKeyIdx := 0; + FIsQuery := False; + FFontID := FontID; + FFont := TFont.Create(FontID, TFontType.Character); + + FMaxKeyNameWdt := 0; for a := 0 to 255 do begin FFont.GetTextSize(e_KeyNames[a], w, h); - Result := Max(Result, w); + FMaxKeyNameWdt := Max(FMaxKeyNameWdt, w); end; + FMaxKeyNameWdt := FMaxKeyNameWdt-(FMaxKeyNameWdt div 3); + FFont.GetTextSize(KEYREAD_QUERY, w, h); - if w > Result then Result := w; + if w > FMaxKeyNameWdt then FMaxKeyNameWdt := w; FFont.GetTextSize(KEYREAD_CLEAR, w, h); - if w > Result then Result := w; + if w > FMaxKeyNameWdt then FMaxKeyNameWdt := w; end; -procedure TGUIKeyRead.OnMessage(var Msg: TMessage); +function TGUIKeyRead2.WantActivationKey (key: LongInt): Boolean; +begin + case key of + IK_BACKSPACE, IK_LEFT, IK_RIGHT, IK_KPLEFT, IK_KPRIGHT, VK_LEFT, VK_RIGHT, + JOY0_LEFT, JOY1_LEFT, JOY2_LEFT, JOY3_LEFT, + JOY0_RIGHT, JOY1_RIGHT, JOY2_RIGHT, JOY3_RIGHT: + result := True + else + result := False + end +end; + +procedure TGUIKeyRead2.OnMessage(var Msg: TMessage); + procedure actDefCtl (); + begin + with FWindow do + if FDefControl <> '' then + SetActive(GetControl(FDefControl)) + else + SetActive(nil); + end; + begin inherited; @@ -2238,18 +2315,12 @@ begin case Msg of WM_KEYDOWN: case wParam of - IK_ESCAPE: + VK_ESCAPE: begin - if FIsQuery then - with FWindow do - if FDefControl <> '' then - SetActive(GetControl(FDefControl)) - else - SetActive(nil); - + if FIsQuery then actDefCtl(); FIsQuery := False; end; - IK_RETURN, IK_KPRETURN: + IK_RETURN, IK_KPRETURN, VK_FIRE, VK_OPEN, JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK: begin if not FIsQuery then begin @@ -2259,36 +2330,63 @@ begin FIsQuery := True; end - else + else if (wParam < VK_FIRSTKEY) and (wParam > VK_LASTKEY) then begin - FKey := IK_ENTER; // + // if (FKeyIdx = 0) then FKey0 := IK_ENTER else FKey1 := IK_ENTER; // + if (FKeyIdx = 0) then FKey0 := wParam else FKey1 := wParam; FIsQuery := False; - - with FWindow do - if FDefControl <> '' then - SetActive(GetControl(FDefControl)) - else - SetActive(nil); + actDefCtl(); end; end; + IK_BACKSPACE: // clear keybinding if we aren't waiting for a key + begin + if not FIsQuery then + begin + if (FKeyIdx = 0) then FKey0 := 0 else FKey1 := 0; + actDefCtl(); + end; + end; + IK_LEFT, IK_KPLEFT, VK_LEFT, JOY0_LEFT, JOY1_LEFT, JOY2_LEFT, JOY3_LEFT: + if not FIsQuery then + begin + FKeyIdx := 0; + actDefCtl(); + end; + IK_RIGHT, IK_KPRIGHT, VK_RIGHT, JOY0_RIGHT, JOY1_RIGHT, JOY2_RIGHT, JOY3_RIGHT: + if not FIsQuery then + begin + FKeyIdx := 1; + actDefCtl(); + end; end; MESSAGE_DIKEY: - if FIsQuery and (wParam <> IK_ENTER) and (wParam <> IK_KPRETURN) then // Not '' then - FKey := wParam; - FIsQuery := False; - - with FWindow do - if FDefControl <> '' then - SetActive(GetControl(FDefControl)) + if not FIsQuery and (wParam = IK_BACKSPACE) then + begin + if (FKeyIdx = 0) then FKey0 := 0 else FKey1 := 0; + actDefCtl(); + end + else if FIsQuery then + begin + case wParam of + IK_ENTER, IK_KPRETURN, VK_FIRSTKEY..VK_LASTKEY (*, JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK*): // Not '' then + begin + if (FKeyIdx = 0) then FKey0 := wParam else FKey1 := wParam; + end; + FIsQuery := False; + actDefCtl() + end + end; end; end; + + g_GUIGrabInput := FIsQuery end; + { TGUIModelView } constructor TGUIModelView.Create; @@ -2305,15 +2403,6 @@ begin inherited; end; -procedure TGUIModelView.Draw; -begin - inherited; - - DrawBox(FX, FY, 4, 4); - - if FModel <> nil then FModel.Draw(FX+4, FY+4); -end; - procedure TGUIModelView.NextAnim(); begin if FModel = nil then @@ -2330,7 +2419,7 @@ begin if FModel = nil then Exit; - if FModel.Weapon < WEAPON_SUPERPULEMET then + if FModel.Weapon < WP_LAST then FModel.SetWeapon(FModel.Weapon+1) else FModel.SetWeapon(WEAPON_KASTET); @@ -2378,84 +2467,6 @@ begin inherited; end; -procedure TGUIMapPreview.Draw(); -var - a: Integer; - r, g, b: Byte; -begin - inherited; - - DrawBox(FX, FY, MAPPREVIEW_WIDTH, MAPPREVIEW_HEIGHT); - - if (FMapSize.X <= 0) or (FMapSize.Y <= 0) then - Exit; - - e_DrawFillQuad(FX+4, FY+4, - FX+4 + Trunc(FMapSize.X / FScale) - 1, - FY+4 + Trunc(FMapSize.Y / FScale) - 1, - 32, 32, 32, 0); - - if FMapData <> nil then - for a := 0 to High(FMapData) do - with FMapData[a] do - begin - if X1 > MAPPREVIEW_WIDTH*16 then Continue; - if Y1 > MAPPREVIEW_HEIGHT*16 then Continue; - - if X2 < 0 then Continue; - if Y2 < 0 then Continue; - - if X2 > MAPPREVIEW_WIDTH*16 then X2 := MAPPREVIEW_WIDTH*16; - if Y2 > MAPPREVIEW_HEIGHT*16 then Y2 := MAPPREVIEW_HEIGHT*16; - - if X1 < 0 then X1 := 0; - if Y1 < 0 then Y1 := 0; - - case PanelType of - PANEL_WALL: - begin - r := 255; - g := 255; - b := 255; - end; - PANEL_CLOSEDOOR: - begin - r := 255; - g := 255; - b := 0; - end; - PANEL_WATER: - begin - r := 0; - g := 0; - b := 192; - end; - PANEL_ACID1: - begin - r := 0; - g := 176; - b := 0; - end; - PANEL_ACID2: - begin - r := 176; - g := 0; - b := 0; - end; - else - begin - r := 128; - g := 128; - b := 128; - end; - end; - - if ((X2-X1) > 0) and ((Y2-Y1) > 0) then - e_DrawFillQuad(FX+4 + X1, FY+4 + Y1, - FX+4 + X2 - 1, FY+4 + Y2 - 1, r, g, b, 0); - end; -end; - procedure TGUIMapPreview.OnMessage(var Msg: TMessage); begin inherited; @@ -2465,15 +2476,20 @@ end; procedure TGUIMapPreview.SetMap(Res: string); var WAD: TWADFile; - MapReader: TMapReader_1; - panels: TPanelsRec1Array; - header: TMapHeaderRec_1; - a: Integer; + panlist: TDynField; + pan: TDynRecord; + //header: TMapHeaderRec_1; FileName: string; Data: Pointer; Len: Integer; rX, rY: Single; + map: TDynRecord = nil; begin + FMapSize.X := 0; + FMapSize.Y := 0; + FScale := 0.0; + FMapData := nil; + FileName := g_ExtractWadName(Res); WAD := TWADFile.Create(); @@ -2484,7 +2500,7 @@ begin end; //k8: ignores path again - if not WAD.GetResource(g_ExtractFileName(Res), Data, Len) then + if not WAD.GetMapResource(g_ExtractFileName(Res), Data, Len) then begin WAD.Free(); Exit; @@ -2492,68 +2508,71 @@ begin WAD.Free(); - MapReader := TMapReader_1.Create(); - - if not MapReader.LoadMap(Data) then - begin + try + map := g_Map_ParseMap(Data, Len); + except FreeMem(Data); - MapReader.Free(); - FMapSize.X := 0; - FMapSize.Y := 0; - FScale := 0.0; - FMapData := nil; - Exit; + map.Free(); + //raise; + exit; end; FreeMem(Data); - panels := MapReader.GetPanels(); - header := MapReader.GetMapHeader(); + if (map = nil) then exit; - FMapSize.X := header.Width div 16; - FMapSize.Y := header.Height div 16; + try + panlist := map.field['panel']; + //header := GetMapHeader(map); - rX := Ceil(header.Width / (MAPPREVIEW_WIDTH*256.0)); - rY := Ceil(header.Height / (MAPPREVIEW_HEIGHT*256.0)); - FScale := max(rX, rY); + FMapSize.X := map.Width div 16; + FMapSize.Y := map.Height div 16; - FMapData := nil; + rX := Ceil(map.Width / (MAPPREVIEW_WIDTH*256.0)); + rY := Ceil(map.Height / (MAPPREVIEW_HEIGHT*256.0)); + FScale := max(rX, rY); + + FMapData := nil; - if panels <> nil then - for a := 0 to High(panels) do - if WordBool(panels[a].PanelType and (PANEL_WALL or PANEL_CLOSEDOOR or - PANEL_STEP or PANEL_WATER or - PANEL_ACID1 or PANEL_ACID2)) then + if (panlist <> nil) then + begin + for pan in panlist do begin - SetLength(FMapData, Length(FMapData)+1); - with FMapData[High(FMapData)] do + if (pan.PanelType and (PANEL_WALL or PANEL_CLOSEDOOR or + PANEL_STEP or PANEL_WATER or + PANEL_ACID1 or PANEL_ACID2)) <> 0 then begin - X1 := panels[a].X div 16; - Y1 := panels[a].Y div 16; + SetLength(FMapData, Length(FMapData)+1); + with FMapData[High(FMapData)] do + begin + X1 := pan.X div 16; + Y1 := pan.Y div 16; - X2 := (panels[a].X + panels[a].Width) div 16; - Y2 := (panels[a].Y + panels[a].Height) div 16; + X2 := (pan.X + pan.Width) div 16; + Y2 := (pan.Y + pan.Height) div 16; - X1 := Trunc(X1/FScale + 0.5); - Y1 := Trunc(Y1/FScale + 0.5); - X2 := Trunc(X2/FScale + 0.5); - Y2 := Trunc(Y2/FScale + 0.5); + X1 := Trunc(X1/FScale + 0.5); + Y1 := Trunc(Y1/FScale + 0.5); + X2 := Trunc(X2/FScale + 0.5); + Y2 := Trunc(Y2/FScale + 0.5); - if (X1 <> X2) or (Y1 <> Y2) then - begin - if X1 = X2 then - X2 := X2 + 1; - if Y1 = Y2 then - Y2 := Y2 + 1; - end; + if (X1 <> X2) or (Y1 <> Y2) then + begin + if X1 = X2 then + X2 := X2 + 1; + if Y1 = Y2 then + Y2 := Y2 + 1; + end; - PanelType := panels[a].PanelType; + PanelType := pan.PanelType; + end; + end; end; - end; - - panels := nil; - - MapReader.Free(); + end; + finally + //writeln('freeing map'); + map.Free(); + end; end; procedure TGUIMapPreview.ClearMap(); @@ -2593,10 +2612,18 @@ begin SetLength(FItems, Length(FItems)+1); FItems[High(FItems)] := Item; - if FSort then g_Basic.Sort(FItems); + if FSort then g_gui.Sort(FItems); +end; + +function TGUIListBox.ItemExists (item: String): Boolean; + var i: Integer; +begin + i := 0; + while (i <= High(FItems)) and (FItems[i] <> item) do Inc(i); + result := i <= High(FItems) end; -procedure TGUIListBox.Clear(); +procedure TGUIListBox.Clear; begin FItems := nil; @@ -2608,7 +2635,7 @@ constructor TGUIListBox.Create(FontID: DWORD; Width, Height: Word); begin inherited Create(); - FFont := TFont.Create(FontID, FONT_CHAR); + FFont := TFont.Create(FontID, TFontType.Character); FWidth := Width; FHeight := Height; @@ -2618,48 +2645,6 @@ begin FDrawScroll := True; end; -procedure TGUIListBox.Draw; -var - w2, h2: Word; - a: Integer; - s: string; -begin - inherited; - - if FDrawBack then DrawBox(FX, FY, FWidth+1, FHeight); - if FDrawScroll then - DrawScroll(FX+4+FWidth*16, FY+4, FHeight, (FStartLine > 0) and (FItems <> nil), - (FStartLine+FHeight-1 < High(FItems)) and (FItems <> nil)); - - if FItems <> nil then - for a := FStartLine to Min(High(FItems), FStartLine+FHeight-1) do - begin - s := Items[a]; - - FFont.GetTextSize(s, w2, h2); - while (Length(s) > 0) and (w2 > FWidth*16) do - begin - SetLength(s, Length(s)-1); - FFont.GetTextSize(s, w2, h2); - end; - - if a = FIndex then - FFont.Draw(FX+4, FY+4+(a-FStartLine)*16, s, FActiveColor.R, FActiveColor.G, FActiveColor.B) - else - FFont.Draw(FX+4, FY+4+(a-FStartLine)*16, s, FUnActiveColor.R, FUnActiveColor.G, FUnActiveColor.B); - end; -end; - -function TGUIListBox.GetHeight: Word; -begin - Result := 8+FHeight*16; -end; - -function TGUIListBox.GetWidth: Word; -begin - Result := 8+(FWidth+1)*16; -end; - procedure TGUIListBox.OnMessage(var Msg: TMessage); var a: Integer; @@ -2684,21 +2669,21 @@ begin FIndex := High(FItems); FStartLine := Max(High(FItems)-FHeight+1, 0); end; - IK_UP, IK_LEFT, IK_KPUP, IK_KPLEFT: + IK_UP, IK_LEFT, IK_KPUP, IK_KPLEFT, VK_LEFT, JOY0_LEFT, JOY1_LEFT, JOY2_LEFT, JOY3_LEFT: if FIndex > 0 then begin Dec(FIndex); if FIndex < FStartLine then Dec(FStartLine); if @FOnChangeEvent <> nil then FOnChangeEvent(Self); end; - IK_DOWN, IK_RIGHT, IK_KPDOWN, IK_KPRIGHT: + IK_DOWN, IK_RIGHT, IK_KPDOWN, IK_KPRIGHT, VK_RIGHT, JOY0_RIGHT, JOY1_RIGHT, JOY2_RIGHT, JOY3_RIGHT: if FIndex < High(FItems) then begin Inc(FIndex); if FIndex > FStartLine+FHeight-1 then Inc(FStartLine); if @FOnChangeEvent <> nil then FOnChangeEvent(Self); end; - IK_RETURN, IK_KPRETURN: + IK_RETURN, IK_KPRETURN, VK_FIRE, VK_OPEN, JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK: with FWindow do begin if FActiveControl <> Self then SetActive(Self) @@ -2730,7 +2715,7 @@ begin Result := FItems[FIndex]; end; -procedure TGUIListBox.FSetItems(Items: SArray); +procedure TGUIListBox.FSetItems(Items: SSArray); begin if FItems <> nil then FItems := nil; @@ -2740,7 +2725,7 @@ begin FStartLine := 0; FIndex := -1; - if FSort then g_Basic.Sort(FItems); + if FSort then g_gui.Sort(FItems); end; procedure TGUIListBox.SelectItem(Item: String); @@ -2786,7 +2771,7 @@ end; procedure TGUIFileListBox.OnMessage(var Msg: TMessage); var - a: Integer; + a, b: Integer; s: AnsiString; begin if not FEnabled then Exit; @@ -2840,7 +2825,7 @@ begin FStartLine := High(FItems)-FHeight+1; end; - IK_UP, IK_LEFT, IK_KPUP, IK_KPLEFT: + IK_UP, IK_LEFT, IK_KPUP, IK_KPLEFT, VK_UP, VK_LEFT, JOY0_LEFT, JOY1_LEFT, JOY2_LEFT, JOY3_LEFT: if FIndex > 0 then begin Dec(FIndex); @@ -2850,7 +2835,7 @@ begin FOnChangeEvent(Self); end; - IK_DOWN, IK_RIGHT, IK_KPDOWN, IK_KPRIGHT: + IK_DOWN, IK_RIGHT, IK_KPDOWN, IK_KPRIGHT, VK_DOWN, VK_RIGHT, JOY0_RIGHT, JOY1_RIGHT, JOY2_RIGHT, JOY3_RIGHT: if FIndex < High(FItems) then begin Inc(FIndex); @@ -2860,7 +2845,7 @@ begin FOnChangeEvent(Self); end; - IK_RETURN, IK_KPRETURN: + IK_RETURN, IK_KPRETURN, VK_FIRE, VK_OPEN, JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK: with FWindow do begin if FActiveControl <> Self then @@ -2869,7 +2854,18 @@ begin begin if FItems[FIndex][1] = #29 then // Ïàïêà begin - OpenDir(FPath+Copy(FItems[FIndex], 2, 255)); + if FItems[FIndex] = #29 + '..' then + begin + e_LogWritefln('TGUIFileListBox: Upper dir "%s" -> "%s"', [FSubPath, e_UpperDir(FSubPath)]); + FSubPath := e_UpperDir(FSubPath) + end + else + begin + s := Copy(AnsiString(FItems[FIndex]), 2); + e_LogWritefln('TGUIFileListBox: Enter dir "%s" -> "%s"', [FSubPath, e_CatPath(FSubPath, s)]); + FSubPath := e_CatPath(FSubPath, s); + end; + ScanDirs; FIndex := 0; Exit; end; @@ -2883,7 +2879,9 @@ begin end; WM_CHAR: - for a := 0 to High(FItems) do + for b := FIndex + 1 to High(FItems) + FIndex do + begin + a := b mod Length(FItems); if ( (Length(FItems[a]) > 0) and (LowerCase(FItems[a][1]) = LowerCase(Chr(wParam))) ) or ( (Length(FItems[a]) > 1) and @@ -2896,73 +2894,82 @@ begin FOnChangeEvent(Self); Break; end; + end; end; end; -procedure TGUIFileListBox.OpenDir(path: String); -var - SR: TSearchRec; - i: Integer; - sm, sc: string; +procedure TGUIFileListBox.ScanDirs; + var i, j: Integer; path: AnsiString; SR: TSearchRec; sm, sc: String; begin - Clear(); + Clear; - path := IncludeTrailingPathDelimiter(path); - path := ExpandFileName(path); - - // Êàòàëîãè: - if FDirs then + i := High(FBaseList); + while i >= 0 do begin - if FindFirst(path+'*', faDirectory, SR) = 0 then - repeat - if not LongBool(SR.Attr and faDirectory) then - Continue; - if (SR.Name = '.') or - ((SR.Name = '..') and (path = ExpandFileName(FBasePath))) then - Continue; - - AddItem(#1 + SR.Name); - until FindNext(SR) <> 0; - - FindClose(SR); + path := e_CatPath(FBaseList[i], FSubPath); + if FDirs then + begin + if FindFirst(path + '/' + '*', faDirectory, SR) = 0 then + begin + repeat + if LongBool(SR.Attr and faDirectory) then + if (SR.Name <> '.') and ((FSubPath <> '') or (SR.Name <> '..')) then + if Self.ItemExists(#1 + SR.Name) = false then + Self.AddItem(#1 + SR.Name) + until FindNext(SR) <> 0 + end; + FindClose(SR) + end; + Dec(i) end; - // Ôàéëû: - sm := FFileMask; - while sm <> '' do + i := High(FBaseList); + while i >= 0 do begin - i := Pos('|', sm); - if i = 0 then i := length(sm)+1; - sc := Copy(sm, 1, i-1); - Delete(sm, 1, i); - if FindFirst(path+sc, faAnyFile, SR) = 0 then repeat AddItem(SR.Name); until FindNext(SR) <> 0; - FindClose(SR); + path := e_CatPath(FBaseList[i], FSubPath); + sm := FFileMask; + while sm <> '' do + begin + j := Pos('|', sm); + if j = 0 then + j := length(sm) + 1; + sc := Copy(sm, 1, j - 1); + Delete(sm, 1, j); + if FindFirst(path + '/' + sc, faAnyFile, SR) = 0 then + begin + repeat + if Self.ItemExists(SR.Name) = false then + AddItem(SR.Name) + until FindNext(SR) <> 0 + end; + FindClose(SR) + end; + Dec(i) end; for i := 0 to High(FItems) do if FItems[i][1] = #1 then FItems[i][1] := #29; - - FPath := path; end; -procedure TGUIFileListBox.SetBase(path: String); +procedure TGUIFileListBox.SetBase (dirs: SSArray; path: String = ''); begin - FBasePath := path; - OpenDir(FBasePath); + FBaseList := dirs; + FSubPath := path; + ScanDirs end; -function TGUIFileListBox.SelectedItem(): String; +function TGUIFileListBox.SelectedItem (): String; + var s: AnsiString; begin - Result := ''; - - if (FIndex = -1) or (FItems = nil) or - (FIndex > High(FItems)) or - (FItems[FIndex][1] = '/') or - (FItems[FIndex][1] = '\') then - Exit; - - Result := FPath + FItems[FIndex]; + result := ''; + if (FIndex >= 0) and (FIndex <= High(FItems)) and (FItems[FIndex][1] <> '/') and (FItems[FIndex][1] <> '\') then + begin + s := e_CatPath(FSubPath, FItems[FIndex]); + if e_FindResource(FBaseList, s) = true then + result := ExpandFileName(s) + end; + e_LogWritefln('TGUIFileListBox.SelectedItem -> "%s"', [result]); end; procedure TGUIFileListBox.UpdateFileList(); @@ -2977,7 +2984,8 @@ begin else fn := FItems[FIndex]; - OpenDir(FPath); +// OpenDir(FPath); + ScanDirs; if fn <> '' then SelectItem(fn); @@ -2995,7 +3003,7 @@ constructor TGUIMemo.Create(FontID: DWORD; Width, Height: Word); begin inherited Create(); - FFont := TFont.Create(FontID, FONT_CHAR); + FFont := TFont.Create(FontID, TFontType.Character); FWidth := Width; FHeight := Height; @@ -3003,32 +3011,6 @@ begin FDrawScroll := True; end; -procedure TGUIMemo.Draw; -var - a: Integer; -begin - inherited; - - if FDrawBack then DrawBox(FX, FY, FWidth+1, FHeight); - if FDrawScroll then - DrawScroll(FX+4+FWidth*16, FY+4, FHeight, (FStartLine > 0) and (FLines <> nil), - (FStartLine+FHeight-1 < High(FLines)) and (FLines <> nil)); - - if FLines <> nil then - for a := FStartLine to Min(High(FLines), FStartLine+FHeight-1) do - FFont.Draw(FX+4, FY+4+(a-FStartLine)*16, FLines[a], FColor.R, FColor.G, FColor.B); -end; - -function TGUIMemo.GetHeight: Word; -begin - Result := 8+FHeight*16; -end; - -function TGUIMemo.GetWidth: Word; -begin - Result := 8+(FWidth+1)*16; -end; - procedure TGUIMemo.OnMessage(var Msg: TMessage); begin if not FEnabled then Exit; @@ -3041,13 +3023,13 @@ begin case Msg of WM_KEYDOWN: case wParam of - IK_UP, IK_LEFT, IK_KPUP, IK_KPLEFT: + IK_UP, IK_LEFT, IK_KPUP, IK_KPLEFT, VK_UP, VK_LEFT, JOY0_LEFT, JOY1_LEFT, JOY2_LEFT, JOY3_LEFT: if FStartLine > 0 then Dec(FStartLine); - IK_DOWN, IK_RIGHT, IK_KPDOWN, IK_KPRIGHT: + IK_DOWN, IK_RIGHT, IK_KPDOWN, IK_KPRIGHT, VK_DOWN, VK_RIGHT, JOY0_RIGHT, JOY1_RIGHT, JOY2_RIGHT, JOY3_RIGHT: if FStartLine < Length(FLines)-FHeight then Inc(FStartLine); - IK_RETURN, IK_KPRETURN: + IK_RETURN, IK_KPRETURN, VK_FIRE, VK_OPEN, JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK: with FWindow do begin if FActiveControl <> Self then @@ -3091,20 +3073,6 @@ begin inherited; end; -procedure TGUIimage.Draw(); -var - ID: DWORD; -begin - inherited; - - if FImageRes = '' then - begin - if g_Texture_Get(FDefaultRes, ID) then e_Draw(ID, FX, FY, 0, True, False); - end - else - if g_Texture_Get(FImageRes, ID) then e_Draw(ID, FX, FY, 0, True, False); -end; - procedure TGUIimage.OnMessage(var Msg: TMessage); begin inherited;