X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_gui.pas;h=98e49178a73e28dd3f39748abf9fd92d2843ecf0;hb=987c4a835a103345b59937e8e1be8524a6228712;hp=8a599fd7a3a9a0c99c05245216c0f1882937dec6;hpb=84fa2f88d5d832ed9cc932fd2860d74467e242e1;p=d2df-sdl.git diff --git a/src/game/g_gui.pas b/src/game/g_gui.pas index 8a599fd..98e4917 100644 --- a/src/game/g_gui.pas +++ b/src/game/g_gui.pas @@ -2,8 +2,7 @@ * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * the Free Software Foundation, version 3 of the License ONLY. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -467,13 +466,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; @@ -535,6 +535,7 @@ type var g_GUIWindows: array of TGUIWindow; g_ActiveWindow: TGUIWindow = nil; + g_GUIGrabInput: Boolean = False; procedure g_GUI_Init(); function g_GUI_AddWindow(Window: TGUIWindow): TGUIWindow; @@ -813,10 +814,19 @@ procedure TGUIWindow.Draw; var i: Integer; ID: DWORD; + tw, th: Word; begin - if FBackTexture <> '' then + if FBackTexture <> '' then // Here goes code duplication from g_game.pas:DrawMenuBackground() if g_Texture_Get(FBackTexture, ID) then - e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight) + begin + e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0); + e_GetTextureSize(ID, @tw, @th); + if tw = th then + 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); + end else e_Clear(GL_COLOR_BUFFER_BIT, 0.5, 0.5, 0.5); @@ -837,7 +847,7 @@ begin if Msg.Msg = WM_KEYDOWN then begin case Msg.wParam of - IK_ESCAPE, VK_ESCAPE, JOY0_JUMP, JOY1_JUMP, JOY2_JUMP, JOY3_JUMP: + VK_ESCAPE: begin g_GUI_HideWindow; Exit @@ -1023,7 +1033,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; @@ -1043,18 +1053,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 @@ -1077,7 +1090,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(); @@ -1088,12 +1101,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; @@ -1113,10 +1129,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 @@ -2335,7 +2357,8 @@ begin end; end; - g_Touch_ShowKeyboard(FWindow.FActiveControl = Self); + g_GUIGrabInput := (@FOnEnterEvent = nil) and (FWindow.FActiveControl = Self); + g_Touch_ShowKeyboard(g_GUIGrabInput) end; procedure TGUIEdit.SetText(Text: string); @@ -2416,7 +2439,7 @@ begin case Msg of WM_KEYDOWN: case wParam of - IK_ESCAPE, VK_ESCAPE, JOY0_JUMP, JOY1_JUMP, JOY2_JUMP, JOY3_JUMP: + VK_ESCAPE: begin if FIsQuery then actDefCtl(); FIsQuery := False; @@ -2431,9 +2454,10 @@ begin FIsQuery := True; end - else + else if (wParam < VK_FIRSTKEY) and (wParam > VK_LASTKEY) then begin - FKey := IK_ENTER; // + // FKey := IK_ENTER; // + FKey := wParam; FIsQuery := False; actDefCtl(); end; @@ -2458,7 +2482,7 @@ begin else if FIsQuery then begin case wParam of - IK_ENTER, IK_KPRETURN, VK_FIRE, VK_OPEN, JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK: // Not '' then FKey := wParam; @@ -2468,6 +2492,8 @@ begin end; end; end; + + g_GUIGrabInput := FIsQuery end; { TGUIKeyRead2 } @@ -2569,7 +2595,7 @@ begin case Msg of WM_KEYDOWN: case wParam of - IK_ESCAPE, VK_ESCAPE, JOY0_JUMP, JOY1_JUMP, JOY2_JUMP, JOY3_JUMP: + VK_ESCAPE: begin if FIsQuery then actDefCtl(); FIsQuery := False; @@ -2584,9 +2610,10 @@ begin FIsQuery := True; end - else + else if (wParam < VK_FIRSTKEY) and (wParam > VK_LASTKEY) then begin - if (FKeyIdx = 0) then FKey0 := IK_ENTER else FKey1 := IK_ENTER; // + // if (FKeyIdx = 0) then FKey0 := IK_ENTER else FKey1 := IK_ENTER; // + if (FKeyIdx = 0) then FKey0 := wParam else FKey1 := wParam; FIsQuery := False; actDefCtl(); end; @@ -2623,8 +2650,7 @@ begin else if FIsQuery then begin case wParam of - IK_ENTER, IK_KPRETURN, VK_FIRE, VK_OPEN, - JOY0_ATTACK, JOY1_ATTACK, JOY2_ATTACK, JOY3_ATTACK: // Not '' then begin @@ -2636,6 +2662,8 @@ begin end; end; end; + + g_GUIGrabInput := FIsQuery end; @@ -3144,7 +3172,7 @@ end; procedure TGUIFileListBox.OnMessage(var Msg: TMessage); var - a: Integer; + a, b: Integer; begin if not FEnabled then Exit; @@ -3241,7 +3269,9 @@ begin end; WM_CHAR: - for a := 0 to High(FItems) do + for b := FIndex + 1 to High(FItems) + FIndex do + begin + a := b mod Length(FItems); if ( (Length(FItems[a]) > 0) and (LowerCase(FItems[a][1]) = LowerCase(Chr(wParam))) ) or ( (Length(FItems[a]) > 1) and @@ -3254,6 +3284,7 @@ begin FOnChangeEvent(Self); Break; end; + end; end; end;