Use EnumFormatter to generate names for EXI devices
This simplifies the code in GameCubePane, and allows us to use the EXIDeviceType enum in error messages.
This commit is contained in:
parent
d354163fbe
commit
fefde0481d
|
@ -95,7 +95,6 @@ protected:
|
||||||
|
|
||||||
constexpr explicit EnumFormatter(const array_type names) : m_names(std::move(names)) {}
|
constexpr explicit EnumFormatter(const array_type names) : m_names(std::move(names)) {}
|
||||||
|
|
||||||
private:
|
|
||||||
const array_type m_names;
|
const array_type m_names;
|
||||||
char format_type = 'u';
|
char format_type = 'u';
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,7 +4,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include "Common/Common.h"
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
|
#include "Common/EnumFormatter.h"
|
||||||
|
|
||||||
class PointerWrap;
|
class PointerWrap;
|
||||||
|
|
||||||
|
@ -75,3 +78,50 @@ private:
|
||||||
std::unique_ptr<IEXIDevice> EXIDevice_Create(EXIDeviceType device_type, int channel_num,
|
std::unique_ptr<IEXIDevice> EXIDevice_Create(EXIDeviceType device_type, int channel_num,
|
||||||
const Memcard::HeaderData& memcard_header_data);
|
const Memcard::HeaderData& memcard_header_data);
|
||||||
} // namespace ExpansionInterface
|
} // namespace ExpansionInterface
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct fmt::formatter<ExpansionInterface::EXIDeviceType>
|
||||||
|
: EnumFormatter<ExpansionInterface::EXIDeviceType::EthernetTapServer>
|
||||||
|
{
|
||||||
|
static constexpr array_type names = {
|
||||||
|
_trans("Dummy"),
|
||||||
|
_trans("Memory Card"),
|
||||||
|
_trans("Mask ROM"),
|
||||||
|
// i18n: A mysterious debugging/diagnostics peripheral for the GameCube.
|
||||||
|
_trans("AD16"),
|
||||||
|
_trans("Microphone"),
|
||||||
|
_trans("Broadband Adapter (TAP)"),
|
||||||
|
_trans("Triforce AM Baseboard"),
|
||||||
|
_trans("USB Gecko"),
|
||||||
|
_trans("GCI Folder"),
|
||||||
|
_trans("Advance Game Port"),
|
||||||
|
_trans("Broadband Adapter (XLink Kai)"),
|
||||||
|
_trans("Broadband Adapter (tapserver)"),
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr formatter() : EnumFormatter(names) {}
|
||||||
|
|
||||||
|
template <typename FormatContext>
|
||||||
|
auto format(const ExpansionInterface::EXIDeviceType& e, FormatContext& ctx)
|
||||||
|
{
|
||||||
|
if (e != ExpansionInterface::EXIDeviceType::None)
|
||||||
|
{
|
||||||
|
return EnumFormatter::format(e, ctx);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Special-case None since it has a fixed ID (0xff) that is much larger than the rest; we
|
||||||
|
// don't need 200 nullptr entries in names. We also want to format it specially in the UI.
|
||||||
|
switch (format_type)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
case 'u':
|
||||||
|
return fmt::format_to(ctx.out(), "None");
|
||||||
|
case 's':
|
||||||
|
return fmt::format_to(ctx.out(), "0xffu /* None */");
|
||||||
|
case 'n':
|
||||||
|
return fmt::format_to(ctx.out(), _trans("<Nothing>"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "Common/CommonPaths.h"
|
#include "Common/CommonPaths.h"
|
||||||
|
@ -97,31 +98,28 @@ void GameCubePane::CreateWidgets()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add slot devices
|
// Add slot devices
|
||||||
for (const auto& entry : {std::make_pair(tr("<Nothing>"), EXIDeviceType::None),
|
for (const auto device : {EXIDeviceType::None, EXIDeviceType::Dummy, EXIDeviceType::MemoryCard,
|
||||||
std::make_pair(tr("Dummy"), EXIDeviceType::Dummy),
|
EXIDeviceType::MemoryCardFolder, EXIDeviceType::Gecko,
|
||||||
std::make_pair(tr("Memory Card"), EXIDeviceType::MemoryCard),
|
EXIDeviceType::AGP, EXIDeviceType::Microphone})
|
||||||
std::make_pair(tr("GCI Folder"), EXIDeviceType::MemoryCardFolder),
|
|
||||||
std::make_pair(tr("USB Gecko"), EXIDeviceType::Gecko),
|
|
||||||
std::make_pair(tr("Advance Game Port"), EXIDeviceType::AGP),
|
|
||||||
std::make_pair(tr("Microphone"), EXIDeviceType::Microphone)})
|
|
||||||
{
|
{
|
||||||
m_slot_combos[0]->addItem(entry.first, static_cast<int>(entry.second));
|
const QString name = tr(fmt::format("{:n}", device).c_str());
|
||||||
m_slot_combos[1]->addItem(entry.first, static_cast<int>(entry.second));
|
const int value = static_cast<int>(device);
|
||||||
|
m_slot_combos[0]->addItem(name, value);
|
||||||
|
m_slot_combos[1]->addItem(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add SP1 devices
|
// Add SP1 devices
|
||||||
std::vector<std::pair<QString, EXIDeviceType>> sp1Entries{
|
for (const auto device : {
|
||||||
std::make_pair(tr("<Nothing>"), EXIDeviceType::None),
|
EXIDeviceType::None,
|
||||||
std::make_pair(tr("Dummy"), EXIDeviceType::Dummy),
|
EXIDeviceType::Dummy,
|
||||||
std::make_pair(tr("Broadband Adapter (TAP)"), EXIDeviceType::Ethernet),
|
EXIDeviceType::Ethernet,
|
||||||
std::make_pair(tr("Broadband Adapter (XLink Kai)"), EXIDeviceType::EthernetXLink)};
|
EXIDeviceType::EthernetXLink,
|
||||||
#if defined(__APPLE__)
|
#ifdef __APPLE__
|
||||||
sp1Entries.emplace_back(std::make_pair(tr("Broadband Adapter (tapserver)"),
|
EXIDeviceType::EthernetTapServer,
|
||||||
ExpansionInterface::EXIDeviceType::EthernetTapServer));
|
|
||||||
#endif
|
#endif
|
||||||
for (const auto& entry : sp1Entries)
|
})
|
||||||
{
|
{
|
||||||
m_slot_combos[2]->addItem(entry.first, static_cast<int>(entry.second));
|
m_slot_combos[2]->addItem(tr(fmt::format("{:n}", device).c_str()), static_cast<int>(device));
|
||||||
}
|
}
|
||||||
|
|
||||||
device_layout->addWidget(new QLabel(tr("Slot A:")), 0, 0);
|
device_layout->addWidget(new QLabel(tr("Slot A:")), 0, 0);
|
||||||
|
|
Loading…
Reference in New Issue