mirror of https://github.com/mgba-emu/mgba.git
Qt: Add BattleChip "deck" save/load
This commit is contained in:
parent
64ad73c9f9
commit
475c7790c5
|
@ -13,6 +13,7 @@
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFontMetrics>
|
#include <QFontMetrics>
|
||||||
#include <QResource>
|
#include <QResource>
|
||||||
|
#include <QSettings>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
using namespace QGBA;
|
using namespace QGBA;
|
||||||
|
@ -53,6 +54,8 @@ BattleChipView::BattleChipView(std::shared_ptr<CoreController> controller, QWidg
|
||||||
connect(m_ui.add, &QAbstractButton::clicked, this, &BattleChipView::addChip);
|
connect(m_ui.add, &QAbstractButton::clicked, this, &BattleChipView::addChip);
|
||||||
connect(m_ui.remove, &QAbstractButton::clicked, this, &BattleChipView::removeChip);
|
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.save, &QAbstractButton::clicked, this, &BattleChipView::saveDeck);
|
||||||
|
connect(m_ui.load, &QAbstractButton::clicked, this, &BattleChipView::loadDeck);
|
||||||
|
|
||||||
connect(m_ui.gateBattleChip, &QAbstractButton::toggled, this, [this](bool on) {
|
connect(m_ui.gateBattleChip, &QAbstractButton::toggled, this, [this](bool on) {
|
||||||
if (on) {
|
if (on) {
|
||||||
|
@ -130,9 +133,13 @@ void BattleChipView::addChip() {
|
||||||
if (insertedChip < 1) {
|
if (insertedChip < 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QListWidgetItem* add = new QListWidgetItem(m_chipIdToName[insertedChip]);
|
addChipId(insertedChip);
|
||||||
add->setData(Qt::UserRole, insertedChip);
|
}
|
||||||
QString path = QString(":/res/exe%1/%2.png").arg(m_flavor).arg(insertedChip, 3, 10, QLatin1Char('0'));
|
|
||||||
|
void BattleChipView::addChipId(int id) {
|
||||||
|
QListWidgetItem* add = new QListWidgetItem(m_chipIdToName[id]);
|
||||||
|
add->setData(Qt::UserRole, id);
|
||||||
|
QString path = QString(":/res/exe%1/%2.png").arg(m_flavor).arg(id, 3, 10, QLatin1Char('0'));
|
||||||
if (!QFile(path).exists()) {
|
if (!QFile(path).exists()) {
|
||||||
path = QString(":/res/exe%1/placeholder.png").arg(m_flavor);
|
path = QString(":/res/exe%1/placeholder.png").arg(m_flavor);
|
||||||
}
|
}
|
||||||
|
@ -184,4 +191,49 @@ void BattleChipView::advanceFrameCounter() {
|
||||||
if (m_frameCounter >= 0) {
|
if (m_frameCounter >= 0) {
|
||||||
--m_frameCounter;
|
--m_frameCounter;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BattleChipView::saveDeck() {
|
||||||
|
QString filename = GBAApp::app()->getSaveFileName(this, tr("Select deck file"), tr(("BattleChip deck file (*.deck)")));
|
||||||
|
if (filename.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList deck;
|
||||||
|
for (int i = 0; i < m_ui.chipList->count(); ++i) {
|
||||||
|
deck.append(m_ui.chipList->item(i)->data(Qt::UserRole).toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
QSettings ini(filename, QSettings::IniFormat);
|
||||||
|
ini.clear();
|
||||||
|
ini.beginGroup("BattleChipDeck");
|
||||||
|
ini.setValue("version", m_flavor);
|
||||||
|
ini.setValue("deck", deck.join(','));
|
||||||
|
ini.sync();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BattleChipView::loadDeck() {
|
||||||
|
QString filename = GBAApp::app()->getOpenFileName(this, tr("Select deck file"), tr(("BattleChip deck file (*.deck)")));
|
||||||
|
if (filename.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QSettings ini(filename, QSettings::IniFormat);
|
||||||
|
ini.beginGroup("BattleChipDeck");
|
||||||
|
int flavor = ini.value("version").toInt();
|
||||||
|
if (flavor != m_flavor) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (m_ui.chipList->count()) {
|
||||||
|
delete m_ui.chipList->takeItem(m_ui.chipList->count() - 1);
|
||||||
|
}
|
||||||
|
QStringList deck = ini.value("deck").toString().split(',');
|
||||||
|
for (const auto& item : deck) {
|
||||||
|
bool ok;
|
||||||
|
int id = item.toInt(&ok);
|
||||||
|
if (ok) {
|
||||||
|
addChipId(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -32,8 +32,12 @@ public slots:
|
||||||
private slots:
|
private slots:
|
||||||
void advanceFrameCounter();
|
void advanceFrameCounter();
|
||||||
void addChip();
|
void addChip();
|
||||||
|
void addChipId(int);
|
||||||
void removeChip();
|
void removeChip();
|
||||||
|
|
||||||
|
void saveDeck();
|
||||||
|
void loadDeck();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const int UNINSERTED_TIME = 10;
|
static const int UNINSERTED_TIME = 10;
|
||||||
|
|
||||||
|
|
|
@ -6,121 +6,15 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>794</width>
|
<width>630</width>
|
||||||
<height>893</height>
|
<height>722</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>BattleChip Gate</string>
|
<string>BattleChip Gate</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout" rowstretch="1,0,0,0,0" columnstretch="1,0,1">
|
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,0,0,0,0">
|
||||||
<item row="2" column="0">
|
<item>
|
||||||
<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&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 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="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">
|
<widget class="QListWidget" name="chipList">
|
||||||
<property name="acceptDrops">
|
<property name="acceptDrops">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
|
@ -160,30 +54,203 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="4" column="0" colspan="3">
|
<item>
|
||||||
<widget class="QDialogButtonBox" name="buttonBox">
|
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="1,0">
|
||||||
<property name="standardButtons">
|
<item>
|
||||||
<set>QDialogButtonBox::Close</set>
|
<layout class="QFormLayout" name="formLayout_4">
|
||||||
</property>
|
<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="insert">
|
||||||
|
<property name="text">
|
||||||
|
<string>Insert</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="save">
|
||||||
|
<property name="text">
|
||||||
|
<string>Save</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="load">
|
||||||
|
<property name="text">
|
||||||
|
<string>Load</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</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>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QWidget" name="advanced" native="true">
|
||||||
|
<property name="visible">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||||
|
<item>
|
||||||
|
<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&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>
|
||||||
|
<widget class="Line" name="line">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QFormLayout" name="formLayout_5">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="label_4">
|
||||||
|
<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>
|
||||||
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="showAdvanced">
|
||||||
|
<property name="text">
|
||||||
|
<string>Show advanced</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Close</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections>
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>showAdvanced</sender>
|
||||||
|
<signal>toggled(bool)</signal>
|
||||||
|
<receiver>advanced</receiver>
|
||||||
|
<slot>setVisible(bool)</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>109</x>
|
||||||
|
<y>34</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>396</x>
|
||||||
|
<y>654</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
<connection>
|
<connection>
|
||||||
<sender>buttonBox</sender>
|
<sender>buttonBox</sender>
|
||||||
<signal>rejected()</signal>
|
<signal>rejected()</signal>
|
||||||
<receiver>BattleChipView</receiver>
|
<receiver>BattleChipView</receiver>
|
||||||
<slot>close()</slot>
|
<slot>reject()</slot>
|
||||||
<hints>
|
<hints>
|
||||||
<hint type="sourcelabel">
|
<hint type="sourcelabel">
|
||||||
<x>310</x>
|
<x>416</x>
|
||||||
<y>632</y>
|
<y>690</y>
|
||||||
</hint>
|
</hint>
|
||||||
<hint type="destinationlabel">
|
<hint type="destinationlabel">
|
||||||
<x>310</x>
|
<x>314</x>
|
||||||
<y>331</y>
|
<y>360</y>
|
||||||
</hint>
|
</hint>
|
||||||
</hints>
|
</hints>
|
||||||
</connection>
|
</connection>
|
||||||
|
|
Loading…
Reference in New Issue