|
| 1 | +/* |
| 2 | + This source file is part of Rigs of Rods |
| 3 | + Copyright 2016-2020 Petr Ohlidal |
| 4 | +
|
| 5 | + For more information, see http://www.rigsofrods.org/ |
| 6 | +
|
| 7 | + Rigs of Rods is free software: you can redistribute it and/or modify |
| 8 | + it under the terms of the GNU General Public License version 3, as |
| 9 | + published by the Free Software Foundation. |
| 10 | +
|
| 11 | + Rigs of Rods is distributed in the hope that it will be useful, |
| 12 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + GNU General Public License for more details. |
| 15 | +
|
| 16 | + You should have received a copy of the GNU General Public License |
| 17 | + along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>. |
| 18 | +*/ |
| 19 | + |
| 20 | + |
| 21 | +#include "GUI_CharacterPoseUtil.h" |
| 22 | + |
| 23 | +#include "Application.h" |
| 24 | +#include "Actor.h" |
| 25 | +#include "GameContext.h" |
| 26 | +#include "GfxCharacter.h" |
| 27 | +#include "GfxScene.h" |
| 28 | +#include "GUIManager.h" |
| 29 | +#include "Language.h" |
| 30 | + |
| 31 | +#include <Ogre.h> |
| 32 | + |
| 33 | +using namespace RoR; |
| 34 | +using namespace GUI; |
| 35 | +using namespace Ogre; |
| 36 | + |
| 37 | +void CharacterPoseUtil::Draw() |
| 38 | +{ |
| 39 | + Character* character = App::GetGameContext()->GetPlayerCharacter(); |
| 40 | + if (!character) |
| 41 | + { |
| 42 | + App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_ERROR, |
| 43 | + "no player character, closing CharacterPoseUtil"); |
| 44 | + this->SetVisible(false); |
| 45 | + return; |
| 46 | + } |
| 47 | + |
| 48 | + GfxCharacter* gfx_character = nullptr; |
| 49 | + for (GfxCharacter* xchar : App::GetGfxScene()->GetGfxCharacters()) |
| 50 | + { |
| 51 | + if (xchar->xc_character == character) |
| 52 | + gfx_character = xchar; |
| 53 | + } |
| 54 | + if (!gfx_character) |
| 55 | + { |
| 56 | + App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_ERROR, |
| 57 | + "no player character visuals, closing CharacterPoseUtil"); |
| 58 | + this->SetVisible(false); |
| 59 | + return; |
| 60 | + } |
| 61 | + |
| 62 | + Entity* ent = static_cast<Entity*>(gfx_character->xc_scenenode->getAttachedObject(0)); |
| 63 | + |
| 64 | + const int flags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_AlwaysAutoResize; |
| 65 | + bool keep_open = true; |
| 66 | + ImGui::Begin(_LC("CharacterPoseUtil", "Character pose utility"), &keep_open, flags); |
| 67 | + |
| 68 | + ImGui::Dummy(ImVec2(250, 1)); // force minimum width |
| 69 | + |
| 70 | + ImGui::Text("Character: '%s'", gfx_character->xc_instance_name.c_str()); |
| 71 | + ImGui::TextDisabled("(gray text means 'disabled')"); |
| 72 | + ImGui::Separator(); |
| 73 | + |
| 74 | + AnimationStateSet* stateset = ent->getAllAnimationStates(); |
| 75 | + for (auto& state_pair : stateset->getAnimationStates()) |
| 76 | + { |
| 77 | + AnimationState* as = state_pair.second; |
| 78 | + ImVec4 color = (as->getEnabled()) ? ImGui::GetStyle().Colors[ImGuiCol_Text] : ImGui::GetStyle().Colors[ImGuiCol_TextDisabled]; |
| 79 | + ImGui::TextColored(color, "'%s' (%.2f sec)", as->getAnimationName().c_str(), as->getLength()); |
| 80 | + std::string caption = fmt::format("{:.2f} sec", as->getTimePosition()); |
| 81 | + ImGui::ProgressBar(as->getTimePosition() / as->getLength(), ImVec2(-1, 0), caption.c_str()); |
| 82 | + } |
| 83 | + |
| 84 | + // Common window epilogue: |
| 85 | + |
| 86 | + m_is_hovered = ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows); |
| 87 | + App::GetGuiManager()->RequestGuiCaptureKeyboard(m_is_hovered); |
| 88 | + |
| 89 | + ImGui::End(); |
| 90 | + if (!keep_open) |
| 91 | + { |
| 92 | + this->SetVisible(false); |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | +void CharacterPoseUtil::SetVisible(bool v) |
| 97 | +{ |
| 98 | + m_is_visible = v; |
| 99 | + m_is_hovered = false; |
| 100 | +} |
0 commit comments