X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_options.pas;h=cc9a71400bc4a4a7cf159a0392e171f0c8c4cae8;hb=ded89321df07e3f5832331127637375840c25e6f;hp=60b067ed281de1689a980d541789c94f0d371c23;hpb=44bf4b6ea7ee66b36c3cb86c33c180e69f7dc1ba;p=d2df-sdl.git diff --git a/src/game/g_options.pas b/src/game/g_options.pas index 60b067e..cc9a714 100644 --- a/src/game/g_options.pas +++ b/src/game/g_options.pas @@ -61,6 +61,8 @@ type P2Control: TPlayerControl; end; +function GenPlayerName (n: Integer): String; + procedure g_Options_SetDefault(); procedure g_Options_Read(FileName: String); procedure g_Options_Write(FileName: String); @@ -137,11 +139,27 @@ uses {$INCLUDE ../nogl/noGLuses.inc} e_log, e_input, g_window, g_sound, g_gfx, g_player, Math, g_map, g_net, g_netmaster, SysUtils, CONFIG, g_game, g_main, e_texture, - g_items, wadreader, e_graphics, g_touch, SDL2; + g_items, wadreader, e_graphics, g_touch, SDL2, envvars; + + var + machine: Integer; + + function GenPlayerName (n: Integer): String; + begin + ASSERT(n >= 1); + Result := GetUserName; + if Result = '' then + Result := 'Player' + IntToStr(machine MOD 10000); + if n = 1 then + Result := Copy(Result, 1, 12) + ' ' + else + Result := Copy(Result, 1, 10) + ' ' + IntToStr(n) + end; procedure g_Options_SetDefaultVideo; var target, closest, display: TSDL_DisplayMode; + percentage: Integer; begin (* Display 0 = Primary display *) SDL_GetDesktopDisplayMode(0, @display); @@ -153,12 +171,25 @@ begin gFullScreen := True; (* rotation not allowed? *) {$ELSE} (* Window must be smaller than display *) - target.w := display.w * 75 div 100; - target.h := display.h * 75 div 100; - target.format := 0; (* didn't care *) - target.refresh_rate := 0; (* didn't care *) - target.driverdata := nil; (* init *) - SDL_GetClosestDisplayMode(0, @target, @closest); + closest.w := display.w; + closest.h := display.h; + percentage := 75; + while (display.w - closest.w < 48) or (display.h - closest.h < 48) do + begin + if percentage < 25 then + begin + closest.w := display.w * 75 div 100; + closest.h := display.h * 75 div 100; + break; + end; + target.w := display.w * percentage div 100; + target.h := display.h * percentage div 100; + target.format := 0; (* didn't care *) + target.refresh_rate := 0; (* didn't care *) + target.driverdata := nil; (* init *) + SDL_GetClosestDisplayMode(0, @target, @closest); + Dec(percentage); + end; gScreenWidth := closest.w; gScreenHeight := closest.h; //gBPP := SDL_BITSPERPIXEL(closest.format); (* Resolution list didn't work for some reason *) @@ -245,7 +276,7 @@ begin with gPlayer1Settings do begin - Name := 'Player1'; + Name := GenPlayerName(1); Model := STD_PLAYER_MODEL; Color.R := PLAYER1_DEF_COLOR.R; Color.G := PLAYER1_DEF_COLOR.G; @@ -290,7 +321,7 @@ begin with gPlayer2Settings do begin - Name := 'Player2'; + Name := GenPlayerName(2); Model := STD_PLAYER_MODEL; Color.R := PLAYER2_DEF_COLOR.R; Color.G := PLAYER2_DEF_COLOR.G; @@ -939,6 +970,9 @@ begin config.WriteBool('Video', 'Fullscreen', gFullscreen); config.WriteBool('Video', 'Maximized', gWinMaximized); + config.WriteStr('Player1', 'Name', gPlayer1Settings.Name); + config.WriteStr('Player2', 'Name', gPlayer2Settings.Name); + config.SaveFile(FileName); config.Free(); end; @@ -1025,4 +1059,6 @@ begin config.Free(); end; +initialization + machine := Random(10000) end.