refactored aocharmovie.cpp and added flipping implementation
This commit is contained in:
		
							parent
							
								
									d318f1a241
								
							
						
					
					
						commit
						3c569d727a
					
				@ -5,12 +5,14 @@
 | 
				
			|||||||
#include "aoapplication.h"
 | 
					#include "aoapplication.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <QDebug>
 | 
					#include <QDebug>
 | 
				
			||||||
 | 
					#include <QImageReader>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
AOCharMovie::AOCharMovie(QWidget *p_parent, AOApplication *p_ao_app) : QLabel(p_parent)
 | 
					AOCharMovie::AOCharMovie(QWidget *p_parent, AOApplication *p_ao_app) : QLabel(p_parent)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  ao_app = p_ao_app;
 | 
					  ao_app = p_ao_app;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  m_movie = new QMovie(this);
 | 
					  m_movie = new QMovie(this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  preanim_timer = new QTimer(this);
 | 
					  preanim_timer = new QTimer(this);
 | 
				
			||||||
  preanim_timer->setSingleShot(true);
 | 
					  preanim_timer->setSingleShot(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -20,56 +22,59 @@ AOCharMovie::AOCharMovie(QWidget *p_parent, AOApplication *p_ao_app) : QLabel(p_
 | 
				
			|||||||
  connect(preanim_timer, SIGNAL(timeout()), this, SLOT(preanim_done()));
 | 
					  connect(preanim_timer, SIGNAL(timeout()), this, SLOT(preanim_done()));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void AOCharMovie::play_pre(QString p_char, QString p_emote, int duration)
 | 
					void AOCharMovie::play(QString p_char, QString p_emote, QString emote_prefix)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  m_movie->stop();
 | 
					  QString original_path = ao_app->get_character_path(p_char) + emote_prefix + p_emote.toLower() + ".gif";
 | 
				
			||||||
 | 
					 | 
				
			||||||
  QString pre_path = ao_app->get_character_path(p_char) + p_emote.toLower() + ".gif";
 | 
					 | 
				
			||||||
  QString placeholder_path = ao_app->get_theme_path() + "placeholder.gif";
 | 
					  QString placeholder_path = ao_app->get_theme_path() + "placeholder.gif";
 | 
				
			||||||
 | 
					  QString gif_path;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (file_exists(pre_path))
 | 
					  if (file_exists(original_path))
 | 
				
			||||||
    m_movie->setFileName(pre_path);
 | 
					    gif_path = original_path;
 | 
				
			||||||
  else
 | 
					  else
 | 
				
			||||||
    m_movie->setFileName(placeholder_path);
 | 
					    gif_path = placeholder_path;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  m_movie->stop();
 | 
				
			||||||
 | 
					  this->clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  m_movie->setFileName(gif_path);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (m_flipped)
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    QImageReader *reader = new QImageReader(gif_path);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    flipped_movie.clear();
 | 
				
			||||||
 | 
					    QImage f_image = reader->read();
 | 
				
			||||||
 | 
					    while (!f_image.isNull())
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      flipped_movie.append(f_image.mirrored(true, false));
 | 
				
			||||||
 | 
					      f_image = reader->read();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    delete reader;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  else
 | 
				
			||||||
 | 
					  {
 | 
				
			||||||
 | 
					    this->setMovie(m_movie);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  this->show();
 | 
					  this->show();
 | 
				
			||||||
  m_movie->start();
 | 
					  m_movie->start();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AOCharMovie::play_pre(QString p_char, QString p_emote, int duration)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					  play(p_char, p_emote, "");
 | 
				
			||||||
  preanim_timer->start(duration);
 | 
					  preanim_timer->start(duration);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void AOCharMovie::play_talking(QString p_char, QString p_emote)
 | 
					void AOCharMovie::play_talking(QString p_char, QString p_emote)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  m_movie->stop();
 | 
					  play(p_char, p_emote, "(b)");
 | 
				
			||||||
 | 
					 | 
				
			||||||
  QString talking_path = ao_app->get_character_path(p_char) + "(b)" + p_emote.toLower() + ".gif";
 | 
					 | 
				
			||||||
  QString placeholder_path = ao_app->get_theme_path() + "placeholder.gif";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (file_exists(talking_path))
 | 
					 | 
				
			||||||
    m_movie->setFileName(talking_path);
 | 
					 | 
				
			||||||
  else
 | 
					 | 
				
			||||||
    m_movie->setFileName(placeholder_path);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  this->show();
 | 
					 | 
				
			||||||
  m_movie->start();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  //D3bug
 | 
					 | 
				
			||||||
  m_movie->
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void AOCharMovie::play_idle(QString p_char, QString p_emote)
 | 
					void AOCharMovie::play_idle(QString p_char, QString p_emote)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  m_movie->stop();
 | 
					  play(p_char, p_emote, "(a)");
 | 
				
			||||||
 | 
					 | 
				
			||||||
  QString idle_path = ao_app->get_character_path(p_char) + "(a)" + p_emote.toLower() + ".gif";
 | 
					 | 
				
			||||||
  QString placeholder_path = ao_app->get_theme_path() + "placeholder.gif";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  if (file_exists(idle_path))
 | 
					 | 
				
			||||||
    m_movie->setFileName(idle_path);
 | 
					 | 
				
			||||||
  else
 | 
					 | 
				
			||||||
    m_movie->setFileName(placeholder_path);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  this->show();
 | 
					 | 
				
			||||||
  m_movie->start();
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void AOCharMovie::stop()
 | 
					void AOCharMovie::stop()
 | 
				
			||||||
@ -88,8 +93,8 @@ void AOCharMovie::combo_resize(int w, int h)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void AOCharMovie::frame_change(int n_frame)
 | 
					void AOCharMovie::frame_change(int n_frame)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  //we'll need this later
 | 
					  if (m_flipped && flipped_movie.size() > n_frame)
 | 
				
			||||||
  ++n_frame;
 | 
					    this->setPixmap(QPixmap::fromImage(flipped_movie.at(n_frame)));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void AOCharMovie::preanim_done()
 | 
					void AOCharMovie::preanim_done()
 | 
				
			||||||
 | 
				
			|||||||
@ -14,10 +14,13 @@ class AOCharMovie : public QLabel
 | 
				
			|||||||
public:
 | 
					public:
 | 
				
			||||||
  AOCharMovie(QWidget *p_parent, AOApplication *p_ao_app);
 | 
					  AOCharMovie(QWidget *p_parent, AOApplication *p_ao_app);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  void play(QString p_char, QString p_emote, QString emote_prefix);
 | 
				
			||||||
  void play_pre(QString p_char, QString p_emote, int duration);
 | 
					  void play_pre(QString p_char, QString p_emote, int duration);
 | 
				
			||||||
  void play_talking(QString p_char, QString p_emote);
 | 
					  void play_talking(QString p_char, QString p_emote);
 | 
				
			||||||
  void play_idle(QString p_char, QString p_emote);
 | 
					  void play_idle(QString p_char, QString p_emote);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  void set_flipped(bool p_flipped) {m_flipped = p_flipped;}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void stop();
 | 
					  void stop();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void combo_resize(int w, int h);
 | 
					  void combo_resize(int w, int h);
 | 
				
			||||||
@ -26,8 +29,11 @@ private:
 | 
				
			|||||||
  AOApplication *ao_app;
 | 
					  AOApplication *ao_app;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  QMovie *m_movie;
 | 
					  QMovie *m_movie;
 | 
				
			||||||
 | 
					  QVector<QImage> flipped_movie;
 | 
				
			||||||
  QTimer *preanim_timer;
 | 
					  QTimer *preanim_timer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  bool m_flipped = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
signals:
 | 
					signals:
 | 
				
			||||||
  void done();
 | 
					  void done();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user