| 99 | } |
| 100 | |
| 101 | void AiInterface::update(float dt) { |
| 102 | if (!m_client->playerOnOwnShip()) |
| 103 | dismiss(); |
| 104 | |
| 105 | Pane::update(dt); |
| 106 | |
| 107 | m_showCrewButton->setVisibility(m_currentPage == AiPages::StatusPage); |
| 108 | m_showMissionsButton->setVisibility(m_currentPage == AiPages::StatusPage); |
| 109 | m_backButton->setVisibility(m_currentPage != AiPages::StatusPage); |
| 110 | |
| 111 | m_staticAnimation.update(dt); |
| 112 | m_scanlineAnimation.update(dt); |
| 113 | |
| 114 | if (m_currentSpeech) { |
| 115 | m_textLength += m_currentSpeech->speedModifier * m_aiDatabase->charactersPerSecond() * dt; |
| 116 | m_currentTextWidget->setText(m_currentSpeech->text); |
| 117 | m_currentTextWidget->setTextCharLimit(min(m_textMaxLength, floor(m_textLength))); |
| 118 | |
| 119 | if (m_textLength < m_textMaxLength) { |
| 120 | setFaceAnimation(m_currentSpeech->animation); |
| 121 | if (!m_chatterSound || m_chatterSound->finished()) { |
| 122 | auto assets = Root::singleton().assets(); |
| 123 | m_chatterSound = make_shared<AudioInstance>(*assets->audio(assets->json("/interface/ai/ai.config:chatterSound").toString())); |
| 124 | m_chatterSound->setLoops(-1); |
| 125 | GuiContext::singleton().playAudio(m_chatterSound); |
| 126 | } |
| 127 | } else { |
| 128 | setFaceAnimation("idle"); |
| 129 | if (m_chatterSound) |
| 130 | m_chatterSound->stop(); |
| 131 | } |
| 132 | m_faceAnimation.second.update(dt * m_currentSpeech->speedModifier); |
| 133 | } else { |
| 134 | setFaceAnimation("idle"); |
| 135 | m_faceAnimation.second.update(dt); |
| 136 | if (m_chatterSound) |
| 137 | m_chatterSound->stop(); |
| 138 | } |
| 139 | |
| 140 | // If the enabled missions list changes, update the mission list |
| 141 | auto aiState = m_client->mainPlayer()->aiState(); |
| 142 | if (aiState.availableMissions.values() != m_availableMissions |
| 143 | || aiState.completedMissions.values() != m_completedMissions) { |
| 144 | m_availableMissions = aiState.availableMissions.values(); |
| 145 | m_completedMissions = aiState.completedMissions.values(); |
| 146 | populateMissions(); |
| 147 | } |
| 148 | |
| 149 | auto crew = m_client->mainPlayer()->companions()->getCompanions("crew"); |
| 150 | if (crew != m_crew) { |
| 151 | m_crew = crew; |
| 152 | populateCrew(); |
| 153 | } |
| 154 | |
| 155 | m_aiFaceCanvasWidget->clear(); |
| 156 | m_aiFaceCanvasWidget->drawDrawable(m_faceAnimation.second.drawable(1.0f), Vec2F(0, 0)); |
| 157 | m_aiFaceCanvasWidget->drawDrawable(m_staticAnimation.drawable(1.0f), Vec2F(0, 0)); |
| 158 | m_aiFaceCanvasWidget->drawDrawable(m_scanlineAnimation.drawable(1.0f), Vec2F(0, 0)); |
nothing calls this directly
no test coverage detected