DEADSOFTWARE

gui: "yes/no" menu refactored to ease further changes
[d2df-sdl.git] / src / game / g_gui.pas
index 2f9bc08380d79cf1ba7447ce1800a727463e3ec4..08ecee3316b007a783f681974e47f58785f7fbe3 100644 (file)
@@ -82,16 +82,16 @@ type
   end;
 
   TGUIControl = class;
+  TGUIWindow = class;
 
   TOnKeyDownEvent = procedure(Key: Byte);
+  TOnKeyDownEventEx = procedure(win: TGUIWindow; Key: Byte);
   TOnCloseEvent = procedure;
   TOnShowEvent = procedure;
   TOnClickEvent = procedure;
   TOnChangeEvent = procedure(Sender: TGUIControl);
   TOnEnterEvent = procedure(Sender: TGUIControl);
 
-  TGUIWindow = class;
-
   TGUIControl = class
   private
     FX, FY: Integer;
@@ -118,8 +118,10 @@ type
     FBackTexture: string;
     FMainWindow: Boolean;
     FOnKeyDown: TOnKeyDownEvent;
+    FOnKeyDownEx: TOnKeyDownEventEx;
     FOnCloseEvent: TOnCloseEvent;
     FOnShowEvent: TOnShowEvent;
+    FUserData: Pointer;
   public
     Childs: array of TGUIControl;
     constructor Create(Name: string);
@@ -131,12 +133,14 @@ type
     procedure SetActive(Control: TGUIControl);
     function GetControl(Name: string): TGUIControl;
     property OnKeyDown: TOnKeyDownEvent read FOnKeyDown write FOnKeyDown;
+    property OnKeyDownEx: TOnKeyDownEventEx read FOnKeyDownEx write FOnKeyDownEx;
     property OnClose: TOnCloseEvent read FOnCloseEvent write FOnCloseEvent;
     property OnShow: TOnShowEvent read FOnShowEvent write FOnShowEvent;
     property Name: string read FName;
     property DefControl: string read FDefControl write FDefControl;
     property BackTexture: string read FBackTexture write FBackTexture;
     property MainWindow: Boolean read FMainWindow write FMainWindow;
+    property UserData: Pointer read FUserData write FUserData;
   end;
 
   TGUITextButton = class(TGUIControl)
@@ -713,6 +717,7 @@ begin
   FActiveControl := nil;
   FName := Name;
   FOnKeyDown := nil;
+  FOnKeyDownEx := nil;
   FOnCloseEvent := nil;
   FOnShowEvent := nil;
 end;
@@ -765,6 +770,7 @@ procedure TGUIWindow.OnMessage(var Msg: TMessage);
 begin
   if FActiveControl <> nil then FActiveControl.OnMessage(Msg);
   if @FOnKeyDown <> nil then FOnKeyDown(Msg.wParam);
+  if @FOnKeyDownEx <> nil then FOnKeyDownEx(self, Msg.wParam);
 
   if Msg.Msg = WM_KEYDOWN then
     if Msg.wParam = IK_ESCAPE then
@@ -2844,13 +2850,14 @@ procedure TGUIFileListBox.OpenDir(path: String);
 var
   SR: TSearchRec;
   i: Integer;
+  sm, sc: string;
 begin
   Clear();
 
   path := IncludeTrailingPathDelimiter(path);
   path := ExpandFileName(path);
 
-// Êàòàëîãè:
+  // Êàòàëîãè:
   if FDirs then
   begin
     if FindFirst(path+'*', faDirectory, SR) = 0 then
@@ -2867,20 +2874,15 @@ begin
     FindClose(SR);
   end;
 
-// Ôàéëû:
-  if FindFirst(path+FFileMask, faAnyFile, SR) = 0 then
-    repeat
-      AddItem(SR.Name);
-    until FindNext(SR) <> 0;
-  FindClose(SR);
-
-  //FIXME: HACK!
-  if FFileMask = '*.wad' then
+  // Ôàéëû:
+  sm := FFileMask;
+  while sm <> '' do
   begin
-    if FindFirst(path+'*.pk3', faAnyFile, SR) = 0 then
-      repeat
-        AddItem(SR.Name);
-      until FindNext(SR) <> 0;
+    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);
   end;