Skip to content

Commit

Permalink
Make Convert To Frame window convert multiple animations at once
Browse files Browse the repository at this point in the history
The Convert To Frame window allows converting skeletal animations to
frame animations. It would prompt for each animation which was annoying
when converting 25 skeletal animations for a Quake 3 player to frame
animations for exporting as MD3.

I changed the Convert To Frame window to displayed all the selected
skeletal animations in a table with edit fields for frame animation
name and frame count. This allows all frame animations to be edited
at once and converted with a single click.
  • Loading branch information
zturtleman committed Apr 23, 2019
1 parent eb67213 commit 65449c9
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 243 deletions.
23 changes: 8 additions & 15 deletions doc/html/olh_animconvertwin.htm
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ <h1>Convert To Frame Window</h1>
<p>
The <b>Convert To Frame Window</b> will take the currently selected
animations in the <a href="olh_animsetwin.html">Animation Sets Window</a> and convert them into
frame animations. You will be prompted with this window once for every
skeletal animation you have selected. The original animations remain
unmodified.
frame animations. You will be presented with a list of the selected
skeletal animations with options for their conversion. The original
animations remain unmodified.
</p>

<p>
Expand All @@ -15,7 +15,7 @@ <h1>Convert To Frame Window</h1>
</p>

<p>
Provide a name for the frame animation in the <b>Frame Anim Name</b>
Provide a name for the frame animation in the <b>Frame Animation</b>
text box. The name can be the same as the skeletal animation.
</p>

Expand All @@ -38,18 +38,11 @@ <h1>Convert To Frame Window</h1>
</p>

<p>
The <b>Continue</b> button will convert the current skeletal
animation to a frame animation. If you have more skeletal
animations selected you will be prompted with the convert
window once for each of them.
The <b>Convert</b> button will convert the skeletal animations
to frame animations.
</p>

<p>
The <b>Cancel</b> button will cancel the conversion of one
animation.
</p>

<p>
The <b>Cancel All</b> button will cancel the conversion of all
remaining animations.
The <b>Cancel</b> button will cancel the conversion of the
animations.
</p>
133 changes: 104 additions & 29 deletions src/implui/animconvertwin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,77 +30,152 @@
#include <QtWidgets/QSpinBox>
#include <QtWidgets/QLineEdit>

#define COLUMN_ORIGINALNAME 0
#define COLUMN_NAME 1
#define COLUMN_FRAMECOUNT 2

AnimConvertFrameCountDelegate::AnimConvertFrameCountDelegate( QObject *parent )
: QStyledItemDelegate( parent )
{
}

QWidget *AnimConvertFrameCountDelegate::createEditor( QWidget *parent,
const QStyleOptionViewItem &/* option */,
const QModelIndex &/* index */ ) const
{
QSpinBox *editor = new QSpinBox( parent );
editor->setFrame( false );
editor->setMinimum( 0 );
editor->setMaximum( 99 );

return editor;
}

void AnimConvertFrameCountDelegate::setEditorData( QWidget *editor,
const QModelIndex &index ) const
{
int value = index.model()->data( index, Qt::EditRole ).toInt();

QSpinBox *spinBox = static_cast<QSpinBox*>( editor );
spinBox->setValue( value );
}

void AnimConvertFrameCountDelegate::setModelData( QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index ) const
{
QSpinBox *spinBox = static_cast<QSpinBox*>( editor );
spinBox->interpretText();
int value = spinBox->value();

model->setData( index, value, Qt::EditRole );
}

void AnimConvertFrameCountDelegate::updateEditorGeometry( QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &/* index */ ) const
{
editor->setGeometry( option.rect );
}


