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 <QFontMetrics>
|
||||
#include <QResource>
|
||||
#include <QSettings>
|
||||
#include <QStringList>
|
||||
|
||||
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.remove, &QAbstractButton::clicked, this, &BattleChipView::removeChip);
|
||||
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) {
|
||||
if (on) {
|
||||
|
@ -130,9 +133,13 @@ void BattleChipView::addChip() {
|
|||
if (insertedChip < 1) {
|
||||
return;
|
||||
}
|
||||
QListWidgetItem* add = new QListWidgetItem(m_chipIdToName[insertedChip]);
|
||||
add->setData(Qt::UserRole, insertedChip);
|
||||
QString path = QString(":/res/exe%1/%2.png").arg(m_flavor).arg(insertedChip, 3, 10, QLatin1Char('0'));
|
||||
addChipId(insertedChip);
|
||||
}
|
||||
|
||||
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()) {
|
||||
path = QString(":/res/exe%1/placeholder.png").arg(m_flavor);
|
||||
}
|
||||
|
@ -185,3 +192,48 @@ void BattleChipView::advanceFrameCounter() {
|
|||
--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:
|
||||
void advanceFrameCounter();
|
||||
void addChip();
|
||||
void addChipId(int);
|
||||
void removeChip();
|
||||
|
||||
void saveDeck();
|
||||
void loadDeck();
|
||||
|
||||
private:
|
||||
static const int UNINSERTED_TIME = 10;
|
||||
|
||||
|
|
|
@ -6,121 +6,15 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>794</width>
|
||||
<height>893</height>
|
||||
<width>630</width>
|
||||
<height>722</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>BattleChip Gate</string>
|
||||
</property>
|
||||
<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&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">
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,0,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>
|
||||
|
@ -160,7 +54,162 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="3">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="1,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="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>
|
||||
</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>
|
||||
|
@ -168,22 +217,40 @@
|
|||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<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>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>BattleChipView</receiver>
|
||||
<slot>close()</slot>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>310</x>
|
||||
<y>632</y>
|
||||
<x>416</x>
|
||||
<y>690</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>310</x>
|
||||
<y>331</y>
|
||||
<x>314</x>
|
||||
<y>360</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
|
|
Loading…
Reference in New Issue