Skip to content

Commit fc2ffd1

Browse files
xezonhelmutbuhler
andcommitted
[GEN][ZH] Move Replay Map info related code from PopulateReplayFileListbox to new function (#992)
Co-authored-by: Helmut Buhler <buhler@8gadgetpack.net>
1 parent 10b1f2c commit fc2ffd1

File tree

2 files changed

+282
-198
lines changed
  • GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus
  • Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus

2 files changed

+282
-198
lines changed

Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ReplayMenu.cpp

Lines changed: 141 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,75 @@ UnicodeString GetReplayFilenameFromListbox(GameWindow *listbox, Int index)
102102
return fname;
103103
}
104104

105+
//-------------------------------------------------------------------------------------------------
106+
107+
static Bool readReplayMapInfo(const AsciiString& filename, RecorderClass::ReplayHeader &header, ReplayGameInfo &info, const MapMetaData *&mapData)
108+
{
109+
header.forPlayback = FALSE;
110+
header.filename = filename;
111+
112+
if (TheRecorder != NULL && TheRecorder->readReplayHeader(header))
113+
{
114+
if (ParseAsciiStringToGameInfo(&info, header.gameOptions))
115+
{
116+
if (TheMapCache != NULL)
117+
mapData = TheMapCache->findMap(info.getMap());
118+
else
119+
mapData = NULL;
120+
121+
return true;
122+
}
123+
}
124+
return false;
125+
}
126+
127+
//-------------------------------------------------------------------------------------------------
128+
129+
static void removeReplayExtension(UnicodeString& replayName)
130+
{
131+
const Int extensionLength = TheRecorder->getReplayExtention().getLength();
132+
for (Int k=0; k < extensionLength; ++k)
133+
replayName.removeLastChar();
134+
}
135+
136+
//-------------------------------------------------------------------------------------------------
137+
138+
static UnicodeString createReplayName(const AsciiString& filename)
139+
{
140+
AsciiString lastReplayFName = TheRecorder->getLastReplayFileName();
141+
lastReplayFName.concat(TheRecorder->getReplayExtention());
142+
UnicodeString replayName;
143+
144+
if (lastReplayFName.compareNoCase(filename) == 0)
145+
{
146+
replayName = TheGameText->fetch("GUI:LastReplay");
147+
}
148+
else
149+
{
150+
replayName.translate(filename);
151+
removeReplayExtension(replayName);
152+
}
153+
return replayName;
154+
}
155+
156+
//-------------------------------------------------------------------------------------------------
157+
158+
static UnicodeString createMapName(const AsciiString& filename, const ReplayGameInfo& info, const MapMetaData *mapData)
159+
{
160+
UnicodeString mapName;
161+
if (!mapData)
162+
{
163+
// TheSuperHackers @bugfix helmutbuhler 08/03/2025 Just use the filename.
164+
// Displaying a long map path string would break the map list gui.
165+
const char* filename = info.getMap().reverseFind('\\');
166+
mapName.translate(filename ? filename + 1 : info.getMap());
167+
}
168+
else
169+
{
170+
mapName = mapData->m_displayName;
171+
}
172+
return mapName;
173+
}
105174

106175
//-------------------------------------------------------------------------------------------------
107176
/** Populate the listbox with the names of the available replay files */
@@ -145,124 +214,97 @@ void PopulateReplayFileListbox(GameWindow *listbox)
145214
// just want the filename
146215
asciistr.set((*it).reverseFind('\\') + 1);
147216