AnimConvertWindow::AnimConvertWindow( QWidget * parent )
: QDialog( parent ),
m_operation( OP_CONTINUE )
m_frameCountDelegate( NULL ),
m_model( NULL ),
m_mode( Model::AnimationModeE::ANIMMODE_NONE ),
m_animIndicies()
{
setupUi( this );
setModal( true );

QShortcut * help = new QShortcut( QKeySequence( tr("F1", "Help Shortcut")), this );
connect( help, SIGNAL(activated()), this, SLOT(helpNowEvent()) );

m_frameCountDelegate = new AnimConvertFrameCountDelegate();
m_animTable->setItemDelegateForColumn( COLUMN_FRAMECOUNT, m_frameCountDelegate );
m_animTable->horizontalHeader()->resizeSection( COLUMN_ORIGINALNAME, 200 );
m_animTable->horizontalHeader()->resizeSection( COLUMN_NAME, 200 );
m_animTable->horizontalHeader()->resizeSection( COLUMN_FRAMECOUNT, 30 );
m_animTable->setSelectionMode( QAbstractItemView::SelectionMode::NoSelection );
m_animTable->setEditTriggers( QAbstractItemView::CurrentChanged );
}

AnimConvertWindow::~AnimConvertWindow()
{
}

void AnimConvertWindow::setAnimationData( Model * model, Model::AnimationModeE mode, unsigned animIndex )
void AnimConvertWindow::setAnimationData( Model * model, Model::AnimationModeE mode, const std::list<unsigned> & animIndicies )
{
switch ( mode )
m_model = model;
m_mode = mode;
m_animIndicies = animIndicies;

switch ( m_mode )
{
case Model::ANIMMODE_SKELETAL:
m_convertLabel->setText( tr( "Convert Skeletal to Frame:" ) );
m_animTable->horizontalHeaderItem( COLUMN_ORIGINALNAME )->setText( tr( "Skeletal Animation" ) );
break;
case Model::ANIMMODE_FRAME:
m_convertLabel->setText( tr( "Convert Frame to Frame:" ) );
m_animTable->horizontalHeaderItem( COLUMN_ORIGINALNAME )->setText( tr( "Frame Animation" ) );
break;
case Model::ANIMMODE_FRAMERELATIVE:
m_convertLabel->setText( tr( "Convert Frame Relative to Frame:" ) );
m_animTable->horizontalHeaderItem( COLUMN_ORIGINALNAME )->setText( tr( "Frame Relative Animation" ) );
break;
default:
m_convertLabel->setText( tr( "Convert Unknown Type to Frame:" ) );
m_animTable->horizontalHeaderItem( COLUMN_ORIGINALNAME )->setText( tr( "Unknown Type Animation" ) );
break;
}

const char * name = model->getAnimName( mode, animIndex );
m_origName->setText( QString::fromUtf8( name ) );
m_newName->setText( QString::fromUtf8( name ) );
m_newFrameCount->setValue( model->getAnimFrameCount( mode, animIndex ) );
m_animTable->setRowCount( m_animIndicies.size() );

m_origName->setFocus();
}
unsigned row = 0;
std::list<unsigned>::iterator it;

QString AnimConvertWindow::getNewName()
{
return m_newName->text();
}
for ( it = m_animIndicies.begin(), row = 0; it != m_animIndicies.end(); it++, row++ ) {
unsigned t = *it;
const char * name = m_model->getAnimName( m_mode, t );
unsigned frameCount = m_model->getAnimFrameCount( m_mode, t );

unsigned AnimConvertWindow::getNewFrameCount()
{
return m_newFrameCount->value();
}
QTableWidgetItem *originalNameItem = new QTableWidgetItem( QString::fromUtf8( name ) );
originalNameItem->setFlags( originalNameItem->flags() & ~Qt::ItemIsEditable );
m_animTable->setItem( row, COLUMN_ORIGINALNAME, originalNameItem );

AnimConvertWindow::OperationE AnimConvertWindow::requestedOperation()
{
return m_operation;
QTableWidgetItem *nameItem = new QTableWidgetItem( QString::fromUtf8( name ) );
m_animTable->setItem( row, COLUMN_NAME, nameItem );

QString frameCountText;
frameCountText.setNum( frameCount );

QTableWidgetItem *frameCountItem = new QTableWidgetItem( frameCountText );
m_animTable->setItem( row, COLUMN_FRAMECOUNT, frameCountItem );
}
}

