Skip to content

Commit

Permalink
New UI: CharacterPoseUtil - displays anim states
Browse files Browse the repository at this point in the history
  • Loading branch information
ohlidalp committed Sep 19, 2022
1 parent 50c667b commit 5ec548a
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 5 deletions.
1 change: 1 addition & 0 deletions source/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ set(SOURCE_FILES
gui/imgui/imstb_textedit.h
gui/imgui/imstb_truetype.h
gui/panels/GUI_AngelScriptExamples.{h,cpp}
gui/panels/GUI_CharacterPoseUtil.{h,cpp}
gui/panels/GUI_CollisionsDebug.{h,cpp}
gui/panels/GUI_ConsoleView.{h,cpp}
gui/panels/GUI_ConsoleWindow.{h,cpp}
Expand Down
11 changes: 6 additions & 5 deletions source/main/gfx/GfxCharacter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,16 @@ void RoR::GfxCharacter::UpdateCharacterInScene()

// Reset all anims

AnimationStateIterator it = entity->getAllAnimationStates()->getAnimationStateIterator();
LOG(fmt::format("file:{}, line:{}, func:{}, resetting all animations before update", __FILE__, __LINE__, __FUNCTION__ ));
while (it.hasMoreElements())

LOG(fmt::format("file:{}, line:{}, func:{}, resetting all animations before update", __FILE__, __LINE__, __FUNCTION__));
AnimationStateSet* stateset = entity->getAllAnimationStates();
for (auto& state_pair: stateset->getAnimationStates())
{
AnimationState* as = it.getNext();
AnimationState* as = state_pair.second;
as->setEnabled(false);
as->setWeight(0);
LOG(fmt::format("\tanim '{}' was reset", as->getAnimationName()));
}
}

