Rigs of Rods 2026.01
Soft-body Physics Simulation
Loading...
Searching...
No Matches
DashBoardManager.h
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#pragma once
27
28
29#include "Application.h"
30#include "RefCountingObject.h"
32#include "RTTLayer.h"
33
34#include <MyGUI.h>
35
36#include <map>
37#include <string>
38#include <vector>
39
40namespace RoR {
41
42#define DD_MAXCHAR 255
43#define DD_MAX_SCREWPROP 6
44#define DD_MAX_AEROENGINE 6
45#define DD_MAX_WING 6
46#define DD_MAX_GEOMETRIC_ANIMATIONS 10
47
49{
50 bool value_bool = false;
51 int value_int = 0;
52 float value_float = 0.f;
54};
55
56enum
57{
58 DC_MIN, // Used for validation
59
65
66 DC_MAX // Used for validation
67};
68
69typedef struct dashData_t
70{
71 char type; // DC_*
73 bool enabled;
74 std::string name; // char string of name
75
77 {
78 enabled = false;
79 }
80
81 dashData_t(char type, std::string name) : type(type), name(name)
82 {
83 enabled = true;
84 }
85} dashData_t;
86
87// DashData enum definition
88// important: if you add things here, also change the initialization in the constructor
90{
100
106
107 DD_ENGINE_CLUTCH, // the engines clutch
108
109 DD_BRAKE, // the brake application in % 0-1
110 DD_ACCELERATOR, // accelerator pedal in %, 0-1
111
112 DD_ROLL, // roll of the chassis
113 DD_ROLL_CORR, // correction roll of the chassis
114 DD_ROLL_CORR_ACTIVE, // correction rolling active
115
117
120
122
127
128 // water things
129 DD_SCREW_THROTTLE_0, // throttle for screwprop 0
134 DD_SCREW_THROTTLE_5, // if you add some, change DD_MAX_SCREWPROP and DD_SCREW_STEER_*
135
136 DD_SCREW_STEER_0, // steering direction of screw 0
137 DD_SCREW_STEER_1, // steering direction of screw 1
138 DD_SCREW_STEER_2, // steering direction of screw 2
139 DD_SCREW_STEER_3, // steering direction of screw 3
140 DD_SCREW_STEER_4, // steering direction of screw 4
141 DD_SCREW_STEER_5, // steering direction of screw 4, if you add some, change DD_MAX_SCREWPROP and DD_SCREW_THROTTLE_*
142
143 DD_WATER_DEPTH, // how much water is under the boat
144 DD_WATER_SPEED, // speed in knots
145
146 // airplane things
153
160
167
168 DD_AIRSPEED, // speed in air
169
176
179
182
183 // Lights (mirrors RoRnet::Lightmask)
184
195
204
208
214
215 DD_MAX // This is the starting point for custom inputs
217
225
226// this class is NOT intended to be thread safe - performance is required
227class DashBoardManager : public RefCountingObject<DashBoardManager>
228{
229public:
231 virtual ~DashBoardManager() override;
232
233 int registerCustomInput(Ogre::String name, int dataType);
234
235 // Getter / Setter
236 bool _getBool(int key) { return key < data.size() ? data[key].data.value_bool : false; };
237 int _getInt(int key) { return data[key].data.value_int; };
238 float _getFloat(int key) { return data[key].data.value_float; };
239 float getNumeric(int key);
240 char* getChar(int key) { return key < data.size() ? data[key].data.value_char : nullptr; };
241 bool getEnabled(int key) { return key < data.size() ? data[key].enabled : false; };
242
243 void setBool(int key, bool val) { if (key < data.size()) data[key].data.value_bool = val; };
244 void setInt(int key, int val) { if (key < data.size()) data[key].data.value_int = val; };
245 void setFloat(int key, float val) { if (key < data.size()) data[key].data.value_float = val; };
246 void setChar(int key, const char* val) { if (key < data.size()) strncpy(data[key].data.value_char, val, DD_MAXCHAR); };
247
248 void setEnabled(int key, bool val) { if (key < data.size()) data[key].enabled = val; };
249
250 int getDataType(int key) { return key < data.size() ? data[key].type : DC_INVALID; };
251
252 int getLinkIDForName(Ogre::String& str);
253 std::string getLinkNameForID(DashData id);
254
255 DashBoard* loadDashBoard(const std::string& filename, BitMask_t flags, RTTLayer* rttLayer);
256
257 void update(float dt);
258 void updateFeatures();
259
260 bool wasDashboardHudLoaded() const { return m_hud_loaded; };
261 bool wasDashboardRttLoaded() const { return m_rtt_loaded; };
262
263 void setVisible(bool visibility);
264 void setVisible3d(bool visibility);
265 bool getVisible() { return visible; };
266 void windowResized();
267 void applyUiScale();
268 size_t getInputCount() { return data.size(); }
270protected:
271 std::string determineLayoutFromDashboardMod(CacheEntryPtr& entry, std::string const& basename, BitMask_t loaddashboardFlags);
272 std::string determineTruckLayoutFromDashboardMod(Ogre::FileInfoListPtr& filelist);
274 bool visible = false;
275 std::vector<dashData_t> data;
276 std::vector<DashBoard*> m_dashboards;
277 bool m_hud_loaded = false;
278 bool m_rtt_loaded = false;
282};
283
285{
286 friend class DashBoardManager;
287
288public:
289 DashBoard(DashBoardManager* manager, Ogre::String filename, RTTLayer* _rttLayer);
290 ~DashBoard();
291
292 void setVisible(bool visible, bool smooth = true);
293 bool getVisible() { return visible; };
294
295 bool getIsTextureLayer() { return rttLayer != nullptr; }
296
297 void update(float dt);
298 void updateFeatures();
299
300 void windowResized();
301 void applyUiScale();
302
303 float getSmoothNumeric(int linkID, float& lastVal);
304
305protected:
307 {
308 MyGUI::IntCoord coord;
309 int font_height = 0;
310 };
311
312 void snapshotWidgetOriginsRecursive(MyGUI::Widget* parent);
313 void applyUiScaleRecursive(MyGUI::Widget* parent, MyGUI::IntSize parent_orig_size, MyGUI::IntSize parent_new_size);
314
315 std::map<MyGUI::Widget*, WidgetOrigin> m_widget_origins;
316 MyGUI::IntSize m_main_origin_size;
317 float m_ui_scale = 1.f;
318
320 Ogre::String filename;
321 MyGUI::VectorWidgetPtr widgets;
322 MyGUI::WindowPtr mainWidget;
324 std::string prefix;
326
327 enum
328 {
339 };
340
341 enum
342 {
348 };
349
350 enum
351 {
355 };
356
358 {
359 int linkID; // DD_*
360
361 char animationType; // ANIM_*
362
363 float wmin; // rotation/offset whatever (widget min/max)
364 float wmax;
365 float vmin; // value min/max
366 float vmax;
367 char direction; // DIRECTION_*
368 float lastVal;
369 } layoutGeometricAnimation_t;
370
372 {
373 int linkID; // DD_*
374
375 char animationType; // ANIM_*
376
377 int condition; // CONDITION_*
379 char format[255]; // string format
380 char texture[255]; // texture filename
381 char format_neg_zero[255];
382 float lastVal;
383 } layoutGraphicalAnimation_t;
384
385 // linking attributes
386 typedef struct layoutLink_t
387 {
389
390 char name[255]; // widget name
391
395
396 MyGUI::Widget* widget;
397 MyGUI::RotatingSkin* rotImg;
398 MyGUI::ImageBox* img;
399 MyGUI::TextBox* txt;
400 MyGUI::IntSize initialSize;
401 MyGUI::IntPoint initialPosition;
402
404 } layoutLink_t;
405
406 void loadLayoutInternal();
407 void loadLayoutRecursive(MyGUI::WidgetPtr ptr);
408 bool parseLink(std::string& linkArgs, int& linkID, char& condition, float& conditionArgument, const std::string& filename, const std::string& name);
409 std::vector<layoutLink_t> controls;
410};
411
412} // namespace RoR
Central state/object manager and communications hub.
#define BITMASK(OFFSET)
Definition BitFlags.h:10
uint32_t BitMask_t
Definition BitFlags.h:7
#define DD_MAXCHAR
#define DD_MAX_GEOMETRIC_ANIMATIONS
Self reference-counting objects, as requred by AngelScript garbage collector.
MyGUI::WindowPtr mainWidget
Ogre::String filename
void applyUiScaleRecursive(MyGUI::Widget *parent, MyGUI::IntSize parent_orig_size, MyGUI::IntSize parent_new_size)
void setVisible(bool visible, bool smooth=true)
void snapshotWidgetOriginsRecursive(MyGUI::Widget *parent)
void update(float dt)
float getSmoothNumeric(int linkID, float &lastVal)
bool parseLink(std::string &linkArgs, int &linkID, char &condition, float &conditionArgument, const std::string &filename, const std::string &name)
float m_ui_scale
Also applies to pixel values of 'scale' and 'translate' animations.
void applyUiScale()
Reads cvar 'ui_scale_factor'; only affects screen dashboards (not RTT)
MyGUI::VectorWidgetPtr widgets
std::vector< layoutLink_t > controls
std::map< MyGUI::Widget *, WidgetOrigin > m_widget_origins
Unscaled coords as loaded from layout; empty for RTT dashboards.
MyGUI::IntSize m_main_origin_size
Size of mainWidget when m_widget_origins were recorded.
DashBoardManager * manager
void loadLayoutRecursive(MyGUI::WidgetPtr ptr)
void applyUiScale()
Reads cvar 'ui_scale_factor'; only affects screen dashboards (not RTT)
void setVisible(bool visibility)
bool wasDashboardRttLoaded() const
bool wasDashboardHudLoaded() const
void setFloat(int key, float val)
std::vector< dashData_t > data
void setInt(int key, int val)
std::string determineLayoutFromDashboardMod(CacheEntryPtr &entry, std::string const &basename, BitMask_t loaddashboardFlags)
int getLinkIDForName(Ogre::String &str)
void setEnabled(int key, bool val)
void setVisible3d(bool visibility)
void loadDashboardModDetails(CacheEntryPtr &entry)
int getNumLoadedRTTDashboards() const
void setChar(int key, const char *val)
std::string determineTruckLayoutFromDashboardMod(Ogre::FileInfoListPtr &filelist)
int registerCustomInput(Ogre::String name, int dataType)
void setBool(int key, bool val)
virtual ~DashBoardManager() override
std::string getLinkNameForID(DashData id)
std::vector< DashBoard * > m_dashboards
DashBoard * loadDashBoard(const std::string &filename, BitMask_t flags, RTTLayer *rttLayer)
RTT texture 'slot' within MyGUI system; we can only create them, not destroy, so we reuse.
Definition RTTLayer.h:13
@ DD_ENGINE_RPM
@ DD_AEROENGINE_THROTTLE_4
@ DD_SCREW_STEER_2
@ DD_CUSTOM_LIGHT6
custom light 6 on
@ DD_CUSTOM_LIGHT7
custom light 7 on
@ DD_ODOMETER_TOTAL
@ DD_CUSTOM_LIGHT10
custom light 10 on
@ DD_ENGINE_BATTERY
@ DD_SCREW_THROTTLE_2
@ DD_CUSTOM_LIGHT2
custom light 2 on
@ DD_CUSTOM_LIGHT4
custom light 4 on
@ DD_GUISETTING_TACHO
(char) Tacho texture name - from 'guisettings' section of truck file.
@ DD_ENGINE_NUM_GEAR
current gear
@ DD_AEROENGINE_FAILED_4
@ DD_SCREW_THROTTLE_4
@ DD_AEROENGINE_RPM_1
@ DD_LIGHTS_LEGACY
Alias of 'sidelights'.
@ DD_GUISETTING_SPEEDO_KPH
(float) Like DD_ENGINE_SPEEDO_KPH, but if 'speedoTexture' and 'speedoMax' in 'guisettings' are set,...
@ DD_ENGINE_SPEEDO_KPH
@ DD_AEROENGINE_FAILED_5
@ DD_SCREW_STEER_5
@ DD_ENGINE_AUTOGEAR_STRING
string like "<current gear>/<max gear>"
@ DD_AEROENGINE_RPM_5
@ DD_AEROENGINE_FAILED_2
@ DD_SCREW_STEER_1
@ DD_GUISETTING_HELP
(char) Help texture name - from 'guisettings' section of truck file.
@ DD_GUISETTING_TACHO_RPM
(float) Like DD_ENGINE_RPM, but if 'tachoTexture' and 'useMaxRPM' in 'guisettings' is set,...
@ DD_ENGINE_OFF
@ DD_AEROENGINE_RPM_4
@ DD_PARKINGBRAKE
chassis pitch
@ DD_AEROENGINE_THROTTLE_2
@ DD_ENGINE_RUNNING
@ DD_SCREW_THROTTLE_3
@ DD_CUSTOM_LIGHT9
custom light 9 on
@ DD_ENGINE_GEAR_STRING
@ DD_SIGNAL_WARNING
The warning-blink indicator is lit.
@ DD_SCREW_STEER_4
@ DD_CUSTOM_LIGHT3
custom light 3 on
@ DD_BRAKE_LIGHTS
@ DD_ANTILOCKBRAKE_MODE
@ DD_CRUISECONTROL_ACTIVE
ties locked
@ DD_SIGNAL_TURNLEFT
Left blinker is lit.
@ DD_ENGINE_SPEEDO_MPH
speedo in kilometer per hour
@ DD_AEROENGINE_FAILED_3
@ DD_SCREW_THROTTLE_1
@ DD_ENGINE_IGNITION
turbo gauge
@ DD_AEROENGINE_RPM_0
@ DD_CUSTOM_LIGHT8
custom light 8 on
@ DD_ROLL_CORR_ACTIVE
@ DD_AEROENGINE_THROTTLE_5
@ DD_ENGINE_GEAR
clutch warning lamp
@ DD_AEROENGINE_THROTTLE_0
@ DD_AEROENGINE_FAILED_0
@ DD_AEROENGINE_FAILED_1
@ DD_AEROENGINE_RPM_2
@ DD_SCREW_THROTTLE_5
@ DD_LOCKED
parking brake status
@ DD_ENGINE_AUTO_GEAR
string like "P R N G"
@ DD_ODOMETER_USER
@ DD_SCREW_STEER_3
@ DD_REVERSE_LIGHT
@ DD_SIGNAL_TURNRIGHT
Right blinker is lit.
@ DD_CUSTOM_LIGHT5
custom light 5 on
@ DD_ENGINE_CLUTCH_WARNING
battery lamp
@ DD_LOW_PRESSURE
locked lamp
@ DD_ENGINE_TURBO
speedo in miles per hour
@ DD_AEROENGINE_RPM_3
@ DD_ENGINE_CLUTCH
automatic gear
@ DD_GUISETTING_SPEEDO
(char) Speedo texture name - from 'guisettings' section of truck file.
@ DD_CUSTOM_LIGHT1
custom light 1 on
@ DD_ALTITUDE_STRING
@ DD_TRACTIONCONTROL_MODE
low pressure
@ DD_AEROENGINE_THROTTLE_3
@ DD_SCREW_STEER_0
@ DD_SCREW_THROTTLE_0
@ DD_AEROENGINE_THROTTLE_1
@ LOADDASHBOARD_RTT_TEXTURE
Will be drawn to texture. Unless STACKABLE, it prevents the default dashboard from loading.
@ LOADDASHBOARD_RENDERDASH
Will be drawn to texture in classic 'renderdash' format. Ignores STACKABLE flag.
@ LOADDASHBOARD_SCREEN_HUD
Will be drawn to screen. Unless STACKABLE, it prevents the default dashboard from loading.
@ LOADDASHBOARD_STACKABLE
Allows loading multiple dashboards at once (by default there's only one for screen and one for RTT).
int font_height
Only for TextBox widgets.
char format_neg_zero[255]
Test for undesired '-0.0' on display. Only for link type "format". Empty if not applicable.
dataContainer_t data
dashData_t(char type, std::string name)
char value_char[DD_MAXCHAR]