}
}
- // NPC表情变化处理函数
+ // NPC表情变化处理函数(对话表情切换,不包含时间线状态表情)
void ThunderBirdModel::HandleNpcEmotionChange(const char* emotion)
{
//用string来接收表情
if(strlen(description) > 0 && strlen(emotion) > 0)
{
SetCurrentStatusText(description);
- SetCurrentExpression(emotion);
- SetCurrentExpressionAndStatus(); //更新当前表情和状态文本
+ SetCurrentExpressionAndStatus(std::string(emotion)); //更新当前表情和状态文本,表情成功切换后再更新当前表情
// // 标记时间线已获取,允许休眠
// ThunderBirdMainView::SetTimelineReceived(true);
}
// 同时设置当前表情和状态文本
- void ThunderBirdModel::SetCurrentExpressionAndStatus()
+ void ThunderBirdModel::SetCurrentExpressionAndStatus(const std::string& expression)
{
int currentView = ThunderBirdMainView::GetInstance()->GetCurrentView();
int currentSubView = ThunderBirdMainView::GetInstance()->GetCurrentSubView();
//切换表情
//不为屏保模式
std::string expressionPath;
+ std::string targetExpression = expression;
if(screenImageAsEmoji_ == false)
{
//获取当前角色配置
//为默认表情
if((eyesColor_.empty() == true || eyesShape_.empty() == true) || (eyesShape_ == "calm-eyes" && eyesColor_ == "amber"))
{
- std::string emotionFileName = MapEmotionToFileName(m_currentExpression.c_str());
+ std::string emotionFileName = MapEmotionToFileName(targetExpression.c_str());
expressionPath = "/user/res/video/Default/"+ emotionFileName + ".mp4";
- SwitchExpressionVideo(expressionPath.c_str());
- HandleHairIconChange(m_currentExpression);
+ bool switched = SwitchExpressionVideo(expressionPath.c_str());
+ if (switched) {
+ SetCurrentExpression(targetExpression);
+ HandleHairIconChange(targetExpression);
+ }
}
else//非默认表情
{
- if(m_currentExpression == "winking")//如果为眨眼表情,则在默认文件目录里面
+ if(targetExpression == "winking")//如果为眨眼表情,则在默认文件目录里面
{
expressionPath = "/user/res/video/CloseEyes/" + eyesShape_ + "/" + eyesColor_ + ".mp4";
}
else//非眨眼表情,则在下载文件目录里面
{
- if(m_currentExpression == "sleeping")
+ if(targetExpression == "sleeping")
{
expressionPath = "/user/res/video/Default/sleeping.mp4";
}
else
{
- expressionPath = "/user/userdata/leiniao/emoji/" + eyesShape_ + "/" + eyesColor_ + "/" + m_currentExpression + ".mp4";
+ expressionPath = "/user/userdata/leiniao/emoji/" + eyesShape_ + "/" + eyesColor_ + "/" + targetExpression + ".mp4";
}
}
//判断表情文件是否存在
if(access(expressionPath.c_str(), F_OK) != -1)
{
- SwitchExpressionVideo(expressionPath.c_str());
- HandleHairIconChange(m_currentExpression);
+ bool switched = SwitchExpressionVideo(expressionPath.c_str());
+ if (switched) {
+ SetCurrentExpression(targetExpression);
+ HandleHairIconChange(targetExpression);
+ }
}
else
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::not find expression file %s", m_currentExpression.c_str());
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::not find expression file %s", targetExpression.c_str());
+ // 当原始目标表情资源缺失时,若目标不是眨眼,则回退到眨眼表情,避免停留在睡觉/黑屏
+ if(targetExpression != "winking" && m_currentExpression != "winking") {
+ std::string fallbackWinking = "/user/res/video/CloseEyes/" + eyesShape_ + "/" + eyesColor_ + ".mp4";
+ if(access(fallbackWinking.c_str(), F_OK) != -1)
+ {
+ bool switched = SwitchExpressionVideo(fallbackWinking.c_str());
+ if (switched) {
+ SetCurrentExpression("winking"); // 仅在切换成功后更新当前表情
+ HandleHairIconChange("winking");
+ }
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::fallback to winking expression: %s, switched=%d", fallbackWinking.c_str(), switched);
+ }
+ else
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::fallback winking file missing: %s", fallbackWinking.c_str());
+ }
+ }
}
}