RigsofRods
Soft-body Physics Simulation
GUI_VehicleDescription.cpp
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2005-2012 Pierre-Michel Ricordel
4  Copyright 2007-2012 Thomas Fischer
5  Copyright 2013-2020 Petr Ohlidal
6 
7  For more information, see http://www.rigsofrods.org/
8 
9  Rigs of Rods is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License version 3, as
11  published by the Free Software Foundation.
12 
13  Rigs of Rods is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
25 
26 #include "GUI_VehicleDescription.h"
27 
28 #include "Application.h"
29 #include "Actor.h"
30 #include "GameContext.h"
31 #include "GUIManager.h"
32 #include "InputEngine.h"
33 #include "Language.h"
34 
35 #include <fmt/format.h>
36 #include <imgui.h>
37 
38 using namespace RoR;
39 using namespace GUI;
40 
42 {
44  if (!actor)
45  {
46  m_is_visible = false;
47  return;
48  }
49 
50  ImGui::SetNextWindowPosCenter(ImGuiCond_Appearing);
51  ImVec2 size(HELP_TEXTURE_WIDTH + 2*ImGui::GetStyle().WindowPadding.x, 0.f);
52  ImGui::SetNextWindowSize(size, ImGuiCond_Appearing);
53  if (!ImGui::Begin(actor->getTruckName().c_str(), &m_is_visible))
54  {
55  ImGui::End(); // The window is collapsed
56  return;
57  }
58 
59  RoR::GfxActor* gfx_actor = actor->GetGfxActor();
60  if (gfx_actor->GetHelpTex())
61  {
62  ImTextureID im_tex = reinterpret_cast<ImTextureID>(gfx_actor->GetHelpTex()->getHandle());
63  ImGui::Image(im_tex, ImVec2(HELP_TEXTURE_WIDTH, HELP_TEXTURE_HEIGHT));
64  }
65 
66  if (ImGui::CollapsingHeader(_LC("VehicleDescription", "Description"), ImGuiTreeNodeFlags_DefaultOpen))
67  {
68  for (auto line : actor->getDescription())
69  {
70  ImGui::TextWrapped("%s", line.c_str());
71  }
72  }
73 
74  if (ImGui::CollapsingHeader(_LC("VehicleDescription", "Commands"), ImGuiTreeNodeFlags_DefaultOpen))
75  {
76  ImGui::Columns(2, /*id=*/nullptr, /*border=*/true);
77  for (const UniqueCommandKeyPair& qpair: actor->ar_unique_commandkey_pairs)
78  {
79  int eventID = RoR::InputEngine::resolveEventName(fmt::format("COMMANDS_{:02d}", qpair.uckp_key1));
80  Ogre::String keya = RoR::App::GetInputEngine()->getEventCommandTrimmed(eventID);
81  eventID = RoR::InputEngine::resolveEventName(fmt::format("COMMANDS_{:02d}", qpair.uckp_key2));
82  Ogre::String keyb = RoR::App::GetInputEngine()->getEventCommandTrimmed(eventID);
83 
84  ImGui::Text("%s/%s", keya.c_str(), keyb.c_str());
85  ImGui::NextColumn();
86 
87  if (qpair.uckp_description != "")
88  {
89  ImGui::Text("%s", qpair.uckp_description.c_str());
90  }
91  else
92  {
93  ImGui::TextDisabled("%s", _LC("VehicleDescription", "unknown function"));
94  }
95  ImGui::NextColumn();
96  }
97  ImGui::Columns(1);
98  }
99 
100  if (ImGui::CollapsingHeader(_LC("VehicleDescription", "Authors")))
101  {
102  for (authorinfo_t const& author: actor->getAuthors())
103  {
104  ImGui::Text("%s: %s", author.type.c_str(), author.name.c_str());
105  }
106 
107  if (actor->getAuthors().empty())
108  {
109  ImGui::TextDisabled("%s", _LC("VehicleDescription", "(no author information available) "));
110  }
111  }
112 
113  App::GetGuiManager()->RequestGuiCaptureKeyboard(ImGui::IsWindowHovered());
114  ImGui::End();
115 }
GameContext.h
Game state manager and message-queue provider.
RoR::InputEngine::getEventCommandTrimmed
std::string getEventCommandTrimmed(int eventID)
Omits 'EXPL' modifier.
Definition: InputEngine.cpp:788
RoR::App::GetGuiManager
GUIManager * GetGuiManager()
Definition: Application.cpp:269
RoR::Actor::ar_unique_commandkey_pairs
std::vector< UniqueCommandKeyPair > ar_unique_commandkey_pairs
UI helper for displaying command control keys to user (must be built at spawn).
Definition: Actor.h:313
format
Truck file format(technical spec)
RoR::Actor::getDescription
std::vector< std::string > getDescription()
Definition: Actor.cpp:4463
RoR::authorinfo_t
Definition: SimData.h:823
RoR::Actor::GetGfxActor
GfxActor * GetGfxActor()
Definition: Actor.h:263
Language.h
RefCountingObjectPtr< Actor >
GUIManager.h
Actor.h
RoR::UniqueCommandKeyPair::uckp_key2
CommandkeyID_t uckp_key2
Definition: SimData.h:698
RoR::Actor::getAuthors
std::vector< authorinfo_t > getAuthors()
Definition: Actor.cpp:4458
GUI_VehicleDescription.h
RoR::GfxActor::GetHelpTex
Ogre::TexturePtr GetHelpTex()
Definition: GfxActor.h:141
RoR::GUI::VehicleDescription::m_is_visible
bool m_is_visible
Definition: GUI_VehicleDescription.h:45
RoR::GUI::VehicleDescription::Draw
void Draw()
Definition: GUI_VehicleDescription.cpp:41
Application.h
Central state/object manager and communications hub.
RoR::App::GetGameContext
GameContext * GetGameContext()
Definition: Application.cpp:280
RoR::InputEngine::resolveEventName
static int resolveEventName(Ogre::String eventName)
Definition: InputEngine.cpp:2000
_LC
#define _LC(ctx, str)
Definition: Language.h:42
RoR::UniqueCommandKeyPair::uckp_description
std::string uckp_description
Definition: SimData.h:696
RoR::UniqueCommandKeyPair
UI helper for displaying command control keys to user.
Definition: SimData.h:694
RoR::GUI::VehicleDescription::HELP_TEXTURE_WIDTH
const float HELP_TEXTURE_WIDTH
Definition: GUI_VehicleDescription.h:36
RoR::App::GetInputEngine
InputEngine * GetInputEngine()
Definition: Application.cpp:271
RoR::GfxActor
Definition: GfxActor.h:52
InputEngine.h
Handles controller inputs from player. Defines input events and binding mechanism,...
RoR::Actor::getTruckName
std::string getTruckName()
Definition: Actor.h:220
RoR::UniqueCommandKeyPair::uckp_key1
CommandkeyID_t uckp_key1
Definition: SimData.h:697
RoR::GameContext::GetPlayerActor
const ActorPtr & GetPlayerActor()
Definition: GameContext.h:134
RoR::GUI::VehicleDescription::HELP_TEXTURE_HEIGHT
const float HELP_TEXTURE_HEIGHT
Definition: GUI_VehicleDescription.h:37
RoR::GUIManager::RequestGuiCaptureKeyboard
void RequestGuiCaptureKeyboard(bool val)
Pass true during frame to prevent input passing to application.
Definition: GUIManager.cpp:450
RoR
Definition: AppContext.h:36