Add state test menu

This commit is contained in:
2026-05-28 11:08:58 +08:00
parent ece41bafc9
commit c5c29bd6cd
2 changed files with 36 additions and 0 deletions
+33
View File
@@ -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())
+3
View File
@@ -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);