2022-04-11 21:59:37 -04:00
|
|
|
#include "mainwindow.h"
|
|
|
|
|
2022-04-12 12:19:46 -04:00
|
|
|
#include <QHBoxLayout>
|
2022-04-11 21:59:37 -04:00
|
|
|
#include <QTableWidget>
|
|
|
|
#include <QListWidget>
|
2022-04-12 00:30:17 -04:00
|
|
|
#include <QLineEdit>
|
2022-04-12 16:19:06 -04:00
|
|
|
#include <QTimer>
|
2023-04-09 15:31:19 -04:00
|
|
|
|
2022-04-12 20:18:22 -04:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QFileDialog>
|
2022-04-17 20:02:06 -04:00
|
|
|
#include <magic_enum.hpp>
|
2022-04-28 23:20:58 -04:00
|
|
|
#include <QMenuBar>
|
|
|
|
#include <QAction>
|
2022-04-28 17:50:05 -04:00
|
|
|
#include <glm/gtc/type_ptr.hpp>
|
2022-05-03 13:19:48 -04:00
|
|
|
#include <QTreeWidget>
|
2022-08-10 14:52:28 -04:00
|
|
|
#include <physis.hpp>
|
2022-04-28 17:50:05 -04:00
|
|
|
|
2022-08-10 14:52:28 -04:00
|
|
|
void addItem(physis_Skeleton& skeleton, physis_Bone& bone, QTreeWidget* widget, QTreeWidgetItem* parent_item = nullptr) {
|
2022-05-03 13:19:48 -04:00
|
|
|
auto item = new QTreeWidgetItem();
|
2022-08-10 14:52:28 -04:00
|
|
|
item->setText(0, bone.name);
|
2022-05-03 13:19:48 -04:00
|
|
|
|
|
|
|
if(parent_item == nullptr) {
|
|
|
|
widget->addTopLevelItem(item);
|
|
|
|
} else {
|
|
|
|
parent_item->addChild(item);
|
|
|
|
}
|
|
|
|
|
2022-08-10 14:52:28 -04:00
|
|
|
for(int i = 0; i < skeleton.num_bones; i++) {
|
|
|
|
if(skeleton.bones[i].parent_bone != nullptr && strcmp(skeleton.bones[i].parent_bone->name, bone.name) == 0)
|
|
|
|
addItem(skeleton, skeleton.bones[i], widget, item);
|
2022-05-03 13:19:48 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-10 14:52:28 -04:00
|
|
|
MainWindow::MainWindow(GameData* in_data) : data(*in_data) {
|
2022-04-11 21:59:37 -04:00
|
|
|
setWindowTitle("mdlviewer");
|
2023-04-09 15:31:19 -04:00
|
|
|
setMinimumSize(QSize(800, 600));
|
2022-04-11 21:59:37 -04:00
|
|
|
|
2022-04-28 23:20:58 -04:00
|
|
|
auto fileMenu = menuBar()->addMenu("File");
|
|
|
|
|
2023-04-09 15:31:19 -04:00
|
|
|
// TODO: move to a dedicated mdlview?
|
|
|
|
/*auto openMDLFile = fileMenu->addAction("Open MDL...");
|
2022-04-28 23:20:58 -04:00
|
|
|
connect(openMDLFile, &QAction::triggered, [=] {
|
|
|
|
auto fileName = QFileDialog::getOpenFileName(nullptr,
|
|
|
|
"Open MDL File",
|
|
|
|
"~",
|
|
|
|
"FFXIV Model File (*.mdl)");
|
|
|
|
|
2022-08-10 14:52:28 -04:00
|
|
|
auto buffer = physis_read_file(fileName.toStdString().c_str());
|
|
|
|
|
|
|
|
loadedGear.model = physis_mdl_parse(buffer.size, buffer.data);
|
2022-04-28 23:20:58 -04:00
|
|
|
|
|
|
|
reloadGearAppearance();
|
2023-04-09 15:31:19 -04:00
|
|
|
});*/
|
2022-04-28 23:20:58 -04:00
|
|
|
|
2022-04-11 21:59:37 -04:00
|
|
|
auto dummyWidget = new QWidget();
|
|
|
|
setCentralWidget(dummyWidget);
|
|
|
|
|
2022-04-12 12:19:46 -04:00
|
|
|
auto layout = new QHBoxLayout();
|
2022-04-11 21:59:37 -04:00
|
|
|
dummyWidget->setLayout(layout);
|
2022-04-11 23:11:33 -04:00
|
|
|
|
2022-04-12 12:19:46 -04:00
|
|
|
// smallclothes body
|
|
|
|
{
|
|
|
|
GearInfo info = {};
|
|
|
|
info.name = "Smallclothes Body";
|
|
|
|
info.slot = Slot::Body;
|
|
|
|
|
|
|
|
gears.push_back(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
// smallclothes legs
|
|
|
|
{
|
|
|
|
GearInfo info = {};
|
|
|
|
info.name = "Smallclothes Legs";
|
|
|
|
info.slot = Slot::Legs;
|
|
|
|
|
|
|
|
gears.push_back(info);
|
|
|
|
}
|
|
|
|
|
2022-08-10 14:52:28 -04:00
|
|
|
auto exh = physis_gamedata_read_excel_sheet_header(&data, "Item");
|
2023-04-09 15:31:19 -04:00
|
|
|
auto exd = physis_gamedata_read_excel_sheet(&data, "Item", &exh, Language::English, 1);
|
2022-04-12 15:28:29 -04:00
|
|
|
|
2022-08-10 14:52:28 -04:00
|
|
|
for(int i = 0; i < exd.row_count; i++) {
|
|
|
|
const auto row = exd.row_data[i];
|
|
|
|
auto primaryModel = row.column_data[47].u_int64._0;
|
|
|
|
auto secondaryModel = row.column_data[48].u_int64._0;
|
2022-04-12 15:28:29 -04:00
|
|
|
|
|
|
|
int16_t parts[4];
|
|
|
|
memcpy(parts, &primaryModel, sizeof(int16_t) * 4);
|
|
|
|
|
|
|
|
GearInfo info = {};
|
2022-08-10 14:52:28 -04:00
|
|
|
info.name = row.column_data[9].string._0;
|
|
|
|
info.slot = physis_slot_from_id(row.column_data[17].u_int8._0);
|
2022-04-12 15:28:29 -04:00
|
|
|
info.modelInfo.primaryID = parts[0];
|
|
|
|
|
|
|
|
gears.push_back(info);
|
|
|
|
}
|
|
|
|
|
2022-04-12 12:19:46 -04:00
|
|
|
auto listWidget = new QListWidget();
|
|
|
|
for(auto gear : gears)
|
|
|
|
listWidget->addItem(gear.name.c_str());
|
|
|
|
|
|
|
|
listWidget->setMaximumWidth(200);
|
|
|
|
|
|
|
|
layout->addWidget(listWidget);
|
2022-04-11 23:11:33 -04:00
|
|
|
|
2023-04-09 15:31:19 -04:00
|
|
|
gearView = new SingleGearView(&data);
|
|
|
|
connect(gearView, &SingleGearView::addToFullModelViewer, this, [=](GearInfo& info) {
|
|
|
|
fullModelViewer->addGear(info);
|
2022-04-12 12:39:33 -04:00
|
|
|
});
|
2023-04-09 15:31:19 -04:00
|
|
|
layout->addWidget(gearView);
|
2022-04-12 12:39:33 -04:00
|
|
|
|
|
|
|
connect(listWidget, &QListWidget::itemClicked, [this](QListWidgetItem* item) {
|
|
|
|
for(auto& gear : gears) {
|
2022-04-17 20:02:06 -04:00
|
|
|
if(gear.name == item->text().toStdString()) {
|
2023-04-09 15:31:19 -04:00
|
|
|
gearView->setGear(gear);
|
2022-04-17 20:02:06 -04:00
|
|
|
return;
|
|
|
|
}
|
2022-04-12 12:19:46 -04:00
|
|
|
}
|
|
|
|
});
|
2022-04-28 17:50:05 -04:00
|
|
|
|
2023-04-09 15:31:19 -04:00
|
|
|
// TODO: reintroduce into SingleGearView
|
|
|
|
/*auto boneListWidget = new QTreeWidget();
|
2022-08-10 14:52:28 -04:00
|
|
|
for(auto& bone : extraBone) {
|
2022-04-28 17:50:05 -04:00
|
|
|
bone.inversePose = glm::inverse(bone.inversePose);
|
|
|
|
}
|
|
|
|
|
2022-05-03 13:19:48 -04:00
|
|
|
addItem(skeleton, *skeleton.root_bone, boneListWidget);
|
|
|
|
|
2022-04-28 17:50:05 -04:00
|
|
|
boneListWidget->setMaximumWidth(200);
|
|
|
|
|
2022-05-03 13:19:48 -04:00
|
|
|
connect(boneListWidget, &QTreeWidget::itemClicked, [this](QTreeWidgetItem* item, int column) {
|
2022-08-10 14:52:28 -04:00
|
|
|
for(int i = 0; i < skeleton.num_bones; i++) {
|
|
|
|
if(strcmp(skeleton.bones[i].name, item->text(column).toStdString().c_str()) == 0) {
|
|
|
|
currentScale = glm::make_vec3(skeleton.bones[i].scale);
|
|
|
|
currentEditedBone = &skeleton.bones[i];
|
2022-04-28 17:50:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
layout->addWidget(boneListWidget);
|
|
|
|
|
|
|
|
Vector3Edit* scaleEdit = new Vector3Edit(currentScale);
|
|
|
|
connect(scaleEdit, &Vector3Edit::onValueChanged, [this] {
|
2022-08-10 14:52:28 -04:00
|
|
|
memcpy(currentEditedBone->scale, glm::value_ptr(currentScale), sizeof(float) * 3);
|
2022-04-28 17:50:05 -04:00
|
|
|
reloadGearAppearance();
|
|
|
|
});
|
2023-04-09 15:31:19 -04:00
|
|
|
layout->addWidget(scaleEdit);*/
|
2022-04-28 17:50:05 -04:00
|
|
|
|
2023-04-09 15:31:19 -04:00
|
|
|
fullModelViewer = new FullModelViewer(&data);
|
|
|
|
fullModelViewer->show();
|
2022-04-17 20:02:06 -04:00
|
|
|
}
|