void AnimConvertWindow::continueClicked()
void AnimConvertWindow::convertClicked()
{
m_operation = OP_CONTINUE;
unsigned row = 0;
std::list<unsigned>::iterator it;

for ( it = m_animIndicies.begin(), row = 0; it != m_animIndicies.end(); it++, row++ ) {
unsigned t = *it;

QTableWidgetItem *nameItem = m_animTable->item( row, COLUMN_NAME );
QString newName = nameItem->text();

QTableWidgetItem *frameCountItem = m_animTable->item( row, COLUMN_FRAMECOUNT );
unsigned newFrameCount = frameCountItem->text().toInt();

m_model->convertAnimToFrame( m_mode, t, newName.toUtf8().data(), newFrameCount );
}

accept();
}

void AnimConvertWindow::cancelClicked()
{
m_operation = OP_CANCEL;
reject();
}

void AnimConvertWindow::cancelAllClicked()
{
m_operation = OP_CANCEL_ALL;
reject();
}

Expand Down
43 changes: 24 additions & 19 deletions src/implui/animconvertwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,44 +27,49 @@

#include "model.h"

#include <QtWidgets/QStyledItemDelegate>
#include <QtWidgets/QDialog>

class Q3Accel;
class AnimConvertFrameCountDelegate : public QStyledItemDelegate
{
Q_OBJECT

public:
AnimConvertFrameCountDelegate( QObject *parent = NULL );

QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index ) const override;

void setEditorData( QWidget *editor, const QModelIndex &index ) const override;
void setModelData( QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index ) const override;

void updateEditorGeometry( QWidget *editor, const QStyleOptionViewItem &option,
const QModelIndex &index ) const override;
};

class AnimConvertWindow : public QDialog, public Ui::AnimConvertWinBase
{
Q_OBJECT

public:
enum _Operation_e
{
OP_CONTINUE,
OP_CANCEL,
OP_CANCEL_ALL
};
typedef enum _Operation_e OperationE;

AnimConvertWindow( QWidget * parent = NULL );
virtual ~AnimConvertWindow();

void setAnimationData( Model * model, Model::AnimationModeE mode, unsigned animIndex );

QString getNewName();
unsigned getNewFrameCount();

OperationE requestedOperation();
void setAnimationData( Model * model, Model::AnimationModeE mode, const std::list<unsigned> & animIndicies );

public slots:
void helpNowEvent();

void continueClicked();
void convertClicked();
void cancelClicked();
void cancelAllClicked();

protected:
Q3Accel * m_accel;
AnimConvertFrameCountDelegate *m_frameCountDelegate;

OperationE m_operation;
Model *m_model;
Model::AnimationModeE m_mode;
std::list<unsigned> m_animIndicies;
};

#endif // __ANIMCONVERTWIN_H
32 changes: 8 additions & 24 deletions src/implui/animsetwin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -555,37 +555,21 @@ void AnimSetWindow::mergeClicked()
void AnimSetWindow::convertClicked()
{
Model::AnimationModeE mode = indexToMode( m_animType->currentIndex() );
bool cancelled = false;

unsigned count = m_animList->count();
std::list<unsigned> animIndicies;

for ( unsigned t = 0; !cancelled && t < count; t++ )
for ( unsigned t = 0; t < count; t++ )
{
if ( m_animList->item(t)->isSelected() )
{
AnimConvertWindow acw( this );

acw.setAnimationData( m_model, mode, t );
acw.exec();

switch ( acw.requestedOperation() )
{
case AnimConvertWindow::OP_CONTINUE:
{
QString name = acw.getNewName();
unsigned frameCount = acw.getNewFrameCount();

m_model->convertAnimToFrame( mode, t, name.toUtf8(), frameCount );
}
break;
case AnimConvertWindow::OP_CANCEL:
break;
case AnimConvertWindow::OP_CANCEL_ALL:
cancelled = true;
break;
}
animIndicies.push_back( t );
}
}

AnimConvertWindow acw( this );

acw.setAnimationData( m_model, mode, animIndicies );
acw.exec();
}

void AnimSetWindow::accept()
Expand Down
Loading

0 comments on commit 65449c9

Please sign in to comment.