Skip to content

Commit 9445a43

Browse files
committed
refactor: Improve code clarity
1 parent 9bc0d9c commit 9445a43

File tree

2 files changed

+28
-20
lines changed
  • GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus
  • Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus

2 files changed

+28
-20
lines changed

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@
4949
#include "GameClient/GameText.h"
5050
#include "GameClient/GameWindowTransitions.h"
5151

52-
static std::map<UnicodeString, UnicodeString> replayInfoCache;
52+
typedef UnicodeString ReplayName;
53+
typedef UnicodeString TooltipString;
54+
typedef std::map<ReplayName, TooltipString> ReplayTooltipMap;
55+
56+
static ReplayTooltipMap replayTooltipCache;
5357

5458
// window ids -------------------------------------------------------------------------------------
5559
static NameKeyType parentReplayMenuID = NAMEKEY_INVALID;
@@ -187,16 +191,16 @@ static void showReplayTooltip(GameWindow* window, WinInstanceData* instData, Uns
187191

188192
UnicodeString replayFileName = GetReplayFilenameFromListbox(window, row);
189193

190-
std::map<UnicodeString, UnicodeString>::const_iterator it = replayInfoCache.find(replayFileName);
191-
if (it != replayInfoCache.end())
194+
ReplayTooltipMap::const_iterator it = replayTooltipCache.find(replayFileName);
195+
if (it != replayTooltipCache.end())
192196
TheMouse->setCursorTooltip(it->second, -1, NULL, 1.5f);
193197
else
194198
TheMouse->setCursorTooltip(UnicodeString::TheEmptyString);
195199
}
196200

197201
static UnicodeString buildReplayTooltip(RecorderClass::ReplayHeader header, ReplayGameInfo info)
198202
{
199-
UnicodeString extraStr;
203+
UnicodeString tooltipStr;
200204

201205
if (header.endTime < header.startTime)
202206
header.startTime = header.endTime;
@@ -206,7 +210,7 @@ static UnicodeString buildReplayTooltip(RecorderClass::ReplayHeader header, Repl
206210
UnsignedInt mins = (totalSeconds % 3600) / 60;
207211
UnsignedInt secs = totalSeconds % 60;
208212
Real fps = totalSeconds > 0 ? header.frameCount / totalSeconds : 0;
209-
extraStr.format(L"%02u:%02u:%02u (%g fps)", hours, mins, secs, fps);
213+
tooltipStr.format(L"%02u:%02u:%02u (%g fps)", hours, mins, secs, fps);
210214

211215
if (header.localPlayerIndex >= 0)
212216
{
@@ -216,21 +220,21 @@ static UnicodeString buildReplayTooltip(RecorderClass::ReplayHeader header, Repl
216220
const GameSlot* slot = info.getConstSlot(i);
217221
if (slot && slot->isHuman())
218222
{
219-
extraStr.concat(L"\n");
220-
extraStr.concat(info.getConstSlot(i)->getName());
223+
tooltipStr.concat(L"\n");
224+
tooltipStr.concat(info.getConstSlot(i)->getName());
221225
}
222226
}
223227
}
224228

225-
return extraStr;
229+
return tooltipStr;
226230
}
227231

228232
//-------------------------------------------------------------------------------------------------
229233
/** Populate the listbox with the names of the available replay files */
230234
//-------------------------------------------------------------------------------------------------
231235
void PopulateReplayFileListbox(GameWindow *listbox)
232236
{
233-
replayInfoCache.clear();
237+
replayTooltipCache.clear();
234238

235239
if (!TheMapCache)
236240
return;
@@ -300,7 +304,7 @@ void PopulateReplayFileListbox(GameWindow *listbox)
300304

301305
UnicodeString key;
302306
key.translate(asciistr);
303-
replayInfoCache[key] = extraStr;
307+
replayTooltipCache[key] = extraStr;
304308

305309
// pick a color
306310
Color color;

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@
4949
#include "GameClient/GameText.h"
5050
#include "GameClient/GameWindowTransitions.h"
5151

52-
static std::map<UnicodeString, UnicodeString> replayInfoCache;
52+
typedef UnicodeString ReplayName;
53+
typedef UnicodeString TooltipString;
54+
typedef std::map<ReplayName, TooltipString> ReplayTooltipMap;
55+
56+
static ReplayTooltipMap replayTooltipCache;
5357

5458
// window ids -------------------------------------------------------------------------------------
5559
static NameKeyType parentReplayMenuID = NAMEKEY_INVALID;
@@ -187,16 +191,16 @@ static void showReplayTooltip(GameWindow* window, WinInstanceData* instData, Uns
187191

188192
UnicodeString replayFileName = GetReplayFilenameFromListbox(window, row);
189193

190-
std::map<UnicodeString, UnicodeString>::const_iterator it = replayInfoCache.find(replayFileName);
191-
if (it != replayInfoCache.end())
194+
ReplayTooltipMap::const_iterator it = replayTooltipCache.find(replayFileName);
195+
if (it != replayTooltipCache.end())
192196
TheMouse->setCursorTooltip(it->second, -1, NULL, 1.5f);
193197
else
194198
TheMouse->setCursorTooltip(UnicodeString::TheEmptyString);
195199
}
196200

197201
static UnicodeString buildReplayTooltip(RecorderClass::ReplayHeader header, ReplayGameInfo info)
198202
{
199-
UnicodeString extraStr;
203+
UnicodeString tooltipStr;
200204

201205
if (header.endTime < header.startTime)
202206
header.startTime = header.endTime;
@@ -206,7 +210,7 @@ static UnicodeString buildReplayTooltip(RecorderClass::ReplayHeader header, Repl
206210
UnsignedInt mins = (totalSeconds % 3600) / 60;
207211
UnsignedInt secs = totalSeconds % 60;
208212
Real fps = totalSeconds > 0 ? header.frameCount / totalSeconds : 0;
209-
extraStr.format(L"%02u:%02u:%02u (%g fps)", hours, mins, secs, fps);
213+
tooltipStr.format(L"%02u:%02u:%02u (%g fps)", hours, mins, secs, fps);
210214

211215
if (header.localPlayerIndex >= 0)
212216
{
@@ -216,21 +220,21 @@ static UnicodeString buildReplayTooltip(RecorderClass::ReplayHeader header, Repl
216220
const GameSlot* slot = info.getConstSlot(i);
217221
if (slot && slot->isHuman())
218222
{
219-
extraStr.concat(L"\n");
220-
extraStr.concat(info.getConstSlot(i)->getName());
223+
tooltipStr.concat(L"\n");
224+
tooltipStr.concat(info.getConstSlot(i)->getName());
221225
}
222226
}
223227
}
224228

225-
return extraStr;
229+
return tooltipStr;
226230
}
227231

228232
//-------------------------------------------------------------------------------------------------
229233
/** Populate the listbox with the names of the available replay files */
230234
//-------------------------------------------------------------------------------------------------
231235
void PopulateReplayFileListbox(GameWindow *listbox)
232236
{
233-
replayInfoCache.clear();
237+
replayTooltipCache.clear();
234238

235239
if (!TheMapCache)
236240
return;
@@ -300,7 +304,7 @@ void PopulateReplayFileListbox(GameWindow *listbox)
300304

301305
UnicodeString key;
302306
key.translate(asciistr);
303-
replayInfoCache[key] = extraStr;
307+
replayTooltipCache[key] = extraStr;
304308

305309
// pick a color
306310
Color color;

0 commit comments

Comments
 (0)