From: Ketmar Dark Date: Sun, 20 Oct 2019 23:40:49 +0000 (+0300) Subject: game: do not use absolute path in wad selection widgets (it looks ugly, and [almost... X-Git-Url: http://deadsoftware.ru/gitweb?p=d2df-sdl.git;a=commitdiff_plain;h=a959696d242bc66e6890d281eb6e5d627c2588e9 game: do not use absolute path in wad selection widgets (it looks ugly, and [almost] not necessary) --- diff --git a/src/engine/e_res.pas b/src/engine/e_res.pas index e2f8889..a4f9da5 100644 --- a/src/engine/e_res.pas +++ b/src/engine/e_res.pas @@ -48,6 +48,9 @@ interface function e_FindResource (dirs: SSArray; var name: AnsiString; nameIsDir: Boolean = false): Boolean; function e_FindWad (dirs: SSArray; name: AnsiString): AnsiString; + {--- returns relative wad name; never empty string ---} + function e_FindWadRel (dirs: SSArray; name: AnsiString): AnsiString; + {--- append dirs to 'path.wad:\file'. if disk is void, append defWad ---} function e_GetResourcePath (dirs: SSArray; path: AnsiString; defWad: AnsiString): AnsiString; @@ -215,6 +218,32 @@ implementation end end; + function e_FindWadRel (dirs: SSArray; name: AnsiString): AnsiString; + var + s: AnsiString; + maxpfx: AnsiString = ''; + pfx: AnsiString; + begin + result := name; + if not findFileCI(name) then exit; + for s in dirs do + begin + if (length(s) = 0) then continue; + if (length(name) <= length(s)) then continue; + if (length(s) < length(maxpfx)) then continue; + pfx := s; + if not findFileCI(pfx, true) then continue; + if (pfx[length(pfx)] <> '/') and (pfx[length(pfx)] <> '\') then pfx := pfx+'/'; + if (length(pfx)+1 > length(name)) then continue; + if (strEquCI1251(copy(name, 1, length(pfx)), pfx)) then maxpfx := pfx; + end; + if (length(maxpfx) > 0) then + begin + result := name; + Delete(result, 1, length(maxpfx)); + end; + end; + function e_GetResourcePath (dirs: SSArray; path: AnsiString; defWad: AnsiString): AnsiString; var diskName, fileName: AnsiString; begin diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 6564a23..ec7f8f2 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -103,7 +103,7 @@ procedure g_Game_RestartLevel(); procedure g_Game_RestartRound(NoMapRestart: Boolean = False); function g_Game_ClientWAD (NewWAD: String; const WHash: TMD5Digest): AnsiString; procedure g_Game_SaveOptions(); -function g_Game_StartMap(Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean; +function g_Game_StartMap(asMegawad: Boolean; Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean; procedure g_Game_ChangeMap(const MapPath: String); procedure g_Game_ExitLevel(const Map: AnsiString); function g_Game_GetFirstMap(WAD: String): String; @@ -4364,7 +4364,7 @@ begin end; // Çàãðóçêà è çàïóñê êàðòû: - if not g_Game_StartMap(MAP, True) then + if not g_Game_StartMap(false{asMegawad}, MAP, True) then begin if (Pos(':\', Map) > 0) or (Pos(':/', Map) > 0) then tmps := Map else tmps := gGameSettings.WAD + ':\' + MAP; g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [tmps])); @@ -4454,7 +4454,7 @@ begin end; // Çàãðóçêà è çàïóñê êàðòû: - if not g_Game_StartMap(Map, True) then + if not g_Game_StartMap(true{asMegawad}, Map, True) then begin g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map])); Exit; @@ -4565,7 +4565,7 @@ begin g_Net_Slist_ServerStarted(); // Çàãðóçêà è çàïóñê êàðòû: - if not g_Game_StartMap(Map, True) then + if not g_Game_StartMap(false{asMegawad}, Map, True) then begin g_Net_Slist_ServerClosed(); g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map])); @@ -4723,7 +4723,7 @@ begin gPlayer1.UID := NetPlrUID1; gPlayer1.Reset(True); - if not g_Game_StartMap(newResPath + ':\' + Map, True) then + if not g_Game_StartMap(false{asMegawad}, newResPath + ':\' + Map, True) then begin g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WadName + ':\' + Map])); @@ -4791,6 +4791,9 @@ begin e_LogWritefln('unable to find or create directory for configs', []); end; +var + lastAsMegaWad: Boolean = false; + procedure g_Game_ChangeMap(const MapPath: String); var Force: Boolean; @@ -4804,7 +4807,7 @@ begin Force := False; gExitByTrigger := False; end; - if not g_Game_StartMap(MapPath, Force) then + if not g_Game_StartMap(lastAsMegaWad, MapPath, Force) then g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [MapPath])); end; @@ -4820,10 +4823,10 @@ begin MessageTime := 0; gGameOn := False; g_Game_ClearLoading(); - g_Game_StartMap(Map, True, gCurrentMapFileName); + g_Game_StartMap(lastAsMegaWad, Map, True, gCurrentMapFileName); end; -function g_Game_StartMap(Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean; +function g_Game_StartMap (asMegawad: Boolean; Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean; var NewWAD, ResName: String; I: Integer; @@ -4845,6 +4848,7 @@ begin g_Player_ResetTeams(); + lastAsMegaWad := asMegawad; if isWadPath(Map) then begin NewWAD := g_ExtractWadName(Map); @@ -4853,7 +4857,17 @@ begin begin nws := findDiskWad(NewWAD); //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']'); - if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD); + if (asMegawad) then + begin + if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD); + if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD); + end + else + begin + if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD); + if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD); + end; + //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD); //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']'); //nws := NewWAD; if (length(nws) = 0) then diff --git a/src/game/g_menu.pas b/src/game/g_menu.pas index d808bf3..72a5c8c 100644 --- a/src/game/g_menu.pas +++ b/src/game/g_menu.pas @@ -860,6 +860,7 @@ begin WAD := TGUIFileListBox(GetControl('lsWAD')).SelectedItem(); TwoPlayers := TGUISwitch(GetControl('swPlayers')).ItemIndex = 1; end; + WAD := e_FindWadRel(MegawadDirs, WAD); if TwoPlayers then n := 2 @@ -1357,6 +1358,8 @@ begin if (wad = '') or (map = '') then Exit; + wad := e_FindWadRel(MapDirs, WAD); + res := wad+':\'+map; TGUILabel(TGUIMenu(g_GUI_GetWindow('CustomGameMenu').GetControl('mCustomGameMenu')).GetControl('lbMap')).Text := res; diff --git a/src/game/g_netmsg.pas b/src/game/g_netmsg.pas index aec47c7..484f8bb 100644 --- a/src/game/g_netmsg.pas +++ b/src/game/g_netmsg.pas @@ -1801,7 +1801,7 @@ begin gGameSettings.GameMode := gSwitchGameMode; gWADHash := EvHash; - if not g_Game_StartMap(EvStr, True) then + if not g_Game_StartMap(false{asMegawad}, EvStr, True) then begin if not isWadPath(EvStr) then g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [gGameSettings.WAD + ':\' + EvStr])) diff --git a/src/game/g_saveload.pas b/src/game/g_saveload.pas index 4e56974..09f5076 100644 --- a/src/game/g_saveload.pas +++ b/src/game/g_saveload.pas @@ -403,7 +403,8 @@ begin g_Game_SetupScreenSize(); // Çàãðóçêà è çàïóñê êàðòû - if not g_Game_StartMap(WAD_Path+':\'+Map_Name, True, curmapfile) then + //FIXME: save/load `asMegawad` + if not g_Game_StartMap(false{asMegawad}, WAD_Path+':\'+Map_Name, True, curmapfile) then begin g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WAD_Path + ':\' + Map_Name])); exit;