Skip to content

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
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
//-------------------------------------------------------------------------------------------------
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

}
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);
}
}
}
}
Expand Down Expand Up @@ -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);

Choose a reason for hiding this comment

The 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);
}
Expand Down