Skip to content

Commit 8aa90e2

Browse files
authored
Merge pull request #458 from MrS-ibra/feat/quickmatch-map-hover-preview
feat(quickmatch): Add map hover preview on quickmatch map select listbox
2 parents 6ba5480 + b2ba171 commit 8aa90e2

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "GameClient/Gadget.h"
4343
#include "GameClient/GameText.h"
4444
#include "GameClient/InGameUI.h"
45+
#include "GameClient/Display.h"
4546
#include "GameClient/Shell.h"
4647
#include "GameClient/ShellHooks.h"
4748
#include "GameClient/KeyDefs.h"
@@ -142,6 +143,8 @@ static Bool raiseMessageBoxes = false;
142143
static Bool isInInit = FALSE;
143144
static const Image *selectedImage = nullptr;
144145
static const Image *unselectedImage = nullptr;
146+
static const Image *mapHoverPreview = nullptr;
147+
static GameWinDrawFunc mapListboxPreviewFunc = nullptr;
145148

146149
static bool isPopulatingLadderBox = false;
147150
static Int maxPingEntries = 0;
@@ -237,7 +240,41 @@ enum{ MAX_DISCONNECTS_COUNT = 5 };
237240
static Int MAX_DISCONNECTS[MAX_DISCONNECTS_COUNT] = {MAX_DISCONNECTS_ANY, MAX_DISCONNECTS_5,
238241
MAX_DISCONNECTS_10, MAX_DISCONNECTS_25,
239242
MAX_DISCONNECTS_50};
243+
void updateMapHoverPreview(GameWindow* window, WinInstanceData* instData)
244+
{
245+
if (mapListboxPreviewFunc)
246+
mapListboxPreviewFunc(window, instData);
247+
if (listboxMapSelect == nullptr)
248+
return;
249+
250+
const MouseIO* mouseStatus = TheMouse->getMouseStatus();
251+
Int mouseX = mouseStatus->pos.x;
252+
Int mouseY = mouseStatus->pos.y;
253+
Int listboxX, listboxY, listboxW, listboxH;
254+
listboxMapSelect->winGetScreenPosition(&listboxX, &listboxY);
255+
listboxMapSelect->winGetSize(&listboxW, &listboxH);
240256

257+
// mouse is outside the listbox?
258+
if (mouseX < listboxX || mouseX > listboxX + listboxW || mouseY < listboxY || mouseY > listboxY + listboxH)
259+
return;
260+
261+
Int hoveredRow, col;
262+
GadgetListBoxGetEntryBasedOnXY(listboxMapSelect, mouseX, mouseY, hoveredRow, col);
263+
const MapMetaData* mapData = (const MapMetaData*)GadgetListBoxGetItemData(listboxMapSelect, hoveredRow, 1);
264+
mapHoverPreview = mapData ? getMapPreviewImage(mapData->m_fileName) : nullptr;
265+
266+
if (mapHoverPreview == nullptr)
267+
return;
268+
269+
Real wScale = TheDisplay->getWidth() / (Real)DEFAULT_DISPLAY_WIDTH;
270+
Real hScale = TheDisplay->getHeight() / (Real)DEFAULT_DISPLAY_HEIGHT;
271+
Real scale = (wScale + hScale) * 0.5f;
272+
Int previewSize = (Int)(50 * scale);
273+
Int offset = (Int)(20 * scale);
274+
Int previewX = mouseX + offset;
275+
Int previewY = mouseY - (previewSize / 2);
276+
TheWindowManager->winDrawImage(mapHoverPreview, previewX, previewY, previewX + previewSize, previewY + previewSize);
277+
}
241278

242279
void UpdateStartButton()
243280
{
@@ -903,6 +940,11 @@ void WOLQuickMatchMenuInit( WindowLayout *layout, void *userData )
903940
buttonWiden = TheWindowManager->winGetWindowFromId( parentWOLQuickMatch, buttonWidenID);
904941
quickmatchTextWindow = TheWindowManager->winGetWindowFromId( parentWOLQuickMatch, listboxQuickMatchID);
905942
listboxMapSelect = TheWindowManager->winGetWindowFromId( parentWOLQuickMatch, listboxMapSelectID);
943+
if (listboxMapSelect)
944+
{
945+
mapListboxPreviewFunc = listboxMapSelect->winGetDrawFunc();
946+
listboxMapSelect->winSetDrawFunc(updateMapHoverPreview);
947+
}
906948
//textEntryMaxDisconnects = TheWindowManager->winGetWindowFromId( parentWOLQuickMatch, textEntryMaxDisconnectsID );
907949
//textEntryMaxPoints = TheWindowManager->winGetWindowFromId( parentWOLQuickMatch, textEntryMaxPointsID );
908950
//textEntryMinPoints = TheWindowManager->winGetWindowFromId( parentWOLQuickMatch, textEntryMinPointsID );

0 commit comments

Comments
 (0)