mirror of
https://github.com/redstrate/Novus.git
synced 2025-04-19 17:06:50 +00:00
Add a combobox to switch languages of an Excel sheet
This commit is contained in:
parent
0dcad9c5f6
commit
f99c3e4360
3 changed files with 47 additions and 23 deletions
|
@ -8,7 +8,8 @@ target_link_libraries(exdpart
|
||||||
KF6::I18n
|
KF6::I18n
|
||||||
Physis::Physis
|
Physis::Physis
|
||||||
Qt6::Core
|
Qt6::Core
|
||||||
Qt6::Widgets)
|
Qt6::Widgets
|
||||||
|
magic_enum)
|
||||||
target_include_directories(exdpart PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
target_include_directories(exdpart PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
target_compile_definitions(exdpart PRIVATE TRANSLATION_DOMAIN="novus")
|
target_compile_definitions(exdpart PRIVATE TRANSLATION_DOMAIN="novus")
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
#include <QJsonArray>
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
@ -14,6 +13,8 @@
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <physis.hpp>
|
#include <physis.hpp>
|
||||||
|
|
||||||
|
#include "magic_enum.hpp"
|
||||||
|
|
||||||
EXDPart::EXDPart(GameData *data, QWidget *parent)
|
EXDPart::EXDPart(GameData *data, QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, data(data)
|
, data(data)
|
||||||
|
@ -22,11 +23,14 @@ EXDPart::EXDPart(GameData *data, QWidget *parent)
|
||||||
layout->setContentsMargins(0, 0, 0, 0);
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
|
|
||||||
// TODO: This information should really be somewhere else
|
languageComboBox = new QComboBox();
|
||||||
/*auto headerBox = new QGroupBox(QStringLiteral("Header"));
|
connect(languageComboBox, &QComboBox::activated, this, [this](const int index) {
|
||||||
layout->addWidget(headerBox);
|
auto selectedLanguage = languageComboBox->itemData(index);
|
||||||
headerFormLayout = new QFormLayout();
|
preferredLanguage = (Language)selectedLanguage.toInt();
|
||||||
headerBox->setLayout(headerFormLayout);*/
|
|
||||||
|
loadTables();
|
||||||
|
});
|
||||||
|
layout->addWidget(languageComboBox);
|
||||||
|
|
||||||
pageTabWidget = new QTabWidget();
|
pageTabWidget = new QTabWidget();
|
||||||
pageTabWidget->setTabPosition(QTabWidget::TabPosition::South);
|
pageTabWidget->setTabPosition(QTabWidget::TabPosition::South);
|
||||||
|
@ -36,12 +40,9 @@ EXDPart::EXDPart(GameData *data, QWidget *parent)
|
||||||
|
|
||||||
void EXDPart::loadSheet(const QString &name, physis_Buffer buffer, const QString &definitionPath)
|
void EXDPart::loadSheet(const QString &name, physis_Buffer buffer, const QString &definitionPath)
|
||||||
{
|
{
|
||||||
pageTabWidget->clear();
|
|
||||||
|
|
||||||
QFile definitionFile(definitionPath);
|
QFile definitionFile(definitionPath);
|
||||||
definitionFile.open(QIODevice::ReadOnly);
|
definitionFile.open(QIODevice::ReadOnly);
|
||||||
|
|
||||||
QJsonArray definitionList;
|
|
||||||
if (definitionFile.isOpen()) {
|
if (definitionFile.isOpen()) {
|
||||||
auto document = QJsonDocument::fromJson(definitionFile.readAll());
|
auto document = QJsonDocument::fromJson(definitionFile.readAll());
|
||||||
definitionList = document.object()[QLatin1String("definitions")].toArray();
|
definitionList = document.object()[QLatin1String("definitions")].toArray();
|
||||||
|
@ -66,19 +67,24 @@ void EXDPart::loadSheet(const QString &name, physis_Buffer buffer, const QString
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto exh = physis_parse_excel_sheet_header(buffer);
|
this->name = name;
|
||||||
|
exh = physis_parse_excel_sheet_header(buffer);
|
||||||
|
|
||||||
// ditto
|
languageComboBox->clear();
|
||||||
/*QLayoutItem *child;
|
for (int i = 0; i < exh->language_count; i++) {
|
||||||
while ((child = headerFormLayout->takeAt(0)) != nullptr) {
|
const auto itemText = QString::fromUtf8(magic_enum::enum_name(exh->languages[i]));
|
||||||
delete child->widget();
|
// Don't add duplicates
|
||||||
delete child;
|
if (languageComboBox->findText(itemText) == -1) {
|
||||||
|
languageComboBox->addItem(itemText, static_cast<int>(exh->languages[i]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
headerFormLayout->addRow(QStringLiteral("Num Rows"), new QLabel(QString::number(exh->row_count)));
|
loadTables();
|
||||||
headerFormLayout->addRow(QStringLiteral("Num Columns"), new QLabel(QString::number(exh->column_count)));
|
}
|
||||||
headerFormLayout->addRow(QStringLiteral("Num Pages"), new QLabel(QString::number(exh->page_count)));
|
|
||||||
headerFormLayout->addRow(QStringLiteral("Num Languages"), new QLabel(QString::number(exh->language_count)));*/
|
void EXDPart::loadTables()
|
||||||
|
{
|
||||||
|
pageTabWidget->clear();
|
||||||
|
|
||||||
for (uint32_t i = 0; i < exh->page_count; i++) {
|
for (uint32_t i = 0; i < exh->page_count; i++) {
|
||||||
auto tableWidget = new QTableWidget();
|
auto tableWidget = new QTableWidget();
|
||||||
|
@ -185,13 +191,22 @@ void EXDPart::loadSheet(const QString &name, physis_Buffer buffer, const QString
|
||||||
|
|
||||||
Language EXDPart::getSuitableLanguage(physis_EXH *pExh)
|
Language EXDPart::getSuitableLanguage(physis_EXH *pExh)
|
||||||
{
|
{
|
||||||
|
// Find the preferred language first
|
||||||
for (uint32_t i = 0; i < pExh->language_count; i++) {
|
for (uint32_t i = 0; i < pExh->language_count; i++) {
|
||||||
if (pExh->languages[i] == Language::English) {
|
if (pExh->languages[i] == preferredLanguage) {
|
||||||
return Language::English;
|
return preferredLanguage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Language::None;
|
// Fallback to None
|
||||||
|
for (uint32_t i = 0; i < pExh->language_count; i++) {
|
||||||
|
if (pExh->languages[i] == Language::None) {
|
||||||
|
return Language::None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Then English
|
||||||
|
return Language::English;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<QString, int> EXDPart::getColumnData(physis_ColumnData &columnData)
|
std::pair<QString, int> EXDPart::getColumnData(physis_ColumnData &columnData)
|
||||||
|
|
|
@ -3,7 +3,9 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <QComboBox>
|
||||||
#include <QFormLayout>
|
#include <QFormLayout>
|
||||||
|
#include <QJsonArray>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QTabWidget>
|
#include <QTabWidget>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
@ -21,11 +23,13 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::pair<QString, int> getColumnData(physis_ColumnData &columnData);
|
std::pair<QString, int> getColumnData(physis_ColumnData &columnData);
|
||||||
|
void loadTables();
|
||||||
|
|
||||||
GameData *data = nullptr;
|
GameData *data = nullptr;
|
||||||
|
|
||||||
QTabWidget *pageTabWidget = nullptr;
|
QTabWidget *pageTabWidget = nullptr;
|
||||||
QFormLayout *headerFormLayout = nullptr;
|
QFormLayout *headerFormLayout = nullptr;
|
||||||
|
QComboBox *languageComboBox = nullptr;
|
||||||
|
|
||||||
struct CachedExcel {
|
struct CachedExcel {
|
||||||
physis_EXH *exh = nullptr;
|
physis_EXH *exh = nullptr;
|
||||||
|
@ -33,4 +37,8 @@ private:
|
||||||
};
|
};
|
||||||
QMap<QString, CachedExcel> cachedExcelSheets;
|
QMap<QString, CachedExcel> cachedExcelSheets;
|
||||||
Language getSuitableLanguage(physis_EXH *pExh);
|
Language getSuitableLanguage(physis_EXH *pExh);
|
||||||
|
Language preferredLanguage = Language::English;
|
||||||
|
physis_EXH *exh = nullptr;
|
||||||
|
QString name;
|
||||||
|
QJsonArray definitionList;
|
||||||
};
|
};
|
Loading…
Add table
Reference in a new issue