diff --git a/src/platform/qt/BattleChipView.cpp b/src/platform/qt/BattleChipView.cpp index fa12cbbf2..c6d6578d4 100644 --- a/src/platform/qt/BattleChipView.cpp +++ b/src/platform/qt/BattleChipView.cpp @@ -5,9 +5,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "BattleChipView.h" +#include "ConfigController.h" #include "CoreController.h" +#include "GBAApp.h" +#include #include +#include #include using namespace QGBA; @@ -16,6 +20,9 @@ BattleChipView::BattleChipView(std::shared_ptr controller, QWidg : QDialog(parent) , m_controller(controller) { + QResource::registerResource(GBAApp::dataDir() + "/chips.rcc"); + QResource::registerResource(ConfigController::configDir() + "/chips.rcc"); + m_ui.setupUi(this); char title[9]; @@ -34,6 +41,9 @@ BattleChipView::BattleChipView(std::shared_ptr controller, QWidg }); connect(m_ui.inserted, &QAbstractButton::toggled, this, &BattleChipView::insertChip); + connect(m_ui.insert, &QAbstractButton::clicked, this, &BattleChipView::reinsert); + connect(m_ui.add, &QAbstractButton::clicked, this, &BattleChipView::addChip); + connect(m_ui.remove, &QAbstractButton::clicked, this, &BattleChipView::removeChip); connect(controller.get(), &CoreController::stopping, this, &QWidget::close); connect(m_ui.gateBattleChip, &QAbstractButton::toggled, this, [this](bool on) { @@ -56,6 +66,16 @@ BattleChipView::BattleChipView(std::shared_ptr controller, QWidg } }); + connect(m_controller.get(), &CoreController::frameAvailable, this, &BattleChipView::advanceFrameCounter); + + connect(m_ui.chipList, &QListWidget::itemClicked, this, [this](QListWidgetItem* item) { + QVariant chip = item->data(Qt::UserRole); + bool blocked = m_ui.chipId->blockSignals(true); + m_ui.chipId->setValue(chip.toInt()); + m_ui.chipId->blockSignals(blocked); + reinsert(); + }); + m_controller->attachBattleChipGate(); setFlavor(4); if (qtitle.startsWith("AGB-B4B") || qtitle.startsWith("AGB-B4W") || qtitle.startsWith("AGB-BR4") || qtitle.startsWith("AGB-BZ3")) { @@ -77,6 +97,9 @@ void BattleChipView::setFlavor(int flavor) { } void BattleChipView::insertChip(bool inserted) { + bool blocked = m_ui.inserted->blockSignals(true); + m_ui.inserted->setChecked(inserted); + m_ui.inserted->blockSignals(blocked); if (inserted) { m_controller->setBattleChipId(m_ui.chipId->value()); } else { @@ -84,14 +107,41 @@ void BattleChipView::insertChip(bool inserted) { } } +void BattleChipView::reinsert() { + if (m_ui.inserted->isChecked()) { + insertChip(false); + m_next = true; + m_frameCounter = UNINSERTED_TIME; + } else { + insertChip(true); + } +} + +void BattleChipView::addChip() { + int insertedChip = m_ui.chipId->value(); + if (insertedChip < 1) { + return; + } + QListWidgetItem* add = new QListWidgetItem(m_chipIdToName[insertedChip]); + add->setData(Qt::UserRole, insertedChip); + add->setIcon(QIcon(QString(":/res/exe%1/%2.png").arg(m_flavor).arg(insertedChip, 3, 10, QLatin1Char('0')))); + m_ui.chipList->addItem(add); +} + +void BattleChipView::removeChip() { + qDeleteAll(m_ui.chipList->selectedItems()); +} + void BattleChipView::loadChipNames(int flavor) { QStringList chipNames; chipNames.append(tr("(None)")); m_chipIndexToId.clear(); + m_chipIdToName.clear(); if (flavor == GBA_FLAVOR_BEAST_LINK_GATE_US) { flavor = GBA_FLAVOR_BEAST_LINK_GATE; } + m_flavor = flavor; QFile file(QString(":/res/chip-names-%1.txt").arg(flavor)); file.open(QIODevice::ReadOnly | QIODevice::Text); @@ -105,10 +155,21 @@ void BattleChipView::loadChipNames(int flavor) { if (line.trimmed().isEmpty()) { continue; } + QString name = QString::fromUtf8(line).trimmed(); m_chipIndexToId[chipNames.length()] = id; - chipNames.append(QString::fromUtf8(line).trimmed()); + m_chipIdToName[id] = name; + chipNames.append(name); } m_ui.chipName->clear(); m_ui.chipName->addItems(chipNames); +} + +void BattleChipView::advanceFrameCounter() { + if (m_frameCounter == 0) { + insertChip(m_next); + } + if (m_frameCounter >= 0) { + --m_frameCounter; + } } \ No newline at end of file diff --git a/src/platform/qt/BattleChipView.h b/src/platform/qt/BattleChipView.h index 7dbdc9561..6b4582c36 100644 --- a/src/platform/qt/BattleChipView.h +++ b/src/platform/qt/BattleChipView.h @@ -27,14 +27,27 @@ public: public slots: void setFlavor(int); void insertChip(bool); + void reinsert(); + +private slots: + void advanceFrameCounter(); + void addChip(); + void removeChip(); private: + static const int UNINSERTED_TIME = 10; + void loadChipNames(int); Ui::BattleChipView m_ui; QMap m_chipIndexToId; + QMap m_chipIdToName; std::shared_ptr m_controller; + int m_flavor; + + int m_frameCounter = -1; + bool m_next = false; }; } \ No newline at end of file diff --git a/src/platform/qt/BattleChipView.ui b/src/platform/qt/BattleChipView.ui index ba95e455a..14ce62c55 100644 --- a/src/platform/qt/BattleChipView.ui +++ b/src/platform/qt/BattleChipView.ui @@ -6,90 +6,186 @@ 0 0 - 426 - 278 + 794 + 893 BattleChip Gate - - - - - Inserted - - + + + + + + + Gate type + + + + + + + Ba&ttleChip Gate + + + true + + + + + + + Progress &Gate + + + + + + + Beast &Link Gate + + + + - - - - Chip ID - - - - - - - Chip name - - - - - - - 65535 - - - - - - - - - - Gate type - - - - - - - Progress &Gate - - - gate - - - - - - - Ba&ttleChip Gate - - - true - - - gate - - + + + + + + Chip ID + + + + + + + 65535 + + + + + + + Inserted + + + + - - - Beast &Link Gate + + + Qt::Vertical + + + + + + + + + + + + + + Chip name + + + + + + + + + Add + + + + + + + Remove + + + + + + + Insert + + + + + + + + + true + + + true + + + QAbstractItemView::InternalMove + + + Qt::MoveAction + + + + 56 + 48 + + + + QListView::Snap + + + true + + + QListView::Adjust + + + + 160 + 128 + + + + QListView::IconMode + + + + + + + QDialogButtonBox::Close - - gate - - - - - + + + buttonBox + rejected() + BattleChipView + close() + + + 310 + 632 + + + 310 + 331 + + + +