Skip to content

Commit

Permalink
add submenus for manufacturers when list becomes long (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamiras authored Nov 17, 2022
1 parent dd52c1d commit a3d3d76
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 17 deletions.
72 changes: 55 additions & 17 deletions src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1823,6 +1823,25 @@ void Application::aboutDialog()
::aboutDialog(_logger.contents().c_str());
}

static void buildSystemMenu(HMENU parentMenu, int system, std::string systemName)
{
std::set<std::string> systemCores;
getAvailableSystemCores(system, systemCores);

std::map<std::string, int> systemItems;
for (const auto& systemCore : systemCores)
{
int id = encodeCoreName(systemCore, system);
systemItems.emplace(getEmulatorName(systemCore, system), id);
}

HMENU systemMenu = CreateMenu();
for (const auto& systemItem : systemItems)
AppendMenu(systemMenu, MF_STRING, IDM_SYSTEM_FIRST + systemItem.second, systemItem.first.c_str());

AppendMenu(parentMenu, MF_POPUP | MF_STRING, (UINT_PTR)systemMenu, systemName.c_str());
}

void Application::buildSystemsMenu()
{
std::set<int> availableSystems;
Expand All @@ -1833,36 +1852,55 @@ void Application::buildSystemsMenu()
// use map to sort labels
std::set<std::string> systemCores;
std::map<std::string, int> systemMap;
std::map<std::string, int> systemItems;

for (auto system : availableSystems)
systemMap.emplace(getSystemName(system), system);
{
systemCores.clear();
getAvailableSystemCores(system, systemCores);
if (!systemCores.empty())
systemMap.emplace(getSystemName(system), system);
}

HMENU fileMenu = GetSubMenu(_menu, 0);
HMENU systemsMenu = GetSubMenu(fileMenu, 0);

while (GetMenuItemCount(systemsMenu) > 0)
DeleteMenu(systemsMenu, 0, MF_BYPOSITION);

for (const auto& pair : systemMap)
if (systemMap.size() > 20)
{
int system = pair.second;
systemCores.clear();
getAvailableSystemCores(system, systemCores);
if (systemCores.empty())
continue;

systemItems.clear();
for (const auto& systemCore : systemCores)
std::map<std::string, std::vector<int>> manufacturerMap;
for (const auto& pair : systemMap)
{
int id = encodeCoreName(systemCore, pair.second);
systemItems.emplace(getEmulatorName(systemCore, system), id);
int system = pair.second;
std::string manufacturer = getSystemManufacturer(system);
manufacturerMap[manufacturer].push_back(system);
}

HMENU systemMenu = CreateMenu();
for (const auto& systemItem : systemItems)
AppendMenu(systemMenu, MF_STRING, IDM_SYSTEM_FIRST + systemItem.second, systemItem.first.c_str());
for (const auto& pair : manufacturerMap)
{
HMENU manufacturerMenu = CreateMenu();

for (const auto& systemPair : systemMap)
{
int system = systemPair.second;
for (const auto manufacturerSystem : pair.second)
{
if (manufacturerSystem == system)
{
buildSystemMenu(manufacturerMenu, system, systemPair.first);
break;
}
}
}

AppendMenu(systemsMenu, MF_POPUP | MF_STRING, (UINT_PTR)systemMenu, pair.first.c_str());
AppendMenu(systemsMenu, MF_POPUP | MF_STRING, (UINT_PTR)manufacturerMenu, pair.first.c_str());
}
}
else
{
for (const auto& pair : systemMap)
buildSystemMenu(systemsMenu, pair.second, pair.first);
}
}

Expand Down
56 changes: 56 additions & 0 deletions src/Emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,62 @@ const char* getSystemName(int system)
return rc_console_name(system);
}

const char* getSystemManufacturer(int system)
{
switch (system)
{
case RC_CONSOLE_GAMEBOY:
case RC_CONSOLE_GAMEBOY_COLOR:
case RC_CONSOLE_GAMEBOY_ADVANCE:
case RC_CONSOLE_NINTENDO:
case RC_CONSOLE_SUPER_NINTENDO:
case RC_CONSOLE_NINTENDO_64:
case RC_CONSOLE_NINTENDO_DS:
case RC_CONSOLE_NINTENDO_3DS:
case RC_CONSOLE_POKEMON_MINI:
case RC_CONSOLE_VIRTUAL_BOY:
case RC_CONSOLE_WII:
case RC_CONSOLE_WII_U:
return "Nintendo";

case RC_CONSOLE_PLAYSTATION:
case RC_CONSOLE_PLAYSTATION_2:
case RC_CONSOLE_PSP:
return "Sony";

case RC_CONSOLE_ATARI_2600:
case RC_CONSOLE_ATARI_5200:
case RC_CONSOLE_ATARI_7800:
case RC_CONSOLE_ATARI_JAGUAR:
case RC_CONSOLE_ATARI_JAGUAR_CD:
case RC_CONSOLE_ATARI_LYNX:
case RC_CONSOLE_ATARI_ST:
return "Atari";

case RC_CONSOLE_PC_ENGINE:
case RC_CONSOLE_PC_ENGINE_CD:
case RC_CONSOLE_PC6000:
case RC_CONSOLE_PC8800:
case RC_CONSOLE_PC9800:
case RC_CONSOLE_PCFX:
return "NEC";

case RC_CONSOLE_SG1000:
case RC_CONSOLE_MASTER_SYSTEM:
case RC_CONSOLE_GAME_GEAR:
case RC_CONSOLE_MEGA_DRIVE:
case RC_CONSOLE_PICO:
case RC_CONSOLE_SEGA_32X:
case RC_CONSOLE_SEGA_CD:
case RC_CONSOLE_SATURN:
case RC_CONSOLE_DREAMCAST:
return "Sega";

default:
return "Other";
}
}

#ifdef _WINDOWS

class CoreDialog : public Dialog
Expand Down
1 change: 1 addition & 0 deletions src/Emulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ along with RALibretro. If not, see <http://www.gnu.org/licenses/>.
const std::string& getEmulatorName(const std::string& coreName, int system);
const char* getEmulatorExtensions(const std::string& coreName, int system);
const char* getSystemName(int system);
const char* getSystemManufacturer(int system);

class Config;
class Logger;
Expand Down

0 comments on commit a3d3d76

Please sign in to comment.