mirror of https://github.com/mgba-emu/mgba.git
Qt: Revamp BattleChip UI
This commit is contained in:
parent
99a6db6738
commit
ce419ee1c6
|
@ -5,9 +5,13 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
#include "BattleChipView.h"
|
#include "BattleChipView.h"
|
||||||
|
|
||||||
|
#include "ConfigController.h"
|
||||||
#include "CoreController.h"
|
#include "CoreController.h"
|
||||||
|
#include "GBAApp.h"
|
||||||
|
|
||||||
|
#include <QtAlgorithms>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
#include <QResource>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
using namespace QGBA;
|
using namespace QGBA;
|
||||||
|
@ -16,6 +20,9 @@ BattleChipView::BattleChipView(std::shared_ptr<CoreController> controller, QWidg
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
, m_controller(controller)
|
, m_controller(controller)
|
||||||
{
|
{
|
||||||
|
QResource::registerResource(GBAApp::dataDir() + "/chips.rcc");
|
||||||
|
QResource::registerResource(ConfigController::configDir() + "/chips.rcc");
|
||||||
|
|
||||||
m_ui.setupUi(this);
|
m_ui.setupUi(this);
|
||||||
|
|
||||||
char title[9];
|
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.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(controller.get(), &CoreController::stopping, this, &QWidget::close);
|
||||||
|
|
||||||
connect(m_ui.gateBattleChip, &QAbstractButton::toggled, this, [this](bool on) {
|
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();
|
m_controller->attachBattleChipGate();
|
||||||
setFlavor(4);
|
setFlavor(4);
|
||||||
if (qtitle.startsWith("AGB-B4B") || qtitle.startsWith("AGB-B4W") || qtitle.startsWith("AGB-BR4") || qtitle.startsWith("AGB-BZ3")) {
|
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) {
|
void BattleChipView::insertChip(bool inserted) {
|
||||||
|
bool blocked = m_ui.inserted->blockSignals(true);
|
||||||
|
m_ui.inserted->setChecked(inserted);
|
||||||
|
m_ui.inserted->blockSignals(blocked);
|
||||||
if (inserted) {
|
if (inserted) {
|
||||||
m_controller->setBattleChipId(m_ui.chipId->value());
|
m_controller->setBattleChipId(m_ui.chipId->value());
|
||||||
} else {
|
} 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) {
|
void BattleChipView::loadChipNames(int flavor) {
|
||||||
QStringList chipNames;
|
QStringList chipNames;
|
||||||
chipNames.append(tr("(None)"));
|
chipNames.append(tr("(None)"));
|
||||||
|
|
||||||
m_chipIndexToId.clear();
|
m_chipIndexToId.clear();
|
||||||
|
m_chipIdToName.clear();
|
||||||
if (flavor == GBA_FLAVOR_BEAST_LINK_GATE_US) {
|
if (flavor == GBA_FLAVOR_BEAST_LINK_GATE_US) {
|
||||||
flavor = GBA_FLAVOR_BEAST_LINK_GATE;
|
flavor = GBA_FLAVOR_BEAST_LINK_GATE;
|
||||||
}
|
}
|
||||||
|
m_flavor = flavor;
|
||||||
|
|
||||||
QFile file(QString(":/res/chip-names-%1.txt").arg(flavor));
|
QFile file(QString(":/res/chip-names-%1.txt").arg(flavor));
|
||||||
file.open(QIODevice::ReadOnly | QIODevice::Text);
|
file.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||||
|
@ -105,10 +155,21 @@ void BattleChipView::loadChipNames(int flavor) {
|
||||||
if (line.trimmed().isEmpty()) {
|
if (line.trimmed().isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
QString name = QString::fromUtf8(line).trimmed();
|
||||||
m_chipIndexToId[chipNames.length()] = id;
|
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->clear();
|
||||||
m_ui.chipName->addItems(chipNames);
|
m_ui.chipName->addItems(chipNames);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BattleChipView::advanceFrameCounter() {
|
||||||
|
if (m_frameCounter == 0) {
|
||||||
|
insertChip(m_next);
|
||||||
|
}
|
||||||
|
if (m_frameCounter >= 0) {
|
||||||
|
--m_frameCounter;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -27,14 +27,27 @@ public:
|
||||||
public slots:
|
public slots:
|
||||||
void setFlavor(int);
|
void setFlavor(int);
|
||||||
void insertChip(bool);
|
void insertChip(bool);
|
||||||
|
void reinsert();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void advanceFrameCounter();
|
||||||
|
void addChip();
|
||||||
|
void removeChip();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static const int UNINSERTED_TIME = 10;
|
||||||
|
|
||||||
void loadChipNames(int);
|
void loadChipNames(int);
|
||||||
|
|
||||||
Ui::BattleChipView m_ui;
|
Ui::BattleChipView m_ui;
|
||||||
|
|
||||||
QMap<int, int> m_chipIndexToId;
|
QMap<int, int> m_chipIndexToId;
|
||||||
|
QMap<int, QString> m_chipIdToName;
|
||||||
std::shared_ptr<CoreController> m_controller;
|
std::shared_ptr<CoreController> m_controller;
|
||||||
|
int m_flavor;
|
||||||
|
|
||||||
|
int m_frameCounter = -1;
|
||||||
|
bool m_next = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
|
@ -6,90 +6,186 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>426</width>
|
<width>794</width>
|
||||||
<height>278</height>
|
<height>893</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>BattleChip Gate</string>
|
<string>BattleChip Gate</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QFormLayout" name="formLayout">
|
<layout class="QGridLayout" name="gridLayout" rowstretch="1,0,0,0,0" columnstretch="1,0,1">
|
||||||
<item row="5" column="1">
|
<item row="2" column="0">
|
||||||
<widget class="QCheckBox" name="inserted">
|
<layout class="QFormLayout" name="formLayout_2">
|
||||||
<property name="text">
|
<item row="1" column="0">
|
||||||
<string>Inserted</string>
|
<widget class="QLabel" name="label_3">
|
||||||
</property>
|
<property name="text">
|
||||||
</widget>
|
<string>Gate type</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QRadioButton" name="gateBattleChip">
|
||||||
|
<property name="text">
|
||||||
|
<string>Ba&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 &Gate</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="1">
|
||||||
|
<widget class="QRadioButton" name="gateBeastLink">
|
||||||
|
<property name="text">
|
||||||
|
<string>Beast &Link Gate</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="4" column="0">
|
<item row="2" column="2">
|
||||||
<widget class="QLabel" name="label">
|
<layout class="QFormLayout" name="formLayout_3">
|
||||||
<property name="text">
|
<item row="0" column="0">
|
||||||
<string>Chip ID</string>
|
<widget class="QLabel" name="label">
|
||||||
</property>
|
<property name="text">
|
||||||
</widget>
|
<string>Chip ID</string>
|
||||||
</item>
|
</property>
|
||||||
<item row="3" column="0">
|
</widget>
|
||||||
<widget class="QLabel" name="label_2">
|
</item>
|
||||||
<property name="text">
|
<item row="0" column="1">
|
||||||
<string>Chip name</string>
|
<widget class="QSpinBox" name="chipId">
|
||||||
</property>
|
<property name="maximum">
|
||||||
</widget>
|
<number>65535</number>
|
||||||
</item>
|
</property>
|
||||||
<item row="4" column="1">
|
</widget>
|
||||||
<widget class="QSpinBox" name="chipId">
|
</item>
|
||||||
<property name="maximum">
|
<item row="1" column="1">
|
||||||
<number>65535</number>
|
<widget class="QCheckBox" name="inserted">
|
||||||
</property>
|
<property name="text">
|
||||||
</widget>
|
<string>Inserted</string>
|
||||||
</item>
|
</property>
|
||||||
<item row="3" column="1">
|
</widget>
|
||||||
<widget class="QComboBox" name="chipName"/>
|
</item>
|
||||||
</item>
|
</layout>
|
||||||
<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 &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&ttleChip Gate</string>
|
|
||||||
</property>
|
|
||||||
<property name="checked">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<attribute name="buttonGroup">
|
|
||||||
<string notr="true">gate</string>
|
|
||||||
</attribute>
|
|
||||||
</widget>
|
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="2" column="1">
|
||||||
<widget class="QRadioButton" name="gateBeastLink">
|
<widget class="Line" name="line">
|
||||||
<property name="text">
|
<property name="orientation">
|
||||||
<string>Beast &Link Gate</string>
|
<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>
|
</property>
|
||||||
<attribute name="buttonGroup">
|
|
||||||
<string notr="true">gate</string>
|
|
||||||
</attribute>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections>
|
||||||
<buttongroups>
|
<connection>
|
||||||
<buttongroup name="gate"/>
|
<sender>buttonBox</sender>
|
||||||
</buttongroups>
|
<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>
|
</ui>
|
||||||
|
|
Loading…
Reference in New Issue