DEADSOFTWARE

allow to bind joystick button zero in menu
[d2df-sdl.git] / src / game / g_gui.pas
index ef5645962bdc2e0bcdedd2f992979fd0c816f360..6043a37e671b9e4f0547f90a7fc4c5db6a2883f5 100644 (file)
@@ -467,13 +467,14 @@ type
   private
     FButtons: array of TGUITextButton;
     FHeader: TGUILabel;
+    FLogo: DWord;
     FIndex: Integer;
     FFontID: DWORD;
     FCounter: Byte;
     FMarkerID1: DWORD;
     FMarkerID2: DWORD;
   public
-    constructor Create(FontID: DWORD; Header: string);
+    constructor Create(FontID: DWORD; Logo, Header: string);
     destructor Destroy; override;
     procedure OnMessage(var Msg: TMessage); override;
     function AddButton(fProc: Pointer; Caption: string; ShowWindow: string = ''): TGUITextButton;
@@ -685,14 +686,14 @@ begin
   if len = 0 then
     Exit;
 
-// ���� � ������� ����:
+// Îêíî ñ ãëàâíûì ìåíþ:
   g_GUI_ShowWindow(Saved_Windows[len-1]);
 
-// �� ������������� (��� ������ ������):
+// Íå ïåðåêëþ÷èëîñü (èëè íåêóäà äàëüøå):
   if (len = 1) or (g_ActiveWindow = nil) then
     Exit;
 
-// ���� ������ � ��������� �����:
+// Èùåì êíîïêè â îñòàëüíûõ îêíàõ:
   for k := len-1 downto 1 do
   begin
     ok := False;
@@ -726,7 +727,7 @@ begin
         Break;
     end;
 
-  // �� �������������:
+  // Íå ïåðåêëþ÷èëîñü:
     if (not ok) or
        (g_ActiveWindow.Name = Saved_Windows[k]) then
       Break;
@@ -825,7 +826,7 @@ begin
         tw := round(tw * 1.333 * (gScreenHeight / th))
       else
         tw := trunc(tw * (gScreenHeight / th));
-        e_DrawSize(ID, (gScreenWidth - tw) div 2, 0, 0, False, False, tw, gScreenHeight);
+      e_DrawSize(ID, (gScreenWidth - tw) div 2, 0, 0, False, False, tw, gScreenHeight);
     end
     else
       e_Clear(GL_COLOR_BUFFER_BIT, 0.5, 0.5, 0.5);
@@ -1033,7 +1034,7 @@ end;
 function TGUIMainMenu.AddButton(fProc: Pointer; Caption: string; ShowWindow: string = ''): TGUITextButton;
 var
   a, _x: Integer;
-  h, hh: Word;
+  h, hh, lh: Word;
 begin
   FIndex := 0;
 
@@ -1053,18 +1054,21 @@ begin
     if FButtons[a] <> nil then
       _x := Min(_x, (gScreenWidth div 2)-(FButtons[a].GetWidth div 2));
 
-  hh := FHeader.GetHeight;
+  if FLogo <> 0 then e_GetTextureSize(FLogo, nil, @lh);
+  hh := FButtons[High(FButtons)].GetHeight;
 
-  h := hh*(2+Length(FButtons))+MAINMENU_SPACE*(Length(FButtons)-1);
-  h := (gScreenHeight div 2)-(h div 2);
+  if FLogo <> 0 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 FLogo <> 0 then Inc(h, lh)
+  else Inc(h, hh*2);
 
   for a := 0 to High(FButtons) do
   begin
@@ -1087,7 +1091,7 @@ begin
   FButtons[High(FButtons)] := nil;
 end;
 
-constructor TGUIMainMenu.Create(FontID: DWORD; Header: string);
+constructor TGUIMainMenu.Create(FontID: DWORD; Logo, Header: string);
 begin
   inherited Create();
 
@@ -1098,12 +1102,15 @@ begin
   g_Texture_Get(MAINMENU_MARKER1, FMarkerID1);
   g_Texture_Get(MAINMENU_MARKER2, FMarkerID2);
 
-  FHeader := TGUILabel.Create(Header, FFontID);
-  with FHeader do
+  if not g_Texture_Get(Logo, FLogo) 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;
 
@@ -1123,10 +1130,16 @@ end;
 procedure TGUIMainMenu.Draw;
 var
   a: Integer;
+  w, h: Word;
+
 begin
   inherited;
 
-  FHeader.Draw;
+  if FHeader <> nil then FHeader.Draw
+  else begin
+    e_GetTextureSize(FLogo, @w, @h);
+    e_Draw(FLogo, ((gScreenWidth div 2) - (w div 2)), FButtons[0].FY - FButtons[0].GetHeight - h, 0, True, False);
+  end;
 
   if FButtons <> nil then
   begin
@@ -2470,7 +2483,7 @@ begin
           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 <Enter
+              IK_ENTER, IK_KPRETURN, VK_FIRSTKEY..VK_LASTKEY (*, JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK*): // Not <Enter
             else
               if e_KeyNames[wParam] <> '' then
                 FKey := wParam;
@@ -2638,7 +2651,7 @@ begin
           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 <Enter
+              IK_ENTER, IK_KPRETURN, VK_FIRSTKEY..VK_LASTKEY (*, JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK*): // Not <Enter
             else
               if e_KeyNames[wParam] <> '' then
               begin
@@ -3241,7 +3254,7 @@ begin
                 SetActive(Self)
               else
                 begin
-                  if FItems[FIndex][1] = #29 then // �����
+                  if FItems[FIndex][1] = #29 then // Ïàïêà
                   begin
                     OpenDir(FPath+Copy(FItems[FIndex], 2, 255));
                     FIndex := 0;
@@ -3263,7 +3276,7 @@ begin
           if ( (Length(FItems[a]) > 0) and
                (LowerCase(FItems[a][1]) = LowerCase(Chr(wParam))) ) or
              ( (Length(FItems[a]) > 1) and
-               (FItems[a][1] = #29) and // �����
+               (FItems[a][1] = #29) and // Ïàïêà
                (LowerCase(FItems[a][2]) = LowerCase(Chr(wParam))) ) then
           begin
             FIndex := a;
@@ -3287,7 +3300,7 @@ begin
   path := IncludeTrailingPathDelimiter(path);
   path := ExpandFileName(path);
 
-  // ��������:
+  // Êàòàëîãè:
   if FDirs then
   begin
     if FindFirst(path+'*', faDirectory, SR) = 0 then
@@ -3304,7 +3317,7 @@ begin
     FindClose(SR);
   end;
 
-  // �����:
+  // Ôàéëû:
   sm := FFileMask;
   while sm <> '' do
   begin