diff --git a/src/game/g_gui.pas b/src/game/g_gui.pas
index 48700f74e782969b9b562b2f54250ca4d874e527..22cb48d1e4317c46a4f39adcb2f98115741d8ded 100644 (file)
--- a/src/game/g_gui.pas
+++ b/src/game/g_gui.pas
interface
uses
- e_graphics, e_input, g_playermodel, g_basic, MAPSTRUCT, wadreader;
+ e_graphics, e_input, e_log, g_playermodel, g_basic, MAPSTRUCT, wadreader;
const
MAINMENU_HEADER_COLOR: TRGB = (R:255; G:255; B:255);
procedure OnMessage(var Msg: TMessage); virtual;
procedure Update; virtual;
procedure Draw; 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;
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;
procedure TGUIControl.Update();
begin
-
end;
procedure TGUIControl.Draw();
begin
+end;
+function TGUIControl.WantActivationKey (key: LongInt): Boolean;
+begin
+ result := false;
end;
{ TGUITextButton }
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
if w > Result then Result := w;
end;
+function TGUIKeyRead.WantActivationKey (key: LongInt): Boolean;
+begin
+ result :=
+ (key = IK_BACKSPACE) or
+ (key = IK_LEFT) or (key = IK_RIGHT) or
+ (key = IK_KPLEFT) or (key = IK_KPRIGHT) 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;
case wParam of
IK_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:
begin
FKey := IK_ENTER; // <Enter>
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
+ FKey := 0;
+ actDefCtl();
+ end;
+ end;
end;
MESSAGE_DIKEY:
- if FIsQuery and (wParam <> IK_ENTER) and (wParam <> IK_KPRETURN) then // Not <Enter
begin
- if e_KeyNames[wParam] <> '' then
- FKey := wParam;
- FIsQuery := False;
-
- with FWindow do
- if FDefControl <> '' then
- SetActive(GetControl(FDefControl))
- else
- SetActive(nil);
+ if not FIsQuery and (wParam = IK_BACKSPACE) then
+ begin
+ FKey := 0;
+ actDefCtl();
+ end
+ else if FIsQuery and (wParam <> IK_ENTER) and (wParam <> IK_KPRETURN) then // Not <Enter
+ begin
+ e_WriteLog(Format('HIT! %s', ['3']), MSG_WARNING);
+ if e_KeyNames[wParam] <> '' then
+ FKey := wParam;
+ FIsQuery := False;
+ actDefCtl();
+ end;
end;
end;
end;