DEADSOFTWARE

put "{$MODE ...}" directive in each source file; removed trailing spaces, and convert...
[d2df-sdl.git] / src / game / g_menu.pas
index 015c1e2556f31c61b0905dc464af6633e45ee029..62e4e8d6c0e80852a63bd2ae6064079d7323a2bf 100644 (file)
@@ -1,3 +1,4 @@
+{$MODE DELPHI}
 unit g_menu;
 
 interface
@@ -29,7 +30,7 @@ uses
   g_gui, g_textures, e_graphics, g_main, g_window, g_game, g_map,
   g_basic, g_console, g_sound, g_gfx, g_player, g_options,
   e_log, SysUtils, CONFIG, g_playermodel, DateUtils,
-  MAPSTRUCT, WADEDITOR, Math, WADSTRUCT, g_saveload,
+  MAPSTRUCT, wadreader, Math, g_saveload,
   e_textures, GL, GLExt, g_language,
   g_net, g_netmsg, g_netmaster, g_items, e_input;
 
@@ -45,40 +46,38 @@ begin
   end;
 end;
 
-function CreateYNMenu (Name, Text: String; MaxLen: Word; FontID: DWORD; ActionProc: TYNCallback): TGUIWindow;
+procedure YesButtonCB (ctl: TGUITextButton);
+begin
+  if ctl.UserData = nil then exit;
+  TYNCallback(ctl.UserData)(true);
+end;
+
+procedure NoButtonCB (ctl: TGUITextButton);
+begin
+  if ctl.UserData = nil then exit;
+  TYNCallback(ctl.UserData)(false);
+end;
+
+function CreateYNMenu (WinName, Text: String; MaxLen: Word; FontID: DWORD; ActionProc: TYNCallback): TGUIWindow;
 var
-  a: Integer;
-  h, _x: Word;
-  lines: SArray;
+  menu: TGUIMenu;
 begin
-  Result := TGUIWindow.Create(Name);
+  //if length(Text) = 0 then exit;
+  Result := TGUIWindow.Create(WinName);
   with Result do
   begin
-    OnKeyDownEx := @YNKeyDownProc;
-    UserData := @ActionProc;
-    lines := GetLines(Text, FontID, MaxLen);
-    h := e_CharFont_GetMaxHeight(FontID);
-    _x := (gScreenHeight div 2)-(h*Length(lines) div 2);
-    if lines <> nil then
+    //OnKeyDownEx := @YNKeyDownProc;
+    //UserData := @ActionProc;
+    menu := TGUIMenu(Result.AddChild(TGUIMenu.Create(gMenuSmallFont, gMenuSmallFont, '')));
+    with menu do
     begin
-      for a := 0 to High(lines) do
-      begin
-        with TGUILabel(Result.AddChild(TGUILabel.Create(lines[a], FontID))) do
-        begin
-          X := (gScreenWidth div 2)-(GetWidth div 2);
-          Y := _x;
-          Color := _RGB(255, 0, 0);
-          _x := _x+h;
-        end;
-      end;
-      with TGUILabel(Result.AddChild(TGUILabel.Create('(Y/N)', FontID))) do
-      begin
-        X := (gScreenWidth div 2)-(GetWidth div 2);
-        Y := _x;
-        Color := _RGB(255, 0, 0);
-      end;
+      Name := '__temp_yes_no_menu:'+WinName;
+      YesNo := true;
+      AddText(Text, MaxLen);
+      with AddButton(nil, _lc[I_MENU_YES]) do begin ProcEx := @YesButtonCB; UserData := @ActionProc; end;
+      with AddButton(nil, _lc[I_MENU_NO]) do begin ProcEx := @NoButtonCB; UserData := @ActionProc; end;
     end;
-    DefControl := '';
+    DefControl := '__temp_yes_no_menu:'+WinName;
     SetActive(nil);
   end;
 end;
@@ -776,14 +775,14 @@ var
   cwdt, chgt: Byte;
   spc: ShortInt;
   ID: DWORD;
-  wad: TWADEditor_1;
+  wad: TWADFile;
   cfgdata: Pointer;
   cfglen: Integer;
   config: TConfig;
 begin
   cfglen := 0;
 
-  wad := TWADEditor_1.Create;
+  wad := TWADFile.Create;
   if wad.ReadFile(GameWAD) then
     wad.GetResource('FONTS', cfgres, cfgdata, cfglen);
   wad.Free();
@@ -811,7 +810,7 @@ var
   cwdt, chgt: Byte;
   spc: ShortInt;
   CharID: DWORD;
-  wad: TWADEditor_1;
+  wad: TWADFile;
   cfgdata, fntdata: Pointer;
   cfglen, fntlen: Integer;
   config: TConfig;
@@ -821,7 +820,7 @@ begin
   cfglen := 0;
   fntlen := 0;
 
-  wad := TWADEditor_1.Create;
+  wad := TWADFile.Create;
   if wad.ReadFile(GameWAD) then
   begin
     wad.GetResource('FONTS', txtres, cfgdata, cfglen);