// upper body anim
if (xc_simbuf.simbuf_anim_upper_name != "")
Expand Down
6 changes: 6 additions & 0 deletions source/main/gui/GUIManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ bool GUIManager::AreStaticMenusAllowed() //!< i.e. top menubar / vehicle UI butt
{
return (App::GetCameraManager()->GetCurrentBehavior() != CameraManager::CAMERA_BEHAVIOR_FREE &&
!App::GetGuiManager()->ConsoleWindow.IsHovered() &&
!App::GetGuiManager()->CharacterPoseUtil.IsHovered() &&
!App::GetGuiManager()->GameControls.IsHovered() &&
!App::GetGuiManager()->FrictionSettings.IsHovered() &&
!App::GetGuiManager()->TextureToolWindow.IsHovered() &&
Expand Down Expand Up @@ -184,6 +185,11 @@ void GUIManager::DrawSimGuiBuffered(GfxActor* player_gfx_actor)
this->FrictionSettings.Draw();
}

if (this->CharacterPoseUtil.IsVisible())
{
this->CharacterPoseUtil.Draw();
}

if (this->VehicleDescription.IsVisible())
{
this->VehicleDescription.Draw();
Expand Down
2 changes: 2 additions & 0 deletions source/main/gui/GUIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
// GUI panels
#include "GUI_CollisionsDebug.h"
#include "GUI_ConsoleWindow.h"
#include "GUI_CharacterPoseUtil.h"
#include "GUI_FrictionSettings.h"
#include "GUI_RepositorySelector.h"
#include "GUI_GameMainMenu.h"
Expand Down Expand Up @@ -101,6 +102,7 @@ class GUIManager: public ZeroedMemoryAllocator
~GUIManager();


GUI::CharacterPoseUtil CharacterPoseUtil;
GUI::CollisionsDebug CollisionsDebug;
GUI::GameMainMenu GameMainMenu;
GUI::GameAbout GameAbout;
Expand Down
100 changes: 100 additions & 0 deletions source/main/gui/panels/GUI_CharacterPoseUtil.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
This source file is part of Rigs of Rods
Copyright 2016-2020 Petr Ohlidal
For more information, see http://www.rigsofrods.org/
Rigs of Rods is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3, as
published by the Free Software Foundation.
Rigs of Rods is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
*/


#include "GUI_CharacterPoseUtil.h"

#include "Application.h"
#include "Actor.h"
#include "GameContext.h"
#include "GfxCharacter.h"
#include "GfxScene.h"
#include "GUIManager.h"
#include "Language.h"

#include <Ogre.h>

using namespace RoR;
using namespace GUI;
using namespace Ogre;

void CharacterPoseUtil::Draw()
{
Character* character = App::GetGameContext()->GetPlayerCharacter();
if (!character)
{
App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_ERROR,
"no player character, closing CharacterPoseUtil");
this->SetVisible(false);
return;
}

GfxCharacter* gfx_character = nullptr;
for (GfxCharacter* xchar : App::GetGfxScene()->GetGfxCharacters())
{
if (xchar->xc_character == character)
gfx_character = xchar;
}
if (!gfx_character)
{
App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_INFO, Console::CONSOLE_SYSTEM_ERROR,
"no player character visuals, closing CharacterPoseUtil");
this->SetVisible(false);
return;
}

Entity* ent = static_cast<Entity*>(gfx_character->xc_scenenode->getAttachedObject(0));

const int flags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_AlwaysAutoResize;
bool keep_open = true;
ImGui::Begin(_LC("CharacterPoseUtil", "Character pose utility"), &keep_open, flags);

ImGui::Dummy(ImVec2(250, 1)); // force minimum width

ImGui::Text("Character: '%s'", gfx_character->xc_instance_name.c_str());
ImGui::TextDisabled("(gray text means 'disabled')");
ImGui::Separator();

AnimationStateSet* stateset = ent->getAllAnimationStates();
for (auto& state_pair : stateset->getAnimationStates())
{
AnimationState* as = state_pair.second;
ImVec4 color = (as->getEnabled()) ? ImGui::GetStyle().Colors[ImGuiCol_Text] : ImGui::GetStyle().Colors[ImGuiCol_TextDisabled];
ImGui::TextColored(color, "'%s' (%.2f sec)", as->getAnimationName().c_str(), as->getLength());
std::string caption = fmt::format("{:.2f} sec", as->getTimePosition());
ImGui::ProgressBar(as->getTimePosition() / as->getLength(), ImVec2(-1, 0), caption.c_str());
}

// Common window epilogue:

m_is_hovered = ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows);
App::GetGuiManager()->RequestGuiCaptureKeyboard(m_is_hovered);

ImGui::End();
if (!keep_open)
{
this->SetVisible(false);
}
}

void CharacterPoseUtil::SetVisible(bool v)
{
m_is_visible = v;
m_is_hovered = false;
}
44 changes: 44 additions & 0 deletions source/main/gui/panels/GUI_CharacterPoseUtil.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
This source file is part of Rigs of Rods
Copyright 2016-2020 Petr Ohlidal
For more information, see http://www.rigsofrods.org/
Rigs of Rods is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3, as
published by the Free Software Foundation.
Rigs of Rods is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "Application.h"
#include "OgreImGui.h"

namespace RoR {
namespace GUI {

class CharacterPoseUtil
{
public:
void Draw();

void SetVisible(bool visible);
bool IsVisible() const { return m_is_visible; }
bool IsHovered() const { return IsVisible() && m_is_hovered; }

private:
bool m_is_visible = false;
bool m_is_hovered = false;

};

} // namespace GUI
} // namespace RoR
6 changes: 6 additions & 0 deletions source/main/gui/panels/GUI_TopMenubar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,12 @@ void TopMenubar::Update()
m_open_menu = TopMenu::TOPMENU_NONE;
}

if (ImGui::Button(_LC("TopMenubar", "Character pose util")))
{
App::GetGuiManager()->CharacterPoseUtil.SetVisible(true);
m_open_menu = TopMenu::TOPMENU_NONE;
}

if (ImGui::Button(_LC("TopMenubar", "Collisions debug")))
{
App::GetGuiManager()->CollisionsDebug.SetVisible(true);
Expand Down

0 comments on commit 5ec548a

Please sign in to comment.