DEADSOFTWARE

added alot of hacks and made "yes/no" menu a real menu
[d2df-sdl.git] / src / game / g_menu.pas
index a3bf1ef5937613de1b959c5e5ac8cc1614b52ba2..23e9629666c3a91727a73c2829b8ce74dd283072 100644 (file)
@@ -39,45 +39,44 @@ type TYNCallback = procedure (yes:Boolean);
 procedure YNKeyDownProc (win: TGUIWindow; Key: Byte);
 begin
   if win.UserData = nil then exit;
-  //writeln('YNEX; key=', Key, '; ', (Key = ord('y')));
-       if Key = ord('y') then TYNCallback(win.UserData)(true)
-  else if Key = ord('n') then TYNCallback(win.UserData)(false);
+  case Key of
+    IK_Y, IK_SPACE: TYNCallback(win.UserData)(true);
+    IK_N: TYNCallback(win.UserData)(false);
+  end;
+end;
+
+procedure YesButtonCB (ctl: TGUITextButton);
+begin
+  if ctl.UserData = nil then exit;
+  TYNCallback(ctl.UserData)(true);
 end;
 
-function CreateYNMenu (Name, Text: String; MaxLen: Word; FontID: DWORD; ActionProc: TYNCallback): TGUIWindow;
+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, 'Yes') do begin ProcEx := @YesButtonCB; UserData := @ActionProc; end;
+      with AddButton(nil, 'No') do begin ProcEx := @NoButtonCB; UserData := @ActionProc; end;
     end;
-    DefControl := '';
+    DefControl := '__temp_yes_no_menu:'+WinName;
     SetActive(nil);
   end;
 end;