forked from electronicarts/CnC_Generals_Zero_Hour
-
Notifications
You must be signed in to change notification settings - Fork 70
Fix Replay GUI #398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
helmutbuhler
wants to merge
5
commits into
TheSuperHackers:main
Choose a base branch
from
helmutbuhler:replay_ea
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fix Replay GUI #398
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a5b13f6
Fix wrong replay list display when there is a map that's not in mapcache
helmutbuhler 34303dc
Don't limit replay list to 100
helmutbuhler 831f84e
Refactor some code into a helper function GetMapInfo (needed soon)
helmutbuhler 210c5f0
Show error message instead of crashing when trying to open a replay w…
helmutbuhler 796919e
Show replay entries whose map is missing in red.
helmutbuhler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,7 +102,31 @@ UnicodeString GetReplayFilenameFromListbox(GameWindow *listbox, Int index) | |
return fname; | ||
} | ||
|
||
|
||
Bool GetMapInfo(const AsciiString& filename, RecorderClass::ReplayHeader *headerOut, ReplayGameInfo *infoOut, const MapMetaData **mdOut) | ||
{ | ||
// lets get some info about the replay | ||
RecorderClass::ReplayHeader header; | ||
header.forPlayback = FALSE; | ||
header.filename = filename; | ||
Bool success = TheRecorder && TheMapCache && TheRecorder->readReplayHeader( header ); | ||
if (!success) | ||
return false; | ||
|
||
ReplayGameInfo info; | ||
if (!ParseAsciiStringToGameInfo( &info, header.gameOptions )) | ||
return false; | ||
|
||
header.replayName.translate(filename); | ||
for (Int tmp=0; tmp < TheRecorder->getReplayExtention().getLength(); ++tmp) | ||
header.replayName.removeLastChar(); | ||
|
||
if (headerOut) *headerOut = header; | ||
if (infoOut) *infoOut = info; | ||
|
||
if (mdOut) | ||
*mdOut = TheMapCache->findMap(info.getMap()); | ||
return true; | ||
} | ||
//------------------------------------------------------------------------------------------------- | ||
/** Populate the listbox with the names of the available replay files */ | ||
//------------------------------------------------------------------------------------------------- | ||
|
@@ -118,13 +142,15 @@ void PopulateReplayFileListbox(GameWindow *listbox) | |
COLOR_SP_CRC_MISMATCH, | ||
COLOR_MP, | ||
COLOR_MP_CRC_MISMATCH, | ||
COLOR_MAP_NOT_PRESENT, | ||
COLOR_MAX | ||
}; | ||
Color colors[COLOR_MAX] = { | ||
GameMakeColor( 255, 255, 255, 255 ), | ||
GameMakeColor( 128, 128, 128, 255 ), | ||
GameMakeColor( 255, 255, 255, 255 ), | ||
GameMakeColor( 128, 128, 128, 255 ) | ||
GameMakeColor( 128, 128, 128, 255 ), | ||
GameMakeColor( 140, 50, 50, 255 ) | ||
}; | ||
|
||
AsciiString asciistr; | ||
|
@@ -144,122 +170,122 @@ void PopulateReplayFileListbox(GameWindow *listbox) | |
{ | ||
// just want the filename | ||
asciistr.set((*it).reverseFind('\\') + 1); | ||
|
||
// lets get some info about the replay | ||
RecorderClass::ReplayHeader header; | ||
header.forPlayback = FALSE; | ||
header.filename = asciistr; | ||
Bool success = TheRecorder && TheMapCache && TheRecorder->readReplayHeader( header ); | ||
ReplayGameInfo info; | ||
const MapMetaData *md; | ||
Bool success = GetMapInfo(asciistr, &header, &info, &md); | ||
|
||
if (success) | ||
{ | ||
ReplayGameInfo info; | ||
if (ParseAsciiStringToGameInfo( &info, header.gameOptions )) | ||
{ | ||
// columns are: name, date, version, map, extra | ||
|
||
// columns are: name, date, version, map, extra | ||
// name | ||
|
||
// name | ||
header.replayName.translate(asciistr); | ||
for (Int tmp=0; tmp < TheRecorder->getReplayExtention().getLength(); ++tmp) | ||
header.replayName.removeLastChar(); | ||
UnicodeString replayNameToShow = header.replayName; | ||
|
||
UnicodeString replayNameToShow = header.replayName; | ||
AsciiString lastReplayFName = TheRecorder->getLastReplayFileName(); | ||
lastReplayFName.concat(TheRecorder->getReplayExtention()); | ||
if (lastReplayFName.compareNoCase(asciistr) == 0) | ||
replayNameToShow = TheGameText->fetch("GUI:LastReplay"); | ||
|
||
AsciiString lastReplayFName = TheRecorder->getLastReplayFileName(); | ||
lastReplayFName.concat(TheRecorder->getReplayExtention()); | ||
if (lastReplayFName.compareNoCase(asciistr) == 0) | ||
replayNameToShow = TheGameText->fetch("GUI:LastReplay"); | ||
UnicodeString displayTimeBuffer = getUnicodeTimeBuffer(header.timeVal); | ||
|
||
UnicodeString displayTimeBuffer = getUnicodeTimeBuffer(header.timeVal); | ||
//displayTimeBuffer.format( L"%ls", timeBuffer); | ||
|
||
//displayTimeBuffer.format( L"%ls", timeBuffer); | ||
// version (no-op) | ||
|
||
// version (no-op) | ||
// map | ||
UnicodeString mapStr; | ||
if (!md) | ||
{ | ||
const char* filename = info.getMap().reverseFind('\\'); | ||
mapStr.translate(filename ? filename + 1 : info.getMap()); | ||
} | ||
else | ||
{ | ||
mapStr = md->m_displayName; | ||
} | ||
|
||
// map | ||
UnicodeString mapStr; | ||
const MapMetaData *md = TheMapCache->findMap(info.getMap()); | ||
if (!md) | ||
// // extra | ||
// UnicodeString extraStr; | ||
// if (header.localPlayerIndex >= 0) | ||
// { | ||
// // MP game | ||
// time_t totalSeconds = header.endTime - header.startTime; | ||
// Int mins = totalSeconds/60; | ||
// Int secs = totalSeconds%60; | ||
// Real fps = header.frameDuration/totalSeconds; | ||
// extraStr.format(L"%d:%d (%g fps) %hs", mins, secs, fps, header.desyncGame?"OOS ":""); | ||
// | ||
// for (Int i=0; i<MAX_SLOTS; ++i) | ||
// { | ||
// const GameSlot *slot = info.getConstSlot(i); | ||
// if (slot && slot->isHuman()) | ||
// { | ||
// if (i) | ||
// extraStr.concat(L", "); | ||
// if (header.playerDiscons[i]) | ||
// extraStr.concat(L'*'); | ||
// extraStr.concat(info.getConstSlot(i)->getName()); | ||
// } | ||
// } | ||
// } | ||
// else | ||
// { | ||
// // solo game | ||
// time_t totalSeconds = header.endTime - header.startTime; | ||
// Int mins = totalSeconds/60; | ||
// Int secs = totalSeconds%60; | ||
// Real fps = header.frameDuration/totalSeconds; | ||
// extraStr.format(L"%d:%d (%g fps)", mins, secs, fps); | ||
// } | ||
|
||
// pick a color | ||
Color color; | ||
if (header.versionString == TheVersion->getUnicodeVersion() && header.versionNumber == TheVersion->getVersionNumber() && | ||
header.exeCRC == TheGlobalData->m_exeCRC && header.iniCRC == TheGlobalData->m_iniCRC) | ||
{ | ||
// good version | ||
if (header.localPlayerIndex >= 0) | ||
{ | ||
mapStr.translate(info.getMap()); | ||
// MP | ||
color = colors[COLOR_MP]; | ||
} | ||
else | ||
{ | ||
mapStr = md->m_displayName; | ||
// SP | ||
color = colors[COLOR_SP]; | ||
} | ||
|
||
// // extra | ||
// UnicodeString extraStr; | ||
// if (header.localPlayerIndex >= 0) | ||
// { | ||
// // MP game | ||
// time_t totalSeconds = header.endTime - header.startTime; | ||
// Int mins = totalSeconds/60; | ||
// Int secs = totalSeconds%60; | ||
// Real fps = header.frameDuration/totalSeconds; | ||
// extraStr.format(L"%d:%d (%g fps) %hs", mins, secs, fps, header.desyncGame?"OOS ":""); | ||
// | ||
// for (Int i=0; i<MAX_SLOTS; ++i) | ||
// { | ||
// const GameSlot *slot = info.getConstSlot(i); | ||
// if (slot && slot->isHuman()) | ||
// { | ||
// if (i) | ||
// extraStr.concat(L", "); | ||
// if (header.playerDiscons[i]) | ||
// extraStr.concat(L'*'); | ||
// extraStr.concat(info.getConstSlot(i)->getName()); | ||
// } | ||
// } | ||
// } | ||
// else | ||
// { | ||
// // solo game | ||
// time_t totalSeconds = header.endTime - header.startTime; | ||
// Int mins = totalSeconds/60; | ||
// Int secs = totalSeconds%60; | ||
// Real fps = header.frameDuration/totalSeconds; | ||
// extraStr.format(L"%d:%d (%g fps)", mins, secs, fps); | ||
// } | ||
|
||
// pick a color | ||
Color color; | ||
if (header.versionString == TheVersion->getUnicodeVersion() && header.versionNumber == TheVersion->getVersionNumber() && | ||
header.exeCRC == TheGlobalData->m_exeCRC && header.iniCRC == TheGlobalData->m_iniCRC) | ||
} | ||
else | ||
{ | ||
// bad version | ||
if (header.localPlayerIndex >= 0) | ||
{ | ||
// good version | ||
if (header.localPlayerIndex >= 0) | ||
{ | ||
// MP | ||
color = colors[COLOR_MP]; | ||
} | ||
else | ||
{ | ||
// SP | ||
color = colors[COLOR_SP]; | ||
} | ||
// MP | ||
color = colors[COLOR_MP_CRC_MISMATCH]; | ||
} | ||
else | ||
{ | ||
// bad version | ||
if (header.localPlayerIndex >= 0) | ||
{ | ||
// MP | ||
color = colors[COLOR_MP_CRC_MISMATCH]; | ||
} | ||
else | ||
{ | ||
// SP | ||
color = colors[COLOR_SP_CRC_MISMATCH]; | ||
} | ||
// SP | ||
color = colors[COLOR_SP_CRC_MISMATCH]; | ||
} | ||
|
||
Int insertionIndex = GadgetListBoxAddEntryText(listbox, replayNameToShow, color, -1, 0); | ||
GadgetListBoxAddEntryText(listbox, displayTimeBuffer, color, insertionIndex, 1); | ||
GadgetListBoxAddEntryText(listbox, header.versionString, color, insertionIndex, 2); | ||
GadgetListBoxAddEntryText(listbox, mapStr, color, insertionIndex, 3); | ||
//GadgetListBoxAddEntryText(listbox, extraStr, color, insertionIndex, 4); | ||
} | ||
|
||
Int insertionIndex = GadgetListBoxAddEntryText(listbox, replayNameToShow, color, -1, 0); | ||
if (insertionIndex == -1) | ||
{ | ||
// The list originally has a maximum length of 100. If we fail here we probably | ||
// exceeded that and just double the max here and try again. | ||
Int length = GadgetListBoxGetNumEntries(listbox); | ||
GadgetListBoxSetListLength(listbox, length * 2); | ||
|
||
insertionIndex = GadgetListBoxAddEntryText(listbox, replayNameToShow, color, -1, 0); | ||
} | ||
GadgetListBoxAddEntryText(listbox, displayTimeBuffer, color, insertionIndex, 1); | ||
GadgetListBoxAddEntryText(listbox, header.versionString, color, insertionIndex, 2); | ||
GadgetListBoxAddEntryText(listbox, mapStr, md ? color : colors[COLOR_MAP_NOT_PRESENT], insertionIndex, 3); | ||
//GadgetListBoxAddEntryText(listbox, extraStr, color, insertionIndex, 4); | ||
} | ||
} | ||
GadgetListBoxSetSelected(listbox, 0); | ||
|
@@ -495,11 +521,26 @@ WindowMsgHandledType ReplayMenuSystem( GameWindow *window, UnsignedInt msg, | |
|
||
AsciiString asciiFilename; | ||
asciiFilename.translate(filename); | ||
TheRecorder->playbackFile(asciiFilename); | ||
|
||
if(parentReplayMenu != NULL) | ||
const MapMetaData *md; | ||
Bool success = GetMapInfo(asciiFilename, NULL, NULL, &md); | ||
|
||
if(!success || md == NULL) | ||
{ | ||
parentReplayMenu->winHide(TRUE); | ||
MessageBoxOk(UnicodeString(L"MAP NOT FOUND"), UnicodeString(L"This replay cannot be loaded because the map is not present."), NULL); | ||
} | ||
else if(TheRecorder->testVersionPlayback(asciiFilename)) | ||
{ | ||
MessageBoxOkCancel(TheGameText->fetch("GUI:OlderReplayVersionTitle"), TheGameText->fetch("GUI:OlderReplayVersion"),reallyLoadReplay ,NULL); | ||
} | ||
else | ||
{ | ||
TheRecorder->playbackFile(asciiFilename); | ||
|
||
if(parentReplayMenu != NULL) | ||
{ | ||
parentReplayMenu->winHide(TRUE); | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -557,7 +598,14 @@ WindowMsgHandledType ReplayMenuSystem( GameWindow *window, UnsignedInt msg, | |
AsciiString asciiFilename; | ||
asciiFilename.translate(filename); | ||
|
||
if(TheRecorder->testVersionPlayback(asciiFilename)) | ||
const MapMetaData *md; | ||
Bool success = GetMapInfo(asciiFilename, NULL, NULL, &md); | ||
|
||
if(!success || md == NULL) | ||
{ | ||
MessageBoxOk(UnicodeString(L"MAP NOT FOUND"), UnicodeString(L"This replay cannot be loaded because the map is not present."), NULL); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New strings should be defined strings editable in CSF or STR, not hard-coded. |
||
} | ||
else if(TheRecorder->testVersionPlayback(asciiFilename)) | ||
{ | ||
MessageBoxOkCancel(TheGameText->fetch("GUI:OlderReplayVersionTitle"), TheGameText->fetch("GUI:OlderReplayVersion"),reallyLoadReplay ,NULL); | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto