mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-27 21:45:16 +01:00
A universal control (window, door, sun blind) whose definition in the .mmd
has the new optional key drag: can be dragged with the left mouse button to
any position between its ends, and stays where it is let go:
universal1: { okno_p mov -0.71 0 0.3 drag: left soundinc: ... }
The value is the direction the mouse moves to open the control: up, down,
left or right (yes = up, no = off). The drag works like the sliders of the
controllers: the cursor is hidden, its move over 0.6 of the window height
takes the control from one end to the other. A click without dragging
toggles the control as before, and so do the keys: to the end farther from
where it is. Push controls aren't dragged. Without the key every universal
works as it did; none of the cab definitions has it yet.
New commands genericset0..29 set universal N to the position in param1
(0-1); the mouse sends them, and they can be bound to a gamepad axis.
The rules (the key's values, the move of the cursor along the direction,
the ends, click or drag, the keys) are in vehicle/universaldrag.h, with
unit tests.
161 lines
7.3 KiB
C++
161 lines
7.3 KiB
C++
/*
|
|
This Source Code Form is subject to the
|
|
terms of the Mozilla Public License, v.
|
|
2.0. If a copy of the MPL was not
|
|
distributed with this file, You can
|
|
obtain one at
|
|
http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "utilities/Classes.h"
|
|
#include "audio/sound.h"
|
|
#include "vehicle/gaugescale.h"
|
|
#include "vehicle/universaldrag.h"
|
|
|
|
enum class TGaugeAnimation {
|
|
// typ ruchu
|
|
gt_Unknown, // na razie nie znany
|
|
gt_Rotate, // obrót
|
|
gt_Move, // przesunięcie równoległe
|
|
gt_Wiper, // obrót trzech kolejnych submodeli o ten sam kąt (np. wycieraczka, drzwi harmonijkowe)
|
|
gt_Digital // licznik cyfrowy, np. kilometrów
|
|
};
|
|
|
|
enum class TGaugeType : int {
|
|
toggle = 1 << 0,
|
|
push = 1 << 1,
|
|
delayed = 1 << 2,
|
|
pushtoggle = toggle | push,
|
|
push_delayed = push | delayed,
|
|
pushtoggle_delayed = toggle | push | delayed
|
|
};
|
|
|
|
// animowany wskaźnik, mogący przyjmować wiele stanów pośrednich
|
|
class TGauge {
|
|
|
|
public:
|
|
// methods
|
|
TGauge() = default;
|
|
explicit TGauge( sound_source const &Soundtemplate );
|
|
|
|
inline
|
|
void Clear() {
|
|
*this = TGauge(); }
|
|
void Init(TSubModel *Submodel, TSubModel *Submodelon, TGaugeAnimation Type, float Scale = 1, float Offset = 0, float Friction = 0, float Value = 0, float const Endvalue = -1.0, float const Endscale = -1.0, bool const Interpolate = false );
|
|
void Load(cParser &Parser, TDynamicObject const *Owner, double const mul = 1.0);
|
|
bool UpdateValue( float fNewDesired );
|
|
bool UpdateValue( float fNewDesired, std::optional<sound_source> &Fallbacksound );
|
|
void PutValue(float fNewDesired);
|
|
float GetValue() const;
|
|
float GetDesiredValue() const;
|
|
void Update( bool const Power = true );
|
|
void AssignFloat(float *fValue);
|
|
void AssignDouble(double *dValue);
|
|
void AssignInt(int *iValue);
|
|
void AssignBool(bool *bValue);
|
|
void UpdateValue();
|
|
void AssignState( bool const *State );
|
|
// copies of the control animated along with it, from its definitions marked duplicate: yes
|
|
std::vector<TGauge> const &mirrors() const {
|
|
return m_mirrors; }
|
|
// the value shown is value * scale + offset. the copies of the control (mirrors()) show the same value, so they
|
|
// get the same offset
|
|
float offset() const {
|
|
return m_offset; }
|
|
void offset( float const Offset ) {
|
|
m_offset = Offset;
|
|
for( auto &mirror : m_mirrors ) {
|
|
mirror.m_offset = Offset; } }
|
|
float scale() const {
|
|
return m_scale; }
|
|
// returns offset of submodel associated with the button from the model centre
|
|
glm::vec3 model_offset() const;
|
|
TGaugeType type() const;
|
|
// whether the definition of the control declared its type, rather than left it at the default
|
|
bool type_declared() const {
|
|
return m_typedeclared; }
|
|
inline
|
|
bool is_push() const {
|
|
return ( static_cast<int>( type() ) & static_cast<int>( TGaugeType::push ) ) != 0; }
|
|
inline
|
|
bool is_toggle() const {
|
|
return ( static_cast<int>( type() ) & static_cast<int>( TGaugeType::toggle ) ) != 0; }
|
|
bool is_delayed() const {
|
|
return ( static_cast<int>( type() ) & static_cast<int>( TGaugeType::delayed ) ) != 0; }
|
|
// true if the gauge was given a non-uniform scale (scaletable:)
|
|
bool has_scaletable() const {
|
|
return false == m_scaletable.empty(); }
|
|
// the direction the mouse drags the control in to any position between its ends (drag:, MaSzyna-EU07/maszyna#62),
|
|
// none for a control set only to its ends. a push control springs back, so it isn't dragged
|
|
universal_drag::direction drag() const {
|
|
return universal_drag::effective( m_drag, is_push() ); }
|
|
// members
|
|
TSubModel *SubModel { nullptr }; // McZapkie-310302: zeby mozna bylo sprawdzac czy zainicjowany poprawnie
|
|
TSubModel *SubModelOn { nullptr }; // optional submodel visible when the state input is set
|
|
|
|
private:
|
|
// types
|
|
struct scratch_data {
|
|
std::optional< std::array<float, 6> > soundproofing;
|
|
bool duplicate { false }; // the definition is a duplicate submodel of the control defined before
|
|
std::vector<gauge_scale::point> scaletable; // as read, in the units of the config
|
|
universal_drag::direction drag { universal_drag::direction::none };
|
|
};
|
|
// methods
|
|
// imports member data pair from the config file
|
|
bool
|
|
Load_mapping( cParser &Input, TGauge::scratch_data &Scratchpad );
|
|
static bool
|
|
Load_scaletable( cParser &Input, TGauge::scratch_data &Scratchpad );
|
|
float
|
|
GetScaledValue() const;
|
|
void
|
|
UpdateAnimation( TSubModel *Submodel ) const;
|
|
// shows the default or the active state submodel as the state says
|
|
void
|
|
UpdateVisibility() const;
|
|
// the copy of this control's submodels and animation, without its sounds and bindings
|
|
TGauge
|
|
MirrorCopy() const;
|
|
|
|
// members
|
|
TGaugeAnimation m_animation { TGaugeAnimation::gt_Unknown }; // typ ruchu
|
|
TGaugeType m_type { TGaugeType::toggle }; // switch type
|
|
bool m_typedeclared { false }; // the type was given with type: in the definition
|
|
float m_friction { 0.f }; // hamowanie przy zliżaniu się do zadanej wartości
|
|
float m_targetvalue { 0.f }; // wartość docelowa
|
|
float m_value { 0.f }; // wartość obecna
|
|
float m_offset { 0.f }; // wartość początkowa ("0")
|
|
float m_scale { 1.f }; // scale applied to the value at the start of accepted value range
|
|
float m_endscale { -1.f }; // scale applied to the value at the end of accepted value range
|
|
float m_endvalue { -1.f }; // end value of accepted value range
|
|
bool m_interpolatescale { false };
|
|
std::vector<gauge_scale::point> m_scaletable; // optional non-uniform scale, sorted by value; replaces scale and offset
|
|
universal_drag::direction m_drag { universal_drag::direction::none }; // the mouse drags the control smoothly, drag:
|
|
|
|
char m_datatype { '\0' }; // typ zmiennej parametru: f-float, d-double, i-int, b-bool; none until one is assigned
|
|
union {
|
|
// wskaźnik na parametr pokazywany przez animację
|
|
float *fData;
|
|
double *dData { nullptr };
|
|
int *iData;
|
|
bool *bData;
|
|
};
|
|
bool m_state { false }; // visibility of the control's submodel(s); false : default, true: active
|
|
bool const *m_stateinput { nullptr }; // bound variable determining visibility of the control's submodel(s)
|
|
int m_soundtype { 0 }; // toggle between exclusive and multiple sound generation
|
|
sound_source m_soundtemplate { sound_placement::internal, EU07_SOUND_CABCONTROLSCUTOFFRANGE }; // shared properties for control's sounds
|
|
sound_source m_soundfxon { m_soundtemplate }; // sound associated with switching the control to active state
|
|
sound_source m_soundfxoff { m_soundtemplate }; // sound associated with switching the control to default state
|
|
sound_source m_soundfxincrease { m_soundtemplate }; // sound associated with increasing control's value
|
|
sound_source m_soundfxdecrease { m_soundtemplate }; // sound associated with decreasing control's value
|
|
std::map<int, sound_source> m_soundfxvalues; // sounds associated with specific values
|
|
TModel3d const *m_sourcemodel { nullptr }; // the 3d model the submodel was found in by Load()
|
|
std::vector<TGauge> m_mirrors; // duplicate submodels of the control (duplicate: yes), animated along with it
|
|
|
|
};
|
|
|
|
//---------------------------------------------------------------------------
|