app/lib: added ability to edit location and start times of objects

This commit is contained in:
itsmattkc 2022-07-21 17:39:13 -07:00
parent de234a5544
commit 90463ea6cf
6 changed files with 84 additions and 7 deletions

View file

@ -58,6 +58,31 @@ MainWindow::MainWindow(QWidget *parent) :
panel_media_ = new MediaPanel();
config_stack_->addWidget(panel_media_);
properties_group_ = new QGroupBox();
config_layout->addWidget(properties_group_);
auto properties_layout = new QGridLayout(properties_group_);
{
int prow = 0;
properties_layout->addWidget(new QLabel(tr("Location")), prow, 0);
m_LocationEdit = new Vector3Edit();
connect(m_LocationEdit, &Vector3Edit::changed, this, &MainWindow::LocationChanged);
properties_layout->addWidget(m_LocationEdit, prow, 1);
prow++;
properties_layout->addWidget(new QLabel(tr("Start Time")), prow, 0);
start_time_edit_ = new QSpinBox();
start_time_edit_->setMinimum(0);
start_time_edit_->setMaximum(INT_MAX);
connect(start_time_edit_, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, &MainWindow::StartTimeChanged);
properties_layout->addWidget(start_time_edit_, prow, 1);
}
InitializeMenuBar();
splitter->setSizes({99999, 99999});
@ -113,6 +138,12 @@ void MainWindow::SetPanel(Panel *panel, si::Object *chunk)
last_set_data_ = chunk;
action_grp_->setEnabled(chunk);
properties_group_->setEnabled(chunk);
if (chunk) {
m_LocationEdit->SetValue(chunk->location_);
start_time_edit_->setValue(chunk->time_offset_);
}
}
void MainWindow::ExtractObject(si::Object *obj)
@ -301,3 +332,17 @@ void MainWindow::ViewSIFile()
}
}
}
void MainWindow::LocationChanged(const Vector3 &v)
{
if (last_set_data_) {
last_set_data_->location_ = v;
}
}
void MainWindow::StartTimeChanged(int t)
{
if (last_set_data_) {
last_set_data_->time_offset_ = t;
}
}

View file

@ -10,6 +10,7 @@
#include "objectmodel.h"
#include "panel.h"
#include "vector3edit.h"
#include "viewer/mediapanel.h"
class MainWindow : public QMainWindow
@ -52,6 +53,12 @@ private:
QString current_filename_;
QGroupBox *properties_group_;
Vector3Edit *m_LocationEdit;
QSpinBox *start_time_edit_;
private slots:
void NewFile();
void OpenFile();
@ -69,6 +76,9 @@ private slots:
void ViewSIFile();
void LocationChanged(const si::Vector3 &v);
void StartTimeChanged(int t);
};
#endif // MAINWINDOW_H

View file

@ -9,30 +9,33 @@ Vector3Edit::Vector3Edit(QWidget *parent) :
{
auto layout = new QHBoxLayout(this);
layout->addWidget(new QLabel("X"));
layout->addWidget(new QLabel(tr("X")));
x_edit_ = new QDoubleSpinBox();
x_edit_->setMinimum(DBL_MIN);
x_edit_->setMaximum(DBL_MAX);
layout->addWidget(x_edit_);
connect(x_edit_, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &Vector3Edit::internalChanged);
layout->addStretch();
layout->addWidget(new QLabel("Y"));
layout->addWidget(new QLabel(tr("Y")));
y_edit_ = new QDoubleSpinBox();
y_edit_->setMinimum(DBL_MIN);
y_edit_->setMaximum(DBL_MAX);
layout->addWidget(y_edit_);
connect(y_edit_, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &Vector3Edit::internalChanged);
layout->addStretch();
layout->addWidget(new QLabel("Z"));
layout->addWidget(new QLabel(tr("Z")));
z_edit_ = new QDoubleSpinBox();
z_edit_->setMinimum(DBL_MIN);
z_edit_->setMaximum(DBL_MAX);
layout->addWidget(z_edit_);
connect(z_edit_, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this, &Vector3Edit::internalChanged);
}
si::Vector3 Vector3Edit::GetValue() const
@ -42,7 +45,20 @@ si::Vector3 Vector3Edit::GetValue() const
void Vector3Edit::SetValue(const si::Vector3 &xyz)
{
x_edit_->blockSignals(true);
y_edit_->blockSignals(true);
z_edit_->blockSignals(true);
x_edit_->setValue(xyz.x);
y_edit_->setValue(xyz.y);
z_edit_->setValue(xyz.z);
x_edit_->blockSignals(false);
y_edit_->blockSignals(false);
z_edit_->blockSignals(false);
}
void Vector3Edit::internalChanged()
{
emit changed(si::Vector3(x_edit_->value(), y_edit_->value(), z_edit_->value()));
}

View file

@ -15,11 +15,17 @@ public:
si::Vector3 GetValue() const;
void SetValue(const si::Vector3 &xyz);
signals:
void changed(const si::Vector3 &v);
private:
QDoubleSpinBox *x_edit_;
QDoubleSpinBox *y_edit_;
QDoubleSpinBox *z_edit_;
private slots:
void internalChanged();
};
#endif // VECTOR3EDIT_H

View file

@ -272,8 +272,8 @@ Object *Interleaf::ReadObject(FileBase *f, Object *o, std::stringstream &desc)
desc << "Duration: " << o->duration_ << std::endl;
o->loops_ = f->ReadU32();
desc << "Loops: " << o->loops_ << std::endl;
o->position_ = f->ReadVector3();
desc << "Position: " << o->position_.x << " " << o->position_.y << " " << o->position_.z << std::endl;
o->location_ = f->ReadVector3();
desc << "Location: " << o->location_.x << " " << o->location_.y << " " << o->location_.z << std::endl;
o->direction_ = f->ReadVector3();
desc << "Direction: " << o->direction_.x << " " << o->direction_.y << " " << o->direction_.z << std::endl;
o->up_ = f->ReadVector3();
@ -429,7 +429,7 @@ void Interleaf::WriteObject(FileBase *f, const Object *o) const
f->WriteU32(o->unknown4_);
f->WriteU32(o->duration_);
f->WriteU32(o->loops_);
f->WriteVector3(o->position_);
f->WriteVector3(o->location_);
f->WriteVector3(o->direction_);
f->WriteVector3(o->up_);

View file

@ -49,7 +49,7 @@ public:
uint32_t unknown4_;
uint32_t duration_;
uint32_t loops_;
Vector3 position_;
Vector3 location_;
Vector3 direction_;
Vector3 up_;
bytearray extra_;