Qt: Refactor GB names and lists into namespace

This commit is contained in:
Vicki Pfau 2020-08-28 01:49:07 -07:00
parent f5a1ceb025
commit ddc913c13a
9 changed files with 183 additions and 238 deletions

View File

@ -16,7 +16,7 @@ if(BUILD_SDL)
endif()
if(POLICY CMP0071)
cmake_policy(SET CMP0071 OLD)
cmake_policy(SET CMP0071 NEW)
endif()
set(CMAKE_AUTOMOC ON)
@ -154,6 +154,7 @@ set(GBA_SRC
GBAOverride.cpp)
set(GB_SRC
GameBoy.cpp
GBOverride.cpp
PrinterView.cpp)

View File

@ -0,0 +1,94 @@
/* Copyright (c) 2013-2020 Jeffrey Pfau
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "GameBoy.h"
#include <QCoreApplication>
#include <QMap>
using namespace QGBA;
static const QList<GBModel> s_gbModelList{
GB_MODEL_DMG,
GB_MODEL_SGB,
GB_MODEL_CGB,
GB_MODEL_AGB,
};
static const QList<GBMemoryBankControllerType> s_mbcList{
GB_MBC_NONE,
GB_MBC1,
GB_MBC2,
GB_MBC3,
GB_MBC3_RTC,
GB_MBC5,
GB_MBC5_RUMBLE,
GB_MBC6,
GB_MBC7,
GB_MMM01,
GB_POCKETCAM,
GB_TAMA5,
GB_HuC1,
GB_HuC3,
GB_UNL_WISDOM_TREE,
GB_UNL_BBD,
GB_UNL_HITEK,
GB_UNL_PKJD,
};
static QMap<GBModel, QString> s_gbModelNames;
static QMap<GBMemoryBankControllerType, QString> s_mbcNames;
static QString tr(const char* str) {
return QCoreApplication::translate("Game Boy", str);
}
QList<GBModel> GameBoy::modelList() {
return s_gbModelList;
}
QString GameBoy::modelName(GBModel model) {
if (s_gbModelNames.isEmpty()) {
s_gbModelNames[GB_MODEL_AUTODETECT] = tr("Autodetect");
s_gbModelNames[GB_MODEL_DMG] = tr("Game Boy (DMG)");
s_gbModelNames[GB_MODEL_MGB] = tr("Game Boy Pocket (MGB)");
s_gbModelNames[GB_MODEL_SGB] = tr("Super Game Boy (SGB)");
s_gbModelNames[GB_MODEL_SGB2] = tr("Super Game Boy 2 (SGB)");
s_gbModelNames[GB_MODEL_CGB] = tr("Game Boy Color (CGB)");
s_gbModelNames[GB_MODEL_AGB] = tr("Game Boy Advance (AGB)");
}
return s_gbModelNames[model];
}
QList<GBMemoryBankControllerType> GameBoy::mbcList() {
return s_mbcList;
}
QString GameBoy::mbcName(GBMemoryBankControllerType mbc) {
if (s_mbcNames.isEmpty()) {
s_mbcNames[GB_MBC_AUTODETECT] = tr("Autodetect");
s_mbcNames[GB_MBC_NONE] = tr("ROM Only");
s_mbcNames[GB_MBC1] = tr("MBC1");
s_mbcNames[GB_MBC2] = tr("MBC2");
s_mbcNames[GB_MBC3] = tr("MBC3");
s_mbcNames[GB_MBC3_RTC] = tr("MBC3 + RTC");
s_mbcNames[GB_MBC5] = tr("MBC5");
s_mbcNames[GB_MBC5_RUMBLE] = tr("MBC5 + Rumble");
s_mbcNames[GB_MBC6] = tr("MBC6");
s_mbcNames[GB_MBC7] = tr("MBC7 (Tilt)");
s_mbcNames[GB_MMM01] = tr("MMM01");
s_mbcNames[GB_HuC1] = tr("HuC-1");
s_mbcNames[GB_HuC3] = tr("HuC-3");
s_mbcNames[GB_POCKETCAM] = tr("Pocket Cam");
s_mbcNames[GB_TAMA5] = tr("TAMA5");
s_mbcNames[GB_UNL_WISDOM_TREE] = tr("Wisdom Tree");
s_mbcNames[GB_UNL_PKJD] = tr("Pokémon Jade/Diamond");
s_mbcNames[GB_UNL_BBD] = tr("BBD");
s_mbcNames[GB_UNL_HITEK] = tr("Hitek");
}
return s_mbcNames[mbc];
}

25
src/platform/qt/GameBoy.h Normal file
View File

@ -0,0 +1,25 @@
/* Copyright (c) 2013-2020 Jeffrey Pfau
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#pragma once
#include <QList>
#include <QString>
#ifdef M_CORE_GB
#include <mgba/gb/interface.h>
namespace QGBA {
namespace GameBoy {
QList<GBModel> modelList();
QString modelName(GBModel);
QList<GBMemoryBankControllerType> mbcList();
QString mbcName(GBMemoryBankControllerType);
}
}
#endif

View File

@ -6,6 +6,7 @@
#include "OverrideView.h"
#include <QPushButton>
#include <QStandardItemModel>
#include "ConfigController.h"
#include "CoreController.h"
@ -16,53 +17,17 @@
#endif
#ifdef M_CORE_GB
#include "GameBoy.h"
#include "GBOverride.h"
#include <mgba/internal/gb/gb.h>
#endif
using namespace QGBA;
#ifdef M_CORE_GB
QList<enum GBModel> OverrideView::s_gbModelList;
QList<enum GBMemoryBankControllerType> OverrideView::s_mbcList;
#endif
OverrideView::OverrideView(ConfigController* config, QWidget* parent)
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint)
, m_config(config)
{
#ifdef M_CORE_GB
if (s_mbcList.isEmpty()) {
// NB: Keep in sync with OverrideView.ui
s_mbcList.append(GB_MBC_AUTODETECT);
s_mbcList.append(GB_MBC_NONE);
s_mbcList.append(GB_MBC1);
s_mbcList.append(GB_MBC2);
s_mbcList.append(GB_MBC3);
s_mbcList.append(GB_MBC3_RTC);
s_mbcList.append(GB_MBC5);
s_mbcList.append(GB_MBC5_RUMBLE);
s_mbcList.append(GB_MBC6);
s_mbcList.append(GB_MBC7);
s_mbcList.append(GB_MMM01);
s_mbcList.append(GB_POCKETCAM);
s_mbcList.append(GB_TAMA5);
s_mbcList.append(GB_HuC1);
s_mbcList.append(GB_HuC3);
s_mbcList.append(GB_UNL_WISDOM_TREE);
s_mbcList.append(GB_UNL_BBD);
s_mbcList.append(GB_UNL_HITEK);
s_mbcList.append(GB_UNL_PKJD);
}
if (s_gbModelList.isEmpty()) {
// NB: Keep in sync with OverrideView.ui
s_gbModelList.append(GB_MODEL_AUTODETECT);
s_gbModelList.append(GB_MODEL_DMG);
s_gbModelList.append(GB_MODEL_SGB);
s_gbModelList.append(GB_MODEL_CGB);
s_gbModelList.append(GB_MODEL_AGB);
}
#endif
m_ui.setupUi(this);
connect(m_ui.hwAutodetect, &QAbstractButton::toggled, [this] (bool enabled) {
@ -74,6 +39,33 @@ OverrideView::OverrideView(ConfigController* config, QWidget* parent)
});
#ifdef M_CORE_GB
m_ui.gbModel->setItemData(0, GB_MODEL_AUTODETECT);
m_ui.mbc->setItemData(0, GB_MBC_AUTODETECT);
for (auto model : GameBoy::modelList()) {
m_ui.gbModel->addItem(GameBoy::modelName(model), model);
}
QStandardItemModel* model = static_cast<QStandardItemModel*>(m_ui.mbc->model());
int bitsSeen = 0;
for (auto mbc : GameBoy::mbcList()) {
int mbcValue = static_cast<int>(mbc);
if ((mbcValue & ~bitsSeen) & 0x001) {
m_ui.mbc->addItem(tr("Official MBCs"), -2);
model->item(m_ui.mbc->count() - 1)->setFlags(Qt::NoItemFlags);
}
if ((mbcValue & ~bitsSeen) & 0x010) {
m_ui.mbc->addItem(tr("Licensed MBCs"), -3);
model->item(m_ui.mbc->count() - 1)->setFlags(Qt::NoItemFlags);
}
if ((mbcValue & ~bitsSeen) & 0x200) {
m_ui.mbc->addItem(tr("Unlicensed MBCs"), -4);
model->item(m_ui.mbc->count() - 1)->setFlags(Qt::NoItemFlags);
}
bitsSeen |= mbcValue;
m_ui.mbc->addItem(GameBoy::mbcName(mbc), mbc);
}
m_colorPickers[0] = ColorPicker(m_ui.color0, QColor(0xF8, 0xF8, 0xF8));
m_colorPickers[1] = ColorPicker(m_ui.color1, QColor(0xA8, 0xA8, 0xA8));
m_colorPickers[2] = ColorPicker(m_ui.color2, QColor(0x50, 0x50, 0x50));
@ -190,8 +182,8 @@ void OverrideView::updateOverrides() {
#ifdef M_CORE_GB
if (m_ui.tabWidget->currentWidget() == m_ui.tabGB) {
std::unique_ptr<GBOverride> gb(new GBOverride);
gb->override.mbc = s_mbcList[m_ui.mbc->currentIndex()];
gb->override.model = s_gbModelList[m_ui.gbModel->currentIndex()];
gb->override.mbc = static_cast<GBMemoryBankControllerType>(m_ui.mbc->currentData().toInt());
gb->override.model = static_cast<GBModel>(m_ui.gbModel->currentData().toInt());
bool hasColor = false;
for (int i = 0; i < 12; ++i) {
gb->override.gbColors[i] = m_gbColors[i];
@ -240,13 +232,13 @@ void OverrideView::gameStarted() {
case PLATFORM_GB: {
m_ui.tabWidget->setCurrentWidget(m_ui.tabGB);
GB* gb = static_cast<GB*>(thread->core->board);
int mbc = s_mbcList.indexOf(gb->memory.mbcType);
if (mbc >= 0) {
m_ui.mbc->setCurrentIndex(mbc);
int index = m_ui.mbc->findData(gb->memory.mbcType);
if (index >= 0) {
m_ui.mbc->setCurrentIndex(index);
} else {
m_ui.mbc->setCurrentIndex(0);
}
int model = s_gbModelList.indexOf(gb->model);
int model = m_ui.gbModel->findData(gb->model);
if (model >= 0) {
m_ui.gbModel->setCurrentIndex(model);
} else {

View File

@ -55,9 +55,6 @@ private:
#ifdef M_CORE_GB
uint32_t m_gbColors[12]{};
ColorPicker m_colorPickers[12];
static QList<enum GBModel> s_gbModelList;
static QList<enum GBMemoryBankControllerType> s_mbcList;
#endif
};

View File

@ -248,26 +248,6 @@
<string>Autodetect</string>
</property>
</item>
<item>
<property name="text">
<string>Game Boy (DMG)</string>
</property>
</item>
<item>
<property name="text">
<string>Super Game Boy (SGB)</string>
</property>
</item>
<item>
<property name="text">
<string>Game Boy Color (CGB)</string>
</property>
</item>
<item>
<property name="text">
<string>Game Boy Advance (AGB)</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
@ -284,96 +264,6 @@
<string>Autodetect</string>
</property>
</item>
<item>
<property name="text">
<string>None</string>
</property>
</item>
<item>
<property name="text">
<string>MBC1</string>
</property>
</item>
<item>
<property name="text">
<string>MBC2</string>
</property>
</item>
<item>
<property name="text">
<string>MBC3</string>
</property>
</item>
<item>
<property name="text">
<string>MBC3 + RTC</string>
</property>
</item>
<item>
<property name="text">
<string>MBC5</string>
</property>
</item>
<item>
<property name="text">
<string>MBC5 + Rumble</string>
</property>
</item>
<item>
<property name="text">
<string>MBC6</string>
</property>
</item>
<item>
<property name="text">
<string>MBC7</string>
</property>
</item>
<item>
<property name="text">
<string>MMM01</string>
</property>
</item>
<item>
<property name="text">
<string>Pocket Cam</string>
</property>
</item>
<item>
<property name="text">
<string>TAMA5</string>
</property>
</item>
<item>
<property name="text">
<string>HuC-1</string>
</property>
</item>
<item>
<property name="text">
<string>HuC-3</string>
</property>
</item>
<item>
<property name="text">
<string>Wisdom Tree (Unlicensed)</string>
</property>
</item>
<item>
<property name="text">
<string>BBD (Unlicensed)</string>
</property>
</item>
<item>
<property name="text">
<string>Hitek (Unlicensed)</string>
</property>
</item>
<item>
<property name="text">
<string>Pokémon Jade/Diamond (Unlicensed)</string>
</property>
</item>
</widget>
</item>
<item row="2" column="0">

View File

@ -15,16 +15,16 @@
#include "ShaderSelector.h"
#include "ShortcutView.h"
#ifdef M_CORE_GB
#include "GameBoy.h"
#endif
#include <mgba/core/serialize.h>
#include <mgba/core/version.h>
#include <mgba/internal/gba/gba.h>
using namespace QGBA;
#ifdef M_CORE_GB
QList<enum GBModel> SettingsView::s_gbModelList;
#endif
SettingsView::SettingsView(ConfigController* controller, InputController* inputController, ShortcutController* shortcutController, LogController* logController, QWidget* parent)
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint)
, m_controller(controller)
@ -33,13 +33,14 @@ SettingsView::SettingsView(ConfigController* controller, InputController* inputC
m_ui.setupUi(this);
#ifdef M_CORE_GB
if (s_gbModelList.isEmpty()) {
// NB: Keep in sync with SettingsView.ui
s_gbModelList.append(GB_MODEL_AUTODETECT);
s_gbModelList.append(GB_MODEL_DMG);
s_gbModelList.append(GB_MODEL_SGB);
s_gbModelList.append(GB_MODEL_CGB);
s_gbModelList.append(GB_MODEL_AGB);
m_ui.gbModel->setItemData(0, GB_MODEL_AUTODETECT);
m_ui.sgbModel->setItemData(0, GB_MODEL_AUTODETECT);
m_ui.cgbModel->setItemData(0, GB_MODEL_AUTODETECT);
for (auto model : GameBoy::modelList()) {
m_ui.gbModel->addItem(GameBoy::modelName(model), model);
m_ui.sgbModel->addItem(GameBoy::modelName(model), model);
m_ui.cgbModel->addItem(GameBoy::modelName(model), model);
}
#endif
@ -511,14 +512,20 @@ void SettingsView::updateConfig() {
m_logModel.logger()->logToStdout(m_ui.logToStdout->isChecked());
#ifdef M_CORE_GB
GBModel modelGB = s_gbModelList[m_ui.gbModel->currentIndex()];
m_controller->setOption("gb.model", GBModelToName(modelGB));
QVariant modelGB = m_ui.gbModel->currentData();
if (modelGB.isValid()) {
m_controller->setOption("gb.model", GBModelToName(static_cast<GBModel>(modelGB.toInt())));
}
GBModel modelSGB = s_gbModelList[m_ui.sgbModel->currentIndex()];
m_controller->setOption("sgb.model", GBModelToName(modelSGB));
QVariant modelSGB = m_ui.sgbModel->currentData();
if (modelSGB.isValid()) {
m_controller->setOption("sgb.model", GBModelToName(static_cast<GBModel>(modelSGB.toInt())));
}
GBModel modelCGB = s_gbModelList[m_ui.cgbModel->currentIndex()];
m_controller->setOption("cgb.model", GBModelToName(modelCGB));
QVariant modelCGB = m_ui.cgbModel->currentData();
if (modelCGB.isValid()) {
m_controller->setOption("cgb.model", GBModelToName(static_cast<GBModel>(modelCGB.toInt())));
}
for (int colorId = 0; colorId < 12; ++colorId) {
if (!(m_gbColors[colorId] & 0xFF000000)) {
@ -641,21 +648,21 @@ void SettingsView::reloadConfig() {
QString modelGB = m_controller->getOption("gb.model");
if (!modelGB.isNull()) {
GBModel model = GBNameToModel(modelGB.toUtf8().constData());
int index = s_gbModelList.indexOf(model);
int index = m_ui.gbModel->findData(model);
m_ui.gbModel->setCurrentIndex(index >= 0 ? index : 0);
}
QString modelSGB = m_controller->getOption("sgb.model");
if (!modelSGB.isNull()) {
GBModel model = GBNameToModel(modelSGB.toUtf8().constData());
int index = s_gbModelList.indexOf(model);
int index = m_ui.sgbModel->findData(model);
m_ui.sgbModel->setCurrentIndex(index >= 0 ? index : 0);
}
QString modelCGB = m_controller->getOption("cgb.model");
if (!modelCGB.isNull()) {
GBModel model = GBNameToModel(modelCGB.toUtf8().constData());
int index = s_gbModelList.indexOf(model);
int index = m_ui.cgbModel->findData(model);
m_ui.cgbModel->setCurrentIndex(index >= 0 ? index : 0);
}
#endif

View File

@ -61,7 +61,6 @@ private:
#ifdef M_CORE_GB
uint32_t m_gbColors[12]{};
ColorPicker m_colorPickers[12];
static QList<enum GBModel> s_gbModelList;
#endif
void saveSetting(const char* key, const QAbstractButton*);

View File

@ -1476,26 +1476,6 @@
<string>Autodetect</string>
</property>
</item>
<item>
<property name="text">
<string>Game Boy (DMG)</string>
</property>
</item>
<item>
<property name="text">
<string>Super Game Boy (SGB)</string>
</property>
</item>
<item>
<property name="text">
<string>Game Boy Color (CGB)</string>
</property>
</item>
<item>
<property name="text">
<string>Game Boy Advance (AGB)</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
@ -1512,26 +1492,6 @@
<string>Autodetect</string>
</property>
</item>
<item>
<property name="text">
<string>Game Boy (DMG)</string>
</property>
</item>
<item>
<property name="text">
<string>Super Game Boy (SGB)</string>
</property>
</item>
<item>
<property name="text">
<string>Game Boy Color (CGB)</string>
</property>
</item>
<item>
<property name="text">
<string>Game Boy Advance (AGB)</string>
</property>
</item>
</widget>
</item>
<item row="2" column="0">
@ -1548,26 +1508,6 @@
<string>Autodetect</string>
</property>
</item>
<item>
<property name="text">
<string>Game Boy (DMG)</string>
</property>
</item>
<item>
<property name="text">
<string>Super Game Boy (SGB)</string>
</property>
</item>
<item>
<property name="text">
<string>Game Boy Color (CGB)</string>
</property>
</item>
<item>
<property name="text">
<string>Game Boy Advance (AGB)</string>
</property>
</item>
</widget>
</item>
<item row="3" column="0" colspan="2">