148-
// lets get some info about the replay
149217
RecorderClass::ReplayHeader header;
150-
header.forPlayback = FALSE;
151-
header.filename = asciistr;
152-
Bool success = TheRecorder && TheMapCache && TheRecorder->readReplayHeader( header );
153-
if (success)
154-
{
155-
ReplayGameInfo info;
156-
if (ParseAsciiStringToGameInfo( &info, header.gameOptions ))
157-
{
218+
ReplayGameInfo info;
219+
const MapMetaData *mapData;
158220

159-
// columns are: name, date, version, map, extra
160-
161-
// name
162-
header.replayName.translate(asciistr);
163-
for (Int tmp=0; tmp < TheRecorder->getReplayExtention().getLength(); ++tmp)
164-
header.replayName.removeLastChar();
221+
if (readReplayMapInfo(asciistr, header, info, mapData))
222+
{
223+
// columns are: name, date, version, map, extra
165224

166-
UnicodeString replayNameToShow = header.replayName;
225+
// name
226+
UnicodeString replayNameToShow = createReplayName(asciistr);
167227

168-
AsciiString lastReplayFName = TheRecorder->getLastReplayFileName();
169-
lastReplayFName.concat(TheRecorder->getReplayExtention());
170-
if (lastReplayFName.compareNoCase(asciistr) == 0)
171-
replayNameToShow = TheGameText->fetch("GUI:LastReplay");
228+
UnicodeString displayTimeBuffer = getUnicodeTimeBuffer(header.timeVal);
172229

173-
UnicodeString displayTimeBuffer = getUnicodeTimeBuffer(header.timeVal);
230+
//displayTimeBuffer.format( L"%ls", timeBuffer);
174231

175-
//displayTimeBuffer.format( L"%ls", timeBuffer);
232+
// version (no-op)
176233

177-
// version (no-op)
234+
// map
235+
UnicodeString mapStr = createMapName(asciistr, info, mapData);
178236

179-
// map
180-
UnicodeString mapStr;
181-
const MapMetaData *md = TheMapCache->findMap(info.getMap());
182-
if (!md)
237+
// // extra
238+
// UnicodeString extraStr;
239+
// if (header.localPlayerIndex >= 0)
240+
// {
241+
// // MP game
242+
// time_t totalSeconds = header.endTime - header.startTime;
243+
// Int mins = totalSeconds/60;
244+
// Int secs = totalSeconds%60;
245+
// Real fps = header.frameDuration/totalSeconds;
246+
// extraStr.format(L"%d:%d (%g fps) %hs", mins, secs, fps, header.desyncGame?"OOS ":"");
247+
//
248+
// for (Int i=0; i<MAX_SLOTS; ++i)
249+
// {
250+
// const GameSlot *slot = info.getConstSlot(i);
251+
// if (slot && slot->isHuman())
252+
// {
253+
// if (i)
254+
// extraStr.concat(L", ");
255+
// if (header.playerDiscons[i])
256+
// extraStr.concat(L'*');
257+
// extraStr.concat(info.getConstSlot(i)->getName());
258+
// }
259+
// }
260+
// }
261+
// else
262+
// {
263+
// // solo game
264+
// time_t totalSeconds = header.endTime - header.startTime;
265+
// Int mins = totalSeconds/60;
266+
// Int secs = totalSeconds%60;
267+
// Real fps = header.frameDuration/totalSeconds;
268+
// extraStr.format(L"%d:%d (%g fps)", mins, secs, fps);
269+
// }
270+
271+
// pick a color
272+
Color color;
273+
if (header.versionString == TheVersion->getUnicodeVersion() && header.versionNumber == TheVersion->getVersionNumber() &&
274+
header.exeCRC == TheGlobalData->m_exeCRC && header.iniCRC == TheGlobalData->m_iniCRC)
275+
{
276+
// good version
277+
if (header.localPlayerIndex >= 0)
183278
{
184-
// TheSuperHackers @bugfix helmutbuhler 08/03/2025 Just use the filename.
185-
// Displaying a long map path string would break the map list gui.
186-
const char* filename = info.getMap().reverseFind('\\');
187-
mapStr.translate(filename ? filename + 1 : info.getMap());
279+
// MP
280+
color = colors[COLOR_MP];
188281
}
189282
else
190283
{
191-
mapStr = md->m_displayName;
284+
// SP
285+
color = colors[COLOR_SP];
192286
}
193-
194-
// // extra
195-
// UnicodeString extraStr;
196-
// if (header.localPlayerIndex >= 0)
197-
// {
198-
// // MP game
199-
// time_t totalSeconds = header.endTime - header.startTime;
200-
// Int mins = totalSeconds/60;
201-
// Int secs = totalSeconds%60;
202-
// Real fps = header.frameDuration/totalSeconds;
203-
// extraStr.format(L"%d:%d (%g fps) %hs", mins, secs, fps, header.desyncGame?"OOS ":"");
204-
//
205-
// for (Int i=0; i<MAX_SLOTS; ++i)
206-
// {
207-
// const GameSlot *slot = info.getConstSlot(i);
208-
// if (slot && slot->isHuman())
209-
// {
210-
// if (i)
211-
// extraStr.concat(L", ");
212-
// if (header.playerDiscons[i])
213-
// extraStr.concat(L'*');
214-
// extraStr.concat(info.getConstSlot(i)->getName());
215-
// }
216-
// }
217-
// }
218-
// else
219-
// {
220-
// // solo game
221-
// time_t totalSeconds = header.endTime - header.startTime;
222-
// Int mins = totalSeconds/60;
223-
// Int secs = totalSeconds%60;
224-
// Real fps = header.frameDuration/totalSeconds;
225-
// extraStr.format(L"%d:%d (%g fps)", mins, secs, fps);
226-
// }
227-
228-
// pick a color
229-
Color color;
230-
if (header.versionString == TheVersion->getUnicodeVersion() && header.versionNumber == TheVersion->getVersionNumber() &&
231-
header.exeCRC == TheGlobalData->m_exeCRC && header.iniCRC == TheGlobalData->m_iniCRC)
287+
}
288+
else
289+
{
290+
// bad version
291+
if (header.localPlayerIndex >= 0)
232292
{
233-
// good version
234-
if (header.localPlayerIndex >= 0)
235-
{
236-
// MP
237-
color = colors[COLOR_MP];
238-
}
239-
else
240-
{
241-
// SP
242-
color = colors[COLOR_SP];
243-
}
293+
// MP
294+
color = colors[COLOR_MP_CRC_MISMATCH];
244295
}
245296
else
246297
{
247-
// bad version
248-
if (header.localPlayerIndex >= 0)
249-
{
250-
// MP
251-
color = colors[COLOR_MP_CRC_MISMATCH];
252-
}
253-
else
254-
{
255-
// SP
256-
color = colors[COLOR_SP_CRC_MISMATCH];
257-
}
298+
// SP
299+
color = colors[COLOR_SP_CRC_MISMATCH];
258300
}
259-
260-
Int insertionIndex = GadgetListBoxAddEntryText(listbox, replayNameToShow, color, -1, 0);
261-
GadgetListBoxAddEntryText(listbox, displayTimeBuffer, color, insertionIndex, 1);
262-
GadgetListBoxAddEntryText(listbox, header.versionString, color, insertionIndex, 2);
263-
GadgetListBoxAddEntryText(listbox, mapStr, color, insertionIndex, 3);
264-
//GadgetListBoxAddEntryText(listbox, extraStr, color, insertionIndex, 4);
265301
}
302+
303+
Int insertionIndex = GadgetListBoxAddEntryText(listbox, replayNameToShow, color, -1, 0);
304+
GadgetListBoxAddEntryText(listbox, displayTimeBuffer, color, insertionIndex, 1);
305+
GadgetListBoxAddEntryText(listbox, header.versionString, color, insertionIndex, 2);
306+
GadgetListBoxAddEntryText(listbox, mapStr, color, insertionIndex, 3);
307+
//GadgetListBoxAddEntryText(listbox, extraStr, color, insertionIndex, 4);
266308
}
267309
}
268310
GadgetListBoxSetSelected(listbox, 0);

0 commit comments

Comments
 (0)