Skip to content

Commit cc1adf1

Browse files
committed
New UI: CharacterPoseUtil - displays anim states
1 parent a040eda commit cc1adf1

7 files changed

Lines changed: 165 additions & 5 deletions

File tree

source/main/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ set(SOURCE_FILES
117117
gui/imgui/imstb_textedit.h
118118
gui/imgui/imstb_truetype.h
119119
gui/panels/GUI_AngelScriptExamples.{h,cpp}
120+
gui/panels/GUI_CharacterPoseUtil.{h,cpp}
120121
gui/panels/GUI_ConsoleView.{h,cpp}
121122
gui/panels/GUI_ConsoleWindow.{h,cpp}
122123
gui/panels/GUI_DirectionArrow.{h,cpp}

source/main/gfx/GfxCharacter.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,16 @@ void RoR::GfxCharacter::UpdateCharacterInScene()
148148

149149
// Reset all anims
150150

151-
AnimationStateIterator it = entity->getAllAnimationStates()->getAnimationStateIterator();
152-
LOG(fmt::format("file:{}, line:{}, func:{}, resetting all animations before update", __FILE__, __LINE__, __FUNCTION__ ));
153-
while (it.hasMoreElements())
151+
152+
LOG(fmt::format("file:{}, line:{}, func:{}, resetting all animations before update", __FILE__, __LINE__, __FUNCTION__));
153+
AnimationStateSet* stateset = entity->getAllAnimationStates();
154+
for (auto& state_pair: stateset->getAnimationStates())
154155
{
155-
AnimationState* as = it.getNext();
156+
AnimationState* as = state_pair.second;
156157
as->setEnabled(false);
157158
as->setWeight(0);
158159
LOG(fmt::format("\tanim '{}' was reset", as->getAnimationName()));
159-
}
160+
}
160161

161162
// upper body anim
162163
if (xc_simbuf.simbuf_anim_upper_name != "")

source/main/gui/GUIManager.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ bool GUIManager::AreStaticMenusAllowed() //!< i.e. top menubar / vehicle UI butt
114114
{
115115
return (App::GetCameraManager()->GetCurrentBehavior() != CameraManager::CAMERA_BEHAVIOR_FREE &&
116116
!App::GetGuiManager()->ConsoleWindow.IsHovered() &&
117+
!App::GetGuiManager()->CharacterPoseUtil.IsHovered() &&
117118
!App::GetGuiManager()->GameControls.IsHovered() &&
118119
!App::GetGuiManager()->FrictionSettings.IsHovered() &&
119120
!App::GetGuiManager()->TextureToolWindow.IsHovered() &&
@@ -178,6 +179,11 @@ void GUIManager::DrawSimGuiBuffered(GfxActor* player_gfx_actor)
178179
this->FrictionSettings.Draw();
179180
}
180181

182+
if (this->CharacterPoseUtil.IsVisible())
183+
{
184+
this->CharacterPoseUtil.Draw();
185+
}
186+
181187
if (this->VehicleDescription.IsVisible())
182188
{
183189
this->VehicleDescription.Draw();

source/main/gui/GUIManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
// GUI panels
3232
#include "GUI_ConsoleWindow.h"
33+
#include "GUI_CharacterPoseUtil.h"
3334
#include "GUI_FrictionSettings.h"
3435
#include "GUI_RepositorySelector.h"
3536
#include "GUI_GameMainMenu.h"
@@ -100,6 +101,7 @@ class GUIManager: public ZeroedMemoryAllocator
100101
~GUIManager();
101102

102103

104+
GUI::CharacterPoseUtil CharacterPoseUtil;
103105
GUI::GameMainMenu GameMainMenu;
104106
GUI::GameAbout GameAbout;
105107
GUI::GameSettings GameSettings;
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
#pragma once
21+
22+
#include "Application.h"
23+
#include "OgreImGui.h"
24+
25+
namespace RoR {
26+
namespace GUI {
27+
28+
class CharacterPoseUtil
29+
{
30+
public:
31+
void Draw();
32+
33+
void SetVisible(bool visible);
34+
bool IsVisible() const { return m_is_visible; }
35+
bool IsHovered() const { return IsVisible() && m_is_hovered; }
36+
37+
private:
38+
bool m_is_visible = false;
39+
bool m_is_hovered = false;
40+
41+
};
42+
43+
} // namespace GUI
44+
} // namespace RoR

source/main/gui/panels/GUI_TopMenubar.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,12 @@ void TopMenubar::Update()
547547
m_open_menu = TopMenu::TOPMENU_NONE;
548548
}
549549

550+
if (ImGui::Button(_LC("TopMenubar", "Character pose util")))
551+
{
552+
App::GetGuiManager()->CharacterPoseUtil.SetVisible(true);
553+
m_open_menu = TopMenu::TOPMENU_NONE;
554+
}
555+
550556
if (current_actor != nullptr)
551557
{
552558
if (ImGui::Button(_LC("TopMenubar", "Node / Beam utility")))

0 commit comments

Comments
 (0)