Add state test menu
This commit is contained in:
@@ -59,6 +59,8 @@ void PetWindow::contextMenuEvent(QContextMenuEvent *event)
|
||||
topAction->setCheckable(true);
|
||||
topAction->setChecked(m_alwaysOnTop);
|
||||
|
||||
addStateTestActions(&menu);
|
||||
|
||||
menu.addSeparator();
|
||||
QAction *exitAction = menu.addAction(QStringLiteral("退出"));
|
||||
|
||||
@@ -71,6 +73,10 @@ void PetWindow::contextMenuEvent(QContextMenuEvent *event)
|
||||
{
|
||||
close();
|
||||
}
|
||||
else if (selectedAction != nullptr && selectedAction->data().isValid())
|
||||
{
|
||||
playState(selectedAction->data().toString(), false);
|
||||
}
|
||||
}
|
||||
|
||||
void PetWindow::mouseMoveEvent(QMouseEvent *event)
|
||||
@@ -125,6 +131,33 @@ void PetWindow::loadInitialImage()
|
||||
setDisplayImage(previewImagePath(), true);
|
||||
}
|
||||
|
||||
void PetWindow::addStateTestActions(QMenu *menu)
|
||||
{
|
||||
QMenu *stateMenu = menu->addMenu(QStringLiteral("State Test"));
|
||||
const QStringList stateNames = {
|
||||
QStringLiteral("idle"),
|
||||
QStringLiteral("talk"),
|
||||
QStringLiteral("think"),
|
||||
QStringLiteral("sleep"),
|
||||
QStringLiteral("happy"),
|
||||
QStringLiteral("error"),
|
||||
QStringLiteral("drag"),
|
||||
};
|
||||
|
||||
for (const QString &stateName : stateNames)
|
||||
{
|
||||
if (!m_characterPackage.hasState(stateName))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
QAction *stateAction = stateMenu->addAction(stateName);
|
||||
stateAction->setData(stateName);
|
||||
}
|
||||
|
||||
stateMenu->setEnabled(!stateMenu->actions().isEmpty());
|
||||
}
|
||||
|
||||
void PetWindow::playState(const QString &stateName, bool centerWindow)
|
||||
{
|
||||
if (m_currentStateName == stateName && !m_currentFrames.isEmpty())
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include <QTimer>
|
||||
#include <QWidget>
|
||||
|
||||
class QMenu;
|
||||
|
||||
class PetWindow : public QWidget
|
||||
{
|
||||
public:
|
||||
@@ -21,6 +23,7 @@ protected:
|
||||
|
||||
private:
|
||||
void loadInitialImage();
|
||||
void addStateTestActions(QMenu *menu);
|
||||
void playState(const QString &stateName, bool centerWindow);
|
||||
void advanceStateFrame();
|
||||
void setDisplayImage(const QString &imagePath, bool centerWindow);
|
||||
|
||||
Reference in New Issue
Block a user