mirror of https://github.com/mgba-emu/mgba.git
Qt: Quality of life improvements for BattleChip UI
This commit is contained in:
parent
b4698ab638
commit
407f5988aa
|
@ -14,6 +14,8 @@
|
|||
#include <QtAlgorithms>
|
||||
#include <QFile>
|
||||
#include <QFontMetrics>
|
||||
#include <QMessageBox>
|
||||
#include <QMultiMap>
|
||||
#include <QResource>
|
||||
#include <QSettings>
|
||||
#include <QStringList>
|
||||
|
@ -21,12 +23,12 @@
|
|||
using namespace QGBA;
|
||||
|
||||
BattleChipView::BattleChipView(std::shared_ptr<CoreController> controller, Window* window, QWidget* parent)
|
||||
: QDialog(parent)
|
||||
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint)
|
||||
, m_controller(controller)
|
||||
, m_window(window)
|
||||
{
|
||||
QResource::registerResource(GBAApp::dataDir() + "/chips.rcc");
|
||||
QResource::registerResource(ConfigController::configDir() + "/chips.rcc");
|
||||
QResource::registerResource(GBAApp::dataDir() + "/chips.rcc", "/exe");
|
||||
QResource::registerResource(ConfigController::configDir() + "/chips.rcc", "/exe");
|
||||
|
||||
m_ui.setupUi(this);
|
||||
|
||||
|
@ -38,12 +40,12 @@ BattleChipView::BattleChipView(std::shared_ptr<CoreController> controller, Windo
|
|||
QString qtitle(title);
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
|
||||
int size = QFontMetrics(QFont()).height() / ((int) ceil(devicePixelRatioF()) * 16);
|
||||
int size = QFontMetrics(QFont()).height() / ((int) ceil(devicePixelRatioF()) * 12);
|
||||
#else
|
||||
int size = QFontMetrics(QFont()).height() / (devicePixelRatio() * 16);
|
||||
int size = QFontMetrics(QFont()).height() / (devicePixelRatio() * 12);
|
||||
#endif
|
||||
m_ui.chipList->setGridSize(m_ui.chipList->gridSize() * size);
|
||||
m_ui.chipList->setIconSize(m_ui.chipList->iconSize() * size);
|
||||
m_ui.chipList->setGridSize(m_ui.chipList->gridSize() * size);
|
||||
|
||||
connect(m_ui.chipId, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), m_ui.inserted, [this]() {
|
||||
m_ui.inserted->setChecked(Qt::Unchecked);
|
||||
|
@ -59,6 +61,7 @@ BattleChipView::BattleChipView(std::shared_ptr<CoreController> controller, Windo
|
|||
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.buttonBox->button(QDialogButtonBox::Reset), &QAbstractButton::clicked, m_ui.chipList, &QListWidget::clear);
|
||||
|
||||
connect(m_ui.gateBattleChip, &QAbstractButton::toggled, this, [this](bool on) {
|
||||
if (on) {
|
||||
|
@ -144,11 +147,11 @@ void BattleChipView::addChip() {
|
|||
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'));
|
||||
QString path = QString(":/exe/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);
|
||||
path = QString(":/exe/exe%1/placeholder.png").arg(m_flavor);
|
||||
}
|
||||
add->setIcon(QIcon(path));
|
||||
add->setIcon(QPixmap(path).scaled(m_ui.chipList->iconSize()));
|
||||
m_ui.chipList->addItem(add);
|
||||
}
|
||||
|
||||
|
@ -167,7 +170,7 @@ void BattleChipView::loadChipNames(int flavor) {
|
|||
}
|
||||
m_flavor = flavor;
|
||||
|
||||
QFile file(QString(":/res/exe%1/chip-names.txt").arg(flavor));
|
||||
QFile file(QString(":/exe/exe%1/chip-names.txt").arg(flavor));
|
||||
file.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||
int id = 0;
|
||||
while (true) {
|
||||
|
@ -227,12 +230,17 @@ void BattleChipView::loadDeck() {
|
|||
ini.beginGroup("BattleChipDeck");
|
||||
int flavor = ini.value("version").toInt();
|
||||
if (flavor != m_flavor) {
|
||||
QMessageBox* error = new QMessageBox(this);
|
||||
error->setIcon(QMessageBox::Warning);
|
||||
error->setStandardButtons(QMessageBox::Ok);
|
||||
error->setWindowTitle(tr("Incompatible deck"));
|
||||
error->setText(tr("The selected deck is not compatible with this Chip Gate"));
|
||||
error->setAttribute(Qt::WA_DeleteOnClose);
|
||||
error->show();
|
||||
return;
|
||||
}
|
||||
|
||||
while (m_ui.chipList->count()) {
|
||||
delete m_ui.chipList->takeItem(m_ui.chipList->count() - 1);
|
||||
}
|
||||
|
||||
m_ui.chipList->clear();
|
||||
QStringList deck = ini.value("deck").toString().split(',');
|
||||
for (const auto& item : deck) {
|
||||
bool ok;
|
||||
|
@ -241,4 +249,4 @@ void BattleChipView::loadDeck() {
|
|||
addChipId(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,4 +57,4 @@ private:
|
|||
Window* m_window;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<property name="windowTitle">
|
||||
<string>BattleChip Gate</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,0,0,0,0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,0,0,0,0,0">
|
||||
<item>
|
||||
<widget class="QListWidget" name="chipList">
|
||||
<property name="acceptDrops">
|
||||
|
@ -35,7 +35,7 @@
|
|||
</size>
|
||||
</property>
|
||||
<property name="movement">
|
||||
<enum>QListView::Snap</enum>
|
||||
<enum>QListView::Static</enum>
|
||||
</property>
|
||||
<property name="isWrapping" stdset="0">
|
||||
<bool>true</bool>
|
||||
|
@ -45,13 +45,19 @@
|
|||
</property>
|
||||
<property name="gridSize">
|
||||
<size>
|
||||
<width>80</width>
|
||||
<width>120</width>
|
||||
<height>72</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="viewMode">
|
||||
<enum>QListView::IconMode</enum>
|
||||
</property>
|
||||
<property name="uniformItemSizes">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="selectionRectVisible">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
|
@ -174,10 +180,10 @@
|
|||
</item>
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout_5">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<item row="1" column="1">
|
||||
<widget class="QCheckBox" name="inserted">
|
||||
<property name="text">
|
||||
<string>Chip ID</string>
|
||||
<string>Inserted</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -188,10 +194,10 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QCheckBox" name="inserted">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Inserted</string>
|
||||
<string>Chip ID</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -200,19 +206,19 @@
|
|||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="showAdvanced">
|
||||
<property name="text">
|
||||
<string>Show advanced</string>
|
||||
</property>
|
||||
</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>
|
||||
<set>QDialogButtonBox::Close|QDialogButtonBox::Reset</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -222,6 +228,22 @@
|
|||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>BattleChipView</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>416</x>
|
||||
<y>690</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>314</x>
|
||||
<y>360</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>showAdvanced</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
|
@ -239,18 +261,18 @@
|
|||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>BattleChipView</receiver>
|
||||
<slot>reject()</slot>
|
||||
<sender>chipList</sender>
|
||||
<signal>indexesMoved(QModelIndexList)</signal>
|
||||
<receiver>chipList</receiver>
|
||||
<slot>doItemsLayout()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>416</x>
|
||||
<y>690</y>
|
||||
<x>314</x>
|
||||
<y>203</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>314</x>
|
||||
<y>360</y>
|
||||
<y>203</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
<!DOCTYPE RCC><RCC version="1.0">
|
||||
<!DOCTYPE RCC>
|
||||
<RCC version="1.0">
|
||||
<qresource>
|
||||
<file>../../../res/mgba-1024.png</file>
|
||||
<file>../../../res/keymap.qpic</file>
|
||||
<file>../../../res/patrons.txt</file>
|
||||
<file>../../../res/no-cam.png</file>
|
||||
<file>../../../res/exe4/chip-names.txt</file>
|
||||
<file>../../../res/exe4/placeholder.png</file>
|
||||
<file>../../../res/exe5/chip-names.txt</file>
|
||||
<file>../../../res/exe5/placeholder.png</file>
|
||||
<file>../../../res/exe6/chip-names.txt</file>
|
||||
<file>../../../res/exe6/placeholder.png</file>
|
||||
<file>../../../res/mgba-1024.png</file>
|
||||
<file>../../../res/keymap.qpic</file>
|
||||
<file>../../../res/patrons.txt</file>
|
||||
<file>../../../res/no-cam.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
<qresource prefix="/exe">
|
||||
<file alias="exe4/chip-names.txt">../../../res/exe4/chip-names.txt</file>
|
||||
<file alias="exe4/placeholder.png">../../../res/exe4/placeholder.png</file>
|
||||
<file alias="exe5/chip-names.txt">../../../res/exe5/chip-names.txt</file>
|
||||
<file alias="exe5/placeholder.png">../../../res/exe5/placeholder.png</file>
|
||||
<file alias="exe6/chip-names.txt">../../../res/exe6/chip-names.txt</file>
|
||||
<file alias="exe6/placeholder.png">../../../res/exe6/placeholder.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
Loading…
Reference in New Issue