Qt: Revamp BattleChip UI

This commit is contained in:
Vicki Pfau 2019-02-21 02:00:11 -08:00
parent 99a6db6738
commit ce419ee1c6
3 changed files with 243 additions and 73 deletions

View File

@ -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 <QtAlgorithms>
#include <QFile>
#include <QResource>
#include <QStringList>
using namespace QGBA;
@ -16,6 +20,9 @@ BattleChipView::BattleChipView(std::shared_ptr<CoreController> 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<CoreController> 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<CoreController> 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;
}
}

View File

@ -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<int, int> m_chipIndexToId;
QMap<int, QString> m_chipIdToName;
std::shared_ptr<CoreController> m_controller;
int m_flavor;
int m_frameCounter = -1;
bool m_next = false;
};
}

View File

@ -6,90 +6,186 @@
<rect>
<x>0</x>
<y>0</y>
<width>426</width>
<height>278</height>
<width>794</width>
<height>893</height>
</rect>
</property>
<property name="windowTitle">
<string>BattleChip Gate</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="5" column="1">
<widget class="QCheckBox" name="inserted">
<property name="text">
<string>Inserted</string>
</property>
</widget>
<layout class="QGridLayout" name="gridLayout" rowstretch="1,0,0,0,0" columnstretch="1,0,1">
<item row="2" column="0">
<layout class="QFormLayout" name="formLayout_2">
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Gate type</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QRadioButton" name="gateBattleChip">
<property name="text">
<string>Ba&amp;ttleChip Gate</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QRadioButton" name="gateProgress">
<property name="text">
<string>Progress &amp;Gate</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QRadioButton" name="gateBeastLink">
<property name="text">
<string>Beast &amp;Link Gate</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Chip ID</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Chip name</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QSpinBox" name="chipId">
<property name="maximum">
<number>65535</number>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="chipName"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Gate type</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QRadioButton" name="gateProgress">
<property name="text">
<string>Progress &amp;Gate</string>
</property>
<attribute name="buttonGroup">
<string notr="true">gate</string>
</attribute>
</widget>
</item>
<item row="0" column="1">
<widget class="QRadioButton" name="gateBattleChip">
<property name="text">
<string>Ba&amp;ttleChip Gate</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">gate</string>
</attribute>
</widget>
<item row="2" column="2">
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Chip ID</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="chipId">
<property name="maximum">
<number>65535</number>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="inserted">
<property name="text">
<string>Inserted</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="1">
<widget class="QRadioButton" name="gateBeastLink">
<property name="text">
<string>Beast &amp;Link Gate</string>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="1,0,0,0">
<item>
<layout class="QFormLayout" name="formLayout_4">
<item row="0" column="1">
<widget class="QComboBox" name="chipName"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Chip name</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="add">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="remove">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="insert">
<property name="text">
<string>Insert</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="0" colspan="3">
<widget class="QListWidget" name="chipList">
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::InternalMove</enum>
</property>
<property name="defaultDropAction">
<enum>Qt::MoveAction</enum>
</property>
<property name="iconSize">
<size>
<width>56</width>
<height>48</height>
</size>
</property>
<property name="movement">
<enum>QListView::Snap</enum>
</property>
<property name="isWrapping" stdset="0">
<bool>true</bool>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
<property name="gridSize">
<size>
<width>160</width>
<height>128</height>
</size>
</property>
<property name="viewMode">
<enum>QListView::IconMode</enum>
</property>
</widget>
</item>
<item row="4" column="0" colspan="3">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
<attribute name="buttonGroup">
<string notr="true">gate</string>
</attribute>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
<buttongroups>
<buttongroup name="gate"/>
</buttongroups>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>BattleChipView</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>310</x>
<y>632</y>
</hint>
<hint type="destinationlabel">
<x>310</x>
<y>331</y>
</hint>
</hints>
</connection>
</connections>
</ui>